src/window_gui.h
branchNewGRF_ports
changeset 6872 1c4a4a609f85
child 6877 889301acc299
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file window_gui.h Functions, definitions and such used only by the GUI. */
       
     4 
       
     5 #ifndef WINDOW_GUI_H
       
     6 #define WINDOW_GUI_H
       
     7 
       
     8 #include "core/bitmath_func.hpp"
       
     9 #include "vehicle_type.h"
       
    10 #include "viewport_type.h"
       
    11 #include "player_type.h"
       
    12 #include "strings_type.h"
       
    13 
       
    14 /**
       
    15  * The maximum number of windows that can be opened.
       
    16  */
       
    17 static const int MAX_NUMBER_OF_WINDOWS = 25;
       
    18 
       
    19 typedef void WindowProc(Window *w, WindowEvent *e);
       
    20 
       
    21 /* How the resize system works:
       
    22     First, you need to add a WWT_RESIZEBOX to the widgets, and you need
       
    23      to add the flag WDF_RESIZABLE to the window. Now the window is ready
       
    24      to resize itself.
       
    25     As you may have noticed, all widgets have a RESIZE_XXX in their line.
       
    26      This lines controls how the widgets behave on resize. RESIZE_NONE means
       
    27      it doesn't do anything. Any other option let's one of the borders
       
    28      move with the changed width/height. So if a widget has
       
    29      RESIZE_RIGHT, and the window is made 5 pixels wider by the user,
       
    30      the right of the window will also be made 5 pixels wider.
       
    31     Now, what if you want to clamp a widget to the bottom? Give it the flag
       
    32      RESIZE_TB. This is RESIZE_TOP + RESIZE_BOTTOM. Now if the window gets
       
    33      5 pixels bigger, both the top and bottom gets 5 bigger, so the whole
       
    34      widgets moves downwards without resizing, and appears to be clamped
       
    35      to the bottom. Nice aint it?
       
    36    You should know one more thing about this system. Most windows can't
       
    37     handle an increase of 1 pixel. So there is a step function, which
       
    38     let the windowsize only be changed by X pixels. You configure this
       
    39     after making the window, like this:
       
    40       w->resize.step_height = 10;
       
    41     Now the window will only change in height in steps of 10.
       
    42    You can also give a minimum width and height. The default value is
       
    43     the default height/width of the window itself. You can change this
       
    44     AFTER window-creation, with:
       
    45      w->resize.width or w->resize.height.
       
    46    That was all.. good luck, and enjoy :) -- TrueLight */
       
    47 
       
    48 enum ResizeFlag {
       
    49 	RESIZE_NONE   = 0,  ///< no resize required
       
    50 
       
    51 	RESIZE_LEFT   = 1,  ///< left resize flag
       
    52 	RESIZE_RIGHT  = 2,  ///< rigth resize flag
       
    53 	RESIZE_TOP    = 4,  ///< top resize flag
       
    54 	RESIZE_BOTTOM = 8,  ///< bottom resize flag
       
    55 
       
    56 	RESIZE_LR     = RESIZE_LEFT  | RESIZE_RIGHT,   ///<  combination of left and right resize flags
       
    57 	RESIZE_RB     = RESIZE_RIGHT | RESIZE_BOTTOM,  ///<  combination of right and bottom resize flags
       
    58 	RESIZE_TB     = RESIZE_TOP   | RESIZE_BOTTOM,  ///<  combination of top and bottom resize flags
       
    59 	RESIZE_LRB    = RESIZE_LEFT  | RESIZE_RIGHT  | RESIZE_BOTTOM, ///< combination of left, right and bottom resize flags
       
    60 	RESIZE_LRTB   = RESIZE_LEFT  | RESIZE_RIGHT  | RESIZE_TOP | RESIZE_BOTTOM,  ///<  combination of all resize flags
       
    61 	RESIZE_RTB    = RESIZE_RIGHT | RESIZE_TOP    | RESIZE_BOTTOM, ///<  combination of right, top and bottom resize flag
       
    62 
       
    63 	/* The following flags are used by the system to specify what is disabled, hidden, or clicked
       
    64 	 * They are used in the same place as the above RESIZE_x flags, Widget visual_flags.
       
    65 	 * These states are used in exceptions. If nothing is specified, they will indicate
       
    66 	 * Enabled, visible or unclicked widgets*/
       
    67 	WIDG_DISABLED = 4,  ///< widget is greyed out, not available
       
    68 	WIDG_HIDDEN   = 5,  ///< widget is made invisible
       
    69 	WIDG_LOWERED  = 6,  ///< widget is paint lowered, a pressed button in fact
       
    70 };
       
    71 
       
    72 enum {
       
    73 	WIDGET_LIST_END = -1, ///< indicate the end of widgets' list for vararg functions
       
    74 };
       
    75 
       
    76 struct Widget {
       
    77 	byte type;                        ///< Widget type, see WindowWidgetTypes
       
    78 	byte display_flags;               ///< Resize direction, alignment, etc. during resizing, see ResizeFlags
       
    79 	byte color;                       ///< Widget colour, see docs/ottd-colourtext-palette.png
       
    80 	int16 left, right, top, bottom;   ///< The position offsets inside the window
       
    81 	uint16 data;                      ///< The String/Image or special code (list-matrixes) of a widget
       
    82 	StringID tooltips;                ///< Tooltips that are shown when rightclicking on a widget
       
    83 };
       
    84 
       
    85 enum FrameFlags {
       
    86 	FR_NONE         =  0,
       
    87 	FR_TRANSPARENT  =  1 << 0,  ///< Makes the background transparent if set
       
    88 	FR_BORDERONLY   =  1 << 4,  ///< Draw border only, no background
       
    89 	FR_LOWERED      =  1 << 5,  ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed)
       
    90 	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)
       
    91 };
       
    92 
       
    93 DECLARE_ENUM_AS_BIT_SET(FrameFlags);
       
    94 
       
    95 void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags);
       
    96 
       
    97 enum WindowEventCodes {
       
    98 	WE_CREATE,
       
    99 	WE_DESTROY,
       
   100 	WE_PAINT,
       
   101 	WE_KEYPRESS,
       
   102 	WE_CLICK,
       
   103 	WE_DOUBLE_CLICK,
       
   104 	WE_RCLICK,
       
   105 	WE_MOUSEOVER,
       
   106 	WE_MOUSELOOP,
       
   107 	WE_MOUSEWHEEL,
       
   108 	WE_TICK,
       
   109 	WE_4,
       
   110 	WE_TIMEOUT,
       
   111 	WE_PLACE_OBJ,
       
   112 	WE_ABORT_PLACE_OBJ,
       
   113 	WE_ON_EDIT_TEXT,
       
   114 	WE_ON_EDIT_TEXT_CANCEL,
       
   115 	WE_POPUPMENU_SELECT,
       
   116 	WE_POPUPMENU_OVER,
       
   117 	WE_DRAGDROP,
       
   118 	WE_PLACE_DRAG,
       
   119 	WE_PLACE_MOUSEUP,
       
   120 	WE_PLACE_PRESIZE,
       
   121 	WE_DROPDOWN_SELECT,
       
   122 	WE_RESIZE,
       
   123 	WE_MESSAGE,
       
   124 	WE_SCROLL,
       
   125 	WE_INVALIDATE_DATA,
       
   126 };
       
   127 
       
   128 struct WindowEvent {
       
   129 	byte event;
       
   130 	union {
       
   131 		struct {
       
   132 			void *data;
       
   133 		} create;
       
   134 
       
   135 		struct {
       
   136 			Point pt;
       
   137 			int widget;
       
   138 		} click;
       
   139 
       
   140 		struct {
       
   141 			Point pt;
       
   142 			TileIndex tile;
       
   143 			TileIndex starttile;
       
   144 			ViewportPlaceMethod select_method;
       
   145 			byte select_proc;
       
   146 		} place;
       
   147 
       
   148 		struct {
       
   149 			Point pt;
       
   150 			int widget;
       
   151 		} dragdrop;
       
   152 
       
   153 		struct {
       
   154 			Point size;
       
   155 			Point diff;
       
   156 		} sizing;
       
   157 
       
   158 		struct {
       
   159 			char *str;
       
   160 		} edittext;
       
   161 
       
   162 		struct {
       
   163 			Point pt;
       
   164 		} popupmenu;
       
   165 
       
   166 		struct {
       
   167 			int button;
       
   168 			int index;
       
   169 		} dropdown;
       
   170 
       
   171 		struct {
       
   172 			Point pt;
       
   173 			int widget;
       
   174 		} mouseover;
       
   175 
       
   176 		struct {
       
   177 			bool cont;      ///< continue the search? (default true)
       
   178 			uint16 key;     ///< 16-bit Unicode value of the key
       
   179 			uint16 keycode; ///< untranslated key (including shift-state)
       
   180 		} keypress;
       
   181 
       
   182 		struct {
       
   183 			int msg;      ///< message to be sent
       
   184 			int wparam;   ///< additional message-specific information
       
   185 			int lparam;   ///< additional message-specific information
       
   186 		} message;
       
   187 
       
   188 		struct {
       
   189 			Point delta;   ///< delta position against position of last call
       
   190 		} scroll;
       
   191 
       
   192 		struct {
       
   193 			int wheel;     ///< how much was 'wheel'd'
       
   194 		} wheel;
       
   195 	} we;
       
   196 };
       
   197 
       
   198 struct WindowDesc {
       
   199 	int16 left, top, minimum_width, minimum_height, default_width, default_height;
       
   200 	WindowClass cls;
       
   201 	WindowClass parent_cls;
       
   202 	uint32 flags;
       
   203 	const Widget *widgets;
       
   204 	WindowProc *proc;
       
   205 };
       
   206 
       
   207 enum WindowDefaultFlag {
       
   208 	WDF_STD_TOOLTIPS    =   1 << 0, ///< use standard routine when displaying tooltips
       
   209 	WDF_DEF_WIDGET      =   1 << 1, ///< default widget control for some widgets in the on click event
       
   210 	WDF_STD_BTN         =   1 << 2, ///< default handling for close and drag widgets (widget no 0 and 1)
       
   211 
       
   212 	WDF_UNCLICK_BUTTONS =   1 << 4, ///< Unclick buttons when the window event times out */
       
   213 	WDF_STICKY_BUTTON   =   1 << 5, ///< Set window to sticky mode; they are not closed unless closed with 'X' (widget 2)
       
   214 	WDF_RESIZABLE       =   1 << 6, ///< A window can be resized
       
   215 	WDF_MODAL           =   1 << 7, ///< The window is a modal child of some other window, meaning the parent is 'inactive'
       
   216 };
       
   217 
       
   218 /* can be used as x or y coordinates to cause a specific placement */
       
   219 enum WindowDefaultPosition {
       
   220 	WDP_AUTO      = -1, ///< Find a place automatically
       
   221 	WDP_CENTER    = -2, ///< Center the window (left/right or top/bottom)
       
   222 	WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar
       
   223 	WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar
       
   224 };
       
   225 
       
   226 #define WP(ptr, str) (*(str*)(ptr)->custom)
       
   227 
       
   228 struct Scrollbar {
       
   229 	uint16 count, cap, pos;
       
   230 };
       
   231 
       
   232 struct ResizeInfo {
       
   233 	uint width; ///< Minimum width and height
       
   234 	uint height;
       
   235 	uint step_width; ///< In how big steps the width and height go
       
   236 	uint step_height;
       
   237 };
       
   238 
       
   239 struct WindowMessage {
       
   240 	int msg;
       
   241 	int wparam;
       
   242 	int lparam;
       
   243 };
       
   244 
       
   245 struct Window {
       
   246 	uint16 flags4;
       
   247 	WindowClass window_class;
       
   248 	WindowNumber window_number;
       
   249 
       
   250 	int left, top;
       
   251 	int width, height;
       
   252 
       
   253 	Scrollbar hscroll, vscroll, vscroll2;
       
   254 	ResizeInfo resize;
       
   255 
       
   256 	byte caption_color;
       
   257 
       
   258 	WindowProc *wndproc;
       
   259 	ViewPort *viewport;
       
   260 	const Widget *original_widget;
       
   261 	Widget *widget;
       
   262 	uint widget_count;
       
   263 	uint32 desc_flags;
       
   264 
       
   265 	WindowMessage message;
       
   266 	Window *parent;
       
   267 	byte custom[WINDOW_CUSTOM_SIZE];
       
   268 
       
   269 	void HandleButtonClick(byte widget);
       
   270 
       
   271 	void SetWidgetDisabledState(byte widget_index, bool disab_stat);
       
   272 	void DisableWidget(byte widget_index);
       
   273 	void EnableWidget(byte widget_index);
       
   274 	bool IsWidgetDisabled(byte widget_index) const;
       
   275 	void SetWidgetHiddenState(byte widget_index, bool hidden_stat);
       
   276 	void HideWidget(byte widget_index);
       
   277 	void ShowWidget(byte widget_index);
       
   278 	bool IsWidgetHidden(byte widget_index) const;
       
   279 	void SetWidgetLoweredState(byte widget_index, bool lowered_stat);
       
   280 	void ToggleWidgetLoweredState(byte widget_index);
       
   281 	void LowerWidget(byte widget_index);
       
   282 	void RaiseWidget(byte widget_index);
       
   283 	bool IsWidgetLowered(byte widget_index) const;
       
   284 
       
   285 	void RaiseButtons();
       
   286 	void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);
       
   287 	void CDECL SetWidgetsHiddenState(bool hidden_stat, int widgets, ...);
       
   288 	void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...);
       
   289 	void InvalidateWidget(byte widget_index) const;
       
   290 };
       
   291 
       
   292 struct menu_d {
       
   293 	byte item_count;      ///< follow_vehicle
       
   294 	byte sel_index;       ///< scrollpos_x
       
   295 	byte main_button;     ///< scrollpos_y
       
   296 	byte action_id;
       
   297 	StringID string_id;   ///< unk30
       
   298 	uint16 checked_items; ///< unk32
       
   299 	byte disabled_items;
       
   300 };
       
   301 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d));
       
   302 
       
   303 struct def_d {
       
   304 	int16 data_1, data_2, data_3;
       
   305 	int16 data_4, data_5;
       
   306 	bool close;
       
   307 	byte byte_1;
       
   308 };
       
   309 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d));
       
   310 
       
   311 struct void_d {
       
   312 	void *data;
       
   313 };
       
   314 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(void_d));
       
   315 
       
   316 struct tree_d {
       
   317 	uint16 base;
       
   318 	uint16 count;
       
   319 };
       
   320 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tree_d));
       
   321 
       
   322 struct tooltips_d {
       
   323 	StringID string_id;
       
   324 	byte paramcount;
       
   325 	uint64 params[5];
       
   326 };
       
   327 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d));
       
   328 
       
   329 struct replaceveh_d {
       
   330 	byte sel_index[2];
       
   331 	EngineID sel_engine[2];
       
   332 	uint16 count[2];
       
   333 	bool wagon_btnstate; ///< true means engine is selected
       
   334 	EngineList list[2];
       
   335 	bool update_left;
       
   336 	bool update_right;
       
   337 	bool init_lists;
       
   338 	GroupID sel_group;
       
   339 };
       
   340 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(replaceveh_d));
       
   341 
       
   342 struct depot_d {
       
   343 	VehicleID sel;
       
   344 	VehicleType type;
       
   345 	bool generate_list;
       
   346 	uint16 engine_list_length;
       
   347 	uint16 wagon_list_length;
       
   348 	uint16 engine_count;
       
   349 	uint16 wagon_count;
       
   350 	Vehicle **vehicle_list;
       
   351 	Vehicle **wagon_list;
       
   352 };
       
   353 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(depot_d));
       
   354 
       
   355 struct order_d {
       
   356 	int sel;
       
   357 };
       
   358 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(order_d));
       
   359 
       
   360 struct vehicledetails_d {
       
   361 	byte tab;
       
   362 };
       
   363 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehicledetails_d));
       
   364 
       
   365 struct smallmap_d {
       
   366 	int32 scroll_x;
       
   367 	int32 scroll_y;
       
   368 	int32 subscroll;
       
   369 };
       
   370 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(smallmap_d));
       
   371 
       
   372 struct refit_d {
       
   373 	int sel;
       
   374 	struct RefitOption *cargo;
       
   375 	struct RefitList *list;
       
   376 	uint length;
       
   377 	VehicleOrderID order;
       
   378 };
       
   379 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(refit_d));
       
   380 
       
   381 struct vp_d {
       
   382 	VehicleID follow_vehicle;
       
   383 	int32 scrollpos_x;
       
   384 	int32 scrollpos_y;
       
   385 	int32 dest_scrollpos_x;
       
   386 	int32 dest_scrollpos_y;
       
   387 };
       
   388 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vp_d));
       
   389 
       
   390 struct news_d {
       
   391 	uint16 follow_vehicle;
       
   392 	int32 scrollpos_x;
       
   393 	int32 scrollpos_y;
       
   394 	int32 dest_scrollpos_x;
       
   395 	int32 dest_scrollpos_y;
       
   396 	NewsItem *ni;
       
   397 };
       
   398 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(news_d));
       
   399 
       
   400 struct highscore_d {
       
   401 	uint32 background_img;
       
   402 	int8 rank;
       
   403 };
       
   404 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(highscore_d));
       
   405 
       
   406 struct scroller_d {
       
   407 	int height;
       
   408 	uint16 counter;
       
   409 };
       
   410 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d));
       
   411 
       
   412 enum SortListFlags {
       
   413 	VL_NONE    = 0,      ///< no sort
       
   414 	VL_DESC    = 1 << 0, ///< sort descending or ascending
       
   415 	VL_RESORT  = 1 << 1, ///< instruct the code to resort the list in the next loop
       
   416 	VL_REBUILD = 1 << 2, ///< create sort-listing to use for qsort and friends
       
   417 	VL_END     = 1 << 3,
       
   418 };
       
   419 
       
   420 DECLARE_ENUM_AS_BIT_SET(SortListFlags);
       
   421 
       
   422 struct Listing {
       
   423 	bool order;    ///< Ascending/descending
       
   424 	byte criteria; ///< Sorting criteria
       
   425 };
       
   426 
       
   427 struct list_d {
       
   428 	uint16 list_length;  ///< length of the list being sorted
       
   429 	byte sort_type;      ///< what criteria to sort on
       
   430 	SortListFlags flags; ///< used to control sorting/resorting/etc.
       
   431 	uint16 resort_timer; ///< resort list after a given amount of ticks if set
       
   432 };
       
   433 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(list_d));
       
   434 
       
   435 struct message_d {
       
   436 	int msg;
       
   437 	int wparam;
       
   438 	int lparam;
       
   439 };
       
   440 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(message_d));
       
   441 
       
   442 struct vehiclelist_d {
       
   443 	const Vehicle** sort_list;  // List of vehicles (sorted)
       
   444 	Listing *_sorting;          // pointer to the appropiate subcategory of _sorting
       
   445 	uint16 length_of_sort_list; // Keeps track of how many vehicle pointers sort list got space for
       
   446 	VehicleType vehicle_type;   // The vehicle type that is sorted
       
   447 	list_d l;                   // General list struct
       
   448 };
       
   449 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
       
   450 
       
   451 struct grouplist_d {
       
   452 	const Group **sort_list;
       
   453 	list_d l;                   // General list struct
       
   454 };
       
   455 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(grouplist_d));
       
   456 
       
   457 struct groupveh_d : vehiclelist_d {
       
   458 	GroupID group_sel;
       
   459 	VehicleID vehicle_sel;
       
   460 
       
   461 	grouplist_d gl;
       
   462 };
       
   463 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(groupveh_d));
       
   464 
       
   465 /****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/
       
   466 enum WindowWidgetBehaviours {
       
   467 	WWB_PUSHBUTTON  = 1 << 5,
       
   468 
       
   469 	WWB_MASK        = 0xE0,
       
   470 };
       
   471 
       
   472 
       
   473 enum WindowWidgetTypes {
       
   474 	WWT_EMPTY,
       
   475 
       
   476 	WWT_PANEL,      ///< simple depressed panel
       
   477 	WWT_INSET,      ///< pressed (inset) panel, most commonly used as combo box _text_ area
       
   478 	WWT_IMGBTN,     ///< button with image
       
   479 	WWT_IMGBTN_2,   ///< button with diff image when clicked
       
   480 
       
   481 	WWT_TEXTBTN,    ///< button with text
       
   482 	WWT_TEXTBTN_2,  ///< button with diff text when clicked
       
   483 	WWT_LABEL,      ///< centered label
       
   484 	WWT_TEXT,       ///< pure simple text
       
   485 	WWT_MATRIX,
       
   486 	WWT_SCROLLBAR,
       
   487 	WWT_FRAME,      ///< frame
       
   488 	WWT_CAPTION,
       
   489 
       
   490 	WWT_HSCROLLBAR,
       
   491 	WWT_STICKYBOX,
       
   492 	WWT_SCROLL2BAR, ///< 2nd vertical scrollbar
       
   493 	WWT_RESIZEBOX,
       
   494 	WWT_CLOSEBOX,
       
   495 	WWT_DROPDOWN,   ///< Raised drop down list (regular)
       
   496 	WWT_DROPDOWNIN, ///< Inset drop down list (used on game options only)
       
   497 	WWT_LAST,       ///< Last Item. use WIDGETS_END to fill up padding!!
       
   498 
       
   499 	WWT_MASK = 0x1F,
       
   500 
       
   501 	WWT_PUSHBTN     = WWT_PANEL   | WWB_PUSHBUTTON,
       
   502 	WWT_PUSHTXTBTN  = WWT_TEXTBTN | WWB_PUSHBUTTON,
       
   503 	WWT_PUSHIMGBTN  = WWT_IMGBTN  | WWB_PUSHBUTTON,
       
   504 };
       
   505 
       
   506 #define WIDGETS_END WWT_LAST,   RESIZE_NONE,     0,     0,     0,     0,     0, 0, STR_NULL
       
   507 
       
   508 enum WindowFlags {
       
   509 	WF_TIMEOUT_SHL       = 0,
       
   510 	WF_TIMEOUT_MASK      = 7,
       
   511 	WF_DRAGGING          = 1 <<  3,
       
   512 	WF_SCROLL_UP         = 1 <<  4,
       
   513 	WF_SCROLL_DOWN       = 1 <<  5,
       
   514 	WF_SCROLL_MIDDLE     = 1 <<  6,
       
   515 	WF_HSCROLL           = 1 <<  7,
       
   516 	WF_SIZING            = 1 <<  8,
       
   517 	WF_STICKY            = 1 <<  9,
       
   518 
       
   519 	WF_DISABLE_VP_SCROLL = 1 << 10,
       
   520 
       
   521 	WF_WHITE_BORDER_ONE  = 1 << 11,
       
   522 	WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE,
       
   523 	WF_SCROLL2           = 1 << 13,
       
   524 };
       
   525 
       
   526 /* window.cpp */
       
   527 void CallWindowEventNP(Window *w, int event);
       
   528 void CallWindowTickEvent();
       
   529 
       
   530 /**
       
   531  * Marks the window as dirty for repaint.
       
   532  *
       
   533  * @ingroup dirty
       
   534  */
       
   535 void SetWindowDirty(const Window *w);
       
   536 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam);
       
   537 void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam);
       
   538 
       
   539 Window *FindWindowById(WindowClass cls, WindowNumber number);
       
   540 void DeleteWindow(Window *w);
       
   541 void DeletePlayerWindows(PlayerID pi);
       
   542 void ChangeWindowOwner(PlayerID old_player, PlayerID new_player);
       
   543 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
       
   544 Window *FindWindowFromPt(int x, int y);
       
   545 
       
   546 bool IsWindowOfPrototype(const Window *w, const Widget *widget);
       
   547 void AssignWidgetToWindow(Window *w, const Widget *widget);
       
   548 Window *AllocateWindow(
       
   549 							int x,
       
   550 							int y,
       
   551 							int width,
       
   552 							int height,
       
   553 							WindowProc *proc,
       
   554 							WindowClass cls,
       
   555 							const Widget *widget,
       
   556 							void *data = NULL);
       
   557 
       
   558 Window *AllocateWindowDesc(const WindowDesc *desc, void *data = NULL);
       
   559 Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data = NULL);
       
   560 
       
   561 void DrawWindowViewport(const Window *w);
       
   562 void ResizeWindow(Window *w, int x, int y);
       
   563 
       
   564 void InitWindowSystem();
       
   565 void UnInitWindowSystem();
       
   566 void ResetWindowSystem();
       
   567 int GetMenuItemIndex(const Window *w, int x, int y);
       
   568 void InputLoop();
       
   569 void InvalidateThisWindowData(Window *w);
       
   570 void InvalidateWindowData(WindowClass cls, WindowNumber number);
       
   571 void RelocateAllWindows(int neww, int newh);
       
   572 
       
   573 /* misc_gui.cpp */
       
   574 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[]);
       
   575 static inline void GuiShowTooltips(StringID str)
       
   576 {
       
   577 	GuiShowTooltipsWithArgs(str, 0, NULL);
       
   578 }
       
   579 
       
   580 /* widget.cpp */
       
   581 int GetWidgetFromPos(const Window *w, int x, int y);
       
   582 void DrawWindowWidgets(const Window *w);
       
   583 
       
   584 enum SortButtonState {
       
   585 	SBS_OFF,
       
   586 	SBS_DOWN,
       
   587 	SBS_UP,
       
   588 };
       
   589 
       
   590 void DrawSortButtonState(const Window *w, int widget, SortButtonState state);
       
   591 
       
   592 
       
   593 Window *GetCallbackWnd();
       
   594 void DeleteNonVitalWindows();
       
   595 void DeleteAllNonVitalWindows();
       
   596 void HideVitalWindows();
       
   597 void ShowVitalWindows();
       
   598 Window **FindWindowZPosition(const Window *w);
       
   599 
       
   600 /* window.cpp */
       
   601 extern Window *_z_windows[];
       
   602 extern Window **_last_z_window;
       
   603 #define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++)
       
   604 
       
   605 extern Point _cursorpos_drag_start;
       
   606 
       
   607 extern int _scrollbar_start_pos;
       
   608 extern int _scrollbar_size;
       
   609 extern byte _scroller_click_timeout;
       
   610 
       
   611 extern bool _scrolling_scrollbar;
       
   612 extern bool _scrolling_viewport;
       
   613 extern bool _popup_menu_active;
       
   614 
       
   615 extern byte _special_mouse_mode;
       
   616 enum SpecialMouseMode {
       
   617 	WSM_NONE     = 0,
       
   618 	WSM_DRAGDROP = 1,
       
   619 	WSM_SIZING   = 2,
       
   620 	WSM_PRESIZE  = 3,
       
   621 };
       
   622 
       
   623 void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y);
       
   624 
       
   625 /** Evenly distribute some widgets when resizing horizontally (often a button row)
       
   626  *  The widgets are presumed to be in a line and numberef from left to right (without gaps)
       
   627  * @param w widow to modify
       
   628  * @param left The leftmost widget to resize
       
   629  * @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT
       
   630  */
       
   631 void ResizeButtons(Window *w, byte left, byte right);
       
   632 
       
   633 
       
   634 /**
       
   635  * Sets the enabled/disabled status of a widget.
       
   636  * By default, widgets are enabled.
       
   637  * On certain conditions, they have to be disabled.
       
   638  * @param widget_index : index of this widget in the window
       
   639  * @param disab_stat : status to use ie: disabled = true, enabled = false
       
   640  */
       
   641 inline void Window::SetWidgetDisabledState(byte widget_index, bool disab_stat)
       
   642 {
       
   643 	assert(widget_index < this->widget_count);
       
   644 	SB(this->widget[widget_index].display_flags, WIDG_DISABLED, 1, !!disab_stat);
       
   645 }
       
   646 
       
   647 /**
       
   648  * Sets a widget to disabled.
       
   649  * @param widget_index : index of this widget in the window
       
   650  */
       
   651 inline void Window::DisableWidget(byte widget_index)
       
   652 {
       
   653 	SetWidgetDisabledState(widget_index, true);
       
   654 }
       
   655 
       
   656 /**
       
   657  * Sets a widget to Enabled.
       
   658  * @param widget_index : index of this widget in the window
       
   659  */
       
   660 inline void Window::EnableWidget(byte widget_index)
       
   661 {
       
   662 	SetWidgetDisabledState(widget_index, false);
       
   663 }
       
   664 
       
   665 /**
       
   666  * Gets the enabled/disabled status of a widget.
       
   667  * @param widget_index : index of this widget in the window
       
   668  * @return status of the widget ie: disabled = true, enabled = false
       
   669  */
       
   670 inline bool Window::IsWidgetDisabled(byte widget_index) const
       
   671 {
       
   672 	assert(widget_index < this->widget_count);
       
   673 	return HasBit(this->widget[widget_index].display_flags, WIDG_DISABLED);
       
   674 }
       
   675 
       
   676 /**
       
   677  * Sets the hidden/shown status of a widget.
       
   678  * By default, widgets are visible.
       
   679  * On certain conditions, they have to be hidden.
       
   680  * @param widget_index index of this widget in the window
       
   681  * @param hidden_stat status to use ie. hidden = true, visible = false
       
   682  */
       
   683 inline void Window::SetWidgetHiddenState(byte widget_index, bool hidden_stat)
       
   684 {
       
   685 	assert(widget_index < this->widget_count);
       
   686 	SB(this->widget[widget_index].display_flags, WIDG_HIDDEN, 1, !!hidden_stat);
       
   687 }
       
   688 
       
   689 /**
       
   690  * Sets a widget hidden.
       
   691  * @param widget_index : index of this widget in the window
       
   692  */
       
   693 inline void Window::HideWidget(byte widget_index)
       
   694 {
       
   695 	SetWidgetHiddenState(widget_index, true);
       
   696 }
       
   697 
       
   698 /**
       
   699  * Sets a widget visible.
       
   700  * @param widget_index : index of this widget in the window
       
   701  */
       
   702 inline void Window::ShowWidget(byte widget_index)
       
   703 {
       
   704 	SetWidgetHiddenState(widget_index, false);
       
   705 }
       
   706 
       
   707 /**
       
   708  * Gets the visibility of a widget.
       
   709  * @param widget_index : index of this widget in the window
       
   710  * @return status of the widget ie: hidden = true, visible = false
       
   711  */
       
   712 inline bool Window::IsWidgetHidden(byte widget_index) const
       
   713 {
       
   714 	assert(widget_index < this->widget_count);
       
   715 	return HasBit(this->widget[widget_index].display_flags, WIDG_HIDDEN);
       
   716 }
       
   717 
       
   718 /**
       
   719  * Sets the lowered/raised status of a widget.
       
   720  * @param widget_index : index of this widget in the window
       
   721  * @param lowered_stat : status to use ie: lowered = true, raised = false
       
   722  */
       
   723 inline void Window::SetWidgetLoweredState(byte widget_index, bool lowered_stat)
       
   724 {
       
   725 	assert(widget_index < this->widget_count);
       
   726 	SB(this->widget[widget_index].display_flags, WIDG_LOWERED, 1, !!lowered_stat);
       
   727 }
       
   728 
       
   729 /**
       
   730  * Invert the lowered/raised  status of a widget.
       
   731  * @param widget_index : index of this widget in the window
       
   732  */
       
   733 inline void Window::ToggleWidgetLoweredState(byte widget_index)
       
   734 {
       
   735 	assert(widget_index < this->widget_count);
       
   736 	ToggleBit(this->widget[widget_index].display_flags, WIDG_LOWERED);
       
   737 }
       
   738 
       
   739 /**
       
   740  * Marks a widget as lowered.
       
   741  * @param widget_index : index of this widget in the window
       
   742  */
       
   743 inline void Window::LowerWidget(byte widget_index)
       
   744 {
       
   745 	SetWidgetLoweredState(widget_index, true);
       
   746 }
       
   747 
       
   748 /**
       
   749  * Marks a widget as raised.
       
   750  * @param widget_index : index of this widget in the window
       
   751  */
       
   752 inline void Window::RaiseWidget(byte widget_index)
       
   753 {
       
   754 	SetWidgetLoweredState(widget_index, false);
       
   755 }
       
   756 
       
   757 /**
       
   758  * Gets the lowered state of a widget.
       
   759  * @param widget_index : index of this widget in the window
       
   760  * @return status of the widget ie: lowered = true, raised= false
       
   761  */
       
   762 inline bool Window::IsWidgetLowered(byte widget_index) const
       
   763 {
       
   764 	assert(widget_index < this->widget_count);
       
   765 	return HasBit(this->widget[widget_index].display_flags, WIDG_LOWERED);
       
   766 }
       
   767 
       
   768 #endif /* WINDOW_GUI_H */