Rev 6470 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6470 | Rev 6479 | ||
---|---|---|---|
1 | #ifndef KOLIBRI_GUI_H |
1 | #ifndef KOLIBRI_GUI_H |
2 | #define KOLIBRI_GUI_H |
2 | #define KOLIBRI_GUI_H |
3 | - | ||
4 | #include |
- | |
5 | #include |
- | |
6 | 3 | ||
7 | #include "kolibri_debug.h" /* work with debug board */ |
4 | #include "kolibri_debug.h" /* work with debug board */ |
8 | 5 | ||
9 | /* boxlib loader */ |
6 | /* boxlib loader */ |
10 | #include "kolibri_boxlib.h" |
7 | #include "kolibri_boxlib.h" |
11 | 8 | ||
12 | /* All supported GUI elements included */ |
9 | /* All supported GUI elements included */ |
13 | #include "kolibri_gui_elements.h" |
10 | #include "kolibri_gui_elements.h" |
14 | 11 | ||
15 | enum KOLIBRI_GUI_EVENTS { |
12 | enum KOLIBRI_GUI_EVENTS { |
16 | KOLIBRI_EVENT_NONE = 0, /* Event queue is empty */ |
13 | KOLIBRI_EVENT_NONE = 0, /* Event queue is empty */ |
17 | KOLIBRI_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */ |
14 | KOLIBRI_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */ |
18 | KOLIBRI_EVENT_KEY = 2, /* A key on the keyboard was pressed */ |
15 | KOLIBRI_EVENT_KEY = 2, /* A key on the keyboard was pressed */ |
19 | KOLIBRI_EVENT_BUTTON = 3, /* A button was clicked with the mouse */ |
16 | KOLIBRI_EVENT_BUTTON = 3, /* A button was clicked with the mouse */ |
20 | KOLIBRI_EVENT_DESKTOP = 5, /* Desktop redraw finished */ |
17 | KOLIBRI_EVENT_DESKTOP = 5, /* Desktop redraw finished */ |
21 | KOLIBRI_EVENT_MOUSE = 6, /* Mouse activity (movement, button press) was detected */ |
18 | KOLIBRI_EVENT_MOUSE = 6, /* Mouse activity (movement, button press) was detected */ |
22 | KOLIBRI_EVENT_IPC = 7, /* Interprocess communication notify */ |
19 | KOLIBRI_EVENT_IPC = 7, /* Interprocess communication notify */ |
23 | KOLIBRI_EVENT_NETWORK = 8, /* Network event */ |
20 | KOLIBRI_EVENT_NETWORK = 8, /* Network event */ |
24 | KOLIBRI_EVENT_DEBUG = 9, /* Debug subsystem event */ |
21 | KOLIBRI_EVENT_DEBUG = 9, /* Debug subsystem event */ |
25 | KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */ |
22 | KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */ |
26 | }; |
23 | }; |
27 | 24 | ||
28 | #define BUTTON_CLOSE 0x1 |
25 | #define BUTTON_CLOSE 0x1 |
29 | #define BTN_QUIT 1 |
26 | #define BTN_QUIT 1 |
30 | 27 | ||
31 | void kolibri_handle_event_redraw(kolibri_window* some_window) |
28 | void kolibri_handle_event_redraw(kolibri_window* some_window) |
32 | { |
29 | { |
33 | /* Draw windows with system color table. */ |
30 | /* Draw windows with system color table. */ |
34 | 31 | ||
35 | BeginDraw(); |
32 | BeginDraw(); |
36 | 33 | ||
37 | DrawWindow(some_window->topleftx, some_window->toplefty, |
34 | DrawWindow(some_window->topleftx, some_window->toplefty, |
38 | some_window->sizex, some_window->sizey, |
35 | some_window->sizex, some_window->sizey, |
39 | some_window->window_title, |
36 | some_window->window_title, |
40 | kolibri_color_table.color_work_area, some_window->XY); |
37 | kolibri_color_table.color_work_area, some_window->XY); |
41 | 38 | ||
42 | /* Enumerate and draw all window elements here */ |
39 | /* Enumerate and draw all window elements here */ |
43 | if(some_window->elements) /* Draw all elements added to window */ |
40 | if(some_window->elements) /* Draw all elements added to window */ |
44 | { |
41 | { |
45 | kolibri_window_element* current_element = some_window -> elements; |
42 | kolibri_window_element* current_element = some_window -> elements; |
46 | 43 | ||
47 | do |
44 | do |
48 | { |
45 | { |
49 | /* The redraw_fn serves as draw_fn on initial draw */ |
46 | /* The redraw_fn serves as draw_fn on initial draw */ |
50 | if((int)kolibri_gui_op_table[current_element -> type].redraw_fn > 0) // -1 if DLL link fail |
47 | if((int)kolibri_gui_op_table[current_element -> type].redraw_fn > 0) // -1 if DLL link fail |
51 | kolibri_gui_op_table[current_element -> type].redraw_fn(current_element -> element); |
48 | kolibri_gui_op_table[current_element -> type].redraw_fn(current_element -> element); |
52 | 49 | ||
53 | //sie after fixing calling conventions no more needed |
50 | //sie after fixing calling conventions no more needed |
54 | /* |
51 | /* |
55 | switch(current_element -> type) |
52 | switch(current_element -> type) |
56 | { |
53 | { |
57 | case KOLIBRI_EDIT_BOX: |
54 | case KOLIBRI_EDIT_BOX: |
58 | case KOLIBRI_CHECK_BOX: |
55 | case KOLIBRI_CHECK_BOX: |
59 | __asm__ volatile("push $0x13371337"::); / * Random value pushed to balance stack * / |
56 | __asm__ volatile("push $0x13371337"::); / * Random value pushed to balance stack * / |
60 | / * otherwise edit_box_draw leaves stack unbalanced * / |
57 | / * otherwise edit_box_draw leaves stack unbalanced * / |
61 | / * and GCC jumps like a crazy motha' fucka' * / |
58 | / * and GCC jumps like a crazy motha' fucka' * / |
62 | 59 | ||
63 | break; |
60 | break; |
64 | } |
61 | } |
65 | */ |
62 | */ |
66 | current_element = current_element -> next; |
63 | current_element = current_element -> next; |
67 | 64 | ||
68 | } while(current_element != some_window->elements); /* Have we covered all elements? */ |
65 | } while(current_element != some_window->elements); /* Have we covered all elements? */ |
69 | } |
66 | } |
70 | } |
67 | } |
71 | 68 | ||
72 | void kolibri_handle_event_key(kolibri_window* some_window) |
69 | void kolibri_handle_event_key(kolibri_window* some_window) |
73 | { |
70 | { |
74 | /* Enumerate and trigger key handling functions of window elements here */ |
71 | /* Enumerate and trigger key handling functions of window elements here */ |
75 | if(some_window->elements) |
72 | if(some_window->elements) |
76 | { |
73 | { |
77 | kolibri_window_element *current_element = some_window -> elements; |
74 | kolibri_window_element *current_element = some_window -> elements; |
78 | 75 | ||
79 | do |
76 | do |
80 | { |
77 | { |
81 | /* Only execute if the function pointer isn't NULL */ |
78 | /* Only execute if the function pointer isn't NULL */ |
82 | if((int)kolibri_gui_op_table[current_element -> type].key_fn > 0) |
79 | if((int)kolibri_gui_op_table[current_element -> type].key_fn > 0) |
83 | kolibri_gui_op_table[current_element -> type].key_fn(current_element -> element); |
80 | kolibri_gui_op_table[current_element -> type].key_fn(current_element -> element); |
84 | 81 | ||
85 | current_element = current_element -> next; |
82 | current_element = current_element -> next; |
86 | } while(current_element != some_window->elements); /* Have we covered all elements? */ |
83 | } while(current_element != some_window->elements); /* Have we covered all elements? */ |
87 | } |
84 | } |
88 | } |
85 | } |
89 | 86 | ||
90 | void kolibri_handle_event_mouse(kolibri_window* some_window) |
87 | void kolibri_handle_event_mouse(kolibri_window* some_window) |
91 | { |
88 | { |
92 | /* Enumerate and trigger mouse handling functions of window elements here */ |
89 | /* Enumerate and trigger mouse handling functions of window elements here */ |
93 | if(some_window->elements) |
90 | if(some_window->elements) |
94 | { |
91 | { |
95 | kolibri_window_element *current_element = some_window -> elements; |
92 | kolibri_window_element *current_element = some_window -> elements; |
96 | 93 | ||
97 | do |
94 | do |
98 | { |
95 | { |
99 | if((int)kolibri_gui_op_table[current_element -> type].mouse_fn > 0) |
96 | if((int)kolibri_gui_op_table[current_element -> type].mouse_fn > 0) |
100 | kolibri_gui_op_table[current_element -> type].mouse_fn(current_element -> element); |
97 | kolibri_gui_op_table[current_element -> type].mouse_fn(current_element -> element); |
101 | 98 | ||
102 | current_element = current_element -> next; |
99 | current_element = current_element -> next; |
103 | 100 | ||
104 | } while(current_element != some_window->elements); /* Have we covered all elements? */ |
101 | } while(current_element != some_window->elements); /* Have we covered all elements? */ |
105 | } |
102 | } |
106 | } |
103 | } |
107 | 104 | ||
108 | void kolibri_exit(void) |
105 | void kolibri_exit(void) |
109 | { |
106 | { |
110 | __asm__ volatile ("int $0x40"::"a"(-1)); |
107 | __asm__ volatile ("int $0x40"::"a"(-1)); |
111 | } |
108 | } |
112 | 109 | ||
113 | int kolibri_gui_init(void) |
110 | int kolibri_gui_init(void) |
114 | { |
111 | { |
115 | int boxlib_init_status = kolibri_boxlib_init(); |
112 | int boxlib_init_status = kolibri_boxlib_init(); |
116 | 113 | ||
117 | if(boxlib_init_status == 0) |
114 | if(boxlib_init_status == 0) |
118 | debug_board_write_str("ashmew2 is happy: Kolibri GUI Successfully Initialized.\n"); |
115 | debug_board_write_str("ashmew2 is happy: Kolibri GUI Successfully Initialized.\n"); |
119 | else |
116 | else |
120 | { |
117 | { |
121 | debug_board_write_str("ashmew2 is sad: Kolibri GUI Failed to initialize.\n"); |
118 | debug_board_write_str("ashmew2 is sad: Kolibri GUI Failed to initialize.\n"); |
122 | kolibri_exit(); |
119 | kolibri_exit(); |
123 | } |
120 | } |
124 | 121 | ||
125 | /* Initialize the global operation table which handles event functions of */ |
122 | /* Initialize the global operation table which handles event functions of */ |
126 | /* each individual element type */ |
123 | /* each individual element type */ |
127 | kolibri_init_gui_op_table(); |
124 | kolibri_init_gui_op_table(); |
128 | 125 | ||
129 | /* Get the current color table for Kolibri and store in global table*/ |
126 | /* Get the current color table for Kolibri and store in global table*/ |
130 | kolibri_get_system_colors(&kolibri_color_table); |
127 | kolibri_get_system_colors(&kolibri_color_table); |
131 | 128 | ||
132 | /* Set up system events for buttons, mouse and keyboard and redraw */ |
129 | /* Set up system events for buttons, mouse and keyboard and redraw */ |
133 | /* Also set filters so that window receives mouse events only when active |
130 | /* Also set filters so that window receives mouse events only when active |
134 | and mouse inside window */ |
131 | and mouse inside window */ |
135 | __asm__ volatile("int $0x40"::"a"(40), "b"(0xC0000027)); |
132 | __asm__ volatile("int $0x40"::"a"(40), "b"(0xC0000027)); |
136 | 133 | ||
137 | return boxlib_init_status; |
134 | return boxlib_init_status; |
138 | } |
135 | } |
139 | 136 | ||
140 | /* Note: The current implementation tries to automatically colors |
137 | /* Note: The current implementation tries to automatically colors |
141 | GUI elements with system theme */ |
138 | GUI elements with system theme */ |
142 | 139 | ||
143 | #endif /* KOLIBRI_GUI_H */ |
140 | #endif /* KOLIBRI_GUI_H */ |