Hi,

Just wanted to point to some sort of discrepancy with Fl::event_inside(const 
Fl_Widget*) I recently noticed.

I was using it from within a handle() of a class derived from Fl_Window and 
found, that it didn't work as expected.

Either there is some discrepancy between the coordinate system 
Fl::event_inside() uses with the Fl::event_x()/y() coordinate system uses.

Or it is simply never meant to be used for container type widgets, which means 
the documentation should be made clearer in this aspect.

I have made a small source example for this case:

--- snip ---
#include <FL/Fl_Window.H>
#include <FL/Fl.H>
#include <stdio.h>

// The way Fl::event_inside() should be implemeted?
static int event_inside(const Fl_Widget *o) /*const*/ {
  int mx = /*e_x*/Fl::event_x();  // no access to e_x
  int my = /*e_y*/Fl::event_y();  // no access to e_y
  if (o->type() < FL_WINDOW) {
    mx -= o->x();
    my -= o->y();
  }
  return (mx >= 0 && mx < o->w() && my >= 0 && my < o->h());
}

// just for making debug output more readable...
static const char* colorname(Fl_Color c)
{Now I have made a small demo class, that shoes what i mean.
  switch (c)
  {
    case FL_GREEN:
      return "GREEN";
    case FL_RED:
      return "RED";
    default:
      return "unknown";
  }
}

class SubWin : public Fl_Window
{
public:
  SubWin( int x_, int y_, int w_, int h_ ) :
    Fl_Window( x_, y_, w_, h_ )
  {
  }
  virtual int handle( int e_ )
  {
    switch ( e_ )
    {
      case FL_PUSH:
        printf( "FL_PUSH %p: x=%d y=%d Fl::event_x()=%d Fl::event_y()=%d\n",
                this, x(), y(), Fl::event_x(), Fl::event_y() );
        if ( Fl::event_inside( this ) )
        {
          // doesn't work if you push in the top/left areas of the subwins
          // because Fl_event_x/y() counts coordinates relative to subwin,
          // wheras Fl::event_inside() uses coordinates relative to parent 
window.
          printf( "Fl::event_inside(): pushed inside %s canvas (%p)\n", 
colorname(color()), this );
        }
        if ( /*Fl::*/event_inside( this ) )
        {
          // works as expected
          printf( "event_inside(): pushed inside %s canvas (%p)\n", 
colorname(color()), this );
        }
        break;
      case FL_RELEASE:
        printf("\n");
        break;
    }
    return Fl_Window::handle( e_ );
  }
};

int main( int argc_, const char *argv_[] )
{
  Fl_Window win( 640, 480, "event_inside TEST" );
  SubWin subwin( 100, 100, 300, 200 );
  subwin.color( FL_GREEN );
  SubWin subwin2( 30, 30, 100, 100 );
  subwin2.color( FL_RED );
  subwin2.end();
  win.show();
  return Fl::run();
}
--- snip ---
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to