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.15 by root, Tue Apr 11 13:14:36 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_get_pixel_size (CFClient__Layout self, int *w, int *h)
29{
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
22MODULE = Crossfire::Client PACKAGE = Crossfire::Client 37MODULE = CFClient PACKAGE = CFClient
23 38
24PROTOTYPES: ENABLE 39PROTOTYPES: ENABLE
25 40
26BOOT: 41BOOT:
27{ 42{
47 RETVAL = (char *)glGetString (GL_EXTENSIONS); 62 RETVAL = (char *)glGetString (GL_EXTENSIONS);
48 OUTPUT: 63 OUTPUT:
49 RETVAL 64 RETVAL
50 65
51void 66void
67add_font (char *file)
68 CODE:
69 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */
70
71void
52set_font (char *file) 72set_font (char *file)
53 CODE: 73 CODE:
54{ 74{
55 int count; 75 int count;
56 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); 76 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); 77 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
59 FcPatternDestroy (pattern); 78 FcPatternDestroy (pattern);
60 pango_context_set_font_description (context, font); 79 pango_context_set_font_description (context, font);
61} 80}
62 81
82MODULE = CFClient PACKAGE = CFClient::Layout
83
84CFClient::Layout
85new (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
63void 94void
64font_render (SV *text_, int height = 10) 95DESTROY (CFClient::Layout self)
65 PPCODE: 96 CODE:
97 g_object_unref (self->pl);
98 Safefree (self);
99
100void
101set_markup (CFClient::Layout self, SV *text_)
102 CODE:
66{ 103{
67 STRLEN textlen; 104 STRLEN textlen;
68 char *text = SvPVutf8 (text_, textlen); 105 char *text = SvPVutf8 (text_, textlen);
106
107 pango_layout_set_markup (self->pl, text, textlen);
108}
109
110void
111set_width (CFClient::Layout self, int max_width = -1)
112 CODE:
113 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
114
115void
116size (CFClient::Layout self)
117 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
131void
132render (CFClient::Layout self)
133 PPCODE:
134{
69 SV *retval; 135 SV *retval;
70 int w, h; 136 int w, h;
71 FT_Bitmap bitmap; 137 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 138
76 layout = pango_layout_new (context);
77 pango_layout_set_markup (layout, text, textlen);
78 pango_layout_get_pixel_size (layout, &w, &h); 139 layout_get_pixel_size (self, &w, &h);
79
80 w = (w + 3) & ~3;
81 if (!w) w = 1;
82 if (!h) h = 1;
83 140
84 retval = newSV (w * h); 141 retval = newSV (w * h);
85 SvPOK_only (retval); 142 SvPOK_only (retval);
86 SvCUR_set (retval, w * h); 143 SvCUR_set (retval, w * h);
87 144
92 bitmap.num_grays = 256; 149 bitmap.num_grays = 256;
93 bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; 150 bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
94 151
95 memset (bitmap.buffer, 0, w * h); 152 memset (bitmap.buffer, 0, w * h);
96 153
97 pango_ft2_render_layout (&bitmap, layout, 0 * PANGO_SCALE, 0 * PANGO_SCALE); 154 pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE);
98 g_object_unref (layout);
99 155
100 EXTEND (SP, 3); 156 EXTEND (SP, 3);
101 PUSHs (sv_2mortal (newSViv (w))); 157 PUSHs (sv_2mortal (newSViv (w)));
102 PUSHs (sv_2mortal (newSViv (h))); 158 PUSHs (sv_2mortal (newSViv (h)));
103 PUSHs (sv_2mortal (retval)); 159 PUSHs (sv_2mortal (retval));
104} 160}
105 161
106MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Texture 162MODULE = CFClient PACKAGE = CFClient::Texture
107 163
108void 164void
109draw_quad (SV *self, double x, double y, double w = 0, double h = 0) 165draw_quad (SV *self, double x, double y, double w = 0, double h = 0)
110 PROTOTYPE: $$$;$$ 166 PROTOTYPE: $$$;$$
111 CODE: 167 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines