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.14 by root, Tue Apr 11 13:05:11 2006 UTC vs.
Revision 1.22 by root, Wed Apr 12 20:06:36 2006 UTC

8#include <SDL_opengl.h> 8#include <SDL_opengl.h>
9 9
10#include <pango/pango.h> 10#include <pango/pango.h>
11#include <pango/pangofc-fontmap.h> 11#include <pango/pangofc-fontmap.h>
12#include <pango/pangoft2.h> 12#include <pango/pangoft2.h>
13
14#include <sys/time.h>
15#include <sys/types.h>
16#include <unistd.h>
13 17
14#include <sys/types.h> 18#include <sys/types.h>
15#include <sys/socket.h> 19#include <sys/socket.h>
16#include <netinet/in.h> 20#include <netinet/in.h>
17#include <netinet/tcp.h> 21#include <netinet/tcp.h>
20static PangoFontMap *fontmap; 24static PangoFontMap *fontmap;
21 25
22typedef struct cf_layout { 26typedef struct cf_layout {
23 PangoLayout *pl; 27 PangoLayout *pl;
24 int base_height; 28 int base_height;
25} *Crossfire__Client__Layout; 29} *CFClient__Layout;
26 30
27static void 31static void
32substitute_func (FcPattern *pattern, gpointer data)
33{
34 FcPatternAddBool (pattern, FC_HINTING , 1);
35 FcPatternAddBool (pattern, FC_AUTOHINT, 1);
36}
37
38static void
39layout_update (CFClient__Layout self)
40{
41 /* use a random scale factor to account for unknown descenders, 0.8 works
42 * reasonably well with bitstream vera
43 */
44 PangoFontDescription *font = pango_context_get_font_description (context);
45 pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10));
46}
47
48static void
28layout_get_pixel_size (Crossfire__Client__Layout self, int *w, int *h) 49layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
29{ 50{
51 layout_update (self);
52
30 pango_layout_get_pixel_size (self->pl, w, h); 53 pango_layout_get_pixel_size (self->pl, w, h);
31 54
32 *w = (*w + 3) & ~3; 55 *w = (*w + 3) & ~3;
33 if (!*w) *w = 1; 56 if (!*w) *w = 1;
34 if (!*h) *h = 1; 57 if (!*h) *h = 1;
35} 58}
36 59
37MODULE = Crossfire::Client PACKAGE = Crossfire::Client 60MODULE = CFClient PACKAGE = CFClient
38 61
39PROTOTYPES: ENABLE 62PROTOTYPES: ENABLE
40 63
41BOOT: 64BOOT:
42{ 65{
43 fontmap = pango_ft2_font_map_new (); 66 fontmap = pango_ft2_font_map_new ();
67 pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0);
44 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); 68 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap);
45} 69}
46 70
47void 71void
48lowdelay (int fd, int val = 1) 72lowdelay (int fd, int val = 1)
77 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); 101 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
78 FcPatternDestroy (pattern); 102 FcPatternDestroy (pattern);
79 pango_context_set_font_description (context, font); 103 pango_context_set_font_description (context, font);
80} 104}
81 105
82MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Layout 106MODULE = CFClient PACKAGE = CFClient::Layout
83 107
84Crossfire::Client::Layout 108CFClient::Layout
85new (SV *class, int base_height = 10) 109new (SV *class, int base_height = 10)
86 CODE: 110 CODE:
87 New (0, RETVAL, 1, struct cf_layout); 111 New (0, RETVAL, 1, struct cf_layout);
88 RETVAL->base_height = base_height; 112 RETVAL->base_height = base_height;
89 RETVAL->pl = pango_layout_new (context); 113 RETVAL->pl = pango_layout_new (context);
90 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 114 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
91 OUTPUT: 115 OUTPUT:
92 RETVAL 116 RETVAL
93 117
94void 118void
95DESTROY (Crossfire::Client::Layout self) 119DESTROY (CFClient::Layout self)
96 CODE: 120 CODE:
97 g_object_unref (self->pl); 121 g_object_unref (self->pl);
98 Safefree (self); 122 Safefree (self);
99 123
100void 124void
101set_markup (Crossfire::Client::Layout self, SV *text_) 125set_markup (CFClient::Layout self, SV *text_)
102 CODE: 126 CODE:
103{ 127{
104 STRLEN textlen; 128 STRLEN textlen;
105 char *text = SvPVutf8 (text_, textlen); 129 char *text = SvPVutf8 (text_, textlen);
106 130
107 pango_layout_set_markup (self->pl, text, textlen); 131 pango_layout_set_markup (self->pl, text, textlen);
108} 132}
109 133
110void 134void
135set_height (CFClient::Layout self, int base_height)
136 CODE:
137 self->base_height = base_height;
138
139void
111set_width (Crossfire::Client::Layout self, int max_width = -1) 140set_width (CFClient::Layout self, int max_width = -1)
112 CODE: 141 CODE:
113 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 142 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
114 143
115void 144void
116size (Crossfire::Client::Layout self) 145size (CFClient::Layout self)
117 PPCODE: 146 PPCODE:
118{ 147{
119 int w, h; 148 int w, h;
120 149
121 PangoFontDescription *font = pango_context_get_font_description (context); 150 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); 151 layout_get_pixel_size (self, &w, &h);
125 152
126 EXTEND (SP, 2); 153 EXTEND (SP, 2);
127 PUSHs (sv_2mortal (newSViv (w))); 154 PUSHs (sv_2mortal (newSViv (w)));
128 PUSHs (sv_2mortal (newSViv (h))); 155 PUSHs (sv_2mortal (newSViv (h)));
129} 156}
130 157
158int
159xy_to_index (CFClient::Layout self, int x, int y)
160 CODE:
161{
162 int index, trailing;
163
164 layout_update (self);
165 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
166
167 RETVAL = index;
168}
169 OUTPUT:
170 RETVAL
171
131void 172void
173cursor_pos (CFClient::Layout self, int index)
174 PPCODE:
175{
176 PangoRectangle strong_pos;
177 layout_update (self);
178 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
179 EXTEND (SP, 3);
180 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
181 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
182 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
183}
184
185void
132render (Crossfire::Client::Layout self) 186render (CFClient::Layout self)
133 PPCODE: 187 PPCODE:
134{ 188{
135 SV *retval; 189 SV *retval;
136 int w, h; 190 int w, h;
137 FT_Bitmap bitmap; 191 FT_Bitmap bitmap;
138 192
193 layout_update (self);
139 layout_get_pixel_size (self, &w, &h); 194 layout_get_pixel_size (self, &w, &h);
140 195
141 retval = newSV (w * h); 196 retval = newSV (w * h);
142 SvPOK_only (retval); 197 SvPOK_only (retval);
143 SvCUR_set (retval, w * h); 198 SvCUR_set (retval, w * h);
157 PUSHs (sv_2mortal (newSViv (w))); 212 PUSHs (sv_2mortal (newSViv (w)));
158 PUSHs (sv_2mortal (newSViv (h))); 213 PUSHs (sv_2mortal (newSViv (h)));
159 PUSHs (sv_2mortal (retval)); 214 PUSHs (sv_2mortal (retval));
160} 215}
161 216
162MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Texture 217MODULE = CFClient PACKAGE = CFClient::Texture
163 218
164void 219void
165draw_quad (SV *self, double x, double y, double w = 0, double h = 0) 220draw_quad (SV *self, double x, double y, double w = 0, double h = 0)
166 PROTOTYPE: $$$;$$ 221 PROTOTYPE: $$$;$$
167 CODE: 222 CODE:
171 double t = SvNV (*hv_fetch (hv, "t", 1, 1)); 226 double t = SvNV (*hv_fetch (hv, "t", 1, 1));
172 int name = SvIV (*hv_fetch (hv, "name", 4, 1)); 227 int name = SvIV (*hv_fetch (hv, "name", 4, 1));
173 228
174 if (items < 5) 229 if (items < 5)
175 { 230 {
176 w = SvNV (*hv_fetch (hv, "width", 5, 1)); 231 w = SvNV (*hv_fetch (hv, "w", 1, 1));
177 h = SvNV (*hv_fetch (hv, "height", 6, 1)); 232 h = SvNV (*hv_fetch (hv, "h", 1, 1));
178 } 233 }
179 234
180 glBindTexture (GL_TEXTURE_2D, name); 235 glBindTexture (GL_TEXTURE_2D, name);
181 glBegin (GL_QUADS); 236 glBegin (GL_QUADS);
182 glTexCoord2d (0, 0); glVertex2d (x , y ); 237 glTexCoord2d (0, 0); glVertex2d (x , y );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines