tron@2186: /* $Id$ */ tron@2186: rubidium@8602: /** @file window_gui.h Functions, definitions and such used only by the GUI. */ belugas@6443: rubidium@8602: #ifndef WINDOW_GUI_H rubidium@8602: #define WINDOW_GUI_H truelight@0: rubidium@8718: #include "core/bitmath_func.hpp" rubidium@10445: #include "core/geometry_type.hpp" rubidium@8635: #include "vehicle_type.h" rubidium@8720: #include "viewport_type.h" rubidium@8750: #include "player_type.h" rubidium@8760: #include "strings_type.h" rubidium@10164: #include "core/alloc_type.hpp" rubidium@10445: #include "window_type.h" rubidium@10445: #include "tile_type.h" truelight@4299: rubidium@8564: /** rubidium@8564: * The maximum number of windows that can be opened. rubidium@8564: */ rubidium@8564: static const int MAX_NUMBER_OF_WINDOWS = 25; rubidium@8564: truelight@867: /* How the resize system works: truelight@867: First, you need to add a WWT_RESIZEBOX to the widgets, and you need truelight@867: to add the flag WDF_RESIZABLE to the window. Now the window is ready truelight@867: to resize itself. truelight@867: As you may have noticed, all widgets have a RESIZE_XXX in their line. truelight@867: This lines controls how the widgets behave on resize. RESIZE_NONE means truelight@867: it doesn't do anything. Any other option let's one of the borders truelight@867: move with the changed width/height. So if a widget has truelight@867: RESIZE_RIGHT, and the window is made 5 pixels wider by the user, truelight@867: the right of the window will also be made 5 pixels wider. truelight@867: Now, what if you want to clamp a widget to the bottom? Give it the flag truelight@867: RESIZE_TB. This is RESIZE_TOP + RESIZE_BOTTOM. Now if the window gets truelight@867: 5 pixels bigger, both the top and bottom gets 5 bigger, so the whole truelight@867: widgets moves downwards without resizing, and appears to be clamped truelight@867: to the bottom. Nice aint it? truelight@867: You should know one more thing about this system. Most windows can't truelight@867: handle an increase of 1 pixel. So there is a step function, which truelight@867: let the windowsize only be changed by X pixels. You configure this truelight@867: after making the window, like this: truelight@867: w->resize.step_height = 10; truelight@867: Now the window will only change in height in steps of 10. truelight@867: You can also give a minimum width and height. The default value is truelight@867: the default height/width of the window itself. You can change this rubidium@10229: AFTER window - creation, with: truelight@867: w->resize.width or w->resize.height. truelight@867: That was all.. good luck, and enjoy :) -- TrueLight */ truelight@867: rubidium@6574: enum ResizeFlag { belugas@6505: RESIZE_NONE = 0, ///< no resize required truelight@867: belugas@6505: RESIZE_LEFT = 1, ///< left resize flag belugas@6505: RESIZE_RIGHT = 2, ///< rigth resize flag belugas@6505: RESIZE_TOP = 4, ///< top resize flag belugas@6505: RESIZE_BOTTOM = 8, ///< bottom resize flag truelight@867: belugas@6505: RESIZE_LR = RESIZE_LEFT | RESIZE_RIGHT, ///< combination of left and right resize flags belugas@6505: RESIZE_RB = RESIZE_RIGHT | RESIZE_BOTTOM, ///< combination of right and bottom resize flags belugas@6505: RESIZE_TB = RESIZE_TOP | RESIZE_BOTTOM, ///< combination of top and bottom resize flags belugas@6505: RESIZE_LRB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_BOTTOM, ///< combination of left, right and bottom resize flags belugas@6505: RESIZE_LRTB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM, ///< combination of all resize flags belugas@6505: RESIZE_RTB = RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM, ///< combination of right, top and bottom resize flag belugas@4749: belugas@4749: /* The following flags are used by the system to specify what is disabled, hidden, or clicked belugas@4749: * They are used in the same place as the above RESIZE_x flags, Widget visual_flags. belugas@4749: * These states are used in exceptions. If nothing is specified, they will indicate belugas@4749: * Enabled, visible or unclicked widgets*/ belugas@6443: WIDG_DISABLED = 4, ///< widget is greyed out, not available belugas@6443: WIDG_HIDDEN = 5, ///< widget is made invisible belugas@6443: WIDG_LOWERED = 6, ///< widget is paint lowered, a pressed button in fact rubidium@6574: }; truelight@867: glx@4755: enum { belugas@6505: WIDGET_LIST_END = -1, ///< indicate the end of widgets' list for vararg functions glx@4755: }; glx@4755: rubidium@10083: /** rubidium@10083: * Window widget data structure rubidium@10083: */ rubidium@6574: struct Widget { belugas@6443: byte type; ///< Widget type, see WindowWidgetTypes belugas@6443: byte display_flags; ///< Resize direction, alignment, etc. during resizing, see ResizeFlags Darkvater@4547: byte color; ///< Widget colour, see docs/ottd-colourtext-palette.png bjarni@6224: int16 left, right, top, bottom; ///< The position offsets inside the window Darkvater@4547: uint16 data; ///< The String/Image or special code (list-matrixes) of a widget Darkvater@4547: StringID tooltips; ///< Tooltips that are shown when rightclicking on a widget rubidium@6574: }; truelight@0: rubidium@10083: /** rubidium@10083: * Flags to describe the look of the frame rubidium@10083: */ rubidium@6574: enum FrameFlags { belugas@8504: FR_NONE = 0, belugas@8504: FR_TRANSPARENT = 1 << 0, ///< Makes the background transparent if set belugas@8504: FR_BORDERONLY = 1 << 4, ///< Draw border only, no background belugas@8504: FR_LOWERED = 1 << 5, ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed) belugas@8504: FR_DARKENED = 1 << 6, ///< If set the background is darker, allows for lowered frames with normal background color when used with FR_LOWERED (ie. dropdown boxes) rubidium@6574: }; tron@4437: rubidium@5838: DECLARE_ENUM_AS_BIT_SET(FrameFlags); rubidium@5838: rubidium@10083: /* wiget.cpp */ tron@4437: void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags); hackykid@1938: rubidium@10083: /** rubidium@10083: * High level window description rubidium@10083: */ rubidium@6574: struct WindowDesc { rubidium@10083: int16 left; ///< Prefered x position of left edge of the window, @see WindowDefaultPosition() rubidium@10083: int16 top; ///< Prefered y position of the top of the window, @see WindowDefaultPosition() rubidium@10083: int16 minimum_width; ///< Minimal width of the window rubidium@10083: int16 minimum_height; ///< Minimal height of the window rubidium@10083: int16 default_width; ///< Prefered initial width of the window rubidium@10083: int16 default_height; ///< Prefered initial height of the window rubidium@10083: WindowClass cls; ///< Class of the window, @see WindowClass rubidium@10083: WindowClass parent_cls; ///< Class of the parent window, @see WindowClass rubidium@10083: uint32 flags; ///< Flags, @see WindowDefaultFlags rubidium@10083: const Widget *widgets; ///< List of widgets with their position and size for the window rubidium@6574: }; truelight@0: rubidium@10083: /** rubidium@10083: * Window default widget/window handling flags rubidium@10083: */ Darkvater@5664: enum WindowDefaultFlag { belugas@8504: WDF_STD_TOOLTIPS = 1 << 0, ///< use standard routine when displaying tooltips rubidium@10083: WDF_DEF_WIDGET = 1 << 1, ///< Default widget control for some widgets in the on click event, @see DispatchLeftClickEvent() rubidium@10083: WDF_STD_BTN = 1 << 2, ///< Default handling for close and titlebar widgets (widget no 0 and 1) belugas@8515: rubidium@10083: WDF_UNCLICK_BUTTONS = 1 << 4, ///< Unclick buttons when the window event times out belugas@8504: WDF_STICKY_BUTTON = 1 << 5, ///< Set window to sticky mode; they are not closed unless closed with 'X' (widget 2) rubidium@10083: WDF_RESIZABLE = 1 << 6, ///< Window can be resized belugas@8504: WDF_MODAL = 1 << 7, ///< The window is a modal child of some other window, meaning the parent is 'inactive' truelight@0: }; truelight@0: rubidium@10083: /** rubidium@10083: * Special values for 'left' and 'top' to cause a specific placement rubidium@10083: */ Darkvater@5664: enum WindowDefaultPosition { Darkvater@5072: WDP_AUTO = -1, ///< Find a place automatically Darkvater@5072: WDP_CENTER = -2, ///< Center the window (left/right or top/bottom) Darkvater@5072: WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar Darkvater@5072: WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar truelight@0: }; truelight@0: rubidium@10083: /** rubidium@10083: * Scrollbar data structure rubidium@10083: */ rubidium@6574: struct Scrollbar { rubidium@10083: uint16 count; ///< Number of elements in the list rubidium@10083: uint16 cap; ///< Number of visible elements of the scroll bar rubidium@10083: uint16 pos; rubidium@6574: }; truelight@0: rubidium@10083: /** rubidium@10083: * Data structure for resizing a window rubidium@10083: */ rubidium@6574: struct ResizeInfo { rubidium@10083: uint width; ///< Minimum allowed width of the window rubidium@10083: uint height; ///< Minimum allowed height of the window rubidium@10083: uint step_width; ///< Step-size of width resize changes rubidium@10083: uint step_height; ///< Step-size of height resize changes rubidium@6574: }; truelight@867: rubidium@10595: enum SortButtonState { rubidium@10595: SBS_OFF, rubidium@10595: SBS_DOWN, rubidium@10595: SBS_UP, rubidium@10595: }; rubidium@10595: rubidium@10083: /** glx@10504: * Data structure for a window viewport glx@10504: */ glx@10504: struct ViewportData : ViewPort { glx@10504: VehicleID follow_vehicle; glx@10504: int32 scrollpos_x; glx@10504: int32 scrollpos_y; glx@10504: int32 dest_scrollpos_x; glx@10504: int32 dest_scrollpos_y; glx@10504: }; glx@10504: belugas@10589: /** rubidium@10083: * Data structure for an opened window rubidium@10083: */ rubidium@10164: struct Window : ZeroedMemoryAllocator { rubidium@10607: enum EventState { rubidium@10607: ES_HANDLED, rubidium@10607: ES_NOT_HANDLED, rubidium@10607: }; rubidium@10607: rubidium@10461: protected: rubidium@10498: void Initialize(int x, int y, int min_width, int min_height, rubidium@10641: WindowClass cls, const Widget *widget, int window_number); rubidium@10498: void FindWindowPlacementAndResize(int def_width, int def_height); rubidium@10498: void FindWindowPlacementAndResize(const WindowDesc *desc); rubidium@10461: rubidium@10399: public: rubidium@10625: Window(int x, int y, int width, int height, WindowClass cls, const Widget *widget); rubidium@10525: Window(const WindowDesc *desc, WindowNumber number = 0); rubidium@10461: rubidium@10433: virtual ~Window(); rubidium@10399: rubidium@10083: uint16 flags4; ///< Window flags, @see WindowFlags rubidium@10083: WindowClass window_class; ///< Window class rubidium@10083: WindowNumber window_number; ///< Window number within the window class truelight@0: rubidium@10083: int left; ///< x position of left edge of the window rubidium@10083: int top; ///< y position of top edge of the window rubidium@10083: int width; ///< width of the window (number of pixels to the right in x direction) rubidium@10083: int height; ///< Height of the window (number of pixels down in y direction) truelight@0: rubidium@10083: Scrollbar hscroll; ///< Horizontal scroll bar rubidium@10083: Scrollbar vscroll; ///< First vertical scroll bar rubidium@10083: Scrollbar vscroll2; ///< Second vertical scroll bar rubidium@10083: ResizeInfo resize; ///< Resize information truelight@0: rubidium@10083: byte caption_color; ///< Background color of the window caption, contains PlayerID rubidium@10083: glx@10504: ViewportData *viewport; ///< Pointer to viewport data, if present rubidium@10083: Widget *widget; ///< Widgets of the window rubidium@10083: uint widget_count; ///< Number of widgets of the window rubidium@10083: uint32 desc_flags; ///< Window/widgets default flags setting, @see WindowDefaultFlag rubidium@10083: rubidium@10083: Window *parent; ///< Parent window belugas@8489: belugas@8531: void HandleButtonClick(byte widget); belugas@8531: belugas@8489: void SetWidgetDisabledState(byte widget_index, bool disab_stat); belugas@8489: void DisableWidget(byte widget_index); belugas@8489: void EnableWidget(byte widget_index); rubidium@8491: bool IsWidgetDisabled(byte widget_index) const; belugas@8489: void SetWidgetHiddenState(byte widget_index, bool hidden_stat); belugas@8489: void HideWidget(byte widget_index); belugas@8489: void ShowWidget(byte widget_index); rubidium@8491: bool IsWidgetHidden(byte widget_index) const; belugas@8489: void SetWidgetLoweredState(byte widget_index, bool lowered_stat); rubidium@8492: void ToggleWidgetLoweredState(byte widget_index); belugas@8489: void LowerWidget(byte widget_index); belugas@8489: void RaiseWidget(byte widget_index); rubidium@8491: bool IsWidgetLowered(byte widget_index) const; belugas@8489: belugas@8489: void RaiseButtons(); belugas@8489: void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...); belugas@8489: void CDECL SetWidgetsHiddenState(bool hidden_stat, int widgets, ...); belugas@8489: void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...); glx@8522: void InvalidateWidget(byte widget_index) const; rubidium@10399: rubidium@10595: void DrawWidgets() const; rubidium@10595: void DrawViewport() const; rubidium@10595: void DrawSortButtonState(int widget, SortButtonState state) const; rubidium@10595: rubidium@10433: void SetDirty() const; rubidium@10433: rubidium@10486: /*** Event handling ***/ rubidium@10486: rubidium@10486: /** rubidium@10486: * This window is currently being repainted. rubidium@10486: */ rubidium@10641: virtual void OnPaint() {} rubidium@10486: rubidium@10486: rubidium@10486: /** rubidium@10486: * A key has been pressed. rubidium@10486: * @param key the Unicode value of the key. rubidium@10486: * @param keycode the untranslated key code including shift state. rubidium@10607: * @return ES_HANDLED if the key press has been handled and no other rubidium@10486: * window should receive the event. rubidium@10486: */ rubidium@10641: virtual EventState OnKeyPress(uint16 key, uint16 keycode) { return ES_NOT_HANDLED; } rubidium@10486: rubidium@10486: /** rubidium@10486: * The state of the control key has changed rubidium@10607: * @return ES_HANDLED if the change has been handled and no other rubidium@10486: * window should receive the event. rubidium@10486: */ rubidium@10641: virtual EventState OnCTRLStateChange() { return ES_NOT_HANDLED; } rubidium@10486: rubidium@10486: rubidium@10486: /** rubidium@10486: * A click with the left mouse button has been made on the window. rubidium@10486: * @param pt the point inside the window that has been clicked. rubidium@10486: * @param widget the clicked widget. rubidium@10486: */ rubidium@10641: virtual void OnClick(Point pt, int widget) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * A double click with the left mouse button has been made on the window. rubidium@10486: * @param pt the point inside the window that has been clicked. rubidium@10486: * @param widget the clicked widget. rubidium@10486: */ rubidium@10586: virtual void OnDoubleClick(Point pt, int widget) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * A click with the right mouse button has been made on the window. rubidium@10486: * @param pt the point inside the window that has been clicked. rubidium@10486: * @param widget the clicked widget. rubidium@10486: */ rubidium@10586: virtual void OnRightClick(Point pt, int widget) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * A dragged 'object' has been released. rubidium@10486: * @param pt the point inside the window where the release took place. rubidium@10486: * @param widget the widget where the release took place. rubidium@10486: */ rubidium@10586: virtual void OnDragDrop(Point pt, int widget) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * Handle the request for (viewport) scrolling. rubidium@10486: * @param delta the amount the viewport must be scrolled. rubidium@10486: */ rubidium@10586: virtual void OnScroll(Point delta) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * The mouse is currently moving over the window or has just moved outside rubidium@10486: * of the window. In the latter case pt is (-1, -1). rubidium@10486: * @param pt the point inside the window that the mouse hovers over. rubidium@10486: * @param widget the widget the mouse hovers over. rubidium@10486: */ rubidium@10586: virtual void OnMouseOver(Point pt, int widget) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * The mouse wheel has been turned. rubidium@10486: * @param wheel the amount of movement of the mouse wheel. rubidium@10486: */ rubidium@10586: virtual void OnMouseWheel(int wheel) {} rubidium@10486: rubidium@10486: rubidium@10486: /** rubidium@10486: * Called for every mouse loop run, which is at least once per (game) tick. rubidium@10486: */ rubidium@10641: virtual void OnMouseLoop() {} rubidium@10486: rubidium@10486: /** rubidium@10486: * Called once per (game) tick. rubidium@10486: */ rubidium@10641: virtual void OnTick() {} rubidium@10486: rubidium@10486: /** rubidium@10486: * Called once every 100 (game) ticks. rubidium@10486: */ rubidium@10641: virtual void OnHundredthTick() {} rubidium@10486: rubidium@10486: /** rubidium@10486: * Called when this window's timeout has been reached. rubidium@10486: */ rubidium@10641: virtual void OnTimeout() {} rubidium@10486: rubidium@10486: rubidium@10486: /** rubidium@10486: * Called when the window got resized. rubidium@10486: * @param new_size the new size of the window. rubidium@10486: * @param delta the amount of which the window size changed. rubidium@10486: */ rubidium@10641: virtual void OnResize(Point new_size, Point delta) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * A dropdown option associated to this window has been selected. rubidium@10486: * @param widget the widget (button) that the dropdown is associated with. rubidium@10486: * @param index the element in the dropdown that is selected. rubidium@10486: */ rubidium@10641: virtual void OnDropdownSelect(int widget, int index) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * The query window opened from this window has closed. rubidium@10486: * @param str the new value of the string or NULL if the window rubidium@10486: * was cancelled. rubidium@10486: */ rubidium@10641: virtual void OnQueryTextFinished(char *str) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * Some data on this window has become invalid. rubidium@10486: * @param data information about the changed data. rubidium@10486: */ rubidium@10641: virtual void OnInvalidateData(int data = 0) {} rubidium@10486: rubidium@10486: rubidium@10486: /** rubidium@10486: * The user clicked some place on the map when a tile highlight mode rubidium@10486: * has been set. rubidium@10486: * @param pt the exact point on the map that has been clicked. rubidium@10486: * @param tile the tile on the map that has been clicked. rubidium@10486: */ rubidium@10641: virtual void OnPlaceObject(Point pt, TileIndex tile) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * The user cancelled a tile highlight mode that has been set. rubidium@10486: */ rubidium@10641: virtual void OnPlaceObjectAbort() {} rubidium@10486: rubidium@10486: rubidium@10486: /** rubidium@10486: * The user is dragging over the map when the tile highlight mode rubidium@10486: * has been set. rubidium@10486: * @param select_method the method of selection (allowed directions) rubidium@10486: * @param select_proc what will be created when the drag is over. rubidium@10486: * @param pt the exact point on the map where the mouse is. rubidium@10486: */ rubidium@10641: virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * The user has dragged over the map when the tile highlight mode rubidium@10486: * has been set. rubidium@10486: * @param select_method the method of selection (allowed directions) rubidium@10486: * @param select_proc what should be created. rubidium@10486: * @param pt the exact point on the map where the mouse was released. rubidium@10486: * @param start_tile the begin tile of the drag. rubidium@10486: * @param end_tile the end tile of the drag. rubidium@10486: */ rubidium@10641: virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) {} rubidium@10486: rubidium@10486: /** rubidium@10486: * The user moves over the map when a tile highlight mode has been set rubidium@10486: * when the special mouse mode has been set to 'PRESIZE' mode. An rubidium@10486: * example of this is the tile highlight for dock building. rubidium@10486: * @param pt the exact point on the map where the mouse is. rubidium@10486: * @param tile the tile on the map where the mouse is. rubidium@10486: */ rubidium@10641: virtual void OnPlacePresize(Point pt, TileIndex tile) {} rubidium@10486: rubidium@10486: /*** End of the event handling ***/ truelight@0: }; truelight@0: belugas@10589: /** belugas@10589: * Data structure for a window opened from a toolbar belugas@10589: */ belugas@10589: class PickerWindowBase : public Window { belugas@10589: belugas@10589: public: frosch@10686: PickerWindowBase(const WindowDesc *desc, Window *parent) : Window(desc) frosch@10686: { frosch@10686: this->parent = parent; frosch@10686: }; belugas@10589: belugas@10589: virtual ~PickerWindowBase(); belugas@10589: }; belugas@10589: truelight@0: /****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/ truelight@0: enum WindowWidgetBehaviours { rubidium@4344: WWB_PUSHBUTTON = 1 << 5, Darkvater@4938: Darkvater@4938: WWB_MASK = 0xE0, truelight@0: }; truelight@0: truelight@0: rubidium@10083: /** rubidium@10083: * Window widget types rubidium@10083: */ truelight@0: enum WindowWidgetTypes { rubidium@10083: WWT_EMPTY, ///< Empty widget, place holder to reserve space in widget array Darkvater@4938: rubidium@10083: WWT_PANEL, ///< Simple depressed panel rubidium@10083: WWT_INSET, ///< Pressed (inset) panel, most commonly used as combo box _text_ area rubidium@10083: WWT_IMGBTN, ///< Button with image rubidium@10083: WWT_IMGBTN_2, ///< Button with diff image when clicked truelight@0: rubidium@10083: WWT_TEXTBTN, ///< Button with text rubidium@10083: WWT_TEXTBTN_2, ///< Button with diff text when clicked rubidium@10083: WWT_LABEL, ///< Centered label rubidium@10083: WWT_TEXT, ///< Pure simple text rubidium@10083: WWT_MATRIX, ///< List of items underneath each other rubidium@10083: WWT_SCROLLBAR, ///< Vertical scrollbar rubidium@10083: WWT_FRAME, ///< Frame rubidium@10083: WWT_CAPTION, ///< Window caption (window title between closebox and stickybox) rubidium@10083: rubidium@10083: WWT_HSCROLLBAR, ///< Horizontal scrollbar rubidium@10083: WWT_STICKYBOX, ///< Sticky box (normally at top-right of a window) belugas@6443: WWT_SCROLL2BAR, ///< 2nd vertical scrollbar rubidium@10083: WWT_RESIZEBOX, ///< Resize box (normally at bottom-right of a window) rubidium@10083: WWT_CLOSEBOX, ///< Close box (at top-left of a window) peter1138@8831: WWT_DROPDOWN, ///< Raised drop down list (regular) peter1138@8831: WWT_DROPDOWNIN, ///< Inset drop down list (used on game options only) rubidium@9233: WWT_EDITBOX, ///< a textbox for typing (don't forget to call ShowOnScreenKeyboard() when clicked) belugas@6443: WWT_LAST, ///< Last Item. use WIDGETS_END to fill up padding!! Darkvater@4939: Darkvater@4939: WWT_MASK = 0x1F, truelight@0: Darkvater@4938: WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON, rubidium@4434: WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON, rubidium@4434: WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON, truelight@0: }; truelight@0: truelight@867: #define WIDGETS_END WWT_LAST, RESIZE_NONE, 0, 0, 0, 0, 0, 0, STR_NULL darkvater@176: rubidium@10083: /** rubidium@10083: * Window flags rubidium@10083: */ truelight@0: enum WindowFlags { rubidium@10083: WF_TIMEOUT_SHL = 0, ///< Window timeout counter shift rubidium@10083: WF_TIMEOUT_MASK = 7, ///< Window timeout counter bit mask (3 bits), @see WF_TIMEOUT_SHL rubidium@10083: WF_DRAGGING = 1 << 3, ///< Window is being dragged rubidium@10083: WF_SCROLL_UP = 1 << 4, ///< Upper scroll button has been pressed, @see ScrollbarClickHandler() rubidium@10083: WF_SCROLL_DOWN = 1 << 5, ///< Lower scroll button has been pressed, @see ScrollbarClickHandler() rubidium@10083: WF_SCROLL_MIDDLE = 1 << 6, ///< Scrollbar scrolling, @see ScrollbarClickHandler() rubidium@4344: WF_HSCROLL = 1 << 7, rubidium@4344: WF_SIZING = 1 << 8, rubidium@10083: WF_STICKY = 1 << 9, ///< Window is made sticky by user truelight@867: rubidium@10083: WF_DISABLE_VP_SCROLL = 1 << 10, ///< Window does not do autoscroll, @see HandleAutoscroll() truelight@0: rubidium@4344: WF_WHITE_BORDER_ONE = 1 << 11, Darkvater@5667: WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE, rubidium@4344: WF_SCROLL2 = 1 << 13, truelight@0: }; truelight@0: truelight@0: Window *BringWindowToFrontById(WindowClass cls, WindowNumber number); truelight@0: Window *FindWindowFromPt(int x, int y); truelight@0: rubidium@10462: /** rubidium@10462: * Open a new window. rubidium@10462: * @param *desc The pointer to the WindowDesc to be created rubidium@10462: * @param window_number the window number of the new window rubidium@10462: * @param data arbitrary data that is send with the WE_CREATE message rubidium@10462: * @return see Window pointer of the newly created window rubidium@10462: */ rubidium@10462: template rubidium@10525: Wcls *AllocateWindowDescFront(const WindowDesc *desc, int window_number) rubidium@10462: { rubidium@10462: if (BringWindowToFrontById(desc->cls, window_number)) return NULL; rubidium@10525: return new Wcls(desc, window_number); rubidium@10462: } truelight@0: truelight@0: void RelocateAllWindows(int neww, int newh); truelight@0: belugas@6443: /* misc_gui.cpp */ rubidium@7502: void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[]); Darkvater@4834: static inline void GuiShowTooltips(StringID str) Darkvater@4834: { Darkvater@4834: GuiShowTooltipsWithArgs(str, 0, NULL); Darkvater@4834: } belugas@4719: belugas@6443: /* widget.cpp */ Darkvater@2436: int GetWidgetFromPos(const Window *w, int x, int y); truelight@0: belugas@6443: /* window.cpp */ Darkvater@5124: extern Window *_z_windows[]; Darkvater@5124: extern Window **_last_z_window; Darkvater@5124: #define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++) truelight@0: rubidium@10772: /** rubidium@10772: * In certain windows you navigate with the arrow keys. Do not scroll the rubidium@10772: * gameview when here. Bitencoded variable that only allows scrolling if all rubidium@10772: * elements are zero rubidium@10772: */ rubidium@10772: enum { rubidium@10772: SCROLL_CON = 0, rubidium@10772: SCROLL_EDIT = 1, rubidium@10772: SCROLL_SAVE = 2, rubidium@10772: SCROLL_CHAT = 4, rubidium@10772: }; rubidium@10772: rubidium@10772: /** Disable scrolling of the main viewport when an input-window is active. */ rubidium@10772: extern byte _no_scroll; rubidium@10772: rubidium@8764: extern Point _cursorpos_drag_start; truelight@0: rubidium@8764: extern int _scrollbar_start_pos; rubidium@8764: extern int _scrollbar_size; rubidium@8764: extern byte _scroller_click_timeout; truelight@0: rubidium@8764: extern bool _scrolling_scrollbar; rubidium@8764: extern bool _scrolling_viewport; truelight@0: rubidium@8764: extern byte _special_mouse_mode; truelight@0: enum SpecialMouseMode { rubidium@4344: WSM_NONE = 0, truelight@0: WSM_DRAGDROP = 1, rubidium@4344: WSM_SIZING = 2, rubidium@4344: WSM_PRESIZE = 3, truelight@0: }; truelight@0: rubidium@10258: Window *GetCallbackWnd(); rubidium@10258: Window **FindWindowZPosition(const Window *w); rubidium@10258: truelight@0: void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y); truelight@0: bjarni@6073: void ResizeButtons(Window *w, byte left, byte right); bjarni@6073: peter1138@8914: void ResizeWindowForWidget(Window *w, int widget, int delta_x, int delta_y); peter1138@8914: rubidium@10768: void SetVScrollCount(Window *w, int num); rubidium@10768: void SetVScroll2Count(Window *w, int num); rubidium@10768: void SetHScrollCount(Window *w, int num); rubidium@10768: belugas@8489: belugas@8489: /** belugas@8489: * Sets the enabled/disabled status of a widget. belugas@8489: * By default, widgets are enabled. belugas@8489: * On certain conditions, they have to be disabled. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: * @param disab_stat : status to use ie: disabled = true, enabled = false belugas@8489: */ belugas@8489: inline void Window::SetWidgetDisabledState(byte widget_index, bool disab_stat) belugas@8489: { belugas@8489: assert(widget_index < this->widget_count); belugas@8489: SB(this->widget[widget_index].display_flags, WIDG_DISABLED, 1, !!disab_stat); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Sets a widget to disabled. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: */ belugas@8489: inline void Window::DisableWidget(byte widget_index) belugas@8489: { belugas@8489: SetWidgetDisabledState(widget_index, true); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Sets a widget to Enabled. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: */ rubidium@8491: inline void Window::EnableWidget(byte widget_index) rubidium@8491: { rubidium@8491: SetWidgetDisabledState(widget_index, false); rubidium@8491: } belugas@8489: belugas@8489: /** belugas@8489: * Gets the enabled/disabled status of a widget. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: * @return status of the widget ie: disabled = true, enabled = false belugas@8489: */ rubidium@8491: inline bool Window::IsWidgetDisabled(byte widget_index) const belugas@8489: { belugas@8489: assert(widget_index < this->widget_count); belugas@8489: return HasBit(this->widget[widget_index].display_flags, WIDG_DISABLED); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Sets the hidden/shown status of a widget. belugas@8489: * By default, widgets are visible. belugas@8489: * On certain conditions, they have to be hidden. belugas@8489: * @param widget_index index of this widget in the window belugas@8489: * @param hidden_stat status to use ie. hidden = true, visible = false belugas@8489: */ belugas@8489: inline void Window::SetWidgetHiddenState(byte widget_index, bool hidden_stat) belugas@8489: { belugas@8489: assert(widget_index < this->widget_count); belugas@8489: SB(this->widget[widget_index].display_flags, WIDG_HIDDEN, 1, !!hidden_stat); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Sets a widget hidden. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: */ belugas@8489: inline void Window::HideWidget(byte widget_index) belugas@8489: { belugas@8489: SetWidgetHiddenState(widget_index, true); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Sets a widget visible. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: */ belugas@8489: inline void Window::ShowWidget(byte widget_index) belugas@8489: { belugas@8489: SetWidgetHiddenState(widget_index, false); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Gets the visibility of a widget. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: * @return status of the widget ie: hidden = true, visible = false belugas@8489: */ rubidium@8491: inline bool Window::IsWidgetHidden(byte widget_index) const belugas@8489: { belugas@8489: assert(widget_index < this->widget_count); belugas@8489: return HasBit(this->widget[widget_index].display_flags, WIDG_HIDDEN); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Sets the lowered/raised status of a widget. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: * @param lowered_stat : status to use ie: lowered = true, raised = false belugas@8489: */ belugas@8489: inline void Window::SetWidgetLoweredState(byte widget_index, bool lowered_stat) belugas@8489: { belugas@8489: assert(widget_index < this->widget_count); belugas@8489: SB(this->widget[widget_index].display_flags, WIDG_LOWERED, 1, !!lowered_stat); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Invert the lowered/raised status of a widget. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: */ rubidium@8492: inline void Window::ToggleWidgetLoweredState(byte widget_index) belugas@8489: { belugas@8489: assert(widget_index < this->widget_count); belugas@8489: ToggleBit(this->widget[widget_index].display_flags, WIDG_LOWERED); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Marks a widget as lowered. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: */ belugas@8489: inline void Window::LowerWidget(byte widget_index) belugas@8489: { belugas@8489: SetWidgetLoweredState(widget_index, true); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Marks a widget as raised. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: */ belugas@8489: inline void Window::RaiseWidget(byte widget_index) belugas@8489: { belugas@8489: SetWidgetLoweredState(widget_index, false); belugas@8489: } belugas@8489: belugas@8489: /** belugas@8489: * Gets the lowered state of a widget. belugas@8489: * @param widget_index : index of this widget in the window belugas@8489: * @return status of the widget ie: lowered = true, raised= false belugas@8489: */ rubidium@8491: inline bool Window::IsWidgetLowered(byte widget_index) const belugas@8489: { belugas@8489: assert(widget_index < this->widget_count); belugas@8489: return HasBit(this->widget[widget_index].display_flags, WIDG_LOWERED); belugas@8489: } belugas@8489: rubidium@8602: #endif /* WINDOW_GUI_H */