… | |
… | |
10 | #include "XSUB.h" |
10 | #include "XSUB.h" |
11 | |
11 | |
12 | #include <math.h> |
12 | #include <math.h> |
13 | #include <string.h> |
13 | #include <string.h> |
14 | #include <stdio.h> |
14 | #include <stdio.h> |
|
|
15 | #include <stdlib.h> |
15 | |
16 | |
16 | #include <SDL.h> |
17 | #include <SDL.h> |
17 | #include <SDL_endian.h> |
18 | #include <SDL_endian.h> |
18 | #include <SDL_image.h> |
19 | #include <SDL_image.h> |
19 | #include <SDL_mixer.h> |
20 | #include <SDL_mixer.h> |
… | |
… | |
85 | static PangoFontMap *ft2_fontmap, *cairo_fontmap; |
86 | static PangoFontMap *ft2_fontmap, *cairo_fontmap; |
86 | |
87 | |
87 | static void |
88 | static void |
88 | substitute_func (FcPattern *pattern, gpointer data) |
89 | substitute_func (FcPattern *pattern, gpointer data) |
89 | { |
90 | { |
90 | FcPatternAddBool (pattern, FC_HINTING , 1); |
91 | FcPatternAddBool (pattern, FC_HINTING, 1); |
|
|
92 | #ifdef FC_HINT_STYLE |
|
|
93 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
|
|
94 | #endif |
91 | #ifdef _WIN32 |
95 | #ifdef _WIN32 |
92 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
96 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
93 | #else |
97 | #else |
94 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
98 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
95 | #endif |
99 | #endif |
… | |
… | |
296 | ev.code = 1; |
300 | ev.code = 1; |
297 | ev.data1 = (void *)(long)channel; |
301 | ev.data1 = (void *)(long)channel; |
298 | ev.data2 = 0; |
302 | ev.data2 = 0; |
299 | |
303 | |
300 | SDL_PushEvent ((SDL_Event *)&ev); |
304 | SDL_PushEvent ((SDL_Event *)&ev); |
|
|
305 | } |
|
|
306 | |
|
|
307 | static unsigned int |
|
|
308 | minpot (unsigned int n) |
|
|
309 | { |
|
|
310 | if (!n) |
|
|
311 | return 0; |
|
|
312 | |
|
|
313 | --n; |
|
|
314 | |
|
|
315 | n |= n >> 1; |
|
|
316 | n |= n >> 2; |
|
|
317 | n |= n >> 4; |
|
|
318 | n |= n >> 8; |
|
|
319 | n |= n >> 16; |
|
|
320 | |
|
|
321 | return n + 1; |
301 | } |
322 | } |
302 | |
323 | |
303 | MODULE = CFClient PACKAGE = CFClient |
324 | MODULE = CFClient PACKAGE = CFClient |
304 | |
325 | |
305 | PROTOTYPES: ENABLE |
326 | PROTOTYPES: ENABLE |
… | |
… | |
418 | } |
439 | } |
419 | |
440 | |
420 | void |
441 | void |
421 | pango_init () |
442 | pango_init () |
422 | CODE: |
443 | CODE: |
423 | { |
|
|
424 | // delayed, so it can pick up new fonts added by AddFontResourceEx |
444 | // delayed, so it can pick up new fonts added by AddFontResourceEx |
|
|
445 | { |
|
|
446 | { |
425 | ft2_fontmap = pango_ft2_font_map_new (); |
447 | ft2_fontmap = pango_ft2_font_map_new (); |
426 | pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); |
448 | pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); |
427 | ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); |
449 | ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); |
428 | |
450 | } |
|
|
451 | { |
|
|
452 | cairo_font_options_t *fopt = cairo_font_options_create (); |
429 | cairo_fontmap = pango_cairo_font_map_get_default (); |
453 | cairo_fontmap = pango_cairo_font_map_get_default (); |
430 | cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); |
454 | cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); |
|
|
455 | #ifdef _WIN32 |
|
|
456 | // cairo looks like shit eaten twice on windows |
|
|
457 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE); |
|
|
458 | #else |
|
|
459 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY); |
|
|
460 | #endif |
|
|
461 | cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL); |
|
|
462 | cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON); |
|
|
463 | pango_cairo_context_set_font_options (cairo_context, fopt); |
|
|
464 | cairo_font_options_destroy (fopt); |
|
|
465 | } |
431 | } |
466 | } |
432 | |
467 | |
433 | int |
468 | int |
434 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) |
469 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) |
435 | |
470 | |
… | |
… | |
686 | CODE: |
721 | CODE: |
687 | fprintf (stderr, "FATAL: %s\n", message); |
722 | fprintf (stderr, "FATAL: %s\n", message); |
688 | #ifdef _WIN32 |
723 | #ifdef _WIN32 |
689 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
724 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
690 | #endif |
725 | #endif |
691 | exit (1); |
726 | _exit (1); |
|
|
727 | |
|
|
728 | void |
|
|
729 | _exit (int retval) |
|
|
730 | CODE: |
|
|
731 | _exit (retval); |
692 | |
732 | |
693 | MODULE = CFClient PACKAGE = CFClient::Font |
733 | MODULE = CFClient PACKAGE = CFClient::Font |
694 | |
734 | |
695 | CFClient::Font |
735 | CFClient::Font |
696 | new_from_file (SV *class, char *path, int id = 0) |
736 | new_from_file (SV *class, char *path, int id = 0) |
… | |
… | |
717 | MODULE = CFClient PACKAGE = CFClient::Layout |
757 | MODULE = CFClient PACKAGE = CFClient::Layout |
718 | |
758 | |
719 | CFClient::Layout |
759 | CFClient::Layout |
720 | new (SV *class, int rgba = 0) |
760 | new (SV *class, int rgba = 0) |
721 | CODE: |
761 | CODE: |
722 | #if _WIN32 |
|
|
723 | //rgba = 0;//D makes text nicer, breaks TextView |
|
|
724 | #endif |
|
|
725 | rgba=1;//D |
|
|
726 | New (0, RETVAL, 1, struct cf_layout); |
762 | New (0, RETVAL, 1, struct cf_layout); |
727 | |
763 | |
728 | RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); |
764 | RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); |
729 | RETVAL->rgba = rgba; |
765 | RETVAL->rgba = rgba; |
730 | RETVAL->r = 1.; |
766 | RETVAL->r = 1.; |
… | |
… | |
774 | |
810 | |
775 | SV * |
811 | SV * |
776 | get_text (CFClient::Layout self) |
812 | get_text (CFClient::Layout self) |
777 | CODE: |
813 | CODE: |
778 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
814 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
779 | SvUTF8_on (RETVAL); |
815 | sv_utf8_decode (RETVAL); |
780 | OUTPUT: |
816 | OUTPUT: |
781 | RETVAL |
817 | RETVAL |
782 | |
818 | |
783 | void |
819 | void |
784 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
820 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
… | |
… | |
965 | } |
1001 | } |
966 | |
1002 | |
967 | MODULE = CFClient PACKAGE = CFClient::Texture |
1003 | MODULE = CFClient PACKAGE = CFClient::Texture |
968 | |
1004 | |
969 | void |
1005 | void |
|
|
1006 | pad2pot (SV *data_, SV *w_, SV *h_) |
|
|
1007 | CODE: |
|
|
1008 | { |
|
|
1009 | int ow = SvIV (w_); |
|
|
1010 | int oh = SvIV (h_); |
|
|
1011 | |
|
|
1012 | if (ow && oh) |
|
|
1013 | { |
|
|
1014 | int nw = minpot (ow); |
|
|
1015 | int nh = minpot (oh); |
|
|
1016 | |
|
|
1017 | if (nw != ow || nh != oh) |
|
|
1018 | { |
|
|
1019 | if (SvOK (data_)) |
|
|
1020 | { |
|
|
1021 | STRLEN datalen; |
|
|
1022 | char *data = SvPVbyte (data_, datalen); |
|
|
1023 | int bpp = datalen / (ow * oh); |
|
|
1024 | SV *result_ = sv_2mortal (newSV (nw * nh * bpp)); |
|
|
1025 | |
|
|
1026 | SvPOK_only (result_); |
|
|
1027 | SvCUR_set (result_, nw * nh * bpp); |
|
|
1028 | |
|
|
1029 | memset (SvPVX (result_), 0, nw * nh * bpp); |
|
|
1030 | while (oh--) |
|
|
1031 | memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp); |
|
|
1032 | |
|
|
1033 | sv_setsv (data_, result_); |
|
|
1034 | } |
|
|
1035 | |
|
|
1036 | sv_setiv (w_, nw); |
|
|
1037 | sv_setiv (h_, nh); |
|
|
1038 | } |
|
|
1039 | } |
|
|
1040 | } |
|
|
1041 | |
|
|
1042 | void |
970 | draw_quad (SV *self, float x, float y, float w = 0, float h = 0) |
1043 | draw_quad (SV *self, float x, float y, float w = 0., float h = 0.) |
971 | PROTOTYPE: $$$;$$ |
1044 | PROTOTYPE: $$$;$$ |
972 | ALIAS: |
1045 | ALIAS: |
973 | draw_quad_alpha = 1 |
1046 | draw_quad_alpha = 1 |
974 | draw_quad_alpha_premultiplied = 2 |
1047 | draw_quad_alpha_premultiplied = 2 |
975 | CODE: |
1048 | CODE: |
… | |
… | |
1040 | DESTROY (CFClient::Map self) |
1113 | DESTROY (CFClient::Map self) |
1041 | CODE: |
1114 | CODE: |
1042 | { |
1115 | { |
1043 | map_clear (self); |
1116 | map_clear (self); |
1044 | Safefree (self->face); |
1117 | Safefree (self->face); |
|
|
1118 | Safefree (self->tex); |
1045 | Safefree (self); |
1119 | Safefree (self); |
1046 | } |
1120 | } |
1047 | |
1121 | |
1048 | void |
1122 | void |
1049 | clear (CFClient::Map self) |
1123 | clear (CFClient::Map self) |
… | |
… | |
1647 | OUTPUT: |
1721 | OUTPUT: |
1648 | RETVAL |
1722 | RETVAL |
1649 | |
1723 | |
1650 | int glGetError () |
1724 | int glGetError () |
1651 | |
1725 | |
|
|
1726 | void glFinish () |
|
|
1727 | |
1652 | void glClear (int mask) |
1728 | void glClear (int mask) |
1653 | |
1729 | |
1654 | void glClearColor (float r, float g, float b, float a = 1.0) |
1730 | void glClearColor (float r, float g, float b, float a = 1.0) |
1655 | PROTOTYPE: @ |
1731 | PROTOTYPE: @ |
1656 | |
1732 | |