|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
10 #ifndef WIDGETS_DROPDOWN_TYPE_H
11 #define WIDGETS_DROPDOWN_TYPE_H
13 #include "../window_type.h"
14 #include "../gfx_func.h"
15 #include "../gfx_type.h"
16 #include "../palette_func.h"
17 #include "../string_func.h"
18 #include "../strings_func.h"
19 #include "../table/strings.h"
20 #include "../window_gui.h"
34 virtual bool Selectable()
const {
return true; }
35 virtual uint
Height()
const {
return 0; }
36 virtual uint Width()
const {
return 0; }
38 virtual void Draw(
const Rect &full,
const Rect &,
bool, Colours bg_colour)
const
45 if (this->shaded)
return (sel ? TC_SILVER : TC_GREY) |
TC_NO_SHADE;
46 return sel ? TC_WHITE : TC_BLACK;
55 template<
class TBase, FontSize TFs = FS_NORMAL>
58 template <
typename... Args>
59 explicit DropDownDivider(Args&&... args) : TBase(std::forward<Args>(args)...) {}
61 bool Selectable()
const override {
return false; }
64 void Draw(
const Rect &full,
const Rect &,
bool, Colours bg_colour)
const override
81 template<
class TBase, FontSize TFs = FS_NORMAL,
bool TEnd = false>
86 template <
typename... Args>
92 template <
typename... Args>
93 explicit DropDownString(
const std::string &
string, Args&&... args) : TBase(std::forward<Args>(args)...)
96 this->SetString(
GetString(STR_JUST_RAW_STRING));
99 void SetString(std::string &&
string)
101 this->
string = std::move(
string);
105 uint
Height()
const override
107 return std::max<uint>(this->dim.height, this->TBase::Height());
110 uint Width()
const override {
return this->dim.width + this->TBase::Width(); }
112 void Draw(
const Rect &full,
const Rect &r,
bool sel, Colours bg_colour)
const override
116 this->TBase::Draw(full, r.
Indent(this->dim.width, rtl), sel, bg_colour);
126 static bool NatSortFunc(std::unique_ptr<const DropDownListItem>
const &first, std::unique_ptr<const DropDownListItem>
const &second)
128 const std::string &str1 =
static_cast<const DropDownString*
>(first.get())->
string;
129 const std::string &str2 =
static_cast<const DropDownString*
>(second.get())->
string;
139 template<
class TBase,
bool TEnd = false>
146 template <
typename... Args>
153 template <
typename... Args>
159 uint
Height()
const override {
return std::max(this->dbounds.height, this->TBase::Height()); }
162 void Draw(
const Rect &full,
const Rect &r,
bool sel, Colours bg_colour)
const override
177 template<
class TBase,
bool TEnd = false, FontSize TFs = FS_NORMAL>
182 template <
typename... Args>
188 uint
Height()
const override {
return std::max<uint>(this->dim.height, this->TBase::Height()); }
191 void Draw(
const Rect &full,
const Rect &r,
bool sel, Colours bg_colour)
const override
210 typedef std::vector<std::unique_ptr<const DropDownListItem>>
DropDownList;
Drop down divider component.
int result
Result value to return to window on selection.
int16_t Height
Fixed point type for heights.
Dimensions (a width and height) of a rectangle in 2D.
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close=false)
Show a drop down list.
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Base list item class from which others are derived.
uint32_t PaletteID
The number of the palette.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Drop down icon component.
Dimension dbounds
Bounding box dimensions of bounds.
bool shaded
Shaded item, affects text colour.
SpriteID sprite
Sprite ID to be drawn.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
@ TC_NO_SHADE
Do not add shading to this text colour.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
std::string string
String to be drawn.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Dimension dim
Dimensions of string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width=0, bool instant_close=false)
Show a drop down list.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
@ SA_CENTER
Center both horizontally and vertically.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Drop down checkmark component.
Data structure for an opened window.
Dimension dim
Dimension of checkmark.
Specification of a rectangle with absolute coordinates of all edges.
bool checked
Is item checked.
Drop down string component.
bool masked
Masked and unselectable item.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
PaletteID palette
Palette ID to use.
Dimension dsprite
Bounding box dimensions of sprite.