… | |
… | |
46 | |
46 | |
47 | #include <glib/gmacros.h> |
47 | #include <glib/gmacros.h> |
48 | |
48 | |
49 | #include <pango/pango.h> |
49 | #include <pango/pango.h> |
50 | |
50 | |
|
|
51 | #ifndef PANGO_VERSION_CHECK |
|
|
52 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
|
|
53 | #endif |
|
|
54 | |
|
|
55 | #if !PANGO_VERSION_CHECK (1, 15, 2) |
|
|
56 | # define pango_layout_get_line_readonly pango_layout_get_line |
|
|
57 | # define pango_layout_get_lines_readonly pango_layout_get_lines |
|
|
58 | # define pango_layout_iter_get_line_readonly pango_layout_iter_get_line |
|
|
59 | # define pango_layout_iter_get_run_readonly pango_layout_iter_get_run |
|
|
60 | #endif |
|
|
61 | |
51 | #ifndef _WIN32 |
62 | #ifndef _WIN32 |
52 | # include <sys/types.h> |
63 | # include <sys/types.h> |
53 | # include <sys/socket.h> |
64 | # include <sys/socket.h> |
54 | # include <netinet/in.h> |
65 | # include <netinet/in.h> |
55 | # include <netinet/tcp.h> |
66 | # include <netinet/tcp.h> |
… | |
… | |
63 | #define MAP_EXTEND_X 32 |
74 | #define MAP_EXTEND_X 32 |
64 | #define MAP_EXTEND_Y 512 |
75 | #define MAP_EXTEND_Y 512 |
65 | |
76 | |
66 | #define MIN_FONT_HEIGHT 10 |
77 | #define MIN_FONT_HEIGHT 10 |
67 | |
78 | |
|
|
79 | /* mask out modifiers we are not interested in */ |
|
|
80 | #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) |
|
|
81 | |
68 | #if 0 |
82 | #if 0 |
69 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
83 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
70 | #else |
84 | #else |
71 | # define PARACHUTE 0 |
85 | # define PARACHUTE 0 |
72 | #endif |
86 | #endif |
… | |
… | |
120 | |
134 | |
121 | #include "pango-font.c" |
135 | #include "pango-font.c" |
122 | #include "pango-fontmap.c" |
136 | #include "pango-fontmap.c" |
123 | #include "pango-render.c" |
137 | #include "pango-render.c" |
124 | |
138 | |
125 | typedef IV dc__Channel; |
139 | typedef IV DC__Channel; |
126 | typedef SDL_RWops *dc__RW; |
140 | typedef SDL_RWops *DC__RW; |
127 | typedef Mix_Chunk *dc__MixChunk; |
141 | typedef Mix_Chunk *DC__MixChunk; |
128 | typedef Mix_Music *dc__MixMusic; |
142 | typedef Mix_Music *DC__MixMusic; |
129 | |
143 | |
130 | typedef PangoFontDescription *dc__Font; |
144 | typedef PangoFontDescription *DC__Font; |
131 | |
145 | |
132 | static int |
146 | static int |
133 | shape_attr_p (PangoLayoutRun *run) |
147 | shape_attr_p (PangoLayoutRun *run) |
134 | { |
148 | { |
135 | GSList *attrs = run->item->analysis.extra_attrs; |
149 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
149 | |
163 | |
150 | typedef struct cf_layout { |
164 | typedef struct cf_layout { |
151 | PangoLayout *pl; |
165 | PangoLayout *pl; |
152 | float r, g, b, a; // default color for rgba mode |
166 | float r, g, b, a; // default color for rgba mode |
153 | int base_height; |
167 | int base_height; |
154 | dc__Font font; |
168 | DC__Font font; |
155 | rc_t *rc; |
169 | rc_t *rc; |
156 | } *dc__Layout; |
170 | } *DC__Layout; |
157 | |
171 | |
158 | static dc__Font default_font; |
172 | static DC__Font default_font; |
159 | static PangoContext *opengl_context; |
173 | static PangoContext *opengl_context; |
160 | static PangoFontMap *opengl_fontmap; |
174 | static PangoFontMap *opengl_fontmap; |
161 | |
175 | |
162 | static void |
176 | static void |
163 | substitute_func (FcPattern *pattern, gpointer data) |
177 | substitute_func (FcPattern *pattern, gpointer data) |
… | |
… | |
168 | #endif |
182 | #endif |
169 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
183 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
170 | } |
184 | } |
171 | |
185 | |
172 | static void |
186 | static void |
173 | layout_update_font (dc__Layout self) |
187 | layout_update_font (DC__Layout self) |
174 | { |
188 | { |
175 | /* use a random scale factor to account for unknown descenders, 0.8 works |
189 | /* use a random scale factor to account for unknown descenders, 0.8 works |
176 | * reasonably well with bitstream vera |
190 | * reasonably well with bitstream vera |
177 | */ |
191 | */ |
178 | PangoFontDescription *font = self->font ? self->font : default_font; |
192 | PangoFontDescription *font = self->font ? self->font : default_font; |
… | |
… | |
182 | |
196 | |
183 | pango_layout_set_font_description (self->pl, font); |
197 | pango_layout_set_font_description (self->pl, font); |
184 | } |
198 | } |
185 | |
199 | |
186 | static void |
200 | static void |
187 | layout_get_pixel_size (dc__Layout self, int *w, int *h) |
201 | layout_get_pixel_size (DC__Layout self, int *w, int *h) |
188 | { |
202 | { |
189 | PangoRectangle rect; |
203 | PangoRectangle rect; |
190 | |
204 | |
191 | // get_pixel_* wrongly rounds down |
205 | // get_pixel_* wrongly rounds down |
192 | pango_layout_get_extents (self->pl, 0, &rect); |
206 | pango_layout_get_extents (self->pl, 0, &rect); |
… | |
… | |
231 | int faces; tileid *face2tile; // [faceid] |
245 | int faces; tileid *face2tile; // [faceid] |
232 | int texs; maptex *tex; // [tileid] |
246 | int texs; maptex *tex; // [tileid] |
233 | |
247 | |
234 | int32_t rows; |
248 | int32_t rows; |
235 | maprow *row; |
249 | maprow *row; |
236 | } *dc__Map; |
250 | } *DC__Map; |
237 | |
251 | |
238 | static char * |
252 | static char * |
239 | prepend (char *ptr, int sze, int inc) |
253 | prepend (char *ptr, int sze, int inc) |
240 | { |
254 | { |
241 | char *p; |
255 | char *p; |
… | |
… | |
279 | self->texs *= 2; |
293 | self->texs *= 2; |
280 | } |
294 | } |
281 | } |
295 | } |
282 | |
296 | |
283 | static maprow * |
297 | static maprow * |
284 | map_get_row (dc__Map self, int y) |
298 | map_get_row (DC__Map self, int y) |
285 | { |
299 | { |
286 | if (0 > y) |
300 | if (0 > y) |
287 | { |
301 | { |
288 | int extend = - y + MAP_EXTEND_Y; |
302 | int extend = - y + MAP_EXTEND_Y; |
289 | Prepend (maprow, self->row, self->rows, extend); |
303 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
327 | |
341 | |
328 | return row->col + (x - row->c0); |
342 | return row->col + (x - row->c0); |
329 | } |
343 | } |
330 | |
344 | |
331 | static mapcell * |
345 | static mapcell * |
332 | map_get_cell (dc__Map self, int x, int y) |
346 | map_get_cell (DC__Map self, int x, int y) |
333 | { |
347 | { |
334 | return row_get_cell (map_get_row (self, y), x); |
348 | return row_get_cell (map_get_row (self, y), x); |
335 | } |
349 | } |
336 | |
350 | |
337 | static void |
351 | static void |
338 | map_clear (dc__Map self) |
352 | map_clear (DC__Map self) |
339 | { |
353 | { |
340 | int r; |
354 | int r; |
341 | |
355 | |
342 | for (r = 0; r < self->rows; r++) |
356 | for (r = 0; r < self->rows; r++) |
343 | Safefree (self->row[r].col); |
357 | Safefree (self->row[r].col); |
… | |
… | |
351 | self->row = 0; |
365 | self->row = 0; |
352 | self->rows = 0; |
366 | self->rows = 0; |
353 | } |
367 | } |
354 | |
368 | |
355 | static void |
369 | static void |
356 | map_blank (dc__Map self, int x0, int y0, int w, int h) |
370 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
357 | { |
371 | { |
358 | int x, y; |
372 | int x, y; |
359 | maprow *row; |
373 | maprow *row; |
360 | mapcell *cell; |
374 | mapcell *cell; |
361 | |
375 | |
… | |
… | |
498 | return 0; |
512 | return 0; |
499 | |
513 | |
500 | return 1; |
514 | return 1; |
501 | } |
515 | } |
502 | |
516 | |
503 | MODULE = Deliantra::Client PACKAGE = dc |
517 | MODULE = Deliantra::Client PACKAGE = DC |
504 | |
518 | |
505 | PROTOTYPES: ENABLE |
519 | PROTOTYPES: ENABLE |
506 | |
520 | |
507 | BOOT: |
521 | BOOT: |
508 | { |
522 | { |
509 | HV *stash = gv_stashpv ("dc", 1); |
523 | HV *stash = gv_stashpv ("DC", 1); |
510 | static const struct { |
524 | static const struct { |
511 | const char *name; |
525 | const char *name; |
512 | IV iv; |
526 | IV iv; |
513 | } *civ, const_iv[] = { |
527 | } *civ, const_iv[] = { |
514 | # define const_iv(name) { # name, (IV)name } |
528 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
659 | CODE: |
673 | CODE: |
660 | { |
674 | { |
661 | opengl_fontmap = pango_opengl_font_map_new (); |
675 | opengl_fontmap = pango_opengl_font_map_new (); |
662 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
676 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
663 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
677 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
|
|
678 | #if PANGO_VERSION_CHECK (1, 15, 2) |
|
|
679 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
|
|
680 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
|
|
681 | #endif |
664 | } |
682 | } |
665 | |
683 | |
666 | char * |
684 | char * |
667 | SDL_GetError () |
685 | SDL_GetError () |
668 | |
686 | |
… | |
… | |
700 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
718 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
701 | |
719 | |
702 | if (m && m != (SDL_Rect **)-1) |
720 | if (m && m != (SDL_Rect **)-1) |
703 | while (*m) |
721 | while (*m) |
704 | { |
722 | { |
705 | if ((*m)->w >= 800 && (*m)->h >= 600) |
723 | if ((*m)->w >= 800 && (*m)->h >= 480) |
706 | { |
724 | { |
707 | AV *av = newAV (); |
725 | AV *av = newAV (); |
708 | av_push (av, newSViv ((*m)->w)); |
726 | av_push (av, newSViv ((*m)->w)); |
709 | av_push (av, newSViv ((*m)->h)); |
727 | av_push (av, newSViv ((*m)->h)); |
710 | av_push (av, newSViv (rgb)); |
728 | av_push (av, newSViv (rgb)); |
… | |
… | |
752 | SDL_GetKeyName (int sym) |
770 | SDL_GetKeyName (int sym) |
753 | |
771 | |
754 | int |
772 | int |
755 | SDL_GetAppState () |
773 | SDL_GetAppState () |
756 | |
774 | |
|
|
775 | int |
|
|
776 | SDL_GetModState () |
|
|
777 | |
757 | void |
778 | void |
758 | poll_events () |
779 | poll_events () |
759 | PPCODE: |
780 | PPCODE: |
760 | { |
781 | { |
761 | SDL_Event ev; |
782 | SDL_Event ev; |
… | |
… | |
770 | { |
791 | { |
771 | case SDL_KEYDOWN: |
792 | case SDL_KEYDOWN: |
772 | case SDL_KEYUP: |
793 | case SDL_KEYUP: |
773 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
794 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
774 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
795 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
775 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); |
796 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0); |
776 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ |
797 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */ |
777 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
798 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
778 | break; |
799 | break; |
779 | |
800 | |
780 | case SDL_ACTIVEEVENT: |
801 | case SDL_ACTIVEEVENT: |
781 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
802 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
799 | x = ev.motion.x; |
820 | x = ev.motion.x; |
800 | y = ev.motion.y; |
821 | y = ev.motion.y; |
801 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
822 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
802 | } |
823 | } |
803 | |
824 | |
804 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
825 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
805 | hv_store (hv, "state", 5, newSViv (state), 0); |
826 | hv_store (hv, "state", 5, newSViv (state), 0); |
806 | hv_store (hv, "x", 1, newSViv (x), 0); |
827 | hv_store (hv, "x", 1, newSViv (x), 0); |
807 | hv_store (hv, "y", 1, newSViv (y), 0); |
828 | hv_store (hv, "y", 1, newSViv (y), 0); |
808 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
829 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
809 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
830 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
810 | } |
831 | } |
811 | break; |
832 | break; |
812 | |
833 | |
813 | case SDL_MOUSEBUTTONDOWN: |
834 | case SDL_MOUSEBUTTONDOWN: |
814 | case SDL_MOUSEBUTTONUP: |
835 | case SDL_MOUSEBUTTONUP: |
815 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
836 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
816 | |
837 | |
817 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
838 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
818 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
839 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
819 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
840 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
820 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
841 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
… | |
… | |
825 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
846 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
826 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
847 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
827 | break; |
848 | break; |
828 | } |
849 | } |
829 | |
850 | |
830 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("dc::UI::Event", 1)))); |
851 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
831 | } |
852 | } |
832 | } |
853 | } |
833 | |
854 | |
834 | int |
855 | int |
835 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
856 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
… | |
… | |
1023 | #if DEBUG |
1044 | #if DEBUG |
1024 | VALGRIND_DO_LEAK_CHECK; |
1045 | VALGRIND_DO_LEAK_CHECK; |
1025 | #endif |
1046 | #endif |
1026 | } |
1047 | } |
1027 | |
1048 | |
1028 | MODULE = Deliantra::Client PACKAGE = dc::Font |
1049 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1029 | |
1050 | |
1030 | PROTOTYPES: DISABLE |
1051 | PROTOTYPES: DISABLE |
1031 | |
1052 | |
1032 | dc::Font |
1053 | DC::Font |
1033 | new_from_file (SV *class, char *path, int id = 0) |
1054 | new_from_file (SV *class, char *path, int id = 0) |
1034 | CODE: |
1055 | CODE: |
1035 | { |
1056 | { |
1036 | int count; |
1057 | int count; |
1037 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1058 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
1040 | } |
1061 | } |
1041 | OUTPUT: |
1062 | OUTPUT: |
1042 | RETVAL |
1063 | RETVAL |
1043 | |
1064 | |
1044 | void |
1065 | void |
1045 | DESTROY (dc::Font self) |
1066 | DESTROY (DC::Font self) |
1046 | CODE: |
1067 | CODE: |
1047 | pango_font_description_free (self); |
1068 | pango_font_description_free (self); |
1048 | |
1069 | |
1049 | void |
1070 | void |
1050 | make_default (dc::Font self) |
1071 | make_default (DC::Font self) |
1051 | PROTOTYPE: $ |
1072 | PROTOTYPE: $ |
1052 | CODE: |
1073 | CODE: |
1053 | default_font = self; |
1074 | default_font = self; |
1054 | |
1075 | |
1055 | MODULE = Deliantra::Client PACKAGE = dc::Layout |
1076 | MODULE = Deliantra::Client PACKAGE = DC::Layout |
1056 | |
1077 | |
1057 | PROTOTYPES: DISABLE |
1078 | PROTOTYPES: DISABLE |
1058 | |
1079 | |
1059 | void |
1080 | void |
1060 | glyph_cache_backup () |
1081 | glyph_cache_backup () |
… | |
… | |
1066 | glyph_cache_restore () |
1087 | glyph_cache_restore () |
1067 | PROTOTYPE: |
1088 | PROTOTYPE: |
1068 | CODE: |
1089 | CODE: |
1069 | tc_restore (); |
1090 | tc_restore (); |
1070 | |
1091 | |
1071 | dc::Layout |
1092 | DC::Layout |
1072 | new (SV *class) |
1093 | new (SV *class) |
1073 | CODE: |
1094 | CODE: |
1074 | New (0, RETVAL, 1, struct cf_layout); |
1095 | New (0, RETVAL, 1, struct cf_layout); |
1075 | |
1096 | |
1076 | RETVAL->pl = pango_layout_new (opengl_context); |
1097 | RETVAL->pl = pango_layout_new (opengl_context); |
… | |
… | |
1086 | layout_update_font (RETVAL); |
1107 | layout_update_font (RETVAL); |
1087 | OUTPUT: |
1108 | OUTPUT: |
1088 | RETVAL |
1109 | RETVAL |
1089 | |
1110 | |
1090 | void |
1111 | void |
1091 | DESTROY (dc::Layout self) |
1112 | DESTROY (DC::Layout self) |
1092 | CODE: |
1113 | CODE: |
1093 | g_object_unref (self->pl); |
1114 | g_object_unref (self->pl); |
1094 | rc_free (self->rc); |
1115 | rc_free (self->rc); |
1095 | Safefree (self); |
1116 | Safefree (self); |
1096 | |
1117 | |
1097 | void |
1118 | void |
1098 | set_text (dc::Layout self, SV *text_) |
1119 | set_text (DC::Layout self, SV *text_) |
1099 | CODE: |
1120 | CODE: |
1100 | { |
1121 | { |
1101 | STRLEN textlen; |
1122 | STRLEN textlen; |
1102 | char *text = SvPVutf8 (text_, textlen); |
1123 | char *text = SvPVutf8 (text_, textlen); |
1103 | |
1124 | |
1104 | pango_layout_set_text (self->pl, text, textlen); |
1125 | pango_layout_set_text (self->pl, text, textlen); |
1105 | } |
1126 | } |
1106 | |
1127 | |
1107 | void |
1128 | void |
1108 | set_markup (dc::Layout self, SV *text_) |
1129 | set_markup (DC::Layout self, SV *text_) |
1109 | CODE: |
1130 | CODE: |
1110 | { |
1131 | { |
1111 | STRLEN textlen; |
1132 | STRLEN textlen; |
1112 | char *text = SvPVutf8 (text_, textlen); |
1133 | char *text = SvPVutf8 (text_, textlen); |
1113 | |
1134 | |
1114 | pango_layout_set_markup (self->pl, text, textlen); |
1135 | pango_layout_set_markup (self->pl, text, textlen); |
1115 | } |
1136 | } |
1116 | |
1137 | |
1117 | void |
1138 | void |
1118 | set_shapes (dc::Layout self, ...) |
1139 | set_shapes (DC::Layout self, ...) |
1119 | CODE: |
1140 | CODE: |
1120 | { |
1141 | { |
1121 | PangoAttrList *attrs = 0; |
1142 | PangoAttrList *attrs = 0; |
1122 | const char *text = pango_layout_get_text (self->pl); |
1143 | const char *text = pango_layout_get_text (self->pl); |
1123 | const char *pos = text; |
1144 | const char *pos = text; |
… | |
… | |
1158 | if (attrs) |
1179 | if (attrs) |
1159 | pango_layout_set_attributes (self->pl, attrs); |
1180 | pango_layout_set_attributes (self->pl, attrs); |
1160 | } |
1181 | } |
1161 | |
1182 | |
1162 | void |
1183 | void |
1163 | get_shapes (dc::Layout self) |
1184 | get_shapes (DC::Layout self) |
1164 | PPCODE: |
1185 | PPCODE: |
1165 | { |
1186 | { |
1166 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1187 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1167 | |
1188 | |
1168 | do |
1189 | do |
1169 | { |
1190 | { |
1170 | PangoLayoutRun *run = pango_layout_iter_get_run (iter); |
1191 | PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter); |
1171 | |
1192 | |
1172 | if (run && shape_attr_p (run)) |
1193 | if (run && shape_attr_p (run)) |
1173 | { |
1194 | { |
1174 | PangoRectangle extents; |
1195 | PangoRectangle extents; |
1175 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
1196 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
… | |
… | |
1183 | |
1204 | |
1184 | pango_layout_iter_free (iter); |
1205 | pango_layout_iter_free (iter); |
1185 | } |
1206 | } |
1186 | |
1207 | |
1187 | int |
1208 | int |
1188 | has_wrapped (dc::Layout self) |
1209 | has_wrapped (DC::Layout self) |
1189 | CODE: |
1210 | CODE: |
1190 | { |
1211 | { |
1191 | int lines = 1; |
1212 | int lines = 1; |
1192 | const char *text = pango_layout_get_text (self->pl); |
1213 | const char *text = pango_layout_get_text (self->pl); |
1193 | |
1214 | |
… | |
… | |
1198 | } |
1219 | } |
1199 | OUTPUT: |
1220 | OUTPUT: |
1200 | RETVAL |
1221 | RETVAL |
1201 | |
1222 | |
1202 | SV * |
1223 | SV * |
1203 | get_text (dc::Layout self) |
1224 | get_text (DC::Layout self) |
1204 | CODE: |
1225 | CODE: |
1205 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1226 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1206 | sv_utf8_decode (RETVAL); |
1227 | sv_utf8_decode (RETVAL); |
1207 | OUTPUT: |
1228 | OUTPUT: |
1208 | RETVAL |
1229 | RETVAL |
1209 | |
1230 | |
1210 | void |
1231 | void |
1211 | set_foreground (dc::Layout self, float r, float g, float b, float a = 1.) |
1232 | set_foreground (DC::Layout self, float r, float g, float b, float a = 1.) |
1212 | CODE: |
1233 | CODE: |
1213 | self->r = r; |
1234 | self->r = r; |
1214 | self->g = g; |
1235 | self->g = g; |
1215 | self->b = b; |
1236 | self->b = b; |
1216 | self->a = a; |
1237 | self->a = a; |
1217 | |
1238 | |
1218 | void |
1239 | void |
1219 | set_font (dc::Layout self, dc::Font font = 0) |
1240 | set_font (DC::Layout self, DC::Font font = 0) |
1220 | CODE: |
1241 | CODE: |
1221 | if (self->font != font) |
1242 | if (self->font != font) |
1222 | { |
1243 | { |
1223 | self->font = font; |
1244 | self->font = font; |
1224 | layout_update_font (self); |
1245 | layout_update_font (self); |
1225 | } |
1246 | } |
1226 | |
1247 | |
1227 | void |
1248 | void |
1228 | set_height (dc::Layout self, int base_height) |
1249 | set_height (DC::Layout self, int base_height) |
1229 | CODE: |
1250 | CODE: |
1230 | if (self->base_height != base_height) |
1251 | if (self->base_height != base_height) |
1231 | { |
1252 | { |
1232 | self->base_height = base_height; |
1253 | self->base_height = base_height; |
1233 | layout_update_font (self); |
1254 | layout_update_font (self); |
1234 | } |
1255 | } |
1235 | |
1256 | |
1236 | void |
1257 | void |
1237 | set_width (dc::Layout self, int max_width = -1) |
1258 | set_width (DC::Layout self, int max_width = -1) |
1238 | CODE: |
1259 | CODE: |
1239 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1260 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1240 | |
1261 | |
1241 | void |
1262 | void |
1242 | set_indent (dc::Layout self, int indent) |
1263 | set_indent (DC::Layout self, int indent) |
1243 | CODE: |
1264 | CODE: |
1244 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1265 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1245 | |
1266 | |
1246 | void |
1267 | void |
1247 | set_spacing (dc::Layout self, int spacing) |
1268 | set_spacing (DC::Layout self, int spacing) |
1248 | CODE: |
1269 | CODE: |
1249 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1270 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1250 | |
1271 | |
1251 | void |
1272 | void |
1252 | set_ellipsise (dc::Layout self, int ellipsise) |
1273 | set_ellipsise (DC::Layout self, int ellipsise) |
1253 | CODE: |
1274 | CODE: |
1254 | pango_layout_set_ellipsize (self->pl, |
1275 | pango_layout_set_ellipsize (self->pl, |
1255 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1276 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1256 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1277 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1257 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1278 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1258 | : PANGO_ELLIPSIZE_NONE |
1279 | : PANGO_ELLIPSIZE_NONE |
1259 | ); |
1280 | ); |
1260 | |
1281 | |
1261 | void |
1282 | void |
1262 | set_single_paragraph_mode (dc::Layout self, int spm) |
1283 | set_single_paragraph_mode (DC::Layout self, int spm) |
1263 | CODE: |
1284 | CODE: |
1264 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1285 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1265 | |
1286 | |
1266 | void |
1287 | void |
1267 | size (dc::Layout self) |
1288 | size (DC::Layout self) |
1268 | PPCODE: |
1289 | PPCODE: |
1269 | { |
1290 | { |
1270 | int w, h; |
1291 | int w, h; |
1271 | |
1292 | |
1272 | layout_get_pixel_size (self, &w, &h); |
1293 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
1275 | PUSHs (sv_2mortal (newSViv (w))); |
1296 | PUSHs (sv_2mortal (newSViv (w))); |
1276 | PUSHs (sv_2mortal (newSViv (h))); |
1297 | PUSHs (sv_2mortal (newSViv (h))); |
1277 | } |
1298 | } |
1278 | |
1299 | |
1279 | int |
1300 | int |
1280 | descent (dc::Layout self) |
1301 | descent (DC::Layout self) |
1281 | CODE: |
1302 | CODE: |
1282 | { |
1303 | { |
1283 | PangoRectangle rect; |
1304 | PangoRectangle rect; |
1284 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1305 | PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0); |
1285 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1306 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1286 | RETVAL = PANGO_DESCENT (rect); |
1307 | RETVAL = PANGO_DESCENT (rect); |
1287 | } |
1308 | } |
1288 | OUTPUT: |
1309 | OUTPUT: |
1289 | RETVAL |
1310 | RETVAL |
1290 | |
1311 | |
1291 | int |
1312 | int |
1292 | xy_to_index (dc::Layout self, int x, int y) |
1313 | xy_to_index (DC::Layout self, int x, int y) |
1293 | CODE: |
1314 | CODE: |
1294 | { |
1315 | { |
1295 | int index, trailing; |
1316 | int index, trailing; |
1296 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1317 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1297 | RETVAL = index + trailing; |
1318 | RETVAL = index + trailing; |
1298 | } |
1319 | } |
1299 | OUTPUT: |
1320 | OUTPUT: |
1300 | RETVAL |
1321 | RETVAL |
1301 | |
1322 | |
1302 | void |
1323 | void |
1303 | cursor_pos (dc::Layout self, int index) |
1324 | cursor_pos (DC::Layout self, int index) |
1304 | PPCODE: |
1325 | PPCODE: |
1305 | { |
1326 | { |
1306 | PangoRectangle strong_pos; |
1327 | PangoRectangle pos; |
1307 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1328 | pango_layout_get_cursor_pos (self->pl, index, &pos, 0); |
1308 | |
1329 | |
1309 | EXTEND (SP, 3); |
1330 | EXTEND (SP, 3); |
1310 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1331 | PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE))); |
1311 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1332 | PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE))); |
1312 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1333 | PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE))); |
1313 | } |
1334 | } |
1314 | |
1335 | |
1315 | void |
1336 | void |
1316 | index_to_line_x (dc::Layout self, int index, int trailing = 0) |
1337 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1317 | PPCODE: |
1338 | PPCODE: |
1318 | { |
1339 | { |
1319 | int line, x; |
1340 | int line, x; |
1320 | |
1341 | |
1321 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1342 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1343 | #if !PANGO_VERSION_CHECK (1, 17, 3) |
1322 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1344 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1323 | |
1345 | --line; |
|
|
1346 | #endif |
1324 | EXTEND (SP, 2); |
1347 | EXTEND (SP, 2); |
1325 | PUSHs (sv_2mortal (newSViv (line - 1))); |
1348 | PUSHs (sv_2mortal (newSViv (line))); |
1326 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1349 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1327 | } |
1350 | } |
1328 | |
1351 | |
1329 | void |
1352 | void |
1330 | line_x_to_index (dc::Layout self, int line, int x) |
1353 | line_x_to_index (DC::Layout self, int line, int x) |
1331 | PPCODE: |
1354 | PPCODE: |
1332 | { |
1355 | { |
1333 | PangoLayoutLine *lp; |
1356 | PangoLayoutLine *lp; |
1334 | int index, trailing; |
1357 | int index, trailing; |
1335 | |
1358 | |
1336 | if (line < 0) |
1359 | if (line < 0) |
1337 | XSRETURN_EMPTY; |
1360 | XSRETURN_EMPTY; |
1338 | |
1361 | |
1339 | if (!(lp = pango_layout_get_line (self->pl, line))) |
1362 | if (!(lp = pango_layout_get_line_readonly (self->pl, line))) |
1340 | XSRETURN_EMPTY; /* do better */ |
1363 | XSRETURN_EMPTY; /* do better */ |
1341 | |
1364 | |
1342 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1365 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1343 | |
1366 | |
1344 | EXTEND (SP, 2); |
1367 | EXTEND (SP, 2); |
… | |
… | |
1350 | PUSHs (sv_2mortal (newSViv (trailing))); |
1373 | PUSHs (sv_2mortal (newSViv (trailing))); |
1351 | } |
1374 | } |
1352 | } |
1375 | } |
1353 | |
1376 | |
1354 | void |
1377 | void |
1355 | render (dc::Layout self, float x, float y, int flags = 0) |
1378 | render (DC::Layout self, float x, float y, int flags = 0) |
1356 | CODE: |
1379 | CODE: |
1357 | rc_clear (self->rc); |
1380 | rc_clear (self->rc); |
1358 | pango_opengl_render_layout_subpixel ( |
1381 | pango_opengl_render_layout_subpixel ( |
1359 | self->pl, |
1382 | self->pl, |
1360 | self->rc, |
1383 | self->rc, |
… | |
… | |
1365 | // we assume that context_change actually clears/frees stuff |
1388 | // we assume that context_change actually clears/frees stuff |
1366 | // and does not do any recomputation... |
1389 | // and does not do any recomputation... |
1367 | pango_layout_context_changed (self->pl); |
1390 | pango_layout_context_changed (self->pl); |
1368 | |
1391 | |
1369 | void |
1392 | void |
1370 | draw (dc::Layout self) |
1393 | draw (DC::Layout self) |
1371 | CODE: |
1394 | CODE: |
1372 | { |
1395 | { |
1373 | glEnable (GL_TEXTURE_2D); |
1396 | glEnable (GL_TEXTURE_2D); |
1374 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
1397 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
1375 | glEnable (GL_BLEND); |
1398 | glEnable (GL_BLEND); |
… | |
… | |
1383 | glDisable (GL_ALPHA_TEST); |
1406 | glDisable (GL_ALPHA_TEST); |
1384 | glDisable (GL_BLEND); |
1407 | glDisable (GL_BLEND); |
1385 | glDisable (GL_TEXTURE_2D); |
1408 | glDisable (GL_TEXTURE_2D); |
1386 | } |
1409 | } |
1387 | |
1410 | |
1388 | MODULE = Deliantra::Client PACKAGE = dc::Texture |
1411 | MODULE = Deliantra::Client PACKAGE = DC::Texture |
1389 | |
1412 | |
1390 | PROTOTYPES: ENABLE |
1413 | PROTOTYPES: ENABLE |
1391 | |
1414 | |
1392 | void |
1415 | void |
1393 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1416 | pad (SV *data_, int ow, int oh, int nw, int nh) |
… | |
… | |
1472 | RETVAL = width > 0; |
1495 | RETVAL = width > 0; |
1473 | } |
1496 | } |
1474 | OUTPUT: |
1497 | OUTPUT: |
1475 | RETVAL |
1498 | RETVAL |
1476 | |
1499 | |
1477 | MODULE = Deliantra::Client PACKAGE = dc::Map |
1500 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1478 | |
1501 | |
1479 | PROTOTYPES: DISABLE |
1502 | PROTOTYPES: DISABLE |
1480 | |
1503 | |
1481 | dc::Map |
1504 | DC::Map |
1482 | new (SV *class) |
1505 | new (SV *class) |
1483 | CODE: |
1506 | CODE: |
1484 | New (0, RETVAL, 1, struct map); |
1507 | New (0, RETVAL, 1, struct map); |
1485 | RETVAL->x = 0; |
1508 | RETVAL->x = 0; |
1486 | RETVAL->y = 0; |
1509 | RETVAL->y = 0; |
… | |
… | |
1494 | RETVAL->row = 0; |
1517 | RETVAL->row = 0; |
1495 | OUTPUT: |
1518 | OUTPUT: |
1496 | RETVAL |
1519 | RETVAL |
1497 | |
1520 | |
1498 | void |
1521 | void |
1499 | DESTROY (dc::Map self) |
1522 | DESTROY (DC::Map self) |
1500 | CODE: |
1523 | CODE: |
1501 | { |
1524 | { |
1502 | map_clear (self); |
1525 | map_clear (self); |
1503 | Safefree (self->face2tile); |
1526 | Safefree (self->face2tile); |
1504 | Safefree (self->tex); |
1527 | Safefree (self->tex); |
1505 | Safefree (self); |
1528 | Safefree (self); |
1506 | } |
1529 | } |
1507 | |
1530 | |
1508 | void |
1531 | void |
1509 | resize (dc::Map self, int map_width, int map_height) |
1532 | resize (DC::Map self, int map_width, int map_height) |
1510 | CODE: |
1533 | CODE: |
1511 | self->w = map_width; |
1534 | self->w = map_width; |
1512 | self->h = map_height; |
1535 | self->h = map_height; |
1513 | |
1536 | |
1514 | void |
1537 | void |
1515 | clear (dc::Map self) |
1538 | clear (DC::Map self) |
1516 | CODE: |
1539 | CODE: |
1517 | map_clear (self); |
1540 | map_clear (self); |
1518 | |
1541 | |
1519 | void |
1542 | void |
1520 | set_tileid (dc::Map self, int face, int tile) |
1543 | set_tileid (DC::Map self, int face, int tile) |
1521 | CODE: |
1544 | CODE: |
1522 | { |
1545 | { |
1523 | need_facenum (self, face); self->face2tile [face] = tile; |
1546 | need_facenum (self, face); self->face2tile [face] = tile; |
1524 | need_texid (self, tile); |
1547 | need_texid (self, tile); |
1525 | } |
1548 | } |
1526 | |
1549 | |
1527 | void |
1550 | void |
1528 | set_smooth (dc::Map self, int face, int smooth, int level) |
1551 | set_smooth (DC::Map self, int face, int smooth, int level) |
1529 | CODE: |
1552 | CODE: |
1530 | { |
1553 | { |
1531 | tileid texid; |
1554 | tileid texid; |
1532 | maptex *tex; |
1555 | maptex *tex; |
1533 | |
1556 | |
… | |
… | |
1546 | tex->smoothtile = self->face2tile [smooth]; |
1569 | tex->smoothtile = self->face2tile [smooth]; |
1547 | tex->smoothlevel = level; |
1570 | tex->smoothlevel = level; |
1548 | } |
1571 | } |
1549 | |
1572 | |
1550 | void |
1573 | void |
1551 | set_texture (dc::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
1574 | set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
1552 | CODE: |
1575 | CODE: |
1553 | { |
1576 | { |
1554 | need_texid (self, texid); |
1577 | need_texid (self, texid); |
1555 | |
1578 | |
1556 | { |
1579 | { |
… | |
… | |
1576 | // from transparent color bleeding and ugly wrapping effects. |
1599 | // from transparent color bleeding and ugly wrapping effects. |
1577 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1600 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1578 | } |
1601 | } |
1579 | |
1602 | |
1580 | int |
1603 | int |
1581 | ox (dc::Map self) |
1604 | ox (DC::Map self) |
1582 | ALIAS: |
1605 | ALIAS: |
1583 | oy = 1 |
1606 | oy = 1 |
1584 | x = 2 |
1607 | x = 2 |
1585 | y = 3 |
1608 | y = 3 |
1586 | w = 4 |
1609 | w = 4 |
… | |
… | |
1597 | } |
1620 | } |
1598 | OUTPUT: |
1621 | OUTPUT: |
1599 | RETVAL |
1622 | RETVAL |
1600 | |
1623 | |
1601 | void |
1624 | void |
1602 | scroll (dc::Map self, int dx, int dy) |
1625 | scroll (DC::Map self, int dx, int dy) |
1603 | CODE: |
1626 | CODE: |
1604 | { |
1627 | { |
1605 | if (dx > 0) |
1628 | if (dx > 0) |
1606 | map_blank (self, self->x, self->y, dx, self->h); |
1629 | map_blank (self, self->x, self->y, dx, self->h); |
1607 | else if (dx < 0) |
1630 | else if (dx < 0) |
… | |
… | |
1623 | self->y += MAP_EXTEND_Y; |
1646 | self->y += MAP_EXTEND_Y; |
1624 | } |
1647 | } |
1625 | } |
1648 | } |
1626 | |
1649 | |
1627 | SV * |
1650 | SV * |
1628 | map1a_update (dc::Map self, SV *data_, int extmap) |
1651 | map1a_update (DC::Map self, SV *data_, int extmap) |
1629 | CODE: |
1652 | CODE: |
1630 | { |
1653 | { |
1631 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1654 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1632 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1655 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1633 | mapcell *cell; |
1656 | mapcell *cell; |
… | |
… | |
1722 | } |
1745 | } |
1723 | OUTPUT: |
1746 | OUTPUT: |
1724 | RETVAL |
1747 | RETVAL |
1725 | |
1748 | |
1726 | SV * |
1749 | SV * |
1727 | mapmap (dc::Map self, int x0, int y0, int w, int h) |
1750 | mapmap (DC::Map self, int x0, int y0, int w, int h) |
1728 | CODE: |
1751 | CODE: |
1729 | { |
1752 | { |
1730 | int x1, x; |
1753 | int x1, x; |
1731 | int y1, y; |
1754 | int y1, y; |
1732 | int z; |
1755 | int z; |
… | |
… | |
1777 | } |
1800 | } |
1778 | OUTPUT: |
1801 | OUTPUT: |
1779 | RETVAL |
1802 | RETVAL |
1780 | |
1803 | |
1781 | void |
1804 | void |
1782 | draw (dc::Map self, int mx, int my, int sw, int sh, int T) |
1805 | draw (DC::Map self, int mx, int my, int sw, int sh, int T) |
1783 | CODE: |
1806 | CODE: |
1784 | { |
1807 | { |
1785 | int x, y, z; |
1808 | int x, y, z; |
1786 | |
1809 | |
1787 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1810 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
… | |
… | |
2058 | } |
2081 | } |
2059 | } |
2082 | } |
2060 | } |
2083 | } |
2061 | |
2084 | |
2062 | void |
2085 | void |
2063 | draw_magicmap (dc::Map self, int dx, int dy, int w, int h, unsigned char *data) |
2086 | draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data) |
2064 | CODE: |
2087 | CODE: |
2065 | { |
2088 | { |
2066 | static float color[16][3] = { |
2089 | static float color[16][3] = { |
2067 | { 0.00F, 0.00F, 0.00F }, |
2090 | { 0.00F, 0.00F, 0.00F }, |
2068 | { 1.00F, 1.00F, 1.00F }, |
2091 | { 1.00F, 1.00F, 1.00F }, |
… | |
… | |
2118 | glDisable (GL_BLEND); |
2141 | glDisable (GL_BLEND); |
2119 | glDisable (GL_TEXTURE_2D); |
2142 | glDisable (GL_TEXTURE_2D); |
2120 | } |
2143 | } |
2121 | |
2144 | |
2122 | void |
2145 | void |
2123 | fow_texture (dc::Map self, int mx, int my, int sw, int sh) |
2146 | fow_texture (DC::Map self, int mx, int my, int sw, int sh) |
2124 | PPCODE: |
2147 | PPCODE: |
2125 | { |
2148 | { |
2126 | int x, y; |
2149 | int x, y; |
2127 | int sw1 = sw + 2; |
2150 | int sw1 = sw + 2; |
2128 | int sh1 = sh + 2; |
2151 | int sh1 = sh + 2; |
… | |
… | |
2199 | PUSHs (sv_2mortal (newSViv (sh3))); |
2222 | PUSHs (sv_2mortal (newSViv (sh3))); |
2200 | PUSHs (darkness3_sv); |
2223 | PUSHs (darkness3_sv); |
2201 | } |
2224 | } |
2202 | |
2225 | |
2203 | SV * |
2226 | SV * |
2204 | get_rect (dc::Map self, int x0, int y0, int w, int h) |
2227 | get_rect (DC::Map self, int x0, int y0, int w, int h) |
2205 | CODE: |
2228 | CODE: |
2206 | { |
2229 | { |
2207 | int x, y, x1, y1; |
2230 | int x, y, x1, y1; |
2208 | SV *data_sv = newSV (w * h * 7 + 5); |
2231 | SV *data_sv = newSV (w * h * 7 + 5); |
2209 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
2232 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
2274 | } |
2297 | } |
2275 | OUTPUT: |
2298 | OUTPUT: |
2276 | RETVAL |
2299 | RETVAL |
2277 | |
2300 | |
2278 | void |
2301 | void |
2279 | set_rect (dc::Map self, int x0, int y0, uint8_t *data) |
2302 | set_rect (DC::Map self, int x0, int y0, uint8_t *data) |
2280 | PPCODE: |
2303 | PPCODE: |
2281 | { |
2304 | { |
2282 | int x, y, z; |
2305 | int x, y, z; |
2283 | int w, h; |
2306 | int w, h; |
2284 | int x1, y1; |
2307 | int x1, y1; |
… | |
… | |
2337 | } |
2360 | } |
2338 | } |
2361 | } |
2339 | } |
2362 | } |
2340 | } |
2363 | } |
2341 | |
2364 | |
2342 | MODULE = Deliantra::Client PACKAGE = dc::RW |
2365 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2343 | |
2366 | |
2344 | dc::RW |
2367 | DC::RW |
2345 | new (SV *class, SV *data_sv) |
2368 | new (SV *class, SV *data_sv) |
2346 | CODE: |
2369 | CODE: |
2347 | { |
2370 | { |
2348 | STRLEN datalen; |
2371 | STRLEN datalen; |
2349 | char *data = SvPVbyte (data_sv, datalen); |
2372 | char *data = SvPVbyte (data_sv, datalen); |
… | |
… | |
2351 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2374 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2352 | } |
2375 | } |
2353 | OUTPUT: |
2376 | OUTPUT: |
2354 | RETVAL |
2377 | RETVAL |
2355 | |
2378 | |
2356 | dc::RW |
2379 | DC::RW |
2357 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2380 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2358 | CODE: |
2381 | CODE: |
2359 | RETVAL = SDL_RWFromFile (path, mode); |
2382 | RETVAL = SDL_RWFromFile (path, mode); |
2360 | OUTPUT: |
2383 | OUTPUT: |
2361 | RETVAL |
2384 | RETVAL |
2362 | |
2385 | |
2363 | # fails on win32: |
2386 | # fails on win32: |
2364 | # dc.xs(2268) : error C2059: syntax error : '(' |
2387 | # dc.xs(2268) : error C2059: syntax error : '(' |
2365 | #void |
2388 | #void |
2366 | #close (dc::RW self) |
2389 | #close (DC::RW self) |
2367 | # CODE: |
2390 | # CODE: |
2368 | # (self->(close)) (self); |
2391 | # (self->(close)) (self); |
2369 | |
2392 | |
2370 | MODULE = Deliantra::Client PACKAGE = dc::Channel |
2393 | MODULE = Deliantra::Client PACKAGE = DC::Channel |
2371 | |
2394 | |
2372 | PROTOTYPES: DISABLE |
2395 | PROTOTYPES: DISABLE |
2373 | |
2396 | |
2374 | dc::Channel |
2397 | DC::Channel |
2375 | find () |
2398 | find () |
2376 | CODE: |
2399 | CODE: |
2377 | { |
2400 | { |
2378 | RETVAL = Mix_GroupAvailable (-1); |
2401 | RETVAL = Mix_GroupAvailable (-1); |
2379 | |
2402 | |
… | |
… | |
2392 | } |
2415 | } |
2393 | OUTPUT: |
2416 | OUTPUT: |
2394 | RETVAL |
2417 | RETVAL |
2395 | |
2418 | |
2396 | void |
2419 | void |
2397 | halt (dc::Channel self) |
2420 | halt (DC::Channel self) |
2398 | CODE: |
2421 | CODE: |
2399 | Mix_HaltChannel (self); |
2422 | Mix_HaltChannel (self); |
2400 | |
2423 | |
2401 | void |
2424 | void |
2402 | expire (dc::Channel self, int ticks = -1) |
2425 | expire (DC::Channel self, int ticks = -1) |
2403 | CODE: |
2426 | CODE: |
2404 | Mix_ExpireChannel (self, ticks); |
2427 | Mix_ExpireChannel (self, ticks); |
2405 | |
2428 | |
2406 | void |
2429 | void |
2407 | fade_out (dc::Channel self, int ticks = -1) |
2430 | fade_out (DC::Channel self, int ticks = -1) |
2408 | CODE: |
2431 | CODE: |
2409 | Mix_FadeOutChannel (self, ticks); |
2432 | Mix_FadeOutChannel (self, ticks); |
2410 | |
2433 | |
2411 | int |
2434 | int |
2412 | volume (dc::Channel self, int volume) |
2435 | volume (DC::Channel self, int volume) |
2413 | CODE: |
2436 | CODE: |
2414 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2437 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2415 | OUTPUT: |
2438 | OUTPUT: |
2416 | RETVAL |
2439 | RETVAL |
2417 | |
2440 | |
2418 | void |
2441 | void |
2419 | unregister_all_effects (dc::Channel self) |
2442 | unregister_all_effects (DC::Channel self) |
2420 | CODE: |
2443 | CODE: |
2421 | Mix_UnregisterAllEffects (self); |
2444 | Mix_UnregisterAllEffects (self); |
2422 | |
2445 | |
2423 | void |
2446 | void |
2424 | set_panning (dc::Channel self, int left, int right) |
2447 | set_panning (DC::Channel self, int left, int right) |
2425 | CODE: |
2448 | CODE: |
2426 | left = CLAMP (left , 0, 255); |
2449 | left = CLAMP (left , 0, 255); |
2427 | right = CLAMP (right, 0, 255); |
2450 | right = CLAMP (right, 0, 255); |
2428 | Mix_SetPanning (self, left, right); |
2451 | Mix_SetPanning (self, left, right); |
2429 | |
2452 | |
2430 | void |
2453 | void |
2431 | set_distance (dc::Channel self, int distance) |
2454 | set_distance (DC::Channel self, int distance) |
2432 | CODE: |
2455 | CODE: |
2433 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2456 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2434 | |
2457 | |
2435 | void |
2458 | void |
2436 | set_position (dc::Channel self, int angle, int distance) |
2459 | set_position (DC::Channel self, int angle, int distance) |
2437 | CODE: |
2460 | CODE: |
2438 | |
2461 | |
2439 | void |
2462 | void |
2440 | set_position_r (dc::Channel self, int dx, int dy, int maxdistance) |
2463 | set_position_r (DC::Channel self, int dx, int dy, int maxdistance) |
2441 | CODE: |
2464 | CODE: |
2442 | { |
2465 | { |
2443 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
2466 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
2444 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
2467 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
2445 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2468 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2446 | } |
2469 | } |
2447 | |
2470 | |
2448 | void |
2471 | void |
2449 | set_reverse_stereo (dc::Channel self, int flip) |
2472 | set_reverse_stereo (DC::Channel self, int flip) |
2450 | CODE: |
2473 | CODE: |
2451 | Mix_SetReverseStereo (self, flip); |
2474 | Mix_SetReverseStereo (self, flip); |
2452 | |
2475 | |
2453 | MODULE = Deliantra::Client PACKAGE = dc::MixChunk |
2476 | MODULE = Deliantra::Client PACKAGE = DC::MixChunk |
2454 | |
2477 | |
2455 | PROTOTYPES: DISABLE |
2478 | PROTOTYPES: DISABLE |
2456 | |
2479 | |
2457 | dc::MixChunk |
2480 | DC::MixChunk |
2458 | new (SV *class, dc::RW rwops) |
2481 | new (SV *class, DC::RW rwops) |
2459 | CODE: |
2482 | CODE: |
2460 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2483 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2461 | OUTPUT: |
2484 | OUTPUT: |
2462 | RETVAL |
2485 | RETVAL |
2463 | |
2486 | |
2464 | void |
2487 | void |
2465 | DESTROY (dc::MixChunk self) |
2488 | DESTROY (DC::MixChunk self) |
2466 | CODE: |
2489 | CODE: |
2467 | Mix_FreeChunk (self); |
2490 | Mix_FreeChunk (self); |
2468 | |
2491 | |
2469 | int |
2492 | int |
2470 | volume (dc::MixChunk self, int volume = -1) |
2493 | volume (DC::MixChunk self, int volume = -1) |
2471 | CODE: |
2494 | CODE: |
2472 | if (items > 1) |
2495 | if (items > 1) |
2473 | volume = CLAMP (volume, 0, 128); |
2496 | volume = CLAMP (volume, 0, 128); |
2474 | RETVAL = Mix_VolumeChunk (self, volume); |
2497 | RETVAL = Mix_VolumeChunk (self, volume); |
2475 | OUTPUT: |
2498 | OUTPUT: |
2476 | RETVAL |
2499 | RETVAL |
2477 | |
2500 | |
2478 | dc::Channel |
2501 | DC::Channel |
2479 | play (dc::MixChunk self, dc::Channel channel = -1, int loops = 0, int ticks = -1) |
2502 | play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1) |
2480 | CODE: |
2503 | CODE: |
2481 | { |
2504 | { |
2482 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2505 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2483 | |
2506 | |
2484 | if (RETVAL < 0) |
2507 | if (RETVAL < 0) |
… | |
… | |
2491 | } |
2514 | } |
2492 | } |
2515 | } |
2493 | OUTPUT: |
2516 | OUTPUT: |
2494 | RETVAL |
2517 | RETVAL |
2495 | |
2518 | |
2496 | MODULE = Deliantra::Client PACKAGE = dc::MixMusic |
2519 | MODULE = Deliantra::Client PACKAGE = DC::MixMusic |
2497 | |
2520 | |
2498 | int |
2521 | int |
2499 | volume (int volume = -1) |
2522 | volume (int volume = -1) |
2500 | PROTOTYPE: ;$ |
2523 | PROTOTYPE: ;$ |
2501 | CODE: |
2524 | CODE: |
… | |
… | |
2513 | void |
2536 | void |
2514 | halt () |
2537 | halt () |
2515 | CODE: |
2538 | CODE: |
2516 | Mix_HaltMusic (); |
2539 | Mix_HaltMusic (); |
2517 | |
2540 | |
2518 | dc::MixMusic |
2541 | DC::MixMusic |
2519 | new (SV *class, dc::RW rwops) |
2542 | new (SV *class, DC::RW rwops) |
2520 | CODE: |
2543 | CODE: |
2521 | RETVAL = Mix_LoadMUS_RW (rwops); |
2544 | RETVAL = Mix_LoadMUS_RW (rwops); |
2522 | OUTPUT: |
2545 | OUTPUT: |
2523 | RETVAL |
2546 | RETVAL |
2524 | |
2547 | |
2525 | void |
2548 | void |
2526 | DESTROY (dc::MixMusic self) |
2549 | DESTROY (DC::MixMusic self) |
2527 | CODE: |
2550 | CODE: |
2528 | Mix_FreeMusic (self); |
2551 | Mix_FreeMusic (self); |
2529 | |
2552 | |
2530 | int |
2553 | int |
2531 | play (dc::MixMusic self, int loops = -1) |
2554 | play (DC::MixMusic self, int loops = -1) |
2532 | CODE: |
2555 | CODE: |
2533 | RETVAL = Mix_PlayMusic (self, loops); |
2556 | RETVAL = Mix_PlayMusic (self, loops); |
2534 | OUTPUT: |
2557 | OUTPUT: |
2535 | RETVAL |
2558 | RETVAL |
2536 | |
2559 | |
2537 | void |
2560 | void |
2538 | fade_in_pos (dc::MixMusic self, int loops, int ms, double position) |
2561 | fade_in_pos (DC::MixMusic self, int loops, int ms, double position) |
2539 | CODE: |
2562 | CODE: |
2540 | Mix_FadeInMusicPos (self, loops, ms, position); |
2563 | Mix_FadeInMusicPos (self, loops, ms, position); |
2541 | |
2564 | |
2542 | MODULE = Deliantra::Client PACKAGE = dc::OpenGL |
2565 | MODULE = Deliantra::Client PACKAGE = DC::OpenGL |
2543 | |
2566 | |
2544 | PROTOTYPES: ENABLE |
2567 | PROTOTYPES: ENABLE |
2545 | |
2568 | |
2546 | BOOT: |
2569 | BOOT: |
2547 | { |
2570 | { |
2548 | HV *stash = gv_stashpv ("dc::OpenGL", 1); |
2571 | HV *stash = gv_stashpv ("DC::OpenGL", 1); |
2549 | static const struct { |
2572 | static const struct { |
2550 | const char *name; |
2573 | const char *name; |
2551 | IV iv; |
2574 | IV iv; |
2552 | } *civ, const_iv[] = { |
2575 | } *civ, const_iv[] = { |
2553 | # define const_iv(name) { # name, (IV)name } |
2576 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
2846 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2869 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2847 | CODE: |
2870 | CODE: |
2848 | if (gl.SeparableFilter2D) |
2871 | if (gl.SeparableFilter2D) |
2849 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2872 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2850 | |
2873 | |
2851 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) |
2874 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0) |
2852 | |
2875 | |
2853 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2876 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2854 | |
2877 | |
2855 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2878 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2856 | |
2879 | |
… | |
… | |
2882 | |
2905 | |
2883 | void glEndList () |
2906 | void glEndList () |
2884 | |
2907 | |
2885 | void glCallList (int list) |
2908 | void glCallList (int list) |
2886 | |
2909 | |
2887 | MODULE = Deliantra::Client PACKAGE = dc::UI::Base |
2910 | MODULE = Deliantra::Client PACKAGE = DC::UI::Base |
2888 | |
2911 | |
2889 | PROTOTYPES: DISABLE |
2912 | PROTOTYPES: DISABLE |
2890 | |
2913 | |
2891 | void |
2914 | void |
2892 | find_widget (SV *self, NV x, NV y) |
2915 | find_widget (SV *self, NV x, NV y) |
… | |
… | |
2896 | XPUSHs (self); |
2919 | XPUSHs (self); |
2897 | } |
2920 | } |
2898 | |
2921 | |
2899 | BOOT: |
2922 | BOOT: |
2900 | { |
2923 | { |
2901 | hover_gv = gv_fetchpv ("dc::UI::HOVER", 1, SVt_NV); |
2924 | hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV); |
2902 | |
2925 | |
2903 | draw_x_gv = gv_fetchpv ("dc::UI::Base::draw_x", 1, SVt_NV); |
2926 | draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV); |
2904 | draw_y_gv = gv_fetchpv ("dc::UI::Base::draw_y", 1, SVt_NV); |
2927 | draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV); |
2905 | draw_w_gv = gv_fetchpv ("dc::UI::Base::draw_w", 1, SVt_NV); |
2928 | draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV); |
2906 | draw_h_gv = gv_fetchpv ("dc::UI::Base::draw_h", 1, SVt_NV); |
2929 | draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV); |
2907 | } |
2930 | } |
2908 | |
2931 | |
2909 | void |
2932 | void |
2910 | draw (SV *self) |
2933 | draw (SV *self) |
2911 | CODE: |
2934 | CODE: |
… | |
… | |
2918 | SV *draw_w_sv = GvSV (draw_w_gv); |
2941 | SV *draw_w_sv = GvSV (draw_w_gv); |
2919 | SV *draw_h_sv = GvSV (draw_h_gv); |
2942 | SV *draw_h_sv = GvSV (draw_h_gv); |
2920 | double draw_x, draw_y; |
2943 | double draw_x, draw_y; |
2921 | |
2944 | |
2922 | if (!SvROK (self)) |
2945 | if (!SvROK (self)) |
2923 | croak ("dc::Base::draw: %s not a reference", SvPV_nolen (self)); |
2946 | croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self)); |
2924 | |
2947 | |
2925 | hv = (HV *)SvRV (self); |
2948 | hv = (HV *)SvRV (self); |
2926 | |
2949 | |
2927 | if (SvTYPE (hv) != SVt_PVHV) |
2950 | if (SvTYPE (hv) != SVt_PVHV) |
2928 | croak ("dc::Base::draw: %s not a hashref", SvPV_nolen (self)); |
2951 | croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self)); |
2929 | |
2952 | |
2930 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
2953 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
2931 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
2954 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
2932 | |
2955 | |
2933 | if (!h || !w) |
2956 | if (!h || !w) |