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.15 by root, Tue Apr 11 13:14:36 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{
47 layout_update (self);
48
30 pango_layout_get_pixel_size (self->pl, w, h); 49 pango_layout_get_pixel_size (self->pl, w, h);
31 50
32 *w = (*w + 3) & ~3; 51 *w = (*w + 3) & ~3;
33 if (!*w) *w = 1; 52 if (!*w) *w = 1;
34 if (!*h) *h = 1; 53 if (!*h) *h = 1;
39PROTOTYPES: ENABLE 58PROTOTYPES: ENABLE
40 59
41BOOT: 60BOOT:
42{ 61{
43 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);
44 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); 64 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap);
45} 65}
46 66
47void 67void
48lowdelay (int fd, int val = 1) 68lowdelay (int fd, int val = 1)
77 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); 97 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
78 FcPatternDestroy (pattern); 98 FcPatternDestroy (pattern);
79 pango_context_set_font_description (context, font); 99 pango_context_set_font_description (context, font);
80} 100}
81 101
102void
103wait_events (SV *rfd_, SV *wfd_)
104 PPCODE:
105{
106}
107
82MODULE = CFClient PACKAGE = CFClient::Layout 108MODULE = CFClient PACKAGE = CFClient::Layout
83 109
84CFClient::Layout 110CFClient::Layout
85new (SV *class, int base_height = 10) 111new (SV *class, int base_height = 10)
86 CODE: 112 CODE:
106 132
107 pango_layout_set_markup (self->pl, text, textlen); 133 pango_layout_set_markup (self->pl, text, textlen);
108} 134}
109 135
110void 136void
137set_height (CFClient::Layout self, int base_height)
138 CODE:
139 self->base_height = base_height;
140
141void
111set_width (CFClient::Layout self, int max_width = -1) 142set_width (CFClient::Layout self, int max_width = -1)
112 CODE: 143 CODE:
113 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 144 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
114 145
115void 146void
116size (CFClient::Layout self) 147size (CFClient::Layout self)
117 PPCODE: 148 PPCODE:
118{ 149{
119 int w, h; 150 int w, h;
120 151
121 PangoFontDescription *font = pango_context_get_font_description (context); 152 layout_update (self);
122 pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE);
123
124 layout_get_pixel_size (self, &w, &h); 153 layout_get_pixel_size (self, &w, &h);
125 154
126 EXTEND (SP, 2); 155 EXTEND (SP, 2);
127 PUSHs (sv_2mortal (newSViv (w))); 156 PUSHs (sv_2mortal (newSViv (w)));
128 PUSHs (sv_2mortal (newSViv (h))); 157 PUSHs (sv_2mortal (newSViv (h)));
129} 158}
130 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
131void 187void
132render (CFClient::Layout self) 188render (CFClient::Layout self)
133 PPCODE: 189 PPCODE:
134{ 190{
135 SV *retval; 191 SV *retval;
136 int w, h; 192 int w, h;
137 FT_Bitmap bitmap; 193 FT_Bitmap bitmap;
138 194
195 layout_update (self);
139 layout_get_pixel_size (self, &w, &h); 196 layout_get_pixel_size (self, &w, &h);
140 197
141 retval = newSV (w * h); 198 retval = newSV (w * h);
142 SvPOK_only (retval); 199 SvPOK_only (retval);
143 SvCUR_set (retval, w * h); 200 SvCUR_set (retval, w * h);
171 double t = SvNV (*hv_fetch (hv, "t", 1, 1)); 228 double t = SvNV (*hv_fetch (hv, "t", 1, 1));
172 int name = SvIV (*hv_fetch (hv, "name", 4, 1)); 229 int name = SvIV (*hv_fetch (hv, "name", 4, 1));
173 230
174 if (items < 5) 231 if (items < 5)
175 { 232 {
176 w = SvNV (*hv_fetch (hv, "width", 5, 1)); 233 w = SvNV (*hv_fetch (hv, "w", 1, 1));
177 h = SvNV (*hv_fetch (hv, "height", 6, 1)); 234 h = SvNV (*hv_fetch (hv, "h", 1, 1));
178 } 235 }
179 236
180 glBindTexture (GL_TEXTURE_2D, name); 237 glBindTexture (GL_TEXTURE_2D, name);
181 glBegin (GL_QUADS); 238 glBegin (GL_QUADS);
182 glTexCoord2d (0, 0); glVertex2d (x , y ); 239 glTexCoord2d (0, 0); glVertex2d (x , y );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines