From c461ccfecb9e31f8430046b2b82aebeaf05e3a6a Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 18 Nov 2009 12:45:20 +0000 Subject: (svn r18166) -Codechange: make the livery colour window RTL aware --- src/company_gui.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 40daa7aac..0591b63b1 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -528,8 +528,9 @@ public: 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, left + 16, top + 7); - DrawString(left + 32, right - 2, top + max(0, 13 - FONT_HEIGHT_NORMAL), this->String(), sel ? TC_WHITE : TC_BLACK); + bool rtl = _dynlang.text_dir == TD_RTL; + DrawSprite(SPR_VEH_BUS_SIDE_VIEW, PALETTE_RECOLOUR_START + this->result, rtl ? right - 16 : left + 16, top + 7); + DrawString(rtl ? left + 2 : left + 32, rtl ? right - 32 : right - 2, top + max(0, 13 - FONT_HEIGHT_NORMAL), this->String(), sel ? TC_WHITE : TC_BLACK); } }; @@ -552,7 +553,7 @@ enum SelectCompanyLiveryWindowWidgets { /** Company livery colour scheme window. */ struct SelectCompanyLiveryWindow : public Window { private: - static const int TEXT_INDENT = 15; ///< Number of pixels to indent the text in each column in the #SCLW_WIDGET_MATRIX to make room for the (coloured) rectangles. + static const uint TEXT_INDENT = 15; ///< Number of pixels to indent the text in each column in the #SCLW_WIDGET_MATRIX to make room for the (coloured) rectangles. uint32 sel; LiveryClass livery_class; @@ -661,6 +662,8 @@ public: { if (widget != SCLW_WIDGET_MATRIX) return; + bool rtl = _dynlang.text_dir == TD_RTL; + /* Horizontal coordinates of scheme name column. */ const NWidgetBase *nwi = this->GetWidget(SCLW_WIDGET_SPACER_DROPDOWN); int sch_left = nwi->pos_x; @@ -674,6 +677,9 @@ public: int sec_left = nwi->pos_x; int sec_right = sec_left + nwi->current_x - 1; + int text_left = (rtl ? (uint)WD_FRAMERECT_LEFT : TEXT_INDENT); + int text_right = (rtl ? TEXT_INDENT : (uint)WD_FRAMERECT_RIGHT); + int y = r.top + 3; const Company *c = Company::Get((CompanyID)this->window_number); for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) { @@ -682,18 +688,18 @@ public: /* Optional check box + scheme name. */ if (scheme != LS_DEFAULT) { - DrawSprite(c->livery[scheme].in_use ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, sch_left + WD_FRAMERECT_LEFT, y); + DrawSprite(c->livery[scheme].in_use ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, (rtl ? sch_right - TEXT_INDENT + WD_FRAMERECT_RIGHT : sch_left) + WD_FRAMERECT_LEFT, y); } - DrawString(sch_left + TEXT_INDENT, sch_right - WD_FRAMERECT_RIGHT, y, STR_LIVERY_DEFAULT + scheme, sel ? TC_WHITE : TC_BLACK); + DrawString(sch_left + text_left, sch_right - text_right, y, STR_LIVERY_DEFAULT + scheme, sel ? TC_WHITE : TC_BLACK); /* Text below the first dropdown. */ - DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(c->livery[scheme].colour1), pri_left + WD_FRAMERECT_LEFT, y); - DrawString(pri_left + TEXT_INDENT, pri_right - WD_FRAMERECT_RIGHT, y, STR_COLOUR_DARK_BLUE + c->livery[scheme].colour1, sel ? TC_WHITE : TC_GOLD); + DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(c->livery[scheme].colour1), (rtl ? pri_right - TEXT_INDENT + WD_FRAMERECT_RIGHT : pri_left) + WD_FRAMERECT_LEFT, y); + DrawString(pri_left + text_left, pri_right - text_right, y, STR_COLOUR_DARK_BLUE + c->livery[scheme].colour1, sel ? TC_WHITE : TC_GOLD); /* Text below the second dropdown. */ if (sec_right > sec_left) { // Second dropdown has non-zero size. - DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(c->livery[scheme].colour2), sec_left + WD_FRAMERECT_LEFT, y); - DrawString(sec_left + TEXT_INDENT, sec_right - WD_FRAMERECT_RIGHT, y, STR_COLOUR_DARK_BLUE + c->livery[scheme].colour2, sel ? TC_WHITE : TC_GOLD); + DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(c->livery[scheme].colour2), (rtl ? sec_right - TEXT_INDENT + WD_FRAMERECT_RIGHT : sec_left) + WD_FRAMERECT_LEFT, y); + DrawString(sec_left + text_left, sec_right - text_right, y, STR_COLOUR_DARK_BLUE + c->livery[scheme].colour2, sel ? TC_WHITE : TC_GOLD); } y += 4 + FONT_HEIGHT_NORMAL; @@ -735,7 +741,8 @@ public: break; case SCLW_WIDGET_MATRIX: { - LiveryScheme j = (LiveryScheme)((pt.y - this->GetWidget(SCLW_WIDGET_MATRIX)->pos_y) / (4 + FONT_HEIGHT_NORMAL)); + const NWidgetBase *wid = this->GetWidget(SCLW_WIDGET_MATRIX); + LiveryScheme j = (LiveryScheme)((pt.y - wid->pos_y) / (4 + FONT_HEIGHT_NORMAL)); for (LiveryScheme scheme = LS_BEGIN; scheme <= j; scheme++) { if (_livery_class[scheme] != this->livery_class) j++; @@ -744,7 +751,7 @@ public: if (j >= LS_END) return; /* If clicking on the left edge, toggle using the livery */ - if (pt.x < 10) { + if (_dynlang.text_dir == TD_RTL ? pt.x - wid->pos_x > wid->current_x - TEXT_INDENT : pt.x - wid->pos_x < TEXT_INDENT) { DoCommandP(0, j | (2 << 8), !Company::Get((CompanyID)this->window_number)->livery[j].in_use, CMD_SET_COMPANY_COLOUR); } -- cgit v1.2.3-70-g09d2