Handling of the default/simple widgets. More...
#include "stdafx.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 "core/geometry_func.hpp"
#include "settings_type.h"
#include "querystring_gui.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "table/palettes.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, NWidgetScrollbar *sb, 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, 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 | DrawDebugBox (const Rect &r, Colours colour, bool clicked) |
Draw a NewGRF debug 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. | |
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 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. | |
NWidgetBase * | MakeCompanyButtonRows (int *biggest_index, int widget_first, int widget_last, int max_length, StringID button_tooltip) |
Make a number of rows with button-like graphics, for enabling/disabling each company. | |
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. |
Handling of the default/simple widgets.
Definition in file widget.cpp.
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 540 of file widget.cpp.
References _current_text_dir, DOWNARROW, DrawFrameRect(), DrawString(), FONT_HEIGHT_NORMAL, FR_LOWERED, max(), SA_HOR_CENTER, TD_LTR, WD_DROPDOWNTEXT_LEFT, and WD_DROPDOWNTEXT_RIGHT.
Referenced by NWidgetLeaf::Draw(), and DrawDropdown().
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 514 of file widget.cpp.
References _colour_gradient, _company_colours, DrawFrameRect(), DrawString(), FR_BORDERONLY, FR_DARKENED, FR_LOWERED, GetStringBoundingBox(), GfxFillRect(), INVALID_OWNER, max(), SA_HOR_CENTER, WD_CAPTIONTEXT_LEFT, and WD_CAPTIONTEXT_RIGHT.
Referenced by NWidgetLeaf::Draw(), and NewsWindow::DrawWidget().
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 500 of file widget.cpp.
References DrawFrameRect(), DrawString(), SA_HOR_CENTER, WD_CLOSEBOX_LEFT, WD_CLOSEBOX_RIGHT, and WD_CLOSEBOX_TOP.
Referenced by NWidgetLeaf::Draw().
static void DrawDebugBox | ( | const Rect & | r, | |
Colours | colour, | |||
bool | clicked | |||
) | [inline, static] |
Draw a NewGRF debug box.
r | Rectangle of the box. | |
colour | Colour of the debug box. | |
clicked | Box is lowered. |
Definition at line 469 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, WD_DEBUGBOX_LEFT, and WD_DEBUGBOX_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 564 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 395 of file widget.cpp.
References _colour_gradient, _current_text_dir, DrawString(), FONT_HEIGHT_NORMAL, GfxFillRect(), TD_LTR, 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 176 of file widget.cpp.
References _colour_gradient, FILLRECT_RECOLOUR, FR_BORDERONLY, FR_DARKENED, FR_LOWERED, FR_TRANSPARENT, GfxFillRect(), PALETTE_TO_TRANSPARENT, WD_BEVEL_BOTTOM, WD_BEVEL_LEFT, WD_BEVEL_RIGHT, and WD_BEVEL_TOP.
Referenced by NWidgetLeaf::Draw(), NWidgetBackground::Draw(), DrawAircraftImage(), DrawArrowButtons(), DrawBoolButton(), DrawButtonDropdown(), DrawCaption(), DrawCloseBox(), DrawDebugBox(), DrawDropDownButton(), DrawHorizontalScrollbar(), DrawImageButtons(), DrawInset(), DrawMatrix(), DrawResizeBox(), DrawRoadVehImage(), DrawShadeBox(), DrawShipImage(), DrawStickyBox(), DrawTrainImage(), DrawVerticalScrollbar(), RefitWindow::DrawWidget(), TransparenciesWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), MusicWindow::DrawWidget(), GenerateProgressWindow::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 360 of file widget.cpp.
References _colour_gradient, DrawFrameRect(), DrawSprite(), FILLRECT_CHECKER, FR_LOWERED, GfxFillRect(), and HandleScrollbarHittest().
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 217 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, 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 261 of file widget.cpp.
References DrawFrameRect(), DrawString(), FR_DARKENED, FR_LOWERED, 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 233 of file widget.cpp.
References DrawString(), GetStringBoundingBox(), max(), SA_HOR_CENTER, 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 274 of file widget.cpp.
References _colour_gradient, DrawFrameRect(), FR_LOWERED, GB(), GfxFillRect(), MAT_COL_BITS, MAT_COL_START, MAT_ROW_BITS, and MAT_ROW_START.
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 482 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, GetSpriteSize(), WD_RESIZEBOX_BOTTOM, WD_RESIZEBOX_LEFT, and WD_RESIZEBOX_RIGHT.
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 445 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, 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 457 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, 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 248 of file widget.cpp.
References DrawString(), GetStringBoundingBox(), and max().
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 322 of file widget.cpp.
References _colour_gradient, DOWNARROW, DrawFrameRect(), DrawString(), FILLRECT_CHECKER, FR_LOWERED, GfxFillRect(), HandleScrollbarHittest(), SA_HOR_CENTER, and UPARROW.
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 161 of file widget.cpp.
References NWidgetBase::GetWidgetFromPos(), NWidgetCore::index, and Window::nested_root.
Referenced by DropdownWindow::GetDropDownItem(), HandleMouseDragDrop(), and Window::OnDropdownClose().
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 39 of file widget.cpp.
References _current_text_dir, Scrollbar::GetCapacity(), Scrollbar::GetCount(), Scrollbar::GetPosition(), and TD_RTL.
Referenced by DrawHorizontalScrollbar(), DrawVerticalScrollbar(), and ScrollbarClickPositioning().
NWidgetBase* MakeCompanyButtonRows | ( | int * | biggest_index, | |
int | widget_first, | |||
int | widget_last, | |||
int | max_length, | |||
StringID | button_tooltip | |||
) |
Make a number of rows with button-like graphics, for enabling/disabling each company.
biggest_index | Storage for collecting the biggest index used in the returned tree. | |
widget_first | The first widget index to use. | |
widget_last | The last widget index to use. | |
max_length | Maximal number of company buttons in one row. | |
button_tooltip | The tooltip-string of every button. |
*biggest_index
contains the largest used index in the tree. Definition at line 2766 of file widget.cpp.
References NWidgetContainer::Add(), GetSpriteSize(), NWidgetCore::SetDataTip(), NWidgetResizeBase::SetFill(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetResize(), WD_MATRIX_BOTTOM, WD_MATRIX_LEFT, WD_MATRIX_TOP, and WWT_PANEL.
Referenced by MakeCompanyButtonRowsAIDebug(), MakeCompanyButtonRowsGraphGUI(), and MakeCompanyButtonRowsLinkGraphGUI().
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 2464 of file widget.cpp.
References NWidgetPartWidget::colour, NWidgetPart::cont_flags, NWidgetPartDataTip::data, NWidgetPart::data_tip, FS_BEGIN, NWidgetPart::func_ptr, NWidgetPartWidget::index, NWidgetPartPaddings::left, NWidgetPartTextLines::lines, max(), NWID_BUTTON_DROPDOWN, NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_HSCROLLBAR, NWID_MATRIX, NWID_SELECTION, NWID_SPACER, NWID_VERTICAL, NWID_VIEWPORT, NWID_VSCROLLBAR, NWidgetPart::padding, NWidgetPart::pip, NWidgetPartPIP::post, NWidgetCore::scrollbar_index, NWidgetResizeBase::SetFill(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetMinimalTextLines(), NWidgetBackground::SetPIP(), NWidgetPIPContainer::SetPIP(), NWidgetResizeBase::SetResize(), NWidgetPartTextLines::size, NWidgetPartTextLines::spacing, NWidgetPart::text_lines, NWidgetCore::tool_tip, NWidgetPartDataTip::tooltip, NWidgetPart::type, NWidgetPart::widget, NWidgetCore::widget_data, WPT_DATATIP, WPT_ENDCONTAINER, WPT_FILL, WPT_FUNCTION, WPT_MINSIZE, WPT_MINTEXTLINES, WPT_PADDING, WPT_PIPSPACE, WPT_RESIZE, WPT_SCROLLBAR, WWT_FRAME, WWT_INSET, WWT_LAST, WWT_PANEL, and NWidgetPart::xy.
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 2638 of file widget.cpp.
References NWidgetBackground::Add(), NWidgetContainer::Add(), MakeNWidget(), NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_MATRIX, 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, | |
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 139 of file widget.cpp.
References NWidgetBase::current_x, NWidgetBase::current_y, NWID_HSCROLLBAR, NWidgetBase::pos_x, NWidgetBase::pos_y, ScrollbarClickPositioning(), and NWidgetBase::type.
Referenced by DispatchLeftClickEvent().
static void ScrollbarClickPositioning | ( | Window * | w, | |
NWidgetScrollbar * | sb, | |||
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. | |
sb | Scrollbar | |
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 82 of file widget.cpp.
References _current_text_dir, NWidgetCore::disp_flags, HandleScrollbarHittest(), NWidgetCore::index, NDB_SCROLLBAR_DOWN, NDB_SCROLLBAR_UP, NWID_HSCROLLBAR, Window::scrolling_scrollbar, SetBit(), Window::SetDirty(), Scrollbar::SS_BIG, NWidgetBase::type, and Scrollbar::UpdatePosition().
Referenced by ScrollbarClickHandler().