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