… | |
… | |
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; |
… | |
… | |
237 | break; |
240 | break; |
238 | |
241 | |
239 | row->col[x - row->c0].darkness = -1; |
242 | row->col[x - row->c0].darkness = -1; |
240 | } |
243 | } |
241 | } |
244 | } |
|
|
245 | } |
|
|
246 | |
|
|
247 | static void |
|
|
248 | music_finished () |
|
|
249 | { |
|
|
250 | SDL_UserEvent ev; |
|
|
251 | |
|
|
252 | ev.type = SDL_USEREVENT; |
|
|
253 | ev.code = 0; |
|
|
254 | ev.data1 = 0; |
|
|
255 | ev.data2 = 0; |
|
|
256 | |
|
|
257 | SDL_PushEvent ((SDL_Event *)&ev); |
242 | } |
258 | } |
243 | |
259 | |
244 | MODULE = CFClient PACKAGE = CFClient |
260 | MODULE = CFClient PACKAGE = CFClient |
245 | |
261 | |
246 | PROTOTYPES: ENABLE |
262 | PROTOTYPES: ENABLE |
… | |
… | |
463 | } |
479 | } |
464 | } |
480 | } |
465 | |
481 | |
466 | int |
482 | int |
467 | Mix_OpenAudio (int frequency = 22050, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 512) |
483 | Mix_OpenAudio (int frequency = 22050, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 512) |
|
|
484 | POSTCALL: |
|
|
485 | Mix_HookMusicFinished (music_finished); |
468 | |
486 | |
469 | void |
487 | void |
470 | Mix_CloseAudio () |
488 | Mix_CloseAudio () |
471 | |
489 | |
472 | int |
490 | int |
… | |
… | |
495 | |
513 | |
496 | void |
514 | void |
497 | add_font (char *file) |
515 | add_font (char *file) |
498 | CODE: |
516 | CODE: |
499 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
517 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
500 | |
|
|
501 | void |
|
|
502 | set_font (char *file) |
|
|
503 | CODE: |
|
|
504 | { |
|
|
505 | int count; |
|
|
506 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
|
|
507 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
508 | FcPatternDestroy (pattern); |
|
|
509 | pango_context_set_font_description (context, font); |
|
|
510 | } |
|
|
511 | |
518 | |
512 | void |
519 | void |
513 | load_image_inline (SV *image_) |
520 | load_image_inline (SV *image_) |
514 | ALIAS: |
521 | ALIAS: |
515 | load_image_file = 1 |
522 | load_image_file = 1 |
… | |
… | |
606 | #else |
613 | #else |
607 | fprintf (stderr, "FATAL: %s\n", message); |
614 | fprintf (stderr, "FATAL: %s\n", message); |
608 | #endif |
615 | #endif |
609 | exit (1); |
616 | exit (1); |
610 | |
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 | |
611 | MODULE = CFClient PACKAGE = CFClient::Layout |
642 | MODULE = CFClient PACKAGE = CFClient::Layout |
612 | |
643 | |
613 | CFClient::Layout |
644 | CFClient::Layout |
614 | new (SV *class, int base_height = 10) |
645 | new (SV *class, int base_height = MIN_FONT_HEIGHT) |
615 | CODE: |
646 | CODE: |
616 | New (0, RETVAL, 1, struct cf_layout); |
647 | New (0, RETVAL, 1, struct cf_layout); |
|
|
648 | RETVAL->pl = pango_layout_new (context); |
617 | RETVAL->base_height = base_height; |
649 | RETVAL->base_height = base_height; |
618 | RETVAL->pl = pango_layout_new (context); |
650 | RETVAL->font = 0; |
619 | 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); |
620 | OUTPUT: |
653 | OUTPUT: |
621 | RETVAL |
654 | RETVAL |
622 | |
655 | |
623 | void |
656 | void |
624 | DESTROY (CFClient::Layout self) |
657 | DESTROY (CFClient::Layout self) |
… | |
… | |
653 | SvUTF8_on (RETVAL); |
686 | SvUTF8_on (RETVAL); |
654 | OUTPUT: |
687 | OUTPUT: |
655 | RETVAL |
688 | RETVAL |
656 | |
689 | |
657 | 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 |
658 | set_height (CFClient::Layout self, int base_height) |
700 | set_height (CFClient::Layout self, int base_height) |
659 | CODE: |
701 | CODE: |
|
|
702 | if (self->base_height != base_height) |
|
|
703 | { |
660 | self->base_height = base_height; |
704 | self->base_height = base_height; |
|
|
705 | layout_update_font (self); |
|
|
706 | } |
661 | |
707 | |
662 | void |
708 | void |
663 | set_width (CFClient::Layout self, int max_width = -1) |
709 | set_width (CFClient::Layout self, int max_width = -1) |
664 | CODE: |
710 | CODE: |
665 | 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); |
… | |
… | |
668 | size (CFClient::Layout self) |
714 | size (CFClient::Layout self) |
669 | PPCODE: |
715 | PPCODE: |
670 | { |
716 | { |
671 | int w, h; |
717 | int w, h; |
672 | |
718 | |
673 | layout_update (self); |
|
|
674 | layout_get_pixel_size (self, &w, &h); |
719 | layout_get_pixel_size (self, &w, &h); |
675 | |
720 | |
676 | EXTEND (SP, 2); |
721 | EXTEND (SP, 2); |
677 | PUSHs (sv_2mortal (newSViv (w))); |
722 | PUSHs (sv_2mortal (newSViv (w))); |
678 | PUSHs (sv_2mortal (newSViv (h))); |
723 | PUSHs (sv_2mortal (newSViv (h))); |
… | |
… | |
681 | int |
726 | int |
682 | xy_to_index (CFClient::Layout self, int x, int y) |
727 | xy_to_index (CFClient::Layout self, int x, int y) |
683 | CODE: |
728 | CODE: |
684 | { |
729 | { |
685 | int index, trailing; |
730 | int index, trailing; |
686 | |
|
|
687 | layout_update (self); |
|
|
688 | 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); |
689 | |
|
|
690 | RETVAL = index; |
732 | RETVAL = index; |
691 | } |
733 | } |
692 | OUTPUT: |
734 | OUTPUT: |
693 | RETVAL |
735 | RETVAL |
694 | |
736 | |
695 | void |
737 | void |
696 | cursor_pos (CFClient::Layout self, int index) |
738 | cursor_pos (CFClient::Layout self, int index) |
697 | PPCODE: |
739 | PPCODE: |
698 | { |
740 | { |
699 | PangoRectangle strong_pos; |
741 | PangoRectangle strong_pos; |
700 | layout_update (self); |
|
|
701 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
742 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
702 | |
743 | |
703 | EXTEND (SP, 3); |
744 | EXTEND (SP, 3); |
704 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
745 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
705 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
746 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
… | |
… | |
712 | { |
753 | { |
713 | SV *retval; |
754 | SV *retval; |
714 | int w, h; |
755 | int w, h; |
715 | FT_Bitmap bitmap; |
756 | FT_Bitmap bitmap; |
716 | |
757 | |
717 | layout_update (self); |
|
|
718 | layout_get_pixel_size (self, &w, &h); |
758 | layout_get_pixel_size (self, &w, &h); |
719 | |
759 | |
720 | retval = newSV (w * h); |
760 | retval = newSV (w * h); |
721 | SvPOK_only (retval); |
761 | SvPOK_only (retval); |
722 | SvCUR_set (retval, w * h); |
762 | SvCUR_set (retval, w * h); |
… | |
… | |
1308 | const_iv (GL_TEXTURE_WRAP_T), |
1348 | const_iv (GL_TEXTURE_WRAP_T), |
1309 | const_iv (GL_CLAMP), |
1349 | const_iv (GL_CLAMP), |
1310 | const_iv (GL_REPEAT), |
1350 | const_iv (GL_REPEAT), |
1311 | const_iv (GL_NEAREST), |
1351 | const_iv (GL_NEAREST), |
1312 | 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), |
1313 | const_iv (GL_MODULATE), |
1359 | const_iv (GL_MODULATE), |
1314 | const_iv (GL_REPLACE), |
1360 | const_iv (GL_REPLACE), |
1315 | const_iv (GL_COLOR_BUFFER_BIT), |
1361 | const_iv (GL_COLOR_BUFFER_BIT), |
1316 | const_iv (GL_PROJECTION), |
1362 | const_iv (GL_PROJECTION), |
1317 | const_iv (GL_MODELVIEW), |
1363 | const_iv (GL_MODELVIEW), |
… | |
… | |
1364 | |
1410 | |
1365 | void glTranslate (float x, float y, float z = 0.) |
1411 | void glTranslate (float x, float y, float z = 0.) |
1366 | CODE: |
1412 | CODE: |
1367 | glTranslatef (x, y, z); |
1413 | glTranslatef (x, y, z); |
1368 | |
1414 | |
1369 | void glScale (float x, float y, float z) |
1415 | void glScale (float x, float y, float z = 1.) |
1370 | CODE: |
1416 | CODE: |
1371 | glScalef (x, y, z); |
1417 | glScalef (x, y, z); |
1372 | |
1418 | |
1373 | void glRotate (float angle, float x, float y, float z) |
1419 | void glRotate (float angle, float x, float y, float z) |
1374 | CODE: |
1420 | CODE: |