Rev 6535 | Rev 6561 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6535 | Rev 6559 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | KolibriGUI demobox |
2 | KolibriGUI demobox |
3 | -Picture Button |
3 | -Picture Button |
4 | -StaticText |
4 | -StaticText |
5 | -File Open/Save Dialog |
5 | -File Open/Save Dialog |
6 | -Filebrowser (planned) |
6 | -Filebrowser |
- | 7 | -Controlling minimal window size |
|
Line 7... | Line 8... | ||
7 | 8 | ||
Line 8... | Line 9... | ||
8 | Free for all |
9 | Free for all |
Line 14... | Line 15... | ||
14 | */ |
15 | */ |
Line 15... | Line 16... | ||
15 | 16 | ||
16 | #include |
17 | #include |
17 | #include |
18 | #include |
- | 19 | #include |
|
18 | #include |
20 | #include |
19 | #include "kos32sys.h" |
21 | #include "kos32sys.h" |
20 | #include "kolibri_gui.h" |
22 | #include "kolibri_gui.h" |
21 | #include "kolibri_opendialog.h" |
23 | #include "kolibri_opendialog.h" |
Line 22... | Line 24... | ||
22 | #include "kolibri_libimg.h" |
24 | #include "kolibri_libimg.h" |
23 | 25 | ||
Line -... | Line 26... | ||
- | 26 | char temp_path[4096]; |
|
- | 27 | char** sys_path = (char**)0x20; // hack - get path from KOS header. analog argv[0] |
|
- | 28 | ||
- | 29 | char* load_file_inmem(char* fname, int32_t* read_sz); // see below |
|
24 | char temp_path[4096]; |
30 | void* read_folderdata(char* name); |
25 | char** sys_path = (char**)0x20; // hack - get path from KOS header. analog argv[0] |
31 | void control_minimal_window_size(int wmin, int hmin); |
26 | 32 | ||
27 | int main(int argc, char **argv) |
33 | int main(int argc, char **argv) |
28 | { |
34 | { |
Line 42... | Line 48... | ||
42 | // pos_t mouse_pos; |
48 | // pos_t mouse_pos; |
43 | oskey_t keypress; |
49 | oskey_t keypress; |
Line 44... | Line 50... | ||
44 | 50 | ||
45 | // load image for buttons |
51 | // load image for buttons |
46 | const int icon_rgb_size = 16*16*3; // every icons 16x16 24bpp |
52 | const int icon_rgb_size = 16*16*3; // every icons 16x16 24bpp |
47 | char *image_data_rgb = malloc(icon_rgb_size * 3), |
53 | char *image_data_rgb, |
- | 54 | *image_data, |
|
48 | *image_data, *pc; |
55 | *filedata; |
49 | // make full path + argv |
56 | // make full path + argv |
50 | strcpy(temp_path, *sys_path); |
57 | strcpy(temp_path, *sys_path); |
51 | pc = strrchr(temp_path, '/'); // this fails if has params with '/' within. use argv[0] instead |
58 | char *pc = strrchr(temp_path, '/'); // this fails if has params with '/' within. use argv[0] instead |
52 | if (pc) pc[1] = 0; |
59 | if (pc) pc[1] = 0; |
53 | strcat(temp_path, "reload_16x16_8b.png"); |
60 | strcat(temp_path, "reload_16x16_8b.png"); |
54 | debug_board_write_str(temp_path); |
- | |
55 | FILE *ficon = fopen(temp_path, "rb"); |
- | |
56 | if (!ficon) |
- | |
57 | { |
- | |
58 | debug_board_write_str("no icons file reload_16x16_8b.png "); |
- | |
59 | return 1; |
- | |
60 | } |
- | |
61 | int ficon_size = fread(image_data_rgb, 1, icon_rgb_size * 3, ficon); |
- | |
62 | if (ferror(ficon)) |
- | |
63 | { |
- | |
64 | debug_board_write_str("error reading file reload_16x16_8b.png "); |
- | |
65 | return 1; |
- | |
66 | } |
- | |
Line -... | Line 61... | ||
- | 61 | // debug_board_write_str(temp_path); |
|
- | 62 | ||
- | 63 | int32_t read_bytes; |
|
67 | fclose(ficon); |
64 | filedata = load_file_inmem(temp_path, &read_bytes); |
68 | 65 | image_data_rgb = malloc(icon_rgb_size * 3); // we know size |
|
69 | // îïðåäåëÿåì âèä èçîáðàæåíèÿ è ïåðåâîäèì åãî âî âðåìåííûé áóôåð image_data |
66 | // îïðåäåëÿåì âèä èçîáðàæåíèÿ è ïåðåâîäèì åãî âî âðåìåííûé áóôåð image_data |
70 | image_data = (*img_decode)(image_data_rgb, ficon_size, 0); |
67 | image_data = (*img_decode)(filedata, read_bytes, 0); |
71 | // ïðåîáðàçóåì èçîáðàæåíèå ê ôîðìàòó rgb |
68 | // ïðåîáðàçóåì èçîáðàæåíèå ê ôîðìàòó rgb |
72 | (*img_to_rgb2)(image_data, image_data_rgb); |
69 | (*img_to_rgb2)(image_data, image_data_rgb); |
- | 70 | // óäàëÿåì âðåìåííûé áóôåð image_data |
|
Line 73... | Line 71... | ||
73 | // óäàëÿåì âðåìåííûé áóôåð image_data |
71 | (*img_destroy)(image_data); |
74 | (*img_destroy)(image_data); |
72 | free(filedata); |
Line 75... | Line 73... | ||
75 | 73 | ||
76 | // creating GUI using library functions |
74 | // creating GUI using library functions |
77 | kolibri_window *main_window = kolibri_new_window(50, 40, 400, 160, "PictureButton and File dialog demo"); |
75 | kolibri_window *main_window = kolibri_new_window(50, 40, 430, 500, "PictureButton and File dialog demo"); |
78 | 76 | ||
Line 79... | Line 77... | ||
79 | pict_button tbar[3]; |
77 | pict_button tbar[3]; |
80 | gui_add_pict_button(main_window, kolibri_pict_button(&tbar[0], X_Y(10, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0)); |
78 | gui_add_pict_button(main_window, kolibri_pict_button(&tbar[0], X_Y(10, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0)); |
81 | gui_add_pict_button(main_window, kolibri_pict_button(&tbar[1], X_Y(35, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0)); |
79 | gui_add_pict_button(main_window, kolibri_pict_button(&tbar[1], X_Y(35, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0)); |
82 | gui_add_pict_button(main_window, kolibri_pict_button(&tbar[2], X_Y(60, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0)); |
80 | gui_add_pict_button(main_window, kolibri_pict_button(&tbar[2], X_Y(60, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0)); |
Line 83... | Line 81... | ||
83 | 81 | ||
84 | statictext labels[3]; // tips |
82 | statictext labels[3]; // tips |
Line 85... | Line 83... | ||
85 | gui_add_statictext(main_window, kolibri_statictext_def(&labels[0], X_Y(5, 28), "Open")); |
83 | gui_add_statictext(main_window, kolibri_statictext_def(&labels[0], X_Y(5, 28), "Open")); |
86 | gui_add_statictext(main_window, kolibri_statictext_def(&labels[1], X_Y(35, 28), "Save")); |
84 | gui_add_statictext(main_window, kolibri_statictext_def(&labels[1], X_Y(35, 28), "Save")); |
Line -... | Line 85... | ||
- | 85 | gui_add_statictext(main_window, kolibri_statictext_def(&labels[2], X_Y(65, 28), "Select Dir & browse")); |
|
- | 86 | ||
- | 87 | open_dialog *dlg_opensave = kolibri_new_open_dialog(OPEN, 10, 10, 420, 320); |
|
- | 88 | (*OpenDialog_init)(dlg_opensave); |
|
- | 89 | ||
- | 90 | pathview pview; |
|
- | 91 | gui_add_pathview(main_window, kolibri_pathview(&pview, X_Y(10, 50), 330, 1, 0, dlg_opensave->openfile_path, temp_path, 0, 0)); // black font, no background, font 1 |
|
- | 92 | ||
- | 93 | filebrowser brows; |
|
- | 94 | filedata = load_file_inmem("/rd/1/File managers/z_icons.png", &read_bytes); |
|
- | 95 | image_data_rgb = malloc(icon_rgb_size * 20); // we know size |
|
- | 96 | // îïðåäåëÿåì âèä èçîáðàæåíèÿ è ïåðåâîäèì åãî âî âðåìåííûé áóôåð image_data |
|
- | 97 | image_data = (*img_decode)(filedata, read_bytes, 0); |
|
- | 98 | // ïðåîáðàçóåì èçîáðàæåíèå ê ôîðìàòó rgb |
|
- | 99 | (*img_to_rgb2)(image_data, image_data_rgb); |
|
- | 100 | // óäàëÿåì âðåìåííûé áóôåð image_data |
|
- | 101 | (*img_destroy)(image_data); |
|
- | 102 | free(filedata); |
|
- | 103 | ||
- | 104 | filedata = load_file_inmem("/rd/1/File managers/icons.ini", &read_bytes); |
|
87 | gui_add_statictext(main_window, kolibri_statictext_def(&labels[2], X_Y(65, 28), "Select Dir")); |
105 | gui_add_filebrowser(main_window, kolibri_filebrowser(&brows, X_Y(10, 400), X_Y(80, 300), X_Y(6, 9), X_Y(16, 16), image_data_rgb, NULL, 24, |
88 | 106 | filedata, filedata + read_bytes, |
|
89 | open_dialog *dlg_opensave = kolibri_new_open_dialog(OPEN, 10, 10, 420, 320); |
107 | 0x00FF00, 0xbbddff, 0x000000, 0xFFFFFF, 0xFF0000)); |
90 | (*OpenDialog_init)(dlg_opensave); |
108 | |
91 | 109 | // try devices "/" - good |
|
- | 110 | brows.folder_data = read_folderdata("/rd/1"); |
|
- | 111 | brows.select_panel_counter = 1; |
|
- | 112 | ||
- | 113 | do /* Start of main activity loop */ |
|
92 | pathview pview; |
114 | { |
- | 115 | switch(gui_event) |
|
93 | gui_add_pathview(main_window, kolibri_pathview(&pview, X_Y(10, 50), 330, 1, 0, dlg_opensave->openfile_path, temp_path, 0, 0)); // black font, no background, font 1 |
116 | { |
94 | 117 | case KOLIBRI_EVENT_REDRAW: |
|
95 | do /* Start of main activity loop */ |
118 | //???? start red |
96 | { |
119 | //brows.marked_file = 1; |
97 | switch(gui_event) |
120 | control_minimal_window_size(430, 500); |
Line 115... | Line 138... | ||
115 | } |
138 | } |
116 | break; |
139 | break; |
117 | case KOLIBRI_EVENT_MOUSE: |
140 | case KOLIBRI_EVENT_MOUSE: |
118 | // mouse_pos = get_mouse_pos(POS_WINDOW); // window relative |
141 | // mouse_pos = get_mouse_pos(POS_WINDOW); // window relative |
119 | // mouse_button = get_mouse_eventstate(); |
142 | // mouse_button = get_mouse_eventstate(); |
- | 143 | //brows.all_redraw = 1; |
|
120 | kolibri_handle_event_mouse(main_window); |
144 | kolibri_handle_event_mouse(main_window); |
Line -... | Line 145... | ||
- | 145 | ||
- | 146 | ||
- | 147 | if (brows.mouse_keys_delta == 3) // double clicked in browser |
|
- | 148 | { |
|
- | 149 | debug_board_printf("mouse_keys_delta == 3, name %s\n", brows.selected_BDVK_adress->fname); |
|
- | 150 | brows.mouse_keys_delta = 0; |
|
- | 151 | } |
|
121 | 152 | ||
122 | if(tbar[0].click) // open |
153 | if(tbar[0].click) // open |
123 | { |
154 | { |
124 | tbar[0].click = 0; |
155 | tbar[0].click = 0; |
125 | dlg_opensave->mode = OPEN; |
156 | dlg_opensave->mode = OPEN; |
Line 136... | Line 167... | ||
136 | tbar[1].click = 0; |
167 | tbar[1].click = 0; |
137 | dlg_opensave->mode = SAVE; |
168 | dlg_opensave->mode = SAVE; |
138 | (*OpenDialog_start)(dlg_opensave); |
169 | (*OpenDialog_start)(dlg_opensave); |
139 | if (dlg_opensave->status != 2 && dlg_opensave->status != 0) // fail or cancel |
170 | if (dlg_opensave->status != 2 && dlg_opensave->status != 0) // fail or cancel |
140 | (*path_show_prepare)(&pview); |
171 | (*path_show_prepare)(&pview); |
- | 172 | ||
- | 173 | // just calling line below draws incomplete |
|
141 | kolibri_handle_event_redraw(main_window); |
174 | // kolibri_handle_event_redraw(main_window); |
142 | } |
175 | } |
143 | if(tbar[2].click) // select |
176 | if(tbar[2].click) // select |
144 | { |
177 | { |
145 | tbar[2].click = 0; |
178 | tbar[2].click = 0; |
146 | dlg_opensave->mode = SELECT; |
179 | dlg_opensave->mode = SELECT; |
147 | (*OpenDialog_start)(dlg_opensave); |
180 | (*OpenDialog_start)(dlg_opensave); |
148 | if (dlg_opensave->status != 2 && dlg_opensave->status != 0) // fail or cancel |
181 | if (dlg_opensave->status != 2 && dlg_opensave->status != 0) // fail or cancel |
- | 182 | { |
|
149 | (*path_show_prepare)(&pview); |
183 | (*path_show_prepare)(&pview); |
- | 184 | free(brows.folder_data); |
|
- | 185 | brows.folder_data = read_folderdata(dlg_opensave->openfile_path); |
|
- | 186 | } |
|
- | 187 | // we may redraw here, or just wait next redraw event |
|
- | 188 | brows.all_redraw = 1; |
|
150 | kolibri_handle_event_redraw(main_window); |
189 | kolibri_handle_event_redraw(main_window); |
- | 190 | brows.all_redraw = 0; |
|
151 | } |
191 | } |
Line 152... | Line 192... | ||
152 | 192 | ||
153 | break; |
193 | break; |
Line 157... | Line 197... | ||
157 | } while(1) ; /* End of main activity loop */ |
197 | } while(1) ; /* End of main activity loop */ |
Line 158... | Line 198... | ||
158 | 198 | ||
159 | return 0; |
199 | return 0; |
Line -... | Line 200... | ||
- | 200 | } |
|
- | 201 | ||
- | 202 | ||
- | 203 | char* load_file_inmem(char* fname, int32_t* read_sz) |
|
- | 204 | { |
|
- | 205 | FILE *f = fopen(fname, "rb"); |
|
- | 206 | if (!f) { |
|
- | 207 | debug_board_printf("Can't open file: %s", fname); |
|
- | 208 | exit(1); |
|
- | 209 | } |
|
- | 210 | if (fseek(f, 0, SEEK_END)) { |
|
- | 211 | debug_board_printf("Can't SEEK_END file: %s", fname); |
|
- | 212 | exit(1); |
|
- | 213 | } |
|
- | 214 | int filesize = ftell(f); |
|
- | 215 | rewind(f); |
|
- | 216 | char* fdata = malloc(filesize); |
|
- | 217 | if(!fdata) { |
|
- | 218 | debug_board_printf("No memory for file %s", fname); |
|
- | 219 | exit(1); |
|
- | 220 | } |
|
- | 221 | *read_sz = fread(fdata, 1, filesize, f); |
|
- | 222 | if (ferror(f)) { |
|
- | 223 | debug_board_printf("Error reading file %s", fname); |
|
- | 224 | exit(1); |
|
- | 225 | } |
|
- | 226 | fclose(f); |
|
- | 227 | ||
- | 228 | return fdata; |
|
- | 229 | } |
|
- | 230 | ||
- | 231 | void* read_folderdata(char* name) |
|
- | 232 | { |
|
- | 233 | struct fs_dirinfo di; |
|
- | 234 | struct fs_dirheader dhead; |
|
- | 235 | assert(sizeof di == 25); |
|
- | 236 | memset(&di, 0, sizeof di); |
|
- | 237 | di.ppath = name; |
|
- | 238 | di.retval = (uint32_t)&dhead; |
|
- | 239 | int rc = sf_file(1, &di); // read dir size |
|
- | 240 | if(rc) { |
|
- | 241 | debug_board_printf("Error reading dir size %s", name); |
|
- | 242 | exit(1); |
|
- | 243 | } |
|
- | 244 | di.size = dhead.totl_blocks; |
|
- | 245 | ||
- | 246 | char *retdir = malloc(sizeof dhead + dhead.totl_blocks * sizeof(struct fsBDFE)); |
|
- | 247 | if(!retdir) { |
|
- | 248 | debug_board_printf("No memory for dir %s", name); |
|
- | 249 | exit(1); |
|
- | 250 | } |
|
- | 251 | di.retval = (uint32_t)retdir; |
|
- | 252 | rc = sf_file(1, &di); // read dir size |
|
- | 253 | if(rc) { |
|
- | 254 | debug_board_printf("Error 2 reading dir size %s", name); |
|
- | 255 | exit(1); |
|
- | 256 | } |
|
- | 257 | ||
- | 258 | debug_board_printf("Loaded dir [%s] etnries %d,\n first file [%s]\n", name, ((struct fs_dirheader*)(retdir))->curn_blocks, ((struct fsBDFE*)(retdir+32))->fname); |
|
- | 259 | ||
- | 260 | return retdir; |
|
- | 261 | } |
|
- | 262 | ||
- | 263 | ||
- | 264 | ||
- | 265 | void control_minimal_window_size(int wmin, int hmin) |
|
- | 266 | { |
|
- | 267 | char pinfo[1024]; |
|
- | 268 | get_proc_info(pinfo); |
|
- | 269 | ||
- | 270 | int win_hight = *(int*)(pinfo + 46), |
|
- | 271 | win_width = *(int*)(pinfo + 42); |
|
- | 272 | char win_status = pinfo[70]; |
|
- | 273 | ||
- | 274 | if (win_status & 7) return; // maximized, minimized or titlebar mode |
|
- | 275 | ||
- | 276 | if (win_width < wmin) |
|
- | 277 | __asm__ __volatile__("int $0x40" ::"a"(67), "b"(-1), "c"(-1), "d"(wmin), "S"(-1)); // SF_CHANGE_WINDOW x,y,w,h |
|
- | 278 | if (win_hight < hmin) |
|
- | 279 | __asm__ __volatile__("int $0x40" ::"a"(67), "b"(-1), "c"(-1), "d"(-1), "S"(hmin)); // x,y,w,h |
|
- | 280 | ||
- | 281 | }>> |