forked from wagy/WinBinder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
phpwb_draw.c
149 lines (106 loc) · 4.07 KB
/
phpwb_draw.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
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
/*******************************************************************************
WINBINDER - The native Windows binding for PHP for PHP
Copyright © Hypervisual - see LICENSE.TXT for details
Author: Rubem Pechansky (http://winbinder.org/contact.php)
ZEND wrapper for drawing functions
*******************************************************************************/
//----------------------------------------------------------------- DEPENDENCIES
#include "phpwb.h"
//----------------------------------------------------------- EXPORTED FUNCTIONS
/*
source can be a WinBinder object, a bitmap handle, a window handle or a DC.
Returns NOCOLOR (0xFFFFFFFF) if error
TODO: handle could also be a bitmap file?
*/
ZEND_FUNCTION(wb_get_pixel)
{
if(ZEND_NUM_ARGS() == 3) {
zend_long handle, x, y;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"lll", &handle, &x, &y) == FAILURE)
return;
RETURN_LONG(wbGetPixel((HANDLE)handle, x, y));
} else {
// With four parameters: call wbGetPixelDirect() for faster performance (not stable)
zend_long x, y;
unsigned char *pixdata;
int pixdata_len;
BOOL compress4to3 = FALSE;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"slll", &pixdata, &pixdata_len, &x, &y, &compress4to3) == FAILURE)
return;
RETURN_LONG(wbGetPixelDirect(pixdata, x, y, compress4to3));
}
}
/*
source can be a WinBinder object, a bitmap handle, a window handle or a DC.
TODO: allow separate R,G,B values
TODO: handle could also be a bitmap file??
*/
ZEND_FUNCTION(wb_draw_point)
{
zend_long handle, x, y, color;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"llll", &handle, &x, &y, &color) == FAILURE)
return;
RETURN_BOOL(wbSetPixel((HANDLE)handle, x, y, color));
}
ZEND_FUNCTION(wb_draw_line)
{
zend_long handle, x0, y0, x1, y1, color, linewidth = 0, linestyle = 0;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"llllll|ll", &handle, &x0, &y0, &x1, &y1, &color, &linewidth, &linestyle) == FAILURE)
return;
RETURN_BOOL(wbDrawLine((HANDLE)handle, x0, y0, x1, y1, color, linewidth, linestyle));
}
ZEND_FUNCTION(wb_draw_rect)
{
zend_long handle, x, y, width, height, color, filled = TRUE, linewidth = 0, linestyle = 0;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"llllll|lll", &handle, &x, &y, &width, &height, &color, &filled, &linewidth, &linestyle) == FAILURE)
return;
RETURN_BOOL(wbDrawRect((HANDLE)handle, x, y, width, height, color, filled, linewidth, linestyle));
}
ZEND_FUNCTION(wb_draw_ellipse)
{
zend_long handle, x, y, width, height, color, filled = TRUE, linewidth = 0, linestyle = 0;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"llllll|lll", &handle, &x, &y, &width, &height, &color, &filled, &linewidth, &linestyle) == FAILURE)
return;
RETURN_BOOL(wbDrawEllipse((HANDLE)handle, x, y, width, height, color, filled, linewidth, linestyle));
}
ZEND_FUNCTION(wb_draw_text)
{
zend_long handle, x, y, width = 0, height = 0, nfont = -1, flags = 0;
char *text;
int text_len;
int nargs;
TCHAR *wcs = 0;
nargs = ZEND_NUM_ARGS();
if(zend_parse_parameters(nargs TSRMLS_CC,
"lsll|llll", &handle, &text, &text_len, &x, &y, &width, &height, &nfont, &flags) == FAILURE)
return;
switch(nargs) {
case 4:
nfont = -1;
break;
case 5:
nfont = width;
break;
}
// UGLY, DIRTY HACK that is necessary to change the unnatural default parameters of wbDrawText.
// Must change the internal defaults in font functions from the API layer.
nfont = (nfont == 0 ? -1 : (nfont < 0 ? 0 : nfont));
wcs = Utf82WideChar(text, text_len);
RETURN_BOOL(wbDrawText((HANDLE)handle, wcs, x, y, width, height, nfont, flags));
}
ZEND_FUNCTION(wb_draw_image)
{
zend_long handle, hbm, x = 0, y = 0, w = 0, h = 0, cx = 0, cy = 0;
COLORREF transpcolor = NOCOLOR;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ll|lllllll", &handle, &hbm, &x, &y, &w, &h, &transpcolor, &cx, &cy) == FAILURE)
return;
RETURN_BOOL((LONG)wbDrawBitmap((HANDLE)handle, (HBITMAP)hbm, x, y, w, h, cx, cy, transpcolor))
}
//------------------------------------------------------------------ END OF FILE