mirror of https://github.com/OpenTTD/OpenTTD
(svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
parent
eb112946a7
commit
9fa2e849f2
|
@ -87,9 +87,9 @@ struct DropdownWindow : Window {
|
||||||
DeleteDropDownList(this->list);
|
DeleteDropDownList(this->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetDropDownItem()
|
bool GetDropDownItem(int &value)
|
||||||
{
|
{
|
||||||
if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return -1;
|
if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
|
||||||
|
|
||||||
int y = _cursor.pos.y - this->top - 2;
|
int y = _cursor.pos.y - this->top - 2;
|
||||||
int width = this->widget[0].right - 3;
|
int width = this->widget[0].right - 3;
|
||||||
|
@ -105,14 +105,15 @@ struct DropdownWindow : Window {
|
||||||
int item_height = item->Height(width);
|
int item_height = item->Height(width);
|
||||||
|
|
||||||
if (y < item_height) {
|
if (y < item_height) {
|
||||||
if (item->masked || item->String() == STR_NULL) return -1;
|
if (item->masked || item->String() == STR_NULL) return false;
|
||||||
return item->result;
|
value = item->result;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
y -= item_height;
|
y -= item_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnPaint()
|
virtual void OnPaint()
|
||||||
|
@ -162,8 +163,8 @@ struct DropdownWindow : Window {
|
||||||
virtual void OnClick(Point pt, int widget)
|
virtual void OnClick(Point pt, int widget)
|
||||||
{
|
{
|
||||||
if (widget != 0) return;
|
if (widget != 0) return;
|
||||||
int item = GetDropDownItem();
|
int item;
|
||||||
if (item >= 0) {
|
if (this->GetDropDownItem(item)) {
|
||||||
this->click_delay = 4;
|
this->click_delay = 4;
|
||||||
this->selected_index = item;
|
this->selected_index = item;
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
|
@ -197,11 +198,11 @@ struct DropdownWindow : Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->drag_mode) {
|
if (this->drag_mode) {
|
||||||
int item = GetDropDownItem();
|
int item;
|
||||||
|
|
||||||
if (!_left_button_clicked) {
|
if (!_left_button_clicked) {
|
||||||
this->drag_mode = false;
|
this->drag_mode = false;
|
||||||
if (item < 0) return;
|
if (!this->GetDropDownItem(item)) return;
|
||||||
this->click_delay = 2;
|
this->click_delay = 2;
|
||||||
} else {
|
} else {
|
||||||
if (_cursor.pos.y <= this->top + 2) {
|
if (_cursor.pos.y <= this->top + 2) {
|
||||||
|
@ -214,7 +215,7 @@ struct DropdownWindow : Window {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item < 0) return;
|
if (!this->GetDropDownItem(item)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->selected_index = item;
|
this->selected_index = item;
|
||||||
|
|
Loading…
Reference in New Issue