From ddbfc13e55587f1f4e8a459d290682529e6cc8b9 Mon Sep 17 00:00:00 2001 From: MatthewColvin Date: Tue, 10 Oct 2023 13:37:16 -0500 Subject: [PATCH] Update SDLDisplay so it finds the window based on events that way it works on windows and Ubuntu --- .../HAL/Targets/Simulator/SDLDisplay.cpp | 52 +++++++++---------- .../HAL/Targets/Simulator/SDLDisplay.hpp | 28 +++++----- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp b/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp index 461cf61..1552e7d 100644 --- a/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp +++ b/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp @@ -1,39 +1,39 @@ #include "SDLDisplay.hpp" #include "sdl/sdl.h" -#include +#include -std::shared_ptr SDLDisplay::getInstance(){ - if (!DisplayAbstract::mInstance){ - DisplayAbstract::mInstance = std::shared_ptr(new SDLDisplay()); - } - return std::static_pointer_cast(mInstance); +std::shared_ptr SDLDisplay::getInstance() { + if (!DisplayAbstract::mInstance) { + DisplayAbstract::mInstance = std::shared_ptr(new SDLDisplay()); + } + return std::static_pointer_cast(mInstance); } -void SDLDisplay::setBrightness(uint8_t brightness){ - mBrightness = brightness; +void SDLDisplay::setBrightness(uint8_t brightness) { mBrightness = brightness; } + +uint8_t SDLDisplay::getBrightness() { return mBrightness; } + +void SDLDisplay::turnOff() {} + +void SDLDisplay::flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, + lv_color_t *color_p) { + sdl_display_flush(disp, area, color_p); } -uint8_t SDLDisplay::getBrightness(){ - return mBrightness; +void SDLDisplay::screenInput(lv_indev_drv_t *indev_driver, + lv_indev_data_t *data) { + sdl_mouse_read(indev_driver, data); } -void SDLDisplay::turnOff(){ - +void SDLDisplay::setTitle(std::string aNewTitle) { + SDL_SetWindowTitle(mSimWindow, aNewTitle.c_str()); } -void SDLDisplay::flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p){ - sdl_display_flush(disp,area,color_p); -} +SDLDisplay::SDLDisplay() : DisplayAbstract() { + sdl_init(); -void SDLDisplay::screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data){ - sdl_mouse_read(indev_driver,data); -} - -void SDLDisplay::setTitle(std::string aNewTitle){ - SDL_SetWindowTitle(mSimWindow,aNewTitle.c_str()); -} - -SDLDisplay::SDLDisplay(): DisplayAbstract() { - sdl_init(); - mSimWindow = SDL_GetWindowFromID(1); // Get the SDL window via ID hopefully it is always 1... + // Get the SDL window via an event + SDL_Event aWindowIdFinder; + SDL_PollEvent(&aWindowIdFinder); + mSimWindow = SDL_GetWindowFromID(aWindowIdFinder.window.windowID); } \ No newline at end of file diff --git a/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp b/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp index 98f58b2..f88c189 100644 --- a/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp +++ b/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp @@ -1,25 +1,27 @@ #pragma once -#include -#include "SDL2/SDL.h" #include "DisplayAbstract.h" +#include "SDL2/SDL.h" +#include -class SDLDisplay : public DisplayAbstract{ +class SDLDisplay : public DisplayAbstract { public: - static std::shared_ptr getInstance(); + static std::shared_ptr getInstance(); - virtual void setBrightness(uint8_t brightness) override; - virtual uint8_t getBrightness() override; - virtual void turnOff() override; + virtual void setBrightness(uint8_t brightness) override; + virtual uint8_t getBrightness() override; + virtual void turnOff() override; - void setTitle(std::string aNewTitle); + void setTitle(std::string aNewTitle); protected: - virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) override; - virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override; + virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, + lv_color_t *color_p) override; + virtual void screenInput(lv_indev_drv_t *indev_driver, + lv_indev_data_t *data) override; private: - SDLDisplay(); - uint8_t mBrightness; - SDL_Window* mSimWindow; + SDLDisplay(); + uint8_t mBrightness; + SDL_Window *mSimWindow; }; \ No newline at end of file