combine with desktop project
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
42
include/ui/Device.h
Normal file
42
include/ui/Device.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "UIWidget.h"
|
||||
#include "../model/AppContext.h"
|
||||
#include "common/Widget.h"
|
||||
|
||||
class Device final : public UIWidget {
|
||||
public:
|
||||
explicit Device(void* appstate);
|
||||
|
||||
void render() const override;
|
||||
|
||||
void hit_test(SDL_MouseMotionEvent* event) const;
|
||||
|
||||
void onButtonClicked(uint8_t button) const;
|
||||
|
||||
private:
|
||||
void draw_background() const;
|
||||
|
||||
void draw_screen() const;
|
||||
|
||||
void draw_text() const;
|
||||
|
||||
void render_u8g2() const;
|
||||
|
||||
void setScreen(const std::shared_ptr<Widget>& screen);
|
||||
|
||||
void pushScreen(const std::shared_ptr<Widget>& screen);
|
||||
|
||||
void popScreen();
|
||||
|
||||
static void pushKey(SDL_Keycode key);
|
||||
|
||||
std::vector<std::shared_ptr<UIWidget>> m_children{};
|
||||
|
||||
std::shared_ptr<Widget> widget;
|
||||
std::vector<std::shared_ptr<Widget>> history;
|
||||
};
|
16
include/ui/Matrix.h
Normal file
16
include/ui/Matrix.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "../model/Window.h"
|
||||
|
||||
class Matrix {
|
||||
public:
|
||||
explicit Matrix(Window *window);
|
||||
|
||||
[[nodiscard]] Window *window() const;
|
||||
|
||||
void render() const;
|
||||
|
||||
private:
|
||||
void draw_colored_grid(int rows, int cols, float cellSize, float spacing) const;
|
||||
|
||||
Window *m_window;
|
||||
};
|
17
include/ui/UIWidget.h
Normal file
17
include/ui/UIWidget.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "../model/AppContext.h"
|
||||
|
||||
class UIWidget {
|
||||
public:
|
||||
explicit UIWidget(void *appstate);
|
||||
|
||||
virtual ~UIWidget();
|
||||
|
||||
virtual void render() const = 0;
|
||||
|
||||
[[nodiscard]] AppContext *get_context() const;
|
||||
|
||||
private:
|
||||
AppContext *m_context{};
|
||||
};
|
20
include/ui/widgets/Button.h
Normal file
20
include/ui/widgets/Button.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "../UIWidget.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#define BUTTON_WIDTH (35)
|
||||
|
||||
class Button final : public UIWidget {
|
||||
public:
|
||||
Button(void* appState, float x, float y, float width, std::function<void()> callback);
|
||||
|
||||
void render() const override;
|
||||
|
||||
private:
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_width;
|
||||
std::function<void()> m_callback;
|
||||
};
|
20
include/ui/widgets/D_Pad.h
Normal file
20
include/ui/widgets/D_Pad.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "functional"
|
||||
|
||||
#include "ui/UIWidget.h"
|
||||
|
||||
#define DPAD_WIDTH (105)
|
||||
|
||||
class D_Pad final : public UIWidget {
|
||||
public:
|
||||
D_Pad(void* appState, float x, float y, float width, std::function<void(int)> callback);
|
||||
|
||||
void render() const override;
|
||||
|
||||
private:
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_width;
|
||||
std::function<void(int)> m_callback;
|
||||
};
|
Reference in New Issue
Block a user