Subversion Repositories Kolibri OS

Rev

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