diff --git a/engine.cmake b/engine.cmake index 5af28f1..deeeda0 100644 --- a/engine.cmake +++ b/engine.cmake @@ -25,7 +25,7 @@ set( ENGINE_SRC # Platform source/Platform/PlatformApplication.cpp - source/Platform/PlatformDisplay.cpp + source/Platform/PlatformWindow.cpp # Math source/Math/Color.cpp @@ -40,11 +40,11 @@ set( ENGINE_SRC source/Input/Keyboard.cpp source/Input/Mouse.cpp - # Display - source/Display/Display.cpp - source/Display/DisplayDescription.cpp - source/Display/DisplayMode.cpp - source/Display/GLContext.cpp + # Window + source/Window/Window.cpp + source/Window/WindowDescription.cpp + source/Window/DisplayMode.cpp + source/Window/GLContext.cpp # GfxDriver source/GfxDriver/ShaderProgram.cpp @@ -95,7 +95,7 @@ set(ENGINE_GFXDRIVER_OPENGL_SRC set(ENGINE_PLATFORM_WIN32_SRC source/Platform/Win32/Win32Application.cpp - source/Platform/Win32/Win32Display.cpp + source/Platform/Win32/Win32Window.cpp source/Platform/Win32/Win32GLContext.cpp source/Platform/Win32/Win32Input.cpp source/Platform/Win32/Win32Internal.cpp diff --git a/examples/display/DisplayExample.cpp b/examples/display/DisplayExample.cpp index 8a430ae..26a16ec 100644 --- a/examples/display/DisplayExample.cpp +++ b/examples/display/DisplayExample.cpp @@ -1,5 +1,5 @@ -#include +#include #include #include #include @@ -8,7 +8,7 @@ void DisplayExample::init() { m_renderer = new sp::BatchRenderer2D(); - m_mode = sp::Display::WINDOWED; + m_mode = sp::Window::WINDOWED; getMessageHandler()->registerListener(this); m_texture.create("assets/textures/tux.png"); @@ -26,27 +26,27 @@ void DisplayExample::onEvent(const sp::Event& event) if (event.key.code == sp::Keyboard::W) { - if (m_mode == sp::Display::WINDOWED) { - m_mode = sp::Display::WINDOWEDFULLSCREEN; + if (m_mode == sp::Window::WINDOWED) { + m_mode = sp::Window::WINDOWEDFULLSCREEN; sp::Log::info("Windowed Fullscreen"); } else { - m_mode = sp::Display::WINDOWED; + m_mode = sp::Window::WINDOWED; sp::Log::info("Windowed"); } - getGraphics()->setDisplayMode(m_mode); + getGraphics()->setWindowMode(m_mode); } else if (event.key.code == sp::Keyboard::Space) { - if (m_mode == sp::Display::WINDOWED) { - m_mode = sp::Display::FULLSCREEN; + if (m_mode == sp::Window::WINDOWED) { + m_mode = sp::Window::FULLSCREEN; sp::Log::info("Fullscreen"); } else { - m_mode = sp::Display::WINDOWED; + m_mode = sp::Window::WINDOWED; sp::Log::info("Windowed"); } - getGraphics()->setDisplayMode(m_mode); + getGraphics()->setWindowMode(m_mode); } } } diff --git a/examples/display/DisplayExample.h b/examples/display/DisplayExample.h index 68de736..7351124 100644 --- a/examples/display/DisplayExample.h +++ b/examples/display/DisplayExample.h @@ -23,7 +23,7 @@ protected : protected : - sp::Display::Mode m_mode; + sp::Window::Mode m_mode; sp::Camera2D m_camera; sp::Renderer2D *m_renderer; diff --git a/examples/input/InputExample.cpp b/examples/input/InputExample.cpp index 76b1233..c18f942 100644 --- a/examples/input/InputExample.cpp +++ b/examples/input/InputExample.cpp @@ -61,7 +61,7 @@ void InputExample::update(double dt) } } -void InputExample::onSizeChanged(sp::Display* display, int width, int height) +void InputExample::onSizeChanged(sp::Window* Window, int width, int height) { } @@ -70,10 +70,10 @@ void InputExample::onEvent(const sp::Event& event) { if (event.type == event.Key && !event.key.pressed) { if (event.key.code == sp::Keyboard::G) { - getGraphics()->getDisplay()->grabCursor(true); + getGraphics()->getWindow()->grabCursor(true); sp::Log::info("Mouse Grabbed"); } else if (event.key.code == sp::Keyboard::U) { - getGraphics()->getDisplay()->grabCursor(false); + getGraphics()->getWindow()->grabCursor(false); sp::Log::info("Mouse Released"); } } else if (event.type == event.MouseButton && event.mouseButton.button == sp::Mouse::Right) { diff --git a/examples/input/InputExample.h b/examples/input/InputExample.h index 8c95e5d..6e9281c 100644 --- a/examples/input/InputExample.h +++ b/examples/input/InputExample.h @@ -22,7 +22,7 @@ protected : void render(); - void onSizeChanged(sp::Display* display, int width, int height); + void onSizeChanged(sp::Window* display, int width, int height); void onEvent(const sp::Event& event); diff --git a/include/Spectre/Display/DisplayDescription.h b/include/Spectre/Display/DisplayDescription.h deleted file mode 100644 index 06067e0..0000000 --- a/include/Spectre/Display/DisplayDescription.h +++ /dev/null @@ -1,34 +0,0 @@ - -#ifndef SPECTRE_DISPLAY_DISPLAYDESCRIPTION_H -#define SPECTRE_DISPLAY_DISPLAYDESCRIPTION_H - -#include "DisplayMode.h" - -namespace sp { - -namespace DisplayDecorate { - - enum Type { - Empty = 0, - Menu = 1 << 0, - Resize = 1 << 1, - Close = 1 << 2, - Default = Menu | Resize | Close, - }; -}; - -struct DisplayDescription -{ -public : - DisplayDescription(); - DisplayDescription(DisplayMode mode, unsigned decoration = DisplayDecorate::Default); - -public : - DisplayMode mode; - - unsigned int decoration; -}; - -} // namespace sp - -#endif /* SPECTRE_DISPLAY_DISPLAYDESCRIPTION_H */ diff --git a/include/Spectre/Graphics.h b/include/Spectre/Graphics.h index df6f125..0720285 100644 --- a/include/Spectre/Graphics.h +++ b/include/Spectre/Graphics.h @@ -3,7 +3,7 @@ #define GRAPHICS_H #include -#include +#include namespace sp { @@ -31,7 +31,7 @@ public : std::string getVersion() const; - void setDisplayMode(Display::Mode mode); + void setWindowMode(Window::Mode mode); void setSize(int width, int height); @@ -45,14 +45,14 @@ public : GfxDriver* getDriver(); - Display* getDisplay(); + Window* getWindow(); protected : int m_width; int m_height; - Display *m_display; + Window *m_window; // Graphics Driver. OpenGL/Vulcan/DirectX etc. GfxDriver *m_gfxdrv; diff --git a/include/Spectre/System/Event.h b/include/Spectre/System/Event.h index 70a39e0..4577c5f 100644 --- a/include/Spectre/System/Event.h +++ b/include/Spectre/System/Event.h @@ -7,7 +7,7 @@ namespace sp { -class Display; +class Window; struct Event { @@ -43,7 +43,7 @@ public : struct SizeEvent { - Display *display; + Window *window; int width; int height; }; @@ -62,7 +62,7 @@ public : // Helper methods - static Event createSize(Display *display, int width, int height); + static Event createSize(Window *window, int width, int height); static Event createKey(Keyboard::Key code, bool pressed); diff --git a/include/Spectre/System/EventListener.h b/include/Spectre/System/EventListener.h index 5b18d6b..7dfbc53 100644 --- a/include/Spectre/System/EventListener.h +++ b/include/Spectre/System/EventListener.h @@ -8,12 +8,12 @@ namespace sp { -class Display; +class Window; class EventListener { public : - virtual void onSizeChanged(Display* display, int width, int height); + virtual void onSizeChanged(Window* window, int width, int height); virtual void onEvent(const Event& event); }; diff --git a/include/Spectre/System/MessageHandler.h b/include/Spectre/System/MessageHandler.h index 4ca39bc..b3081c7 100644 --- a/include/Spectre/System/MessageHandler.h +++ b/include/Spectre/System/MessageHandler.h @@ -15,7 +15,7 @@ public : void unregisterListener(EventListener *listener); - virtual void onSizeChanged(Display* display, int width, int height); + virtual void onSizeChanged(Window* window, int width, int height); virtual void onEvent(const Event& event); diff --git a/include/Spectre/Display/DisplayMode.h b/include/Spectre/Window/DisplayMode.h similarity index 100% rename from include/Spectre/Display/DisplayMode.h rename to include/Spectre/Window/DisplayMode.h diff --git a/include/Spectre/Display/GLContext.h b/include/Spectre/Window/GLContext.h similarity index 80% rename from include/Spectre/Display/GLContext.h rename to include/Spectre/Window/GLContext.h index 837d629..4a08b93 100644 --- a/include/Spectre/Display/GLContext.h +++ b/include/Spectre/Window/GLContext.h @@ -1,12 +1,12 @@ -#ifndef DISPLAY_GLCONTEXT_H -#define DISPLAY_GLCONTEXT_H +#ifndef SPECTRE_WINDOW_GLCONTEXT_H +#define SPECTRE_WINDOW_GLCONTEXT_H #include namespace sp { -class PlatformDisplay; +class PlatformWindow; // Platform independant interface for OpenGL Contexts. @@ -17,8 +17,8 @@ public : virtual ~GLContext(); - // Create a GLContext for this perticular display. - virtual bool create(const PlatformDisplay* display) = 0; + // Create a GLContext for this perticular window. + virtual bool create(const PlatformWindow* window) = 0; virtual void destroy() = 0; @@ -44,4 +44,4 @@ public : } // namespace sp -#endif /* DISPLAY_GLCONTEXT_H */ +#endif /* SPECTRE_WINDOW_GLCONTEXT_H */ diff --git a/include/Spectre/Display/Display.h b/include/Spectre/Window/Window.h similarity index 74% rename from include/Spectre/Display/Display.h rename to include/Spectre/Window/Window.h index e953f72..41a7074 100644 --- a/include/Spectre/Display/Display.h +++ b/include/Spectre/Window/Window.h @@ -1,22 +1,22 @@ -#ifndef SPECTRE_DISPLAY_DISPLAY_H -#define SPECTRE_DISPLAY_DISPLAY_H +#ifndef SPECTRE_WINDOW_WINDOW_H +#define SPECTRE_WINDOW_WINDOW_H #include "DisplayMode.h" -#include "DisplayDescription.h" +#include "WindowDescription.h" #include -#include +#include #include #include namespace sp { -class PlatformDisplay; +class PlatformWindow; class GLContext; -class Display +class Window { -friend class PlatformDisplay; +friend class PlatformWindow; public : enum Mode { WINDOWED = 0, @@ -25,10 +25,10 @@ public : }; public : - Display(); - virtual ~Display(); + Window(); + virtual ~Window(); - bool create(DisplayDescription decription); + bool create(WindowDescription decription); void destroy(); @@ -78,16 +78,16 @@ protected : // So it can be restored when returning to window mode. Vector2u m_cachePos; - DisplayDescription m_description; - DisplayDescription m_cacheDesc; + WindowDescription m_description; + WindowDescription m_cacheDesc; std::string m_caption; - PlatformDisplay* m_impl; + PlatformWindow* m_impl; GLContext* m_context; }; } // namepsace sp -#endif /* SPECTRE_DISPLAY_DISPLAY_H */ +#endif /* SPECTRE_WINDOW_WINDOW_H */ diff --git a/include/Spectre/Window/WindowDescription.h b/include/Spectre/Window/WindowDescription.h new file mode 100644 index 0000000..9ea0de1 --- /dev/null +++ b/include/Spectre/Window/WindowDescription.h @@ -0,0 +1,34 @@ + +#ifndef SPECTRE_WINDOW_WINDOWDESCRIPTION_H +#define SPECTRE_WINDOW_WINDOWDESCRIPTION_H + +#include "DisplayMode.h" + +namespace sp { + +namespace WindowDecorate { + + enum Type { + Empty = 0, + Menu = 1 << 0, + Resize = 1 << 1, + Close = 1 << 2, + Default = Menu | Resize | Close, + }; +}; + +struct WindowDescription +{ +public : + WindowDescription(); + WindowDescription(DisplayMode mode, unsigned decoration = WindowDecorate::Default); + +public : + DisplayMode mode; + + unsigned int decoration; +}; + +} // namespace sp + +#endif /* SPECTRE_WINDOW_WINDOWDESCRIPTION_H */ diff --git a/source/Display/DisplayDescription.cpp b/source/Display/DisplayDescription.cpp deleted file mode 100644 index 0f6a72d..0000000 --- a/source/Display/DisplayDescription.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -#include - -namespace sp { - -DisplayDescription::DisplayDescription() : -mode (), -decoration (DisplayDecorate::Default) -{ -} - -DisplayDescription::DisplayDescription(DisplayMode mode, unsigned decoration) : -mode (mode), -decoration (decoration) -{ -} - -} // namespace sp diff --git a/source/Game.cpp b/source/Game.cpp index c22e241..9842a64 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -90,7 +90,7 @@ void Game::processEvents() // Call message handler. if (event.type == Event::Size) { - m_messageHandler->onSizeChanged(event.size.display, event.size.width, event.size.height); + m_messageHandler->onSizeChanged(event.size.window, event.size.width, event.size.height); } m_messageHandler->onEvent(event); diff --git a/source/Graphics/Graphics.cpp b/source/Graphics/Graphics.cpp index 641a25c..63cfc4e 100644 --- a/source/Graphics/Graphics.cpp +++ b/source/Graphics/Graphics.cpp @@ -10,7 +10,7 @@ Graphics::Graphics(PlatformApplication *platform) m_width = 800; m_height = 600; - m_display = new Display(); + m_window = new Window(); // Only have OpenGL atm. m_gfxdrv = new OpenGLDrv(); @@ -19,16 +19,16 @@ Graphics::Graphics(PlatformApplication *platform) Graphics::~Graphics() { shutdown(); - delete m_display; + delete m_window; delete m_gfxdrv; } bool Graphics::init() { DisplayMode mode(m_width, m_height); - DisplayDescription desc(mode); + WindowDescription desc(mode); - if (!m_display->create(desc)) { + if (!m_window->create(desc)) { return false; } @@ -41,7 +41,7 @@ bool Graphics::init() void Graphics::shutdown() { - m_display->destroy(); + m_window->destroy(); } std::string Graphics::getVersion() const @@ -49,14 +49,14 @@ std::string Graphics::getVersion() const return m_gfxdrv->getVendor(); } -void Graphics::setDisplayMode(Display::Mode mode) +void Graphics::setWindowMode(Window::Mode mode) { - m_display->setVideoMode(mode); + m_window->setVideoMode(mode); } void Graphics::setSize(int width, int height) { - m_display->setSize(width, height); + m_window->setSize(width, height); } void Graphics::setViewport(int x, int y, int width, int height) @@ -76,7 +76,7 @@ void Graphics::clearBuffer() void Graphics::swapBuffers() { - m_display->swapBuffers(); + m_window->swapBuffers(); } GfxDriver* Graphics::getDriver() @@ -84,9 +84,9 @@ GfxDriver* Graphics::getDriver() return m_gfxdrv; } -Display* Graphics::getDisplay() +Window* Graphics::getWindow() { - return m_display; + return m_window; } } // namespace sp diff --git a/source/Platform/PlatformDisplay.cpp b/source/Platform/PlatformDisplay.cpp deleted file mode 100644 index 4cfb3c7..0000000 --- a/source/Platform/PlatformDisplay.cpp +++ /dev/null @@ -1,39 +0,0 @@ - -#include -#include "PlatformDisplay.h" - -#ifdef SPECTRE_PLATFORM_WIN -#include -typedef sp::Win32Display DisplayType; -#elif SPECTRE_PLATFORM_UNIX -#include -typedef sp::X11Display DisplayType; -#else -#error "No Display implementation exists" -#endif - -namespace sp { - -PlatformDisplay* PlatformDisplay::make(Display* parent) -{ - DisplayType* disp = new DisplayType(); - disp->m_parent = parent; - return disp; -} - -PlatformDisplay::PlatformDisplay() -{ -} - -PlatformDisplay::~PlatformDisplay() -{ - // Nothing to do. -} - -void PlatformDisplay::onReshape(int width, int height) -{ - // Forward to parent. - m_parent->onReshape(width, height); -} - -} // namespace sp diff --git a/source/Platform/PlatformMisc.h b/source/Platform/PlatformMisc.h index 55d484b..70c7b1e 100644 --- a/source/Platform/PlatformMisc.h +++ b/source/Platform/PlatformMisc.h @@ -2,7 +2,7 @@ #ifndef PLATFORM_MISC_H #define PLATFORM_MISC_H -#include +#include #include namespace sp { diff --git a/source/Platform/PlatformWindow.cpp b/source/Platform/PlatformWindow.cpp new file mode 100644 index 0000000..90db860 --- /dev/null +++ b/source/Platform/PlatformWindow.cpp @@ -0,0 +1,39 @@ + +#include +#include "PlatformWindow.h" + +#ifdef SPECTRE_PLATFORM_WIN +#include +typedef sp::Win32Window WindowType; +#elif SPECTRE_PLATFORM_UNIX +#include +typedef sp::X11Window WindowType; +#else +#error "No Window implementation exists" +#endif + +namespace sp { + +PlatformWindow* PlatformWindow::make(Window* parent) +{ + WindowType* disp = new WindowType(); + disp->m_parent = parent; + return disp; +} + +PlatformWindow::PlatformWindow() +{ +} + +PlatformWindow::~PlatformWindow() +{ + // Nothing to do. +} + +void PlatformWindow::onReshape(int width, int height) +{ + // Forward to parent. + m_parent->onReshape(width, height); +} + +} // namespace sp diff --git a/source/Platform/PlatformDisplay.h b/source/Platform/PlatformWindow.h similarity index 74% rename from source/Platform/PlatformDisplay.h rename to source/Platform/PlatformWindow.h index 3fff71f..1ce10d5 100644 --- a/source/Platform/PlatformDisplay.h +++ b/source/Platform/PlatformWindow.h @@ -1,10 +1,10 @@ -#ifndef SPECTRE_PLATFORM_DISPLAY_H -#define SPECTRE_PLATFORM_DISPLAY_H +#ifndef SPECTRE_PLATFORM_WINDOW_H +#define SPECTRE_PLATFORM_WINDOW_H #include -#include -#include +#include +#include #include #include @@ -12,17 +12,17 @@ namespace sp { -class Display; +class Window; -class PlatformDisplay +class PlatformWindow { public : // Factory method. - static PlatformDisplay* make(Display* parent); + static PlatformWindow* make(Window* parent); - virtual ~PlatformDisplay(); + virtual ~PlatformWindow(); - virtual bool create(DisplayDescription description) = 0; + virtual bool create(WindowDescription description) = 0; virtual void destroy() = 0; @@ -60,13 +60,13 @@ public : protected : - PlatformDisplay(); + PlatformWindow(); void onReshape(int width, int height); private : - Display * m_parent; + Window * m_parent; }; } // namespace sp diff --git a/source/Platform/Win32/Win32Application.h b/source/Platform/Win32/Win32Application.h index 51ed8ab..9fe035d 100644 --- a/source/Platform/Win32/Win32Application.h +++ b/source/Platform/Win32/Win32Application.h @@ -4,7 +4,7 @@ #include -#include "Win32Display.h" +#include "Win32Window.h" #include "Win32Input.h" #include #include diff --git a/source/Platform/Win32/Win32GLContext.cpp b/source/Platform/Win32/Win32GLContext.cpp index 5a02f8a..cfc59bc 100644 --- a/source/Platform/Win32/Win32GLContext.cpp +++ b/source/Platform/Win32/Win32GLContext.cpp @@ -1,7 +1,7 @@ #include "glad_wgl.h" -#include +#include #include #include "Win32Internal.h" @@ -43,12 +43,12 @@ Win32GLContext::~Win32GLContext() destroy(); } -bool Win32GLContext::create(const PlatformDisplay* display) +bool Win32GLContext::create(const PlatformWindow* window) { // If created. destroy old handles. destroy(); - m_wnd = (HWND) display->getHandle(); + m_wnd = (HWND) window->getHandle(); // Should have a valid handle here. trigger error. if (!m_wnd) { diff --git a/source/Platform/Win32/Win32GLContext.h b/source/Platform/Win32/Win32GLContext.h index b91807e..9601cb8 100644 --- a/source/Platform/Win32/Win32GLContext.h +++ b/source/Platform/Win32/Win32GLContext.h @@ -5,7 +5,7 @@ // Win32 OpenGL Context (wgl) #include -#include +#include namespace sp { @@ -16,7 +16,7 @@ public : ~Win32GLContext(); // Create a context associated with a display. - bool create(const PlatformDisplay* display); + bool create(const PlatformWindow* window); void destroy(); diff --git a/source/Platform/Win32/Win32Display.cpp b/source/Platform/Win32/Win32Window.cpp similarity index 79% rename from source/Platform/Win32/Win32Display.cpp rename to source/Platform/Win32/Win32Window.cpp index 23f53c7..a3cce29 100644 --- a/source/Platform/Win32/Win32Display.cpp +++ b/source/Platform/Win32/Win32Window.cpp @@ -1,12 +1,11 @@ #include - -#include +#include #include #include "Win32Application.h" #include "Win32Internal.h" -#include "Win32Display.h" +#include "Win32Window.h" namespace sp { @@ -19,7 +18,7 @@ namespace sp { static bool firstTime = true; -Win32Display::Win32Display() : +Win32Window::Win32Window() : m_handle (NULL), m_icon (0), m_cursor (0), @@ -28,7 +27,7 @@ m_minSize (200, 200) { } -Win32Display::~Win32Display() +Win32Window::~Win32Window() { if (m_icon) { DestroyIcon(m_icon); @@ -39,7 +38,7 @@ Win32Display::~Win32Display() } } -bool Win32Display::create(DisplayDescription description) +bool Win32Window::create(WindowDescription description) { DWORD flags; Vector2i pos, actual_size; @@ -72,7 +71,7 @@ bool Win32Display::create(DisplayDescription description) return true; } -void Win32Display::destroy() +void Win32Window::destroy() { if (m_handle) { DestroyWindow(m_handle); @@ -80,23 +79,23 @@ void Win32Display::destroy() } } -void* Win32Display::getHandle() const +void* Win32Window::getHandle() const { return m_handle; } -bool Win32Display::isValid() +bool Win32Window::isValid() { return m_handle != NULL; } -void Win32Display::setSize(unsigned int width, unsigned int height) +void Win32Window::setSize(unsigned int width, unsigned int height) { Vector2i s = calculateSize(GetWindowLong(m_handle, GWL_STYLE), width, height); ::SetWindowPos(m_handle, NULL, 0, 0, s.x, s.y, SWP_NOMOVE | SWP_NOZORDER); } -Vector2u Win32Display::getSize() const +Vector2u Win32Window::getSize() const { RECT rect; Vector2u size; @@ -108,44 +107,44 @@ Vector2u Win32Display::getSize() const return size; } -void Win32Display::setPosition(unsigned int x, unsigned int y) +void Win32Window::setPosition(unsigned int x, unsigned int y) { ::SetWindowPos(m_handle, NULL, x, y, 0, 0, SWP_NOSIZE); } -Vector2u Win32Display::getPosition() const +Vector2u Win32Window::getPosition() const { RECT r; GetWindowRect(m_handle, &r); return Vector2u(r.left, r.top); } -void Win32Display::setVisible(bool visible) +void Win32Window::setVisible(bool visible) { ::ShowWindow(m_handle, visible ? SW_SHOW : SW_HIDE); } -void Win32Display::setDecoration(unsigned decoration) +void Win32Window::setDecoration(unsigned decoration) { ::SetWindowLong(m_handle, GWL_STYLE, getWin32Flags(decoration)); } -void Win32Display::minimize() +void Win32Window::minimize() { ::ShowWindow(m_handle, SW_MINIMIZE); } -void Win32Display::maximize() +void Win32Window::maximize() { ::ShowWindow(m_handle, SW_MAXIMIZE); } -void Win32Display::setCaption(const std::string& caption) +void Win32Window::setCaption(const std::string& caption) { ::SetWindowText(m_handle, caption.c_str()); } -void Win32Display::showCursor(bool value) +void Win32Window::showCursor(bool value) { if (value) { m_cursor = ::LoadCursor(NULL, IDC_ARROW); @@ -156,7 +155,7 @@ void Win32Display::showCursor(bool value) ::SetCursor(m_cursor); } -void Win32Display::grabCursor(bool value) +void Win32Window::grabCursor(bool value) { if (value) { RECT rect; @@ -168,7 +167,7 @@ void Win32Display::grabCursor(bool value) } } -void Win32Display::setIcon(unsigned int width, unsigned int height, const uint8_t *pixels) +void Win32Window::setIcon(unsigned int width, unsigned int height, const uint8_t *pixels) { ::HDC hdc; ::ICONINFO ii; @@ -192,13 +191,13 @@ void Win32Display::setIcon(unsigned int width, unsigned int height, const uint8_ ::ReleaseDC(NULL, hdc); if (!bmp_color) { - Log::error("Win32Display::setIcon() - Failed to create RGBA bitmap"); + Log::error("Win32Window::setIcon() - Failed to create RGBA bitmap"); return; } bmp_mask = CreateBitmap(width, height, 1, 1, NULL); if (!bmp_mask) { - Log::error("Win32Display::setIcon() - Failed to create mask bitmap"); + Log::error("Win32Window::setIcon() - Failed to create mask bitmap"); ::DeleteObject(bmp_color); return; } @@ -228,50 +227,50 @@ void Win32Display::setIcon(unsigned int width, unsigned int height, const uint8_ ::SendMessage(m_handle, WM_SETICON, ICON_SMALL, (LPARAM) m_icon); ::SendMessage(m_handle, WM_SETICON, ICON_BIG, (LPARAM) m_icon); } else { - Log::error("Win32Display::setIcon() - Failed to create icon"); + Log::error("Win32Window::setIcon() - Failed to create icon"); } ::DeleteObject(bmp_color); ::DeleteObject(bmp_mask); } -void Win32Display::registerClass() +void Win32Window::registerClass() { WNDCLASSA wndcl; ZeroMemory(&wndcl, sizeof(wndcl)); wndcl.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; - wndcl.lpfnWndProc = Win32Display::staticWndProc; + wndcl.lpfnWndProc = Win32Window::staticWndProc; wndcl.hInstance = ::GetModuleHandle(NULL); wndcl.lpszClassName = WND_CLASSNAME; ::RegisterClass(&wndcl); } -DWORD Win32Display::getWin32Flags(unsigned int flags) +DWORD Win32Window::getWin32Flags(unsigned int flags) { DWORD win32_flags = WS_VISIBLE; - if (flags == DisplayDecorate::Empty) { + if (flags == WindowDecorate::Empty) { win32_flags |= WS_POPUP; } else { - if (flags & DisplayDecorate::Menu) { + if (flags & WindowDecorate::Menu) { win32_flags |= WS_CAPTION | WS_MINIMIZEBOX; } - if (flags & DisplayDecorate::Resize) { + if (flags & WindowDecorate::Resize) { win32_flags |= WS_THICKFRAME | WS_MAXIMIZEBOX; } - if (flags & DisplayDecorate::Close) { + if (flags & WindowDecorate::Close) { win32_flags |= WS_SYSMENU; } } return win32_flags; } -Vector2i Win32Display::centerWindow(int width, int height) +Vector2i Win32Window::centerWindow(int width, int height) { Vector2i v; v.x = (::GetSystemMetrics(SM_CXSCREEN) - width) / 2; @@ -279,14 +278,14 @@ Vector2i Win32Display::centerWindow(int width, int height) return v; } -Vector2u Win32Display::calculateSize(DWORD flags, LONG width, LONG height) +Vector2u Win32Window::calculateSize(DWORD flags, LONG width, LONG height) { RECT r = {0, 0, width, height}; AdjustWindowRect(&r, flags, false); return Vector2u(r.right - r.left, r.bottom - r.top); } -void Win32Display::enterFullscreen(DisplayMode mode) +void Win32Window::enterFullscreen(DisplayMode mode) { LONG rc; ::DEVMODEW dev; @@ -331,7 +330,7 @@ void Win32Display::enterFullscreen(DisplayMode mode) m_fs_mode = mode; } -void Win32Display::exitFullscreen() +void Win32Window::exitFullscreen() { if (!m_fs_mode.empty()) { // Restore to previous mode. @@ -340,7 +339,7 @@ void Win32Display::exitFullscreen() } } -void Win32Display::processResizeMessage(const Vector2u& new_size) +void Win32Window::processResizeMessage(const Vector2u& new_size) { // Check if the size has actually changed. if (m_size != new_size) { @@ -351,7 +350,7 @@ void Win32Display::processResizeMessage(const Vector2u& new_size) } } -void Win32Display::processMessage(UINT message, WPARAM wParam, LPARAM lParam) +void Win32Window::processMessage(UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_SETCURSOR : @@ -407,22 +406,22 @@ void Win32Display::processMessage(UINT message, WPARAM wParam, LPARAM lParam) } } -LRESULT CALLBACK Win32Display::staticWndProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK Win32Window::staticWndProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam) { - Win32Display *display; + Win32Window *win; if (message == WM_NCCREATE) { LONG_PTR ptr = (LONG_PTR) ((LPCREATESTRUCT)lParam)->lpCreateParams; ::SetWindowLongPtr(handle, GWL_USERDATA, ptr); - display = (Win32Display*) ptr; + win = (Win32Window*) ptr; } else { - display = (Win32Display*) ::GetWindowLongPtr(handle, GWL_USERDATA); + win = (Win32Window*) ::GetWindowLongPtr(handle, GWL_USERDATA); } - if (display) { - display->processMessage(message, wParam, lParam); + if (win) { + win->processMessage(message, wParam, lParam); } return DefWindowProc(handle, message, wParam, lParam); } diff --git a/source/Platform/Win32/Win32Display.h b/source/Platform/Win32/Win32Window.h similarity index 90% rename from source/Platform/Win32/Win32Display.h rename to source/Platform/Win32/Win32Window.h index 5d7b4fe..ee87398 100644 --- a/source/Platform/Win32/Win32Display.h +++ b/source/Platform/Win32/Win32Window.h @@ -3,19 +3,19 @@ #define PLATFORM_WIN32_DISPLAY_H #include "Win32GLContext.h" -#include +#include #include #include namespace sp { -class Win32Display : public PlatformDisplay +class Win32Window : public PlatformWindow { public : - Win32Display(); - virtual ~Win32Display(); + Win32Window(); + virtual ~Win32Window(); - virtual bool create(DisplayDescription description); + virtual bool create(WindowDescription description); virtual void destroy(); diff --git a/source/System/Event.cpp b/source/System/Event.cpp index 33b252a..e985db9 100644 --- a/source/System/Event.cpp +++ b/source/System/Event.cpp @@ -38,10 +38,10 @@ std::string Event::MouseButtonEvent::getName() const // Helper methods -Event Event::createSize(Display *display, int width, int height) +Event Event::createSize(Window *window, int width, int height) { Event event(Size); - event.size.display = display; + event.size.window = window; event.size.width = width; event.size.height = height; return event; diff --git a/source/System/EventListener.cpp b/source/System/EventListener.cpp index d2d6875..69accc0 100644 --- a/source/System/EventListener.cpp +++ b/source/System/EventListener.cpp @@ -1,9 +1,9 @@ -#include +#include #include namespace sp { -void EventListener::onSizeChanged(Display* display, int width, int height) +void EventListener::onSizeChanged(Window* window, int width, int height) { } diff --git a/source/System/MessageHandler.cpp b/source/System/MessageHandler.cpp index f0eb45f..faa48d0 100644 --- a/source/System/MessageHandler.cpp +++ b/source/System/MessageHandler.cpp @@ -1,5 +1,5 @@ -#include +#include #include namespace sp { @@ -28,10 +28,10 @@ void MessageHandler::unregisterListener(EventListener *listener) } } -void MessageHandler::onSizeChanged(Display* display, int width, int height) +void MessageHandler::onSizeChanged(Window* window, int width, int height) { for(EventListener* listener : m_listeners) { - listener->onSizeChanged(display, width, height); + listener->onSizeChanged(window, width, height); } } diff --git a/source/Display/DisplayMode.cpp b/source/Window/DisplayMode.cpp similarity index 96% rename from source/Display/DisplayMode.cpp rename to source/Window/DisplayMode.cpp index 13128c8..b092298 100644 --- a/source/Display/DisplayMode.cpp +++ b/source/Window/DisplayMode.cpp @@ -1,5 +1,5 @@ -#include +#include #include #include diff --git a/source/Display/GLContext.cpp b/source/Window/GLContext.cpp similarity index 91% rename from source/Display/GLContext.cpp rename to source/Window/GLContext.cpp index 2c812dc..7d9cb84 100644 --- a/source/Display/GLContext.cpp +++ b/source/Window/GLContext.cpp @@ -1,5 +1,5 @@ -#include +#include #ifdef SPECTRE_PLATFORM_WIN #include diff --git a/source/Display/Display.cpp b/source/Window/Window.cpp similarity index 69% rename from source/Display/Display.cpp rename to source/Window/Window.cpp index 2d57402..6efe7b7 100644 --- a/source/Display/Display.cpp +++ b/source/Window/Window.cpp @@ -1,9 +1,12 @@ #include -#include -#include +#include +#include +#include +#include +#include #include -#include +#include #include @@ -12,22 +15,22 @@ namespace sp { #define CAPTION_DEFAULT "Spectre" #define ICON_DEFAULT "./assets/app.ico" -Display::Display() +Window::Window() { m_caption = CAPTION_DEFAULT; m_fmode = WINDOWED; m_context = GLContext::create(); - m_impl = PlatformDisplay::make(this); + m_impl = PlatformWindow::make(this); } -Display::~Display() +Window::~Window() { delete m_context; delete m_impl; } -bool Display::create(DisplayDescription description) +bool Window::create(WindowDescription description) { destroy(); @@ -46,7 +49,7 @@ bool Display::create(DisplayDescription description) return true; } -void Display::init() +void Window::init() { m_impl->setCaption(m_caption); @@ -58,25 +61,25 @@ void Display::init() showCursor(true); } -void Display::destroy() +void Window::destroy() { m_context->destroy(); m_impl->destroy(); } -void Display::setCaption(const std::string& caption) +void Window::setCaption(const std::string& caption) { m_caption = caption; m_impl->setCaption(m_caption); } -const std::string& Display::getCaption() const +const std::string& Window::getCaption() const { return m_caption; } -void Display::setIcon(const std::string& filename) +void Window::setIcon(const std::string& filename) { Image img; @@ -85,12 +88,12 @@ void Display::setIcon(const std::string& filename) } } -void Display::setIcon(unsigned int width, unsigned int height, const uint8_t *pixels) +void Window::setIcon(unsigned int width, unsigned int height, const uint8_t *pixels) { m_impl->setIcon(width, height, pixels); } -void Display::setSize(unsigned int width, unsigned int height) +void Window::setSize(unsigned int width, unsigned int height) { m_description.mode.width = width; m_description.mode.height = height; @@ -98,12 +101,12 @@ void Display::setSize(unsigned int width, unsigned int height) m_impl->setSize(width, height); } -sp::Vector2u Display::getSize() const +sp::Vector2u Window::getSize() const { return m_impl->getSize(); } -void Display::setVideoMode(Mode mode) +void Window::setVideoMode(Mode mode) { if (m_fmode == mode) { return; @@ -125,7 +128,7 @@ void Display::setVideoMode(Mode mode) // Windowed fullscreen. else if (mode == WINDOWEDFULLSCREEN) { DisplayMode desktop = DisplayMode::getDesktopMode(); - m_impl->setDecoration(DisplayDecorate::Empty); + m_impl->setDecoration(WindowDecorate::Empty); m_impl->setSize(desktop.width, desktop.height); m_impl->setPosition(0, 0); } @@ -142,27 +145,27 @@ void Display::setVideoMode(Mode mode) m_fmode = mode; } -enum Display::Mode Display::getVideoMode() const +enum Window::Mode Window::getVideoMode() const { return m_fmode; } -void Display::setVisible(bool visible) +void Window::setVisible(bool visible) { m_impl->setVisible(visible); } -void Display::showCursor(bool value) +void Window::showCursor(bool value) { m_impl->showCursor(value); } -void Display::grabCursor(bool value) +void Window::grabCursor(bool value) { m_impl->grabCursor(value); } -bool Display::activate(bool value) +bool Window::activate(bool value) { if (value) { return m_context->activate(); @@ -170,19 +173,19 @@ bool Display::activate(bool value) return m_context->deactivate(); } -bool Display::enableVSync(bool value) +bool Window::enableVSync(bool value) { return m_context->setSwapInterval(value ? 1 : 0); } -void Display::swapBuffers() +void Window::swapBuffers() { if (activate(true)) { m_context->swapBuffers(); } } -void Display::onReshape(int width, int height) +void Window::onReshape(int width, int height) { // TODO: This should even not be here. // Generic Display should not have any GL calls. diff --git a/source/Window/WindowDescription.cpp b/source/Window/WindowDescription.cpp new file mode 100644 index 0000000..c7c49d5 --- /dev/null +++ b/source/Window/WindowDescription.cpp @@ -0,0 +1,18 @@ + +#include + +namespace sp { + +WindowDescription::WindowDescription() : +mode (), +decoration (WindowDecorate::Default) +{ +} + +WindowDescription::WindowDescription(DisplayMode mode, unsigned decoration) : +mode (mode), +decoration (decoration) +{ +} + +} // namespace sp