class::ui::EventLoop

class ui::EventLoop
  : public ev::EventLoop

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(

ui::Element & start_element,
sgfx::Bitmap & bitmap,
sgfx::Bitmap * scratch
)

virtual Element * catch_null_handler(

Element * last_element
)

Element * current_element() const

draw::DrawingAttr & drawing_attr()

virtual void loop()

void set_current_element(

Element * v
)

void set_drawing_attr(

const draw::DrawingAttr & attributes
)

void set_drawing_attributes(

const draw::DrawingAttr & attributes
)

virtual void start()

static Element * handle_event(

Element * current_element,
const Event & event,
const draw::DrawingAttr & drawing_attr,
EventLoop * event_loop
)

static void handle_transition(

Element * current_element,
Element * next_element,
const draw::DrawingAttr & drawing_attr
)

static void start(

ui::Element * element,
const draw::DrawingAttr & drawing_attr
)

protected virtual bool handle_event(

const ui::Event & event
)

Members

EventLoop(

ui::Element & start_element,
sgfx::Bitmap & bitmap,
sgfx::Bitmap * scratch
)

Constructs a new event loop.

Parameters

  • start_element The initial element to process

  • bitmap The bitmap to use for drawing

  • scratch The bitmap used for animations (0 if animations are not used)


virtual Element * catch_null_handler(

Element * last_element
)


Element * current_element() const

Accesses the current element.


draw::DrawingAttr & drawing_attr()

Accesses the drawing attributes.


virtual void loop()

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


void set_current_element(

Element * v
)

Sets the current element.


void set_drawing_attr(

const draw::DrawingAttr & attributes
)


void set_drawing_attributes(

const draw::DrawingAttr & attributes
)

Updates the drawing attributes.


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 Element * handle_event(

Element * current_element,
const Event & event,
const draw::DrawingAttr & drawing_attr,
EventLoop * event_loop
)


static void handle_transition(

Element * current_element,
Element * next_element,
const draw::DrawingAttr & drawing_attr
)


static void start(

ui::Element * element,
const draw::DrawingAttr & drawing_attr
)


protected virtual bool handle_event(

const ui::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());

}

X

Thanks for Coming!

Subscribe to news and updates