Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.     KolibriGUI demobox
  3.     -Button
  4.     -CheckBox
  5.     -EditBox
  6.     -Frame
  7.  
  8.     Free for all
  9.  
  10.     Initially written by ashmew2, 2015
  11.  
  12.     Updated by Siemargl, 2016
  13.  
  14.     ToDo
  15. */
  16.  
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <kos32sys.h>
  20. #include <kolibri_gui.h>
  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.   /* Set gui_event to REDRAW so that window is drawn in first iteration  */
  31.   unsigned int gui_event = KOLIBRI_EVENT_REDRAW;
  32.   oskey_t key;
  33.  
  34.   kolibri_window *main_window = kolibri_new_window(50, 50, 400, 120, "BoardMsg: OpenDialog 0.12");
  35.   check_box *checkbox = kolibri_new_check_box(20, 45, 12, 12, "Append BOARDMSG to entered message.");
  36.  
  37.   edit_box *editbox_interlock = NULL;
  38.   edit_box *textbox = kolibri_new_edit_box(20, 60, 40, &editbox_interlock);
  39.   edit_box *textbox2 = kolibri_new_edit_box(20, 80, 40, &editbox_interlock);
  40.   kolibri_button *button = kolibri_new_button(310, 60, 24, 14, 0x21, kolibri_color_table.color_work_button);
  41.   frame *fr = kolibri_new_frame(X_Y(12, 350), X_Y(35, 70), 0x00FCFCFC, 0x00DCDCDC, "Frame Title", 0, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area);
  42.  
  43.   kolibri_window_add_element(main_window, KOLIBRI_EDIT_BOX, textbox);
  44.   kolibri_window_add_element(main_window, KOLIBRI_EDIT_BOX, textbox2);
  45.   kolibri_window_add_element(main_window, KOLIBRI_CHECK_BOX, checkbox);
  46.   kolibri_window_add_element(main_window, KOLIBRI_BUTTON, button);
  47.   kolibri_window_add_element(main_window, KOLIBRI_FRAME, fr);
  48.  
  49.   extern volatile unsigned press_key;
  50.  
  51.   do  /* Start of main activity loop */
  52.     {
  53.       if(gui_event == KOLIBRI_EVENT_REDRAW)
  54.         {
  55.           kolibri_handle_event_redraw(main_window);
  56.         }
  57.       else if(gui_event == KOLIBRI_EVENT_KEY)
  58.         {
  59.           key = get_key();
  60.           switch (key.code)
  61.           {
  62.                   case 13:
  63.                         if(checkbox -> flags & CHECKBOX_IS_SET) /* Append BoardMsg checkbox is set */
  64.                                 debug_board_write_str("BOARDMSG: ");
  65.  
  66.                         debug_board_write_str(textbox->text);
  67.                         debug_board_write_str("\n");
  68.                         break;
  69.           }
  70.           press_key = key.val;
  71.  
  72.           kolibri_handle_event_key(main_window);
  73.         }
  74.       else if(gui_event == KOLIBRI_EVENT_BUTTON)
  75.         {
  76.           unsigned int pressed_button = kolibri_button_get_identifier();
  77.           switch (pressed_button)
  78.           {
  79.                   case 0x21:
  80.                         if(checkbox -> flags & CHECKBOX_IS_SET) /* Append BoardMsg checkbox is set */
  81.                         debug_board_write_str("BOARDMSG: ");
  82.                         debug_board_write_str(textbox->text);
  83.                         debug_board_write_str("\n");
  84.                         break;
  85.               case BUTTON_CLOSE:
  86.                         kolibri_exit();
  87.           }
  88.          }
  89.       else if(gui_event == KOLIBRI_EVENT_MOUSE)
  90.         {
  91.           kolibri_handle_event_mouse(main_window);
  92.         }
  93.  
  94.     } while((gui_event = get_os_event())); /* End of main activity loop */
  95.  
  96.   /* kolibri_quit(); */
  97.  
  98.   return 0;
  99. }
  100.