summaryrefslogtreecommitdiff
path: root/src/gui/widget.h
blob: 87b8c62221647ba6215355e18f64270f23a313b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef WIDGET_H
#define WIDGET_H

#include "graphics_context.h"

#include <stdbool.h>

struct widget_t;

typedef struct {
	void (*draw)( void *obj, graphics_context_t *context );
	void (*get_focus)( void *obj, struct widget_t *widget );
	void (*model_to_screen)( void *obj, int *x, int *y );
	bool (*contains_coordinate)( void *obj, const int x, const int y );
	void (*on_mouse_down)( void *obj, const int x, const int y );
	void (*on_mouse_up)( void *obj, const int x, const int y );
	void (*on_mouse_move)( void *obj, const int old_x, const int old_y, const int x, const int y );
	void (*on_key_down)( void *obj, char c );
	void (*on_key_up)( void *obj, char c );
} widget_vtable_t;

typedef struct widget_t {
	int x;
	int y;
	int w;
	int h;
	vga_color_t background_color;
	bool focusable;
	struct widget_t *parent;
	widget_vtable_t const *vtable;
} widget_t;

void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color );

void widget_draw( void *obj, graphics_context_t *context );
void widget_get_focus( void *obj, widget_t *widget );
void widget_model_to_screen( void *obj, int *x, int *y );
bool widget_contains_coordinate( void *obj, const int x, const int y );
void widget_on_mouse_down( void *obj, const int x, const int y );
void widget_on_mouse_up( void *obj, const int x, const int y );
void widget_on_mouse_move( void *obj, const int old_x, const int old_y, const int x, const int y );
void widget_on_key_down( void *obj, char c );
void widget_on_key_up( void *obj, char c );

#endif // WIDGET_H