--- deliantra/Deliantra-Client/Client.xs 2007/07/20 18:19:45 1.207 +++ deliantra/Deliantra-Client/Client.xs 2007/07/24 18:24:03 1.210 @@ -437,6 +437,9 @@ /******************************************************************************/ +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) { @@ -2388,6 +2391,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), @@ -2396,6 +2400,7 @@ 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), @@ -2500,6 +2505,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) @@ -2516,12 +2523,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: @@ -2534,12 +2536,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); @@ -2553,6 +2549,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); @@ -2619,10 +2635,109 @@ PROTOTYPES: DISABLE void -find_widget (SV *widget, NV x, NV y) +find_widget (SV *self, NV x, NV y) PPCODE: { - if (within_widget (widget, x, y)) - XPUSHs (widget); + 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); }