-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_api.c
111 lines (93 loc) · 2.67 KB
/
gui_api.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
106
107
108
109
110
111
#include "types.h"
#include "user.h"
#include "gui_base.h"
#include "msg.h"
#include "character.h"
int api_createwindow(Window* wnd)
{
Size size = wnd->size;
wnd->wholeContent = malloc(size.w * (size.h + UTITLE_HEIGHT) * 3);
wnd->content = wnd->wholeContent + size.w * UTITLE_HEIGHT;
// set all content to zero
memset(wnd->content, 255, size.w * size.h * 3);
wnd->hwnd = createwindow(wnd->pos.x, wnd->pos.y,
wnd->size.w, wnd->size.h, wnd->title, wnd->wholeContent);
return wnd->hwnd;
}
int api_paint24Bitmap(Window* wnd, struct RGB* img, Point p, Size s)
{
drawBitmap(wnd->content, img, p, (Point){0, 0}, wnd->size, s, s);
return 0;
}
int api_paint24BitmapToContent(Window* wnd, struct RGB* img, Point pWnd, Point pBmp, Size sBmp, Size s)
{
drawBitmap(wnd->content, img, pWnd, pBmp, wnd->size, sBmp, s);
return 0;
}
int api_paint24BitmapToContentTransparent(Window* wnd, struct RGB* img, Point pWnd, Point pBmp, Size sBmp, Size s)
{
drawTransparentBitmap(wnd->content, img, pWnd, pBmp, wnd->size, sBmp, s);
return 0;
}
int api_repaint(Window* wnd)
{
repaintwindow(wnd->hwnd);
return 0;
}
int api_update(Window* wnd, Rect rect)
{
updatewindow(wnd->hwnd, rect.x, rect.y, rect.h, rect.w);
return 0;
}
int api_exec(Window* wnd, ProcFun pf)
{
message msg;
int r = 0;
while(1)
{
r = getmessage(wnd->hwnd, &msg);
if(r)
{
pf(&msg);
}
}
return -1;
}
int api_settimer(Window* wnd, int interval)
{
settimer(wnd->hwnd, interval);
return 0;
}
int api_drawRect(Window *wnd, Point p, Size s, RGB color)
{
drawRect(wnd->content, p, wnd->size, color, s);
return 0;
}
int api_drawCharacter(Window *wnd, int x, int y, char ch, RGBA color) {
drawCharacter(wnd->content, (Point){x, y}, wnd->size, ch, color);
return 0;
}
int api_drawString(Window *wnd, int x, int y, char *str, RGBA color) {
drawString(wnd->content, (Point){x, y}, wnd->size, str, color);
return 0;
}
int api_drawButton(Window *wnd, Point p, Size s, char * str)
{
RGB bColor;
bColor.R = 9;
bColor.G = 163;
bColor.B = 220;
api_drawRect(wnd, p, s, bColor);
api_drawString(wnd, p.x + 10, p.y + 10, str, (RGBA){255,255,255,255});
return 0;
}
int api_drawImgButton(Window* wnd, struct RGB* img, Point pWnd, Size s, int borderWidth, RGB borderColor, int shift) {
drawBitmap(wnd->content, img, pWnd, (Point){0, 0}, wnd->size, s, s);
colorShift(wnd->content, pWnd, wnd->size, s, shift);
drawBorder(wnd->content, pWnd, wnd->size, borderColor, s, borderWidth);
return 0;
}
int api_destroywindow(Window *wnd) {
destroywindow(wnd->hwnd);
return 0;
}