2005-07-24 14:12:37 +00:00
/* $Id$ */
2007-02-23 01:48:53 +00:00
/** @file window.h regroups declarations for all windowing system, as well as a few helper functions */
2004-08-09 17:04:08 +00:00
# ifndef WINDOW_H
# define WINDOW_H
2006-10-01 01:32:07 +00:00
# include "macros.h"
2006-08-19 09:31:22 +00:00
# include "string.h"
2006-10-03 14:52:39 +00:00
# include "order.h"
2007-01-10 18:56:51 +00:00
# include "rail.h"
2007-05-21 21:58:31 +00:00
# include "road.h"
2007-01-10 18:56:51 +00:00
# include "airport.h"
2007-05-18 17:31:41 +00:00
# include "vehicle.h"
2006-08-19 09:31:22 +00:00
2007-03-07 12:11:48 +00:00
struct WindowEvent ;
2004-08-09 17:04:08 +00:00
typedef void WindowProc ( Window * w , WindowEvent * e ) ;
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
AFTER window - creation , with :
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 01:33:27 +00: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 21:10:14 +00: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 21:10:14 +00:00
} ;
2007-03-07 12:11:48 +00:00
struct Widget {
2007-02-23 01:48:53 +00:00
byte type ; ///< Widget type, see WindowWidgetTypes
byte display_flags ; ///< Resize direction, alignment, etc. during resizing, see ResizeFlags
2006-09-04 15:44:28 +00: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 15:44:28 +00: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 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
enum FrameFlags {
2007-01-10 18:56:51 +00:00
FR_NONE = 0x00 ,
2005-06-15 17:27:14 +00:00
FR_TRANSPARENT = 0x01 , ///< Makes the background transparent if set
FR_BORDERONLY = 0x10 , ///< Draw border only, no background
FR_LOWERED = 0x20 , ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed)
FR_DARKENED = 0x40 , ///< 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 06:07:57 +00:00
2007-01-10 18:56:51 +00:00
DECLARE_ENUM_AS_BIT_SET ( FrameFlags ) ;
2006-08-29 06:07:57 +00:00
void DrawFrameRect ( int left , int top , int right , int bottom , int color , FrameFlags flags ) ;
2005-06-15 17:27:14 +00:00
2006-09-23 02:39:24 +00:00
enum WindowEventCodes {
2006-12-29 13:59:48 +00:00
WE_CREATE ,
WE_DESTROY ,
WE_PAINT ,
WE_KEYPRESS ,
WE_CLICK ,
2007-06-22 10:57:53 +00:00
WE_DOUBLE_CLICK ,
2006-12-29 13:59:48 +00:00
WE_RCLICK ,
WE_MOUSEOVER ,
WE_MOUSELOOP ,
WE_MOUSEWHEEL ,
WE_TICK ,
WE_4 ,
WE_TIMEOUT ,
WE_PLACE_OBJ ,
WE_ABORT_PLACE_OBJ ,
WE_ON_EDIT_TEXT ,
WE_ON_EDIT_TEXT_CANCEL ,
WE_POPUPMENU_SELECT ,
WE_POPUPMENU_OVER ,
WE_DRAGDROP ,
WE_PLACE_DRAG ,
WE_PLACE_MOUSEUP ,
WE_PLACE_PRESIZE ,
WE_DROPDOWN_SELECT ,
WE_RESIZE ,
WE_MESSAGE ,
WE_SCROLL ,
WE_INVALIDATE_DATA ,
2006-09-23 02:39:24 +00:00
} ;
struct WindowEvent {
2004-08-09 17:04:08 +00:00
byte event ;
2006-09-23 02:39:24 +00:00
union {
struct {
Point pt ;
int widget ;
} click ;
struct {
Point pt ;
TileIndex tile ;
TileIndex starttile ;
2007-05-23 12:45:56 +00:00
byte select_method ;
byte select_proc ;
2006-09-23 02:39:24 +00:00
} place ;
struct {
Point pt ;
int widget ;
} dragdrop ;
struct {
Point size ;
Point diff ;
} sizing ;
struct {
char * str ;
} edittext ;
struct {
Point pt ;
} popupmenu ;
struct {
int button ;
int index ;
} dropdown ;
struct {
Point pt ;
int widget ;
} mouseover ;
struct {
2007-02-23 01:48:53 +00:00
bool cont ; ///< continue the search? (default true)
uint16 key ; ///< 16-bit Unicode value of the key
uint16 keycode ; ///< untranslated key (including shift-state)
2006-09-23 02:39:24 +00:00
} keypress ;
struct {
2007-02-23 01:48:53 +00:00
int msg ; ///< message to be sent
int wparam ; ///< additional message-specific information
int lparam ; ///< additional message-specific information
2006-09-23 02:39:24 +00:00
} message ;
struct {
2007-02-23 01:48:53 +00:00
Point delta ; ///< delta position against position of last call
2006-09-23 02:39:24 +00:00
} scroll ;
struct {
2007-02-23 01:48:53 +00:00
int wheel ; ///< how much was 'wheel'd'
2006-09-23 02:39:24 +00:00
} wheel ;
} we ;
2004-08-09 17:04:08 +00:00
} ;
2007-03-07 12:11:48 +00:00
struct WindowDesc {
2007-07-27 12:49:04 +00:00
int16 left , top , minimum_width , minimum_height , default_width , default_height ;
2005-12-24 15:01:17 +00:00
WindowClass cls ;
WindowClass parent_cls ;
2004-08-09 17:04:08 +00:00
uint32 flags ;
const Widget * widgets ;
WindowProc * proc ;
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2006-12-29 13:59:48 +00:00
enum WindowDefaultFlag {
2007-02-23 01:48:53 +00:00
WDF_STD_TOOLTIPS = 1 , ///< use standard routine when displaying tooltips
WDF_DEF_WIDGET = 2 , ///< default widget control for some widgets in the on click event
WDF_STD_BTN = 4 , ///< default handling for close and drag widgets (widget no 0 and 1)
WDF_UNCLICK_BUTTONS = 16 , ///< Unclick buttons when the window event times out */
WDF_STICKY_BUTTON = 32 , ///< Set window to sticky mode; they are not closed unless closed with 'X' (widget 2)
WDF_RESIZABLE = 64 , ///< A window can be resized
WDF_MODAL = 128 , ///< The window is a modal child of some other window, meaning the parent is 'inactive'
2004-08-09 17:04:08 +00:00
} ;
/* can be used as x or y coordinates 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 17:04:08 +00:00
} ;
2007-03-07 12:11:48 +00:00
struct Textbuf {
2007-02-23 01:48:53 +00:00
char * buf ; ///< buffer in which text is saved
uint16 maxlength , maxwidth ; ///< the maximum size of the buffer. Maxwidth specifies screensize in pixels, maxlength is in bytes
uint16 length , width ; ///< the current size of the string. Width specifies screensize in pixels, length is in bytes
bool caret ; ///< is the caret ("_") visible or not
uint16 caretpos ; ///< the current position of the caret in the buffer, in bytes
uint16 caretxoffs ; ///< the current position of the caret in pixels
2007-03-07 12:11:48 +00:00
} ;
2005-02-21 18:59:54 +00:00
2004-08-09 17:04:08 +00:00
# define WP(ptr,str) (*(str*)(ptr)->custom)
2006-01-28 11:52:20 +00:00
/* You cannot 100% reliably calculate the biggest custom struct as
* the number of pointers in it and alignment will have a huge impact .
2006-08-19 09:31:22 +00:00
* 96 is the largest window - size for 64 - bit machines currently */
# define WINDOW_CUSTOM_SIZE 96
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct Scrollbar {
2004-08-16 13:09:52 +00:00
uint16 count , cap , pos ;
2007-03-07 12:11:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct ResizeInfo {
2007-02-23 01:48:53 +00:00
uint width ; ///< Minimum width and height
2005-01-03 19:45:18 +00:00
uint height ;
2007-02-23 01:48:53 +00:00
uint step_width ; ///< In how big steps the width and height go
2005-01-03 19:45:18 +00:00
uint step_height ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-03 19:45:18 +00:00
2007-03-07 12:11:48 +00:00
struct WindowMessage {
int msg ;
int wparam ;
int lparam ;
} ;
2005-04-05 21:03:30 +00:00
2004-08-09 17:04:08 +00:00
struct Window {
uint16 flags4 ;
WindowClass window_class ;
WindowNumber window_number ;
2005-01-03 19:45:18 +00:00
int left , top ;
int width , height ;
2004-08-09 17:04:08 +00:00
2005-01-02 17:23:04 +00:00
Scrollbar hscroll , vscroll , vscroll2 ;
2005-01-03 19:45:18 +00:00
ResizeInfo resize ;
2004-08-09 17:04:08 +00:00
byte caption_color ;
WindowProc * wndproc ;
ViewPort * viewport ;
2005-01-03 19:45:18 +00:00
const Widget * original_widget ;
2006-06-27 21:25:53 +00:00
Widget * widget ;
2006-12-04 13:36:27 +00:00
uint widget_count ;
2004-08-09 17:04:08 +00:00
uint32 desc_flags ;
2005-11-10 15:23:55 +00:00
WindowMessage message ;
2006-12-29 17:07:41 +00:00
Window * parent ;
2004-09-05 14:20:36 +00:00
byte custom [ WINDOW_CUSTOM_SIZE ] ;
2004-08-09 17:04:08 +00:00
} ;
2007-03-07 12:11:48 +00:00
struct querystr_d {
2006-08-19 09:31:22 +00:00
StringID caption ;
Textbuf text ;
const char * orig ;
CharSetFilter afilter ;
2006-12-30 01:17:53 +00:00
bool handled ;
2007-03-07 12:11:48 +00:00
} ;
2006-08-19 09:31:22 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( querystr_d ) ) ;
2007-04-26 07:41:24 +00:00
struct chatquerystr_d : public querystr_d {
int dest ;
} ;
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( chatquerystr_d ) ) ;
2007-03-07 12:11:48 +00:00
struct menu_d {
2007-02-23 01:48:53 +00:00
byte item_count ; ///< follow_vehicle
byte sel_index ; ///< scrollpos_x
byte main_button ; ///< scrollpos_y
2004-08-09 17:04:08 +00:00
byte action_id ;
2007-02-23 01:48:53 +00:00
StringID string_id ; ///< unk30
uint16 checked_items ; ///< unk32
2005-07-28 08:49:29 +00:00
byte disabled_items ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( menu_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct def_d {
2004-08-09 17:04:08 +00:00
int16 data_1 , data_2 , data_3 ;
int16 data_4 , data_5 ;
2005-11-04 14:01:44 +00:00
bool close ;
2004-08-09 17:04:08 +00:00
byte byte_1 ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( def_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct void_d {
2004-08-09 17:04:08 +00:00
void * data ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( void_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct tree_d {
2005-11-04 14:01:44 +00:00
uint16 base ;
uint16 count ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( tree_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct tooltips_d {
2004-08-09 17:04:08 +00:00
StringID string_id ;
2006-10-12 15:13:40 +00:00
byte paramcount ;
2007-06-21 19:08:47 +00:00
uint64 params [ 5 ] ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( tooltips_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct buildvehicle_d {
2007-05-18 17:31:41 +00:00
VehicleType vehicle_type ;
2006-11-30 16:03:12 +00:00
union {
2007-01-10 18:56:51 +00:00
RailTypeByte railtype ;
2007-02-15 20:16:33 +00:00
AirportFTAClass : : Flags flags ;
2007-05-21 21:58:31 +00:00
RoadTypes roadtypes ;
2006-11-30 16:03:12 +00:00
} filter ;
2007-02-23 01:48:53 +00:00
byte sel_index ; ///< deprecated value, used for 'unified' ship and road
2006-11-30 16:03:12 +00:00
bool descending_sort_order ;
2006-10-07 22:58:25 +00:00
byte sort_criteria ;
2007-01-21 23:13:46 +00:00
bool regenerate_list ;
2005-10-07 07:35:15 +00:00
EngineID sel_engine ;
EngineID rename_engine ;
2006-11-30 16:03:12 +00:00
EngineList eng_list ;
2007-03-07 12:11:48 +00:00
} ;
2006-10-10 07:56:23 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( buildvehicle_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct replaceveh_d {
2005-01-02 17:23:04 +00:00
byte sel_index [ 2 ] ;
2005-12-13 09:57:07 +00:00
EngineID sel_engine [ 2 ] ;
2005-01-02 17:23:04 +00:00
uint16 count [ 2 ] ;
2007-02-23 01:48:53 +00:00
bool wagon_btnstate ; ///< true means engine is selected
2007-02-06 11:11:12 +00:00
EngineList list [ 2 ] ;
bool update_left ;
bool update_right ;
bool init_lists ;
2007-05-19 09:40:18 +00:00
GroupID sel_group ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( replaceveh_d ) ) ;
2005-01-02 17:23:04 +00:00
2007-03-07 12:11:48 +00:00
struct depot_d {
2004-08-09 17:04:08 +00:00
VehicleID sel ;
2007-05-18 17:31:41 +00:00
VehicleType type ;
2006-10-05 12:59:28 +00:00
bool generate_list ;
2006-09-24 15:01:02 +00:00
uint16 engine_list_length ;
uint16 wagon_list_length ;
uint16 engine_count ;
uint16 wagon_count ;
Vehicle * * vehicle_list ;
Vehicle * * wagon_list ;
2007-03-07 12:11:48 +00:00
} ;
2006-09-26 16:47:51 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( depot_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct order_d {
2004-08-09 17:04:08 +00:00
int sel ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( order_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct traindetails_d {
2004-08-09 17:04:08 +00:00
byte tab ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( traindetails_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct smallmap_d {
2005-01-03 08:50:44 +00:00
int32 scroll_x ;
int32 scroll_y ;
int32 subscroll ;
2007-03-07 12:11:48 +00:00
} ;
2006-08-20 11:51:10 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( smallmap_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct facesel_d {
2004-08-09 17:04:08 +00:00
uint32 face ;
byte gender ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( facesel_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct refit_d {
2004-08-09 17:04:08 +00:00
int sel ;
2006-10-01 12:25:31 +00:00
struct RefitOption * cargo ;
2006-10-01 12:00:32 +00:00
struct RefitList * list ;
uint length ;
2006-10-03 14:52:39 +00:00
VehicleOrderID order ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( refit_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct vp_d {
2005-07-17 20:14:58 +00:00
VehicleID follow_vehicle ;
2005-01-03 08:50:44 +00:00
int32 scrollpos_x ;
int32 scrollpos_y ;
2007-05-28 16:46:16 +00:00
int32 dest_scrollpos_x ;
int32 dest_scrollpos_y ;
2007-03-07 12:11:48 +00:00
} ;
2006-11-18 13:55:44 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( vp_d ) ) ;
2005-01-14 00:14:13 +00:00
2007-03-07 12:11:48 +00:00
struct news_d {
2004-08-09 17:04:08 +00:00
uint16 follow_vehicle ;
2005-01-03 08:50:44 +00:00
int32 scrollpos_x ;
int32 scrollpos_y ;
2007-05-28 16:46:16 +00:00
int32 dest_scrollpos_x ;
int32 dest_scrollpos_y ;
2004-08-09 17:04:08 +00:00
NewsItem * ni ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( news_d ) ) ;
2004-08-09 17:04:08 +00:00
2007-03-07 12:11:48 +00:00
struct highscore_d {
2005-01-13 16:28:47 +00:00
uint32 background_img ;
int8 rank ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( highscore_d ) ) ;
2005-01-13 16:28:47 +00:00
2007-03-07 12:11:48 +00:00
struct scroller_d {
2005-01-13 16:28:47 +00:00
int height ;
uint16 counter ;
2007-03-07 12:11:48 +00:00
} ;
2005-01-14 00:14:13 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( scroller_d ) ) ;
2005-01-03 16:45:42 +00:00
2007-03-07 12:11:48 +00:00
enum SortListFlags {
2007-03-01 01:24:44 +00:00
VL_NONE = 0x00 , ///< no sort
2007-02-23 01:48:53 +00:00
VL_DESC = 0x01 , ///< sort descending or ascending
VL_RESORT = 0x02 , ///< instruct the code to resort the list in the next loop
VL_REBUILD = 0x04 , ///< create sort-listing to use for qsort and friends
2007-01-10 18:56:51 +00:00
VL_END = 0x08
2007-03-07 12:11:48 +00:00
} ;
2004-12-10 18:16:08 +00:00
2007-01-10 18:56:51 +00:00
DECLARE_ENUM_AS_BIT_SET ( SortListFlags ) ;
2007-03-07 12:11:48 +00:00
struct Listing {
2007-02-23 01:48:53 +00:00
bool order ; ///< Ascending/descending
byte criteria ; ///< Sorting criteria
2007-03-07 12:11:48 +00:00
} ;
2004-12-10 18:16:08 +00:00
2007-03-07 12:11:48 +00:00
struct list_d {
2007-02-23 01:48:53 +00:00
uint16 list_length ; ///< length of the list being sorted
byte sort_type ; ///< what criteria to sort on
SortListFlags flags ; ///< used to control sorting/resorting/etc.
uint16 resort_timer ; ///< resort list after a given amount of ticks if set
2007-03-07 12:11:48 +00:00
} ;
2006-01-26 17:10:11 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( list_d ) ) ;
2007-03-07 12:11:48 +00:00
struct message_d {
2005-04-05 21:03:30 +00:00
int msg ;
int wparam ;
int lparam ;
2007-03-07 12:11:48 +00:00
} ;
2005-04-05 21:03:30 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( message_d ) ) ;
2007-03-07 12:11:48 +00:00
struct dropdown_d {
2005-11-22 14:02:45 +00:00
uint32 disabled_state ;
uint32 hidden_state ;
2005-11-14 08:42:45 +00:00
WindowClass parent_wnd_class ;
WindowNumber parent_wnd_num ;
byte parent_button ;
byte num_items ;
byte selected_index ;
const StringID * items ;
byte click_delay ;
bool drag_mode ;
2007-03-07 12:11:48 +00:00
} ;
2005-11-14 08:42:45 +00:00
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( dropdown_d ) ) ;
2007-05-19 09:40:18 +00:00
struct vehiclelist_d {
const Vehicle * * sort_list ; // List of vehicles (sorted)
Listing * _sorting ; // pointer to the appropiate subcategory of _sorting
uint16 length_of_sort_list ; // Keeps track of how many vehicle pointers sort list got space for
VehicleType vehicle_type ; // The vehicle type that is sorted
list_d l ; // General list struct
} ;
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( vehiclelist_d ) ) ;
struct grouplist_d {
const Group * * sort_list ;
list_d l ; // General list struct
} ;
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( grouplist_d ) ) ;
struct groupveh_d : vehiclelist_d {
GroupID group_sel ;
VehicleID vehicle_sel ;
grouplist_d gl ;
} ;
assert_compile ( WINDOW_CUSTOM_SIZE > = sizeof ( groupveh_d ) ) ;
2004-08-09 17:04:08 +00:00
/****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/
enum WindowWidgetBehaviours {
2006-08-22 14:38:37 +00:00
WWB_PUSHBUTTON = 1 < < 5 ,
2006-10-24 14:15:17 +00:00
WWB_MASK = 0xE0 ,
2004-08-09 17:04:08 +00:00
} ;
enum WindowWidgetTypes {
2006-10-24 16:27:18 +00:00
WWT_EMPTY ,
2007-02-23 01:48:53 +00:00
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
2006-10-24 16:27:18 +00:00
2007-02-23 01:48:53 +00:00
WWT_TEXTBTN , ///< button with text
WWT_TEXTBTN_2 , ///< button with diff text when clicked
WWT_LABEL , ///< centered label
2007-03-10 03:25:15 +00:00
WWT_TEXT , ///< pure simple text
2006-10-24 16:27:18 +00:00
WWT_MATRIX ,
WWT_SCROLLBAR ,
2007-02-23 01:48:53 +00:00
WWT_FRAME , ///< frame
2006-10-24 16:27:18 +00:00
WWT_CAPTION ,
WWT_HSCROLLBAR ,
WWT_STICKYBOX ,
2007-02-23 01:48:53 +00:00
WWT_SCROLL2BAR , ///< 2nd vertical scrollbar
2006-10-24 16:27:18 +00:00
WWT_RESIZEBOX ,
WWT_CLOSEBOX ,
2007-02-23 01:48:53 +00:00
WWT_LAST , ///< Last Item. use WIDGETS_END to fill up padding!!
2006-10-24 16:27:18 +00:00
WWT_MASK = 0x1F ,
2004-08-09 17:04:08 +00:00
2006-10-24 14:15:17 +00:00
WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON ,
2006-08-28 18:53:03 +00:00
WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON ,
WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON ,
2004-08-09 17:04:08 +00: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 21:48:09 +00:00
2004-08-09 17:04:08 +00:00
enum WindowFlags {
2006-08-22 14:38:37 +00:00
WF_TIMEOUT_SHL = 0 ,
WF_TIMEOUT_MASK = 7 ,
WF_DRAGGING = 1 < < 3 ,
WF_SCROLL_UP = 1 < < 4 ,
WF_SCROLL_DOWN = 1 < < 5 ,
WF_SCROLL_MIDDLE = 1 < < 6 ,
WF_HSCROLL = 1 < < 7 ,
WF_SIZING = 1 < < 8 ,
WF_STICKY = 1 < < 9 ,
2005-01-03 19:45:18 +00:00
2004-08-09 17:04:08 +00:00
WF_DISABLE_VP_SCROLL = 1 < < 10 ,
2006-08-22 14:38:37 +00: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 14:38:37 +00:00
WF_SCROLL2 = 1 < < 13 ,
2004-08-09 17:04:08 +00:00
} ;
2007-02-23 01:48:53 +00:00
/* window.cpp */
2004-08-09 17:04:08 +00:00
void CallWindowEventNP ( Window * w , int event ) ;
2007-03-07 11:47:46 +00:00
void CallWindowTickEvent ( ) ;
2006-07-26 03:33:12 +00:00
void SetWindowDirty ( const Window * w ) ;
2007-01-10 18:56:51 +00:00
void SendWindowMessage ( WindowClass wnd_class , WindowNumber wnd_num , int msg , int wparam , int lparam ) ;
void SendWindowMessageClass ( WindowClass wnd_class , int msg , int wparam , int lparam ) ;
2004-08-09 17:04:08 +00:00
Window * FindWindowById ( WindowClass cls , WindowNumber number ) ;
void DeleteWindow ( Window * w ) ;
2006-11-13 20:33:51 +00:00
void DeletePlayerWindows ( PlayerID pi ) ;
void ChangeWindowOwner ( PlayerID old_player , PlayerID new_player ) ;
2004-08-09 17:04:08 +00:00
Window * BringWindowToFrontById ( WindowClass cls , WindowNumber number ) ;
Window * FindWindowFromPt ( int x , int y ) ;
2006-07-26 03:33:12 +00:00
bool IsWindowOfPrototype ( const Window * w , const Widget * widget ) ;
2005-01-03 19:45:18 +00:00
void AssignWidgetToWindow ( Window * w , const Widget * widget ) ;
2004-08-09 17:04:08 +00:00
Window * AllocateWindow (
int x ,
int y ,
int width ,
int height ,
2004-09-05 14:20:36 +00:00
WindowProc * proc ,
2004-08-09 17:04:08 +00:00
WindowClass cls ,
const Widget * widget ) ;
Window * AllocateWindowDesc ( const WindowDesc * desc ) ;
2006-09-02 20:09:16 +00:00
Window * AllocateWindowDescFront ( const WindowDesc * desc , int window_number ) ;
2004-08-09 17:04:08 +00:00
2006-11-18 00:14:43 +00:00
void DrawWindowViewport ( const Window * w ) ;
2006-12-07 00:47:35 +00:00
void ResizeWindow ( Window * w , int x , int y ) ;
2004-08-09 17:04:08 +00:00
2006-10-01 01:32:07 +00:00
/**
* Sets the enabled / disabled status of a widget .
* By default , widgets are enabled .
* On certain conditions , they have to be disabled .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
* @ param disab_stat : status to use ie : disabled = true , enabled = false
*/
static inline void SetWindowWidgetDisabledState ( Window * w , byte widget_index , bool disab_stat )
{
2006-12-04 13:36:27 +00:00
assert ( widget_index < w - > widget_count ) ;
2006-10-06 01:33:27 +00:00
SB ( w - > widget [ widget_index ] . display_flags , WIDG_DISABLED , 1 , ! ! disab_stat ) ;
2006-10-01 01:32:07 +00:00
}
/**
* Sets a widget to disabled .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
*/
static inline void DisableWindowWidget ( Window * w , byte widget_index )
{
SetWindowWidgetDisabledState ( w , widget_index , true ) ;
}
/**
* Sets a widget to Enabled .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
*/
static inline void EnableWindowWidget ( Window * w , byte widget_index )
{
SetWindowWidgetDisabledState ( w , widget_index , false ) ;
}
/**
* Gets the enabled / disabled status of a widget .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
* @ return status of the widget ie : disabled = true , enabled = false
*/
2006-12-04 13:38:45 +00:00
static inline bool IsWindowWidgetDisabled ( const Window * w , byte widget_index )
2006-10-01 01:32:07 +00:00
{
2006-12-04 13:36:27 +00:00
assert ( widget_index < w - > widget_count ) ;
2006-12-04 13:57:04 +00:00
return HASBIT ( w - > widget [ widget_index ] . display_flags , WIDG_DISABLED ) ;
2006-10-01 01:32:07 +00:00
}
/**
* Sets the hidden / shown status of a widget .
* By default , widgets are visible .
* On certain conditions , they have to be hidden .
* @ param w Window on which the widget is located
* @ param widget_index index of this widget in the window
* @ param hidden_stat status to use ie . hidden = true , visible = false
*/
static inline void SetWindowWidgetHiddenState ( Window * w , byte widget_index , bool hidden_stat )
{
2006-12-04 13:36:27 +00:00
assert ( widget_index < w - > widget_count ) ;
2006-10-06 01:33:27 +00:00
SB ( w - > widget [ widget_index ] . display_flags , WIDG_HIDDEN , 1 , ! ! hidden_stat ) ;
2006-10-01 01:32:07 +00:00
}
/**
* Sets a widget hidden .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
*/
static inline void HideWindowWidget ( Window * w , byte widget_index )
{
SetWindowWidgetHiddenState ( w , widget_index , true ) ;
}
/**
* Sets a widget visible .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
*/
static inline void ShowWindowWidget ( Window * w , byte widget_index )
{
SetWindowWidgetHiddenState ( w , widget_index , false ) ;
}
/**
* Gets the visibility of a widget .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
* @ return status of the widget ie : hidden = true , visible = false
*/
2006-12-04 13:38:45 +00:00
static inline bool IsWindowWidgetHidden ( const Window * w , byte widget_index )
2006-10-01 01:32:07 +00:00
{
2006-12-04 13:36:27 +00:00
assert ( widget_index < w - > widget_count ) ;
2006-12-04 13:57:04 +00:00
return HASBIT ( w - > widget [ widget_index ] . display_flags , WIDG_HIDDEN ) ;
2006-10-01 01:32:07 +00:00
}
/**
* Sets the lowered / raised status of a widget .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
2007-04-06 04:10:19 +00:00
* @ param lowered_stat : status to use ie : lowered = true , raised = false
2006-10-01 01:32:07 +00:00
*/
2006-10-04 19:11:43 +00:00
static inline void SetWindowWidgetLoweredState ( Window * w , byte widget_index , bool lowered_stat )
2006-10-01 01:32:07 +00:00
{
2006-12-04 13:36:27 +00:00
assert ( widget_index < w - > widget_count ) ;
2006-10-06 01:33:27 +00:00
SB ( w - > widget [ widget_index ] . display_flags , WIDG_LOWERED , 1 , ! ! lowered_stat ) ;
2006-10-01 01:32:07 +00:00
}
/**
* Invert the lowered / raised status of a widget .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
*/
static inline void ToggleWidgetLoweredState ( Window * w , byte widget_index )
{
2006-12-04 13:36:27 +00:00
assert ( widget_index < w - > widget_count ) ;
2006-10-06 01:33:27 +00:00
TOGGLEBIT ( w - > widget [ widget_index ] . display_flags , WIDG_LOWERED ) ;
2006-10-01 01:32:07 +00:00
}
/**
* Marks a widget as lowered .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
*/
static inline void LowerWindowWidget ( Window * w , byte widget_index )
{
2006-10-04 20:12:39 +00:00
SetWindowWidgetLoweredState ( w , widget_index , true ) ;
2006-10-01 01:32:07 +00:00
}
/**
* Marks a widget as raised .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
*/
static inline void RaiseWindowWidget ( Window * w , byte widget_index )
{
2006-10-04 20:12:39 +00:00
SetWindowWidgetLoweredState ( w , widget_index , false ) ;
2006-10-01 01:32:07 +00:00
}
/**
* Gets the lowered state of a widget .
* @ param w : Window on which the widget is located
* @ param widget_index : index of this widget in the window
* @ return status of the widget ie : lowered = true , raised = false
*/
2006-12-04 13:38:45 +00:00
static inline bool IsWindowWidgetLowered ( const Window * w , byte widget_index )
2006-10-01 01:32:07 +00:00
{
2006-12-04 13:36:27 +00:00
assert ( widget_index < w - > widget_count ) ;
2006-10-06 01:33:27 +00:00
return HASBIT ( w - > widget [ widget_index ] . display_flags , WIDG_LOWERED ) ;
2006-10-01 01:32:07 +00:00
}
2007-03-07 11:47:46 +00:00
void InitWindowSystem ( ) ;
void UnInitWindowSystem ( ) ;
void ResetWindowSystem ( ) ;
2005-09-18 20:56:44 +00:00
int GetMenuItemIndex ( const Window * w , int x , int y ) ;
2007-03-07 11:47:46 +00:00
void InputLoop ( ) ;
2006-07-26 03:33:12 +00:00
void InvalidateWidget ( const Window * w , byte widget_index ) ;
2006-10-07 14:30:13 +00:00
void InvalidateThisWindowData ( Window * w ) ;
2006-10-05 12:59:28 +00:00
void InvalidateWindowData ( WindowClass cls , WindowNumber number ) ;
2006-10-03 20:16:20 +00:00
void RaiseWindowButtons ( Window * w ) ;
2004-08-09 17:04:08 +00:00
void RelocateAllWindows ( int neww , int newh ) ;
2004-11-13 18:15:03 +00:00
int PositionMainToolbar ( Window * w ) ;
2006-10-06 21:10:14 +00:00
void CDECL SetWindowWidgetsDisabledState ( Window * w , bool disab_stat , int widgets , . . . ) ;
void CDECL SetWindowWidgetsHiddenState ( Window * w , bool hidden_stat , int widgets , . . . ) ;
void CDECL SetWindowWidgetsLoweredState ( Window * w , bool lowered_stat , int widgets , . . . ) ;
2004-08-09 17:04:08 +00:00
2007-02-23 01:48:53 +00:00
/* misc_gui.cpp */
2007-06-21 19:08:47 +00:00
void GuiShowTooltipsWithArgs ( StringID str , uint paramcount , const uint64 params [ ] ) ;
2006-10-12 15:13:40 +00:00
static inline void GuiShowTooltips ( StringID str )
{
GuiShowTooltipsWithArgs ( str , 0 , NULL ) ;
}
2006-10-03 20:16:20 +00:00
2007-02-23 01:48:53 +00:00
/* widget.cpp */
2005-09-18 20:56:44 +00:00
int GetWidgetFromPos ( const Window * w , int x , int y ) ;
void DrawWindowWidgets ( const Window * w ) ;
2005-09-23 07:44:03 +00:00
void ShowDropDownMenu ( Window * w , const StringID * strings , int selected , int button , uint32 disabled_mask , uint32 hidden_mask ) ;
2004-08-09 17:04:08 +00:00
void HandleButtonClick ( Window * w , byte widget ) ;
2007-03-07 11:47:46 +00:00
Window * GetCallbackWnd ( ) ;
void DeleteNonVitalWindows ( ) ;
void DeleteAllNonVitalWindows ( ) ;
void HideVitalWindows ( ) ;
void ShowVitalWindows ( ) ;
2006-11-18 16:47:02 +00:00
Window * * FindWindowZPosition ( const Window * w ) ;
2004-08-09 17:04:08 +00: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 17:04:08 +00:00
VARDEF Point _cursorpos_drag_start ;
VARDEF int _scrollbar_start_pos ;
VARDEF int _scrollbar_size ;
VARDEF byte _scroller_click_timeout ;
VARDEF bool _scrolling_scrollbar ;
VARDEF bool _scrolling_viewport ;
VARDEF bool _popup_menu_active ;
VARDEF byte _special_mouse_mode ;
enum SpecialMouseMode {
2006-08-22 14:38:37 +00:00
WSM_NONE = 0 ,
2004-08-09 17:04:08 +00:00
WSM_DRAGDROP = 1 ,
2006-08-22 14:38:37 +00:00
WSM_SIZING = 2 ,
WSM_PRESIZE = 3 ,
2004-08-09 17:04:08 +00:00
} ;
void ScrollbarClickHandler ( Window * w , const Widget * wi , int x , int y ) ;
2007-01-24 02:36:55 +00:00
/** Evenly distribute some widgets when resizing horizontally (often a button row)
2007-01-24 14:32:20 +00:00
* The widgets are presumed to be in a line and numberef from left to right ( without gaps )
2007-01-24 02:36:55 +00:00
* @ param w widow to modify
* @ param left The leftmost widget to resize
2007-01-24 14:32:20 +00:00
* @ param right The rightmost widget to resize . Since right side of it is used , remember to set it to RESIZE_RIGHT
2007-01-24 02:36:55 +00:00
*/
void ResizeButtons ( Window * w , byte left , byte right ) ;
2004-08-09 17:04:08 +00:00
# endif /* WINDOW_H */