2008-01-14 17:10:58 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file dropdown_type.h Types related to the drop down widget. */
|
|
|
|
|
2008-01-14 17:10:58 +01:00
|
|
|
#ifndef WIDGETS_DROPDOWN_TYPE_H
|
|
|
|
#define WIDGETS_DROPDOWN_TYPE_H
|
|
|
|
|
|
|
|
#include "../window_type.h"
|
2010-01-15 17:41:15 +01:00
|
|
|
#include "../gfx_func.h"
|
2011-04-10 16:56:14 +02:00
|
|
|
#include "table/strings.h"
|
2008-01-14 17:10:58 +01:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base list item class from which others are derived. If placed in a list it
|
|
|
|
* will appear as a horizontal line in the menu.
|
|
|
|
*/
|
|
|
|
class DropDownListItem {
|
|
|
|
public:
|
|
|
|
int result; ///< Result code to return to window on selection
|
|
|
|
bool masked; ///< Masked and unselectable item
|
|
|
|
|
2008-01-14 21:52:43 +01:00
|
|
|
DropDownListItem(int result, bool masked) : result(result), masked(masked) {}
|
|
|
|
virtual ~DropDownListItem() {}
|
2008-08-06 09:10:40 +02:00
|
|
|
|
|
|
|
virtual bool Selectable() const { return false; }
|
2009-03-28 13:47:29 +01:00
|
|
|
virtual uint Height(uint width) const { return FONT_HEIGHT_NORMAL; }
|
2008-08-07 20:11:09 +02:00
|
|
|
virtual uint Width() const { return 0; }
|
2009-03-21 20:31:47 +01:00
|
|
|
virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const;
|
2008-01-14 17:10:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common string list item.
|
|
|
|
*/
|
|
|
|
class DropDownListStringItem : public DropDownListItem {
|
|
|
|
public:
|
|
|
|
StringID string; ///< String ID of item
|
|
|
|
|
2008-01-14 21:52:43 +01:00
|
|
|
DropDownListStringItem(StringID string, int result, bool masked) : DropDownListItem(result, masked), string(string) {}
|
2008-01-15 01:48:14 +01:00
|
|
|
virtual ~DropDownListStringItem() {}
|
2008-01-14 17:10:58 +01:00
|
|
|
|
2008-08-06 09:10:40 +02:00
|
|
|
virtual bool Selectable() const { return true; }
|
2008-08-07 20:11:09 +02:00
|
|
|
virtual uint Width() const;
|
2009-03-21 20:31:47 +01:00
|
|
|
virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const;
|
2008-08-06 09:10:40 +02:00
|
|
|
virtual StringID String() const { return this->string; }
|
2008-01-14 17:10:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* String list item with parameters.
|
|
|
|
*/
|
|
|
|
class DropDownListParamStringItem : public DropDownListStringItem {
|
|
|
|
public:
|
|
|
|
uint64 decode_params[10]; ///< Parameters of the string
|
|
|
|
|
2008-01-14 21:52:43 +01:00
|
|
|
DropDownListParamStringItem(StringID string, int result, bool masked) : DropDownListStringItem(string, result, masked) {}
|
2008-01-15 01:48:14 +01:00
|
|
|
virtual ~DropDownListParamStringItem() {}
|
2008-01-14 17:35:49 +01:00
|
|
|
|
2008-08-06 09:10:40 +02:00
|
|
|
virtual StringID String() const;
|
|
|
|
virtual void SetParam(uint index, uint64 value) { decode_params[index] = value; }
|
2008-01-14 17:10:58 +01:00
|
|
|
};
|
|
|
|
|
2009-02-07 01:37:35 +01:00
|
|
|
/**
|
|
|
|
* List item containing a C char string.
|
|
|
|
*/
|
2011-04-10 16:56:14 +02:00
|
|
|
class DropDownListCharStringItem : public DropDownListStringItem {
|
2009-02-07 01:37:35 +01:00
|
|
|
public:
|
2011-04-10 16:56:14 +02:00
|
|
|
const char *raw_string;
|
2009-02-07 01:37:35 +01:00
|
|
|
|
2011-04-10 16:56:14 +02:00
|
|
|
DropDownListCharStringItem(const char *raw_string, int result, bool masked) : DropDownListStringItem(STR_JUST_RAW_STRING, result, masked), raw_string(raw_string) {}
|
2009-02-07 01:37:35 +01:00
|
|
|
virtual ~DropDownListCharStringItem() {}
|
|
|
|
|
2011-04-10 16:56:14 +02:00
|
|
|
virtual StringID String() const;
|
2009-02-07 01:37:35 +01:00
|
|
|
};
|
|
|
|
|
2008-01-14 17:10:58 +01:00
|
|
|
/**
|
|
|
|
* A drop down list is a collection of drop down list items.
|
|
|
|
*/
|
|
|
|
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.
|
2008-04-10 01:00:12 +02:00
|
|
|
* @param width Override the width determined by the selected widget.
|
2008-08-25 18:07:10 +02:00
|
|
|
* @param auto_width Maximum width is determined by the widest item in the list.
|
2008-08-07 20:26:13 +02:00
|
|
|
* @param instant_close Set to true if releasing mouse button should close the
|
|
|
|
* list regardless of where the cursor is.
|
2008-01-14 17:10:58 +01:00
|
|
|
*/
|
2008-08-25 18:07:10 +02:00
|
|
|
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false);
|
2008-01-14 17:10:58 +01:00
|
|
|
|
|
|
|
#endif /* WIDGETS_DROPDOWN_TYPE_H */
|