Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.     KolibriGUI demobox
  3.     -OptionBox
  4.     -MenuBar
  5.     -Frame
  6.  
  7.     Free for all
  8.  
  9.     Initially written by Siemargl, 2016
  10.  
  11.  
  12.     ToDo
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "kos32sys.h"
  19. #include "kolibri_gui.h"
  20.  
  21.  
  22. int main()
  23. {
  24.     /* Load all libraries, initialize global tables like system color table and
  25.     operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
  26.     to do it's job. This is all you need to call and all libraries and GUI
  27.     elements can be used after a successful call to this function
  28.     */
  29.     kolibri_gui_init();
  30.     int gui_event = KOLIBRI_EVENT_REDRAW;
  31.     uint32_t pressed_button = 0;
  32. //    uint32_t mouse_button;
  33. //    pos_t   mouse_pos;
  34.     oskey_t keypress;
  35.  
  36.  
  37.     // creating GUI using library functions
  38.     kolibri_window *main_window = kolibri_new_window(50, 50, 400, 160, "OptionBox and Menu demo");
  39.     //check_box *checkbox = kolibri_new_check_box(20, 45, 12, 12, "Append BOARDMSG to entered message.");
  40.  
  41.     option_box opts1[3];
  42.     option_box *option1sel = opts1; // intially selected RED
  43.  
  44.     option_box *op1_1 = gui_optionbox(opts1, X_Y(20, 60), "G1 Item RED", &option1sel);
  45.     option_box *op1_2 = gui_optionbox(opts1+1, X_Y(20, 80), "G1 Item GREEN", &option1sel);
  46.     option_box *op1_3 = gui_optionbox(opts1+2, X_Y(20, 100), "G1 Item BLUE", &option1sel);
  47.     option_box* option_group1[] = {op1_1, op1_2, op1_3, NULL};
  48.  
  49.     option_box opts2[3];
  50.     option_box *option2sel = opts2 + 1; // intially selected #2
  51.     option_box *op2_1 = gui_optionbox(&opts2[0], X_Y(140, 60), "G2 Item 1st", &option2sel);
  52.     option_box *op2_2 = gui_optionbox(&opts2[1], X_Y(140, 80), "G2 Item 2nd", &option2sel);
  53.     option_box *op2_3 = gui_optionbox(&opts2[2], X_Y(140, 100), "G2 Item 3rd", &option2sel);
  54.     option_box* option_group2[] = {op2_1, op2_2, op2_3, NULL};
  55.  
  56.     frame *fr1 = kolibri_new_frame_def(X_Y(12, 110), X_Y(50, 70), "Option 1");
  57.     frame *fr2 = kolibri_new_frame_def(X_Y(132, 100), X_Y(50, 70), "Option 2");
  58.  
  59.     gui_add_optiongroup(main_window, option_group1);  // new syntax
  60.     gui_add_optiongroup(main_window, option_group2);
  61.     gui_add_frame(main_window, fr1);
  62.     gui_add_frame(main_window, fr2);
  63.  
  64.     int option_index1 = 0;  // index of selected option
  65.     int option_index2 = 0;
  66.  
  67.     static char *menu1t = "Menu1";
  68.     static char *menu11t = "Set RED";
  69.     static char *menu12t = "Set GREEN";
  70.     static char *menu13t = "Set BLUE";
  71.     static char *menu14t = "";
  72.     menubar* menu1 = kolibri_new_menubar_def(X_Y(20, 40), X_Y(25, 15), 80, 100, menu1t, menu11t);
  73.     gui_add_menubar(main_window, menu1);
  74.  
  75.     static char *menu2t = "Menu2";
  76.     static char *menu21t = "Set Option 1";
  77.     static char *menu22t = "Set Option 2";
  78.     static char *menu23t = "Set Option 3";
  79.     static char *menu24t = "";
  80.     menubar* menu2 = kolibri_new_menubar_def(X_Y(60, 40), X_Y(25, 15), 80, 100, menu2t, menu21t);
  81.     gui_add_menubar(main_window, menu2);
  82.  
  83.  
  84.  
  85.  
  86.     do  /* Start of main activity loop */
  87.     {
  88.         if(option_index1 != option1sel - opts1)
  89.             debug_board_printf("Option1 change to %d\n", option1sel - opts1);
  90.         if(option_index2 != option2sel - opts2)
  91.             debug_board_printf("Option2 change to %d\n", option2sel - opts2);
  92.         option_index1 = option1sel - opts1;
  93.         option_index2 = option2sel - opts2;
  94.  
  95.         switch(gui_event)
  96.         {
  97.         case KOLIBRI_EVENT_REDRAW:
  98.             kolibri_handle_event_redraw(main_window);
  99.             break;
  100.         case KOLIBRI_EVENT_NONE:
  101.                         break;
  102.         case KOLIBRI_EVENT_KEY:
  103.             kolibri_handle_event_key(main_window); // ???????
  104.                         break;
  105.         case KOLIBRI_EVENT_BUTTON:
  106.             pressed_button = get_os_button();
  107.             switch (pressed_button)
  108.             {
  109.               case BTN_QUIT:
  110.                 return 0;
  111.                 break;
  112.             }
  113.             break;
  114.         case KOLIBRI_EVENT_MOUSE:
  115. //            mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
  116. //            mouse_button = get_mouse_eventstate();
  117.             kolibri_handle_event_mouse(main_window);
  118.             break;
  119.         }
  120.  
  121.         gui_event = get_os_event();
  122.     } while(1) ; /* End of main activity loop */
  123.  
  124.   return 0;
  125. }
  126.  
  127.