Rev 6456 | Rev 6470 | 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_H |
2 | #define KOLIBRI_GUI_H |
||
3 | |||
6395 | siemargl | 4 | #include |
6391 | ashmew2 | 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 | |||
6457 | punk_joker | 22 | #define BUTTON_CLOSE 0x1 |
23 | |||
24 | void kolibri_handle_event_redraw(kolibri_window* some_window) |
||
6391 | ashmew2 | 25 | { |
26 | /* Draw windows with system color table. */ |
||
27 | |||
28 | BeginDraw(); |
||
29 | |||
6395 | siemargl | 30 | DrawWindow(some_window->topleftx, some_window->toplefty, |
6391 | ashmew2 | 31 | some_window->sizex, some_window->sizey, |
32 | some_window->window_title, |
||
33 | kolibri_color_table.color_work_area, some_window->XY); |
||
6395 | siemargl | 34 | |
6391 | ashmew2 | 35 | /* Enumerate and draw all window elements here */ |
36 | if(some_window->elements) /* Draw all elements added to window */ |
||
37 | { |
||
6457 | punk_joker | 38 | kolibri_window_element* current_element = some_window -> elements; |
6395 | siemargl | 39 | |
6391 | ashmew2 | 40 | do |
41 | { |
||
42 | /* The redraw_fn serves as draw_fn on initial draw */ |
||
43 | if(kolibri_gui_op_table[current_element -> type].redraw_fn) |
||
44 | kolibri_gui_op_table[current_element -> type].redraw_fn(current_element -> element); |
||
6395 | siemargl | 45 | |
46 | //sie after fixing calling conventions no more needed |
||
47 | /* |
||
6391 | ashmew2 | 48 | switch(current_element -> type) |
49 | { |
||
50 | case KOLIBRI_EDIT_BOX: |
||
51 | case KOLIBRI_CHECK_BOX: |
||
6395 | siemargl | 52 | __asm__ volatile("push $0x13371337"::); / * Random value pushed to balance stack * / |
53 | / * otherwise edit_box_draw leaves stack unbalanced * / |
||
54 | / * and GCC jumps like a crazy motha' fucka' * / |
||
55 | |||
6391 | ashmew2 | 56 | break; |
57 | } |
||
6395 | siemargl | 58 | */ |
59 | current_element = current_element -> next; |
||
6391 | ashmew2 | 60 | |
61 | } while(current_element != some_window->elements); /* Have we covered all elements? */ |
||
62 | } |
||
63 | } |
||
64 | |||
6457 | punk_joker | 65 | void kolibri_handle_event_key(kolibri_window* some_window) |
6391 | ashmew2 | 66 | { |
67 | /* Enumerate and trigger key handling functions of window elements here */ |
||
6395 | siemargl | 68 | if(some_window->elements) |
6391 | ashmew2 | 69 | { |
6457 | punk_joker | 70 | kolibri_window_element *current_element = some_window -> elements; |
6391 | ashmew2 | 71 | |
72 | do |
||
73 | { |
||
74 | /* Only execute if the function pointer isn't NULL */ |
||
75 | if(kolibri_gui_op_table[current_element -> type].key_fn) |
||
76 | kolibri_gui_op_table[current_element -> type].key_fn(current_element -> element); |
||
6395 | siemargl | 77 | |
6391 | ashmew2 | 78 | current_element = current_element -> next; |
79 | } while(current_element != some_window->elements); /* Have we covered all elements? */ |
||
80 | } |
||
81 | } |
||
82 | |||
6457 | punk_joker | 83 | void kolibri_handle_event_mouse(kolibri_window* some_window) |
6391 | ashmew2 | 84 | { |
85 | /* Enumerate and trigger mouse handling functions of window elements here */ |
||
6395 | siemargl | 86 | if(some_window->elements) |
6391 | ashmew2 | 87 | { |
6457 | punk_joker | 88 | kolibri_window_element *current_element = some_window -> elements; |
6391 | ashmew2 | 89 | |
90 | do |
||
91 | { |
||
92 | if(kolibri_gui_op_table[current_element -> type].mouse_fn) |
||
93 | kolibri_gui_op_table[current_element -> type].mouse_fn(current_element -> element); |
||
94 | |||
95 | current_element = current_element -> next; |
||
6395 | siemargl | 96 | |
6391 | ashmew2 | 97 | } while(current_element != some_window->elements); /* Have we covered all elements? */ |
98 | } |
||
99 | } |
||
100 | |||
101 | void kolibri_exit(void) |
||
102 | { |
||
103 | __asm__ volatile ("int $0x40"::"a"(-1)); |
||
104 | } |
||
105 | |||
106 | int kolibri_gui_init(void) |
||
107 | { |
||
108 | int boxlib_init_status = kolibri_boxlib_init(); |
||
109 | |||
6395 | siemargl | 110 | if(boxlib_init_status == 0) |
6391 | ashmew2 | 111 | debug_board_write_str("ashmew2 is happy: Kolibri GUI Successfully Initialized.\n"); |
6395 | siemargl | 112 | else |
6391 | ashmew2 | 113 | { |
114 | debug_board_write_str("ashmew2 is sad: Kolibri GUI Failed to initialize.\n"); |
||
115 | kolibri_exit(); |
||
116 | } |
||
117 | |||
118 | /* Initialize the global operation table which handles event functions of */ |
||
119 | /* each individual element type */ |
||
120 | kolibri_init_gui_op_table(); |
||
121 | |||
122 | /* Get the current color table for Kolibri and store in global table*/ |
||
123 | kolibri_get_system_colors(&kolibri_color_table); |
||
124 | |||
125 | /* Set up system events for buttons, mouse and keyboard and redraw */ |
||
126 | /* Also set filters so that window receives mouse events only when active |
||
127 | and mouse inside window */ |
||
6395 | siemargl | 128 | __asm__ volatile("int $0x40"::"a"(40), "b"(0xC0000027)); |
129 | |||
130 | return boxlib_init_status; |
||
6391 | ashmew2 | 131 | } |
132 | |||
6395 | siemargl | 133 | /* Note: The current implementation tries to automatically colors |
6391 | ashmew2 | 134 | GUI elements with system theme */ |
135 | |||
136 | #endif /* KOLIBRI_GUI_H */ |