Rev 8687 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8687 | Rev 8718 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include |
5 | #include |
6 | 6 | ||
7 | ksys_colors_table_t sys_color_table; |
7 | ksys_colors_table_t sys_color_table; |
8 | 8 | ||
9 | char statusbar[255]; |
9 | char statusbar[255]; |
10 | ksys_proc_table_t proc_info; |
10 | ksys_proc_table_t proc_info; |
11 | char text_line[255]; |
11 | char text_line[255]; |
12 | 12 | ||
13 | enum BUTTONS |
13 | enum BUTTONS |
14 | { |
14 | { |
15 | BTN_QUIT = 1, |
15 | BTN_QUIT = 1, |
16 | BTN_POP = 10, |
16 | BTN_POP = 10, |
17 | BTN_UNLOCK = 11 |
17 | BTN_UNLOCK = 11 |
18 | }; |
18 | }; |
19 | 19 | ||
20 | #define FONT_W 8 |
20 | #define FONT_W 8 |
21 | #define FONT_H 14 |
21 | #define FONT_H 14 |
22 | #define LINES 10 |
22 | #define LINES 10 |
23 | 23 | ||
24 | void draw_window() |
24 | void draw_window() |
25 | { |
25 | { |
26 | int win_hight, win_width, i, pos_y = _ksys_get_skin_height() + 36; // 60 == 24+36 |
26 | int win_hight, win_width, i, pos_y = _ksys_get_skin_height() + 36; // 60 == 24+36 |
27 | 27 | ||
28 | // start redraw |
28 | // start redraw |
29 | _ksys_start_draw(); |
29 | _ksys_start_draw(); |
30 | // define&draw window |
30 | // define&draw window |
31 | _ksys_create_window(10, 40, 600, 400, "My window", sys_color_table.work_area, 0x13); |
31 | _ksys_create_window(10, 40, 600, 400, "My window", sys_color_table.work_area, 0x13); |
32 | _ksys_process_info(&proc_info, -1); |
32 | _ksys_process_info(&proc_info, -1); |
33 | 33 | ||
34 | win_width = proc_info.winx_size; |
34 | win_width = proc_info.winx_size; |
35 | win_hight = proc_info.winy_size; |
35 | win_hight = proc_info.winy_size; |
36 | 36 | ||
37 | _ksys_define_button(10, 30, 70, 20, BTN_POP, sys_color_table.work_button); |
37 | _ksys_define_button(10, 30, 70, 20, BTN_POP, sys_color_table.work_button); |
38 | _ksys_draw_text("BUTTON1", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); //0x80000000 asciiz |
38 | _ksys_draw_text("BUTTON1", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); //0x80000000 asciiz |
39 | _ksys_define_button(100, 30, 80, 20, BTN_UNLOCK, sys_color_table.work_button); |
39 | _ksys_define_button(100, 30, 80, 20, BTN_UNLOCK, sys_color_table.work_button); |
40 | _ksys_draw_text("BUTTTON2", 110, 34, 0, 0x90000000 | sys_color_table.work_button_text); |
40 | _ksys_draw_text("BUTTTON2", 110, 34, 0, 0x90000000 | sys_color_table.work_button_text); |
41 | 41 | ||
42 | // display statusbar |
42 | // display statusbar |
43 | _ksys_draw_bar(6, win_hight - 17, win_width - 11, 12, 0x80000000 | sys_color_table.work_area); //0x80000000 gradient |
43 | _ksys_draw_bar(6, win_hight - 17, win_width - 11, 12, 0x80000000 | sys_color_table.work_area); //0x80000000 gradient |
44 | _ksys_draw_text(statusbar, 10, win_hight - 15, 0, 0x80000000 | sys_color_table.work_text); |
44 | _ksys_draw_text(statusbar, 10, win_hight - 15, 0, 0x80000000 | sys_color_table.work_text); |
45 | 45 | ||
46 | // display strings |
46 | // display strings |
47 | for (i = LINES; i > 0; i--){ |
47 | for (i = LINES; i > 0; i--){ |
48 | snprintf (text_line, sizeof text_line, "Line[%d]< |
48 | snprintf (text_line, sizeof text_line, "Line[%d]< |
49 | 49 | ||
50 | text_line[(win_width - 10 - 5) / FONT_W + 1] = '\0'; // clip text size, seems to big lines crashing OS, and form len by window size |
50 | text_line[(win_width - 10 - 5) / FONT_W + 1] = '\0'; // clip text size, seems to big lines crashing OS, and form len by window size |
51 | _ksys_draw_text(text_line, 5, pos_y, 0, 0x90000000 | sys_color_table.work_text); |
51 | _ksys_draw_text(text_line, 5, pos_y, 0, 0x90000000 | sys_color_table.work_text); |
52 | pos_y += FONT_H; |
52 | pos_y += FONT_H; |
53 | 53 | ||
54 | if(pos_y + 29 > win_hight) break; // 12 font + 12 statusbar + 5 border |
54 | if(pos_y + 29 > win_hight) break; // 12 font + 12 statusbar + 5 border |
55 | } |
55 | } |
56 | // end redraw |
56 | // end redraw |
57 | _ksys_end_draw(); |
57 | _ksys_end_draw(); |
58 | } |
58 | } |
59 | 59 | ||
60 | int main() |
60 | int main() |
61 | { |
61 | { |
62 | int gui_event; |
62 | int gui_event; |
63 | uint32_t pressed_button = 0, mouse_button; |
63 | uint32_t pressed_button = 0, mouse_button; |
64 | ksys_pos_t mouse_pos; |
64 | ksys_pos_t mouse_pos; |
65 | strcpy(statusbar, "Program running...Double click on TEXT for details"); |
65 | strcpy(statusbar, "Program running...Double click on TEXT for details"); |
66 | 66 | ||
67 | _ksys_get_colors(&sys_color_table); |
67 | _ksys_get_system_colors(&sys_color_table); |
68 | _ksys_set_event_mask(0xC0000027); // mouse events only when focused window and mouse inside |
68 | _ksys_set_event_mask(0xC0000027); // mouse events only when focused window and mouse inside |
69 | 69 | ||
70 | do{ |
70 | do{ |
71 | gui_event = _ksys_get_event(); |
71 | gui_event = _ksys_get_event(); |
72 | switch(gui_event) |
72 | switch(gui_event) |
73 | { |
73 | { |
74 | case KSYS_EVENT_NONE: |
74 | case KSYS_EVENT_NONE: |
75 | break; |
75 | break; |
76 | case KSYS_EVENT_REDRAW: |
76 | case KSYS_EVENT_REDRAW: |
77 | draw_window(); |
77 | draw_window(); |
78 | break; |
78 | break; |
79 | case KSYS_EVENT_KEY: |
79 | case KSYS_EVENT_KEY: |
80 | break; |
80 | break; |
81 | case KSYS_EVENT_BUTTON: |
81 | case KSYS_EVENT_BUTTON: |
82 | pressed_button = _ksys_get_button(); |
82 | pressed_button = _ksys_get_button(); |
83 | switch (pressed_button) |
83 | switch (pressed_button) |
84 | { |
84 | { |
85 | case BTN_POP: |
85 | case BTN_POP: |
86 | strcpy(statusbar, "POP pressed...."); |
86 | strcpy(statusbar, "POP pressed...."); |
87 | draw_window(); |
87 | draw_window(); |
88 | break; |
88 | break; |
89 | case BTN_UNLOCK: |
89 | case BTN_UNLOCK: |
90 | strcpy(statusbar, "UNLOCK pressed...."); |
90 | strcpy(statusbar, "UNLOCK pressed...."); |
91 | draw_window(); |
91 | draw_window(); |
92 | break; |
92 | break; |
93 | case BTN_QUIT: |
93 | case BTN_QUIT: |
94 | return 0; |
94 | return 0; |
95 | break; |
95 | break; |
96 | } |
96 | } |
97 | break; |
97 | break; |
98 | case KSYS_EVENT_MOUSE: |
98 | case KSYS_EVENT_MOUSE: |
99 | mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS); // window relative |
99 | mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS); // window relative |
100 | mouse_button = _ksys_get_mouse_eventstate(); |
100 | mouse_button = _ksys_get_mouse_eventstate(); |
101 | debug_printf("mouse ev (%d,%d)%x\n", mouse_pos.x, mouse_pos.y, mouse_button); |
101 | debug_printf("mouse ev (%d,%d)%x\n", mouse_pos.x, mouse_pos.y, mouse_button); |
102 | if (mouse_button & (1<<24)) // double click |
102 | if (mouse_button & (1<<24)) // double click |
103 | { |
103 | { |
104 | int n = (mouse_pos.y - 60) / FONT_H; |
104 | int n = (mouse_pos.y - 60) / FONT_H; |
105 | if (n < 0 || n >= LINES) break; |
105 | if (n < 0 || n >= LINES) break; |
106 | debug_printf("click on str(%d), clip slot(%d)\n", n, LINES - n - 1); |
106 | debug_printf("click on str(%d), clip slot(%d)\n", n, LINES - n - 1); |
107 | sprintf(statusbar, "click on str(%d), clip slot(%d)\n", n, LINES - n - 1); |
107 | sprintf(statusbar, "click on str(%d), clip slot(%d)\n", n, LINES - n - 1); |
108 | draw_window(); |
108 | draw_window(); |
109 | } |
109 | } |
110 | break; |
110 | break; |
111 | } |
111 | } |
112 | } while(1) ; /* End of main activity loop */ |
112 | } while(1) ; /* End of main activity loop */ |
113 | 113 | ||
114 | return 0; |
114 | return 0; |
115 | }>24))><24))> |
115 | }>24))><24))> |