… | |
… | |
6 | |
6 | |
7 | #include <SDL.h> |
7 | #include <SDL.h> |
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/pangoft2.h> |
12 | #include <pango/pangoft2.h> |
|
|
13 | |
|
|
14 | #include <sys/types.h> |
|
|
15 | #include <sys/socket.h> |
|
|
16 | #include <netinet/in.h> |
|
|
17 | #include <netinet/tcp.h> |
12 | |
18 | |
13 | static PangoContext *context; |
19 | static PangoContext *context; |
14 | static PangoFontMap *fontmap; |
20 | static PangoFontMap *fontmap; |
15 | |
21 | |
|
|
22 | typedef struct cf_layout { |
|
|
23 | PangoLayout *pl; |
|
|
24 | int base_height; |
|
|
25 | } *Crossfire__Client__Layout; |
|
|
26 | |
|
|
27 | static void |
|
|
28 | layout_get_pixel_size (Crossfire__Client__Layout self, int *w, int *h) |
|
|
29 | { |
|
|
30 | pango_layout_get_pixel_size (self->pl, w, h); |
|
|
31 | |
|
|
32 | *w = (*w + 3) & ~3; |
|
|
33 | if (!*w) *w = 1; |
|
|
34 | if (!*h) *h = 1; |
|
|
35 | } |
|
|
36 | |
16 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
37 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
|
|
38 | |
|
|
39 | PROTOTYPES: ENABLE |
17 | |
40 | |
18 | BOOT: |
41 | BOOT: |
19 | { |
42 | { |
20 | fontmap = pango_ft2_font_map_new (); |
43 | fontmap = pango_ft2_font_map_new (); |
21 | context = pango_context_new (); |
44 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
22 | pango_context_set_font_map (context, fontmap); |
|
|
23 | } |
45 | } |
|
|
46 | |
|
|
47 | void |
|
|
48 | lowdelay (int fd, int val = 1) |
|
|
49 | CODE: |
|
|
50 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
24 | |
51 | |
25 | char * |
52 | char * |
26 | gl_version () |
53 | gl_version () |
27 | CODE: |
54 | CODE: |
28 | RETVAL = (char *)glGetString (GL_VERSION); |
55 | RETVAL = (char *)glGetString (GL_VERSION); |
… | |
… | |
35 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
62 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
36 | OUTPUT: |
63 | OUTPUT: |
37 | RETVAL |
64 | RETVAL |
38 | |
65 | |
39 | void |
66 | void |
40 | font_render (SV *text_, int height) |
67 | add_font (char *file) |
41 | PPCODE: |
68 | CODE: |
|
|
69 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
|
|
70 | |
|
|
71 | void |
|
|
72 | set_font (char *file) |
|
|
73 | CODE: |
|
|
74 | { |
|
|
75 | int count; |
|
|
76 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
|
|
77 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
78 | FcPatternDestroy (pattern); |
|
|
79 | pango_context_set_font_description (context, font); |
|
|
80 | } |
|
|
81 | |
|
|
82 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Layout |
|
|
83 | |
|
|
84 | Crossfire::Client::Layout |
|
|
85 | new (SV *class, int base_height = 10) |
|
|
86 | CODE: |
|
|
87 | New (0, RETVAL, 1, struct cf_layout); |
|
|
88 | RETVAL->base_height = base_height; |
|
|
89 | RETVAL->pl = pango_layout_new (context); |
|
|
90 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
|
|
91 | OUTPUT: |
|
|
92 | RETVAL |
|
|
93 | |
|
|
94 | void |
|
|
95 | DESTROY (Crossfire::Client::Layout self) |
|
|
96 | CODE: |
|
|
97 | g_object_unref (self->pl); |
|
|
98 | Safefree (self); |
|
|
99 | |
|
|
100 | void |
|
|
101 | set_markup (Crossfire::Client::Layout self, SV *text_) |
|
|
102 | CODE: |
42 | { |
103 | { |
43 | STRLEN textlen; |
104 | STRLEN textlen; |
44 | char *text = SvPVutf8 (text_, textlen); |
105 | char *text = SvPVutf8 (text_, textlen); |
|
|
106 | |
|
|
107 | pango_layout_set_markup (self->pl, text, textlen); |
|
|
108 | } |
|
|
109 | |
|
|
110 | void |
|
|
111 | set_width (Crossfire::Client::Layout self, int max_width = -1) |
|
|
112 | CODE: |
|
|
113 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
|
|
114 | |
|
|
115 | void |
|
|
116 | size (Crossfire::Client::Layout self) |
|
|
117 | PPCODE: |
|
|
118 | { |
|
|
119 | 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 | |
|
|
124 | layout_get_pixel_size (self, &w, &h); |
|
|
125 | |
|
|
126 | EXTEND (SP, 2); |
|
|
127 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
128 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
129 | } |
|
|
130 | |
|
|
131 | void |
|
|
132 | render (Crossfire::Client::Layout self) |
|
|
133 | PPCODE: |
|
|
134 | { |
45 | SV *retval; |
135 | SV *retval; |
46 | int w, h; |
136 | int w, h; |
47 | FT_Bitmap bitmap; |
137 | FT_Bitmap bitmap; |
48 | PangoLayout *layout; |
|
|
49 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
50 | pango_font_description_set_absolute_size (font, 40 * PANGO_SCALE); |
|
|
51 | |
138 | |
52 | layout = pango_layout_new (context); |
|
|
53 | pango_layout_set_markup (layout, text, textlen); |
|
|
54 | pango_layout_get_pixel_size (layout, &w, &h); |
139 | layout_get_pixel_size (self, &w, &h); |
55 | |
|
|
56 | w = (w + 3) & ~3; |
|
|
57 | if (h == 0) h = 1; |
|
|
58 | |
140 | |
59 | retval = newSV (w * h); |
141 | retval = newSV (w * h); |
60 | SvPOK_only (retval); |
142 | SvPOK_only (retval); |
61 | SvCUR_set (retval, w * h); |
143 | SvCUR_set (retval, w * h); |
62 | |
144 | |
… | |
… | |
67 | bitmap.num_grays = 256; |
149 | bitmap.num_grays = 256; |
68 | bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
150 | bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
69 | |
151 | |
70 | memset (bitmap.buffer, 0, w * h); |
152 | memset (bitmap.buffer, 0, w * h); |
71 | |
153 | |
72 | pango_ft2_render_layout (&bitmap, layout, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
154 | pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
73 | g_object_unref (layout); |
|
|
74 | |
155 | |
75 | EXTEND (SP, 3); |
156 | EXTEND (SP, 3); |
76 | PUSHs (sv_2mortal (newSViv (w))); |
157 | PUSHs (sv_2mortal (newSViv (w))); |
77 | PUSHs (sv_2mortal (newSViv (h))); |
158 | PUSHs (sv_2mortal (newSViv (h))); |
78 | PUSHs (sv_2mortal (retval)); |
159 | PUSHs (sv_2mortal (retval)); |
79 | } |
160 | } |
|
|
161 | |
|
|
162 | MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Texture |
|
|
163 | |
|
|
164 | void |
|
|
165 | draw_quad (SV *self, double x, double y, double w = 0, double h = 0) |
|
|
166 | PROTOTYPE: $$$;$$ |
|
|
167 | CODE: |
|
|
168 | { |
|
|
169 | HV *hv = (HV *)SvRV (self); |
|
|
170 | double s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
|
|
171 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
|
|
172 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
|
|
173 | |
|
|
174 | if (items < 5) |
|
|
175 | { |
|
|
176 | w = SvNV (*hv_fetch (hv, "width", 5, 1)); |
|
|
177 | h = SvNV (*hv_fetch (hv, "height", 6, 1)); |
|
|
178 | } |
|
|
179 | |
|
|
180 | glBindTexture (GL_TEXTURE_2D, name); |
|
|
181 | glBegin (GL_QUADS); |
|
|
182 | glTexCoord2d (0, 0); glVertex2d (x , y ); |
|
|
183 | glTexCoord2d (0, t); glVertex2d (x , y + h); |
|
|
184 | glTexCoord2d (s, t); glVertex2d (x + w, y + h); |
|
|
185 | glTexCoord2d (s, 0); glVertex2d (x + w, y ); |
|
|
186 | glEnd (); |
|
|
187 | } |