… | |
… | |
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 | layout_update (CFClient__Layout self) |
|
|
29 | { |
|
|
30 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
31 | pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
|
|
32 | } |
|
|
33 | |
|
|
34 | static void |
28 | layout_get_pixel_size (Crossfire__Client__Layout self, int *w, int *h) |
35 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
29 | { |
36 | { |
|
|
37 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
38 | pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
|
|
39 | |
30 | pango_layout_get_pixel_size (self->pl, w, h); |
40 | pango_layout_get_pixel_size (self->pl, w, h); |
31 | |
41 | |
32 | *w = (*w + 3) & ~3; |
42 | *w = (*w + 3) & ~3; |
33 | if (!*w) *w = 1; |
43 | if (!*w) *w = 1; |
34 | if (!*h) *h = 1; |
44 | if (!*h) *h = 1; |
35 | } |
45 | } |
36 | |
46 | |
37 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
47 | MODULE = CFClient PACKAGE = CFClient |
38 | |
48 | |
39 | PROTOTYPES: ENABLE |
49 | PROTOTYPES: ENABLE |
40 | |
50 | |
41 | BOOT: |
51 | BOOT: |
42 | { |
52 | { |
… | |
… | |
77 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
87 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
78 | FcPatternDestroy (pattern); |
88 | FcPatternDestroy (pattern); |
79 | pango_context_set_font_description (context, font); |
89 | pango_context_set_font_description (context, font); |
80 | } |
90 | } |
81 | |
91 | |
82 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Layout |
92 | MODULE = CFClient PACKAGE = CFClient::Layout |
83 | |
93 | |
84 | Crossfire::Client::Layout |
94 | CFClient::Layout |
85 | new (SV *class, int base_height = 10) |
95 | new (SV *class, int base_height = 10) |
86 | CODE: |
96 | CODE: |
87 | New (0, RETVAL, 1, struct cf_layout); |
97 | New (0, RETVAL, 1, struct cf_layout); |
88 | RETVAL->base_height = base_height; |
98 | RETVAL->base_height = base_height; |
89 | RETVAL->pl = pango_layout_new (context); |
99 | RETVAL->pl = pango_layout_new (context); |
90 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
100 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
91 | OUTPUT: |
101 | OUTPUT: |
92 | RETVAL |
102 | RETVAL |
93 | |
103 | |
94 | void |
104 | void |
95 | DESTROY (Crossfire::Client::Layout self) |
105 | DESTROY (CFClient::Layout self) |
96 | CODE: |
106 | CODE: |
97 | g_object_unref (self->pl); |
107 | g_object_unref (self->pl); |
98 | Safefree (self); |
108 | Safefree (self); |
99 | |
109 | |
100 | void |
110 | void |
101 | set_markup (Crossfire::Client::Layout self, SV *text_) |
111 | set_markup (CFClient::Layout self, SV *text_) |
102 | CODE: |
112 | CODE: |
103 | { |
113 | { |
104 | STRLEN textlen; |
114 | STRLEN textlen; |
105 | char *text = SvPVutf8 (text_, textlen); |
115 | char *text = SvPVutf8 (text_, textlen); |
106 | |
116 | |
107 | pango_layout_set_markup (self->pl, text, textlen); |
117 | pango_layout_set_markup (self->pl, text, textlen); |
108 | } |
118 | } |
109 | |
119 | |
110 | void |
120 | void |
|
|
121 | set_height (CFClient::Layout self, int base_height) |
|
|
122 | CODE: |
|
|
123 | self->base_height = base_height; |
|
|
124 | |
|
|
125 | void |
111 | set_width (Crossfire::Client::Layout self, int max_width = -1) |
126 | set_width (CFClient::Layout self, int max_width = -1) |
112 | CODE: |
127 | CODE: |
113 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
128 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
114 | |
129 | |
115 | void |
130 | void |
116 | size (Crossfire::Client::Layout self) |
131 | size (CFClient::Layout self) |
117 | PPCODE: |
132 | PPCODE: |
118 | { |
133 | { |
119 | int w, h; |
134 | int w, h; |
120 | |
135 | |
121 | PangoFontDescription *font = pango_context_get_font_description (context); |
136 | 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); |
137 | layout_get_pixel_size (self, &w, &h); |
125 | |
138 | |
126 | EXTEND (SP, 2); |
139 | EXTEND (SP, 2); |
127 | PUSHs (sv_2mortal (newSViv (w))); |
140 | PUSHs (sv_2mortal (newSViv (w))); |
128 | PUSHs (sv_2mortal (newSViv (h))); |
141 | PUSHs (sv_2mortal (newSViv (h))); |
129 | } |
142 | } |
130 | |
143 | |
|
|
144 | int |
|
|
145 | xy_to_index (CFClient::Layout self, int x, int y) |
|
|
146 | CODE: |
|
|
147 | { |
|
|
148 | int index, trailing; |
|
|
149 | |
|
|
150 | layout_update (self); |
|
|
151 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
|
|
152 | |
|
|
153 | RETVAL = index; |
|
|
154 | } |
|
|
155 | OUTPUT: |
|
|
156 | RETVAL |
|
|
157 | |
131 | void |
158 | void |
|
|
159 | cursor_pos (CFClient::Layout self, int index) |
|
|
160 | PPCODE: |
|
|
161 | { |
|
|
162 | PangoRectangle strong_pos; |
|
|
163 | layout_update (self); |
|
|
164 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
|
|
165 | EXTEND (SP, 3); |
|
|
166 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
|
|
167 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
|
|
168 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
|
|
169 | } |
|
|
170 | |
|
|
171 | void |
132 | render (Crossfire::Client::Layout self) |
172 | render (CFClient::Layout self) |
133 | PPCODE: |
173 | PPCODE: |
134 | { |
174 | { |
135 | SV *retval; |
175 | SV *retval; |
136 | int w, h; |
176 | int w, h; |
137 | FT_Bitmap bitmap; |
177 | FT_Bitmap bitmap; |
138 | |
178 | |
|
|
179 | layout_update (self); |
139 | layout_get_pixel_size (self, &w, &h); |
180 | layout_get_pixel_size (self, &w, &h); |
140 | |
181 | |
141 | retval = newSV (w * h); |
182 | retval = newSV (w * h); |
142 | SvPOK_only (retval); |
183 | SvPOK_only (retval); |
143 | SvCUR_set (retval, w * h); |
184 | SvCUR_set (retval, w * h); |
… | |
… | |
157 | PUSHs (sv_2mortal (newSViv (w))); |
198 | PUSHs (sv_2mortal (newSViv (w))); |
158 | PUSHs (sv_2mortal (newSViv (h))); |
199 | PUSHs (sv_2mortal (newSViv (h))); |
159 | PUSHs (sv_2mortal (retval)); |
200 | PUSHs (sv_2mortal (retval)); |
160 | } |
201 | } |
161 | |
202 | |
162 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Texture |
203 | MODULE = CFClient PACKAGE = CFClient::Texture |
163 | |
204 | |
164 | void |
205 | void |
165 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
206 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
166 | PROTOTYPE: $$$;$$ |
207 | PROTOTYPE: $$$;$$ |
167 | CODE: |
208 | CODE: |