ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.59 by root, Sun Apr 23 04:41:33 2006 UTC vs.
Revision 1.63 by root, Mon Apr 24 06:05:33 2006 UTC

40#define FOW_DARKNESS 32 40#define FOW_DARKNESS 32
41 41
42#define MAP_EXTEND_X 32 42#define MAP_EXTEND_X 32
43#define MAP_EXTEND_Y 512 43#define MAP_EXTEND_Y 512
44 44
45#define MIN_FONT_HEIGHT 8 * PANGO_SCALE 45#define MIN_FONT_HEIGHT 10
46 46
47typedef Mix_Chunk *CFClient__MixChunk; 47typedef Mix_Chunk *CFClient__MixChunk;
48typedef Mix_Music *CFClient__MixMusic; 48typedef Mix_Music *CFClient__MixMusic;
49 49
50static PangoContext *context; 50typedef PangoFontDescription *CFClient__Font;
51static PangoFontMap *fontmap;
52 51
53typedef struct cf_layout { 52typedef struct cf_layout {
54 PangoLayout *pl; 53 PangoLayout *pl;
55 int base_height; 54 int base_height;
55 CFClient__Font font;
56} *CFClient__Layout; 56} *CFClient__Layout;
57
58static CFClient__Font default_font;
59static PangoContext *context;
60static PangoFontMap *fontmap;
57 61
58static void 62static void
59substitute_func (FcPattern *pattern, gpointer data) 63substitute_func (FcPattern *pattern, gpointer data)
60{ 64{
61 FcPatternAddBool (pattern, FC_HINTING , 1); 65 FcPatternAddBool (pattern, FC_HINTING , 1);
62 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 66 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
63} 67}
64 68
65static void 69static void
66layout_update (CFClient__Layout self) 70layout_update_font (CFClient__Layout self)
67{ 71{
68 /* 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
69 * reasonably well with bitstream vera 73 * reasonably well with bitstream vera
70 */ 74 */
71 PangoFontDescription *font = pango_layout_get_font_description (self->pl); 75 PangoFontDescription *font = self->font ? self->font : default_font;
72 76
73 int height = self->base_height * (PANGO_SCALE * 8 / 10);
74
75 if (height < MIN_FONT_HEIGHT)
76 height = MIN_FONT_HEIGHT;
77
78 if (pango_font_description_get_size (font) != height)
79 {
80 font = pango_font_description_copy (font);
81 pango_font_description_set_absolute_size (font, height); 77 pango_font_description_set_absolute_size (font,
78 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10));
79
82 pango_layout_set_font_description (self->pl, font); 80 pango_layout_set_font_description (self->pl, font);
83 }
84} 81}
85 82
86static void 83static void
87layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 84layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
88{ 85{
89 layout_update (self);
90
91 pango_layout_get_pixel_size (self->pl, w, h); 86 pango_layout_get_pixel_size (self->pl, w, h);
92 87
93 *w = (*w + 3) & ~3; 88 *w = (*w + 3) & ~3;
94 if (!*w) *w = 1; 89 if (!*w) *w = 1;
95 if (!*h) *h = 1; 90 if (!*h) *h = 1;
520add_font (char *file) 515add_font (char *file)
521 CODE: 516 CODE:
522 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ 517 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */
523 518
524void 519void
525set_font (char *file)
526 CODE:
527{
528 int count;
529 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count);
530 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
531 FcPatternDestroy (pattern);
532 pango_font_description_set_absolute_size (font, MIN_FONT_HEIGHT);
533 pango_context_set_font_description (context, font);
534}
535
536void
537load_image_inline (SV *image_) 520load_image_inline (SV *image_)
538 ALIAS: 521 ALIAS:
539 load_image_file = 1 522 load_image_file = 1
540 PPCODE: 523 PPCODE:
541{ 524{
630#else 613#else
631 fprintf (stderr, "FATAL: %s\n", message); 614 fprintf (stderr, "FATAL: %s\n", message);
632#endif 615#endif
633 exit (1); 616 exit (1);
634 617
618MODULE = CFClient PACKAGE = CFClient::Font
619
620CFClient::Font
621new_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
632void
633DESTROY (CFClient::Font self)
634 CODE:
635 pango_font_description_free (self);
636
637void
638make_default (CFClient::Font self)
639 CODE:
640 default_font = self;
641
635MODULE = CFClient PACKAGE = CFClient::Layout 642MODULE = CFClient PACKAGE = CFClient::Layout
636 643
637CFClient::Layout 644CFClient::Layout
638new (SV *class, int base_height = 10) 645new (SV *class, int base_height = MIN_FONT_HEIGHT)
639 CODE: 646 CODE:
640 New (0, RETVAL, 1, struct cf_layout); 647 New (0, RETVAL, 1, struct cf_layout);
648 RETVAL->pl = pango_layout_new (context);
641 RETVAL->base_height = base_height; 649 RETVAL->base_height = base_height;
642 RETVAL->pl = pango_layout_new (context); 650 RETVAL->font = 0;
643 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 651 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
644 pango_layout_set_font_description (RETVAL->pl, 652 pango_layout_set_font_description (RETVAL->pl, default_font);
645 pango_font_description_copy (
646 pango_context_get_font_description (context)));
647 OUTPUT: 653 OUTPUT:
648 RETVAL 654 RETVAL
649 655
650void 656void
651DESTROY (CFClient::Layout self) 657DESTROY (CFClient::Layout self)
680 SvUTF8_on (RETVAL); 686 SvUTF8_on (RETVAL);
681 OUTPUT: 687 OUTPUT:
682 RETVAL 688 RETVAL
683 689
684void 690void
691set_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
699void
685set_height (CFClient::Layout self, int base_height) 700set_height (CFClient::Layout self, int base_height)
686 CODE: 701 CODE:
702 if (self->base_height != base_height)
703 {
687 self->base_height = base_height; 704 self->base_height = base_height;
705 layout_update_font (self);
706 }
688 707
689void 708void
690set_width (CFClient::Layout self, int max_width = -1) 709set_width (CFClient::Layout self, int max_width = -1)
691 CODE: 710 CODE:
692 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);
695size (CFClient::Layout self) 714size (CFClient::Layout self)
696 PPCODE: 715 PPCODE:
697{ 716{
698 int w, h; 717 int w, h;
699 718
700 layout_update (self);
701 layout_get_pixel_size (self, &w, &h); 719 layout_get_pixel_size (self, &w, &h);
702 720
703 EXTEND (SP, 2); 721 EXTEND (SP, 2);
704 PUSHs (sv_2mortal (newSViv (w))); 722 PUSHs (sv_2mortal (newSViv (w)));
705 PUSHs (sv_2mortal (newSViv (h))); 723 PUSHs (sv_2mortal (newSViv (h)));
708int 726int
709xy_to_index (CFClient::Layout self, int x, int y) 727xy_to_index (CFClient::Layout self, int x, int y)
710 CODE: 728 CODE:
711{ 729{
712 int index, trailing; 730 int index, trailing;
713
714 layout_update (self);
715 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);
716
717 RETVAL = index; 732 RETVAL = index;
718} 733}
719 OUTPUT: 734 OUTPUT:
720 RETVAL 735 RETVAL
721 736
722void 737void
723cursor_pos (CFClient::Layout self, int index) 738cursor_pos (CFClient::Layout self, int index)
724 PPCODE: 739 PPCODE:
725{ 740{
726 PangoRectangle strong_pos; 741 PangoRectangle strong_pos;
727 layout_update (self);
728 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 742 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
729 743
730 EXTEND (SP, 3); 744 EXTEND (SP, 3);
731 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 745 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
732 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 746 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
739{ 753{
740 SV *retval; 754 SV *retval;
741 int w, h; 755 int w, h;
742 FT_Bitmap bitmap; 756 FT_Bitmap bitmap;
743 757
744 layout_update (self);
745 layout_get_pixel_size (self, &w, &h); 758 layout_get_pixel_size (self, &w, &h);
746 759
747 retval = newSV (w * h); 760 retval = newSV (w * h);
748 SvPOK_only (retval); 761 SvPOK_only (retval);
749 SvCUR_set (retval, w * h); 762 SvCUR_set (retval, w * h);
1397 1410
1398void glTranslate (float x, float y, float z = 0.) 1411void glTranslate (float x, float y, float z = 0.)
1399 CODE: 1412 CODE:
1400 glTranslatef (x, y, z); 1413 glTranslatef (x, y, z);
1401 1414
1402void glScale (float x, float y, float z) 1415void glScale (float x, float y, float z = 1.)
1403 CODE: 1416 CODE:
1404 glScalef (x, y, z); 1417 glScalef (x, y, z);
1405 1418
1406void glRotate (float angle, float x, float y, float z) 1419void glRotate (float angle, float x, float y, float z)
1407 CODE: 1420 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines