Rev 6601 | Rev 6615 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6589 | siemargl | 1 | |
2 | KolibriGUI demobox |
||
3 | -Editor (multiline edit) |
||
4 | -TreeView |
||
5 | -MsgBox Dialog |
||
6 | |||
7 | |||
8 | |||
9 | |||
10 | |||
11 | |||
12 | |||
13 | */ |
||
14 | |||
15 | |||
16 | #include |
||
17 | #include |
||
18 | #include |
||
19 | #include "kos32sys.h" |
||
20 | #include "kolibri_gui.h" |
||
21 | #include "kolibri_libimg.h" |
||
22 | #include "kolibri_msgbox.h" |
||
23 | |||
24 | |||
6601 | siemargl | 25 | char fname[4096]; |
26 | |||
6589 | siemargl | 27 | |
28 | char* load_image_file(char* fname); // see below |
||
6601 | siemargl | 29 | |
6589 | siemargl | 30 | |
6612 | siemargl | 31 | // 0 - ASCII, 1 - SCAN |
32 | { |
||
33 | __asm__ __volatile__( |
||
34 | "int $0x40" |
||
35 | ::"a"(66), "b"(1), "c"(mode)); |
||
36 | }; |
||
37 | |||
38 | |||
39 | |||
6589 | siemargl | 40 | { |
41 | /* Load all libraries, initialize global tables like system color table and |
||
42 | operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails |
||
43 | to do it's job. This is all you need to call and all libraries and GUI |
||
44 | elements can be used after a successful call to this function |
||
45 | */ |
||
46 | kolibri_gui_init(); |
||
47 | set_os_keyb_mode(1); // scan code mode needed for editor |
||
6612 | siemargl | 48 | // kolibri_proclib_init(); // opensave && color dialogs |
6601 | siemargl | 49 | kolibri_libimg_init(); // png handling |
6589 | siemargl | 50 | |
51 | |||
52 | uint32_t pressed_button = 0; |
||
53 | // uint32_t mouse_button; |
||
54 | // pos_t mouse_pos; |
||
55 | // oskey_t keypress; |
||
6612 | siemargl | 56 | |
6589 | siemargl | 57 | |
58 | strcpy(run_path, argv[0]); |
||
6601 | siemargl | 59 | char *pc = strrchr(run_path, '/'); // this fails if has params with '/' within. use argv[0] instead |
60 | if (pc) pc[1] = 0; |
||
6589 | siemargl | 61 | // debug_board_write_str(temp_path); |
62 | |||
63 | |||
64 | kolibri_window *main_window = kolibri_new_window(50, 40, 490, 500, "Editor, TreeView and MsgBox demo"); |
||
6601 | siemargl | 65 | |
6589 | siemargl | 66 | |
67 | void *ed_lock; |
||
6612 | siemargl | 68 | |
6589 | siemargl | 69 | |
6612 | siemargl | 70 | ed_lock = ed; |
71 | /* |
||
72 | // load sample file |
||
73 | int res, len; |
||
74 | res = editor_openfile(ed, "/rd/1/boardlog.txt", &len); |
||
75 | debug_board_printf("loaded sample file err=%d, len=%d\n", res, len); |
||
76 | */ |
||
77 | //adding sample text @cursor |
||
78 | char *sampletext = "==========ADDED SAMPLE TEXT==========\n"; |
||
79 | (*ted_text_add)(ed, sampletext, strlen(sampletext), 0); |
||
80 | |||
81 | |||
82 | treelist *tl = kolibri_new_treelist(X_Y(0, 200), X_Y(200, 200), 16, X_Y(16, 16), 100, 50, 0, 0, TL_KEY_NO_EDIT | TL_DRAW_PAR_LINE, &ed_lock, 0x8080ff, 0x0000ff, 0xffffff); |
||
83 | treelist_data_init(tl); |
||
6601 | siemargl | 84 | |
6589 | siemargl | 85 | |
6601 | siemargl | 86 | strcpy(fname, run_path); |
87 | strcat(fname, "tl_sys_16.png"); |
||
88 | tl->data_img_sys = load_image_file(fname); |
||
89 | |||
6589 | siemargl | 90 | |
6601 | siemargl | 91 | strcpy(fname, run_path); |
92 | strcat(fname, "tl_nod_16.png"); |
||
93 | tl->data_img = load_image_file(fname); |
||
94 | |||
6589 | siemargl | 95 | |
6601 | siemargl | 96 | treelist_cursor_next(tl); |
97 | treelist_node_add(tl, "node1.1", 1, 0, 1); |
||
6612 | siemargl | 98 | treelist_cursor_next(tl); |
99 | treelist_node_add(tl, "node1.1.1", 0, 0, 2); |
||
100 | treelist_cursor_next(tl); |
||
101 | treelist_node_add(tl, "node1.2", 1, 0, 1); |
||
102 | treelist_cursor_next(tl); |
||
103 | |||
6589 | siemargl | 104 | |
6612 | siemargl | 105 | treelist_cursor_next(tl); |
6601 | siemargl | 106 | treelist_node_add(tl, "node2.1", 1, 0, 1); |
6612 | siemargl | 107 | treelist_cursor_next(tl); |
108 | |||
6601 | siemargl | 109 | |
110 | treelist_cursor_next(tl); |
||
111 | |||
112 | |||
113 | gui_add_treelist(main_window, tl); |
||
114 | |||
115 | |||
6612 | siemargl | 116 | treelist *tl2 = kolibri_new_treelist(X_Y(220, 200), X_Y(200, 200), 16, X_Y(16, 16), 100, 50, 0, 0, TL_LISTBOX_MODE, &ed_lock, 0x8080ff, 0x0000ff, 0xffffff); |
117 | treelist_data_init(tl2); |
||
118 | |||
119 | |||
120 | tl2->data_img = tl->data_img; |
||
121 | |||
122 | |||
123 | treelist_cursor_next(tl2); |
||
124 | |||
125 | |||
126 | treelist_cursor_next(tl2); |
||
127 | |||
128 | |||
129 | treelist_cursor_next(tl2); |
||
130 | |||
131 | |||
132 | gui_add_treelist(main_window, tl2); |
||
133 | |||
134 | |||
6589 | siemargl | 135 | |
136 | |||
6612 | siemargl | 137 | do /* Start of main activity loop */ |
6589 | siemargl | 138 | { |
139 | switch(gui_event) |
||
140 | { |
||
141 | case KOLIBRI_EVENT_REDRAW: |
||
142 | if (box->retval == 1 || box->retval == 2) goto clearing; // msgbox closes |
||
6601 | siemargl | 143 | |
6589 | siemargl | 144 | |
145 | break; |
||
146 | case KOLIBRI_EVENT_NONE: |
||
147 | break; |
||
148 | case KOLIBRI_EVENT_KEY: |
||
149 | key = get_key(); |
||
6612 | siemargl | 150 | trap(0x55); // for stop in debug |
151 | if (ed_lock == ed) |
||
6589 | siemargl | 152 | editor_key(ed, key); |
6612 | siemargl | 153 | else if(ed_lock == tl) |
154 | { |
||
155 | treelist_key(tl, key); |
||
156 | } |
||
157 | else if(ed_lock == tl2) |
||
158 | { |
||
159 | treelist_key(tl2, key); |
||
160 | } |
||
161 | else |
||
6589 | siemargl | 162 | kolibri_handle_event_key(main_window, key); |
6612 | siemargl | 163 | break; |
6589 | siemargl | 164 | case KOLIBRI_EVENT_BUTTON: |
165 | pressed_button = get_os_button(); |
||
166 | switch (pressed_button) |
||
167 | { |
||
168 | case BTN_QUIT: |
||
169 | if (box->retval == 3 || box->retval == 0) // not started or cancelled, analyze when redraw after closing msgbox |
||
170 | kolibri_start_msgbox(box, NULL); |
||
6601 | siemargl | 171 | break; |
6589 | siemargl | 172 | } |
173 | break; |
||
174 | case KOLIBRI_EVENT_MOUSE: |
||
175 | kolibri_handle_event_mouse(main_window); |
||
176 | break; |
||
177 | } |
||
178 | |||
179 | |||
180 | } while(1) ; /* End of main activity loop */ |
||
181 | |||
6601 | siemargl | 182 | |
183 | editor_delete(ed); |
||
184 | treelist_data_clear(tl); |
||
185 | |||
6589 | siemargl | 186 | |
187 | } |
||
188 | |||
6601 | siemargl | 189 | |
190 | |||
191 | { |
||
192 | FILE *f = fopen(fname, "rb"); |
||
193 | if (!f) { |
||
194 | debug_board_printf("Can't open file: %s", fname); |
||
195 | exit(1); |
||
196 | } |
||
197 | if (fseek(f, 0, SEEK_END)) { |
||
198 | debug_board_printf("Can't SEEK_END file: %s", fname); |
||
199 | exit(1); |
||
200 | } |
||
201 | int filesize = ftell(f); |
||
202 | rewind(f); |
||
203 | char* fdata = malloc(filesize); |
||
204 | if(!fdata) { |
||
205 | debug_board_printf("No memory for file %s", fname); |
||
206 | exit(1); |
||
207 | } |
||
208 | *read_sz = fread(fdata, 1, filesize, f); |
||
209 | if (ferror(f)) { |
||
210 | debug_board_printf("Error reading file %s", fname); |
||
211 | exit(1); |
||
212 | } |
||
213 | fclose(f); |
||
214 | |||
215 | |||
216 | } |
||
217 | |||
218 | |||
219 | { |
||
220 | int32_t read_bytes = -1, w, h; |
||
221 | char *image_data = 0, *image_data_rgb = 0, *filedata = 0; |
||
222 | |||
223 | |||
224 | // определяем вид изображения и переводим его во временный буфер image_data |
||
225 | image_data = (*img_decode)(filedata, read_bytes, 0); |
||
226 | w = *(int*)(image_data +4); |
||
227 | h = *(int*)(image_data +8); |
||
228 | image_data_rgb = malloc(w * h * 3); |
||
229 | // преобразуем изображение к формату rgb |
||
230 | (*img_to_rgb2)(image_data, image_data_rgb); |
||
231 | // удаляем временный буфер image_data |
||
232 | (*img_destroy)(image_data); |
||
233 | free(filedata); |
||
234 | |||
235 | |||
236 | } |
||
237 |