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.56 by root, Thu Apr 20 09:13:31 2006 UTC vs.
Revision 1.61 by root, Sun Apr 23 21:47:30 2006 UTC

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 8
46
43typedef Mix_Chunk *CFClient__MixChunk; 47typedef Mix_Chunk *CFClient__MixChunk;
44typedef Mix_Music *CFClient__MixMusic; 48typedef Mix_Music *CFClient__MixMusic;
45 49
46static PangoContext *context; 50typedef PangoFontDescription *CFClient__Font;
47static PangoFontMap *fontmap;
48 51
49typedef struct cf_layout { 52typedef 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
58static CFClient__Font default_font;
59static PangoContext *context;
60static PangoFontMap *fontmap;
53 61
54static void 62static void
55substitute_func (FcPattern *pattern, gpointer data) 63substitute_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
61static void 69static void
62layout_update (CFClient__Layout self) 70layout_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
78static void 83static void
79layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 84layout_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
257MODULE = CFClient PACKAGE = CFClient 260MODULE = CFClient PACKAGE = CFClient
258 261
259PROTOTYPES: ENABLE 262PROTOTYPES: ENABLE
512add_font (char *file) 515add_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
516void 519void
517set_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
527void
528load_image_inline (SV *image_) 520load_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
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
626MODULE = CFClient PACKAGE = CFClient::Layout 642MODULE = CFClient PACKAGE = CFClient::Layout
627 643
628CFClient::Layout 644CFClient::Layout
629new (SV *class, int base_height = 10) 645new (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
638void 656void
639DESTROY (CFClient::Layout self) 657DESTROY (CFClient::Layout self)
668 SvUTF8_on (RETVAL); 686 SvUTF8_on (RETVAL);
669 OUTPUT: 687 OUTPUT:
670 RETVAL 688 RETVAL
671 689
672void 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
673set_height (CFClient::Layout self, int base_height) 700set_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
677void 708void
678set_width (CFClient::Layout self, int max_width = -1) 709set_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);
683size (CFClient::Layout self) 714size (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)));
696int 726int
697xy_to_index (CFClient::Layout self, int x, int y) 727xy_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
710void 737void
711cursor_pos (CFClient::Layout self, int index) 738cursor_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),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines