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.57 by root, Fri Apr 21 07:09:10 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 10
46
45typedef Mix_Chunk *CFClient__MixChunk; 47typedef Mix_Chunk *CFClient__MixChunk;
46typedef Mix_Music *CFClient__MixMusic; 48typedef Mix_Music *CFClient__MixMusic;
47 49
48static PangoContext *context; 50typedef PangoFontDescription *CFClient__Font;
49static PangoFontMap *fontmap;
50 51
51typedef struct cf_layout { 52typedef struct cf_layout {
52 PangoLayout *pl; 53 PangoLayout *pl;
53 int base_height; 54 int base_height;
55 CFClient__Font font;
54} *CFClient__Layout; 56} *CFClient__Layout;
57
58static CFClient__Font default_font;
59static PangoContext *context;
60static PangoFontMap *fontmap;
55 61
56static void 62static void
57substitute_func (FcPattern *pattern, gpointer data) 63substitute_func (FcPattern *pattern, gpointer data)
58{ 64{
59 FcPatternAddBool (pattern, FC_HINTING , 1); 65 FcPatternAddBool (pattern, FC_HINTING , 1);
60 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 66 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
61} 67}
62 68
63static void 69static void
64layout_update (CFClient__Layout self) 70layout_update_font (CFClient__Layout self)
65{ 71{
66 /* 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
67 * reasonably well with bitstream vera 73 * reasonably well with bitstream vera
68 */ 74 */
69 PangoFontDescription *font = pango_context_get_font_description (context); 75 PangoFontDescription *font = self->font ? self->font : default_font;
70 76
71 int height = self->base_height * (PANGO_SCALE * 8 / 10);
72
73 if (pango_font_description_get_size (font) != height)
74 {
75 pango_font_description_set_absolute_size (font, height); 77 pango_font_description_set_absolute_size (font,
76 pango_layout_context_changed (self->pl); 78 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10));
77 } 79
80 pango_layout_set_font_description (self->pl, font);
78} 81}
79 82
80static void 83static void
81layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 84layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
82{ 85{
83 layout_update (self);
84
85 pango_layout_get_pixel_size (self->pl, w, h); 86 pango_layout_get_pixel_size (self->pl, w, h);
86 87
87 *w = (*w + 3) & ~3; 88 *w = (*w + 3) & ~3;
88 if (!*w) *w = 1; 89 if (!*w) *w = 1;
89 if (!*h) *h = 1; 90 if (!*h) *h = 1;
514add_font (char *file) 515add_font (char *file)
515 CODE: 516 CODE:
516 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ 517 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */
517 518
518void 519void
519set_font (char *file)
520 CODE:
521{
522 int count;
523 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count);
524 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
525 FcPatternDestroy (pattern);
526 pango_context_set_font_description (context, font);
527}
528
529void
530load_image_inline (SV *image_) 520load_image_inline (SV *image_)
531 ALIAS: 521 ALIAS:
532 load_image_file = 1 522 load_image_file = 1
533 PPCODE: 523 PPCODE:
534{ 524{
623#else 613#else
624 fprintf (stderr, "FATAL: %s\n", message); 614 fprintf (stderr, "FATAL: %s\n", message);
625#endif 615#endif
626 exit (1); 616 exit (1);
627 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
628MODULE = CFClient PACKAGE = CFClient::Layout 642MODULE = CFClient PACKAGE = CFClient::Layout
629 643
630CFClient::Layout 644CFClient::Layout
631new (SV *class, int base_height = 10) 645new (SV *class, int base_height = MIN_FONT_HEIGHT)
632 CODE: 646 CODE:
633 New (0, RETVAL, 1, struct cf_layout); 647 New (0, RETVAL, 1, struct cf_layout);
648 RETVAL->pl = pango_layout_new (context);
634 RETVAL->base_height = base_height; 649 RETVAL->base_height = base_height;
635 RETVAL->pl = pango_layout_new (context); 650 RETVAL->font = 0;
636 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);
637 OUTPUT: 653 OUTPUT:
638 RETVAL 654 RETVAL
639 655
640void 656void
641DESTROY (CFClient::Layout self) 657DESTROY (CFClient::Layout self)
670 SvUTF8_on (RETVAL); 686 SvUTF8_on (RETVAL);
671 OUTPUT: 687 OUTPUT:
672 RETVAL 688 RETVAL
673 689
674void 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
675set_height (CFClient::Layout self, int base_height) 700set_height (CFClient::Layout self, int base_height)
676 CODE: 701 CODE:
702 if (self->base_height != base_height)
703 {
677 self->base_height = base_height; 704 self->base_height = base_height;
705 layout_update_font (self);
706 }
678 707
679void 708void
680set_width (CFClient::Layout self, int max_width = -1) 709set_width (CFClient::Layout self, int max_width = -1)
681 CODE: 710 CODE:
682 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);
685size (CFClient::Layout self) 714size (CFClient::Layout self)
686 PPCODE: 715 PPCODE:
687{ 716{
688 int w, h; 717 int w, h;
689 718
690 layout_update (self);
691 layout_get_pixel_size (self, &w, &h); 719 layout_get_pixel_size (self, &w, &h);
692 720
693 EXTEND (SP, 2); 721 EXTEND (SP, 2);
694 PUSHs (sv_2mortal (newSViv (w))); 722 PUSHs (sv_2mortal (newSViv (w)));
695 PUSHs (sv_2mortal (newSViv (h))); 723 PUSHs (sv_2mortal (newSViv (h)));
698int 726int
699xy_to_index (CFClient::Layout self, int x, int y) 727xy_to_index (CFClient::Layout self, int x, int y)
700 CODE: 728 CODE:
701{ 729{
702 int index, trailing; 730 int index, trailing;
703
704 layout_update (self);
705 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);
706
707 RETVAL = index; 732 RETVAL = index;
708} 733}
709 OUTPUT: 734 OUTPUT:
710 RETVAL 735 RETVAL
711 736
712void 737void
713cursor_pos (CFClient::Layout self, int index) 738cursor_pos (CFClient::Layout self, int index)
714 PPCODE: 739 PPCODE:
715{ 740{
716 PangoRectangle strong_pos; 741 PangoRectangle strong_pos;
717 layout_update (self);
718 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 742 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
719 743
720 EXTEND (SP, 3); 744 EXTEND (SP, 3);
721 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 745 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
722 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 746 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
729{ 753{
730 SV *retval; 754 SV *retval;
731 int w, h; 755 int w, h;
732 FT_Bitmap bitmap; 756 FT_Bitmap bitmap;
733 757
734 layout_update (self);
735 layout_get_pixel_size (self, &w, &h); 758 layout_get_pixel_size (self, &w, &h);
736 759
737 retval = newSV (w * h); 760 retval = newSV (w * h);
738 SvPOK_only (retval); 761 SvPOK_only (retval);
739 SvCUR_set (retval, w * h); 762 SvCUR_set (retval, w * h);
1387 1410
1388void glTranslate (float x, float y, float z = 0.) 1411void glTranslate (float x, float y, float z = 0.)
1389 CODE: 1412 CODE:
1390 glTranslatef (x, y, z); 1413 glTranslatef (x, y, z);
1391 1414
1392void glScale (float x, float y, float z) 1415void glScale (float x, float y, float z = 1.)
1393 CODE: 1416 CODE:
1394 glScalef (x, y, z); 1417 glScalef (x, y, z);
1395 1418
1396void glRotate (float angle, float x, float y, float z) 1419void glRotate (float angle, float x, float y, float z)
1397 CODE: 1420 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines