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.58 by root, Sun Apr 23 00:57:38 2006 UTC vs.
Revision 1.62 by root, Mon Apr 24 02:41:47 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 8
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_context_get_font_description (context); 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 pango_font_description_set_absolute_size (font, height); 77 pango_font_description_set_absolute_size (font,
81 pango_layout_context_changed (self->pl); 78 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10));
82 } 79
80 pango_layout_set_font_description (self->pl, font);
83} 81}
84 82
85static void 83static void
86layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 84layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
87{ 85{
88 layout_update (self);
89
90 pango_layout_get_pixel_size (self->pl, w, h); 86 pango_layout_get_pixel_size (self->pl, w, h);
91 87
92 *w = (*w + 3) & ~3; 88 *w = (*w + 3) & ~3;
93 if (!*w) *w = 1; 89 if (!*w) *w = 1;
94 if (!*h) *h = 1; 90 if (!*h) *h = 1;
519add_font (char *file) 515add_font (char *file)
520 CODE: 516 CODE:
521 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ 517 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */
522 518
523void 519void
524set_font (char *file)
525 CODE:
526{
527 int count;
528 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count);
529 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
530 FcPatternDestroy (pattern);
531 pango_context_set_font_description (context, font);
532}
533
534void
535load_image_inline (SV *image_) 520load_image_inline (SV *image_)
536 ALIAS: 521 ALIAS:
537 load_image_file = 1 522 load_image_file = 1
538 PPCODE: 523 PPCODE:
539{ 524{
628#else 613#else
629 fprintf (stderr, "FATAL: %s\n", message); 614 fprintf (stderr, "FATAL: %s\n", message);
630#endif 615#endif
631 exit (1); 616 exit (1);
632 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
633MODULE = CFClient PACKAGE = CFClient::Layout 642MODULE = CFClient PACKAGE = CFClient::Layout
634 643
635CFClient::Layout 644CFClient::Layout
636new (SV *class, int base_height = 10) 645new (SV *class, int base_height = MIN_FONT_HEIGHT)
637 CODE: 646 CODE:
638 New (0, RETVAL, 1, struct cf_layout); 647 New (0, RETVAL, 1, struct cf_layout);
648 RETVAL->pl = pango_layout_new (context);
639 RETVAL->base_height = base_height; 649 RETVAL->base_height = base_height;
640 RETVAL->pl = pango_layout_new (context); 650 RETVAL->font = 0;
641 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);
642 OUTPUT: 653 OUTPUT:
643 RETVAL 654 RETVAL
644 655
645void 656void
646DESTROY (CFClient::Layout self) 657DESTROY (CFClient::Layout self)
675 SvUTF8_on (RETVAL); 686 SvUTF8_on (RETVAL);
676 OUTPUT: 687 OUTPUT:
677 RETVAL 688 RETVAL
678 689
679void 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
680set_height (CFClient::Layout self, int base_height) 700set_height (CFClient::Layout self, int base_height)
681 CODE: 701 CODE:
702 if (self->base_height != base_height)
703 {
682 self->base_height = base_height; 704 self->base_height = base_height;
705 layout_update_font (self);
706 }
683 707
684void 708void
685set_width (CFClient::Layout self, int max_width = -1) 709set_width (CFClient::Layout self, int max_width = -1)
686 CODE: 710 CODE:
687 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);
690size (CFClient::Layout self) 714size (CFClient::Layout self)
691 PPCODE: 715 PPCODE:
692{ 716{
693 int w, h; 717 int w, h;
694 718
695 layout_update (self);
696 layout_get_pixel_size (self, &w, &h); 719 layout_get_pixel_size (self, &w, &h);
697 720
698 EXTEND (SP, 2); 721 EXTEND (SP, 2);
699 PUSHs (sv_2mortal (newSViv (w))); 722 PUSHs (sv_2mortal (newSViv (w)));
700 PUSHs (sv_2mortal (newSViv (h))); 723 PUSHs (sv_2mortal (newSViv (h)));
703int 726int
704xy_to_index (CFClient::Layout self, int x, int y) 727xy_to_index (CFClient::Layout self, int x, int y)
705 CODE: 728 CODE:
706{ 729{
707 int index, trailing; 730 int index, trailing;
708
709 layout_update (self);
710 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);
711
712 RETVAL = index; 732 RETVAL = index;
713} 733}
714 OUTPUT: 734 OUTPUT:
715 RETVAL 735 RETVAL
716 736
717void 737void
718cursor_pos (CFClient::Layout self, int index) 738cursor_pos (CFClient::Layout self, int index)
719 PPCODE: 739 PPCODE:
720{ 740{
721 PangoRectangle strong_pos; 741 PangoRectangle strong_pos;
722 layout_update (self);
723 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 742 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
724 743
725 EXTEND (SP, 3); 744 EXTEND (SP, 3);
726 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 745 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
727 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 746 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
734{ 753{
735 SV *retval; 754 SV *retval;
736 int w, h; 755 int w, h;
737 FT_Bitmap bitmap; 756 FT_Bitmap bitmap;
738 757
739 layout_update (self);
740 layout_get_pixel_size (self, &w, &h); 758 layout_get_pixel_size (self, &w, &h);
741 759
742 retval = newSV (w * h); 760 retval = newSV (w * h);
743 SvPOK_only (retval); 761 SvPOK_only (retval);
744 SvCUR_set (retval, w * h); 762 SvCUR_set (retval, w * h);
1392 1410
1393void glTranslate (float x, float y, float z = 0.) 1411void glTranslate (float x, float y, float z = 0.)
1394 CODE: 1412 CODE:
1395 glTranslatef (x, y, z); 1413 glTranslatef (x, y, z);
1396 1414
1397void glScale (float x, float y, float z) 1415void glScale (float x, float y, float z = 1.)
1398 CODE: 1416 CODE:
1399 glScalef (x, y, z); 1417 glScalef (x, y, z);
1400 1418
1401void glRotate (float angle, float x, float y, float z) 1419void glRotate (float angle, float x, float y, float z)
1402 CODE: 1420 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines