Tiny Graphics Interfaces
载入中...
搜索中...
未找到
tgi.hpp
浏览该文件的文档.
1
22#ifndef TGI_HPP
23#define TGI_HPP
24
25#include "tgi.h"
26
27#ifdef __cplusplus
28namespace tgi
29{
30#define BEGIN_CLASS(Uname, Dname) \
31 class Uname \
32 { \
33 private: \
34 TGI_##Uname *self; \
35 \
36 public: \
37 operator TGI_##Uname *() \
38 { \
39 return self; \
40 } \
41 Uname() \
42 { \
43 self = 0; \
44 } \
45 Uname(TGI_##Uname *_self) \
46 { \
47 self = _self; \
48 } \
49 Uname(const Uname &b) \
50 { \
51 self = b.self; \
52 } \
53 Uname &operator=(const Uname &b) \
54 { \
55 self = b.self; \
56 return *this; \
57 } \
58 Uname &operator=(TGI_##Uname *b) \
59 { \
60 self = b; \
61 return *this; \
62 } \
63 ~Uname() \
64 { \
65 }
66#define END_CLASS() \
67 } \
68 ;
69#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, NAME, \
70 ...) \
71 NAME
72#define NAME2(t1, n1) n1
73#define NAME4(t1, n1, t2, n2) n1, n2
74#define NAME6(t1, n1, t2, n2, t3, n3) n1, n2, n3
75#define NAME8(t1, n1, t2, n2, t3, n3, t4, n4) n1, n2, n3, n4
76#define NAME10(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5) n1, n2, n3, n4, n5
77#define NAME12(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6) n1, n2, n3, n4, n5, n6
78#define NAME14(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6, t7, n7) n1, n2, n3, n4, n5, n6, n7
79#define NAME16(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6, t7, n7, t8, n8) n1, n2, n3, n4, n5, n6, n7, n8
80#define NAME18(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6, t7, n7, t8, n8, t9, n9) \
81 n1, n2, n3, n4, n5, n6, n7, n8, n9
82#define NAME20(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6, t7, n7, t8, n8, t9, n9, t10, n10) \
83 n1, n2, n3, n4, n5, n6, n7, n8, n9, n10
84#define NAME(args...) \
85 GET_MACRO(args, NAME20, NAME19, NAME18, NAME17, NAME16, NAME15, NAME14, NAME13, NAME12, NAME11, NAME10, NAME9, \
86 NAME8, NAME7, NAME6, NAME5, NAME4, NAME3, NAME2, NAME1) \
87 (args)
88#define VAR2(t1, n1) t1 n1
89#define VAR4(t1, n1, t2, n2) t1 n1, t2 n2
90#define VAR6(t1, n1, t2, n2, t3, n3) t1 n1, t2 n2, t3 n3
91#define VAR8(t1, n1, t2, n2, t3, n3, t4, n4) t1 n1, t2 n2, t3 n3, t4 n4
92#define VAR10(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5) t1 n1, t2 n2, t3 n3, t4 n4, t5 n5
93#define VAR12(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6) t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6
94#define VAR14(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6, t7, n7) t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6, t7 n7
95#define VAR16(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6, t7, n7, t8, n8) \
96 t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6, t7 n7, t8 n8
97#define VAR18(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6, t7, n7, t8, n8, t9, n9) \
98 t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6, t7 n7, t8 n8, t9 n9
99#define VAR20(t1, n1, t2, n2, t3, n3, t4, n4, t5, n5, t6, n6, t7, n7, t8, n8, t9, n9, t10, n10) \
100 t1 n1, t2 n2, t3 n3, t4 n4, t5 n5, t6 n6, t7 n7, t8 n8, t9 n9, t10 n10
101#define VAR(args...) \
102 GET_MACRO(args, VAR20, VAR19, VAR18, VAR17, VAR16, VAR15, VAR14, VAR13, VAR12, VAR11, VAR10, VAR9, VAR8, VAR7, \
103 VAR6, VAR5, VAR4, VAR3, VAR2, VAR1) \
104 (args)
105#define NEW(Uname, Dname, param...) \
106 Uname(VAR(param)) \
107 { \
108 self = tgi_##Dname##_create(NAME(param)); \
109 } \
110 static Uname create(VAR(param)) \
111 { \
112 return Uname(tgi_##Dname##_create(NAME(param))); \
113 }
114#define METHOD1(ret, name) \
115 ret name() \
116 { \
117 return self->vptr->name(self); \
118 }
119#define METHOD2(ret, name, param...) \
120 ret name(VAR(param)) \
121 { \
122 return self->vptr->name(self, NAME(param)); \
123 }
124#define METHOD(args...) \
125 GET_MACRO(args, METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, \
126 METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, METHOD2, METHOD1, METHOD1) \
127 (args)
128
129/* type defined */
130typedef TGI_Backend Backend;
131typedef TGI_Encoding Encoding;
132typedef TGI_WindowStyle WindowStyle;
133typedef TGI_FontStyle FontStyle;
134typedef TGI_TextAlign TextAlign;
135typedef TGI_Color Color;
136typedef TGI_Point Point;
137typedef TGI_Rect Rect;
138typedef TGI_KeyEvent KeyEvent;
139typedef TGI_MouseEvent MouseEvent;
140/* class predefined */
141class Application;
142class Window;
143class Graphics;
144class Image;
145class Font;
146class Timer;
147
148/* class Graphics */
149BEGIN_CLASS(Graphics, graphics)
150METHOD(void, free)
151METHOD(int, clear, Color, color)
152METHOD(int, set_color, Color, color)
153METHOD(int, set_width, float, width)
154METHOD(int, draw_line, float, x1, float, y1, float, x2, float, y2)
155METHOD(int, draw_arc, float, x, float, y, float, width, float, height, float, start_angle, float, sweep_angle)
156METHOD(int, draw_rect, float, x, float, y, float, width, float, height)
157METHOD(int, draw_ellipse, float, x, float, y, float, width, float, height)
158METHOD(int, draw_pie, float, x, float, y, float, width, float, height, float, start_angle, float, sweep_angle)
159METHOD(int, draw_polygon, const TGI_Point *, points, int, count)
160METHOD(int, fill_rect, float, x, float, y, float, width, float, height)
161METHOD(int, fill_ellipse, float, x, float, y, float, width, float, height)
162METHOD(int, fill_pie, float, x, float, y, float, width, float, height, float, start_angle, float, sweep_angle)
163METHOD(int, fill_polygon, const TGI_Point *, points, int, count)
164METHOD(int, draw_image, const TGI_Image *, image, float, x, float, y)
165METHOD(int, draw_image_rect, const TGI_Image *, image, float, x, float, y, float, width, float, height)
166METHOD(int, draw_image_ex, const TGI_Image *, image, float, x, float, y, float, src_x, float, src_y, float, src_width,
167 float, src_height)
168METHOD(int, draw_image_rect_ex, const TGI_Image *, image, float, x, float, y, float, width, float, height, float, src_x,
169 float, src_y, float, src_width, float, src_height)
170METHOD(int, draw_text, const char *, text, const TGI_Font *, font, float, x, float, y)
171METHOD(int, draw_text_rect, const char *, text, const TGI_Font *, font, float, x, float, y, float, width, float, height)
172END_CLASS()
173
174/* class Image */
175BEGIN_CLASS(Image, image)
176METHOD(void, free)
177METHOD(TGI_Image *, clone)
178METHOD(int, get_size, Rect *, rect)
179METHOD(TGI_Graphics *, create_graphics)
180END_CLASS()
181
182/* class Window */
183BEGIN_CLASS(Window, window)
184METHOD(void, free)
185typedef int TGIAPI OnCloseCallback(TGI_Window *wnd);
186typedef void TGIAPI OnPaintCallback(TGI_Window *wnd);
187typedef void TGIAPI OnSizeCallback(TGI_Window *wnd, float new_width, float new_height);
188typedef void TGIAPI OnKeyCallback(TGI_Window *wnd, KeyEvent *e);
189typedef void TGIAPI OnMouseCallback(TGI_Window *wnd, MouseEvent *e);
190METHOD(void, on_close, OnCloseCallback, callback)
191METHOD(void, on_paint, OnPaintCallback, callback)
192METHOD(void, on_size, OnSizeCallback, callback)
193METHOD(void, on_key, OnKeyCallback, callback)
194METHOD(void, on_mouse, OnMouseCallback, callback)
195METHOD(int, is_key_down, char, key)
196METHOD(void, show)
197METHOD(void, paint)
198METHOD(int, set_style, WindowStyle, style)
199METHOD(int, get_size, Rect *, rect)
200METHOD(int, set_size, int, width, int, height)
201METHOD(int, set_min_size, int, width, int, height)
202METHOD(int, set_max_size, int, width, int, height)
203METHOD(int, set_title, const char *, title)
204METHOD(TGI_Graphics *, create_graphics)
205METHOD(TGI_Image *, create_image)
206END_CLASS()
207
208/* class Font */
209BEGIN_CLASS(Font, font)
210METHOD(void, free)
211METHOD(int, set_align, TextAlign, align)
212METHOD(int, set_vertical_align, TextAlign, align)
213END_CLASS()
214
215/* class Timer */
216BEGIN_CLASS(Timer, timer)
217METHOD(void, free)
218END_CLASS()
219
220/* class Application */
221BEGIN_CLASS(Application, application)
222METHOD(void, free)
223typedef void TGIAPI TimerCallback(TGI_Timer *timer);
224NEW(Application, application, Backend, backend, Encoding, encoding)
225METHOD(void, exec)
226METHOD(int, exec_once)
227METHOD(TGI_Window *, create_window)
228METHOD(TGI_Image *, create_image, int, width, int, height)
229METHOD(TGI_Image *, create_image_from_file, const char *, filename)
230METHOD(TGI_Font *, create_font, const char *, name, float, size, TGI_FontStyle, style)
231METHOD(TGI_Timer *, create_timer, unsigned int, delay, int, type, TimerCallback, callback)
232END_CLASS()
233
234#undef BEGIN_CLASS
235#undef END_CLASS
236#undef GET_MACRO
237#undef NAME
238#undef NAME2
239#undef NAME4
240#undef NAME6
241#undef NAME8
242#undef NAME10
243#undef NAME12
244#undef NAME14
245#undef NAME16
246#undef NAME18
247#undef NAME20
248#undef VAR
249#undef VAR2
250#undef VAR4
251#undef VAR6
252#undef VAR8
253#undef VAR10
254#undef VAR12
255#undef VAR14
256#undef VAR16
257#undef VAR18
258#undef VAR20
259#undef NEW
260#undef METHOD
261#undef METHOD1
262#undef METHOD2
263
264} // namespace tgi
265#endif
266
267#endif
字体对象类型
Definition tgi.h:184
图形对象类型
Definition tgi.h:157
图像对象类型
Definition tgi.h:172
键盘事件类型
Definition tgi.h:305
鼠标事件类型
Definition tgi.h:337
点(坐标)类型
Definition tgi.h:288
矩形类型
Definition tgi.h:296
计时器对象类型
Definition tgi.h:256
窗口对象类型
Definition tgi.h:86
Tiny Graphics Interfaces
TGI_FontStyle
字体样式类型
Definition tgi.h:196
TGI_TextAlign
字体对齐方法类型
Definition tgi.h:227
TGI_Backend
图形后端类型
Definition tgi.h:22
TGI_Encoding
文本编码类型
Definition tgi.h:35
TGI_WindowStyle
窗口风格类型
Definition tgi.h:100
unsigned int TGI_Color
颜色类型
Definition tgi.h:264