Subversion Repositories Kolibri OS

Rev

Rev 6601 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1.  
  2. /*
  3.     KolibriGUI demobox
  4.     -Editor (multiline edit)
  5.     -TreeView
  6.     -MsgBox Dialog
  7.  
  8.     Free for all
  9.  
  10.     Initially written by Siemargl, 2016
  11.  
  12.  
  13.     ToDo
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <assert.h>
  20. #include "kos32sys.h"
  21. #include "kolibri_gui.h"
  22. #include "kolibri_libimg.h"
  23. #include "kolibri_msgbox.h"
  24.  
  25. char temp_path[4096];
  26.  
  27. char*   load_file_inmem(char* fname, int32_t* read_sz); // see below
  28.  
  29. int main(int argc, char **argv)
  30. {
  31.     /* Load all libraries, initialize global tables like system color table and
  32.     operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
  33.     to do it's job. This is all you need to call and all libraries and GUI
  34.     elements can be used after a successful call to this function
  35.     */
  36.     kolibri_gui_init();
  37.     kolibri_proclib_init();  // opensave && color dialogs
  38.     kolibri_libimg_init();  // png handling
  39.  
  40.     int gui_event = KOLIBRI_EVENT_REDRAW;
  41.     uint32_t pressed_button = 0;
  42. //    uint32_t mouse_button;
  43. //    pos_t   mouse_pos;
  44.     oskey_t keypress;
  45.  
  46.     // load image for buttons
  47.     const int icon_rgb_size = 16*16*3; // every icons 16x16 24bpp
  48.     char *image_data_rgb,
  49.          *image_data,
  50.          *filedata;
  51.     // make full path + argv
  52.     strcpy(temp_path, argv[0]);
  53.     char *pc = strrchr(temp_path, '/');  // this fails if has params with '/' within. use argv[0] instead
  54.     if (pc) pc[1] = 0;
  55.     strcat(temp_path, "reload_16x16_8b.png");
  56. //    debug_board_write_str(temp_path);
  57.  
  58.     int32_t read_bytes;
  59.     filedata = load_file_inmem(temp_path, &read_bytes);
  60.     image_data_rgb = malloc(icon_rgb_size * 3);  // we know size
  61.     // îïðåäåëÿåì âèä èçîáðàæåíèÿ è ïåðåâîäèì åãî âî âðåìåííûé áóôåð image_data
  62.     image_data = (*img_decode)(filedata, read_bytes, 0);
  63.     // ïðåîáðàçóåì èçîáðàæåíèå ê ôîðìàòó rgb
  64.     (*img_to_rgb2)(image_data, image_data_rgb);
  65.     // óäàëÿåì âðåìåííûé áóôåð image_data
  66.     (*img_destroy)(image_data);
  67.     free(filedata);
  68.  
  69.     // creating GUI using library functions
  70.     kolibri_window *main_window = kolibri_new_window(50, 40, 470, 500, "Editor, TreeView and MsgBox demo");
  71.  
  72.     editor *ed;
  73.     editor *ed_lock;
  74.  
  75.     gui_add_editor(main_window, ed = kolibri_new_editor(X_Y(10, 440), X_Y(20, 150), 0x1001, 2048, &ed_lock));
  76.     ed_lock = ed;
  77.  
  78.  
  79.     filedata = load_file_inmem("/rd/1/File managers/z_icons.png", &read_bytes);
  80.     image_data_rgb = malloc(icon_rgb_size * 20);  // we know size
  81.     // îïðåäåëÿåì âèä èçîáðàæåíèÿ è ïåðåâîäèì åãî âî âðåìåííûé áóôåð image_data
  82.     image_data = (*img_decode)(filedata, read_bytes, 0);
  83.     // ïðåîáðàçóåì èçîáðàæåíèå ê ôîðìàòó rgb
  84.     (*img_to_rgb2)(image_data, image_data_rgb);
  85.     // óäàëÿåì âðåìåííûé áóôåð image_data
  86.     (*img_destroy)(image_data);
  87.     free(filedata);
  88.  
  89.     filedata = load_file_inmem("/rd/1/File managers/icons.ini", &read_bytes);
  90.  
  91.  
  92.     int extended_key = 0, act = 0;
  93.     msgbox* box = kolibri_new_msgbox("Exit", "Are\rYOU\rSure?", 3, "YES", "Absolute", "Not Yet", NULL);  // default NOT
  94.  
  95.     do  /* Start of main activity loop */
  96.     {
  97.         switch(gui_event)
  98.         {
  99.         case KOLIBRI_EVENT_REDRAW:
  100.             if (box->retval == 1 || box->retval == 2) return 0;  // msgbox closes
  101.  
  102.             kolibri_handle_event_redraw(main_window);
  103.             break;
  104.         case KOLIBRI_EVENT_NONE:
  105.                         break;
  106.         case KOLIBRI_EVENT_KEY:
  107.             if (ed_lock == ed)
  108.                 editor_key(ed);
  109.             else
  110.                 kolibri_handle_event_key(main_window);
  111.                         break;
  112.         case KOLIBRI_EVENT_BUTTON:
  113.             pressed_button = get_os_button();
  114.             switch (pressed_button)
  115.             {
  116.               case BTN_QUIT:
  117.                   if (box->retval == 3 || box->retval == 0) // not started or cancelled, analyze when redraw after closing msgbox
  118.                     kolibri_start_msgbox(box, NULL);
  119.                 return 0;
  120.                 break;
  121.             }
  122.             break;
  123.         case KOLIBRI_EVENT_MOUSE:
  124.             kolibri_handle_event_mouse(main_window);
  125.             break;
  126.         }
  127.  
  128.         gui_event = get_os_event();
  129.     } while(1) ; /* End of main activity loop */
  130.  
  131.   return 0;
  132. }
  133.