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