Rev 6391 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6391 | ashmew2 | 1 | #ifndef KOLIBRI_GUI_ELEMENTS_H |
2 | #define KOLIBRI_GUI_ELEMENTS_H |
||
3 | |||
4 | /* GUI Elements being used */ |
||
5 | #include "kolibri_editbox.h" |
||
6 | #include "kolibri_checkbox.h" |
||
7 | #include "kolibri_button.h" |
||
8 | |||
9 | /* enum KOLIBRI_GUI_ELEMENT_TYPE contains all available GUI items from box_lib */ |
||
10 | /* More elements can be added from other libraries as required */ |
||
11 | enum KOLIBRI_GUI_ELEMENT_TYPE { |
||
12 | KOLIBRI_EDIT_BOX, |
||
13 | KOLIBRI_CHECK_BOX, |
||
14 | KOLIBRI_RADIO_BUTTON, |
||
15 | KOLIBRI_SCROLL_BAR, |
||
16 | KOLIBRI_DYNAMIC_BUTTON, |
||
17 | KOLIBRI_MENU_BAR, |
||
18 | KOLIBRI_FILE_BROWSER, |
||
19 | KOLIBRI_TREE_LIST, |
||
20 | KOLIBRI_PATH_SHOW, |
||
21 | KOLIBRI_TEXT_EDITOR, |
||
22 | KOLIBRI_FRAME, |
||
23 | KOLIBRI_PROGRESS_BAR, |
||
24 | |||
25 | KOLIBRI_BUTTON, |
||
26 | |||
27 | /* Add elements above this element in order to let KOLIBRI_NUM_GUI_ELEMENTS */ |
||
28 | /* stay at correct value */ |
||
6396 | siemargl | 29 | |
30 | KOLIBRI_NUM_GUI_ELEMENTS |
||
6391 | ashmew2 | 31 | }; |
32 | |||
33 | /* Linked list which connects together all the elements drawn inside a GUI window */ |
||
34 | struct kolibri_window_element { |
||
35 | enum KOLIBRI_GUI_ELEMENT_TYPE type; |
||
36 | void *element; |
||
37 | struct kolibri_window_element *next, *prev; |
||
38 | }; |
||
39 | |||
6396 | siemargl | 40 | |
41 | typedef void (*cb_elem_boxlib)(void *) __attribute__((__stdcall__)); |
||
42 | |||
6391 | ashmew2 | 43 | /* Generic structure for supporting functions on various elements of Kolibri's GUI */ |
44 | struct kolibri_element_operations { |
||
6396 | siemargl | 45 | cb_elem_boxlib redraw_fn; |
46 | cb_elem_boxlib mouse_fn; |
||
47 | cb_elem_boxlib key_fn; |
||
6391 | ashmew2 | 48 | }; |
49 | |||
50 | /* Structure for a GUI Window on Kolibri. It also contains all the elements drawn in window */ |
||
51 | struct kolibri_window { |
||
52 | unsigned int topleftx, toplefty; |
||
53 | unsigned int sizex, sizey; |
||
54 | char *window_title; |
||
55 | |||
56 | /* Refer to sysfuncs, value to be stored in EDX (Function 0) */ |
||
57 | unsigned int XY; |
||
58 | |||
59 | struct kolibri_window_element *elements; |
||
60 | }; |
||
61 | |||
62 | /*---------------------End of Structure and enum definitions---------------*/ |
||
63 | /*---------------------Define various functions for initializing GUI-------*/ |
||
64 | |||
65 | /* Master table containing operations for various GUI elements in one place */ |
||
66 | struct kolibri_element_operations kolibri_gui_op_table[KOLIBRI_NUM_GUI_ELEMENTS]; |
||
67 | |||
68 | void kolibri_init_gui_op_table(void) |
||
69 | { |
||
70 | /* Setting up functions for edit box GUI elements*/ |
||
6396 | siemargl | 71 | kolibri_gui_op_table[KOLIBRI_EDIT_BOX].redraw_fn = (cb_elem_boxlib)edit_box_draw; |
72 | kolibri_gui_op_table[KOLIBRI_EDIT_BOX].mouse_fn = (cb_elem_boxlib)edit_box_mouse; |
||
73 | kolibri_gui_op_table[KOLIBRI_EDIT_BOX].key_fn = (cb_elem_boxlib)editbox_key; |
||
6391 | ashmew2 | 74 | |
75 | /* Setting up functions for check box GUI elements*/ |
||
6396 | siemargl | 76 | kolibri_gui_op_table[KOLIBRI_CHECK_BOX].redraw_fn = (cb_elem_boxlib)check_box_draw2; |
77 | kolibri_gui_op_table[KOLIBRI_CHECK_BOX].mouse_fn = (cb_elem_boxlib)check_box_mouse2; |
||
6391 | ashmew2 | 78 | kolibri_gui_op_table[KOLIBRI_CHECK_BOX].key_fn = NULL; |
79 | |||
80 | /* Setting up functions for Kolibri Buttons ( SysFunc 8 )*/ |
||
6396 | siemargl | 81 | kolibri_gui_op_table[KOLIBRI_BUTTON].redraw_fn = (cb_elem_boxlib)draw_button; |
6391 | ashmew2 | 82 | kolibri_gui_op_table[KOLIBRI_BUTTON].mouse_fn = NULL; |
83 | kolibri_gui_op_table[KOLIBRI_BUTTON].key_fn = NULL; |
||
6396 | siemargl | 84 | |
6391 | ashmew2 | 85 | } |
86 | |||
87 | /* Create a new main GUI window for KolibriOS */ |
||
88 | /* tl stands for TOP LEFT. x and y are coordinates. */ |
||
89 | |||
90 | struct kolibri_window * kolibri_new_window(int tlx, int tly, int sizex, int sizey, char *title) |
||
91 | { |
||
92 | struct kolibri_window *new_win = (struct kolibri_window *)malloc(sizeof(struct kolibri_window)); |
||
93 | |||
94 | new_win->topleftx = tlx; |
||
95 | new_win->toplefty = tly; |
||
96 | new_win->sizex = sizex; |
||
97 | new_win->sizey = sizey; |
||
98 | new_win->window_title = title; |
||
99 | new_win->XY = 0x00000013; /* All windows are skinned windows with caption for now */ |
||
100 | new_win->elements = NULL; |
||
6396 | siemargl | 101 | |
6391 | ashmew2 | 102 | return new_win; |
103 | } |
||
104 | |||
105 | /* Add an element to an existing window */ |
||
106 | void kolibri_window_add_element(struct kolibri_window *some_window, enum KOLIBRI_GUI_ELEMENT_TYPE element_type, void *some_gui_element) |
||
107 | { |
||
108 | struct kolibri_window_element *new_element = (struct kolibri_window_element *)malloc(sizeof(struct kolibri_window_element)); |
||
6396 | siemargl | 109 | |
6391 | ashmew2 | 110 | new_element -> type = element_type; |
111 | new_element -> element = some_gui_element; |
||
112 | |||
113 | if(!(some_window->elements)) /* No elements in window yet */ |
||
114 | { |
||
115 | some_window->elements = new_element; |
||
116 | some_window->elements -> prev = some_window->elements; |
||
117 | some_window->elements -> next = some_window->elements; |
||
118 | } |
||
119 | else |
||
120 | { |
||
121 | struct kolibri_window_element *last_element = some_window -> elements -> prev; |
||
6396 | siemargl | 122 | |
6391 | ashmew2 | 123 | last_element -> next = new_element; |
124 | new_element -> next = some_window -> elements; /* start of linked list */ |
||
125 | some_window -> elements -> prev = new_element; |
||
126 | new_element -> prev = last_element; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | #endif /* KOLIBRI_GUI_ELEMENTS_H */ |