… | |
… | |
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 |
… | |
… | |
418 | } |
422 | } |
419 | |
423 | |
420 | void |
424 | void |
421 | pango_init () |
425 | pango_init () |
422 | CODE: |
426 | CODE: |
423 | { |
|
|
424 | // delayed, so it can pick up new fonts added by AddFontResourceEx |
427 | // delayed, so it can pick up new fonts added by AddFontResourceEx |
|
|
428 | { |
|
|
429 | { |
425 | ft2_fontmap = pango_ft2_font_map_new (); |
430 | ft2_fontmap = pango_ft2_font_map_new (); |
426 | pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); |
431 | 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); |
432 | ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); |
428 | |
433 | } |
|
|
434 | { |
|
|
435 | cairo_font_options_t *fopt = cairo_font_options_create (); |
429 | cairo_fontmap = pango_cairo_font_map_get_default (); |
436 | cairo_fontmap = pango_cairo_font_map_get_default (); |
430 | cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); |
437 | cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); |
|
|
438 | #ifdef _WIN32 |
|
|
439 | // cairo looks like shit eaten twice on windows |
|
|
440 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE); |
|
|
441 | #else |
|
|
442 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY); |
|
|
443 | #endif |
|
|
444 | cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL); |
|
|
445 | cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON); |
|
|
446 | pango_cairo_context_set_font_options (cairo_context, fopt); |
|
|
447 | cairo_font_options_destroy (fopt); |
|
|
448 | } |
431 | } |
449 | } |
432 | |
450 | |
433 | int |
451 | int |
434 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) |
452 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) |
435 | |
453 | |
… | |
… | |
686 | CODE: |
704 | CODE: |
687 | fprintf (stderr, "FATAL: %s\n", message); |
705 | fprintf (stderr, "FATAL: %s\n", message); |
688 | #ifdef _WIN32 |
706 | #ifdef _WIN32 |
689 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
707 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
690 | #endif |
708 | #endif |
691 | exit (1); |
709 | _exit (1); |
|
|
710 | |
|
|
711 | void |
|
|
712 | _exit (int retval) |
|
|
713 | CODE: |
|
|
714 | _exit (retval); |
692 | |
715 | |
693 | MODULE = CFClient PACKAGE = CFClient::Font |
716 | MODULE = CFClient PACKAGE = CFClient::Font |
694 | |
717 | |
695 | CFClient::Font |
718 | CFClient::Font |
696 | new_from_file (SV *class, char *path, int id = 0) |
719 | new_from_file (SV *class, char *path, int id = 0) |
… | |
… | |
717 | MODULE = CFClient PACKAGE = CFClient::Layout |
740 | MODULE = CFClient PACKAGE = CFClient::Layout |
718 | |
741 | |
719 | CFClient::Layout |
742 | CFClient::Layout |
720 | new (SV *class, int rgba = 0) |
743 | new (SV *class, int rgba = 0) |
721 | CODE: |
744 | CODE: |
722 | #if _WIN32 |
|
|
723 | //rgba = 0;//D makes text nicer, breaks TextView |
|
|
724 | #endif |
|
|
725 | New (0, RETVAL, 1, struct cf_layout); |
745 | New (0, RETVAL, 1, struct cf_layout); |
726 | |
746 | |
727 | RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); |
747 | RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); |
728 | RETVAL->rgba = rgba; |
748 | RETVAL->rgba = rgba; |
729 | RETVAL->r = 1.; |
749 | RETVAL->r = 1.; |
… | |
… | |
773 | |
793 | |
774 | SV * |
794 | SV * |
775 | get_text (CFClient::Layout self) |
795 | get_text (CFClient::Layout self) |
776 | CODE: |
796 | CODE: |
777 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
797 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
778 | SvUTF8_on (RETVAL); |
798 | sv_utf8_decode (RETVAL); |
779 | OUTPUT: |
799 | OUTPUT: |
780 | RETVAL |
800 | RETVAL |
781 | |
801 | |
782 | void |
802 | void |
783 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
803 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
… | |
… | |
990 | |
1010 | |
991 | if (ix == 2) |
1011 | if (ix == 2) |
992 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
1012 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
993 | else |
1013 | else |
994 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1014 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
995 | GL_ONE_MINUS_DST_ALPHA, GL_ONE); |
1015 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
996 | |
1016 | |
997 | glEnable (GL_ALPHA_TEST); |
1017 | glEnable (GL_ALPHA_TEST); |
998 | glAlphaFunc (GL_GREATER, 0.01f); |
1018 | glAlphaFunc (GL_GREATER, 0.01f); |
999 | } |
1019 | } |
1000 | |
1020 | |
… | |
… | |
1039 | DESTROY (CFClient::Map self) |
1059 | DESTROY (CFClient::Map self) |
1040 | CODE: |
1060 | CODE: |
1041 | { |
1061 | { |
1042 | map_clear (self); |
1062 | map_clear (self); |
1043 | Safefree (self->face); |
1063 | Safefree (self->face); |
|
|
1064 | Safefree (self->tex); |
1044 | Safefree (self); |
1065 | Safefree (self); |
1045 | } |
1066 | } |
1046 | |
1067 | |
1047 | void |
1068 | void |
1048 | clear (CFClient::Map self) |
1069 | clear (CFClient::Map self) |
… | |
… | |
1557 | const_iv (GL_RESCALE_NORMAL), |
1578 | const_iv (GL_RESCALE_NORMAL), |
1558 | const_iv (GL_AND), |
1579 | const_iv (GL_AND), |
1559 | const_iv (GL_ONE), |
1580 | const_iv (GL_ONE), |
1560 | const_iv (GL_ZERO), |
1581 | const_iv (GL_ZERO), |
1561 | const_iv (GL_SRC_ALPHA), |
1582 | const_iv (GL_SRC_ALPHA), |
1562 | const_iv (GL_SRC_ALPHA_SATURATE), |
1583 | const_iv (GL_DST_ALPHA), |
1563 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
1584 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
1564 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
1585 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
|
|
1586 | const_iv (GL_SRC_ALPHA_SATURATE), |
1565 | const_iv (GL_RGB), |
1587 | const_iv (GL_RGB), |
1566 | const_iv (GL_RGBA), |
1588 | const_iv (GL_RGBA), |
1567 | const_iv (GL_UNSIGNED_BYTE), |
1589 | const_iv (GL_UNSIGNED_BYTE), |
1568 | const_iv (GL_UNSIGNED_SHORT), |
1590 | const_iv (GL_UNSIGNED_SHORT), |
1569 | const_iv (GL_UNSIGNED_INT), |
1591 | const_iv (GL_UNSIGNED_INT), |