… | |
… | |
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_get_pixel_size (Crossfire__Client__Layout self, int *w, int *h) |
28 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
29 | { |
29 | { |
|
|
30 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
31 | pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
|
|
32 | |
30 | pango_layout_get_pixel_size (self->pl, w, h); |
33 | pango_layout_get_pixel_size (self->pl, w, h); |
31 | |
34 | |
32 | *w = (*w + 3) & ~3; |
35 | *w = (*w + 3) & ~3; |
33 | if (!*w) *w = 1; |
36 | if (!*w) *w = 1; |
34 | if (!*h) *h = 1; |
37 | if (!*h) *h = 1; |
35 | } |
38 | } |
36 | |
39 | |
37 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
40 | MODULE = CFClient PACKAGE = CFClient |
38 | |
41 | |
39 | PROTOTYPES: ENABLE |
42 | PROTOTYPES: ENABLE |
40 | |
43 | |
41 | BOOT: |
44 | BOOT: |
42 | { |
45 | { |
… | |
… | |
77 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
80 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
78 | FcPatternDestroy (pattern); |
81 | FcPatternDestroy (pattern); |
79 | pango_context_set_font_description (context, font); |
82 | pango_context_set_font_description (context, font); |
80 | } |
83 | } |
81 | |
84 | |
82 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Layout |
85 | MODULE = CFClient PACKAGE = CFClient::Layout |
83 | |
86 | |
84 | Crossfire::Client::Layout |
87 | CFClient::Layout |
85 | new (SV *class, int base_height = 10) |
88 | new (SV *class, int base_height = 10) |
86 | CODE: |
89 | CODE: |
87 | New (0, RETVAL, 1, struct cf_layout); |
90 | New (0, RETVAL, 1, struct cf_layout); |
88 | RETVAL->base_height = base_height; |
91 | RETVAL->base_height = base_height; |
89 | RETVAL->pl = pango_layout_new (context); |
92 | RETVAL->pl = pango_layout_new (context); |
90 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
93 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
91 | OUTPUT: |
94 | OUTPUT: |
92 | RETVAL |
95 | RETVAL |
93 | |
96 | |
94 | void |
97 | void |
95 | DESTROY (Crossfire::Client::Layout self) |
98 | DESTROY (CFClient::Layout self) |
96 | CODE: |
99 | CODE: |
97 | g_object_unref (self->pl); |
100 | g_object_unref (self->pl); |
98 | Safefree (self); |
101 | Safefree (self); |
99 | |
102 | |
100 | void |
103 | void |
101 | set_markup (Crossfire::Client::Layout self, SV *text_) |
104 | set_markup (CFClient::Layout self, SV *text_) |
102 | CODE: |
105 | CODE: |
103 | { |
106 | { |
104 | STRLEN textlen; |
107 | STRLEN textlen; |
105 | char *text = SvPVutf8 (text_, textlen); |
108 | char *text = SvPVutf8 (text_, textlen); |
106 | |
109 | |
107 | pango_layout_set_markup (self->pl, text, textlen); |
110 | pango_layout_set_markup (self->pl, text, textlen); |
108 | } |
111 | } |
109 | |
112 | |
110 | void |
113 | void |
|
|
114 | set_height (CFClient::Layout self, int base_height) |
|
|
115 | CODE: |
|
|
116 | self->base_height = base_height; |
|
|
117 | |
|
|
118 | void |
111 | set_width (Crossfire::Client::Layout self, int max_width = -1) |
119 | set_width (CFClient::Layout self, int max_width = -1) |
112 | CODE: |
120 | CODE: |
113 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
121 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
114 | |
122 | |
115 | void |
123 | void |
116 | size (Crossfire::Client::Layout self) |
124 | size (CFClient::Layout self) |
117 | PPCODE: |
125 | PPCODE: |
118 | { |
126 | { |
119 | int w, h; |
127 | int w, h; |
120 | |
|
|
121 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
122 | pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
|
|
123 | |
128 | |
124 | layout_get_pixel_size (self, &w, &h); |
129 | layout_get_pixel_size (self, &w, &h); |
125 | |
130 | |
126 | EXTEND (SP, 2); |
131 | EXTEND (SP, 2); |
127 | PUSHs (sv_2mortal (newSViv (w))); |
132 | PUSHs (sv_2mortal (newSViv (w))); |
128 | PUSHs (sv_2mortal (newSViv (h))); |
133 | PUSHs (sv_2mortal (newSViv (h))); |
129 | } |
134 | } |
130 | |
135 | |
131 | void |
136 | void |
132 | render (Crossfire::Client::Layout self) |
137 | render (CFClient::Layout self) |
133 | PPCODE: |
138 | PPCODE: |
134 | { |
139 | { |
135 | SV *retval; |
140 | SV *retval; |
136 | int w, h; |
141 | int w, h; |
137 | FT_Bitmap bitmap; |
142 | FT_Bitmap bitmap; |
… | |
… | |
157 | PUSHs (sv_2mortal (newSViv (w))); |
162 | PUSHs (sv_2mortal (newSViv (w))); |
158 | PUSHs (sv_2mortal (newSViv (h))); |
163 | PUSHs (sv_2mortal (newSViv (h))); |
159 | PUSHs (sv_2mortal (retval)); |
164 | PUSHs (sv_2mortal (retval)); |
160 | } |
165 | } |
161 | |
166 | |
162 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Texture |
167 | MODULE = CFClient PACKAGE = CFClient::Texture |
163 | |
168 | |
164 | void |
169 | void |
165 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
170 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
166 | PROTOTYPE: $$$;$$ |
171 | PROTOTYPE: $$$;$$ |
167 | CODE: |
172 | CODE: |