summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-06-01 10:43:50 +0000
committerfrosch <frosch@openttd.org>2012-06-01 10:43:50 +0000
commit88fff21b932eca52599d66239cc05dc97f5a998e (patch)
tree581ba716af2c29f949088265218de8ec6b330631
parent6207a6017f55729aa3fe365e00c1a4940a917c06 (diff)
downloadopenttd-88fff21b932eca52599d66239cc05dc97f5a998e.tar.xz
(svn r24308) -Add: ShowDropDownListAt() for drawing dropdown windows independent of dropdown widgets.
-rw-r--r--src/widgets/dropdown.cpp80
-rw-r--r--src/widgets/dropdown_type.h15
2 files changed, 62 insertions, 33 deletions
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp
index 45420b0ba..dd2349965 100644
--- a/src/widgets/dropdown.cpp
+++ b/src/widgets/dropdown.cpp
@@ -328,32 +328,29 @@ struct DropdownWindow : Window {
}
};
-void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
+/**
+ * Show a drop down list.
+ * @param w Parent window for the list.
+ * @param list Prepopulated DropDownList. Will be deleted when the list is
+ * closed.
+ * @param selected The initially selected list item.
+ * @param button The widget which is passed to Window::OnDropdownSelect and OnDropdownClose.
+ * Unless you override those functions, this should be then widget index of the dropdown button.
+ * @param wi_rect Coord of the parent drop down button, used to position the dropdown menu.
+ * @param auto_width The width is determined by the widest item in the list,
+ * in this case only one of \a left or \a right is used (depending on text direction).
+ * @param instant_close Set to true if releasing mouse button should close the
+ * list regardless of where the cursor is.
+ */
+void ShowDropDownListAt(Window *w, DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
{
DeleteWindowById(WC_DROPDOWN_MENU, 0);
- /* Our parent's button widget is used to determine where to place the drop
- * down list window. */
- Rect wi_rect;
- Colours wi_colour;
- NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
- wi_rect.left = nwi->pos_x;
- wi_rect.right = nwi->pos_x + nwi->current_x - 1;
- wi_rect.top = nwi->pos_y;
- wi_rect.bottom = nwi->pos_y + nwi->current_y - 1;
- wi_colour = nwi->colour;
-
- if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
- nwi->disp_flags |= ND_DROPDOWN_ACTIVE;
- } else {
- w->LowerWidget(button);
- }
- w->SetWidgetDirty(button);
-
/* The preferred position is just below the dropdown calling widget */
int top = w->top + wi_rect.bottom + 1;
- if (width == 0) width = wi_rect.right - wi_rect.left + 1;
+ /* The preferred width equals the calling widget */
+ uint width = wi_rect.right - wi_rect.left + 1;
uint max_item_width = 0;
@@ -406,6 +403,49 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u
}
/**
+ * Show a drop down list.
+ * @param w Parent window for the list.
+ * @param list Prepopulated DropDownList. Will be deleted when the list is
+ * closed.
+ * @param selected The initially selected list item.
+ * @param button The widget within the parent window that is used to determine
+ * the list's location.
+ * @param width Override the width determined by the selected widget.
+ * @param auto_width Maximum width is determined by the widest item in the list.
+ * @param instant_close Set to true if releasing mouse button should close the
+ * list regardless of where the cursor is.
+ */
+void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
+{
+ /* Our parent's button widget is used to determine where to place the drop
+ * down list window. */
+ Rect wi_rect;
+ NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
+ wi_rect.left = nwi->pos_x;
+ wi_rect.right = nwi->pos_x + nwi->current_x - 1;
+ wi_rect.top = nwi->pos_y;
+ wi_rect.bottom = nwi->pos_y + nwi->current_y - 1;
+ Colours wi_colour = nwi->colour;
+
+ if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
+ nwi->disp_flags |= ND_DROPDOWN_ACTIVE;
+ } else {
+ w->LowerWidget(button);
+ }
+ w->SetWidgetDirty(button);
+
+ if (width != 0) {
+ if (_current_text_dir == TD_RTL) {
+ wi_rect.left = wi_rect.right + 1 - width;
+ } else {
+ wi_rect.right = wi_rect.left + width - 1;
+ }
+ }
+
+ ShowDropDownListAt(w, list, selected, button, wi_rect, wi_colour, auto_width, instant_close);
+}
+
+/**
* Show a dropdown menu window near a widget of the parent window.
* The result code of the items is their index in the \a strings list.
* @param w Parent window that wants the dropdown menu.
diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h
index 6edc5b847..b923445bb 100644
--- a/src/widgets/dropdown_type.h
+++ b/src/widgets/dropdown_type.h
@@ -85,19 +85,8 @@ public:
*/
typedef std::list<DropDownListItem *> DropDownList;
-/**
- * Show a drop down list.
- * @param w Parent window for the list.
- * @param list Prepopulated DropDownList. Will be deleted when the list is
- * closed.
- * @param selected The initially selected list item.
- * @param button The widget within the parent window that is used to determine
- * the list's location.
- * @param width Override the width determined by the selected widget.
- * @param auto_width Maximum width is determined by the widest item in the list.
- * @param instant_close Set to true if releasing mouse button should close the
- * list regardless of where the cursor is.
- */
+void ShowDropDownListAt(Window *w, DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width = false, bool instant_close = false);
+
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false);
#endif /* WIDGETS_DROPDOWN_TYPE_H */