From 93fe44a3c561e357313af0f8332a697b46812474 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 21 Mar 2009 19:31:47 +0000 Subject: (svn r15783) -Codechange: make the dropdown draw code pass around the left/right instead of the x and width to make drawing text at offsets easier. --- src/company_gui.cpp | 6 +++--- src/gfx.cpp | 2 +- src/newgrf_gui.cpp | 4 ++-- src/toolbar_gui.cpp | 12 ++++++------ src/widgets/dropdown.cpp | 23 ++++++++++++----------- src/widgets/dropdown_type.h | 6 +++--- 6 files changed, 27 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/company_gui.cpp b/src/company_gui.cpp index cc1af0e53..1d7187be9 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -399,10 +399,10 @@ public: return true; } - void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const + void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const { - DrawSprite(SPR_VEH_BUS_SIDE_VIEW, PALETTE_RECOLOUR_START + this->result, x + 16, y + 7); - DrawStringTruncated(x + 32, y + 3, this->String(), sel ? TC_WHITE : TC_BLACK, width - 30); + DrawSprite(SPR_VEH_BUS_SIDE_VIEW, PALETTE_RECOLOUR_START + this->result, left + 16, top + 7); + DrawString(left + 32, right - 2, top + 3, this->String(), sel ? TC_WHITE : TC_BLACK); } }; diff --git a/src/gfx.cpp b/src/gfx.cpp index 670f591e1..ee6c33d0a 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -342,7 +342,7 @@ static int TruncateString(char *str, int maxw) if (IsPrintable(c)) { w += GetCharacterWidth(size, c); - if (w >= maxw) { + if (w > maxw) { /* string got too big... insert dotdotdot, but make sure we do not * print anything beyond the string termination character. */ for (int i = 0; *ddd_pos != '\0' && i < 3; i++, ddd_pos++) *ddd_pos = '.'; diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 1b265f4a8..2558336f6 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -274,9 +274,9 @@ public: return true; } - void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const + void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const { - DoDrawStringTruncated(_grf_preset_list[this->result], x + 2, y, sel ? TC_WHITE : TC_BLACK, x + width); + DrawString(left + 2, right + 2, top, _grf_preset_list[this->result], sel ? TC_WHITE : TC_BLACK); } }; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 657802d38..965ebb25e 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -129,12 +129,12 @@ public: virtual ~DropDownListCheckedItem() {} - void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const + void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const { if (checked) { - DrawString(x + 2, y, STR_CHECKMARK, sel ? TC_WHITE : TC_BLACK); + DrawString(left + 2, right - 2, top, STR_CHECKMARK, sel ? TC_WHITE : TC_BLACK); } - DrawStringTruncated(x + 2, y, this->String(), sel ? TC_WHITE : TC_BLACK, width); + DrawString(left + 2, right - 2, top, this->String(), sel ? TC_WHITE : TC_BLACK); } }; @@ -164,10 +164,10 @@ public: return GetStringBoundingBox(buffer).width + 19; } - void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const + void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const { CompanyID company = (CompanyID)result; - DrawCompanyIcon(company, x + 2, y + 1); + DrawCompanyIcon(company, left + 2, top + 1); SetDParam(0, company); SetDParam(1, company); @@ -177,7 +177,7 @@ public: } else { col = sel ? TC_WHITE : TC_BLACK; } - DrawStringTruncated(x + 19, y, STR_7021, col, width - 17); + DrawString(left + 19, right - 2, top, STR_7021, col); } }; diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 88d31ab7a..c3eaa7d35 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -12,13 +12,13 @@ #include "table/strings.h" -void DropDownListItem::Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const +void DropDownListItem::Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const { int c1 = _colour_gradient[bg_colour][3]; int c2 = _colour_gradient[bg_colour][7]; - GfxFillRect(x + 1, y + 3, x + width - 2, y + 3, c1); - GfxFillRect(x + 1, y + 4, x + width - 2, y + 4, c2); + GfxFillRect(left + 1, top + 3, right - 1, top + 3, c1); + GfxFillRect(left + 1, top + 4, right - 1, top + 4, c2); } uint DropDownListStringItem::Width() const @@ -28,9 +28,9 @@ uint DropDownListStringItem::Width() const return GetStringBoundingBox(buffer).width; } -void DropDownListStringItem::Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const +void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const { - DrawStringTruncated(x + 2, y, this->String(), sel ? TC_WHITE : TC_BLACK, width); + DrawString(left + 2, right - 2, top, this->String(), sel ? TC_WHITE : TC_BLACK); } StringID DropDownListParamStringItem::String() const @@ -44,9 +44,9 @@ uint DropDownListCharStringItem::Width() const return GetStringBoundingBox(this->string).width; } -void DropDownListCharStringItem::Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const +void DropDownListCharStringItem::Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const { - DoDrawStringTruncated(this->string, x + 2, y, sel ? TC_WHITE : TC_BLACK, width); + DrawString(left + 2, right - 2, top, this->string, sel ? TC_WHITE : TC_BLACK); } /** @@ -133,7 +133,8 @@ struct DropdownWindow : Window { int sel = this->selected_index; int width = this->widget[0].right - 2; - int height = this->widget[0].bottom; + int right = this->widget[0].right; + int bottom = this->widget[0].bottom; int pos = this->vscroll.pos; DropDownList *list = this->list; @@ -146,12 +147,12 @@ struct DropdownWindow : Window { if (--pos >= 0) continue; if (y + item_height < height) { - if (sel == item->result) GfxFillRect(x + 1, y, x + width - 1, y + item_height - 1, 0); + if (sel == item->result) GfxFillRect(x + 1, y, right - 1, y + item_height - 1, 0); - item->Draw(x, y, width, height, sel == item->result, (TextColour)this->widget[0].colour); + item->Draw(0, right, y, bottom, sel == item->result, (TextColour)this->widget[0].colour); if (item->masked) { - GfxFillRect(x, y, x + width - 1, y + item_height - 1, + GfxFillRect(x, y, right - 1, y + item_height - 1, _colour_gradient[this->widget[0].colour][5], FILLRECT_CHECKER ); } diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h index 607799656..594cabe7e 100644 --- a/src/widgets/dropdown_type.h +++ b/src/widgets/dropdown_type.h @@ -23,7 +23,7 @@ public: virtual bool Selectable() const { return false; } virtual uint Height(uint width) const { return 10; } virtual uint Width() const { return 0; } - virtual void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const; + virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const; }; /** @@ -38,7 +38,7 @@ public: virtual bool Selectable() const { return true; } virtual uint Width() const; - virtual void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const; + virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const; virtual StringID String() const { return this->string; } }; @@ -68,7 +68,7 @@ public: virtual bool Selectable() const { return true; } virtual uint Width() const; - virtual void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const; + virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const; }; /** -- cgit v1.2.3-54-g00ecf