summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/misc_gui.cpp34
-rw-r--r--src/table/sprites.h5
-rw-r--r--src/window.cpp6
3 files changed, 40 insertions, 5 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index dfd5f7e78..c47f62998 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -781,11 +781,23 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
assert((wi->type & WWT_MASK) == WWT_EDITBOX);
- int left = wi->pos_x;
- int right = wi->pos_x + wi->current_x - 1;
+
+ bool rtl = _current_text_dir == TD_RTL;
+ Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
+ int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
+
+ int clearbtn_left = wi->pos_x + (rtl ? 0 : wi->current_x - clearbtn_width);
+ int clearbtn_right = wi->pos_x + (rtl ? clearbtn_width : wi->current_x) - 1;
+ int left = wi->pos_x + (rtl ? clearbtn_width : 0);
+ int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
+
int top = wi->pos_y;
int bottom = wi->pos_y + wi->current_y - 1;
+ DrawFrameRect(clearbtn_left, top, clearbtn_right, bottom, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
+ DrawSprite(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, clearbtn_left + WD_IMGBTN_LEFT + (wi->IsLowered() ? 1 : 0), (top + bottom - sprite_size.height) / 2 + (wi->IsLowered() ? 1 : 0));
+ if (this->text.bytes == 1) GfxFillRect(clearbtn_left + 1, top + 1, clearbtn_right - 1, bottom - 1, _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
+
DrawFrameRect(left, top, right, bottom, wi->colour, FR_LOWERED | FR_DARKENED);
GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, PC_BLACK);
@@ -814,6 +826,24 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
void QueryString::ClickEditBox(Window *w, Point pt, int wid, int click_count, bool focus_changed)
{
+ const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
+
+ assert((wi->type & WWT_MASK) == WWT_EDITBOX);
+
+ bool rtl = _current_text_dir == TD_RTL;
+ int clearbtn_width = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT).width;
+
+ int clearbtn_left = wi->pos_x + (rtl ? 0 : wi->current_x - clearbtn_width);
+
+ if (IsInsideBS(pt.x, clearbtn_left, clearbtn_width)) {
+ if (this->text.bytes > 1) {
+ this->text.DeleteAll();
+ w->HandleButtonClick(wid);
+ w->OnEditboxChanged(wid);
+ }
+ return;
+ }
+
if (!focus_changed && w->window_class != WC_OSK) {
/* Open the OSK window if clicked on an edit box, while not changing focus */
ShowOnScreenKeyboard(w, wid);
diff --git a/src/table/sprites.h b/src/table/sprites.h
index db78222b2..538888308 100644
--- a/src/table/sprites.h
+++ b/src/table/sprites.h
@@ -56,7 +56,7 @@ static const SpriteID SPR_LARGE_SMALL_WINDOW = 682;
/** Extra graphic spritenumbers */
static const SpriteID SPR_OPENTTD_BASE = 4896;
-static const uint16 OPENTTD_SPRITE_COUNT = 166;
+static const uint16 OPENTTD_SPRITE_COUNT = 168;
/* Halftile-selection sprites */
static const SpriteID SPR_HALFTILE_SELECTION_FLAT = SPR_OPENTTD_BASE;
@@ -154,6 +154,9 @@ static const SpriteID SPR_TOWN_RATING_GOOD = SPR_OPENTTD_BASE + 165;
static const SpriteID SPR_IMG_SWITCH_TOOLBAR = SPR_OPENTTD_BASE + 144;
+static const SpriteID SPR_IMG_DELETE_LEFT = SPR_OPENTTD_BASE + 166;
+static const SpriteID SPR_IMG_DELETE_RIGHT = SPR_OPENTTD_BASE + 167;
+
static const SpriteID SPR_SIGNALS_BASE = SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT;
static const uint16 PRESIGNAL_SPRITE_COUNT = 48;
static const uint16 PRESIGNAL_AND_SEMAPHORE_SPRITE_COUNT = 112;
diff --git a/src/window.cpp b/src/window.cpp
index 62109e82c..9705de0df 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -367,8 +367,10 @@ void CDECL Window::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...)
void Window::RaiseButtons(bool autoraise)
{
for (uint i = 0; i < this->nested_array_size; i++) {
- if (this->nested_array[i] != NULL && ((this->nested_array[i]->type & ~WWB_PUSHBUTTON) < WWT_LAST || this->nested_array[i]->type == NWID_PUSHBUTTON_DROPDOWN) &&
- (!autoraise || (this->nested_array[i]->type & WWB_PUSHBUTTON)) && this->IsWidgetLowered(i)) {
+ if (this->nested_array[i] == NULL) continue;
+ WidgetType type = this->nested_array[i]->type;
+ if (((type & ~WWB_PUSHBUTTON) < WWT_LAST || type == NWID_PUSHBUTTON_DROPDOWN) &&
+ (!autoraise || (type & WWB_PUSHBUTTON) || type == WWT_EDITBOX) && this->IsWidgetLowered(i)) {
this->RaiseWidget(i);
this->SetWidgetDirty(i);
}