ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.12 by root, Mon Apr 10 22:16:33 2006 UTC vs.
Revision 1.17 by root, Tue Apr 11 17:02:35 2006 UTC

17#include <netinet/tcp.h> 17#include <netinet/tcp.h>
18 18
19static PangoContext *context; 19static PangoContext *context;
20static PangoFontMap *fontmap; 20static PangoFontMap *fontmap;
21 21
22typedef struct cf_layout {
23 PangoLayout *pl;
24 int base_height;
25} *CFClient__Layout;
26
27static void
28layout_update (CFClient__Layout self)
29{
30 PangoFontDescription *font = pango_context_get_font_description (context);
31 pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE);
32}
33
34static void
35layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
36{
37 PangoFontDescription *font = pango_context_get_font_description (context);
38 pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE);
39
40 pango_layout_get_pixel_size (self->pl, w, h);
41
42 *w = (*w + 3) & ~3;
43 if (!*w) *w = 1;
44 if (!*h) *h = 1;
45}
46
22MODULE = Crossfire::Client PACKAGE = Crossfire::Client 47MODULE = CFClient PACKAGE = CFClient
23 48
24PROTOTYPES: ENABLE 49PROTOTYPES: ENABLE
25 50
26BOOT: 51BOOT:
27{ 52{
47 RETVAL = (char *)glGetString (GL_EXTENSIONS); 72 RETVAL = (char *)glGetString (GL_EXTENSIONS);
48 OUTPUT: 73 OUTPUT:
49 RETVAL 74 RETVAL
50 75
51void 76void
77add_font (char *file)
78 CODE:
79 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */
80
81void
52set_font (char *file) 82set_font (char *file)
53 CODE: 83 CODE:
54{ 84{
55 int count; 85 int count;
56 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); 86 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count);
57 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */
58 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); 87 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
59 FcPatternDestroy (pattern); 88 FcPatternDestroy (pattern);
60 pango_context_set_font_description (context, font); 89 pango_context_set_font_description (context, font);
61} 90}
62 91
63void 92MODULE = CFClient PACKAGE = CFClient::Layout
64font_render (SV *text_, int height = 10) 93
94CFClient::Layout
95new (SV *class, int base_height = 10)
65 PPCODE: 96 CODE:
97 New (0, RETVAL, 1, struct cf_layout);
98 RETVAL->base_height = base_height;
99 RETVAL->pl = pango_layout_new (context);
100 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
101 OUTPUT:
102 RETVAL
103
104void
105DESTROY (CFClient::Layout self)
106 CODE:
107 g_object_unref (self->pl);
108 Safefree (self);
109
110void
111set_markup (CFClient::Layout self, SV *text_)
112 CODE:
66{ 113{
67 STRLEN textlen; 114 STRLEN textlen;
68 char *text = SvPVutf8 (text_, textlen); 115 char *text = SvPVutf8 (text_, textlen);
116
117 pango_layout_set_markup (self->pl, text, textlen);
118}
119
120void
121set_height (CFClient::Layout self, int base_height)
122 CODE:
123 self->base_height = base_height;
124
125void
126set_width (CFClient::Layout self, int max_width = -1)
127 CODE:
128 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
129
130void
131size (CFClient::Layout self)
132 PPCODE:
133{
134 int w, h;
135
136 layout_update (self);
137 layout_get_pixel_size (self, &w, &h);
138
139 EXTEND (SP, 2);
140 PUSHs (sv_2mortal (newSViv (w)));
141 PUSHs (sv_2mortal (newSViv (h)));
142}
143
144int
145xy_to_index (CFClient::Layout self, int x, int y)
146 CODE:
147{
148 int index, trailing;
149
150 layout_update (self);
151 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
152
153 RETVAL = index;
154}
155 OUTPUT:
156 RETVAL
157
158void
159cursor_pos (CFClient::Layout self, int index)
160 PPCODE:
161{
162 PangoRectangle strong_pos;
163 layout_update (self);
164 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
165 EXTEND (SP, 3);
166 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
167 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
168 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
169}
170
171void
172render (CFClient::Layout self)
173 PPCODE:
174{
69 SV *retval; 175 SV *retval;
70 int w, h; 176 int w, h;
71 FT_Bitmap bitmap; 177 FT_Bitmap bitmap;
72 PangoLayout *layout;
73 PangoFontDescription *font = pango_context_get_font_description (context);
74 pango_font_description_set_absolute_size (font, height * PANGO_SCALE);
75 178
76 layout = pango_layout_new (context); 179 layout_update (self);
77 pango_layout_set_markup (layout, text, textlen);
78 pango_layout_get_pixel_size (layout, &w, &h); 180 layout_get_pixel_size (self, &w, &h);
79
80 w = (w + 3) & ~3;
81 if (!w) w = 1;
82 if (!h) h = 1;
83 181
84 retval = newSV (w * h); 182 retval = newSV (w * h);
85 SvPOK_only (retval); 183 SvPOK_only (retval);
86 SvCUR_set (retval, w * h); 184 SvCUR_set (retval, w * h);
87 185
92 bitmap.num_grays = 256; 190 bitmap.num_grays = 256;
93 bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; 191 bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
94 192
95 memset (bitmap.buffer, 0, w * h); 193 memset (bitmap.buffer, 0, w * h);
96 194
97 pango_ft2_render_layout (&bitmap, layout, 0 * PANGO_SCALE, 0 * PANGO_SCALE); 195 pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE);
98 g_object_unref (layout);
99 196
100 EXTEND (SP, 3); 197 EXTEND (SP, 3);
101 PUSHs (sv_2mortal (newSViv (w))); 198 PUSHs (sv_2mortal (newSViv (w)));
102 PUSHs (sv_2mortal (newSViv (h))); 199 PUSHs (sv_2mortal (newSViv (h)));
103 PUSHs (sv_2mortal (retval)); 200 PUSHs (sv_2mortal (retval));
104} 201}
105 202
106MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Texture 203MODULE = CFClient PACKAGE = CFClient::Texture
107 204
108void 205void
109draw_quad (SV *self, double x, double y, double w = 0, double h = 0) 206draw_quad (SV *self, double x, double y, double w = 0, double h = 0)
110 PROTOTYPE: $$$;$$ 207 PROTOTYPE: $$$;$$
111 CODE: 208 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines