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"
|
2013-11-24 15:46:26 +01:00
|
|
|
#include "../core/smallvec_type.hpp"
|
2011-04-10 16:56:14 +02:00
|
|
|
#include "table/strings.h"
|
2008-01-14 17:10:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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; }
|
2019-03-09 19:20:03 +01:00
|
|
|
virtual void Draw(int left, int right, int top, int bottom, bool sel, Colours 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-14 17:10:58 +01:00
|
|
|
|
2019-03-04 08:28:52 +01:00
|
|
|
bool Selectable() const override { return true; }
|
|
|
|
uint Width() const override;
|
|
|
|
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override;
|
2008-08-06 09:10:40 +02:00
|
|
|
virtual StringID String() const { return this->string; }
|
2011-04-10 17:01:14 +02:00
|
|
|
|
2019-04-10 20:55:53 +02:00
|
|
|
static bool NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second);
|
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-14 17:35:49 +01:00
|
|
|
|
2019-03-04 08:28:52 +01:00
|
|
|
StringID String() const override;
|
|
|
|
void SetParam(uint index, uint64 value) { decode_params[index] = value; }
|
2021-03-09 10:58:33 +01:00
|
|
|
void SetParamStr(uint index, const char *str) { this->SetParam(index, (uint64)(size_t)str); }
|
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:
|
2020-05-17 23:32:06 +02:00
|
|
|
std::string raw_string;
|
2009-02-07 01:37:35 +01:00
|
|
|
|
2020-05-17 23:32:06 +02:00
|
|
|
DropDownListCharStringItem(const std::string &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
|
|
|
|
2019-03-04 08:28:52 +01:00
|
|
|
StringID String() const override;
|
2009-02-07 01:37:35 +01:00
|
|
|
};
|
|
|
|
|
2019-03-10 03:10:40 +01:00
|
|
|
/**
|
|
|
|
* List item with icon and string.
|
|
|
|
*/
|
|
|
|
class DropDownListIconItem : public DropDownListParamStringItem {
|
|
|
|
SpriteID sprite;
|
|
|
|
PaletteID pal;
|
|
|
|
Dimension dim;
|
|
|
|
uint sprite_y;
|
|
|
|
public:
|
|
|
|
DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked);
|
|
|
|
|
2019-04-02 21:30:44 +02:00
|
|
|
uint Height(uint width) const override;
|
|
|
|
uint Width() const override;
|
|
|
|
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override;
|
2019-03-10 03:10:40 +01:00
|
|
|
void SetDimension(Dimension d);
|
|
|
|
};
|
|
|
|
|
2008-01-14 17:10:58 +01:00
|
|
|
/**
|
|
|
|
* A drop down list is a collection of drop down list items.
|
|
|
|
*/
|
2019-04-02 21:31:24 +02:00
|
|
|
typedef std::vector<std::unique_ptr<const DropDownListItem>> DropDownList;
|
2008-01-14 17:10:58 +01:00
|
|
|
|
2019-04-02 21:31:24 +02:00
|
|
|
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width = false, bool instant_close = false);
|
2012-06-01 12:43:50 +02:00
|
|
|
|
2019-04-02 21:31:24 +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 */
|