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.242 by root, Wed Dec 26 21:03:21 2007 UTC vs.
Revision 1.256 by root, Mon Mar 24 00:24:46 2008 UTC

46 46
47#include <glib/gmacros.h> 47#include <glib/gmacros.h>
48 48
49#include <pango/pango.h> 49#include <pango/pango.h>
50 50
51#ifndef PANGO_VERSION_CHECK
52# define PANGO_VERSION_CHECK(a,b,c) 0
53#endif
54
55#if !PANGO_VERSION_CHECK (1, 15, 2)
56# define pango_layout_get_line_readonly pango_layout_get_line
57# define pango_layout_get_lines_readonly pango_layout_get_lines
58# define pango_layout_iter_get_line_readonly pango_layout_iter_get_line
59# define pango_layout_iter_get_run_readonly pango_layout_iter_get_run
60#endif
61
51#ifndef _WIN32 62#ifndef _WIN32
52# include <sys/types.h> 63# include <sys/types.h>
53# include <sys/socket.h> 64# include <sys/socket.h>
54# include <netinet/in.h> 65# include <netinet/in.h>
55# include <netinet/tcp.h> 66# include <netinet/tcp.h>
62 73
63#define MAP_EXTEND_X 32 74#define MAP_EXTEND_X 32
64#define MAP_EXTEND_Y 512 75#define MAP_EXTEND_Y 512
65 76
66#define MIN_FONT_HEIGHT 10 77#define MIN_FONT_HEIGHT 10
78
79/* mask out modifiers we are not interested in */
80#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META)
67 81
68#if 0 82#if 0
69# define PARACHUTE SDL_INIT_NOPARACHUTE 83# define PARACHUTE SDL_INIT_NOPARACHUTE
70#else 84#else
71# define PARACHUTE 0 85# define PARACHUTE 0
659 CODE: 673 CODE:
660{ 674{
661 opengl_fontmap = pango_opengl_font_map_new (); 675 opengl_fontmap = pango_opengl_font_map_new ();
662 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); 676 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0);
663 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); 677 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap);
678#if PANGO_VERSION_CHECK (1, 15, 2)
679 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
680 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
681#endif
664} 682}
665 683
666char * 684char *
667SDL_GetError () 685SDL_GetError ()
668 686
700 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 718 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
701 719
702 if (m && m != (SDL_Rect **)-1) 720 if (m && m != (SDL_Rect **)-1)
703 while (*m) 721 while (*m)
704 { 722 {
705 if ((*m)->w >= 800 && (*m)->h >= 600) 723 if ((*m)->w >= 800 && (*m)->h >= 480)
706 { 724 {
707 AV *av = newAV (); 725 AV *av = newAV ();
708 av_push (av, newSViv ((*m)->w)); 726 av_push (av, newSViv ((*m)->w));
709 av_push (av, newSViv ((*m)->h)); 727 av_push (av, newSViv ((*m)->h));
710 av_push (av, newSViv (rgb)); 728 av_push (av, newSViv (rgb));
752SDL_GetKeyName (int sym) 770SDL_GetKeyName (int sym)
753 771
754int 772int
755SDL_GetAppState () 773SDL_GetAppState ()
756 774
775int
776SDL_GetModState ()
777
757void 778void
758poll_events () 779poll_events ()
759 PPCODE: 780 PPCODE:
760{ 781{
761 SDL_Event ev; 782 SDL_Event ev;
770 { 791 {
771 case SDL_KEYDOWN: 792 case SDL_KEYDOWN:
772 case SDL_KEYUP: 793 case SDL_KEYUP:
773 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 794 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
774 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 795 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
775 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 796 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0);
776 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ 797 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */
777 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 798 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
778 break; 799 break;
779 800
780 case SDL_ACTIVEEVENT: 801 case SDL_ACTIVEEVENT:
781 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 802 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
799 x = ev.motion.x; 820 x = ev.motion.x;
800 y = ev.motion.y; 821 y = ev.motion.y;
801 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); 822 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION));
802 } 823 }
803 824
804 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 825 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
805 hv_store (hv, "state", 5, newSViv (state), 0); 826 hv_store (hv, "state", 5, newSViv (state), 0);
806 hv_store (hv, "x", 1, newSViv (x), 0); 827 hv_store (hv, "x", 1, newSViv (x), 0);
807 hv_store (hv, "y", 1, newSViv (y), 0); 828 hv_store (hv, "y", 1, newSViv (y), 0);
808 hv_store (hv, "xrel", 4, newSViv (xrel), 0); 829 hv_store (hv, "xrel", 4, newSViv (xrel), 0);
809 hv_store (hv, "yrel", 4, newSViv (yrel), 0); 830 hv_store (hv, "yrel", 4, newSViv (yrel), 0);
810 } 831 }
811 break; 832 break;
812 833
813 case SDL_MOUSEBUTTONDOWN: 834 case SDL_MOUSEBUTTONDOWN:
814 case SDL_MOUSEBUTTONUP: 835 case SDL_MOUSEBUTTONUP:
815 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 836 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
816 837
817 hv_store (hv, "button", 6, newSViv (ev.button.button), 0); 838 hv_store (hv, "button", 6, newSViv (ev.button.button), 0);
818 hv_store (hv, "state", 5, newSViv (ev.button.state), 0); 839 hv_store (hv, "state", 5, newSViv (ev.button.state), 0);
819 hv_store (hv, "x", 1, newSViv (ev.button.x), 0); 840 hv_store (hv, "x", 1, newSViv (ev.button.x), 0);
820 hv_store (hv, "y", 1, newSViv (ev.button.y), 0); 841 hv_store (hv, "y", 1, newSViv (ev.button.y), 0);
1165{ 1186{
1166 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 1187 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
1167 1188
1168 do 1189 do
1169 { 1190 {
1170 PangoLayoutRun *run = pango_layout_iter_get_run (iter); 1191 PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter);
1171 1192
1172 if (run && shape_attr_p (run)) 1193 if (run && shape_attr_p (run))
1173 { 1194 {
1174 PangoRectangle extents; 1195 PangoRectangle extents;
1175 pango_layout_iter_get_run_extents (iter, 0, &extents); 1196 pango_layout_iter_get_run_extents (iter, 0, &extents);
1279int 1300int
1280descent (DC::Layout self) 1301descent (DC::Layout self)
1281 CODE: 1302 CODE:
1282{ 1303{
1283 PangoRectangle rect; 1304 PangoRectangle rect;
1284 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1305 PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0);
1285 pango_layout_line_get_pixel_extents (line, 0, &rect); 1306 pango_layout_line_get_pixel_extents (line, 0, &rect);
1286 RETVAL = PANGO_DESCENT (rect); 1307 RETVAL = PANGO_DESCENT (rect);
1287} 1308}
1288 OUTPUT: 1309 OUTPUT:
1289 RETVAL 1310 RETVAL
1301 1322
1302void 1323void
1303cursor_pos (DC::Layout self, int index) 1324cursor_pos (DC::Layout self, int index)
1304 PPCODE: 1325 PPCODE:
1305{ 1326{
1306 PangoRectangle strong_pos; 1327 PangoRectangle pos;
1307 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1328 pango_layout_get_cursor_pos (self->pl, index, &pos, 0);
1308 1329
1309 EXTEND (SP, 3); 1330 EXTEND (SP, 3);
1310 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1331 PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE)));
1311 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1332 PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE)));
1312 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1333 PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE)));
1313} 1334}
1314 1335
1315void 1336void
1316index_to_line_x (DC::Layout self, int index, int trailing = 0) 1337index_to_line_x (DC::Layout self, int index, int trailing = 0)
1317 PPCODE: 1338 PPCODE:
1318{ 1339{
1319 int line, x; 1340 int line, x;
1320 1341
1321 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); 1342 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1343#if !PANGO_VERSION_CHECK (1, 17, 3)
1322 /* pango bug: line is between 1..numlines, not 0..numlines-1 */ 1344 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1323 1345 --line;
1346#endif
1324 EXTEND (SP, 2); 1347 EXTEND (SP, 2);
1325 PUSHs (sv_2mortal (newSViv (line - 1))); 1348 PUSHs (sv_2mortal (newSViv (line)));
1326 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); 1349 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1327} 1350}
1328 1351
1329void 1352void
1330line_x_to_index (DC::Layout self, int line, int x) 1353line_x_to_index (DC::Layout self, int line, int x)
1334 int index, trailing; 1357 int index, trailing;
1335 1358
1336 if (line < 0) 1359 if (line < 0)
1337 XSRETURN_EMPTY; 1360 XSRETURN_EMPTY;
1338 1361
1339 if (!(lp = pango_layout_get_line (self->pl, line))) 1362 if (!(lp = pango_layout_get_line_readonly (self->pl, line)))
1340 XSRETURN_EMPTY; /* do better */ 1363 XSRETURN_EMPTY; /* do better */
1341 1364
1342 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); 1365 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1343 1366
1344 EXTEND (SP, 2); 1367 EXTEND (SP, 2);
2846void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) 2869void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column)
2847 CODE: 2870 CODE:
2848 if (gl.SeparableFilter2D) 2871 if (gl.SeparableFilter2D)
2849 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); 2872 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column);
2850 2873
2851void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) 2874void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0)
2852 2875
2853void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) 2876void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border)
2854 2877
2855void glDrawPixels (int width, int height, int format, int type, char *pixels) 2878void glDrawPixels (int width, int height, int format, int type, char *pixels)
2856 2879

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines