--- deliantra/Deliantra-Client/Client.xs 2007/12/28 16:09:03 1.250 +++ deliantra/Deliantra-Client/Client.xs 2008/05/20 20:29:47 1.260 @@ -48,11 +48,15 @@ #include -#if !(defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 15, 2)) -# define pango_layout_get_line_readonly pango_layout_get_line_readonly -# define pango_layout_get_lines_readonly pango_layout_get_lines_readonly -# define pango_layout_iter_get_line_readonly pango_layout_iter_get_line_readonly -# define pango_layout_iter_get_run_readonly pango_layout_iter_get_run_readonly +#ifndef PANGO_VERSION_CHECK +# define PANGO_VERSION_CHECK(a,b,c) 0 +#endif + +#if !PANGO_VERSION_CHECK (1, 15, 2) +# define pango_layout_get_line_readonly pango_layout_get_line +# define pango_layout_get_lines_readonly pango_layout_get_lines +# define pango_layout_iter_get_line_readonly pango_layout_iter_get_line +# define pango_layout_iter_get_run_readonly pango_layout_iter_get_run #endif #ifndef _WIN32 @@ -72,6 +76,9 @@ #define MIN_FONT_HEIGHT 10 +/* mask out modifiers we are not interested in */ +#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) + #if 0 # define PARACHUTE SDL_INIT_NOPARACHUTE #else @@ -180,7 +187,7 @@ layout_update_font (DC__Layout self) { /* use a random scale factor to account for unknown descenders, 0.8 works - * reasonably well with bitstream vera + * reasonably well with dejavu/bistream fonts */ PangoFontDescription *font = self->font ? self->font : default_font; @@ -668,7 +675,8 @@ opengl_fontmap = pango_opengl_font_map_new (); pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); -#if defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 15, 2) + /*pango_context_set_font_description (opengl_context, default_font);*/ +#if PANGO_VERSION_CHECK (1, 15, 2) pango_context_set_language (opengl_context, pango_language_from_string ("en")); /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ #endif @@ -765,6 +773,9 @@ int SDL_GetAppState () +int +SDL_GetModState () + void poll_events () PPCODE: @@ -783,8 +794,8 @@ case SDL_KEYUP: hv_store (hv, "state", 5, newSViv (ev.key.state), 0); hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); - hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); - hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ + hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0); + hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */ hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); break; @@ -812,7 +823,7 @@ SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); } - hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); + hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); hv_store (hv, "state", 5, newSViv (state), 0); hv_store (hv, "x", 1, newSViv (x), 0); hv_store (hv, "y", 1, newSViv (y), 0); @@ -823,7 +834,7 @@ case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: - hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); + hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); hv_store (hv, "button", 6, newSViv (ev.button.button), 0); hv_store (hv, "state", 5, newSViv (ev.button.state), 0); @@ -907,10 +918,12 @@ #endif } -void +int add_font (char *file) CODE: - FcConfigAppFontAddFile (0, (const FcChar8 *)file); + RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); + OUTPUT: + RETVAL void load_image_inline (SV *image_) @@ -1314,13 +1327,13 @@ cursor_pos (DC::Layout self, int index) PPCODE: { - PangoRectangle strong_pos; - pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); + PangoRectangle pos; + pango_layout_get_cursor_pos (self->pl, index, &pos, 0); EXTEND (SP, 3); - PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); - PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); - PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); + PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE))); + PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE))); + PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE))); } void @@ -1330,7 +1343,7 @@ int line, x; pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); -#if !(defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 17, 3)) +#if !PANGO_VERSION_CHECK (1, 17, 3) /* pango bug: line is between 1..numlines, not 0..numlines-1 */ --line; #endif @@ -2281,20 +2294,35 @@ } } - SvPOK_only (data_sv); - SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); - RETVAL = data_sv; + /* if size is w*h + 5 then no data has been found */ + if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) + { + SvPOK_only (data_sv); + SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); + } + + RETVAL = data_sv; } OUTPUT: RETVAL void -set_rect (DC::Map self, int x0, int y0, uint8_t *data) +set_rect (DC::Map self, int x0, int y0, SV *data_sv) PPCODE: { int x, y, z; int w, h; int x1, y1; + STRLEN len; + uint8_t *data, *end; + + len = SvLEN (data_sv); + SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more + data = SvPVbyte_nolen (data_sv); + end = data + len + 8; + + if (len < 5) + XSRETURN_EMPTY; if (*data++ != 0) XSRETURN_EMPTY; /* version mismatch */ @@ -2319,7 +2347,12 @@ for (x = x0; x < x1; x++) { - uint8_t flags = *data++; + uint8_t flags; + + if (data + 7 >= end) + XSRETURN_EMPTY; + + flags = *data++; if (flags) { @@ -2332,7 +2365,8 @@ if (cell->darkness == 0) { - cell->darkness = 0; + /*cell->darkness = 0;*/ + EXTEND (SP, 3); for (z = 0; z <= 2; z++) { @@ -2340,7 +2374,7 @@ if (t >= self->texs || (t && !self->tex [t].name)) { - XPUSHs (sv_2mortal (newSViv (t))); + PUSHs (sv_2mortal (newSViv (t))); need_texid (self, t); }