22,9 → 22,11 |
#include "kolibri_libimg.h" |
#include "kolibri_msgbox.h" |
|
char temp_path[4096]; |
char run_path[4096]; |
char fname[4096]; |
|
char* load_file_inmem(char* fname, int32_t* read_sz); // see below |
char* load_image_file(char* fname); // see below |
|
int main(int argc, char **argv) |
{ |
34,7 → 36,7 |
elements can be used after a successful call to this function |
*/ |
kolibri_gui_init(); |
kolibri_proclib_init(); // opensave && color dialogs |
// kolibri_proclib_init(); // opensave && color dialogs |
kolibri_libimg_init(); // png handling |
|
int gui_event = KOLIBRI_EVENT_REDRAW; |
43,53 → 45,46 |
// pos_t mouse_pos; |
oskey_t keypress; |
|
// load image for buttons |
const int icon_rgb_size = 16*16*3; // every icons 16x16 24bpp |
char *image_data_rgb, |
*image_data, |
*filedata; |
// make full path + argv |
strcpy(temp_path, argv[0]); |
char *pc = strrchr(temp_path, '/'); // this fails if has params with '/' within. use argv[0] instead |
strcpy(run_path, argv[0]); |
char *pc = strrchr(run_path, '/'); // this fails if has params with '/' within. use argv[0] instead |
if (pc) pc[1] = 0; |
strcat(temp_path, "reload_16x16_8b.png"); |
// debug_board_write_str(temp_path); |
|
int32_t read_bytes; |
filedata = load_file_inmem(temp_path, &read_bytes); |
image_data_rgb = malloc(icon_rgb_size * 3); // we know size |
// îïðåäåëÿåì âèä èçîáðàæåíèÿ è ïåðåâîäèì åãî âî âðåìåííûé áóôåð image_data |
image_data = (*img_decode)(filedata, read_bytes, 0); |
// ïðåîáðàçóåì èçîáðàæåíèå ê ôîðìàòó rgb |
(*img_to_rgb2)(image_data, image_data_rgb); |
// óäàëÿåì âðåìåííûé áóôåð image_data |
(*img_destroy)(image_data); |
free(filedata); |
|
// creating GUI using library functions |
kolibri_window *main_window = kolibri_new_window(50, 40, 470, 500, "Editor, TreeView and MsgBox demo"); |
kolibri_window *main_window = kolibri_new_window(50, 40, 490, 500, "Editor, TreeView and MsgBox demo"); |
|
editor *ed; |
editor *ed_lock; |
|
gui_add_editor(main_window, ed = kolibri_new_editor(X_Y(10, 440), X_Y(20, 150), 0x1001, 2048, &ed_lock)); |
gui_add_editor(main_window, ed = kolibri_new_editor(X_Y(0, 440), X_Y(20, 150), 0x1001, 2048, &ed_lock)); |
ed_lock = ed; |
|
treelist *tl = kolibri_new_treelist(X_Y(0, 440), 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); |
treelist_data_init(tl); |
|
filedata = load_file_inmem("/rd/1/File managers/z_icons.png", &read_bytes); |
image_data_rgb = malloc(icon_rgb_size * 20); // we know size |
// îïðåäåëÿåì âèä èçîáðàæåíèÿ è ïåðåâîäèì åãî âî âðåìåííûé áóôåð image_data |
image_data = (*img_decode)(filedata, read_bytes, 0); |
// ïðåîáðàçóåì èçîáðàæåíèå ê ôîðìàòó rgb |
(*img_to_rgb2)(image_data, image_data_rgb); |
// óäàëÿåì âðåìåííûé áóôåð image_data |
(*img_destroy)(image_data); |
free(filedata); |
// ÷èòàåì ôàéë ñ êóðñîðàìè è ëèíèÿìè |
strcpy(fname, run_path); |
strcat(fname, "tl_sys_16.png"); |
tl->data_img_sys = load_image_file(fname); |
|
filedata = load_file_inmem("/rd/1/File managers/icons.ini", &read_bytes); |
// ÷èòàåì ôàéë ñ èêîíêàìè óçëîâ |
strcpy(fname, run_path); |
strcat(fname, "tl_nod_16.png"); |
tl->data_img = load_image_file(fname); |
|
treelist_node_add(tl, "node1", 1, 0, 0); // ãäå 1 íîìåð èêîíêè ñ êíèãîé |
treelist_cursor_next(tl); |
|
int extended_key = 0, act = 0; |
treelist_node_add(tl, "node2", 1, 0, 0); |
treelist_cursor_next(tl); |
|
treelist_node_add(tl, "node3", 1, 0, 0); |
treelist_cursor_next(tl); |
|
treelist_cursor_begin(tl); //;ñòàâèì êóðñîð íà íà÷àëî ñïèñêà |
gui_add_treelist(main_window, tl); |
|
msgbox* box = kolibri_new_msgbox("Exit", "Are\rYOU\rSure?", 3, "YES", "Absolute", "Not Yet", NULL); // default NOT |
|
do /* Start of main activity loop */ |
97,7 → 92,7 |
switch(gui_event) |
{ |
case KOLIBRI_EVENT_REDRAW: |
if (box->retval == 1 || box->retval == 2) return 0; // msgbox closes |
if (box->retval == 1 || box->retval == 2) goto clearing; // msgbox closes |
|
kolibri_handle_event_redraw(main_window); |
break; |
116,7 → 111,6 |
case BTN_QUIT: |
if (box->retval == 3 || box->retval == 0) // not started or cancelled, analyze when redraw after closing msgbox |
kolibri_start_msgbox(box, NULL); |
return 0; |
break; |
} |
break; |
128,5 → 122,59 |
gui_event = get_os_event(); |
} while(1) ; /* End of main activity loop */ |
|
clearing: |
editor_delete(ed); |
treelist_data_clear(tl); |
|
return 0; |
} |
|
|
char* load_file_inmem(char* fname, int32_t* read_sz) |
{ |
FILE *f = fopen(fname, "rb"); |
if (!f) { |
debug_board_printf("Can't open file: %s", fname); |
exit(1); |
} |
if (fseek(f, 0, SEEK_END)) { |
debug_board_printf("Can't SEEK_END file: %s", fname); |
exit(1); |
} |
int filesize = ftell(f); |
rewind(f); |
char* fdata = malloc(filesize); |
if(!fdata) { |
debug_board_printf("No memory for file %s", fname); |
exit(1); |
} |
*read_sz = fread(fdata, 1, filesize, f); |
if (ferror(f)) { |
debug_board_printf("Error reading file %s", fname); |
exit(1); |
} |
fclose(f); |
|
return fdata; |
} |
|
char* load_image_file(char* fname) |
{ |
int32_t read_bytes = -1, w, h; |
char *image_data = 0, *image_data_rgb = 0, *filedata = 0; |
|
filedata = load_file_inmem(fname, &read_bytes); |
// îïðåäåëÿåì âèä èçîáðàæåíèÿ è ïåðåâîäèì åãî âî âðåìåííûé áóôåð image_data |
image_data = (*img_decode)(filedata, read_bytes, 0); |
w = *(int*)(image_data +4); |
h = *(int*)(image_data +8); |
image_data_rgb = malloc(w * h * 3); |
// ïðåîáðàçóåì èçîáðàæåíèå ê ôîðìàòó rgb |
(*img_to_rgb2)(image_data, image_data_rgb); |
// óäàëÿåì âðåìåííûé áóôåð image_data |
(*img_destroy)(image_data); |
free(filedata); |
|
return image_data_rgb; |
} |
|