… | |
… | |
20 | static PangoFontMap *fontmap; |
20 | static PangoFontMap *fontmap; |
21 | |
21 | |
22 | typedef struct cf_layout { |
22 | typedef struct cf_layout { |
23 | PangoLayout *pl; |
23 | PangoLayout *pl; |
24 | int base_height; |
24 | int base_height; |
25 | } *Crossfire__Client__Layout; |
25 | } *CFClient__Layout; |
26 | |
26 | |
27 | static void |
27 | static void |
|
|
28 | substitute_func (FcPattern *pattern, gpointer data) |
|
|
29 | { |
|
|
30 | //FcPatternAddBool (pattern, FC_HINTING, 1); |
|
|
31 | //FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
|
|
32 | } |
|
|
33 | |
|
|
34 | static void |
|
|
35 | layout_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 | |
|
|
44 | static void |
28 | layout_get_pixel_size (Crossfire__Client__Layout self, int *w, int *h) |
45 | layout_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; |
35 | } |
54 | } |
36 | |
55 | |
37 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
56 | MODULE = CFClient PACKAGE = CFClient |
38 | |
57 | |
39 | PROTOTYPES: ENABLE |
58 | PROTOTYPES: ENABLE |
40 | |
59 | |
41 | BOOT: |
60 | BOOT: |
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 | |
47 | void |
67 | void |
48 | lowdelay (int fd, int val = 1) |
68 | lowdelay (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 | |
82 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Layout |
102 | MODULE = CFClient PACKAGE = CFClient::Layout |
83 | |
103 | |
84 | Crossfire::Client::Layout |
104 | CFClient::Layout |
85 | new (SV *class, int base_height = 10) |
105 | new (SV *class, int base_height = 10) |
86 | CODE: |
106 | CODE: |
87 | New (0, RETVAL, 1, struct cf_layout); |
107 | New (0, RETVAL, 1, struct cf_layout); |
88 | RETVAL->base_height = base_height; |
108 | RETVAL->base_height = base_height; |
89 | RETVAL->pl = pango_layout_new (context); |
109 | RETVAL->pl = pango_layout_new (context); |
90 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
110 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
91 | OUTPUT: |
111 | OUTPUT: |
92 | RETVAL |
112 | RETVAL |
93 | |
113 | |
94 | void |
114 | void |
95 | DESTROY (Crossfire::Client::Layout self) |
115 | DESTROY (CFClient::Layout self) |
96 | CODE: |
116 | CODE: |
97 | g_object_unref (self->pl); |
117 | g_object_unref (self->pl); |
98 | Safefree (self); |
118 | Safefree (self); |
99 | |
119 | |
100 | void |
120 | void |
101 | set_markup (Crossfire::Client::Layout self, SV *text_) |
121 | set_markup (CFClient::Layout self, SV *text_) |
102 | CODE: |
122 | CODE: |
103 | { |
123 | { |
104 | STRLEN textlen; |
124 | STRLEN textlen; |
105 | char *text = SvPVutf8 (text_, textlen); |
125 | char *text = SvPVutf8 (text_, textlen); |
106 | |
126 | |
107 | pango_layout_set_markup (self->pl, text, textlen); |
127 | pango_layout_set_markup (self->pl, text, textlen); |
108 | } |
128 | } |
109 | |
129 | |
110 | void |
130 | void |
|
|
131 | set_height (CFClient::Layout self, int base_height) |
|
|
132 | CODE: |
|
|
133 | self->base_height = base_height; |
|
|
134 | |
|
|
135 | void |
111 | set_width (Crossfire::Client::Layout self, int max_width = -1) |
136 | set_width (CFClient::Layout self, int max_width = -1) |
112 | CODE: |
137 | CODE: |
113 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
138 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
114 | |
139 | |
115 | void |
140 | void |
116 | size (Crossfire::Client::Layout self) |
141 | size (CFClient::Layout self) |
117 | PPCODE: |
142 | PPCODE: |
118 | { |
143 | { |
119 | int w, h; |
144 | int w, h; |
120 | |
145 | |
121 | PangoFontDescription *font = pango_context_get_font_description (context); |
146 | 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); |
147 | layout_get_pixel_size (self, &w, &h); |
125 | |
148 | |
126 | EXTEND (SP, 2); |
149 | EXTEND (SP, 2); |
127 | PUSHs (sv_2mortal (newSViv (w))); |
150 | PUSHs (sv_2mortal (newSViv (w))); |
128 | PUSHs (sv_2mortal (newSViv (h))); |
151 | PUSHs (sv_2mortal (newSViv (h))); |
129 | } |
152 | } |
130 | |
153 | |
|
|
154 | int |
|
|
155 | xy_to_index (CFClient::Layout self, int x, int y) |
|
|
156 | CODE: |
|
|
157 | { |
|
|
158 | int index, trailing; |
|
|
159 | |
|
|
160 | layout_update (self); |
|
|
161 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
|
|
162 | |
|
|
163 | RETVAL = index; |
|
|
164 | } |
|
|
165 | OUTPUT: |
|
|
166 | RETVAL |
|
|
167 | |
131 | void |
168 | void |
|
|
169 | cursor_pos (CFClient::Layout self, int index) |
|
|
170 | PPCODE: |
|
|
171 | { |
|
|
172 | PangoRectangle strong_pos; |
|
|
173 | layout_update (self); |
|
|
174 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
|
|
175 | EXTEND (SP, 3); |
|
|
176 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
|
|
177 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
|
|
178 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
|
|
179 | } |
|
|
180 | |
|
|
181 | void |
132 | render (Crossfire::Client::Layout self) |
182 | render (CFClient::Layout self) |
133 | PPCODE: |
183 | PPCODE: |
134 | { |
184 | { |
135 | SV *retval; |
185 | SV *retval; |
136 | int w, h; |
186 | int w, h; |
137 | FT_Bitmap bitmap; |
187 | FT_Bitmap bitmap; |
138 | |
188 | |
|
|
189 | layout_update (self); |
139 | layout_get_pixel_size (self, &w, &h); |
190 | layout_get_pixel_size (self, &w, &h); |
140 | |
191 | |
141 | retval = newSV (w * h); |
192 | retval = newSV (w * h); |
142 | SvPOK_only (retval); |
193 | SvPOK_only (retval); |
143 | SvCUR_set (retval, w * h); |
194 | SvCUR_set (retval, w * h); |
… | |
… | |
157 | PUSHs (sv_2mortal (newSViv (w))); |
208 | PUSHs (sv_2mortal (newSViv (w))); |
158 | PUSHs (sv_2mortal (newSViv (h))); |
209 | PUSHs (sv_2mortal (newSViv (h))); |
159 | PUSHs (sv_2mortal (retval)); |
210 | PUSHs (sv_2mortal (retval)); |
160 | } |
211 | } |
161 | |
212 | |
162 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Texture |
213 | MODULE = CFClient PACKAGE = CFClient::Texture |
163 | |
214 | |
164 | void |
215 | void |
165 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
216 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
166 | PROTOTYPE: $$$;$$ |
217 | PROTOTYPE: $$$;$$ |
167 | CODE: |
218 | CODE: |
… | |
… | |
171 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
222 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
172 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
223 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
173 | |
224 | |
174 | if (items < 5) |
225 | if (items < 5) |
175 | { |
226 | { |
176 | w = SvNV (*hv_fetch (hv, "width", 5, 1)); |
227 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
177 | h = SvNV (*hv_fetch (hv, "height", 6, 1)); |
228 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
178 | } |
229 | } |
179 | |
230 | |
180 | glBindTexture (GL_TEXTURE_2D, name); |
231 | glBindTexture (GL_TEXTURE_2D, name); |
181 | glBegin (GL_QUADS); |
232 | glBegin (GL_QUADS); |
182 | glTexCoord2d (0, 0); glVertex2d (x , y ); |
233 | glTexCoord2d (0, 0); glVertex2d (x , y ); |