Rev 8194 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8194 | Rev 8465 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | // BOXLIB EXAMPLE (scrollbar, progressbar) |
1 | // BOXLIB EXAMPLE (scrollbar, progressbar, editbox and checkbox) |
2 | // Writed by maxcodehack |
2 | // Writed by maxcodehack and superturbocat2001 |
3 | // GCC version is in /contrib/C_Layer/EXAMPLE/boxlib |
- | |
- | 3 | ||
4 | #include |
4 | #include |
5 | #include |
5 | #include |
- | 6 | #include |
|
6 | #include |
7 | #include |
7 | - | ||
8 | #define evReDraw 1 |
- | |
9 | #define evKey 2 |
- | |
10 | #define evButton 3 |
- | |
11 | #define evExit 4 |
- | |
12 | #define evDesktop 5 |
8 | #include |
13 | #define evMouse 6 |
- | |
14 | #define evIPC 7 |
- | |
15 | #define evNetwork 8 |
- | |
16 | #define evDebug 9 |
- | |
Line 17... | Line 9... | ||
17 | 9 | ||
18 | #define WIN_W 640 |
10 | #define WIN_W 640 |
Line -... | Line 11... | ||
- | 11 | #define WIN_H 563 |
|
- | 12 | ||
- | 13 | #define ED_BUFF_LEN 50 |
|
- | 14 | #define TEXT_SIZE 0x10000000 |
|
- | 15 | #define SCROLL_BUTTON_SIZE 15 |
|
- | 16 | #define SCROLL_MAX_LEN 215 |
|
- | 17 | #define BLACK 0x000000 |
|
- | 18 | #define WHITE 0xFFFFFF |
|
19 | #define WIN_H 563 |
19 | #define BLUE 0x0000FF |
20 | 20 | ||
21 | uint32_t wheels; |
- | |
22 | char* title = "Boxlib example"; |
21 | uint32_t wheels; |
Line 23... | Line 22... | ||
23 | scrollbar scroll = {15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, 15, 0,0x707070,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
22 | char* title = "Boxlib example"; |
24 | progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9}; |
- | |
- | 23 | char ed_buff[ED_BUFF_LEN]; |
|
25 | 24 | ||
26 | /* |
- | |
- | 25 | ||
- | 26 | scrollbar scroll = {15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, SCROLL_BUTTON_SIZE, 0,0x707070,0xD2CED0,0x555555}; |
|
Line 27... | Line 27... | ||
27 | // System colors |
27 | progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9}; |
28 | struct kolibri_system_colors sys_color; |
28 | edit_box ed={WIN_W-140,10,60,0xFFFFFF,0x6a9480,0,0x6a9480, BLACK | TEXT_SIZE, ED_BUFF_LEN, ed_buff,NULL,ed_focus}; |
29 | */ |
29 | check_box output_off={X_W(10, 15), Y_H(120,15), 10, WHITE, BLUE, BLACK | TEXT_SIZE, "Disable duplicate output",0}; |
- | 30 | ||
- | 31 | void draw_window(){ |
|
- | 32 | BeginDraw(); |
|
- | 33 | DrawWindow(215,100,WIN_W,WIN_H,title, 0x858585, 0x34); |
|
- | 34 | edit_box_draw(&ed); |
|
- | 35 | check_box_draw2(&output_off); |
|
30 | 36 | if(!output_off.flags) |
|
31 | void draw_window(){ |
37 | { |
32 | BeginDraw(); |
38 | draw_text_sys(ed_buff, 10, 90, strlen(ed_buff), BLACK | TEXT_SIZE); |
33 | DrawWindow(215,100,WIN_W,WIN_H,title, /* sys_color.work_area */ 0x858585, 0x34); |
39 | } |
Line 53... | Line 59... | ||
53 | 59 | ||
54 | 60 | ||
55 | int main() |
61 | int main() |
56 | { |
- | |
57 | kolibri_boxlib_init(); |
62 | { |
58 | /* |
- | |
59 | get_system_colors(&sys_color); |
63 | kolibri_boxlib_init(); |
60 | */ |
64 | init_checkbox2(&output_off); |
61 | set_event_mask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
65 | set_event_mask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE+EVM_MOUSE_FILTER); |
62 | while(1) |
66 | while(1) |
63 | { |
67 | { |
64 | switch(GetOsEvent()) |
68 | switch(GetOsEvent()) |
65 | { |
69 | { |
66 | case evButton: |
70 | case KOLIBRI_EVENT_BUTTON: |
Line 67... | Line 71... | ||
67 | if (get_os_button() == 1) exit(0); |
71 | if (get_os_button() == 1) exit(0); |
68 | break; |
72 | break; |
69 | 73 | ||
Line 70... | Line 74... | ||
70 | case evKey: |
74 | case KOLIBRI_EVENT_KEY: |
71 | get_key(); |
75 | edit_box_key(&ed, get_key().val); |
72 | break; |
76 | break; |
73 | 77 | ||
- | 78 | case KOLIBRI_EVENT_REDRAW: |
|
74 | case evReDraw: |
79 | draw_window(); |
75 | draw_window(); |
- | |
76 | break; |
80 | break; |
77 | case evMouse: |
81 | case KOLIBRI_EVENT_MOUSE: |
78 | scrollbar_v_mouse(&scroll); |
82 | edit_box_mouse(&ed); |
79 | 83 | scrollbar_v_mouse(&scroll); |
|
80 | // Wheel scrolling |
84 | pg.value = scroll.position; |
81 | // Quite unstable |
85 | progressbar_draw(&pg); |
82 | /* |
86 | check_box_mouse2(&output_off); |
83 | int scroll_strong = 40; |
87 | unsigned int scroll_strong = 10; |
84 | wheels = GetMouseWheels(); |
88 | wheels = GetMouseWheels(); |
- | 89 | if(wheels & 0xFFFF) |
|
- | 90 | { |
|
- | 91 | if((short)wheels > 0){ |
|
- | 92 | scroll.position += scroll_strong; |
|
- | 93 | if(scroll.position>scroll.max_area-scroll.cur_area) |
|
85 | if(wheels & 0xFFFF) |
94 | { |
86 | { |
95 | scroll.position=scroll.max_area-scroll.cur_area; |
87 | if((short)wheels > 0 && scroll.position < scroll.max_area - scroll_strong) |
96 | } |
88 | scroll.position += scroll_strong; |
97 | } |
89 | else if((short)wheels < 0 && scroll.position > 0) |
98 | else if((short)wheels < 0 && scroll.position > 0){ |
90 | scroll.position -= scroll_strong; |
- | |
91 | - | ||
92 | scrollbar_v_draw(&scroll); |
- | |
93 | } |
99 | scroll.position -= scroll_strong; |
94 | */ |
100 | } |
95 | pg.value = scroll.position; |
101 | scrollbar_v_draw(&scroll); |
96 | progressbar_draw(&pg); |
102 | } |