-
Notifications
You must be signed in to change notification settings - Fork 12
/
dialog.c
105 lines (86 loc) · 1.86 KB
/
dialog.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Komposter
*
* Copyright (c) 2010 Noora Halme et al. (see AUTHORS)
*
* This code is licensed under the GNU General Public
* License version 2. See LICENSE for full text.
*
* Framework for modal dialog windows
*
*/
#include "dialog.h"
// global vars for modal dialogs
int dialog_active=0;
// function pointers to dialog actions
void (*dialog_drawfunc)(void) = NULL;
void (*dialog_hoverfunc)(int,int) = NULL;
void (*dialog_clickfunc)(int,int,int,int) = NULL;
void (*dialog_kbfunc)(unsigned char,int,int) = NULL;
void (*dialog_dragfunc)(int,int) = NULL;
void (*dialog_specialfunc)(int,int,int) = NULL;
int is_dialog(void)
{
return dialog_active;
}
int is_dialogkb(void)
{
return (dialog_kbfunc!=NULL);
}
int is_dialogdrag(void) {
return (dialog_dragfunc!=NULL);
}
void dialog_open(void *draw, void *hover, void *click)
{
dialog_active=1;
dialog_drawfunc=draw;
dialog_hoverfunc=hover;
dialog_clickfunc=click;
}
void dialog_bindkeyboard(void *kbfunc)
{
dialog_kbfunc=kbfunc;
}
void dialog_binddrag(void *dragfunc)
{
dialog_dragfunc=dragfunc;
}
void dialog_bindspecial(void *specialfunc)
{
dialog_specialfunc=specialfunc;
}
void dialog_close(void)
{
dialog_active=0;
dialog_drawfunc=NULL;
dialog_hoverfunc=NULL;
dialog_clickfunc=NULL;
dialog_kbfunc=NULL;
dialog_dragfunc=NULL;
dialog_specialfunc=NULL;
}
void dialog_draw(void)
{
draw_dimmer();
dialog_drawfunc();
}
void dialog_hover(int x, int y)
{
dialog_hoverfunc(x, y);
}
void dialog_click(int button, int state, int x, int y)
{
if (dialog_clickfunc) dialog_clickfunc(button, state, x, y);
}
void dialog_keyboard(unsigned char key, int x, int y)
{
if (dialog_kbfunc) dialog_kbfunc(key, x, y);
}
void dialog_drag(int x, int y)
{
if (dialog_dragfunc) dialog_dragfunc(x, y);
}
void dialog_special(int key, int x, int y)
{
if (dialog_specialfunc) dialog_specialfunc(key, x, y);
}