Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #include "kolibri_gui.h"
  2. #include "kolibri_kmenu.h"
  3. #include "kolibri_libimg.h"
  4.  
  5. int main()
  6. {
  7.   /* Load all libraries, initialize global tables like system color table and
  8.      operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
  9.      to do it's job. This is all you need to call and all libraries and GUI
  10.      elements can be used after a successful call to this function
  11.   */
  12.   kolibri_gui_init();
  13.   kolibri_kmenu_init();
  14.   kolibri_libimg_init();
  15.   /* Set gui_event to REDRAW so that window is drawn in first iteration  */
  16.   unsigned int gui_event = KOLIBRI_EVENT_REDRAW;
  17.   oskey_t key;
  18.  
  19.   struct kolibri_window *main_window = kolibri_new_window(50, 50, 420, 350, "Example 2");
  20.   struct check_box *checkbox = kolibri_new_check_box(20, 30, 12, 12, "Print to BOARD selected menu item.");
  21.  
  22.   kolibri_window_add_element(main_window, KOLIBRI_CHECK_BOX, checkbox);
  23.    
  24.   extern volatile unsigned press_key;
  25.  
  26.   ufile_t load_f;
  27.   load_f = load_file("/kolibrios/111.png");
  28.   void* image_data_rgb = (void*)malloc(load_f.size);
  29.   void* image_data = img_decode(load_f.data, load_f.size, 0);
  30.   img_to_rgb2(image_data, image_data_rgb);
  31.   //img_destroy(image_data);   
  32.  
  33.   void* main_menu;
  34.   void* main_menu_file;
  35.   void* main_menu_edit;
  36.   kmenu_init(NULL);
  37.   main_menu = ksubmenu_new();
  38.   main_menu_file = ksubmenu_new();
  39.   main_menu_edit = ksubmenu_new();
  40.   ksubmenu_add(main_menu_file, kmenuitem_new(0, "Open", 110));
  41.   ksubmenu_add(main_menu_file, kmenuitem_new(0, "Save", 111));
  42.   ksubmenu_add(main_menu_file, kmenuitem_new(2, NULL, 112));
  43.   ksubmenu_add(main_menu_file, kmenuitem_new(0, "Exit", 113));
  44.   ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "File", main_menu_file));
  45.   ksubmenu_add(main_menu_edit, kmenuitem_new(0, "Vertical flip", 120));
  46.   ksubmenu_add(main_menu_edit, kmenuitem_new(0, "Horizontal flip", 121));
  47.   ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "Edit", main_menu_edit));
  48.  
  49.   do  /* Start of main activity loop */
  50.     {
  51.       if(gui_event == KOLIBRI_EVENT_REDRAW)
  52.         {
  53.           kolibri_handle_event_redraw(main_window);
  54.           kmainmenu_draw(main_menu);
  55.           draw_bitmap(image_data_rgb, 5, 60, 400, 250);
  56.         }
  57.       else if(gui_event == KOLIBRI_EVENT_KEY)
  58.         {
  59.           key = get_key();
  60.           kolibri_handle_event_key(main_window);
  61.         }
  62.       else if(gui_event == KOLIBRI_EVENT_BUTTON)
  63.         {
  64.           unsigned int pressed_button = kolibri_button_get_identifier();
  65.           switch (pressed_button)
  66.           {
  67.               case 0x00000001:
  68.                         kolibri_exit();
  69.                         break;
  70.                   case 110:
  71.                     if(checkbox -> flags & CHECKBOX_IS_SET) debug_board_write_str("Open\n");
  72.                     break;
  73.                   case 111:
  74.                     if(checkbox -> flags & CHECKBOX_IS_SET) debug_board_write_str("Save\n");
  75.                     break;
  76.                   case 113:
  77.                     if(checkbox -> flags & CHECKBOX_IS_SET) debug_board_write_str("Exit\n");
  78.                     kolibri_exit();
  79.                     break;
  80.                   case 120:
  81.                     if(checkbox -> flags & CHECKBOX_IS_SET) debug_board_write_str("Vertical flip\n");
  82.                     img_flip(image_data, 0x01);
  83.                     img_to_rgb2(image_data, image_data_rgb);
  84.                     draw_bitmap(image_data_rgb, 5, 30, 400, 250);
  85.                     break;
  86.                   case 121:
  87.                     if(checkbox -> flags & CHECKBOX_IS_SET) debug_board_write_str("Horizontal flip\n");
  88.                     img_flip(image_data, 0x02);
  89.                     img_to_rgb2(image_data, image_data_rgb);
  90.                     draw_bitmap(image_data_rgb, 5, 30, 400, 250);
  91.                     break;
  92.           }
  93.          }
  94.       else if(gui_event == KOLIBRI_EVENT_MOUSE)
  95.         {
  96.           kolibri_handle_event_mouse(main_window);
  97.           kmainmenu_dispatch_cursorevent(main_menu);
  98.         }
  99.  
  100.     } while(gui_event = get_os_event()); /* End of main activity loop */
  101.  
  102.   /* kolibri_quit(); */
  103.  
  104.   return 0;
  105. }
  106.