(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.

This commit is contained in:
rubidium 2009-03-21 19:31:47 +00:00
parent 8a758beec3
commit 93fe44a3c5
6 changed files with 27 additions and 26 deletions

View File

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

View File

@ -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 = '.';

View File

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

View File

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

View File

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

View File

@ -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;
};
/**