… | |
… | |
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 | New (0, RETVAL, 1, struct cf_layout); |
762 | New (0, RETVAL, 1, struct cf_layout); |
726 | |
763 | |
727 | RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); |
764 | RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); |
728 | RETVAL->rgba = rgba; |
765 | RETVAL->rgba = rgba; |
729 | RETVAL->r = 1.; |
766 | RETVAL->r = 1.; |
… | |
… | |
773 | |
810 | |
774 | SV * |
811 | SV * |
775 | get_text (CFClient::Layout self) |
812 | get_text (CFClient::Layout self) |
776 | CODE: |
813 | CODE: |
777 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
814 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
778 | SvUTF8_on (RETVAL); |
815 | sv_utf8_decode (RETVAL); |
779 | OUTPUT: |
816 | OUTPUT: |
780 | RETVAL |
817 | RETVAL |
781 | |
818 | |
782 | void |
819 | void |
783 | 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.) |
… | |
… | |
964 | } |
1001 | } |
965 | |
1002 | |
966 | MODULE = CFClient PACKAGE = CFClient::Texture |
1003 | MODULE = CFClient PACKAGE = CFClient::Texture |
967 | |
1004 | |
968 | 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 |
969 | 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) |
970 | PROTOTYPE: $$$;$$ |
1044 | PROTOTYPE: $$$;$$ |
971 | ALIAS: |
1045 | ALIAS: |
972 | draw_quad_alpha = 1 |
1046 | draw_quad_alpha = 1 |
973 | draw_quad_alpha_premultiplied = 2 |
1047 | draw_quad_alpha_premultiplied = 2 |
… | |
… | |
990 | |
1064 | |
991 | if (ix == 2) |
1065 | if (ix == 2) |
992 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
1066 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
993 | else |
1067 | else |
994 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1068 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
995 | GL_ONE_MINUS_DST_ALPHA, GL_ONE); |
1069 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
996 | |
1070 | |
997 | glEnable (GL_ALPHA_TEST); |
1071 | glEnable (GL_ALPHA_TEST); |
998 | glAlphaFunc (GL_GREATER, 0.01f); |
1072 | glAlphaFunc (GL_GREATER, 0.01f); |
999 | } |
1073 | } |
1000 | |
1074 | |
… | |
… | |
1039 | DESTROY (CFClient::Map self) |
1113 | DESTROY (CFClient::Map self) |
1040 | CODE: |
1114 | CODE: |
1041 | { |
1115 | { |
1042 | map_clear (self); |
1116 | map_clear (self); |
1043 | Safefree (self->face); |
1117 | Safefree (self->face); |
|
|
1118 | Safefree (self->tex); |
1044 | Safefree (self); |
1119 | Safefree (self); |
1045 | } |
1120 | } |
1046 | |
1121 | |
1047 | void |
1122 | void |
1048 | clear (CFClient::Map self) |
1123 | clear (CFClient::Map self) |
… | |
… | |
1557 | const_iv (GL_RESCALE_NORMAL), |
1632 | const_iv (GL_RESCALE_NORMAL), |
1558 | const_iv (GL_AND), |
1633 | const_iv (GL_AND), |
1559 | const_iv (GL_ONE), |
1634 | const_iv (GL_ONE), |
1560 | const_iv (GL_ZERO), |
1635 | const_iv (GL_ZERO), |
1561 | const_iv (GL_SRC_ALPHA), |
1636 | const_iv (GL_SRC_ALPHA), |
1562 | const_iv (GL_SRC_ALPHA_SATURATE), |
1637 | const_iv (GL_DST_ALPHA), |
1563 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
1638 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
1564 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
1639 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
|
|
1640 | const_iv (GL_SRC_ALPHA_SATURATE), |
1565 | const_iv (GL_RGB), |
1641 | const_iv (GL_RGB), |
1566 | const_iv (GL_RGBA), |
1642 | const_iv (GL_RGBA), |
1567 | const_iv (GL_UNSIGNED_BYTE), |
1643 | const_iv (GL_UNSIGNED_BYTE), |
1568 | const_iv (GL_UNSIGNED_SHORT), |
1644 | const_iv (GL_UNSIGNED_SHORT), |
1569 | const_iv (GL_UNSIGNED_INT), |
1645 | const_iv (GL_UNSIGNED_INT), |