summaryrefslogtreecommitdiff
path: root/src/misc_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-11-14 22:50:56 +0000
committerfrosch <frosch@openttd.org>2012-11-14 22:50:56 +0000
commit5e8238c75c66845da7b942abd1c124f51b5520af (patch)
tree56bbc5298ac5c5e9a622e3b78f8c348020e5b381 /src/misc_gui.cpp
parent545b6de90067cb27013d2d823fc8967dd49b0902 (diff)
downloadopenttd-5e8238c75c66845da7b942abd1c124f51b5520af.tar.xz
(svn r24748) -Add: Clear button to all editboxes.
Diffstat (limited to 'src/misc_gui.cpp')
-rw-r--r--src/misc_gui.cpp34
1 files changed, 32 insertions, 2 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);