renderbug-cpp/lib/Figments/Figment.h

54 lines
1.4 KiB
C
Raw Normal View History

2019-05-10 05:17:29 +00:00
#pragma once
2021-03-29 08:10:55 +00:00
#include <Arduino.h>
2019-05-10 05:17:29 +00:00
#include <functional>
2021-03-29 08:10:55 +00:00
#include <ArduinoLog.h>
2019-05-10 05:17:29 +00:00
class Display;
class InputEvent;
class InputSource;
2021-03-28 01:19:55 +00:00
struct Loopable {
2019-05-10 05:17:29 +00:00
virtual void handleEvent(const InputEvent& event) {}
virtual void loop() = 0;
2021-03-28 01:19:55 +00:00
};
struct Task : public virtual Loopable {
2019-05-10 05:17:29 +00:00
virtual void onStart() {};
virtual void onStop() {};
enum State {
Running,
Stopped,
};
Task() {}
Task(State initialState) : Task(0, initialState) {}
Task(const char* name) : Task(name, Running) {}
Task(const char* name, State initialState) : name(name), state(initialState) {}
2021-03-29 08:10:55 +00:00
void start() { state = Running; onStart(); }
void stop() { onStop(); state = Stopped; }
2021-03-28 01:19:55 +00:00
virtual bool isFigment() const { return false; }
2019-05-10 05:17:29 +00:00
const char* name = 0;
State state = Running;
};
struct Figment: public Task {
Figment() : Task() {}
Figment(State initialState) : Task(initialState) {}
Figment(const char* name) : Task(name) {}
Figment(const char* name, State initialState) : Task(name, initialState) {}
virtual void render(Display* dpy) const = 0;
2021-03-28 01:19:55 +00:00
bool isFigment() const override { return true; }
2019-05-10 05:17:29 +00:00
};
struct FigmentFunc: public Figment {
FigmentFunc(std::function<void(Display*)> func) : Figment("lambda"), func(func) {}
void loop() override {}
void render(Display* dpy) const override {
func(dpy);
}
std::function<void(Display*)> func;
};