Subsampling an event queue

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Subsampling an event queue

Post by bertolino »

Hello,
I am doing time consuming rendering when the mouse moves a slider control (it updates the content of a panel).
In order to avoid latency due to too many motion events, I'd like to subsample them (i.e. discard some of them, but not just keep the mouse left up event).
Is there a way to do that or is it completely foolish?
Any idea?

Pascal
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Subsampling an event queue

Post by DavidHart »

Hi,

You could override wxApp::FilterEvent in your subclass, and do <whatever> to certain types of mouse events.

An example (looking a key events):

Code: Select all

int MyApp::FilterEvent(wxEvent& event)
{
if (frame && event.GetEventType() == wxEVT_KEY_DOWN)
  { if (((wxKeyEvent&)event).GetKeyCode() == WXK_F1)
      { frame->OnHelpF1((wxKeyEvent&)event); return true; }

    if (((wxKeyEvent&)event).GetKeyCode() == GetEscapeKeycode())
      { int flags = 0;
        if (wxGetKeyState(WXK_CONTROL)) flags |= wxACCEL_CTRL; if (wxGetKeyState(WXK_ALT)) flags |= wxACCEL_ALT; if (wxGetKeyState(WXK_SHIFT)) flags |= wxACCEL_SHIFT;
        if (flags == GetEscapeKeyFlags())
          { frame->DoOnProcessCancelled(); return -1; } // This time return -1 (== Skip()) as other things may use this keypress e.g. DnD
      }
  }

return -1;
}
Regards,

David
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Subsampling an event queue

Post by bertolino »

Hi David,

I think that's what I need. I should be able to do what I want with that. Many thanks for your help and your snippet.
Best regards,

Pascal
Post Reply