--- deliantra/Deliantra-Client/Client.xs 2007/07/19 14:54:50 1.204 +++ deliantra/Deliantra-Client/Client.xs 2007/07/29 03:58:26 1.212 @@ -27,6 +27,8 @@ #include #include +#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW + #include #include #include @@ -114,6 +116,8 @@ #include "pango-fontmap.c" #include "pango-render.c" +typedef IV CFPlus__Channel; +typedef SDL_RWops *CFPlus__RW; typedef Mix_Chunk *CFPlus__MixChunk; typedef Mix_Music *CFPlus__MixMusic; @@ -435,6 +439,49 @@ #define SDLK_MODIFIER_MIN 300 #define SDLK_MODIFIER_MAX 314 +/******************************************************************************/ + +static GV *draw_x_gv, *draw_y_gv, *draw_w_gv, *draw_h_gv; +static GV *hover_gv; + +static int +within_widget (SV *widget, NV x, NV y) +{ + HV *self; + SV **svp; + NV wx, ww, wy, wh; + + if (!SvROK (widget)) + return 0; + + self = (HV *)SvRV (widget); + + if (SvTYPE (self) != SVt_PVHV) + return 0; + + svp = hv_fetch (self, "y", 1, 0); wy = svp ? SvNV (*svp) : 0.; + if (y < wy) + return 0; + + svp = hv_fetch (self, "h", 1, 0); wh = svp ? SvNV (*svp) : 0.; + if (y >= wy + wh) + return 0; + + svp = hv_fetch (self, "x", 1, 0); wx = svp ? SvNV (*svp) : 0.; + if (x < wx) + return 0; + + svp = hv_fetch (self, "w", 1, 0); ww = svp ? SvNV (*svp) : 0.; + if (x >= wx + ww) + return 0; + + svp = hv_fetch (self, "can_events", sizeof ("can_events") - 1, 0); + if (!svp || !SvTRUE (*svp)) + return 0; + + return 1; +} + MODULE = CFPlus PACKAGE = CFPlus PROTOTYPES: ENABLE @@ -759,7 +806,7 @@ } int -Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) +Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) POSTCALL: Mix_HookMusicFinished (music_finished); Mix_ChannelFinished (channel_finished); @@ -820,7 +867,7 @@ SDL_Surface *surface, *surface2; SDL_PixelFormat fmt; SDL_RWops *rw = ix - ? SDL_RWFromFile (image, "r") + ? SDL_RWFromFile (image, "rb") : SDL_RWFromConstMem (image, image_len); if (!rw) @@ -935,6 +982,8 @@ MODULE = CFPlus PACKAGE = CFPlus::Font +PROTOTYPES: DISABLE + CFPlus::Font new_from_file (SV *class, char *path, int id = 0) CODE: @@ -954,13 +1003,17 @@ void make_default (CFPlus::Font self) + PROTOTYPE: $ CODE: default_font = self; MODULE = CFPlus PACKAGE = CFPlus::Layout +PROTOTYPES: DISABLE + void reset_glyph_cache () + PROTOTYPE: CODE: tc_clear (); @@ -1257,6 +1310,8 @@ MODULE = CFPlus PACKAGE = CFPlus::Texture +PROTOTYPES: ENABLE + int minpot (int n) void @@ -1343,6 +1398,8 @@ MODULE = CFPlus PACKAGE = CFPlus::Map +PROTOTYPES: DISABLE + CFPlus::Map new (SV *class) CODE: @@ -2181,12 +2238,86 @@ } } +MODULE = CFPlus PACKAGE = CFPlus::RW + +CFPlus::RW +new (SV *class, SV *data_sv) + CODE: +{ + STRLEN datalen; + char *data = SvPVbyte (data_sv, datalen); + + RETVAL = SDL_RWFromConstMem (data, datalen); +} + OUTPUT: + RETVAL + +CFPlus::RW +new_from_file (SV *class, const char *path, const char *mode = "rb") + CODE: + RETVAL = SDL_RWFromFile (path, mode); + OUTPUT: + RETVAL + +void +close (CFPlus::RW self) + CODE: + SDL_RWclose (self); + +MODULE = CFPlus PACKAGE = CFPlus::Channel + +PROTOTYPES: DISABLE + +int +volume (CFPlus::Channel self, int volume) + CODE: + RETVAL = Mix_Volume (self, volume); + OUTPUT: + RETVAL + +int +unregister_all_effects (CFPlus::Channel self) + CODE: + RETVAL = Mix_UnregisterAllEffects (self); + OUTPUT: + RETVAL + +int +set_panning (CFPlus::Channel self, int left, int right) + CODE: + RETVAL = Mix_SetPanning (self, left, right); + OUTPUT: + RETVAL + +int +set_distance (CFPlus::Channel self, int distance) + CODE: + RETVAL = Mix_SetDistance (self, distance); + OUTPUT: + RETVAL + +int +set_position (CFPlus::Channel self, int angle, int distance) + CODE: + RETVAL = Mix_SetPosition (self, angle, distance); + OUTPUT: + RETVAL + +int +set_reverse_stereo (CFPlus::Channel self, int flip) + CODE: + RETVAL = Mix_SetReverseStereo (self, flip); + OUTPUT: + RETVAL + MODULE = CFPlus PACKAGE = CFPlus::MixChunk +PROTOTYPES: DISABLE + CFPlus::MixChunk -new_from_file (SV *class, char *path) +new (SV *class, CFPlus::RW rwops) CODE: - RETVAL = Mix_LoadWAV (path); + RETVAL = Mix_LoadWAV_RW (rwops, 1); OUTPUT: RETVAL @@ -2202,10 +2333,11 @@ OUTPUT: RETVAL -int +CFPlus::Channel play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) CODE: RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); + Mix_UnregisterAllEffects (RETVAL); OUTPUT: RETVAL @@ -2213,6 +2345,7 @@ int volume (int volume = -1) + PROTOTYPE: ;$ CODE: RETVAL = Mix_VolumeMusic (volume); OUTPUT: @@ -2225,10 +2358,15 @@ OUTPUT: RETVAL +void +halt () + CODE: + Mix_HaltMusic (); + CFPlus::MixMusic -new_from_file (SV *class, char *path) +new (SV *class, CFPlus::RW rwops) CODE: - RETVAL = Mix_LoadMUS (path); + RETVAL = Mix_LoadMUS_RW (rwops); OUTPUT: RETVAL @@ -2253,6 +2391,8 @@ MODULE = CFPlus PACKAGE = CFPlus::OpenGL +PROTOTYPES: ENABLE + BOOT: { HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); @@ -2277,6 +2417,7 @@ const_iv (GL_RESCALE_NORMAL), const_iv (GL_FRONT), const_iv (GL_BACK), + const_iv (GL_AUX0), const_iv (GL_AND), const_iv (GL_ONE), const_iv (GL_ZERO), @@ -2332,6 +2473,7 @@ const_iv (GL_CONVOLUTION_2D), const_iv (GL_CONVOLUTION_BORDER_MODE), const_iv (GL_CONSTANT_BORDER), + const_iv (GL_POINTS), const_iv (GL_LINES), const_iv (GL_LINE_STRIP), const_iv (GL_LINE_LOOP), @@ -2340,8 +2482,15 @@ const_iv (GL_TRIANGLES), const_iv (GL_TRIANGLE_STRIP), const_iv (GL_TRIANGLE_FAN), + const_iv (GL_POLYGON), const_iv (GL_PERSPECTIVE_CORRECTION_HINT), + const_iv (GL_POINT_SMOOTH_HINT), + const_iv (GL_LINE_SMOOTH_HINT), + const_iv (GL_POLYGON_SMOOTH_HINT), + const_iv (GL_GENERATE_MIPMAP_HINT), const_iv (GL_FASTEST), + const_iv (GL_DONT_CARE), + const_iv (GL_NICEST), const_iv (GL_V2F), const_iv (GL_V3F), const_iv (GL_T2F_V3F), @@ -2438,6 +2587,8 @@ # near_ and far_ are due to microsofts buggy "c" compiler void glOrtho (double left, double right, double bottom, double top, double near_, double far_) +PROTOTYPES: DISABLE + void glViewport (int x, int y, int width, int height) void glScissor (int x, int y, int width, int height) @@ -2454,12 +2605,7 @@ CODE: glRotatef (angle, x, y, z); -void glBegin (int mode) - -void glEnd () - void glColor (float r, float g, float b, float a = 1.0) - PROTOTYPE: @ ALIAS: glColor_premultiply = 1 CODE: @@ -2472,12 +2618,6 @@ // microsoft visual "c" rounds instead of truncating... glColor4f (r, g, b, a); -void glInterleavedArrays (int format, int stride, char *data) - -void glDrawElements (int mode, int count, int type, char *indices) - -# 1.2 void glDrawRangeElements (int mode, int start, int end - void glRasterPos (float x, float y, float z = 0.) CODE: glRasterPos3f (0, 0, z); @@ -2491,6 +2631,26 @@ CODE: glTexCoord2f (s, t); +void glRect (float x1, float y1, float x2, float y2) + CODE: + glRectf (x1, y1, x2, y2); + +PROTOTYPES: ENABLE + +void glBegin (int mode) + +void glEnd () + +void glPointSize (GLfloat size) + +void glLineWidth (GLfloat width) + +void glInterleavedArrays (int format, int stride, char *data) + +void glDrawElements (int mode, int count, int type, char *indices) + +# 1.2 void glDrawRangeElements (int mode, int start, int end + void glTexEnv (int target, int pname, float param) CODE: glTexEnvf (target, pname, param); @@ -2552,3 +2712,114 @@ void glCallList (int list) +MODULE = CFPlus PACKAGE = CFPlus::UI::Base + +PROTOTYPES: DISABLE + +void +find_widget (SV *self, NV x, NV y) + PPCODE: +{ + if (within_widget (self, x, y)) + XPUSHs (self); +} + +BOOT: +{ + hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); + + draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); + draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); + draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); + draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); +} + +void +draw (SV *self) + CODE: +{ + HV *hv; + SV **svp; + NV x, y, w, h; + SV *draw_x_sv = GvSV (draw_x_gv); + SV *draw_y_sv = GvSV (draw_y_gv); + SV *draw_w_sv = GvSV (draw_w_gv); + SV *draw_h_sv = GvSV (draw_h_gv); + SV *hover; + double draw_x, draw_y, draw_w, draw_h; + + if (!SvROK (self)) + croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); + + hv = (HV *)SvRV (self); + + if (SvTYPE (hv) != SVt_PVHV) + croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); + + svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; + svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; + + if (!h || !w) + XSRETURN_EMPTY; + + svp = hv_fetch (hv, "x", 1, 0); x = svp ? SvNV (*svp) : 0.; + svp = hv_fetch (hv, "y", 1, 0); y = svp ? SvNV (*svp) : 0.; + + draw_x = SvNV (draw_x_sv) + x; + draw_y = SvNV (draw_y_sv) + y; + + if (draw_x + w < 0 || draw_x >= SvNV (draw_w_sv) + || draw_y + h < 0 || draw_y >= SvNV (draw_h_sv)) + XSRETURN_EMPTY; + + sv_setnv (draw_x_sv, draw_x); + sv_setnv (draw_y_sv, draw_y); + + glPushMatrix (); + glTranslated (x, y, 0); + + if (SvROK (GvSV (hover_gv)) && SvRV (GvSV (hover_gv)) == (SV *)hv) + { + svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); + + if (svp && SvTRUE (*svp)) + { + glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); + glEnable (GL_BLEND); + glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + glBegin (GL_QUADS); + glVertex2f (0, 0); + glVertex2f (w, 0); + glVertex2f (w, h); + glVertex2f (0, h); + glEnd (); + glDisable (GL_BLEND); + } + } +#if 0 + if ($ENV{CFPLUS_DEBUG} & 1) { + glPushMatrix; + glColor 1, 1, 0, 1; + glTranslate 0.375, 0.375; + glBegin GL_LINE_LOOP; + glVertex 0 , 0; + glVertex $self->{w} - 1, 0; + glVertex $self->{w} - 1, $self->{h} - 1; + glVertex 0 , $self->{h} - 1; + glEnd; + glPopMatrix; + #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; + } +#endif + PUSHMARK (SP); + XPUSHs (self); + PUTBACK; + call_method ("_draw", G_VOID | G_DISCARD); + SPAGAIN; + + glPopMatrix (); + + draw_x = draw_x - x; sv_setnv (draw_x_sv, draw_x); + draw_y = draw_y - y; sv_setnv (draw_y_sv, draw_y); +} +