2016-04-11 15:38:48 +02:00
|
|
|
#ifndef KOLIBRI_GUI_H
|
|
|
|
#define KOLIBRI_GUI_H
|
|
|
|
|
2016-04-12 20:50:48 +02:00
|
|
|
#include <stdlib.h> /* for malloc() */
|
2016-04-11 15:38:48 +02:00
|
|
|
#include <kos32sys.h>
|
|
|
|
|
|
|
|
#include "kolibri_debug.h" /* work with debug board */
|
|
|
|
|
|
|
|
/* boxlib loader */
|
|
|
|
#include "kolibri_boxlib.h"
|
|
|
|
|
|
|
|
/* All supported GUI elements included */
|
|
|
|
#include "kolibri_gui_elements.h"
|
|
|
|
|
|
|
|
enum KOLIBRI_GUI_EVENTS {
|
|
|
|
KOLIBRI_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */
|
|
|
|
KOLIBRI_EVENT_KEY = 2, /* A key on the keyboard was pressed */
|
|
|
|
KOLIBRI_EVENT_BUTTON = 3, /* A button was clicked with the mouse */
|
|
|
|
KOLIBRI_EVENT_MOUSE = 6 /* Mouse activity (movement, button press) was detected */
|
|
|
|
};
|
|
|
|
|
2016-06-30 18:10:04 +02:00
|
|
|
#define BUTTON_CLOSE 0x1
|
|
|
|
|
|
|
|
void kolibri_handle_event_redraw(kolibri_window* some_window)
|
2016-04-11 15:38:48 +02:00
|
|
|
{
|
|
|
|
/* Draw windows with system color table. */
|
|
|
|
|
|
|
|
BeginDraw();
|
|
|
|
|
2016-04-12 20:50:48 +02:00
|
|
|
DrawWindow(some_window->topleftx, some_window->toplefty,
|
2016-04-11 15:38:48 +02:00
|
|
|
some_window->sizex, some_window->sizey,
|
|
|
|
some_window->window_title,
|
|
|
|
kolibri_color_table.color_work_area, some_window->XY);
|
2016-04-12 20:50:48 +02:00
|
|
|
|
2016-04-11 15:38:48 +02:00
|
|
|
/* Enumerate and draw all window elements here */
|
|
|
|
if(some_window->elements) /* Draw all elements added to window */
|
|
|
|
{
|
2016-06-30 18:10:04 +02:00
|
|
|
kolibri_window_element* current_element = some_window -> elements;
|
2016-04-12 20:50:48 +02:00
|
|
|
|
2016-04-11 15:38:48 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
/* The redraw_fn serves as draw_fn on initial draw */
|
|
|
|
if(kolibri_gui_op_table[current_element -> type].redraw_fn)
|
|
|
|
kolibri_gui_op_table[current_element -> type].redraw_fn(current_element -> element);
|
2016-04-12 20:50:48 +02:00
|
|
|
|
|
|
|
//sie after fixing calling conventions no more needed
|
|
|
|
/*
|
2016-04-11 15:38:48 +02:00
|
|
|
switch(current_element -> type)
|
|
|
|
{
|
|
|
|
case KOLIBRI_EDIT_BOX:
|
|
|
|
case KOLIBRI_CHECK_BOX:
|
2016-04-12 20:50:48 +02:00
|
|
|
__asm__ volatile("push $0x13371337"::); / * Random value pushed to balance stack * /
|
|
|
|
/ * otherwise edit_box_draw leaves stack unbalanced * /
|
|
|
|
/ * and GCC jumps like a crazy motha' fucka' * /
|
|
|
|
|
2016-04-11 15:38:48 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-04-12 20:50:48 +02:00
|
|
|
*/
|
2016-04-11 15:38:48 +02:00
|
|
|
current_element = current_element -> next;
|
2016-04-12 20:50:48 +02:00
|
|
|
|
2016-04-11 15:38:48 +02:00
|
|
|
} while(current_element != some_window->elements); /* Have we covered all elements? */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 18:10:04 +02:00
|
|
|
void kolibri_handle_event_key(kolibri_window* some_window)
|
2016-04-11 15:38:48 +02:00
|
|
|
{
|
|
|
|
/* Enumerate and trigger key handling functions of window elements here */
|
2016-04-12 20:50:48 +02:00
|
|
|
if(some_window->elements)
|
2016-04-11 15:38:48 +02:00
|
|
|
{
|
2016-06-30 18:10:04 +02:00
|
|
|
kolibri_window_element *current_element = some_window -> elements;
|
2016-04-11 15:38:48 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Only execute if the function pointer isn't NULL */
|
|
|
|
if(kolibri_gui_op_table[current_element -> type].key_fn)
|
|
|
|
kolibri_gui_op_table[current_element -> type].key_fn(current_element -> element);
|
2016-04-12 20:50:48 +02:00
|
|
|
|
2016-04-11 15:38:48 +02:00
|
|
|
current_element = current_element -> next;
|
|
|
|
} while(current_element != some_window->elements); /* Have we covered all elements? */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 18:10:04 +02:00
|
|
|
void kolibri_handle_event_mouse(kolibri_window* some_window)
|
2016-04-11 15:38:48 +02:00
|
|
|
{
|
|
|
|
/* Enumerate and trigger mouse handling functions of window elements here */
|
2016-04-12 20:50:48 +02:00
|
|
|
if(some_window->elements)
|
2016-04-11 15:38:48 +02:00
|
|
|
{
|
2016-06-30 18:10:04 +02:00
|
|
|
kolibri_window_element *current_element = some_window -> elements;
|
2016-04-11 15:38:48 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(kolibri_gui_op_table[current_element -> type].mouse_fn)
|
|
|
|
kolibri_gui_op_table[current_element -> type].mouse_fn(current_element -> element);
|
|
|
|
|
|
|
|
current_element = current_element -> next;
|
2016-04-12 20:50:48 +02:00
|
|
|
|
2016-04-11 15:38:48 +02:00
|
|
|
} while(current_element != some_window->elements); /* Have we covered all elements? */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void kolibri_exit(void)
|
|
|
|
{
|
|
|
|
__asm__ volatile ("int $0x40"::"a"(-1));
|
|
|
|
}
|
|
|
|
|
|
|
|
int kolibri_gui_init(void)
|
|
|
|
{
|
|
|
|
int boxlib_init_status = kolibri_boxlib_init();
|
|
|
|
|
2016-04-12 20:50:48 +02:00
|
|
|
if(boxlib_init_status == 0)
|
2016-04-11 15:38:48 +02:00
|
|
|
debug_board_write_str("ashmew2 is happy: Kolibri GUI Successfully Initialized.\n");
|
2016-04-12 20:50:48 +02:00
|
|
|
else
|
2016-04-11 15:38:48 +02:00
|
|
|
{
|
|
|
|
debug_board_write_str("ashmew2 is sad: Kolibri GUI Failed to initialize.\n");
|
|
|
|
kolibri_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the global operation table which handles event functions of */
|
|
|
|
/* each individual element type */
|
|
|
|
kolibri_init_gui_op_table();
|
|
|
|
|
|
|
|
/* Get the current color table for Kolibri and store in global table*/
|
|
|
|
kolibri_get_system_colors(&kolibri_color_table);
|
|
|
|
|
|
|
|
/* Set up system events for buttons, mouse and keyboard and redraw */
|
|
|
|
/* Also set filters so that window receives mouse events only when active
|
|
|
|
and mouse inside window */
|
2016-04-12 20:50:48 +02:00
|
|
|
__asm__ volatile("int $0x40"::"a"(40), "b"(0xC0000027));
|
|
|
|
|
|
|
|
return boxlib_init_status;
|
2016-04-11 15:38:48 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 20:50:48 +02:00
|
|
|
/* Note: The current implementation tries to automatically colors
|
2016-04-11 15:38:48 +02:00
|
|
|
GUI elements with system theme */
|
|
|
|
|
|
|
|
#endif /* KOLIBRI_GUI_H */
|