MacArthur, Ian (SELEX GALILEO, UK) wrote:
> 
>> My proposal for such an inner_box() method is:
>>
>> virtual Fl_Widget::inner_box(int X, int Y, int W, int H);
>>
>> It should be virtual, so that a widget with a custom draw
>> method can override the default method to provide its own
>> correct inner_box() values. The default implementation would
>> be as proposed above.
>>
>> Maybe there could be an additional optional argument (flag)
>> to return the inside area of the scrollbars instead:
>>
>> virtual Fl_Widget::inner_box(int X, int Y, int W, int H, int 
>> scroll=0);
>>
>> Fl_Scroll would then implement this method to account for the
>> scrollbars, if scroll=1.
> 
> Like the sound of that. +1

Okay, let's see if we can make it even better and extensible.

enum Fl_Area {
   FL_AREA_BOX = 0,     ///< the widget's box
   FL_AREA_INNER,       ///< the area inside the frame
   FL_AREA_SCROLL,      ///< the area inside the scrollbars
   FL_AREA_LABEL,       ///< the label box
   FL_AREA_IMAGE,       ///< the image area
   FL_AREA_DEIMAGE,     ///< the inactive image area
   ...
   FL_AREA_USER0 = 100, ///< user-specific area
   FL_AREA_USER1,       ///< user-specific area
   ...
};

/***
   Returns one of many different widget areas.

   This method can be used to get the coordinates of some
   widget areas. ...

   This is a virtual method. The default Fl_Widget implementation
   returns the x/y coordinates, width and height of the widget's
   box, etc. If there is no label, then the value defaults to the
   inner box (inside the box frame).

   You can implement your own versions for derived classes, if you
   have special needs, e.g. custom drawing methods with special
   frame sizes.

   Your implementation should test for special cases and return
   sensible values, if the \p what value is known, and otherwise
   call the base class's implementation.

   \p what values below \p FL_AREA_USER0 are reserved for FLTK
   extensions, values starting with \p FL_AREA_USER0 can be defined
   for special cases of derived classes.

   \returns if the area is known or defaulted
   \retval 1 success, the returned values are precise
   \retval 0 unknown or unrecognized area, values defaulted
*/

virtual int Fl_Widget::widget_area(int X, int Y, int W, int H,
  Fl_Area what=FL_AREA_BOX);

Implementation (untested and incomplete):

int Fl_Widget::widget_are(int X, int Y, int W, int H,
    Fl_Area what=FL_AREA_BOX)
{
   int ret = 0;
   switch (what) {
     case FL_AREA_INNER:
     case FL_AREA_SCROLL:
       X = x() + Fl::box_dx(box());
       Y = y() + Fl::box_dy(box());
       W = w() - Fl::box_dw(box());
       H = h() - Fl::box_dh(box());
       return 1;
     case FL_AREA_IMAGE:
       if (image_) {
         X = image_->x(); // probably wrong
         Y = image_->y(); // probably wrong
         W = image_->w();
         H = image_->h();
         return 1;
       }
       break;
     case ...: // more ...
       break;
     case FL_AREA_BOX:
       ret = 1;
       break;
     default:
       ret = 0; // undefined area
   }
   // return the widget's box dimensions
   X = x(); Y = y(); W = w(); H = h();
   return ret;
}

Just a thought ...

Albrecht
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to