… | |
… | |
33 | typedef signed char int8_t; |
33 | typedef signed char int8_t; |
34 | typedef signed short int16_t; |
34 | typedef signed short int16_t; |
35 | typedef signed int int32_t; |
35 | typedef signed int int32_t; |
36 | #endif |
36 | #endif |
37 | |
37 | |
|
|
38 | #include "glext.h" |
|
|
39 | |
38 | #define FOW_DARKNESS 32 |
40 | #define FOW_DARKNESS 32 |
39 | |
41 | |
40 | #define MAP_EXTEND_X 32 |
42 | #define MAP_EXTEND_X 32 |
41 | #define MAP_EXTEND_Y 512 |
43 | #define MAP_EXTEND_Y 512 |
42 | |
44 | |
|
|
45 | #define MIN_FONT_HEIGHT 10 |
|
|
46 | |
43 | typedef Mix_Chunk *CFClient__MixChunk; |
47 | typedef Mix_Chunk *CFClient__MixChunk; |
44 | typedef Mix_Music *CFClient__MixMusic; |
48 | typedef Mix_Music *CFClient__MixMusic; |
45 | |
49 | |
46 | static PangoContext *context; |
50 | typedef PangoFontDescription *CFClient__Font; |
47 | static PangoFontMap *fontmap; |
|
|
48 | |
51 | |
49 | typedef struct cf_layout { |
52 | typedef struct cf_layout { |
50 | PangoLayout *pl; |
53 | PangoLayout *pl; |
51 | int base_height; |
54 | int base_height; |
|
|
55 | CFClient__Font font; |
52 | } *CFClient__Layout; |
56 | } *CFClient__Layout; |
|
|
57 | |
|
|
58 | static CFClient__Font default_font; |
|
|
59 | static PangoContext *context; |
|
|
60 | static PangoFontMap *fontmap; |
53 | |
61 | |
54 | static void |
62 | static void |
55 | substitute_func (FcPattern *pattern, gpointer data) |
63 | substitute_func (FcPattern *pattern, gpointer data) |
56 | { |
64 | { |
57 | FcPatternAddBool (pattern, FC_HINTING , 1); |
65 | FcPatternAddBool (pattern, FC_HINTING , 1); |
58 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
66 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
59 | } |
67 | } |
60 | |
68 | |
61 | static void |
69 | static void |
62 | layout_update (CFClient__Layout self) |
70 | layout_update_font (CFClient__Layout self) |
63 | { |
71 | { |
64 | /* use a random scale factor to account for unknown descenders, 0.8 works |
72 | /* use a random scale factor to account for unknown descenders, 0.8 works |
65 | * reasonably well with bitstream vera |
73 | * reasonably well with bitstream vera |
66 | */ |
74 | */ |
67 | PangoFontDescription *font = pango_context_get_font_description (context); |
75 | PangoFontDescription *font = self->font ? self->font : default_font; |
68 | |
76 | |
69 | int height = self->base_height * (PANGO_SCALE * 8 / 10); |
|
|
70 | |
|
|
71 | if (pango_font_description_get_size (font) != height) |
|
|
72 | { |
|
|
73 | pango_font_description_set_absolute_size (font, height); |
77 | pango_font_description_set_absolute_size (font, |
74 | pango_layout_context_changed (self->pl); |
78 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
75 | } |
79 | |
|
|
80 | pango_layout_set_font_description (self->pl, font); |
76 | } |
81 | } |
77 | |
82 | |
78 | static void |
83 | static void |
79 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
84 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
80 | { |
85 | { |
81 | layout_update (self); |
|
|
82 | |
|
|
83 | pango_layout_get_pixel_size (self->pl, w, h); |
86 | pango_layout_get_pixel_size (self->pl, w, h); |
84 | |
87 | |
85 | *w = (*w + 3) & ~3; |
88 | *w = (*w + 3) & ~3; |
86 | if (!*w) *w = 1; |
89 | if (!*w) *w = 1; |
87 | if (!*h) *h = 1; |
90 | if (!*h) *h = 1; |
… | |
… | |
249 | ev.type = SDL_USEREVENT; |
252 | ev.type = SDL_USEREVENT; |
250 | ev.code = 0; |
253 | ev.code = 0; |
251 | ev.data1 = 0; |
254 | ev.data1 = 0; |
252 | ev.data2 = 0; |
255 | ev.data2 = 0; |
253 | |
256 | |
254 | SDL_PushEvent (&ev); |
257 | SDL_PushEvent ((SDL_Event *)&ev); |
255 | } |
258 | } |
256 | |
259 | |
257 | MODULE = CFClient PACKAGE = CFClient |
260 | MODULE = CFClient PACKAGE = CFClient |
258 | |
261 | |
259 | PROTOTYPES: ENABLE |
262 | PROTOTYPES: ENABLE |
… | |
… | |
512 | add_font (char *file) |
515 | add_font (char *file) |
513 | CODE: |
516 | CODE: |
514 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
517 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
515 | |
518 | |
516 | void |
519 | void |
517 | set_font (char *file) |
|
|
518 | CODE: |
|
|
519 | { |
|
|
520 | int count; |
|
|
521 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
|
|
522 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
523 | FcPatternDestroy (pattern); |
|
|
524 | pango_context_set_font_description (context, font); |
|
|
525 | } |
|
|
526 | |
|
|
527 | void |
|
|
528 | load_image_inline (SV *image_) |
520 | load_image_inline (SV *image_) |
529 | ALIAS: |
521 | ALIAS: |
530 | load_image_file = 1 |
522 | load_image_file = 1 |
531 | PPCODE: |
523 | PPCODE: |
532 | { |
524 | { |
… | |
… | |
621 | #else |
613 | #else |
622 | fprintf (stderr, "FATAL: %s\n", message); |
614 | fprintf (stderr, "FATAL: %s\n", message); |
623 | #endif |
615 | #endif |
624 | exit (1); |
616 | exit (1); |
625 | |
617 | |
|
|
618 | MODULE = CFClient PACKAGE = CFClient::Font |
|
|
619 | |
|
|
620 | CFClient::Font |
|
|
621 | new_from_file (SV *class, char *path) |
|
|
622 | CODE: |
|
|
623 | { |
|
|
624 | int count; |
|
|
625 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, 0, 0, &count); |
|
|
626 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
627 | FcPatternDestroy (pattern); |
|
|
628 | } |
|
|
629 | OUTPUT: |
|
|
630 | RETVAL |
|
|
631 | |
|
|
632 | void |
|
|
633 | DESTROY (CFClient::Font self) |
|
|
634 | CODE: |
|
|
635 | pango_font_description_free (self); |
|
|
636 | |
|
|
637 | void |
|
|
638 | make_default (CFClient::Font self) |
|
|
639 | CODE: |
|
|
640 | default_font = self; |
|
|
641 | |
626 | MODULE = CFClient PACKAGE = CFClient::Layout |
642 | MODULE = CFClient PACKAGE = CFClient::Layout |
627 | |
643 | |
628 | CFClient::Layout |
644 | CFClient::Layout |
629 | new (SV *class, int base_height = 10) |
645 | new (SV *class, int base_height = MIN_FONT_HEIGHT) |
630 | CODE: |
646 | CODE: |
631 | New (0, RETVAL, 1, struct cf_layout); |
647 | New (0, RETVAL, 1, struct cf_layout); |
|
|
648 | RETVAL->pl = pango_layout_new (context); |
632 | RETVAL->base_height = base_height; |
649 | RETVAL->base_height = base_height; |
633 | RETVAL->pl = pango_layout_new (context); |
650 | RETVAL->font = 0; |
634 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
651 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
|
|
652 | pango_layout_set_font_description (RETVAL->pl, default_font); |
635 | OUTPUT: |
653 | OUTPUT: |
636 | RETVAL |
654 | RETVAL |
637 | |
655 | |
638 | void |
656 | void |
639 | DESTROY (CFClient::Layout self) |
657 | DESTROY (CFClient::Layout self) |
… | |
… | |
668 | SvUTF8_on (RETVAL); |
686 | SvUTF8_on (RETVAL); |
669 | OUTPUT: |
687 | OUTPUT: |
670 | RETVAL |
688 | RETVAL |
671 | |
689 | |
672 | void |
690 | void |
|
|
691 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
|
|
692 | CODE: |
|
|
693 | if (self->font != font) |
|
|
694 | { |
|
|
695 | self->font = font; |
|
|
696 | layout_update_font (self); |
|
|
697 | } |
|
|
698 | |
|
|
699 | void |
673 | set_height (CFClient::Layout self, int base_height) |
700 | set_height (CFClient::Layout self, int base_height) |
674 | CODE: |
701 | CODE: |
|
|
702 | if (self->base_height != base_height) |
|
|
703 | { |
675 | self->base_height = base_height; |
704 | self->base_height = base_height; |
|
|
705 | layout_update_font (self); |
|
|
706 | } |
676 | |
707 | |
677 | void |
708 | void |
678 | set_width (CFClient::Layout self, int max_width = -1) |
709 | set_width (CFClient::Layout self, int max_width = -1) |
679 | CODE: |
710 | CODE: |
680 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
711 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
… | |
… | |
683 | size (CFClient::Layout self) |
714 | size (CFClient::Layout self) |
684 | PPCODE: |
715 | PPCODE: |
685 | { |
716 | { |
686 | int w, h; |
717 | int w, h; |
687 | |
718 | |
688 | layout_update (self); |
|
|
689 | layout_get_pixel_size (self, &w, &h); |
719 | layout_get_pixel_size (self, &w, &h); |
690 | |
720 | |
691 | EXTEND (SP, 2); |
721 | EXTEND (SP, 2); |
692 | PUSHs (sv_2mortal (newSViv (w))); |
722 | PUSHs (sv_2mortal (newSViv (w))); |
693 | PUSHs (sv_2mortal (newSViv (h))); |
723 | PUSHs (sv_2mortal (newSViv (h))); |
… | |
… | |
696 | int |
726 | int |
697 | xy_to_index (CFClient::Layout self, int x, int y) |
727 | xy_to_index (CFClient::Layout self, int x, int y) |
698 | CODE: |
728 | CODE: |
699 | { |
729 | { |
700 | int index, trailing; |
730 | int index, trailing; |
701 | |
|
|
702 | layout_update (self); |
|
|
703 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
731 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
704 | |
|
|
705 | RETVAL = index; |
732 | RETVAL = index; |
706 | } |
733 | } |
707 | OUTPUT: |
734 | OUTPUT: |
708 | RETVAL |
735 | RETVAL |
709 | |
736 | |
710 | void |
737 | void |
711 | cursor_pos (CFClient::Layout self, int index) |
738 | cursor_pos (CFClient::Layout self, int index) |
712 | PPCODE: |
739 | PPCODE: |
713 | { |
740 | { |
714 | PangoRectangle strong_pos; |
741 | PangoRectangle strong_pos; |
715 | layout_update (self); |
|
|
716 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
742 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
717 | |
743 | |
718 | EXTEND (SP, 3); |
744 | EXTEND (SP, 3); |
719 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
745 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
720 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
746 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
… | |
… | |
727 | { |
753 | { |
728 | SV *retval; |
754 | SV *retval; |
729 | int w, h; |
755 | int w, h; |
730 | FT_Bitmap bitmap; |
756 | FT_Bitmap bitmap; |
731 | |
757 | |
732 | layout_update (self); |
|
|
733 | layout_get_pixel_size (self, &w, &h); |
758 | layout_get_pixel_size (self, &w, &h); |
734 | |
759 | |
735 | retval = newSV (w * h); |
760 | retval = newSV (w * h); |
736 | SvPOK_only (retval); |
761 | SvPOK_only (retval); |
737 | SvCUR_set (retval, w * h); |
762 | SvCUR_set (retval, w * h); |
… | |
… | |
1323 | const_iv (GL_TEXTURE_WRAP_T), |
1348 | const_iv (GL_TEXTURE_WRAP_T), |
1324 | const_iv (GL_CLAMP), |
1349 | const_iv (GL_CLAMP), |
1325 | const_iv (GL_REPEAT), |
1350 | const_iv (GL_REPEAT), |
1326 | const_iv (GL_NEAREST), |
1351 | const_iv (GL_NEAREST), |
1327 | const_iv (GL_LINEAR), |
1352 | const_iv (GL_LINEAR), |
|
|
1353 | const_iv (GL_NEAREST_MIPMAP_NEAREST), |
|
|
1354 | const_iv (GL_LINEAR_MIPMAP_NEAREST), |
|
|
1355 | const_iv (GL_NEAREST_MIPMAP_LINEAR), |
|
|
1356 | const_iv (GL_LINEAR_MIPMAP_LINEAR), |
|
|
1357 | const_iv (GL_GENERATE_MIPMAP), |
|
|
1358 | const_iv (GL_LINEAR), |
1328 | const_iv (GL_MODULATE), |
1359 | const_iv (GL_MODULATE), |
1329 | const_iv (GL_REPLACE), |
1360 | const_iv (GL_REPLACE), |
1330 | const_iv (GL_COLOR_BUFFER_BIT), |
1361 | const_iv (GL_COLOR_BUFFER_BIT), |
1331 | const_iv (GL_PROJECTION), |
1362 | const_iv (GL_PROJECTION), |
1332 | const_iv (GL_MODELVIEW), |
1363 | const_iv (GL_MODELVIEW), |
… | |
… | |
1379 | |
1410 | |
1380 | void glTranslate (float x, float y, float z = 0.) |
1411 | void glTranslate (float x, float y, float z = 0.) |
1381 | CODE: |
1412 | CODE: |
1382 | glTranslatef (x, y, z); |
1413 | glTranslatef (x, y, z); |
1383 | |
1414 | |
1384 | void glScale (float x, float y, float z) |
1415 | void glScale (float x, float y, float z = 1.) |
1385 | CODE: |
1416 | CODE: |
1386 | glScalef (x, y, z); |
1417 | glScalef (x, y, z); |
1387 | |
1418 | |
1388 | void glRotate (float angle, float x, float y, float z) |
1419 | void glRotate (float angle, float x, float y, float z) |
1389 | CODE: |
1420 | CODE: |