Changeset - r19793:0039ee2fd9ad
[Not reviewed]
master
0 3 0
frosch - 12 years ago 2012-11-14 22:50:56
frosch@openttd.org
(svn r24748) -Add: Clear button to all editboxes.
3 files changed with 40 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -778,17 +778,29 @@ void QueryString::HandleEditBox(Window *
 

	
 
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);
 

	
 
	/* Limit the drawing of the string inside the widget boundaries */
 
	DrawPixelInfo dpi;
 
	if (!FillDrawPixelInfo(&dpi, left + WD_FRAMERECT_LEFT, top + WD_FRAMERECT_TOP, right - left - WD_FRAMERECT_RIGHT, bottom - top - WD_FRAMERECT_BOTTOM)) return;
 
@@ -811,12 +823,30 @@ void QueryString::DrawEditBox(const Wind
 

	
 
	_cur_dpi = old_dpi;
 
}
 

	
 
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);
 
	}
 
}
 

	
src/table/sprites.h
Show inline comments
 
@@ -53,13 +53,13 @@ static const SpriteID SPR_ASCII_SPACE_SM
 
static const SpriteID SPR_ASCII_SPACE_BIG   = 450;
 

	
 
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;
 
static const SpriteID SPR_HALFTILE_SELECTION_DOWN = SPR_OPENTTD_BASE + 4;
 
static const SpriteID SPR_HALFTILE_SELECTION_UP   = SPR_OPENTTD_BASE + 8;
 

	
 
@@ -151,12 +151,15 @@ static const SpriteID SPR_TOWN_RATING_NA
 
static const SpriteID SPR_TOWN_RATING_APALLING       = SPR_OPENTTD_BASE + 163;
 
static const SpriteID SPR_TOWN_RATING_MEDIOCRE       = SPR_OPENTTD_BASE + 164;
 
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;
 
static const uint16 PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT = 240;
 

	
 
static const SpriteID SPR_CANALS_BASE   = SPR_SIGNALS_BASE + PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT;
src/window.cpp
Show inline comments
 
@@ -364,14 +364,16 @@ void CDECL Window::SetWidgetsLoweredStat
 
 * Raise the buttons of the window.
 
 * @param autoraise Raise only the push buttons of the window.
 
 */
 
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);
 
		}
 
	}
 
}
 

	
0 comments (0 inline, 0 general)