#include "stdafx.h"
#include "openttd.h"
#include "company_func.h"
#include "window_gui.h"
#include "viewport_func.h"
#include "zoom_func.h"
#include "strings_func.h"
#include "transparency.h"
#include "table/sprites.h"
#include "table/strings.h"
Go to the source code of this file.
Functions | |
static Point | HandleScrollbarHittest (const Scrollbar *sb, int top, int bottom, bool horizontal) |
Compute the vertical position of the draggable part of scrollbar. | |
static void | ScrollbarClickPositioning (Window *w, WidgetType wtp, int x, int y, int mi, int ma) |
Compute new position of the scrollbar after a click and updates the window flags. | |
void | ScrollbarClickHandler (Window *w, const NWidgetCore *nw, int x, int y) |
Special handling for the scrollbar widget type. | |
int | GetWidgetFromPos (const Window *w, int x, int y) |
Returns the index for the widget located at the given position relative to the window. | |
void | DrawFrameRect (int left, int top, int right, int bottom, Colours colour, FrameFlags flags) |
Draw frame rectangle. | |
static void | DrawImageButtons (const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img) |
Draw an image button. | |
static void | DrawLabel (const Rect &r, WidgetType type, bool clicked, StringID str) |
Draw the label-part of a widget. | |
static void | DrawText (const Rect &r, TextColour colour, StringID str) |
Draw text. | |
static void | DrawInset (const Rect &r, Colours colour, StringID str) |
Draw an inset widget. | |
static void | DrawMatrix (const Rect &r, Colours colour, bool clicked, uint16 data) |
Draw a matrix widget. | |
static void | DrawVerticalScrollbar (const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar) |
Draw a vertical scrollbar. | |
static void | DrawHorizontalScrollbar (const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar) |
Draw a horizontal scrollbar. | |
static void | DrawFrame (const Rect &r, Colours colour, StringID str) |
Draw a frame widget. | |
static void | DrawShadeBox (const Rect &r, Colours colour, bool clicked) |
Draw a shade box. | |
static void | DrawStickyBox (const Rect &r, Colours colour, bool clicked) |
Draw a sticky box. | |
static void | DrawResizeBox (const Rect &r, Colours colour, bool at_left, bool clicked) |
Draw a resize box. | |
static void | DrawCloseBox (const Rect &r, Colours colour, StringID str) |
Draw a close box. | |
static void | DrawCaption (const Rect &r, Colours colour, Owner owner, StringID str) |
Draw a caption bar. | |
static void | DrawButtonDropdown (const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str) |
Draw a button with a dropdown (WWT_DROPDOWN and NWID_BUTTON_DROPDOWN). | |
static void | DrawDropdown (const Rect &r, Colours colour, bool clicked, StringID str) |
Draw a dropdown WWT_DROPDOWN widget. | |
static uint | ComputeMaxSize (uint base, uint max_space, uint step) |
Return the biggest possible size of a nested widget. | |
static int | MakeNWidget (const NWidgetPart *parts, int count, NWidgetBase **dest, bool *fill_dest, int *biggest_index) |
Construct a single nested widget in *dest from its parts. | |
static int | MakeWidgetTree (const NWidgetPart *parts, int count, NWidgetBase **parent, int *biggest_index) |
Build a nested widget tree by recursively filling containers with nested widgets read from their parts. | |
NWidgetContainer * | MakeNWidgets (const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container) |
Construct a nested widget tree from an array of parts. | |
NWidgetContainer * | MakeWindowNWidgetTree (const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select) |
Make a nested widget tree for a window from a parts array. | |
Variables | |
static const char * | UPARROW = "\xEE\x8A\xA0" |
String containing an upwards pointing arrow. | |
static const char * | DOWNARROW = "\xEE\x8A\xAA" |
String containing a downwards pointing arrow. |
Definition in file widget.cpp.
static uint ComputeMaxSize | ( | uint | base, | |
uint | max_space, | |||
uint | step | |||
) | [inline, static] |
Return the biggest possible size of a nested widget.
base | Base size of the widget. | |
max_space | Available space for the widget. | |
step | Stepsize of the widget. |
Definition at line 938 of file widget.cpp.
Referenced by NWidgetVertical::AssignSizePosition(), NWidgetHorizontal::AssignSizePosition(), and NWidgetStacked::AssignSizePosition().
static void DrawButtonDropdown | ( | const Rect & | r, | |
Colours | colour, | |||
bool | clicked_button, | |||
bool | clicked_dropdown, | |||
StringID | str | |||
) | [inline, static] |
Draw a button with a dropdown (WWT_DROPDOWN and NWID_BUTTON_DROPDOWN).
r | Rectangle containing the widget. | |
colour | Background colour of the widget. | |
clicked_button | The button-part is lowered. | |
clicked_dropdown | The drop-down part is lowered. | |
str | Text of the button. |
Definition at line 538 of file widget.cpp.
References _dynlang, Rect::bottom, DOWNARROW, DrawFrameRect(), DrawString(), FR_LOWERED, Rect::left, Rect::right, SA_CENTER, TD_LTR, DynamicLanguages::text_dir, Rect::top, WD_DROPDOWNTEXT_LEFT, WD_DROPDOWNTEXT_RIGHT, and WD_DROPDOWNTEXT_TOP.
Referenced by NWidgetLeaf::Draw(), and DrawDropdown().
static void DrawCaption | ( | const Rect & | r, | |
Colours | colour, | |||
Owner | owner, | |||
StringID | str | |||
) | [inline, static] |
Draw a caption bar.
r | Rectangle of the bar. | |
colour | Colour of the window. | |
owner | 'Owner' of the window. | |
str | Text to draw in the bar. |
Definition at line 516 of file widget.cpp.
References _colour_gradient, _company_colours, Rect::bottom, DrawFrameRect(), DrawString(), FR_BORDERONLY, FR_DARKENED, FR_LOWERED, GfxFillRect(), INVALID_OWNER, Rect::left, Rect::right, SA_CENTER, Rect::top, WD_CAPTIONTEXT_LEFT, WD_CAPTIONTEXT_RIGHT, and WD_CAPTIONTEXT_TOP.
Referenced by NWidgetLeaf::Draw().
Draw a close box.
r | Rectangle of the box. | |
colour | Colour of the close box. | |
str | Cross to draw (STR_BLACK_CROSS or STR_SILVER_CROSS). |
Definition at line 502 of file widget.cpp.
References Rect::bottom, DrawFrameRect(), DrawString(), Rect::left, Rect::right, SA_CENTER, Rect::top, WD_CLOSEBOX_LEFT, WD_CLOSEBOX_RIGHT, and WD_CLOSEBOX_TOP.
Referenced by NWidgetLeaf::Draw().
static void DrawDropdown | ( | const Rect & | r, | |
Colours | colour, | |||
bool | clicked, | |||
StringID | str | |||
) | [inline, static] |
Draw a dropdown WWT_DROPDOWN widget.
r | Rectangle containing the widget. | |
colour | Background colour of the widget. | |
clicked | The widget is lowered. | |
str | Text of the button. |
Definition at line 560 of file widget.cpp.
References DrawButtonDropdown().
Referenced by NWidgetLeaf::Draw().
Draw a frame widget.
r | Rectangle of the frame. | |
colour | Colour of the frame. | |
str | Text of the frame. |
Definition at line 411 of file widget.cpp.
References _colour_gradient, _dynlang, Rect::bottom, DrawString(), FONT_HEIGHT_NORMAL, GfxFillRect(), Rect::left, Rect::right, TD_LTR, DynamicLanguages::text_dir, Rect::top, WD_FRAMETEXT_LEFT, and WD_FRAMETEXT_RIGHT.
Referenced by NWidgetBackground::Draw().
void DrawFrameRect | ( | int | left, | |
int | top, | |||
int | right, | |||
int | bottom, | |||
Colours | colour, | |||
FrameFlags | flags | |||
) |
Draw frame rectangle.
left | Left edge of the frame | |
top | Top edge of the frame | |
right | Right edge of the frame | |
bottom | Bottom edge of the frame | |
colour | Colour table to use. |
flags | Flags controlling how to draw the frame. |
Definition at line 200 of file widget.cpp.
References _colour_gradient, FILLRECT_RECOLOUR, FR_BORDERONLY, FR_DARKENED, FR_LOWERED, FR_TRANSPARENT, and GfxFillRect().
Referenced by NWidgetLeaf::Draw(), NWidgetBackground::Draw(), DrawAircraftImage(), DrawArrowButtons(), DrawButtonDropdown(), DrawCaption(), DrawCloseBox(), DrawHorizontalScrollbar(), DrawImageButtons(), DrawInset(), DrawMatrix(), DrawResizeBox(), DrawRoadVehImage(), SettingEntry::DrawSetting(), DrawShadeBox(), DrawShipImage(), DrawStickyBox(), DrawTrainImage(), DrawVerticalScrollbar(), AISettingsWindow::DrawWidget(), and Window::DrawWidgets().
static void DrawHorizontalScrollbar | ( | const Rect & | r, | |
Colours | colour, | |||
bool | left_clicked, | |||
bool | bar_dragged, | |||
bool | right_clicked, | |||
const Scrollbar * | scrollbar | |||
) | [inline, static] |
Draw a horizontal scrollbar.
r | Rectangle of the scrollbar widget. | |
colour | Colour of the scrollbar widget. | |
left_clicked | Left-arrow is clicked. | |
bar_dragged | Bar is dragged. | |
right_clicked | Right-arrow is clicked. | |
scrollbar | Scrollbar size, offset, and capacity information. |
Definition at line 379 of file widget.cpp.
References _colour_gradient, Rect::bottom, DrawFrameRect(), DrawSprite(), FILLRECT_CHECKER, FR_LOWERED, GfxFillRect(), HandleScrollbarHittest(), Rect::left, Rect::right, Rect::top, Point::x, and Point::y.
Referenced by NWidgetLeaf::Draw().
static void DrawImageButtons | ( | const Rect & | r, | |
WidgetType | type, | |||
Colours | colour, | |||
bool | clicked, | |||
SpriteID | img | |||
) | [inline, static] |
Draw an image button.
r | Rectangle of the button. | |
type | Widget type (WWT_IMGBTN or WWT_IMGBTN_2). | |
colour | Colour of the button. | |
clicked | Button is lowered. | |
img | Sprite to draw. |
Definition at line 239 of file widget.cpp.
References Rect::bottom, DrawFrameRect(), DrawSprite(), FR_LOWERED, Rect::left, Rect::right, Rect::top, WD_IMGBTN_LEFT, WD_IMGBTN_TOP, and WWT_IMGBTN_2.
Referenced by NWidgetLeaf::Draw().
Draw an inset widget.
r | Rectangle of the background. | |
colour | Colour of the inset. | |
str | Text to draw. |
Definition at line 283 of file widget.cpp.
References Rect::bottom, DrawFrameRect(), DrawString(), FR_DARKENED, FR_LOWERED, Rect::left, Rect::right, Rect::top, WD_INSET_LEFT, WD_INSET_RIGHT, and WD_INSET_TOP.
Referenced by NWidgetBackground::Draw().
static void DrawLabel | ( | const Rect & | r, | |
WidgetType | type, | |||
bool | clicked, | |||
StringID | str | |||
) | [inline, static] |
Draw the label-part of a widget.
r | Rectangle of the label background. | |
type | Widget type (WWT_TEXTBTN, WWT_TEXTBTN_2, or WWT_LABEL). | |
clicked | Label is rendered lowered. | |
str | Text to draw. |
Definition at line 255 of file widget.cpp.
References Rect::bottom, DrawString(), GetStringBoundingBox(), Dimension::height, Rect::left, max(), Rect::right, SA_CENTER, Rect::top, and WWT_TEXTBTN_2.
Referenced by NWidgetLeaf::Draw().
static void DrawMatrix | ( | const Rect & | r, | |
Colours | colour, | |||
bool | clicked, | |||
uint16 | data | |||
) | [inline, static] |
Draw a matrix widget.
r | Rectangle of the matrix background. | |
colour | Colour of the background. | |
clicked | Matrix is rendered lowered. | |
data | Data of the widget, number of rows and columns of the widget. |
Definition at line 296 of file widget.cpp.
References _colour_gradient, Rect::bottom, DrawFrameRect(), FR_LOWERED, GB(), GfxFillRect(), Rect::left, MAT_COL_BITS, MAT_COL_START, MAT_ROW_BITS, MAT_ROW_START, Rect::right, and Rect::top.
Referenced by NWidgetLeaf::Draw().
static void DrawResizeBox | ( | const Rect & | r, | |
Colours | colour, | |||
bool | at_left, | |||
bool | clicked | |||
) | [inline, static] |
Draw a resize box.
r | Rectangle of the box. | |
colour | Colour of the resize box. | |
at_left | Resize box is at left-side of the window, | |
clicked | Box is lowered. |
Definition at line 486 of file widget.cpp.
References Rect::bottom, DrawFrameRect(), DrawSprite(), FR_LOWERED, Rect::left, Rect::right, Rect::top, WD_RESIZEBOX_LEFT, WD_RESIZEBOX_RIGHT, and WD_RESIZEBOX_TOP.
Referenced by NWidgetLeaf::Draw().
static void DrawShadeBox | ( | const Rect & | r, | |
Colours | colour, | |||
bool | clicked | |||
) | [inline, static] |
Draw a shade box.
r | Rectangle of the box. | |
colour | Colour of the shade box. | |
clicked | Box is lowered. |
Definition at line 461 of file widget.cpp.
References Rect::bottom, DrawFrameRect(), DrawSprite(), FR_LOWERED, Rect::left, Rect::right, Rect::top, WD_SHADEBOX_LEFT, and WD_SHADEBOX_TOP.
Referenced by NWidgetLeaf::Draw().
static void DrawStickyBox | ( | const Rect & | r, | |
Colours | colour, | |||
bool | clicked | |||
) | [inline, static] |
Draw a sticky box.
r | Rectangle of the box. | |
colour | Colour of the sticky box. | |
clicked | Box is lowered. |
Definition at line 473 of file widget.cpp.
References Rect::bottom, DrawFrameRect(), DrawSprite(), FR_LOWERED, Rect::left, Rect::right, Rect::top, WD_STICKYBOX_LEFT, and WD_STICKYBOX_TOP.
Referenced by NWidgetLeaf::Draw().
static void DrawText | ( | const Rect & | r, | |
TextColour | colour, | |||
StringID | str | |||
) | [inline, static] |
Draw text.
r | Rectangle of the background. | |
colour | Colour of the text. | |
str | Text to draw. |
Definition at line 270 of file widget.cpp.
References Rect::bottom, DrawString(), GetStringBoundingBox(), Dimension::height, Rect::left, max(), Rect::right, and Rect::top.
Referenced by NWidgetLeaf::Draw().
static void DrawVerticalScrollbar | ( | const Rect & | r, | |
Colours | colour, | |||
bool | up_clicked, | |||
bool | bar_dragged, | |||
bool | down_clicked, | |||
const Scrollbar * | scrollbar | |||
) | [inline, static] |
Draw a vertical scrollbar.
r | Rectangle of the scrollbar widget. | |
colour | Colour of the scrollbar widget. | |
up_clicked | Up-arrow is clicked. | |
bar_dragged | Bar is dragged. | |
down_clicked | Down-arrow is clicked. | |
scrollbar | Scrollbar size, offset, and capacity information. |
Definition at line 344 of file widget.cpp.
References _colour_gradient, Rect::bottom, DOWNARROW, DrawFrameRect(), DrawString(), FILLRECT_CHECKER, FR_LOWERED, GfxFillRect(), HandleScrollbarHittest(), Rect::left, Rect::right, SA_CENTER, Rect::top, UPARROW, Point::x, and Point::y.
Referenced by NWidgetLeaf::Draw().
int GetWidgetFromPos | ( | const Window * | w, | |
int | x, | |||
int | y | |||
) |
Returns the index for the widget located at the given position relative to the window.
It includes all widget-corner pixels as well.
*w | Window to look inside | |
x | The Window client X coordinate | |
y | The Window client y coordinate |
Definition at line 185 of file widget.cpp.
References NWidgetBase::GetWidgetFromPos(), NWidgetCore::index, and Window::nested_root.
Referenced by DropdownWindow::GetDropDownItem(), and DropdownWindow::OnMouseLoop().
static Point HandleScrollbarHittest | ( | const Scrollbar * | sb, | |
int | top, | |||
int | bottom, | |||
bool | horizontal | |||
) | [static] |
Compute the vertical position of the draggable part of scrollbar.
sb | Scrollbar list data | |
top | Top position of the scrollbar (top position of the up-button) | |
bottom | Bottom position of the scrollbar (bottom position of the down-button) | |
horizontal | Whether the scrollbar is horizontal or not |
Definition at line 36 of file widget.cpp.
References _dynlang, Scrollbar::GetCapacity(), Scrollbar::GetCount(), Scrollbar::GetPosition(), TD_RTL, DynamicLanguages::text_dir, Point::x, and Point::y.
Referenced by DrawHorizontalScrollbar(), DrawVerticalScrollbar(), and ScrollbarClickPositioning().
static int MakeNWidget | ( | const NWidgetPart * | parts, | |
int | count, | |||
NWidgetBase ** | dest, | |||
bool * | fill_dest, | |||
int * | biggest_index | |||
) | [static] |
Construct a single nested widget in *dest from its parts.
Construct a NWidgetBase object from a NWidget function, and apply all settings that follow it, until encountering a EndContainer, another NWidget, or the end of the parts array.
parts | Array with parts of the nested widget. | |
count | Length of the parts array. | |
dest | Address of pointer to use for returning the composed widget. | |
fill_dest | Fill the composed widget with child widgets. | |
biggest_index | Pointer to biggest nested widget index in the tree encountered so far. |
biggest_index
!= NULL. Definition at line 2138 of file widget.cpp.
References NWidgetPartPaddings::bottom, NWidgetPartWidget::colour, NWidgetPart::cont_flags, NWidgetPartDataTip::data, NWidgetPart::data_tip, FS_BEGIN, NWidgetPart::func_ptr, NWidgetPartWidget::index, NWidgetPartPIP::inter, NWidgetPartPaddings::left, NWidgetPartTextLines::lines, max(), NWID_BUTTON_ARROW, NWID_BUTTON_DROPDOWN, NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_SELECTION, NWID_SPACER, NWID_VERTICAL, NWID_VIEWPORT, NWidgetLeaf::NWidgetLeaf(), NWidgetPart::padding, NWidgetPart::pip, NWidgetPartPIP::post, NWidgetPartPIP::pre, NWidgetPartPaddings::right, NWidgetResizeBase::SetFill(), NWidgetStacked::SetIndex(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetMinimalTextLines(), NWidgetBackground::SetPIP(), NWidgetPIPContainer::SetPIP(), NWidgetResizeBase::SetResize(), NWidgetPartTextLines::size, NWidgetPartTextLines::spacing, NWidgetPart::text_lines, NWidgetCore::tool_tip, NWidgetPartDataTip::tooltip, NWidgetPartPaddings::top, NWidgetPart::type, NWidgetPart::u, NWidgetPart::widget, NWidgetCore::widget_data, WPT_DATATIP, WPT_ENDCONTAINER, WPT_FILL, WPT_FUNCTION, WPT_MINSIZE, WPT_MINTEXTLINES, WPT_PADDING, WPT_PIPSPACE, WPT_RESIZE, WWT_FRAME, WWT_INSET, WWT_LAST, WWT_PANEL, Point::x, NWidgetPart::xy, and Point::y.
Referenced by MakeWidgetTree().
static int MakeWidgetTree | ( | const NWidgetPart * | parts, | |
int | count, | |||
NWidgetBase ** | parent, | |||
int * | biggest_index | |||
) | [static] |
Build a nested widget tree by recursively filling containers with nested widgets read from their parts.
parts | Array with parts of the nested widgets. | |
count | Length of the parts array. | |
parent | Pointer or container to use for storing the child widgets (*parent == NULL or *parent == container or background widget). | |
biggest_index | Pointer to biggest nested widget index in the tree. |
*biggest_index
contains the largest widget index of the tree and -1
if no index is used. Definition at line 2286 of file widget.cpp.
References NWidgetBackground::Add(), NWidgetContainer::Add(), MakeNWidget(), NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_SELECTION, NWID_VERTICAL, NWidgetPart::type, NWidgetBase::type, WPT_ENDCONTAINER, WWT_FRAME, WWT_INSET, and WWT_PANEL.
Referenced by MakeNWidgets(), and MakeWindowNWidgetTree().
void ScrollbarClickHandler | ( | Window * | w, | |
const NWidgetCore * | nw, | |||
int | x, | |||
int | y | |||
) |
Special handling for the scrollbar widget type.
Handles the special scrolling buttons and other scrolling.
w | Window on which a scroll was performed. | |
nw | Pointer to the scrollbar widget. | |
x | The X coordinate of the mouse click. | |
y | The Y coordinate of the mouse click. |
Definition at line 150 of file widget.cpp.
References NWidgetBase::current_x, NWidgetBase::current_y, NWidgetBase::pos_x, NWidgetBase::pos_y, ScrollbarClickPositioning(), NWidgetBase::type, WWT_HSCROLLBAR, WWT_SCROLL2BAR, and WWT_SCROLLBAR.
Referenced by DispatchLeftClickEvent().
static void ScrollbarClickPositioning | ( | Window * | w, | |
WidgetType | wtp, | |||
int | x, | |||
int | y, | |||
int | mi, | |||
int | ma | |||
) | [static] |
Compute new position of the scrollbar after a click and updates the window flags.
w | Window on which a scroll was performed. | |
wtp | Scrollbar widget type. | |
mi | Minimum coordinate of the scroll bar. | |
ma | Maximum coordinate of the scroll bar. | |
x | The X coordinate of the mouse click. | |
y | The Y coordinate of the mouse click. |
Definition at line 73 of file widget.cpp.
References _dynlang, _left_button_clicked, Window::flags4, Scrollbar::GetCapacity(), HandleScrollbarHittest(), Window::hscroll, CursorVars::pos, Window::SetDirty(), TD_RTL, DynamicLanguages::text_dir, Scrollbar::UpdatePosition(), Window::vscroll, Window::vscroll2, WF_SCROLL_DOWN, WF_SCROLL_MIDDLE, WF_SCROLL_UP, WWT_HSCROLLBAR, WWT_SCROLL2BAR, WWT_SCROLLBAR, Point::x, and Point::y.
Referenced by ScrollbarClickHandler().