Update SDLDisplay so it finds the window based on events that way it works on windows and Ubuntu
This commit is contained in:
parent
af7abe115f
commit
ddbfc13e55
2 changed files with 41 additions and 39 deletions
|
@ -1,39 +1,39 @@
|
||||||
#include "SDLDisplay.hpp"
|
#include "SDLDisplay.hpp"
|
||||||
#include "sdl/sdl.h"
|
#include "sdl/sdl.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::shared_ptr<SDLDisplay> SDLDisplay::getInstance(){
|
std::shared_ptr<SDLDisplay> SDLDisplay::getInstance() {
|
||||||
if (!DisplayAbstract::mInstance){
|
if (!DisplayAbstract::mInstance) {
|
||||||
DisplayAbstract::mInstance = std::shared_ptr<SDLDisplay>(new SDLDisplay());
|
DisplayAbstract::mInstance = std::shared_ptr<SDLDisplay>(new SDLDisplay());
|
||||||
}
|
}
|
||||||
return std::static_pointer_cast<SDLDisplay>(mInstance);
|
return std::static_pointer_cast<SDLDisplay>(mInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLDisplay::setBrightness(uint8_t brightness){
|
void SDLDisplay::setBrightness(uint8_t brightness) { mBrightness = 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(){
|
void SDLDisplay::screenInput(lv_indev_drv_t *indev_driver,
|
||||||
return mBrightness;
|
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){
|
SDLDisplay::SDLDisplay() : DisplayAbstract() {
|
||||||
sdl_display_flush(disp,area,color_p);
|
sdl_init();
|
||||||
}
|
|
||||||
|
|
||||||
void SDLDisplay::screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data){
|
// Get the SDL window via an event
|
||||||
sdl_mouse_read(indev_driver,data);
|
SDL_Event aWindowIdFinder;
|
||||||
}
|
SDL_PollEvent(&aWindowIdFinder);
|
||||||
|
mSimWindow = SDL_GetWindowFromID(aWindowIdFinder.window.windowID);
|
||||||
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...
|
|
||||||
}
|
}
|
|
@ -1,25 +1,27 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
|
||||||
#include "SDL2/SDL.h"
|
|
||||||
#include "DisplayAbstract.h"
|
#include "DisplayAbstract.h"
|
||||||
|
#include "SDL2/SDL.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
class SDLDisplay : public DisplayAbstract{
|
class SDLDisplay : public DisplayAbstract {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::shared_ptr<SDLDisplay> getInstance();
|
static std::shared_ptr<SDLDisplay> getInstance();
|
||||||
|
|
||||||
virtual void setBrightness(uint8_t brightness) override;
|
virtual void setBrightness(uint8_t brightness) override;
|
||||||
virtual uint8_t getBrightness() override;
|
virtual uint8_t getBrightness() override;
|
||||||
virtual void turnOff() override;
|
virtual void turnOff() override;
|
||||||
|
|
||||||
void setTitle(std::string aNewTitle);
|
void setTitle(std::string aNewTitle);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) override;
|
virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area,
|
||||||
virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override;
|
lv_color_t *color_p) override;
|
||||||
|
virtual void screenInput(lv_indev_drv_t *indev_driver,
|
||||||
|
lv_indev_data_t *data) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDLDisplay();
|
SDLDisplay();
|
||||||
uint8_t mBrightness;
|
uint8_t mBrightness;
|
||||||
SDL_Window* mSimWindow;
|
SDL_Window *mSimWindow;
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue