--- deliantra/Deliantra-Client/Client.xs 2007/07/19 23:29:16 1.206 +++ deliantra/Deliantra-Client/Client.xs 2007/07/20 18:19:45 1.207 @@ -435,6 +435,46 @@ #define SDLK_MODIFIER_MIN 300 #define SDLK_MODIFIER_MAX 314 +/******************************************************************************/ + +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 @@ -2574,3 +2614,15 @@ void glCallList (int list) +MODULE = CFPlus PACKAGE = CFPlus::UI::Base + +PROTOTYPES: DISABLE + +void +find_widget (SV *widget, NV x, NV y) + PPCODE: +{ + if (within_widget (widget, x, y)) + XPUSHs (widget); +} +