Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef KOLIBRI_GUI_H
  2. #define KOLIBRI_GUI_H
  3.  
  4. #include <stdlib.h> /* for malloc() */
  5. #include <kos32sys.h>
  6.  
  7. #include "kolibri_debug.h" /* work with debug board */
  8.  
  9. /* boxlib loader */
  10. #include "kolibri_boxlib.h"
  11.  
  12. /* All supported GUI elements included */
  13. #include "kolibri_gui_elements.h"
  14.  
  15. enum KOLIBRI_GUI_EVENTS {
  16.   KOLIBRI_EVENT_REDRAW = 1,   /* Window and window elements should be redrawn */
  17.   KOLIBRI_EVENT_KEY = 2,      /* A key on the keyboard was pressed */
  18.   KOLIBRI_EVENT_BUTTON = 3,   /* A button was clicked with the mouse */
  19.   KOLIBRI_EVENT_MOUSE = 6     /* Mouse activity (movement, button press) was detected */
  20. };
  21.  
  22. #define BUTTON_CLOSE 0x1
  23.  
  24. void kolibri_handle_event_redraw(kolibri_window* some_window)
  25. {
  26.   /*  Draw windows with system color table. */
  27.  
  28.   BeginDraw();
  29.  
  30.   DrawWindow(some_window->topleftx, some_window->toplefty,
  31.              some_window->sizex, some_window->sizey,
  32.              some_window->window_title,
  33.              kolibri_color_table.color_work_area, some_window->XY);
  34.  
  35.   /* Enumerate and draw all window elements here */
  36.   if(some_window->elements) /* Draw all elements added to window */
  37.     {
  38.       kolibri_window_element* current_element = some_window -> elements;
  39.  
  40.       do
  41.         {
  42.           /* The redraw_fn serves as draw_fn on initial draw */
  43.           if(kolibri_gui_op_table[current_element -> type].redraw_fn)
  44.             kolibri_gui_op_table[current_element -> type].redraw_fn(current_element -> element);
  45.  
  46. //sie after fixing calling conventions no more needed
  47. /*
  48.           switch(current_element -> type)
  49.             {
  50.             case KOLIBRI_EDIT_BOX:
  51.             case KOLIBRI_CHECK_BOX:
  52.               __asm__ volatile("push $0x13371337"::); / * Random value pushed to balance stack * /
  53.                                                       / * otherwise edit_box_draw leaves stack unbalanced * /
  54.                                                       / * and GCC jumps like a crazy motha' fucka' * /
  55.  
  56.               break;
  57.             }
  58. */
  59.           current_element = current_element -> next;
  60.  
  61.         } while(current_element != some_window->elements); /* Have we covered all elements? */
  62.     }
  63. }
  64.  
  65. void kolibri_handle_event_key(kolibri_window* some_window)
  66. {
  67.   /* Enumerate and trigger key handling functions of window elements here */
  68.   if(some_window->elements)
  69.     {
  70.       kolibri_window_element *current_element = some_window -> elements;
  71.  
  72.       do
  73.         {
  74.           /* Only execute if the function pointer isn't NULL */
  75.           if(kolibri_gui_op_table[current_element -> type].key_fn)
  76.             kolibri_gui_op_table[current_element -> type].key_fn(current_element -> element);
  77.  
  78.           current_element = current_element -> next;
  79.         } while(current_element != some_window->elements); /* Have we covered all elements? */
  80.     }
  81. }
  82.  
  83. void kolibri_handle_event_mouse(kolibri_window* some_window)
  84. {
  85.   /* Enumerate and trigger mouse handling functions of window elements here */
  86.   if(some_window->elements)
  87.     {
  88.       kolibri_window_element *current_element = some_window -> elements;
  89.  
  90.       do
  91.         {
  92.           if(kolibri_gui_op_table[current_element -> type].mouse_fn)
  93.             kolibri_gui_op_table[current_element -> type].mouse_fn(current_element -> element);
  94.  
  95.           current_element = current_element -> next;
  96.  
  97.         } while(current_element != some_window->elements); /* Have we covered all elements? */
  98.     }
  99. }
  100.  
  101. void kolibri_exit(void)
  102. {
  103.   __asm__ volatile ("int $0x40"::"a"(-1));
  104. }
  105.  
  106. int kolibri_gui_init(void)
  107. {
  108.   int boxlib_init_status = kolibri_boxlib_init();
  109.  
  110.   if(boxlib_init_status == 0)
  111.     debug_board_write_str("ashmew2 is happy: Kolibri GUI Successfully Initialized.\n");
  112.   else
  113.     {
  114.       debug_board_write_str("ashmew2 is sad: Kolibri GUI Failed to initialize.\n");
  115.       kolibri_exit();
  116.     }
  117.  
  118.   /* Initialize the global operation table which handles event functions of */
  119.   /* each individual element type */
  120.   kolibri_init_gui_op_table();
  121.  
  122.   /* Get the current color table for Kolibri and store in global table*/
  123.   kolibri_get_system_colors(&kolibri_color_table);
  124.  
  125.   /* Set up system events for buttons, mouse and keyboard and redraw */
  126.   /* Also set filters so that window receives mouse events only when active
  127.      and mouse inside window */
  128.   __asm__ volatile("int $0x40"::"a"(40), "b"(0xC0000027));
  129.  
  130.   return boxlib_init_status;
  131. }
  132.  
  133. /* Note: The current implementation tries to automatically colors
  134.    GUI elements with system theme */
  135.  
  136. #endif /* KOLIBRI_GUI_H */
  137.