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