src/window.h
changeset 5838 9c3129cb019b
parent 5726 8f399788f6c9
child 6032 cc75c53d40e9
equal deleted inserted replaced
5837:96b4b92b86ae 5838:9c3129cb019b
     4 #define WINDOW_H
     4 #define WINDOW_H
     5 
     5 
     6 #include "macros.h"
     6 #include "macros.h"
     7 #include "string.h"
     7 #include "string.h"
     8 #include "order.h"
     8 #include "order.h"
       
     9 #include "rail.h"
       
    10 #include "airport.h"
     9 
    11 
    10 typedef struct WindowEvent WindowEvent;
    12 typedef struct WindowEvent WindowEvent;
    11 
    13 
    12 typedef void WindowProc(Window *w, WindowEvent *e);
    14 typedef void WindowProc(Window *w, WindowEvent *e);
    13 
    15 
    36     the default height/width of the window itself. You can change this
    38     the default height/width of the window itself. You can change this
    37     AFTER window-creation, with:
    39     AFTER window-creation, with:
    38      w->resize.width or w->resize.height.
    40      w->resize.width or w->resize.height.
    39    That was all.. good luck, and enjoy :) -- TrueLight */
    41    That was all.. good luck, and enjoy :) -- TrueLight */
    40 
    42 
    41 enum ResizeFlags {
    43 typedef enum ResizeFlags {
    42 	RESIZE_NONE   = 0,
    44 	RESIZE_NONE   = 0,
    43 
    45 
    44 	RESIZE_LEFT   = 1,
    46 	RESIZE_LEFT   = 1,
    45 	RESIZE_RIGHT  = 2,
    47 	RESIZE_RIGHT  = 2,
    46 	RESIZE_TOP    = 4,
    48 	RESIZE_TOP    = 4,
    75 	uint16 data;                      ///< The String/Image or special code (list-matrixes) of a widget
    77 	uint16 data;                      ///< The String/Image or special code (list-matrixes) of a widget
    76 	StringID tooltips;                ///< Tooltips that are shown when rightclicking on a widget
    78 	StringID tooltips;                ///< Tooltips that are shown when rightclicking on a widget
    77 } Widget;
    79 } Widget;
    78 
    80 
    79 typedef enum FrameFlags {
    81 typedef enum FrameFlags {
       
    82 	FR_NONE         = 0x00,
    80 	FR_TRANSPARENT  = 0x01,  ///< Makes the background transparent if set
    83 	FR_TRANSPARENT  = 0x01,  ///< Makes the background transparent if set
    81 	FR_BORDERONLY   = 0x10,  ///< Draw border only, no background
    84 	FR_BORDERONLY   = 0x10,  ///< Draw border only, no background
    82 	FR_LOWERED      = 0x20,  ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed)
    85 	FR_LOWERED      = 0x20,  ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed)
    83 	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)
    86 	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)
    84 } FrameFlags;
    87 } FrameFlags;
       
    88 
       
    89 DECLARE_ENUM_AS_BIT_SET(FrameFlags);
    85 
    90 
    86 void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags);
    91 void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags);
    87 
    92 
    88 enum WindowEventCodes {
    93 enum WindowEventCodes {
    89 	WE_CREATE,
    94 	WE_CREATE,
   163 			uint16 key;    // 16-bit Unicode value of the key
   168 			uint16 key;    // 16-bit Unicode value of the key
   164 			uint16 keycode;// untranslated key (including shift-state)
   169 			uint16 keycode;// untranslated key (including shift-state)
   165 		} keypress;
   170 		} keypress;
   166 
   171 
   167 		struct {
   172 		struct {
   168 			uint msg;      // message to be sent
   173 			int msg;      // message to be sent
   169 			uint wparam;   // additional message-specific information
   174 			int wparam;   // additional message-specific information
   170 			uint lparam;   // additional message-specific information
   175 			int lparam;   // additional message-specific information
   171 		} message;
   176 		} message;
   172 
   177 
   173 		struct {
   178 		struct {
   174 			Point delta;   // delta position against position of last call
   179 			Point delta;   // delta position against position of last call
   175 		} scroll;
   180 		} scroll;
   176 
   181 
   177 		struct {
   182 		struct {
   178 			int wheel;     // how much was 'wheel'd'
   183 			int wheel;     // how much was 'wheel'd'
   179 		} wheel;
   184 		} wheel;
   180 	} we;
   185 	} we;
   181 };
       
   182 
       
   183 enum WindowKeyCodes {
       
   184 	WKC_SHIFT = 0x8000,
       
   185 	WKC_CTRL  = 0x4000,
       
   186 	WKC_ALT   = 0x2000,
       
   187 	WKC_META  = 0x1000,
       
   188 
       
   189 	// Special ones
       
   190 	WKC_NONE        =  0,
       
   191 	WKC_ESC         =  1,
       
   192 	WKC_BACKSPACE   =  2,
       
   193 	WKC_INSERT      =  3,
       
   194 	WKC_DELETE      =  4,
       
   195 
       
   196 	WKC_PAGEUP      =  5,
       
   197 	WKC_PAGEDOWN    =  6,
       
   198 	WKC_END         =  7,
       
   199 	WKC_HOME        =  8,
       
   200 
       
   201 	// Arrow keys
       
   202 	WKC_LEFT        =  9,
       
   203 	WKC_UP          = 10,
       
   204 	WKC_RIGHT       = 11,
       
   205 	WKC_DOWN        = 12,
       
   206 
       
   207 	// Return & tab
       
   208 	WKC_RETURN      = 13,
       
   209 	WKC_TAB         = 14,
       
   210 
       
   211 	// Numerical keyboard
       
   212 	WKC_NUM_0       = 16,
       
   213 	WKC_NUM_1       = 17,
       
   214 	WKC_NUM_2       = 18,
       
   215 	WKC_NUM_3       = 19,
       
   216 	WKC_NUM_4       = 20,
       
   217 	WKC_NUM_5       = 21,
       
   218 	WKC_NUM_6       = 22,
       
   219 	WKC_NUM_7       = 23,
       
   220 	WKC_NUM_8       = 24,
       
   221 	WKC_NUM_9       = 25,
       
   222 	WKC_NUM_DIV     = 26,
       
   223 	WKC_NUM_MUL     = 27,
       
   224 	WKC_NUM_MINUS   = 28,
       
   225 	WKC_NUM_PLUS    = 29,
       
   226 	WKC_NUM_ENTER   = 30,
       
   227 	WKC_NUM_DECIMAL = 31,
       
   228 
       
   229 	// Space
       
   230 	WKC_SPACE       = 32,
       
   231 
       
   232 	// Function keys
       
   233 	WKC_F1          = 33,
       
   234 	WKC_F2          = 34,
       
   235 	WKC_F3          = 35,
       
   236 	WKC_F4          = 36,
       
   237 	WKC_F5          = 37,
       
   238 	WKC_F6          = 38,
       
   239 	WKC_F7          = 39,
       
   240 	WKC_F8          = 40,
       
   241 	WKC_F9          = 41,
       
   242 	WKC_F10         = 42,
       
   243 	WKC_F11         = 43,
       
   244 	WKC_F12         = 44,
       
   245 
       
   246 	// backquote is the key left of "1"
       
   247 	// we only store this key here, no matter what character is really mapped to it
       
   248 	// on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °)
       
   249 	WKC_BACKQUOTE   = 45,
       
   250 	WKC_PAUSE       = 46,
       
   251 
       
   252 	// 0-9 are mapped to 48-57
       
   253 	// A-Z are mapped to 65-90
       
   254 	// a-z are mapped to 97-122
       
   255 };
   186 };
   256 
   187 
   257 typedef struct WindowDesc {
   188 typedef struct WindowDesc {
   258 	int16 left, top, width, height;
   189 	int16 left, top, width, height;
   259 	WindowClass cls;
   190 	WindowClass cls;
   387 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d));
   318 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d));
   388 
   319 
   389 typedef struct {
   320 typedef struct {
   390 	byte vehicle_type;
   321 	byte vehicle_type;
   391 	union {
   322 	union {
   392 		byte railtype;
   323 		RailTypeByte railtype;
   393 		byte acc_planes; // AIRCRAFT_ONLY, ALL, HELICOPTERS_ONLY
   324 		AcceptPlanesByte acc_planes; // AIRCRAFT_ONLY, ALL, HELICOPTERS_ONLY
   394 	} filter;
   325 	} filter;
   395 	byte sel_index;  // deprecated value, used for 'unified' ship and road
   326 	byte sel_index;  // deprecated value, used for 'unified' ship and road
   396 	bool descending_sort_order;
   327 	bool descending_sort_order;
   397 	byte sort_criteria;
   328 	byte sort_criteria;
   398 	EngineID sel_engine;
   329 	EngineID sel_engine;
   492 	uint16 counter;
   423 	uint16 counter;
   493 } scroller_d;
   424 } scroller_d;
   494 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d));
   425 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d));
   495 
   426 
   496 typedef enum SortListFlags {
   427 typedef enum SortListFlags {
       
   428 	VL_NONE    = 0x00,
   497 	VL_DESC    = 0x01,  // sort descending or ascending
   429 	VL_DESC    = 0x01,  // sort descending or ascending
   498 	VL_RESORT  = 0x02,  // instruct the code to resort the list in the next loop
   430 	VL_RESORT  = 0x02,  // instruct the code to resort the list in the next loop
   499 	VL_REBUILD = 0x04   // create sort-listing to use for qsort and friends
   431 	VL_REBUILD = 0x04,  // create sort-listing to use for qsort and friends
       
   432 	VL_END     = 0x08
   500 } SortListFlags;
   433 } SortListFlags;
       
   434 
       
   435 DECLARE_ENUM_AS_BIT_SET(SortListFlags);
   501 
   436 
   502 typedef struct Listing {
   437 typedef struct Listing {
   503 	bool order;    // Ascending/descending
   438 	bool order;    // Ascending/descending
   504 	byte criteria; // Sorting criteria
   439 	byte criteria; // Sorting criteria
   505 } Listing;
   440 } Listing;
   594 
   529 
   595 /* window.c */
   530 /* window.c */
   596 void CallWindowEventNP(Window *w, int event);
   531 void CallWindowEventNP(Window *w, int event);
   597 void CallWindowTickEvent(void);
   532 void CallWindowTickEvent(void);
   598 void SetWindowDirty(const Window *w);
   533 void SetWindowDirty(const Window *w);
   599 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam);
   534 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam);
   600 void SendWindowMessageClass(WindowClass wnd_class, uint msg, uint wparam, uint lparam);
   535 void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam);
   601 
   536 
   602 Window *FindWindowById(WindowClass cls, WindowNumber number);
   537 Window *FindWindowById(WindowClass cls, WindowNumber number);
   603 void DeleteWindow(Window *w);
   538 void DeleteWindow(Window *w);
   604 void DeletePlayerWindows(PlayerID pi);
   539 void DeletePlayerWindows(PlayerID pi);
   605 void ChangeWindowOwner(PlayerID old_player, PlayerID new_player);
   540 void ChangeWindowOwner(PlayerID old_player, PlayerID new_player);
   773 void InitWindowSystem(void);
   708 void InitWindowSystem(void);
   774 void UnInitWindowSystem(void);
   709 void UnInitWindowSystem(void);
   775 void ResetWindowSystem(void);
   710 void ResetWindowSystem(void);
   776 int GetMenuItemIndex(const Window *w, int x, int y);
   711 int GetMenuItemIndex(const Window *w, int x, int y);
   777 void InputLoop(void);
   712 void InputLoop(void);
   778 void HandleKeypress(uint32 key);
       
   779 void HandleMouseEvents(void);
       
   780 void UpdateWindows(void);
       
   781 void InvalidateWidget(const Window *w, byte widget_index);
   713 void InvalidateWidget(const Window *w, byte widget_index);
   782 void InvalidateThisWindowData(Window *w);
   714 void InvalidateThisWindowData(Window *w);
   783 void InvalidateWindowData(WindowClass cls, WindowNumber number);
   715 void InvalidateWindowData(WindowClass cls, WindowNumber number);
   784 void RaiseWindowButtons(Window *w);
   716 void RaiseWindowButtons(Window *w);
   785 void RelocateAllWindows(int neww, int newh);
   717 void RelocateAllWindows(int neww, int newh);
   814 extern Window **_last_z_window;
   746 extern Window **_last_z_window;
   815 #define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++)
   747 #define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++)
   816 
   748 
   817 VARDEF Point _cursorpos_drag_start;
   749 VARDEF Point _cursorpos_drag_start;
   818 
   750 
   819 VARDEF bool _left_button_down;
       
   820 VARDEF bool _left_button_clicked;
       
   821 
       
   822 VARDEF bool _right_button_down;
       
   823 VARDEF bool _right_button_clicked;
       
   824 
       
   825 VARDEF int _scrollbar_start_pos;
   751 VARDEF int _scrollbar_start_pos;
   826 VARDEF int _scrollbar_size;
   752 VARDEF int _scrollbar_size;
   827 VARDEF byte _scroller_click_timeout;
   753 VARDEF byte _scroller_click_timeout;
   828 
   754 
   829 VARDEF bool _scrolling_scrollbar;
   755 VARDEF bool _scrolling_scrollbar;