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.11 by root, Mon Apr 10 19:34:03 2006 UTC vs.
Revision 1.14 by root, Tue Apr 11 13:05:11 2006 UTC

16#include <netinet/in.h> 16#include <netinet/in.h>
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
22typedef struct cf_layout {
23 PangoLayout *pl;
24 int base_height;
25} *Crossfire__Client__Layout;
26
27static void
28layout_get_pixel_size (Crossfire__Client__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}
21 36
22MODULE = Crossfire::Client PACKAGE = Crossfire::Client 37MODULE = Crossfire::Client PACKAGE = Crossfire::Client
23 38
24PROTOTYPES: ENABLE 39PROTOTYPES: ENABLE
25 40
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 = Crossfire::Client PACKAGE = Crossfire::Client::Layout
83
84Crossfire::Client::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 (Crossfire::Client::Layout self)
65 PPCODE: 96 CODE:
97 g_object_unref (self->pl);
98 Safefree (self);
99
100void
101set_markup (Crossfire::Client::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 (Crossfire::Client::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 (Crossfire::Client::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 (Crossfire::Client::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 = Crossfire::Client PACKAGE = Crossfire::Client::Texture
107 163
108void 164void
109texture_quad (SV *self, double x0, double y0, double w, double h) 165draw_quad (SV *self, double x, double y, double w = 0, double h = 0)
166 PROTOTYPE: $$$;$$
110 CODE: 167 CODE:
111{ 168{
112 //glBegin 169 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 ();
113} 187}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines