forked from misakamm/xege
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathege_head.h
491 lines (432 loc) · 12 KB
/
ege_head.h
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/*
* EGE (Easy Graphics Engine)
* filename ege_head.cpp
公共声明头文件(私有,不对外使用)
*/
#ifndef _EGE_HEAD_H_
#define _EGE_HEAD_H_
#ifndef _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
#define _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
#endif
#ifndef _ALLOW_RUNTIME_LIBRARY_MISMATCH
#define _ALLOW_RUNTIME_LIBRARY_MISMATCH
#endif
#if _MSC_VER >= 1910
#include <stdint.h>
#elif !defined(_MSC_VER) || _MSC_VER > 1300
#include "stdint.h"
#endif
#define _GRAPH_LIB_BUILD_
#include "ege.h"
#include "thread_queue.h"
#ifndef ERROR_SUCCESS
#define ERROR_SUCCESS 0
#endif
#ifndef ASSERT_TRUE
#ifdef _DEBUG
#include <cassert>
#define ASSERT_TRUE(e) assert((e) != MUSIC_ERROR)
#else
#define ASSERT_TRUE(e) (void(0))
#endif
#endif
#define EGE_GDIPLUS // 使用gdi+函数扩展
#ifdef EGE_GDIPLUS
#ifdef _MSC_VER
# include <gdiplus.h>
#else
# if __GNUC__ == 3
# include "gdiplus3/gdiplus.h"
# elif __GNUC__ >= 4
# include "gdiplus4/gdiplus.h"
# endif
#endif
#endif
#define QUEUE_LEN 1024
#define BITMAP_PAGE_SIZE 4
#define UPDATE_MAX_CALL 0xFF
#define RENDER_TIMER_ID 916
#define IMAGE_INIT_FLAG 0x20100916
#define MAX_KEY_VCODE 256
#define FLOAT_EPS 1e-3f
#ifndef SWAP
#define SWAP(_a, _b, _t) {_t = _a; _a = _b; _b = _t; }
#endif
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#define IFATODOB(A, B) ( (A) && (B, 0) )
#define IFNATODOB(A, B) ( (A) || (B, 0) )
#define CONVERT_IMAGE(pimg) ( ((size_t)(pimg)<0x20 ?\
((pimg) ?\
(graph_setting.img_page[(size_t)(pimg) & 0xF])\
: (--graph_setting.update_mark_count, graph_setting.imgtarget))\
: pimg) )
#define CONVERT_IMAGE_CONST(pimg) ( (size_t)(pimg)<0x20 ?\
((pimg) ?\
(graph_setting.img_page[(size_t)(pimg) & 0xF])\
: graph_setting.imgtarget)\
: pimg)
#define CONVERT_IMAGE_F(pimg) CONVERT_IMAGE(pimg)
#define CONVERT_IMAGE_F_CONST(pimg) CONVERT_IMAGE_CONST(pimg)
#define CONVERT_IMAGE_END
#ifndef DEFAULT_CHARSET
#define DEFAULT_CHARSET ANSI_CHARSET
#endif
#if !defined(_W64)
#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
#define _W64 __w64
#else
#define _W64
#endif
#endif
#ifndef __int3264
#if defined(_WIN64)
typedef __int64 LONG_PTR, *PLONG_PTR;
typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
#define __int3264 __int64
#else
typedef _W64 long LONG_PTR, *PLONG_PTR;
typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
#define __int3264 __int32
#endif
#endif
typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
typedef unsigned int uint32;
#if !defined(_MSC_VER) || _MSC_VER > 1200
typedef intptr_t POINTER_SIZE;
#else
typedef long POINTER_SIZE;
#endif
#ifndef _MSC_VER
#define GRADIENT_FILL_RECT_H 0x00000000
#define GRADIENT_FILL_RECT_V 0x00000001
#define GRADIENT_FILL_TRIANGLE 0x00000002
#define GRADIENT_FILL_OP_FLAG 0x000000ff
extern "C" {
WINGDIAPI
BOOL
WINAPI
GradientFill(
HDC hdc,
PTRIVERTEX pVertex,
ULONG nVertex,
PVOID pMesh,
ULONG nMesh,
ULONG ulMode
);
}
#endif
namespace ege {
enum dealmessage_update {
NORMAL_UPDATE = false,
FORCE_UPDATE = true,
};
struct EGEMSG {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
UINT mousekey;
UINT flag;
};
// 定义图像对象
class IMAGE
{
int m_initflag;
public:
HDC m_hDC;
HBITMAP m_hBmp;
int m_width;
int m_height;
PDWORD m_pBuffer;
color_t m_color;
color_t m_fillcolor;
bool m_aa;
private:
int newimage(HDC hdc, int width, int height);
int deleteimage();
void reset();
public:
viewporttype m_vpt;
textsettingstype m_texttype;
linestyletype m_linestyle;
float m_linewidth;
color_t m_bk_color;
void* m_pattern_obj;
int m_pattern_type;
void* m_texture;
private:
void inittest(const WCHAR* strCallFunction = NULL) const;
public:
IMAGE();
IMAGE(int width, int height);
IMAGE(IMAGE &img); // 拷贝构造函数
IMAGE& operator = (const IMAGE &img); // 赋值运算符重载函数
~IMAGE();
void set_pattern(void* obj, int type);
void delete_pattern();
void gentexture(bool gen);
public:
HDC getdc() const {return m_hDC;}
int getwidth() const {return m_width; }
int getheight() const {return m_height;}
color_t* getbuffer() const {return (color_t*)m_pBuffer;}
int createimage(int width, int height);
int resize(int width, int height);
void copyimage(const PIMAGE pSrcImg);
void getimage(int srcX, int srcY, int srcWidth, int srcHeight);
void getimage(const PIMAGE pSrcImg, int srcX, int srcY, int srcWidth, int srcHeight);
int getimage(LPCSTR pImgFile, int zoomWidth = 0, int zoomHeight = 0);
int getimage(LPCWSTR pImgFile, int zoomWidth = 0, int zoomHeight = 0);
int getimage(LPCSTR pResType, LPCSTR pResName, int zoomWidth = 0, int zoomHeight = 0);
int getimage(LPCWSTR pResType, LPCWSTR pResName, int zoomWidth = 0, int zoomHeight = 0);
int getimage(void* pMem, long size);
void putimage(int dstX, int dstY, DWORD dwRop = SRCCOPY) const;
void putimage(int dstX, int dstY, int dstWidth, int dstHeight, int srcX, int srcY, DWORD dwRop = SRCCOPY) const;
void putimage(PIMAGE pDstImg, int dstX, int dstY, DWORD dwRop = SRCCOPY) const;
void putimage(PIMAGE pDstImg, int dstX, int dstY, int dstWidth, int dstHeight, int srcX, int srcY, DWORD dwRop = SRCCOPY) const;
void putimage(PIMAGE pDstImg, int dstX, int dstY, int dstWidth, int dstHeight, int srcX, int srcY, int srcWidth, int srcHeight, DWORD dwRop = SRCCOPY) const;
int saveimage(LPCSTR filename);
int saveimage(LPCWSTR filename);
int getpngimg(FILE* fp);
int savepngimg(FILE* fp, int bAlpha);
int
putimage_transparent(
PIMAGE imgdest, // handle to dest
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
color_t crTransparent, // color to make transparent
int nXOriginSrc = 0, // x-coord of source upper-left corner
int nYOriginSrc = 0, // y-coord of source upper-left corner
int nWidthSrc = 0, // width of source rectangle
int nHeightSrc = 0 // height of source rectangle
);
int
putimage_alphablend(
PIMAGE imgdest, // handle to dest
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
unsigned char alpha, // alpha
int nXOriginSrc = 0, // x-coord of source upper-left corner
int nYOriginSrc = 0, // y-coord of source upper-left corner
int nWidthSrc = 0, // width of source rectangle
int nHeightSrc = 0 // height of source rectangle
);
int
putimage_alphatransparent(
PIMAGE imgdest, // handle to dest
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
color_t crTransparent, // color to make transparent
unsigned char alpha, // alpha
int nXOriginSrc = 0, // x-coord of source upper-left corner
int nYOriginSrc = 0, // y-coord of source upper-left corner
int nWidthSrc = 0, // width of source rectangle
int nHeightSrc = 0 // height of source rectangle
);
int
putimage_withalpha(
PIMAGE imgdest, // handle to dest
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nXOriginSrc = 0, // x-coord of source upper-left corner
int nYOriginSrc = 0, // y-coord of source upper-left corner
int nWidthSrc = 0, // width of source rectangle
int nHeightSrc = 0 // height of source rectangle
);
int
putimage_alphafilter(
PIMAGE imgdest, // handle to dest
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
PIMAGE imgalpha, // alpha
int nXOriginSrc = 0, // x-coord of source upper-left corner
int nYOriginSrc = 0, // y-coord of source upper-left corner
int nWidthSrc = 0, // width of source rectangle
int nHeightSrc = 0 // height of source rectangle
);
int
imagefilter_blurring_4 (
int intensity,
int alpha,
int nXOriginDest,
int nYOriginDest,
int nWidthDest,
int nHeightDest
);
int
imagefilter_blurring_8 (
int intensity,
int alpha,
int nXOriginDest,
int nYOriginDest,
int nWidthDest,
int nHeightDest
);
int
imagefilter_blurring (
int intensity,
int alpha,
int nXOriginDest = 0,
int nYOriginDest = 0,
int nWidthDest = 0,
int nHeightDest = 0
);
int putimage_rotate(
PIMAGE imgtexture,
int nXOriginDest,
int nYOriginDest,
float centerx,
float centery,
float radian,
int btransparent = 0, // transparent (1) or not (0)
int alpha = -1, // in range[0, 256], alpha== -1 means no alpha
int smooth = 0
);
int putimage_rotatezoom(
PIMAGE imgtexture,
int nXOriginDest,
int nYOriginDest,
float centerx,
float centery,
float radian,
float zoom,
int btransparent = 0, // transparent (1) or not (0)
int alpha = -1, // in range[0, 256], alpha== -1 means no alpha
int smooth = 0
);
};
// 定义ege全局状态对象
struct _graph_setting {
struct _graph {
int width;
int height;
}graph;
struct _aspectratio {
float xasp, yasp;
}aspectratio;
int writemode;
HDC dc;
HDC window_dc;
int dc_w, dc_h;
PIMAGE img_page[BITMAP_PAGE_SIZE];
int base_x, base_y, base_w, base_h;
int visual_page;
int active_page;
PIMAGE imgtarget;
PIMAGE imgtarget_set;
PIMAGE img_timer_update;
HINSTANCE instance;
HWND hwnd;
TCHAR window_class_name[32];
TCHAR window_caption[128];
int exit_flag;
int exit_window;
int update_mark_count; //更新标记
bool close_manually;
bool use_force_exit; //强制关闭进程标记
bool lock_window;
bool init_finish;
bool timer_stop_mark;
bool skip_timer_mark;
thread_queue<EGEMSG> *msgkey_queue, *msgmouse_queue;
HANDLE threadui_handle;
/*鼠标状态记录*/
int mouse_state_l, mouse_state_m, mouse_state_r;
int mouse_last_x, mouse_last_y;
int mouse_lastclick_x, mouse_lastclick_y;
int mouse_lastup_x, mouse_lastup_y;
int mouse_show;
LPMSG_KEY_PROC callback_key;
void* callback_key_param;
LPMSG_MOUSE_PROC callback_mouse;
void* callback_mouse_param;
LPCALLBACK_PROC callback_close;
/* 键盘状态记录 */
int keystatemap[MAX_KEY_VCODE];
/* egeControlBase */
egeControlBase* egectrl_root;
egeControlBase* egectrl_focus;
/* 私用全局变量 */
#ifdef EGE_GDIPLUS
ULONG_PTR g_gdiplusToken;
#endif
LARGE_INTEGER get_highfeq_time_start;
DWORD fclock_start;
//double delay_dwLast;
double delay_ms_dwLast;
double delay_fps_dwLast;
int getch_last_key;
HBRUSH savebrush_hbr;
/* 函数用临时缓冲区 */
DWORD g_t_buff[1024 * 8];
};
extern struct _graph_setting& graph_setting;
template<typename T>
struct count_ptr {
explicit count_ptr( T* p ) {
//m_mutex = new Mutex;
m_cnt = new long( 1 );
m_p = p;
}
~count_ptr() {
//m_mutex->Lock();
--*m_cnt;
if ( *m_cnt == 0 ) {
delete m_p;
m_p = static_cast<T*>( 0 );
delete m_cnt;
m_cnt = static_cast<long*>( 0 );
}
//Mutex* mutex = m_mutex;
//m_mutex = static_cast<Mutex*> ( 0 );
//mutex->UnLock();
}
count_ptr( const count_ptr<T>& count_ptr_ ) {
//m_mutex = count_ptr_.m_mutex;
//m_mutex->Lock();
m_p = count_ptr_.m_p;
m_cnt = count_ptr_.m_cnt;
++*m_cnt;
//m_mutex->UnLock();
}
count_ptr<T>& operator= ( const count_ptr<T>& count_ptr_ ) {
//m_mutex->Lock();
--*m_cnt;
if ( *m_cnt == 0 ) {
delete m_p;
m_p = static_cast<T*>( 0 );
delete m_cnt;
m_cnt = static_cast<long*>( 0 );
}
//Mutex* mutex = m_mutex;
//m_mutex = count_ptr_.m_mutex;
//mutex->UnLock();
//m_mutex->Lock();
m_p = count_ptr_.m_p;
m_cnt = static_cast<long*>( count_ptr_.m_cnt );
++*m_cnt;
//m_mutex->UnLock();
return *this;
}
operator T* () const {
return m_p;
}
T& operator * () const {
return *m_p;
}
T* operator -> () const {
return m_p;
}
private:
T* m_p;
long* m_cnt;
//Mutex* m_mutex;
};
} // namespace ege
#endif /*_EGE_HEAD_H_*/