Rev 6612 | Rev 6690 | 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 | |||
6615 | siemargl | 72 | |
6612 | siemargl | 73 | //int res, len; |
6615 | siemargl | 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 | |||
6612 | siemargl | 78 | char *sampletext = "*123*=========ADDED SAMPLE TEXT=========*789*\n"; |
6615 | siemargl | 79 | (*ted_text_add)(ed, sampletext, strlen(sampletext), 0); |
6612 | siemargl | 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 | (*tl_data_init)(tl); |
||
6615 | 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 | (*tl_cur_next)(tl); |
6615 | siemargl | 97 | treelist_node_add(tl, "node1.1", 1, 0, 1); |
6612 | siemargl | 98 | (*tl_cur_next)(tl); |
6615 | siemargl | 99 | treelist_node_add(tl, "node1.1.1", 0, 0, 2); |
6612 | siemargl | 100 | (*tl_cur_next)(tl); |
6615 | siemargl | 101 | treelist_node_add(tl, "node1.2", 1, 0, 1); |
6612 | siemargl | 102 | (*tl_cur_next)(tl); |
6615 | siemargl | 103 | |
6589 | siemargl | 104 | |
6612 | siemargl | 105 | (*tl_cur_next)(tl); |
6615 | siemargl | 106 | treelist_node_add(tl, "node2.1", 1, 0, 1); |
6612 | siemargl | 107 | (*tl_cur_next)(tl); |
6615 | siemargl | 108 | |
6601 | siemargl | 109 | |
110 | (*tl_cur_next)(tl); |
||
6615 | siemargl | 111 | |
6601 | siemargl | 112 | |
6615 | siemargl | 113 | gui_add_treelist(main_window, tl); |
6601 | siemargl | 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 | (*tl_data_init)(tl2); |
||
6615 | siemargl | 118 | |
6612 | siemargl | 119 | |
120 | tl2->data_img = tl->data_img; |
||
121 | |||
122 | |||
123 | (*tl_cur_next)(tl2); |
||
6615 | siemargl | 124 | |
6612 | siemargl | 125 | |
126 | (*tl_cur_next)(tl2); |
||
6615 | siemargl | 127 | |
6612 | siemargl | 128 | |
129 | (*tl_cur_next)(tl2); |
||
6615 | siemargl | 130 | |
6612 | siemargl | 131 | |
6615 | siemargl | 132 | gui_add_treelist(main_window, tl2); |
6612 | siemargl | 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 | if (ed_lock == ed) |
6589 | siemargl | 151 | editor_key(ed, key); |
6612 | siemargl | 152 | else if(ed_lock == tl) |
153 | { |
||
154 | treelist_key(tl, key); |
||
155 | } |
||
156 | else if(ed_lock == tl2) |
||
157 | { |
||
158 | treelist_key(tl2, key); |
||
159 | } |
||
160 | else |
||
6589 | siemargl | 161 | kolibri_handle_event_key(main_window, key); |
6612 | siemargl | 162 | break; |
6589 | siemargl | 163 | case KOLIBRI_EVENT_BUTTON: |
164 | pressed_button = get_os_button(); |
||
165 | switch (pressed_button) |
||
166 | { |
||
167 | case BTN_QUIT: |
||
168 | if (box->retval == 3 || box->retval == 0) // not started or cancelled, analyze when redraw after closing msgbox |
||
169 | kolibri_start_msgbox(box, NULL); |
||
6601 | siemargl | 170 | break; |
6589 | siemargl | 171 | } |
172 | break; |
||
173 | case KOLIBRI_EVENT_MOUSE: |
||
174 | kolibri_handle_event_mouse(main_window); |
||
175 | break; |
||
176 | } |
||
177 | |||
178 | |||
179 | } while(1) ; /* End of main activity loop */ |
||
180 | |||
6601 | siemargl | 181 | |
182 | trap(0x55); // for stop in debug |
||
6615 | siemargl | 183 | //res = editor_savefile(ed, "/tmp0/1/editorlog.txt"); |
184 | pc = editor_get_text(ed); |
||
185 | debug_board_printf("saved text \"%s\"\n", pc); |
||
186 | free(pc); |
||
187 | |||
188 | |||
189 | |||
190 | |||
6601 | siemargl | 191 | treelist_data_clear(tl); |
192 | |||
6589 | siemargl | 193 | |
194 | } |
||
195 | |||
6601 | siemargl | 196 | |
197 | |||
198 | { |
||
199 | FILE *f = fopen(fname, "rb"); |
||
200 | if (!f) { |
||
201 | debug_board_printf("Can't open file: %s", fname); |
||
202 | exit(1); |
||
203 | } |
||
204 | if (fseek(f, 0, SEEK_END)) { |
||
205 | debug_board_printf("Can't SEEK_END file: %s", fname); |
||
206 | exit(1); |
||
207 | } |
||
208 | int filesize = ftell(f); |
||
209 | rewind(f); |
||
210 | char* fdata = malloc(filesize); |
||
211 | if(!fdata) { |
||
212 | debug_board_printf("No memory for file %s", fname); |
||
213 | exit(1); |
||
214 | } |
||
215 | *read_sz = fread(fdata, 1, filesize, f); |
||
216 | if (ferror(f)) { |
||
217 | debug_board_printf("Error reading file %s", fname); |
||
218 | exit(1); |
||
219 | } |
||
220 | fclose(f); |
||
221 | |||
222 | |||
223 | } |
||
224 | |||
225 | |||
226 | { |
||
227 | int32_t read_bytes = -1, w, h; |
||
228 | char *image_data = 0, *image_data_rgb = 0, *filedata = 0; |
||
229 | |||
230 | |||
231 | // определяем вид изображения и переводим его во временный буфер image_data |
||
232 | image_data = (*img_decode)(filedata, read_bytes, 0); |
||
233 | w = *(int*)(image_data +4); |
||
234 | h = *(int*)(image_data +8); |
||
235 | image_data_rgb = malloc(w * h * 3); |
||
236 | // преобразуем изображение к формату rgb |
||
237 | (*img_to_rgb2)(image_data, image_data_rgb); |
||
238 | // удаляем временный буфер image_data |
||
239 | (*img_destroy)(image_data); |
||
240 | free(filedata); |
||
241 | |||
242 | |||
243 | } |
||
244 |