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.16 by root, Tue Apr 11 13:27:48 2006 UTC vs.
Revision 1.21 by root, Wed Apr 12 18:09:21 2006 UTC

23 PangoLayout *pl; 23 PangoLayout *pl;
24 int base_height; 24 int base_height;
25} *CFClient__Layout; 25} *CFClient__Layout;
26 26
27static void 27static void
28substitute_func (FcPattern *pattern, gpointer data)
29{
30 FcPatternAddBool (pattern, FC_HINTING , 1);
31 FcPatternAddBool (pattern, FC_AUTOHINT, 1);
32}
33
34static void
35layout_update (CFClient__Layout self)
36{
37 /* use a random scale factor to account for unknown descenders, 0.8 works
38 * reasonably well with bitstream vera
39 */
40 PangoFontDescription *font = pango_context_get_font_description (context);
41 pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10));
42}
43
44static void
28layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 45layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
29{ 46{
30 PangoFontDescription *font = pango_context_get_font_description (context); 47 layout_update (self);
31 pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE);
32 48
33 pango_layout_get_pixel_size (self->pl, w, h); 49 pango_layout_get_pixel_size (self->pl, w, h);
34 50
35 *w = (*w + 3) & ~3; 51 *w = (*w + 3) & ~3;
36 if (!*w) *w = 1; 52 if (!*w) *w = 1;
42PROTOTYPES: ENABLE 58PROTOTYPES: ENABLE
43 59
44BOOT: 60BOOT:
45{ 61{
46 fontmap = pango_ft2_font_map_new (); 62 fontmap = pango_ft2_font_map_new ();
63 pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0);
47 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); 64 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap);
48} 65}
49 66
50void 67void
51lowdelay (int fd, int val = 1) 68lowdelay (int fd, int val = 1)
80 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); 97 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
81 FcPatternDestroy (pattern); 98 FcPatternDestroy (pattern);
82 pango_context_set_font_description (context, font); 99 pango_context_set_font_description (context, font);
83} 100}
84 101
102void
103wait_events (SV *rfd_, SV *wfd_)
104 PPCODE:
105{
106}
107
85MODULE = CFClient PACKAGE = CFClient::Layout 108MODULE = CFClient PACKAGE = CFClient::Layout
86 109
87CFClient::Layout 110CFClient::Layout
88new (SV *class, int base_height = 10) 111new (SV *class, int base_height = 10)
89 CODE: 112 CODE:
124size (CFClient::Layout self) 147size (CFClient::Layout self)
125 PPCODE: 148 PPCODE:
126{ 149{
127 int w, h; 150 int w, h;
128 151
152 layout_update (self);
129 layout_get_pixel_size (self, &w, &h); 153 layout_get_pixel_size (self, &w, &h);
130 154
131 EXTEND (SP, 2); 155 EXTEND (SP, 2);
132 PUSHs (sv_2mortal (newSViv (w))); 156 PUSHs (sv_2mortal (newSViv (w)));
133 PUSHs (sv_2mortal (newSViv (h))); 157 PUSHs (sv_2mortal (newSViv (h)));
134} 158}
135 159
160int
161xy_to_index (CFClient::Layout self, int x, int y)
162 CODE:
163{
164 int index, trailing;
165
166 layout_update (self);
167 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
168
169 RETVAL = index;
170}
171 OUTPUT:
172 RETVAL
173
174void
175cursor_pos (CFClient::Layout self, int index)
176 PPCODE:
177{
178 PangoRectangle strong_pos;
179 layout_update (self);
180 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
181 EXTEND (SP, 3);
182 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
183 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
184 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
185}
186
136void 187void
137render (CFClient::Layout self) 188render (CFClient::Layout self)
138 PPCODE: 189 PPCODE:
139{ 190{
140 SV *retval; 191 SV *retval;
141 int w, h; 192 int w, h;
142 FT_Bitmap bitmap; 193 FT_Bitmap bitmap;
143 194
195 layout_update (self);
144 layout_get_pixel_size (self, &w, &h); 196 layout_get_pixel_size (self, &w, &h);
145 197
146 retval = newSV (w * h); 198 retval = newSV (w * h);
147 SvPOK_only (retval); 199 SvPOK_only (retval);
148 SvCUR_set (retval, w * h); 200 SvCUR_set (retval, w * h);
176 double t = SvNV (*hv_fetch (hv, "t", 1, 1)); 228 double t = SvNV (*hv_fetch (hv, "t", 1, 1));
177 int name = SvIV (*hv_fetch (hv, "name", 4, 1)); 229 int name = SvIV (*hv_fetch (hv, "name", 4, 1));
178 230
179 if (items < 5) 231 if (items < 5)
180 { 232 {
181 w = SvNV (*hv_fetch (hv, "width", 5, 1)); 233 w = SvNV (*hv_fetch (hv, "w", 1, 1));
182 h = SvNV (*hv_fetch (hv, "height", 6, 1)); 234 h = SvNV (*hv_fetch (hv, "h", 1, 1));
183 } 235 }
184 236
185 glBindTexture (GL_TEXTURE_2D, name); 237 glBindTexture (GL_TEXTURE_2D, name);
186 glBegin (GL_QUADS); 238 glBegin (GL_QUADS);
187 glTexCoord2d (0, 0); glVertex2d (x , y ); 239 glTexCoord2d (0, 0); glVertex2d (x , y );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines