window.h
changeset 2596 07cecb439908
parent 2549 5587f9a38563
child 2622 73167d7e30c7
equal deleted inserted replaced
2595:1c5db200577c 2596:07cecb439908
     2 
     2 
     3 #ifndef WINDOW_H
     3 #ifndef WINDOW_H
     4 #define WINDOW_H
     4 #define WINDOW_H
     5 
     5 
     6 typedef union WindowEvent WindowEvent;
     6 typedef union WindowEvent WindowEvent;
     7 
       
     8 //typedef void WindowProc(Window *w, int event, int wparam, long lparam);
       
     9 
     7 
    10 typedef void WindowProc(Window *w, WindowEvent *e);
     8 typedef void WindowProc(Window *w, WindowEvent *e);
    11 
     9 
    12 /* How the resize system works:
    10 /* How the resize system works:
    13     First, you need to add a WWT_RESIZEBOX to the widgets, and you need
    11     First, you need to add a WWT_RESIZEBOX to the widgets, and you need
   208 	WKC_PAUSE     = 46,
   206 	WKC_PAUSE     = 46,
   209 
   207 
   210 	// 0-9 are mapped to 48-57
   208 	// 0-9 are mapped to 48-57
   211 	// A-Z are mapped to 65-90
   209 	// A-Z are mapped to 65-90
   212 	// a-z are mapped to 97-122
   210 	// a-z are mapped to 97-122
   213 
       
   214 
       
   215 	//WKC_UNKNOWN = 0xFF,
       
   216 
       
   217 };
   211 };
   218 
   212 
   219 typedef struct WindowDesc {
   213 typedef struct WindowDesc {
   220 	int16 left, top, width, height;
   214 	int16 left, top, width, height;
   221 	byte cls;
   215 	byte cls;
   248 	bool caret;                 /* is the caret ("_") visible or not */
   242 	bool caret;                 /* is the caret ("_") visible or not */
   249 	uint16 caretpos;            /* the current position of the caret in the buffer */
   243 	uint16 caretpos;            /* the current position of the caret in the buffer */
   250 	uint16 caretxoffs;          /* the current position of the caret in pixels */
   244 	uint16 caretxoffs;          /* the current position of the caret in pixels */
   251 } Textbuf;
   245 } Textbuf;
   252 
   246 
   253 typedef struct {
   247 typedef struct querystr_d {
   254 	StringID caption;
   248 	StringID caption;
   255 	WindowClass wnd_class;
   249 	WindowClass wnd_class;
   256 	WindowNumber wnd_num;
   250 	WindowNumber wnd_num;
   257 	Textbuf text;
   251 	Textbuf text;
   258 	const char* orig;
   252 	const char* orig;
   259 } querystr_d;
   253 } querystr_d;
   260 
   254 
   261 #define WP(ptr,str) (*(str*)(ptr)->custom)
   255 #define WP(ptr,str) (*(str*)(ptr)->custom)
   262 // querystr_d is the bigest struct that comes in w->custom
   256 // querystr_d is the largest struct that comes in w->custom
   263 //  because 64-bit systems use 64-bit pointers, it is bigger on a 64-bit system
   257 //  because 64-bit systems use 64-bit pointers, it is bigger on a 64-bit system
   264 //  than on a 32-bit system. Therefore, the size is calculated from querystr_d
   258 //  than on a 32-bit system. Therefore, the size is calculated from querystr_d
   265 //  instead of a hardcoded number.
   259 //  instead of a hardcoded number.
   266 // if any struct becomes bigger the querystr_d, it should be replaced.
   260 // if any struct becomes bigger the querystr_d, it should be replaced.
   267 #define WINDOW_CUSTOM_SIZE sizeof(querystr_d)
   261 #define WINDOW_CUSTOM_SIZE sizeof(querystr_d)
   268 
   262 
   269 typedef struct {
   263 typedef struct Scrollbar {
   270 	uint16 count, cap, pos;
   264 	uint16 count, cap, pos;
   271 } Scrollbar;
   265 } Scrollbar;
   272 
   266 
   273 typedef struct {
   267 typedef struct ResizeInfo {
   274 	uint width; /* Minimum width and height */
   268 	uint width; /* Minimum width and height */
   275 	uint height;
   269 	uint height;
   276 
   270 
   277 	uint step_width; /* In how big steps the width and height go */
   271 	uint step_width; /* In how big steps the width and height go */
   278 	uint step_height;
   272 	uint step_height;
   279 } ResizeInfo;
   273 } ResizeInfo;
   280 
   274 
   281 typedef struct {
   275 typedef struct Message {
   282 		int msg;
   276 		int msg;
   283 		int wparam;
   277 		int wparam;
   284 		int lparam;
   278 		int lparam;
   285 } Message;
   279 } Message;
   286 
   280 
   300 	uint32 click_state, disabled_state, hidden_state;
   294 	uint32 click_state, disabled_state, hidden_state;
   301 	WindowProc *wndproc;
   295 	WindowProc *wndproc;
   302 	ViewPort *viewport;
   296 	ViewPort *viewport;
   303 	const Widget *original_widget;
   297 	const Widget *original_widget;
   304  	Widget *widget;
   298  	Widget *widget;
   305 	//const WindowDesc *desc;
       
   306 	uint32 desc_flags;
   299 	uint32 desc_flags;
   307 
   300 
   308 	Message message;
   301 	Message message;
   309 	byte custom[WINDOW_CUSTOM_SIZE];
   302 	byte custom[WINDOW_CUSTOM_SIZE];
   310 };
   303 };
   321 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d));
   314 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d));
   322 
   315 
   323 typedef struct {
   316 typedef struct {
   324 	int16 data_1, data_2, data_3;
   317 	int16 data_1, data_2, data_3;
   325 	int16 data_4, data_5;
   318 	int16 data_4, data_5;
   326 	bool close; /* scrollpos_y */
   319 	bool close;
   327 	byte byte_1;
   320 	byte byte_1;
   328 } def_d;
   321 } def_d;
   329 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d));
   322 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d));
   330 
   323 
   331 typedef struct {
   324 typedef struct {
   332 	void *data;
   325 	void *data;
   333 } void_d;
   326 } void_d;
   334 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(void_d));
   327 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(void_d));
   335 
   328 
   336 typedef struct {
   329 typedef struct {
   337 	uint16 base; /* follow_vehicle */
   330 	uint16 base;
   338 	uint16 count;/* scrollpos_x */
   331 	uint16 count;
   339 } tree_d;
   332 } tree_d;
   340 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tree_d));
   333 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tree_d));
   341 
   334 
   342 typedef struct {
   335 typedef struct {
   343 	byte refresh_counter; /* follow_vehicle */
   336 	byte refresh_counter;
   344 } plstations_d;
   337 } plstations_d;
   345 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
   338 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
   346 
   339 
   347 typedef struct {
   340 typedef struct {
   348 	StringID string_id;
   341 	StringID string_id;
   542 	WF_WHITE_BORDER_ONE = 1 << 11,
   535 	WF_WHITE_BORDER_ONE = 1 << 11,
   543 	WF_WHITE_BORDER_MASK = 3 << 11,
   536 	WF_WHITE_BORDER_MASK = 3 << 11,
   544 	WF_SCROLL2 = 1 << 13,
   537 	WF_SCROLL2 = 1 << 13,
   545 };
   538 };
   546 
   539 
   547 
       
   548 void DispatchLeftClickEvent(Window *w, int x, int y);
       
   549 void DispatchRightClickEvent(Window *w, int x, int y);
       
   550 void DispatchMouseWheelEvent(Window *w, int widget, int wheel);
       
   551 
       
   552 /* window.c */
   540 /* window.c */
   553 void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom);
   541 void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom);
   554 void CallWindowEventNP(Window *w, int event);
   542 void CallWindowEventNP(Window *w, int event);
   555 void CallWindowTickEvent(void);
   543 void CallWindowTickEvent(void);
   556 void SetWindowDirty(const Window* w);
   544 void SetWindowDirty(const Window* w);
   557 void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam);
       
   558 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam);
   545 void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam);
   559 
   546 
   560 Window *FindWindowById(WindowClass cls, WindowNumber number);
   547 Window *FindWindowById(WindowClass cls, WindowNumber number);
   561 void DeleteWindow(Window *w);
   548 void DeleteWindow(Window *w);
   562 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
   549 Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
   563 Window *BringWindowToFront(Window *w);
   550 Window *BringWindowToFront(Window *w);
   564 Window *StartWindowDrag(Window *w);
   551 Window *StartWindowDrag(Window *w);
   565 Window *StartWindowSizing(Window *w);
   552 Window *StartWindowSizing(Window *w);
   566 Window *FindWindowFromPt(int x, int y);
   553 Window *FindWindowFromPt(int x, int y);
   567 
   554 
   568 bool IsWindowOfPrototype(Window *w, const Widget *widget);
   555 bool IsWindowOfPrototype(const Window* w, const Widget* widget);
   569 void AssignWidgetToWindow(Window *w, const Widget *widget);
   556 void AssignWidgetToWindow(Window *w, const Widget *widget);
   570 /* Use this function to save the current widget to be the global default */
       
   571 void MakeWindowWidgetDefault(Window *w);
       
   572 Window *AllocateWindow(
   557 Window *AllocateWindow(
   573 							int x,
   558 							int x,
   574 							int y,
   559 							int y,
   575 							int width,
   560 							int width,
   576 							int height,
   561 							int height,
   603 void UnInitWindowSystem(void);
   588 void UnInitWindowSystem(void);
   604 void ResetWindowSystem(void);
   589 void ResetWindowSystem(void);
   605 int GetMenuItemIndex(const Window *w, int x, int y);
   590 int GetMenuItemIndex(const Window *w, int x, int y);
   606 void InputLoop(void);
   591 void InputLoop(void);
   607 void UpdateWindows(void);
   592 void UpdateWindows(void);
   608 void InvalidateWidget(Window *w, byte widget_index);
   593 void InvalidateWidget(const Window* w, byte widget_index);
   609 
   594 
   610 void GuiShowTooltips(StringID string_id);
   595 void GuiShowTooltips(StringID string_id);
   611 
   596 
   612 void UnclickWindowButtons(Window *w);
   597 void UnclickWindowButtons(Window *w);
   613 void UnclickSomeWindowButtons(Window *w, uint32 mask);
   598 void UnclickSomeWindowButtons(Window *w, uint32 mask);
   641 
   626 
   642 VARDEF int _alloc_wnd_parent_num;
   627 VARDEF int _alloc_wnd_parent_num;
   643 
   628 
   644 VARDEF int _scrollbar_start_pos;
   629 VARDEF int _scrollbar_start_pos;
   645 VARDEF int _scrollbar_size;
   630 VARDEF int _scrollbar_size;
   646 VARDEF bool _demo_mode;
       
   647 VARDEF byte _scroller_click_timeout;
   631 VARDEF byte _scroller_click_timeout;
   648 
   632 
   649 VARDEF bool _dragging_window;
       
   650 VARDEF bool _scrolling_scrollbar;
   633 VARDEF bool _scrolling_scrollbar;
   651 VARDEF bool _scrolling_viewport;
   634 VARDEF bool _scrolling_viewport;
   652 VARDEF bool _popup_menu_active;
   635 VARDEF bool _popup_menu_active;
   653 //VARDEF bool _dragdrop_active;
       
   654 
       
   655 VARDEF Point _fix_mouse_at;
       
   656 
   636 
   657 VARDEF byte _special_mouse_mode;
   637 VARDEF byte _special_mouse_mode;
   658 enum SpecialMouseMode {
   638 enum SpecialMouseMode {
   659 	WSM_NONE = 0,
   639 	WSM_NONE = 0,
   660 	WSM_DRAGDROP = 1,
   640 	WSM_DRAGDROP = 1,