class::ev::EventLoop

class ev::EventLoop
  : public ev::EventLoopAttributes
  : public api::WorkObject

This class executes an event loop. The events are passed to the current_element() and handled using Element::handle_event(). If Element::handle_event() returns a pointer to a new element, the event loop will Event::EXIT the current element and Event::ENTER the new element and execute an animation to the new event.

The EventLoop is an abstract class, and you must implement the process_events() method which needs to process user events that are specific to the system.

ui::ButtonPin select_button(0,1); //select button is on pin 0.1

MyEventLoop::MyEventLoop(ui::Element & start_element, sgfx::Bitmap & bitmap, sgfx::Bitmap * scratch) :
   EventLoop(start_element, bitmap, scratch){
}

void MyEventLoop::process_events() {
   select_button.update();
   handle_event(select_button.event());
}

Summary

EventLoop(

EventHandler & start_event_handler
)

virtual EventHandler * catch_null_handler(

EventHandler * last_event_handler
)

EventHandler * current_event_handler() const

virtual void execute()

virtual void loop()

void process_events()

void set_current_event_handler(

EventHandler * v
)

virtual void start()

static EventHandler * handle_event(

EventHandler * current_event_handler,
const Event & event,
EventLoop * event_loop
)

static void handle_transition(

EventHandler * current_event_handler,
EventHandler * next_event_handler
)

static void start(

EventHandler * event_handler
)

protected void check_loop_for_hibernate()

protected void check_loop_for_update()

protected virtual bool handle_event(

const Event & event
)

protected chrono::Timer & loop_timer()

protected chrono::Timer & update_timer()

Members

EventLoop(

EventHandler & start_event_handler
)

Constructs a new headless (no display) event loop.

Parameters

  • start_event_handler The initial element to process

The EventLoop will typically update the display when the current_element() indicates that it should. By initializing an EventLoop using this constructor the display is ignored.


virtual EventHandler * catch_null_handler(

EventHandler * last_event_handler
)

Is executed when the event handler returns a null event and the current event is set to null.

Parameters

  • last_event_handler The event handler that returned a null handler.

The default behavior is to exit from the EventLoop (execute() method). This method can be reimplemented by the application to update the event handler based on the value and state of last_event_handler.


EventHandler * current_event_handler() const

Accesses the current event handler.


virtual void execute()

Executes the event loop.

First the event loop will have the current ev::EventHandler handle Event::SETUP.

The loop will then transition to the initial ev::EventHandler and execute Event::ENTER.

The loop will then fire Event::UPDATE every update_period(). If hibernation_threshold() is less than update_period(), the loop will attempt to put the processor in hibernation periodically to save power.

If period() is less then hibernation_threshold(), the loop will execute process_events() every period().

If EventHandler::handle_event() returns a pointer to a new EventHandler, a transtion will occur which includes:

The loop will then continue to process_events() and fire Event::UPDATE as well as hibernate as appropriate for the new element.

If EventHandler::handle_event() returns 0 (null pointer), the event loop will stop executing. That is this method will return.


virtual void loop()

Loops while the current element is valid. It handles sending events to the active element. See execute() for more details.


void process_events()

This method should call handle_event for each possible event in the event loop.

Button * up_button;
Button * down_button;

void MyEventLoop::process_events(){

   handle_event(up_button->event());
   handle_event(down_button->event());
   //call handle event on any other events -- Event loop handles SETUP, ENTER, and UPDATE

}

void set_current_event_handler(

EventHandler * v
)

Sets the current event handler.


virtual void start()

This is called just before the loop starts executing. This method will send the Event::SETUP and Event::ENTER events to the primary element.


static EventHandler * handle_event(

EventHandler * current_event_handler,
const Event & event,
EventLoop * event_loop
)


static void handle_transition(

EventHandler * current_event_handler,
EventHandler * next_event_handler
)


static void start(

EventHandler * event_handler
)


protected void check_loop_for_hibernate()

protected void check_loop_for_update()

protected virtual bool handle_event(

const Event & event
)

Handles the specified event.

Parameters

  • event Event to handle within the loop

This method should be called by process_events() whenever the system triggers an event. For example, if the system needs to just handle an up button or down button press:

#include <sapi/hal.hpp>

ButtonPin up_button(0,0);
ButtonPin down_button(0,1)

void MyEventLoop::process_events(){
 up_button.update(); //refresh button status
 down_button.update();

 handle_event(up_button.event());
 handle_event(down_button.event());

}

protected chrono::Timer & loop_timer()

protected chrono::Timer & update_timer()

X

Thanks for Coming!

Subscribe to news and updates