| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /*
- * author: Patrick-Christopher Mattulat
- * e-mail: webmaster@lynarstudios.com
- */
- #include <SDL3/SDL.h>
- #include <messaging/StatusCodeOk.hpp>
- #include <messaging/StatusCodeWindowApiLoadingFailed.hpp>
- #include <messaging/StatusCodeWindowCreationFailed.hpp>
- #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
- #include <window/SdlApi.hpp>
- #include <window/SdlWindowApi.hpp>
- using ls::atlantis::messaging::StatusCodeOk;
- using ls::atlantis::messaging::StatusCodeWindowApiLoadingFailed;
- using ls::atlantis::messaging::StatusCodeWindowCreationFailed;
- using ls::atlantis::glossary::WindowApiTypes;
- using ls::atlantis::interfaces::AStatusCode;
- using ls::atlantis::interfaces::ISdlApi;
- using ls::atlantis::window::SdlApi;
- using ls::atlantis::window::SdlWindowApi;
- using ls::std::core::NullPointerArgumentEvaluator;
- using ::std::make_shared;
- using ::std::shared_ptr;
- SdlWindowApi::SdlWindowApi() : SdlWindowApi(make_shared<SdlApi>())
- {}
- SdlWindowApi::SdlWindowApi(const shared_ptr<ISdlApi> &_sdlApi)
- : sdlApi(_sdlApi),
- window(nullptr, [this](SDL_Window *_window) { this->sdlApi->DestroyWindow(_window); }),
- windowApiType(WindowApiTypes::SDL_WINDOW_API)
- {
- NullPointerArgumentEvaluator(_sdlApi).evaluate();
- }
- SdlWindowApi::~SdlWindowApi()
- {
- sdlApi->Quit();
- }
- WindowApiTypes SdlWindowApi::getWindowApiType()
- {
- return this->windowApiType;
- }
- shared_ptr<AStatusCode> SdlWindowApi::init()
- {
- shared_ptr<AStatusCode> statusCode = this->_initApi();
- if (statusCode->getId() == StatusCodeOk{}.getId())
- {
- statusCode = this->_createWindow();
- }
- return statusCode;
- }
- shared_ptr<AStatusCode> SdlWindowApi::_createWindow()
- {
- shared_ptr<AStatusCode> statusCode = make_shared<StatusCodeOk>();
- window.reset(sdlApi->CreateWindow("", 0, 0, SDL_WINDOW_FULLSCREEN));
- if (window == nullptr)
- {
- statusCode = make_shared<StatusCodeWindowCreationFailed>();
- statusCode->addHint(sdlApi->GetError());
- }
- return statusCode;
- }
- shared_ptr<AStatusCode> SdlWindowApi::_initApi() const
- {
- shared_ptr<AStatusCode> statusCode = make_shared<StatusCodeOk>();
- if (!sdlApi->Init(SDL_INIT_VIDEO))
- {
- statusCode = make_shared<StatusCodeWindowApiLoadingFailed>();
- statusCode->addHint(sdlApi->GetError());
- }
- return statusCode;
- }
|