desktop code refactoring
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
---
|
||||
BasedOnStyle: Chromium
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
|
@@ -45,14 +45,14 @@ include_dependency(u8g2 https://github.com/olikraus/u8g2 1e92781)
|
||||
add_subdirectory(components)
|
||||
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/include/Version.h.in"
|
||||
"${PROJECT_BINARY_DIR}/include/Version.h"
|
||||
"${CMAKE_SOURCE_DIR}/Version.h.in"
|
||||
"${CMAKE_SOURCE_DIR}/Version.h"
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_INCLUDE_PATH}
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${PROJECT_BINARY_DIR}/include
|
||||
${PROJECT_BINARY_DIR}/src
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
|
@@ -1,11 +1,15 @@
|
||||
## Systen Control
|
||||
|
||||
### ESP32-S3
|
||||
### ESP32-S3 (folder: main)
|
||||
|
||||
This is an implementation of my custom system control project (custom pcb with Lolin ESP32-S3 Mini) and LED strip.
|
||||
|
||||
The build process is straight forward with ESP-IDF. We used version 5.4 while development and the github actions tried to compile for multiple ESP-IDF versions, so we are safe.
|
||||
|
||||
### Desktop
|
||||
### Desktop (folder: src)
|
||||
|
||||
It's included also a desktop application (with SDL3), so you can test the project without any MCU.
|
||||
|
||||
### Global Information
|
||||
|
||||
The projects can be generated from the root, because here is the starting CMakeLists.txt file.
|
||||
|
@@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "../model/AppContext.h"
|
||||
|
||||
namespace DebugOverlay {
|
||||
inline bool show_debug_window = false;
|
||||
inline bool show_unhandled_events = false;
|
||||
inline bool show_led_matrix = true;
|
||||
|
||||
void init(const AppContext *context);
|
||||
|
||||
void update(AppContext *context, const SDL_Event *event);
|
||||
|
||||
void render(const AppContext *context);
|
||||
|
||||
void cleanup();
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "SDL3_ttf/SDL_ttf.h"
|
||||
#include "Window.h"
|
||||
|
||||
class Matrix;
|
||||
|
||||
class AppContext {
|
||||
public:
|
||||
explicit AppContext(const Window *window) : m_window(window) {
|
||||
m_font_default = TTF_OpenFont(
|
||||
"assets/haxrcorp-4089.otf", 21);
|
||||
m_font_text = TTF_OpenFont(
|
||||
"assets/Helvetica-Bold.otf", 21);
|
||||
}
|
||||
|
||||
~AppContext() {
|
||||
TTF_CloseFont(m_font_default);
|
||||
TTF_CloseFont(m_font_text);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto window() const -> SDL_Window *;
|
||||
|
||||
[[nodiscard]] auto renderer() const -> SDL_Renderer *;
|
||||
|
||||
[[nodiscard]] auto surface() const -> SDL_Surface *;
|
||||
|
||||
void setMatrix(Matrix *matrix);
|
||||
|
||||
[[nodiscard]] auto matrix() const -> Matrix *;
|
||||
|
||||
[[nodiscard]] auto matrix_window() const -> SDL_Window *;
|
||||
|
||||
[[nodiscard]] auto matrix_renderer() const -> SDL_Renderer *;
|
||||
|
||||
void matrix_render() const;
|
||||
|
||||
TTF_Font *m_font_default = nullptr;
|
||||
|
||||
private:
|
||||
const Window *m_window;
|
||||
Matrix *m_matrix = nullptr;
|
||||
TTF_Font *m_font_text = nullptr;
|
||||
};
|
@@ -1,12 +1,11 @@
|
||||
#include "debug/DebugOverlay.h"
|
||||
|
||||
#include <imgui_impl_sdlrenderer3.h>
|
||||
#include "Common.h"
|
||||
#include "Version.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include <imgui_impl_sdlrenderer3.h>
|
||||
|
||||
#include "Common.h"
|
||||
#include "ui/Matrix.h"
|
||||
#include "Version.h"
|
||||
|
||||
namespace DebugOverlay {
|
||||
void init(const AppContext* context) {
|
||||
@@ -78,4 +77,4 @@ namespace DebugOverlay {
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
}
|
||||
} // namespace DebugOverlay
|
||||
|
19
src/debug/DebugOverlay.h
Normal file
19
src/debug/DebugOverlay.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "model/AppContext.h"
|
||||
|
||||
namespace DebugOverlay {
|
||||
inline bool show_debug_window = false;
|
||||
inline bool show_unhandled_events = false;
|
||||
inline bool show_led_matrix = true;
|
||||
|
||||
void init(const AppContext* context);
|
||||
|
||||
void update(AppContext* context, const SDL_Event* event);
|
||||
|
||||
void render(const AppContext* context);
|
||||
|
||||
void cleanup();
|
||||
}
|
43
src/model/AppContext.h
Normal file
43
src/model/AppContext.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "SDL3_ttf/SDL_ttf.h"
|
||||
#include "Window.h"
|
||||
|
||||
class Matrix;
|
||||
|
||||
class AppContext {
|
||||
public:
|
||||
explicit AppContext(const Window* window)
|
||||
: m_window(window) {
|
||||
m_font_default = TTF_OpenFont("assets/haxrcorp-4089.otf", 21);
|
||||
m_font_text = TTF_OpenFont("assets/Helvetica-Bold.otf", 21);
|
||||
}
|
||||
|
||||
~AppContext() {
|
||||
TTF_CloseFont(m_font_default);
|
||||
TTF_CloseFont(m_font_text);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto window() const -> SDL_Window*;
|
||||
|
||||
[[nodiscard]] auto renderer() const -> SDL_Renderer*;
|
||||
|
||||
[[nodiscard]] auto surface() const -> SDL_Surface*;
|
||||
|
||||
void setMatrix(Matrix* matrix);
|
||||
|
||||
[[nodiscard]] auto matrix() const -> Matrix*;
|
||||
|
||||
[[nodiscard]] auto matrix_window() const -> SDL_Window*;
|
||||
|
||||
[[nodiscard]] auto matrix_renderer() const -> SDL_Renderer*;
|
||||
|
||||
void matrix_render() const;
|
||||
|
||||
TTF_Font* m_font_default = nullptr;
|
||||
|
||||
private:
|
||||
const Window* m_window;
|
||||
Matrix* m_matrix = nullptr;
|
||||
TTF_Font* m_font_text = nullptr;
|
||||
};
|
@@ -5,7 +5,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "UIWidget.h"
|
||||
#include "../model/AppContext.h"
|
||||
#include "model/AppContext.h"
|
||||
#include "common/Widget.h"
|
||||
|
||||
class Device final : public UIWidget {
|
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "../model/Window.h"
|
||||
|
||||
#include "model/Window.h"
|
||||
|
||||
class Matrix {
|
||||
public:
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../model/AppContext.h"
|
||||
#include "model/AppContext.h"
|
||||
|
||||
class UIWidget {
|
||||
public:
|
@@ -21,8 +21,10 @@ Button::Button(
|
||||
}
|
||||
|
||||
void Button::render() const {
|
||||
const auto button = ResourceManager::getInstance().get_texture(get_context()->renderer(), "assets/button_normal.png");
|
||||
const auto overlay =ResourceManager::getInstance().get_texture(get_context()->renderer(), "assets/button_pressed_overlay.png");
|
||||
const auto button = ResourceManager::getInstance().get_texture(
|
||||
get_context()->renderer(), "assets/button_normal.png");
|
||||
const auto overlay = ResourceManager::getInstance().get_texture(
|
||||
get_context()->renderer(), "assets/button_pressed_overlay.png");
|
||||
|
||||
const auto dst = SDL_FRect(m_x, m_y, m_width, m_width);
|
||||
SDL_RenderTexture(get_context()->renderer(), button, nullptr, &dst);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../UIWidget.h"
|
||||
#include "ui/UIWidget.h"
|
||||
|
||||
#include <functional>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "ui/widgets/D_Pad.h"
|
||||
|
||||
#include <ResourceManager.h>
|
||||
#include "ResourceManager.h"
|
||||
|
||||
D_Pad::D_Pad(
|
||||
void* appState,
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "functional"
|
||||
|
||||
#include "ui/UIWidget.h"
|
||||
|
||||
#define DPAD_WIDTH (105)
|
Reference in New Issue
Block a user