Rev 6516 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6516 | Rev 6589 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | KolibriGUI demobox |
2 | KolibriGUI demobox |
3 | -Button |
3 | -Button |
4 | -CheckBox |
4 | -CheckBox |
5 | -EditBox |
5 | -EditBox |
6 | -Frame |
6 | -Frame |
7 | 7 | ||
8 | Free for all |
8 | Free for all |
9 | 9 | ||
10 | Initially written by ashmew2, 2015 |
10 | Initially written by ashmew2, 2015 |
11 | 11 | ||
12 | Updated by Siemargl, 2016 |
12 | Updated by Siemargl, 2016 |
13 | 13 | ||
14 | ToDo |
14 | ToDo |
15 | */ |
15 | */ |
16 | 16 | ||
17 | #include |
17 | #include |
18 | #include |
18 | #include |
19 | #include |
19 | #include |
20 | #include |
20 | #include |
21 | 21 | ||
22 | int main() |
22 | int main() |
23 | { |
23 | { |
24 | /* Load all libraries, initialize global tables like system color table and |
24 | /* Load all libraries, initialize global tables like system color table and |
25 | operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails |
25 | operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails |
26 | to do it's job. This is all you need to call and all libraries and GUI |
26 | to do it's job. This is all you need to call and all libraries and GUI |
27 | elements can be used after a successful call to this function |
27 | elements can be used after a successful call to this function |
28 | */ |
28 | */ |
29 | kolibri_gui_init(); |
29 | kolibri_gui_init(); |
30 | /* Set gui_event to REDRAW so that window is drawn in first iteration */ |
30 | /* Set gui_event to REDRAW so that window is drawn in first iteration */ |
31 | unsigned int gui_event = KOLIBRI_EVENT_REDRAW; |
31 | unsigned int gui_event = KOLIBRI_EVENT_REDRAW; |
32 | oskey_t key; |
32 | oskey_t key; |
33 | 33 | ||
34 | kolibri_window *main_window = kolibri_new_window(50, 40, 400, 120, "BoardMsg"); |
34 | kolibri_window *main_window = kolibri_new_window(50, 40, 400, 120, "BoardMsg"); |
35 | check_box *checkbox = kolibri_new_check_box(20, 15, 12, 12, "Append BOARDMSG to entered message."); |
35 | check_box *checkbox = kolibri_new_check_box(20, 15, 12, 12, "Append BOARDMSG to entered message."); |
36 | 36 | ||
37 | edit_box *editbox_interlock = NULL; |
37 | edit_box *editbox_interlock = NULL; |
38 | edit_box *textbox = kolibri_new_edit_box(20, 30, 40, &editbox_interlock); |
38 | edit_box *textbox = kolibri_new_edit_box(20, 30, 40, &editbox_interlock); |
39 | edit_box *textbox2 = kolibri_new_edit_box(20, 50, 30, &editbox_interlock); |
39 | edit_box *textbox2 = kolibri_new_edit_box(20, 50, 30, &editbox_interlock); |
40 | kolibri_button *button = kolibri_new_button(310, 30, 24, 14, 0x21, kolibri_color_table.color_work_button); |
40 | kolibri_button *button = kolibri_new_button(310, 30, 24, 14, 0x21, kolibri_color_table.color_work_button); |
41 | frame *fr = kolibri_new_frame(X_Y(12, 350), X_Y(5, 70), 0x00FCFCFC, 0x00DCDCDC, "Frame Title", 0, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area); |
41 | frame *fr = kolibri_new_frame(X_Y(12, 350), X_Y(5, 70), 0x00FCFCFC, 0x00DCDCDC, "Frame Title", 0, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area, 0); |
42 | 42 | ||
43 | kolibri_window_add_element(main_window, KOLIBRI_EDIT_BOX, textbox); |
43 | kolibri_window_add_element(main_window, KOLIBRI_EDIT_BOX, textbox); |
44 | kolibri_window_add_element(main_window, KOLIBRI_EDIT_BOX, textbox2); |
44 | kolibri_window_add_element(main_window, KOLIBRI_EDIT_BOX, textbox2); |
45 | kolibri_window_add_element(main_window, KOLIBRI_CHECK_BOX, checkbox); |
45 | kolibri_window_add_element(main_window, KOLIBRI_CHECK_BOX, checkbox); |
46 | kolibri_window_add_element(main_window, KOLIBRI_BUTTON, button); |
46 | kolibri_window_add_element(main_window, KOLIBRI_BUTTON, button); |
47 | kolibri_window_add_element(main_window, KOLIBRI_FRAME, fr); |
47 | kolibri_window_add_element(main_window, KOLIBRI_FRAME, fr); |
48 | 48 | ||
49 | (*edit_box_set_text)(textbox2, "Sample text very long to get shorted"); |
49 | (*edit_box_set_text)(textbox2, "Sample text very long to get shorted"); |
50 | 50 | ||
51 | extern volatile unsigned press_key; |
51 | extern volatile unsigned press_key; |
52 | 52 | ||
53 | do /* Start of main activity loop */ |
53 | do /* Start of main activity loop */ |
54 | { |
54 | { |
55 | if(gui_event == KOLIBRI_EVENT_REDRAW) |
55 | if(gui_event == KOLIBRI_EVENT_REDRAW) |
56 | { |
56 | { |
57 | kolibri_handle_event_redraw(main_window); |
57 | kolibri_handle_event_redraw(main_window); |
58 | } |
58 | } |
59 | else if(gui_event == KOLIBRI_EVENT_KEY) |
59 | else if(gui_event == KOLIBRI_EVENT_KEY) |
60 | { |
60 | { |
61 | key = get_key(); |
61 | key = get_key(); |
62 | switch (key.code) |
62 | switch (key.code) |
63 | { |
63 | { |
64 | case 13: |
64 | case 13: |
65 | if(checkbox -> flags & CHECKBOX_IS_SET) /* Append BoardMsg checkbox is set */ |
65 | if(checkbox -> flags & CHECKBOX_IS_SET) /* Append BoardMsg checkbox is set */ |
66 | debug_board_write_str("BOARDMSG: "); |
66 | debug_board_write_str("BOARDMSG: "); |
67 | 67 | ||
68 | debug_board_write_str(textbox->text); |
68 | debug_board_write_str(textbox->text); |
69 | debug_board_write_str("\n"); |
69 | debug_board_write_str("\n"); |
70 | break; |
70 | break; |
71 | } |
71 | } |
72 | press_key = key.val; |
72 | press_key = key.val; |
73 | 73 | ||
74 | kolibri_handle_event_key(main_window); |
74 | kolibri_handle_event_key(main_window); |
75 | } |
75 | } |
76 | else if(gui_event == KOLIBRI_EVENT_BUTTON) |
76 | else if(gui_event == KOLIBRI_EVENT_BUTTON) |
77 | { |
77 | { |
78 | unsigned int pressed_button = kolibri_button_get_identifier(); |
78 | unsigned int pressed_button = kolibri_button_get_identifier(); |
79 | switch (pressed_button) |
79 | switch (pressed_button) |
80 | { |
80 | { |
81 | case 0x21: |
81 | case 0x21: |
82 | if(checkbox -> flags & CHECKBOX_IS_SET) /* Append BoardMsg checkbox is set */ |
82 | if(checkbox -> flags & CHECKBOX_IS_SET) /* Append BoardMsg checkbox is set */ |
83 | debug_board_write_str("BOARDMSG: "); |
83 | debug_board_write_str("BOARDMSG: "); |
84 | debug_board_write_str(textbox->text); |
84 | debug_board_write_str(textbox->text); |
85 | debug_board_write_str("\n"); |
85 | debug_board_write_str("\n"); |
86 | break; |
86 | break; |
87 | case BUTTON_CLOSE: |
87 | case BUTTON_CLOSE: |
88 | kolibri_exit(); |
88 | kolibri_exit(); |
89 | } |
89 | } |
90 | } |
90 | } |
91 | else if(gui_event == KOLIBRI_EVENT_MOUSE) |
91 | else if(gui_event == KOLIBRI_EVENT_MOUSE) |
92 | { |
92 | { |
93 | kolibri_handle_event_mouse(main_window); |
93 | kolibri_handle_event_mouse(main_window); |
94 | } |
94 | } |
95 | 95 | ||
96 | } while((gui_event = get_os_event())); /* End of main activity loop */ |
96 | } while((gui_event = get_os_event())); /* End of main activity loop */ |
97 | 97 | ||
98 | /* kolibri_quit(); */ |
98 | /* kolibri_quit(); */ |
99 | 99 | ||
100 | return 0; |
100 | return 0; |
101 | } |
101 | } |