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