more modules for the MCU code
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
#include <ranges>
|
||||
|
||||
ResourceManager& ResourceManager::getInstance() {
|
||||
static ResourceManager instance;
|
||||
@@ -10,13 +11,13 @@ ResourceManager& ResourceManager::getInstance() {
|
||||
}
|
||||
|
||||
ResourceManager::ResourceManager() {
|
||||
SDL_Log("ResourceManager instance created.");
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "ResourceManager instance created.");
|
||||
}
|
||||
|
||||
ResourceManager::~ResourceManager() {
|
||||
for(const auto& pair : m_textures) {
|
||||
if(pair.second != nullptr) {
|
||||
SDL_DestroyTexture(pair.second);
|
||||
for(const auto& texture : m_textures | std::views::values) {
|
||||
if(texture != nullptr) {
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
m_textures.clear();
|
||||
@@ -32,11 +33,14 @@ SDL_Texture* ResourceManager::get_texture(SDL_Renderer* renderer, const std::str
|
||||
SDL_Texture* texture = IMG_LoadTexture(renderer, path.c_str());
|
||||
|
||||
if(!texture) {
|
||||
std::cerr << "ResourceManager Fehler: Konnte Textur nicht laden '" << path << std::endl;
|
||||
SDL_LogError(
|
||||
SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Could not load %s -> %s",
|
||||
path.c_str(),
|
||||
SDL_GetError());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m_textures[path] = texture;
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
10
src/Version.h
Normal file
10
src/Version.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "string"
|
||||
|
||||
const std::string MyProject = "system_control";
|
||||
const std::string MyProjectVersion = "0.0.1";
|
||||
constexpr uint8_t MyProjectVersionMajor = 0;
|
||||
constexpr uint8_t MyProjectVersionMinor = 0;
|
||||
constexpr uint8_t MyProjectVersionPatch = 1;
|
||||
const std::string MyProjectBuildDate = "";
|
@@ -1,7 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#define MY_VERSION "@PROJECT_VERSION@"
|
||||
#define MY_PROJECT "@PROJECT_NAME@"
|
||||
#define MY_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
||||
#define MY_VERSION_MINOR @PROJECT_VERSION_MINOR@
|
||||
#define MY_VERSION_PATCH @PROJECT_VERSION_PATCH@
|
||||
#include "string"
|
||||
|
||||
const std::string MyProject = "@PROJECT_NAME@";
|
||||
const std::string MyProjectVersion = "@PROJECT_VERSION@";
|
||||
constexpr uint8_t MyProjectVersionMajor = @PROJECT_VERSION_MAJOR@;
|
||||
constexpr uint8_t MyProjectVersionMinor = @PROJECT_VERSION_MINOR@;
|
||||
constexpr uint8_t MyProjectVersionPatch = @PROJECT_VERSION_PATCH@;
|
||||
const std::string MyProjectBuildDate = "@PROJECT_BUILD_DATE@";
|
||||
|
@@ -58,8 +58,9 @@ void render(const AppContext* context) {
|
||||
if(ImGui::BeginMenu("Help")) {
|
||||
ImGui::Text("FPS: %.2f", ImGui::GetIO().Framerate);
|
||||
ImGui::SeparatorText("App Info");
|
||||
ImGui::Text("Project: %s", MY_PROJECT);
|
||||
ImGui::Text("Version: %s", MY_VERSION);
|
||||
ImGui::Text("Project: %s", MyProject.c_str());
|
||||
ImGui::Text("Version: %s", MyProjectVersion.c_str());
|
||||
ImGui::Text("Build Date: %s", MyProjectBuildDate.c_str());
|
||||
ImGui::Text("ImGui Version: %s", ImGui::GetVersion());
|
||||
|
||||
ImGui::EndMenu();
|
||||
|
18
src/main.cc
18
src/main.cc
@@ -18,7 +18,8 @@
|
||||
#include "ui/widgets/D_Pad.h"
|
||||
|
||||
constexpr unsigned int WINDOW_WIDTH =
|
||||
(U8G2_SCREEN_WIDTH * U8G2_SCREEN_FACTOR + 3 * U8G2_SCREEN_PADDING + 2 * BUTTON_WIDTH + DPAD_WIDTH + 2 * U8G2_SCREEN_PADDING);
|
||||
(U8G2_SCREEN_WIDTH * U8G2_SCREEN_FACTOR + 3 * U8G2_SCREEN_PADDING + 2 * BUTTON_WIDTH +
|
||||
DPAD_WIDTH + 2 * U8G2_SCREEN_PADDING);
|
||||
constexpr unsigned int WINDOW_HEIGHT = (U8G2_SCREEN_HEIGHT * U8G2_SCREEN_FACTOR + 50);
|
||||
|
||||
std::shared_ptr<Device> device;
|
||||
@@ -26,19 +27,21 @@ std::vector<std::shared_ptr<UIWidget>> widgets;
|
||||
|
||||
SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
|
||||
if(SDL_Init(SDL_INIT_VIDEO) == false) {
|
||||
SDL_ShowSimpleMessageBox(
|
||||
SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), nullptr);
|
||||
SDL_LogError(
|
||||
SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL! -> $s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
if(TTF_Init() == false) {
|
||||
SDL_ShowSimpleMessageBox(
|
||||
SDL_MESSAGEBOX_ERROR, "Couldn't initialize TTF", SDL_GetError(), nullptr);
|
||||
SDL_LogError(
|
||||
SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize TTF! -> %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
const auto win = createWindow("System Control (Simulator)", WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
if(!win) {
|
||||
SDL_LogError(
|
||||
SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window! -> %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
SDL_SetRenderVSync(win->renderer(), SDL_RENDERER_VSYNC_ADAPTIVE);
|
||||
@@ -100,6 +103,9 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
||||
case SDLK_BACKSPACE:
|
||||
device->onButtonClicked(BUTTON_BACK);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -115,7 +121,7 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
||||
|
||||
default: {
|
||||
if(DebugOverlay::show_unhandled_events) {
|
||||
SDL_Log("Unused event: %d", event->type);
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Unused event: %d", event->type);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user