diff options
author | Nao Pross <naopross@thearcway.org> | 2019-01-25 16:01:11 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2019-01-25 16:01:11 +0100 |
commit | 4607c8f0aaa1f27d844cdda3a472ac24c431bdfe (patch) | |
tree | 6dd5e8a6e424536598ae16631f9e210f7f0c8cfa | |
parent | Enable more compiler warnings (diff) | |
download | flatland-4607c8f0aaa1f27d844cdda3a472ac24c431bdfe.tar.gz flatland-4607c8f0aaa1f27d844cdda3a472ac24c431bdfe.zip |
Rebuild flat::window around wsdl2::window
-rw-r--r-- | engine/include/window.hpp | 103 | ||||
-rw-r--r-- | engine/window.cpp | 190 | ||||
m--------- | lib/libwsdl2 | 0 |
3 files changed, 18 insertions, 275 deletions
diff --git a/engine/include/window.hpp b/engine/include/window.hpp index 98e8e04..99a6fa6 100644 --- a/engine/include/window.hpp +++ b/engine/include/window.hpp @@ -1,101 +1,22 @@ -#ifndef __FLATWINDOW_H__ -#define __FLATWINDOW_H__ +#pragma once + +#include "wsdl2/video.hpp" #include "core/object.hpp" #include "serial/keyfocusable.hpp" #include <string> -class SDL_Window; -class SDL_KeyEvent; - namespace flat { + class window : virtual public core::object, public wsdl2::window { + public: + window() = delete; + window(const window& other) = delete; + window(const std::string& title, std::size_t width, std::size_t height); + ~window(); -struct window_status -{ - window_status( unsigned char fullscreen = 0, - unsigned char hidden = 0, - unsigned char borderless = 0, - unsigned char resizable = 1, - unsigned char minimized = 0, - unsigned char maximized = 0, - unsigned char focus = 1) - - : fullscreen(fullscreen), hidden(hidden), borderless(borderless), - resizable(resizable), minimized(minimized), maximized(maximized), - focus(focus) {} - - unsigned char fullscreen:1; - unsigned char hidden:1; - unsigned char borderless:1; - unsigned char resizable:1; - unsigned char minimized:1; - unsigned char maximized:1; - unsigned char focus:1; -}; - - -class FlatLayer; - -class FlatWindow : virtual public core::object, public KeyFocusable -{ - std::string title; - window_status status; - - SDL_Rect * bounds; - SDL_Window * sdl_window; - SDL_Surface * screen; - - FlatLayer * main_layer; - - void key_cb(const SDL_KeyboardEvent*) override; - -// TODO window calls -//protected: - - //virtual void resizeEvent(); - - //virtual void quitEvent(); - -public: - - FlatWindow(int x, int y, - int width, int height, - const std::string& title, - window_status status = window_status()); - - FlatWindow( SDL_Rect *bounds, const std::string& title, - window_status status = window_status()); - - FlatWindow( int width, int height, - const std::string &title, - window_status status = window_status()); - - FlatWindow(const FlatWindow&); - - ~FlatWindow(); - - int open(); - void close(); - - int getWidth() const; - int getHeight() const; - - const SDL_Rect * getBounds() const; - - SDL_Window * getSDLWindow(); - SDL_Surface * getScreenSurface(); - - const std::string& getTitle() const; - - void setTitle(const std::string&); - - window_status getWindowStatus() const; - - void setWindowStatus(window_status); - - static uint32_t winstatus_to_flags(window_status); -}; + private: + // std::multiset<layer> m_layers; + }; } -#endif diff --git a/engine/window.cpp b/engine/window.cpp index 4f22310..ae410d3 100644 --- a/engine/window.cpp +++ b/engine/window.cpp @@ -1,194 +1,16 @@ #include "window.hpp" - -#include <SDL2/SDL.h> -#include <iostream> -#include "layer.hpp" #include "core/signal.hpp" +#include "layer.hpp" -using namespace std; -using namespace flat; - -FlatWindow::FlatWindow( int x, int y, - int width, int height, - const string& title, - window_status status) - - : title(title), status(status), - sdl_window(0), screen(0) -{ - bounds = new SDL_Rect; - - bounds->x = x; - bounds->y = y; - bounds->w = width; - bounds->h = height; - - main_layer = new FlatLayer(0); -} - -FlatWindow::FlatWindow( SDL_Rect *bounds, - const string& title, - window_status status) - - : FlatWindow(bounds->x, bounds->y, bounds->w, bounds->h, title, status) -{ -} - -FlatWindow::FlatWindow( int width, int height, - const string &title, - window_status status) - - : FlatWindow( SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - width, height, - title, status) -{ -} - -FlatWindow::FlatWindow(const FlatWindow& win) - - : flat::core::object(win), - title(win.title), status(win.status), - sdl_window(0), screen(0) -{ - bounds = new SDL_Rect; - - *bounds = *win.bounds; - - main_layer = new FlatLayer(0); -} - -FlatWindow::~FlatWindow() -{ - close(); - delete bounds; - delete main_layer; -} +using namespace flat; -int FlatWindow::open() +window::window(const std::string& title, std::size_t width, std::size_t height) + : wsdl2::window(title, width, height) { - uint32_t win_flags = winstatus_to_flags(status); - sdl_window = SDL_CreateWindow( title.c_str(), - bounds->x, - bounds->y, - bounds->w, - bounds->h, - win_flags); - - if (sdl_window == 0) - { - cout << "Error: failed to initialize window" << endl; - // throw exception - return -1; - } - - screen = SDL_GetWindowSurface(sdl_window); - - if (screen == 0) - { - cout << "Error: SDL_SetVideoMode failed" << endl; - // throw exception - return -1; - } - - return 0; -} - -void FlatWindow::close() -{ - if (screen != 0) - { - SDL_FreeSurface(screen); - screen = 0; - } - - if (sdl_window != 0) - { - SDL_DestroyWindow(sdl_window); - sdl_window = 0; - } } -int FlatWindow::getWidth() const -{ - return bounds->w; -} - -int FlatWindow::getHeight() const -{ - return bounds->h; -} - -const SDL_Rect * FlatWindow::getBounds() const -{ - return bounds; -} - -SDL_Window * FlatWindow::getSDLWindow() -{ - return sdl_window; -} - -SDL_Surface * FlatWindow::getScreenSurface() -{ - return screen; -} - -const std::string& FlatWindow::getTitle() const -{ - return title; -} - -void FlatWindow::setTitle(const std::string& title) -{ - this->title = title; -} - -window_status FlatWindow::getWindowStatus() const -{ - return status; -} - -void FlatWindow::setWindowStatus(window_status status) -{ - this->status = status; -} - -void FlatWindow::key_cb(const SDL_KeyboardEvent *event) -{ - // TODO Default escape exits - - if (event->type == SDL_KEYDOWN && event->keysym.sym == SDLK_ESCAPE) - { - /* Close window */ - close(); - - /* Say flatland to quit */ - // flat::core::signal quit(this, "quit", 0, 0xff); - // quit.emit("core"); - } +window::~window() { + // nothing to destroy yet } - -uint32_t FlatWindow::winstatus_to_flags(window_status s) -{ - uint32_t flags = 0; - - if (s.fullscreen) - flags |= SDL_WINDOW_FULLSCREEN; - if (s.hidden) - flags |= SDL_WINDOW_HIDDEN; - if (s.borderless) - flags |= SDL_WINDOW_BORDERLESS; - if (s.resizable) - flags |= SDL_WINDOW_RESIZABLE; - if (s.minimized) - flags |= SDL_WINDOW_MINIMIZED; - if (s.maximized) - flags |= SDL_WINDOW_MAXIMIZED; - if (s.focus) - flags |= SDL_WINDOW_INPUT_GRABBED; - - return flags; -} - diff --git a/lib/libwsdl2 b/lib/libwsdl2 -Subproject 736ec71fce673d5aa88228b96acfe6c6862a223 +Subproject 71b593ebd1a015a4cb9bfe0eebafc78d897ff28 |