> On Tue, 4 Sep 2007, D. Zimmer wrote:
>
> >> void Fl_Image_Button::draw() {
> >> if (value()==0)
> >> {
> >> if (upimage!=NULL) {
> >> this->image(upimage);
> >> }
> >> } else {
> >> if (this->value()==1)
> >> {
> >> if (downimage!=NULL) {
> >> this->image(downimage);
> >> }
> >> }
> >> }
> >> Fl_Button::draw();
> >> }
>
> > I would recommend not setting image(), but instead copying the code for
> > Fl_Button::draw() then drawing the appropriate image yourself (after
> > drawing the box but before drawing the label). This would circumvent
> > the image() and align() settings for your class,
> > and allow you to ensure that the image is always centered and clipped
> > (assuming you want this).
>
> I noticed things don't work properly if I set a label, and the
> Fl_Button::draw() function is small enough to use instead of
> calling the one of Fl::button, but I'm not sure I anderstand
> what you're saying. Also, I'm not sure how to draw an image- or would it
> work just call Fl_Image::draw()? Otherwise, I'd be interested to see how
> you would solve it.
>
> Best,
> Marc
>
This is what I meant:
#include <FL/fl_draw.H>
void Fl_Image_Button::draw()
{
// begin - Fl_Button::draw() (box section)
if (type() == FL_HIDDEN_BUTTON) return;
Fl_Color col = value() ? selection_color() : color();
draw_box(value() ? (down_box()?down_box():fl_down(box())) : box(), col);
// end - Fl_Button::draw() (box section)
// begin - modification to render up/down image
Fl_Boxtype box_;
Fl_Image *pic_;
if(value())
{
box_ = (down_box())? down_box() : fl_down(box());
pic_ = downimage;
}
else
{
box_ = box();
pic_ = upimage;
}
if(pic_)
{
int xx = x() + Fl::box_dx(box_);
int yy = y() + Fl::box_dy(box_);
int ww = w() - Fl::box_dw(box_);
int hh = h() - Fl::box_dh(box_);
int xpos = (ww - pic_->w()) / 2;
int ypos = (hh - pic_->h()) / 2;
fl_push_clip(xx, yy, ww, hh);
pic_->draw(xx + xpos, yy + ypos);
fl_pop_clip();
}
// end- modification to render up/down image
// begin - Fl_Button::draw() (label section)
if (labeltype() == FL_NORMAL_LABEL && value()) {
Fl_Color c = labelcolor();
labelcolor(fl_contrast(c, col));
draw_label();
labelcolor(c);
} else draw_label();
if (Fl::focus() == this) draw_focus();
// end - Fl_Button::draw() (label section)
}
Here is a complete test program:
http://www.magma.ca/~dzimmer/code/image_button_test.zip
Don.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk