(svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.

This commit is contained in:
alberth 2010-05-16 18:52:11 +00:00
parent 3271362413
commit 219ae56f8a

View File

@ -623,27 +623,12 @@ struct NewGRFWindow : public Window {
this->DrawWidgets(); this->DrawWidgets();
} }
virtual void DrawWidget(const Rect &r, int widget) const /** Pick the palette for the sprite of the grf to display.
* @param c grf to display.
* @return Palette for the sprite.
*/
FORCEINLINE PaletteID GetPalette(const GRFConfig *c) const
{ {
switch (widget) {
case SNGRFS_FILE_LIST: {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0xD7);
uint step_height = this->GetWidget<NWidgetBase>(SNGRFS_FILE_LIST)->resize_y;
uint y = r.top + WD_FRAMERECT_TOP;
int sprite_offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
bool rtl = _dynlang.text_dir == TD_RTL;
uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + 25;
uint text_right = rtl ? r.right - 25 : r.right - WD_FRAMERECT_RIGHT;
uint square_left = rtl ? r.right - 15 : r.left + 5;
uint warning_left = rtl ? r.right - 30 : r.left + 20;
int i = 0;
for (const GRFConfig *c = this->actives; c != NULL; c = c->next, i++) {
if (this->vscroll.IsVisible(i)) {
const char *text = c->GetName();
bool h = (this->active_sel == c);
PaletteID pal; PaletteID pal;
/* Pick a colour */ /* Pick a colour */
@ -669,6 +654,32 @@ struct NewGRFWindow : public Window {
} }
} }
return pal;
}
virtual void DrawWidget(const Rect &r, int widget) const
{
switch (widget) {
case SNGRFS_FILE_LIST: {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0xD7);
uint step_height = this->GetWidget<NWidgetBase>(SNGRFS_FILE_LIST)->resize_y;
uint y = r.top + WD_FRAMERECT_TOP;
int sprite_offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
bool rtl = _dynlang.text_dir == TD_RTL;
uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + 25;
uint text_right = rtl ? r.right - 25 : r.right - WD_FRAMERECT_RIGHT;
uint square_left = rtl ? r.right - 15 : r.left + 5;
uint warning_left = rtl ? r.right - 30 : r.left + 20;
int i = 0;
for (const GRFConfig *c = this->actives; c != NULL; c = c->next, i++) {
if (this->vscroll.IsVisible(i)) {
const char *text = c->GetName();
bool h = (this->active_sel == c);
PaletteID pal = this->GetPalette(c);
if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, 156); if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, 156);
DrawSprite(SPR_SQUARE, pal, square_left, y + sprite_offset_y); DrawSprite(SPR_SQUARE, pal, square_left, y + sprite_offset_y);
if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, y + sprite_offset_y); if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, y + sprite_offset_y);