> > Is it possible to detect when the fl_repeat_button is 
> > 'repeating'? I need 
> > to be able to distinguish between the repeating behaviour on 
> > click-and-hold, and users simply clicking the button very quickly.
> 
> I don't think so... However, the actual code for fl_repeat_button is
> pretty small, so I guess it would be easy to create your own 
> version (I
> think maybe a subclass wouldn't be enough...), and simply have the
> repeat_callback set a flag each time it fires the callback... 
> Something
> like that could work...

Yes - this seems to work well enough...


#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>

#include <stdio.h>

#define INITIALREPEAT .5
#define REPEAT .1

class tst_rpt_btn : public Fl_Button {
  static void repeat_callback(void *);
public:
  int handle(int);
  int rpt;

  tst_rpt_btn(int X,int Y,int W,int H,const char *l=0)
    : Fl_Button(X,Y,W,H,l) {rpt = 0;}
  void deactivate() {
    Fl::remove_timeout(repeat_callback,this);
    Fl_Button::deactivate();
  }
};

void tst_rpt_btn::repeat_callback(void *v) {
  tst_rpt_btn *b = (tst_rpt_btn*)v;
  Fl::add_timeout(REPEAT,repeat_callback,b);
  b->rpt = -1;
  b->do_callback();
  b->rpt = 0;
}

int tst_rpt_btn::handle(int event) {
  int newval;
  switch (event) {
  case FL_HIDE:
  case FL_DEACTIVATE:
  case FL_RELEASE:
    newval = 0; goto J1;
  case FL_PUSH:
  case FL_DRAG:
    if (Fl::visible_focus()) Fl::focus(this);
    newval = Fl::event_inside(this);
  J1:
    if (!active()) 
      newval = 0;
    if (value(newval)) {
      if (newval) {
        Fl::add_timeout(INITIALREPEAT,repeat_callback,this);
        do_callback();
      } else {
        Fl::remove_timeout(repeat_callback,this);
      }
    }
    return 1;
  default:
    return Fl_Button::handle(event);
  }
}

void rpt_cb(Fl_Button*, void *v) {
        tst_rpt_btn *bt1 = (tst_rpt_btn *)v;
        if(bt1->rpt) {
                puts("RPT"); fflush(stdout);
        } else {
                puts("CLICK"); fflush(stdout);
        }
}

void ex_cb(Fl_Button*, void *v) {
        Fl_Window *win = (Fl_Window *)v;
        win->hide();
}

int main(int argc, char**argv)
{
        Fl_Window *win = new Fl_Window(300, 300, "button test");
        win->begin();
        tst_rpt_btn *bt1 = new tst_rpt_btn(10, 10, 60, 35, "Repeat");
        bt1->callback((Fl_Callback*)rpt_cb, bt1);
        
        Fl_Button *ex = new Fl_Button(230, 255, 60, 35, "EXIT");
        ex->callback((Fl_Callback*)ex_cb, win);
        
        win->end();
        
        win->show(argc, argv);
        return Fl::run();
}
/* end of file */









SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

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

Reply via email to