1 |
root |
1.1 |
#include "EXTERN.h" |
2 |
|
|
#include "perl.h" |
3 |
|
|
#include "XSUB.h" |
4 |
|
|
|
5 |
root |
1.5 |
#include <string.h> |
6 |
|
|
|
7 |
root |
1.2 |
#include <SDL.h> |
8 |
root |
1.3 |
#include <SDL_opengl.h> |
9 |
root |
1.5 |
|
10 |
|
|
#include <pango/pango.h> |
11 |
root |
1.10 |
#include <pango/pangofc-fontmap.h> |
12 |
root |
1.5 |
#include <pango/pangoft2.h> |
13 |
|
|
|
14 |
root |
1.10 |
#include <sys/types.h> |
15 |
|
|
#include <sys/socket.h> |
16 |
|
|
#include <netinet/in.h> |
17 |
|
|
#include <netinet/tcp.h> |
18 |
|
|
|
19 |
root |
1.5 |
static PangoContext *context; |
20 |
|
|
static PangoFontMap *fontmap; |
21 |
root |
1.2 |
|
22 |
root |
1.14 |
typedef struct cf_layout { |
23 |
|
|
PangoLayout *pl; |
24 |
|
|
int base_height; |
25 |
root |
1.15 |
} *CFClient__Layout; |
26 |
root |
1.14 |
|
27 |
|
|
static void |
28 |
root |
1.15 |
layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
29 |
root |
1.14 |
{ |
30 |
root |
1.16 |
PangoFontDescription *font = pango_context_get_font_description (context); |
31 |
|
|
pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
32 |
|
|
|
33 |
root |
1.14 |
pango_layout_get_pixel_size (self->pl, w, h); |
34 |
|
|
|
35 |
|
|
*w = (*w + 3) & ~3; |
36 |
|
|
if (!*w) *w = 1; |
37 |
|
|
if (!*h) *h = 1; |
38 |
|
|
} |
39 |
|
|
|
40 |
root |
1.15 |
MODULE = CFClient PACKAGE = CFClient |
41 |
root |
1.1 |
|
42 |
root |
1.11 |
PROTOTYPES: ENABLE |
43 |
|
|
|
44 |
root |
1.5 |
BOOT: |
45 |
|
|
{ |
46 |
|
|
fontmap = pango_ft2_font_map_new (); |
47 |
root |
1.8 |
context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
48 |
root |
1.5 |
} |
49 |
|
|
|
50 |
root |
1.10 |
void |
51 |
|
|
lowdelay (int fd, int val = 1) |
52 |
|
|
CODE: |
53 |
|
|
setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
54 |
|
|
|
55 |
root |
1.3 |
char * |
56 |
root |
1.4 |
gl_version () |
57 |
|
|
CODE: |
58 |
root |
1.5 |
RETVAL = (char *)glGetString (GL_VERSION); |
59 |
root |
1.4 |
OUTPUT: |
60 |
|
|
RETVAL |
61 |
|
|
|
62 |
|
|
char * |
63 |
root |
1.3 |
gl_extensions () |
64 |
|
|
CODE: |
65 |
root |
1.5 |
RETVAL = (char *)glGetString (GL_EXTENSIONS); |
66 |
root |
1.3 |
OUTPUT: |
67 |
|
|
RETVAL |
68 |
|
|
|
69 |
root |
1.5 |
void |
70 |
root |
1.13 |
add_font (char *file) |
71 |
|
|
CODE: |
72 |
|
|
FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
73 |
|
|
|
74 |
|
|
void |
75 |
root |
1.9 |
set_font (char *file) |
76 |
root |
1.8 |
CODE: |
77 |
|
|
{ |
78 |
root |
1.9 |
int count; |
79 |
|
|
FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
80 |
root |
1.10 |
PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
81 |
root |
1.9 |
FcPatternDestroy (pattern); |
82 |
root |
1.8 |
pango_context_set_font_description (context, font); |
83 |
|
|
} |
84 |
|
|
|
85 |
root |
1.15 |
MODULE = CFClient PACKAGE = CFClient::Layout |
86 |
root |
1.14 |
|
87 |
root |
1.15 |
CFClient::Layout |
88 |
root |
1.14 |
new (SV *class, int base_height = 10) |
89 |
|
|
CODE: |
90 |
|
|
New (0, RETVAL, 1, struct cf_layout); |
91 |
|
|
RETVAL->base_height = base_height; |
92 |
|
|
RETVAL->pl = pango_layout_new (context); |
93 |
|
|
pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
94 |
|
|
OUTPUT: |
95 |
|
|
RETVAL |
96 |
|
|
|
97 |
|
|
void |
98 |
root |
1.15 |
DESTROY (CFClient::Layout self) |
99 |
root |
1.14 |
CODE: |
100 |
|
|
g_object_unref (self->pl); |
101 |
|
|
Safefree (self); |
102 |
root |
1.13 |
|
103 |
root |
1.8 |
void |
104 |
root |
1.15 |
set_markup (CFClient::Layout self, SV *text_) |
105 |
root |
1.14 |
CODE: |
106 |
root |
1.5 |
{ |
107 |
|
|
STRLEN textlen; |
108 |
|
|
char *text = SvPVutf8 (text_, textlen); |
109 |
root |
1.14 |
|
110 |
|
|
pango_layout_set_markup (self->pl, text, textlen); |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
void |
114 |
root |
1.16 |
set_height (CFClient::Layout self, int base_height) |
115 |
|
|
CODE: |
116 |
|
|
self->base_height = base_height; |
117 |
|
|
|
118 |
|
|
void |
119 |
root |
1.15 |
set_width (CFClient::Layout self, int max_width = -1) |
120 |
root |
1.14 |
CODE: |
121 |
|
|
pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
122 |
|
|
|
123 |
|
|
void |
124 |
root |
1.15 |
size (CFClient::Layout self) |
125 |
root |
1.14 |
PPCODE: |
126 |
|
|
{ |
127 |
|
|
int w, h; |
128 |
|
|
|
129 |
|
|
layout_get_pixel_size (self, &w, &h); |
130 |
|
|
|
131 |
|
|
EXTEND (SP, 2); |
132 |
|
|
PUSHs (sv_2mortal (newSViv (w))); |
133 |
|
|
PUSHs (sv_2mortal (newSViv (h))); |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
void |
137 |
root |
1.15 |
render (CFClient::Layout self) |
138 |
root |
1.14 |
PPCODE: |
139 |
|
|
{ |
140 |
root |
1.5 |
SV *retval; |
141 |
|
|
int w, h; |
142 |
|
|
FT_Bitmap bitmap; |
143 |
|
|
|
144 |
root |
1.14 |
layout_get_pixel_size (self, &w, &h); |
145 |
root |
1.5 |
|
146 |
|
|
retval = newSV (w * h); |
147 |
|
|
SvPOK_only (retval); |
148 |
|
|
SvCUR_set (retval, w * h); |
149 |
|
|
|
150 |
|
|
bitmap.rows = h; |
151 |
|
|
bitmap.width = w; |
152 |
|
|
bitmap.pitch = w; |
153 |
|
|
bitmap.buffer = (unsigned char*)SvPVX (retval); |
154 |
|
|
bitmap.num_grays = 256; |
155 |
|
|
bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
156 |
|
|
|
157 |
|
|
memset (bitmap.buffer, 0, w * h); |
158 |
|
|
|
159 |
root |
1.14 |
pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
160 |
root |
1.1 |
|
161 |
root |
1.5 |
EXTEND (SP, 3); |
162 |
|
|
PUSHs (sv_2mortal (newSViv (w))); |
163 |
|
|
PUSHs (sv_2mortal (newSViv (h))); |
164 |
|
|
PUSHs (sv_2mortal (retval)); |
165 |
|
|
} |
166 |
root |
1.11 |
|
167 |
root |
1.15 |
MODULE = CFClient PACKAGE = CFClient::Texture |
168 |
root |
1.11 |
|
169 |
|
|
void |
170 |
root |
1.12 |
draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
171 |
|
|
PROTOTYPE: $$$;$$ |
172 |
root |
1.11 |
CODE: |
173 |
|
|
{ |
174 |
root |
1.12 |
HV *hv = (HV *)SvRV (self); |
175 |
|
|
double s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
176 |
|
|
double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
177 |
|
|
int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
178 |
|
|
|
179 |
|
|
if (items < 5) |
180 |
|
|
{ |
181 |
|
|
w = SvNV (*hv_fetch (hv, "width", 5, 1)); |
182 |
|
|
h = SvNV (*hv_fetch (hv, "height", 6, 1)); |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
glBindTexture (GL_TEXTURE_2D, name); |
186 |
|
|
glBegin (GL_QUADS); |
187 |
|
|
glTexCoord2d (0, 0); glVertex2d (x , y ); |
188 |
|
|
glTexCoord2d (0, t); glVertex2d (x , y + h); |
189 |
|
|
glTexCoord2d (s, t); glVertex2d (x + w, y + h); |
190 |
|
|
glTexCoord2d (s, 0); glVertex2d (x + w, y ); |
191 |
|
|
glEnd (); |
192 |
root |
1.11 |
} |