|
OpenTTD
|
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/string_colours.h"#include "safeguards.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, uint resize_x, uint resize_y) |
| 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 | DrawDefSizeBox (const Rect &r, Colours colour, bool clicked) |
| Draw a defsize 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) |
| 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. | |
Handling of the default/simple widgets.
Definition in file widget.cpp.
|
inlinestatic |
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 567 of file widget.cpp.
References _current_text_dir, DrawFrameRect(), DrawSprite(), DrawString(), NWidgetLeaf::dropdown_dimension, FONT_HEIGHT_NORMAL, FR_LOWERED, max(), 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 539 of file widget.cpp.
References _colour_gradient, _company_colours, DrawFrameRect(), DrawString(), FR_BORDERONLY, FR_DARKENED, FR_LOWERED, GetStringBoundingBox(), GfxFillRect(), max(), MAX_COMPANIES, SA_HOR_CENTER, WD_CAPTIONTEXT_LEFT, and WD_CAPTIONTEXT_RIGHT.
Referenced by NWidgetLeaf::Draw(), and NewsWindow::DrawWidget().
|
inlinestatic |
Draw a close box.
| r | Rectangle of the box. |
| colour | Colour of the close box. |
Definition at line 526 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), PALETTE_TEXT_RECOLOUR, WD_CLOSEBOX_LEFT, and WD_CLOSEBOX_TOP.
Referenced by NWidgetLeaf::Draw().
|
inlinestatic |
Draw a NewGRF debug box.
| r | Rectangle of the box. |
| colour | Colour of the debug box. |
| clicked | Box is lowered. |
Definition at line 496 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, WD_DEBUGBOX_LEFT, and WD_DEBUGBOX_TOP.
Referenced by NWidgetLeaf::Draw().
|
inlinestatic |
Draw a defsize box.
| r | Rectangle of the box. |
| colour | Colour of the defsize box. |
| clicked | Box is lowered. |
Definition at line 484 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, WD_DEFSIZEBOX_LEFT, and WD_DEFSIZEBOX_TOP.
Referenced by NWidgetLeaf::Draw().
|
inlinestatic |
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 595 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 410 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 177 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 NWidgetBackground::Draw(), NWidgetLeaf::Draw(), DrawAircraftImage(), DrawArrowButtons(), DrawBoolButton(), DrawButtonDropdown(), DrawCaption(), DrawCloseBox(), DrawDebugBox(), DrawDefSizeBox(), DrawDropDownButton(), DrawHorizontalScrollbar(), DrawImageButtons(), DrawInset(), DrawMatrix(), DrawResizeBox(), DrawRoadVehImage(), DrawShadeBox(), DrawShipImage(), DrawStickyBox(), DrawTrainImage(), DrawVerticalScrollbar(), TransparenciesWindow::DrawWidget(), MusicWindow::DrawWidget(), RefitWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), and Window::DrawWidgets().
|
inlinestatic |
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 375 of file widget.cpp.
References _colour_gradient, DrawFrameRect(), DrawSprite(), FILLRECT_CHECKER, FR_LOWERED, GfxFillRect(), and HandleScrollbarHittest().
Referenced by NWidgetScrollbar::Draw().
|
inlinestatic |
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 218 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 262 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().
|
inlinestatic |
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 234 of file widget.cpp.
References DrawString(), GetStringBoundingBox(), max(), SA_HOR_CENTER, and WWT_TEXTBTN_2.
Referenced by NWidgetLeaf::Draw().
|
inlinestatic |
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. |
| resize_x | Matrix resize unit size. |
| resize_y | Matrix resize unit size. |
Definition at line 277 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().
|
inlinestatic |
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 509 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, GetSpriteSize(), WD_RESIZEBOX_BOTTOM, WD_RESIZEBOX_LEFT, and WD_RESIZEBOX_RIGHT.
Referenced by NWidgetLeaf::Draw().
|
inlinestatic |
Draw a shade box.
| r | Rectangle of the box. |
| colour | Colour of the shade box. |
| clicked | Box is lowered. |
Definition at line 460 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, WD_SHADEBOX_LEFT, and WD_SHADEBOX_TOP.
Referenced by NWidgetLeaf::Draw().
|
inlinestatic |
Draw a sticky box.
| r | Rectangle of the box. |
| colour | Colour of the sticky box. |
| clicked | Box is lowered. |
Definition at line 472 of file widget.cpp.
References DrawFrameRect(), DrawSprite(), FR_LOWERED, WD_STICKYBOX_LEFT, and WD_STICKYBOX_TOP.
Referenced by NWidgetLeaf::Draw().
|
inlinestatic |
Draw text.
| r | Rectangle of the background. |
| colour | Colour of the text. |
| str | Text to draw. |
Definition at line 249 of file widget.cpp.
References DrawString(), GetStringBoundingBox(), and max().
Referenced by NWidgetLeaf::Draw().
|
inlinestatic |
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 337 of file widget.cpp.
References _colour_gradient, DrawFrameRect(), DrawSprite(), FILLRECT_CHECKER, FR_LOWERED, GfxFillRect(), and HandleScrollbarHittest().
Referenced by NWidgetScrollbar::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.
Definition at line 162 of file widget.cpp.
References NWidgetBase::GetWidgetFromPos(), NWidgetCore::index, and Window::nested_root.
Referenced by DropdownWindow::GetDropDownItem(), HandleMouseDragDrop(), and Window::OnDropdownClose().
|
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 38 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 2854 of file widget.cpp.
References NWidgetContainer::Add(), GetSpriteSize(), NWidgetCore::SetDataTip(), NWidgetResizeBase::SetFill(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetResize(), WD_MATRIX_BOTTOM, WD_MATRIX_LEFT, WD_MATRIX_RIGHT, WD_MATRIX_TOP, and WWT_PANEL.
Referenced by MakeCompanyButtonRowsAIDebug(), MakeCompanyButtonRowsGraphGUI(), and MakeCompanyButtonRowsLinkGraphGUI().
|
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 2552 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(), NWidgetPIPContainer::SetPIP(), NWidgetBackground::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 |
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 2726 of file widget.cpp.
References NWidgetContainer::Add(), NWidgetBackground::Add(), MakeNWidget(), NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_MATRIX, NWID_SELECTION, NWID_VERTICAL, NWidgetBase::type, NWidgetPart::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 138 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 |
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 81 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, TD_RTL, NWidgetBase::type, and Scrollbar::UpdatePosition().
Referenced by ScrollbarClickHandler().
1.8.1.2