Files
@ r25013:4c02a1340d93
Branch filter:
Location: cpp/openttd-patchpack/source/src/widgets/dropdown_type.h - annotation
r25013:4c02a1340d93
3.8 KiB
text/x-c
Codechange: don't set the window position when changing blitter
There really is no need to make an extra call to the OS in
these cases.
There really is no need to make an extra call to the OS in
these cases.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r9111:983de9c5a848 r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r14248:a9050881acd7 r21009:09fb379ed85b r17536:874389c26a49 r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8290:b32f411ab7cc r8290:b32f411ab7cc r9859:8c15dba58099 r9859:8c15dba58099 r11511:a8b6e0c60152 r9868:7ffba1f0658a r23441:2965f5a62eaa r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8290:b32f411ab7cc r8284:d769847bf11d r23498:fcdedd342b36 r23498:fcdedd342b36 r23498:fcdedd342b36 r9859:8c15dba58099 r17537:af2bdb4ae259 r23606:675adf28a8f7 r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r8290:b32f411ab7cc r8285:e82ce65cfaa6 r23498:fcdedd342b36 r23498:fcdedd342b36 r8284:d769847bf11d r8284:d769847bf11d r8284:d769847bf11d r11047:addbbfc68d6f r11047:addbbfc68d6f r17536:874389c26a49 r11047:addbbfc68d6f r24217:df2f5854f1e3 r11047:addbbfc68d6f r24217:df2f5854f1e3 r11047:addbbfc68d6f r23498:fcdedd342b36 r11047:addbbfc68d6f r11047:addbbfc68d6f r11047:addbbfc68d6f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23597:6ae8b7b72e2e r23597:6ae8b7b72e2e r23597:6ae8b7b72e2e r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r23444:b4ced115dd3f r8284:d769847bf11d r8284:d769847bf11d r23601:0de2754ecd7e r8284:d769847bf11d r23601:0de2754ecd7e r19391:4991ef1b399a r23601:0de2754ecd7e r8284:d769847bf11d r8284:d769847bf11d | /*
* 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/>.
*/
/** @file dropdown_type.h Types related to the drop down widget. */
#ifndef WIDGETS_DROPDOWN_TYPE_H
#define WIDGETS_DROPDOWN_TYPE_H
#include "../window_type.h"
#include "../gfx_func.h"
#include "../core/smallvec_type.hpp"
#include "table/strings.h"
/**
* 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
DropDownListItem(int result, bool masked) : result(result), masked(masked) {}
virtual ~DropDownListItem() {}
virtual bool Selectable() const { return false; }
virtual uint Height(uint width) const { return FONT_HEIGHT_NORMAL; }
virtual uint Width() const { return 0; }
virtual void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const;
};
/**
* Common string list item.
*/
class DropDownListStringItem : public DropDownListItem {
public:
StringID string; ///< String ID of item
DropDownListStringItem(StringID string, int result, bool masked) : DropDownListItem(result, masked), string(string) {}
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;
virtual StringID String() const { return this->string; }
static bool NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second);
};
/**
* String list item with parameters.
*/
class DropDownListParamStringItem : public DropDownListStringItem {
public:
uint64 decode_params[10]; ///< Parameters of the string
DropDownListParamStringItem(StringID string, int result, bool masked) : DropDownListStringItem(string, result, masked) {}
StringID String() const override;
void SetParam(uint index, uint64 value) { decode_params[index] = value; }
};
/**
* List item containing a C char string.
*/
class DropDownListCharStringItem : public DropDownListStringItem {
public:
std::string raw_string;
DropDownListCharStringItem(const std::string &raw_string, int result, bool masked) : DropDownListStringItem(STR_JUST_RAW_STRING, result, masked), raw_string(raw_string) {}
StringID String() const override;
};
/**
* List item with icon and string.
*/
class DropDownListIconItem : public DropDownListParamStringItem {
SpriteID sprite;
PaletteID pal;
Dimension dim;
uint sprite_y;
uint text_y;
public:
DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked);
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;
void SetDimension(Dimension d);
};
/**
* A drop down list is a collection of drop down list items.
*/
typedef std::vector<std::unique_ptr<const DropDownListItem>> DropDownList;
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 */
|