summaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-08-06 07:10:40 +0000
committerpeter1138 <peter1138@openttd.org>2008-08-06 07:10:40 +0000
commit76b0ffd342c50798d27e85dcdf9a1e573defb8f0 (patch)
tree4eb36d7e879c9f32d78be743b8b4b3e7a274638e /src/widgets
parent6532897b5ae411c716cfd81586c2a662f2ad1ac0 (diff)
downloadopenttd-76b0ffd342c50798d27e85dcdf9a1e573defb8f0.tar.xz
(svn r14004) -Codechange: Clean of drop down lists.
Move empty item drawing to base ListItem Draw() function. Remove String() from base class. Pass correct width to Draw().
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dropdown.cpp48
-rw-r--r--src/widgets/dropdown_type.h15
2 files changed, 26 insertions, 37 deletions
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp
index ecdba6a64..41975a59f 100644
--- a/src/widgets/dropdown.cpp
+++ b/src/widgets/dropdown.cpp
@@ -17,19 +17,18 @@
#include "../table/sprites.h"
#include "table/strings.h"
-StringID DropDownListItem::String() const
+void DropDownListItem::Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const
{
- return STR_NULL;
-}
+ int c1 = _colour_gradient[bg_colour][3];
+ int c2 = _colour_gradient[bg_colour][7];
-uint DropDownListItem::Height(uint width) const
-{
- return 10;
+ GfxFillRect(x + 1, y + 3, x + width - 2, y + 3, c1);
+ GfxFillRect(x + 1, y + 4, x + width - 2, y + 4, c2);
}
-StringID DropDownListStringItem::String() const
+void DropDownListStringItem::Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const
{
- return this->string;
+ DrawStringTruncated(x + 2, y, this->String(), sel ? TC_WHITE : TC_BLACK, width);
}
StringID DropDownListParamStringItem::String() const
@@ -38,11 +37,6 @@ StringID DropDownListParamStringItem::String() const
return this->string;
}
-void DropDownListItem::Draw(int x, int y, uint width, uint height, bool sel) const
-{
- DrawStringTruncated(x + 2, y, this->String(), sel ? TC_WHITE : TC_BLACK, x + width);
-}
-
/**
* Delete all items of a drop down list and the list itself
* @param list List to delete.
@@ -106,7 +100,7 @@ struct DropdownWindow : Window {
int item_height = item->Height(width);
if (y < item_height) {
- if (item->masked || item->String() == STR_NULL) return false;
+ if (item->masked || !item->Selectable()) return false;
value = item->result;
return true;
}
@@ -125,7 +119,7 @@ struct DropdownWindow : Window {
int y = 2;
int sel = this->selected_index;
- int width = this->widget[0].right - 3;
+ int width = this->widget[0].right - 2;
int height = this->widget[0].bottom;
int pos = this->vscroll.pos;
@@ -139,22 +133,14 @@ struct DropdownWindow : Window {
if (--pos >= 0) continue;
if (y + item_height < height) {
- if (item->String() != STR_NULL) {
- if (sel == item->result) GfxFillRect(x + 1, y, x + width, y + item_height - 1, 0);
-
- item->Draw(x, y, width, 10, sel == item->result);
-
- if (item->masked) {
- GfxFillRect(x, y, x + width, y + item_height - 1,
- _colour_gradient[this->widget[0].color][5], FILLRECT_CHECKER
- );
- }
- } else {
- int c1 = _colour_gradient[this->widget[0].color][3];
- int c2 = _colour_gradient[this->widget[0].color][7];
-
- GfxFillRect(x + 1, y + 3, x + this->width - 5, y + 3, c1);
- GfxFillRect(x + 1, y + 4, x + this->width - 5, y + 4, c2);
+ if (sel == item->result) GfxFillRect(x + 1, y, x + width - 1, y + item_height - 1, 0);
+
+ item->Draw(x, y, width, height, sel == item->result, (TextColour)this->widget[0].color);
+
+ if (item->masked) {
+ GfxFillRect(x, y, x + width - 1, y + item_height - 1,
+ _colour_gradient[this->widget[0].color][5], FILLRECT_CHECKER
+ );
}
}
y += item_height;
diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h
index 3cdb48f87..aa4baafe1 100644
--- a/src/widgets/dropdown_type.h
+++ b/src/widgets/dropdown_type.h
@@ -19,9 +19,10 @@ public:
DropDownListItem(int result, bool masked) : result(result), masked(masked) {}
virtual ~DropDownListItem() {}
- virtual StringID String() const;
- virtual uint Height(uint width) const;
- virtual void Draw(int x, int y, uint width, uint height, bool sel) const;
+
+ virtual bool Selectable() const { return false; }
+ virtual uint Height(uint width) const { return 10; }
+ virtual void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const;
};
/**
@@ -34,7 +35,9 @@ public:
DropDownListStringItem(StringID string, int result, bool masked) : DropDownListItem(result, masked), string(string) {}
virtual ~DropDownListStringItem() {}
- StringID String() const;
+ virtual bool Selectable() const { return true; }
+ virtual void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const;
+ virtual StringID String() const { return this->string; }
};
/**
@@ -47,8 +50,8 @@ public:
DropDownListParamStringItem(StringID string, int result, bool masked) : DropDownListStringItem(string, result, masked) {}
virtual ~DropDownListParamStringItem() {}
- StringID String() const;
- void SetParam(uint index, uint64 value) { decode_params[index] = value; }
+ virtual StringID String() const;
+ virtual void SetParam(uint index, uint64 value) { decode_params[index] = value; }
};
/**