Rename Display to Window.
It makes more sense to be consistent and always call it window.
This commit is contained in:
parent
416a71f744
commit
24da7f45e0
33 changed files with 257 additions and 255 deletions
14
engine.cmake
14
engine.cmake
|
|
@ -25,7 +25,7 @@ set( ENGINE_SRC
|
||||||
|
|
||||||
# Platform
|
# Platform
|
||||||
source/Platform/PlatformApplication.cpp
|
source/Platform/PlatformApplication.cpp
|
||||||
source/Platform/PlatformDisplay.cpp
|
source/Platform/PlatformWindow.cpp
|
||||||
|
|
||||||
# Math
|
# Math
|
||||||
source/Math/Color.cpp
|
source/Math/Color.cpp
|
||||||
|
|
@ -40,11 +40,11 @@ set( ENGINE_SRC
|
||||||
source/Input/Keyboard.cpp
|
source/Input/Keyboard.cpp
|
||||||
source/Input/Mouse.cpp
|
source/Input/Mouse.cpp
|
||||||
|
|
||||||
# Display
|
# Window
|
||||||
source/Display/Display.cpp
|
source/Window/Window.cpp
|
||||||
source/Display/DisplayDescription.cpp
|
source/Window/WindowDescription.cpp
|
||||||
source/Display/DisplayMode.cpp
|
source/Window/DisplayMode.cpp
|
||||||
source/Display/GLContext.cpp
|
source/Window/GLContext.cpp
|
||||||
|
|
||||||
# GfxDriver
|
# GfxDriver
|
||||||
source/GfxDriver/ShaderProgram.cpp
|
source/GfxDriver/ShaderProgram.cpp
|
||||||
|
|
@ -95,7 +95,7 @@ set(ENGINE_GFXDRIVER_OPENGL_SRC
|
||||||
|
|
||||||
set(ENGINE_PLATFORM_WIN32_SRC
|
set(ENGINE_PLATFORM_WIN32_SRC
|
||||||
source/Platform/Win32/Win32Application.cpp
|
source/Platform/Win32/Win32Application.cpp
|
||||||
source/Platform/Win32/Win32Display.cpp
|
source/Platform/Win32/Win32Window.cpp
|
||||||
source/Platform/Win32/Win32GLContext.cpp
|
source/Platform/Win32/Win32GLContext.cpp
|
||||||
source/Platform/Win32/Win32Input.cpp
|
source/Platform/Win32/Win32Input.cpp
|
||||||
source/Platform/Win32/Win32Internal.cpp
|
source/Platform/Win32/Win32Internal.cpp
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
#include <Spectre/Display/Display.h>
|
#include <Spectre/Window/Window.h>
|
||||||
#include <Spectre/Graphics/BatchRenderer2D.h>
|
#include <Spectre/Graphics/BatchRenderer2D.h>
|
||||||
#include <Spectre/System/MessageHandler.h>
|
#include <Spectre/System/MessageHandler.h>
|
||||||
#include <Spectre/System/Log.h>
|
#include <Spectre/System/Log.h>
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
void DisplayExample::init()
|
void DisplayExample::init()
|
||||||
{
|
{
|
||||||
m_renderer = new sp::BatchRenderer2D();
|
m_renderer = new sp::BatchRenderer2D();
|
||||||
m_mode = sp::Display::WINDOWED;
|
m_mode = sp::Window::WINDOWED;
|
||||||
getMessageHandler()->registerListener(this);
|
getMessageHandler()->registerListener(this);
|
||||||
|
|
||||||
m_texture.create("assets/textures/tux.png");
|
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 (event.key.code == sp::Keyboard::W) {
|
||||||
|
|
||||||
if (m_mode == sp::Display::WINDOWED) {
|
if (m_mode == sp::Window::WINDOWED) {
|
||||||
m_mode = sp::Display::WINDOWEDFULLSCREEN;
|
m_mode = sp::Window::WINDOWEDFULLSCREEN;
|
||||||
sp::Log::info("Windowed Fullscreen");
|
sp::Log::info("Windowed Fullscreen");
|
||||||
} else {
|
} else {
|
||||||
m_mode = sp::Display::WINDOWED;
|
m_mode = sp::Window::WINDOWED;
|
||||||
sp::Log::info("Windowed");
|
sp::Log::info("Windowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
getGraphics()->setDisplayMode(m_mode);
|
getGraphics()->setWindowMode(m_mode);
|
||||||
|
|
||||||
} else if (event.key.code == sp::Keyboard::Space) {
|
} else if (event.key.code == sp::Keyboard::Space) {
|
||||||
|
|
||||||
if (m_mode == sp::Display::WINDOWED) {
|
if (m_mode == sp::Window::WINDOWED) {
|
||||||
m_mode = sp::Display::FULLSCREEN;
|
m_mode = sp::Window::FULLSCREEN;
|
||||||
sp::Log::info("Fullscreen");
|
sp::Log::info("Fullscreen");
|
||||||
} else {
|
} else {
|
||||||
m_mode = sp::Display::WINDOWED;
|
m_mode = sp::Window::WINDOWED;
|
||||||
sp::Log::info("Windowed");
|
sp::Log::info("Windowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
getGraphics()->setDisplayMode(m_mode);
|
getGraphics()->setWindowMode(m_mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ protected :
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
sp::Display::Mode m_mode;
|
sp::Window::Mode m_mode;
|
||||||
|
|
||||||
sp::Camera2D m_camera;
|
sp::Camera2D m_camera;
|
||||||
sp::Renderer2D *m_renderer;
|
sp::Renderer2D *m_renderer;
|
||||||
|
|
|
||||||
|
|
@ -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.type == event.Key && !event.key.pressed) {
|
||||||
if (event.key.code == sp::Keyboard::G) {
|
if (event.key.code == sp::Keyboard::G) {
|
||||||
getGraphics()->getDisplay()->grabCursor(true);
|
getGraphics()->getWindow()->grabCursor(true);
|
||||||
sp::Log::info("Mouse Grabbed");
|
sp::Log::info("Mouse Grabbed");
|
||||||
} else if (event.key.code == sp::Keyboard::U) {
|
} else if (event.key.code == sp::Keyboard::U) {
|
||||||
getGraphics()->getDisplay()->grabCursor(false);
|
getGraphics()->getWindow()->grabCursor(false);
|
||||||
sp::Log::info("Mouse Released");
|
sp::Log::info("Mouse Released");
|
||||||
}
|
}
|
||||||
} else if (event.type == event.MouseButton && event.mouseButton.button == sp::Mouse::Right) {
|
} else if (event.type == event.MouseButton && event.mouseButton.button == sp::Mouse::Right) {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ protected :
|
||||||
|
|
||||||
void render();
|
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);
|
void onEvent(const sp::Event& event);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 */
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#define GRAPHICS_H
|
#define GRAPHICS_H
|
||||||
|
|
||||||
#include <Spectre/GfxDriver/GfxDriver.h>
|
#include <Spectre/GfxDriver/GfxDriver.h>
|
||||||
#include <Spectre/Display/Display.h>
|
#include <Spectre/Window/Window.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ public :
|
||||||
|
|
||||||
std::string getVersion() const;
|
std::string getVersion() const;
|
||||||
|
|
||||||
void setDisplayMode(Display::Mode mode);
|
void setWindowMode(Window::Mode mode);
|
||||||
|
|
||||||
void setSize(int width, int height);
|
void setSize(int width, int height);
|
||||||
|
|
||||||
|
|
@ -45,14 +45,14 @@ public :
|
||||||
|
|
||||||
GfxDriver* getDriver();
|
GfxDriver* getDriver();
|
||||||
|
|
||||||
Display* getDisplay();
|
Window* getWindow();
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
|
|
||||||
Display *m_display;
|
Window *m_window;
|
||||||
|
|
||||||
// Graphics Driver. OpenGL/Vulcan/DirectX etc.
|
// Graphics Driver. OpenGL/Vulcan/DirectX etc.
|
||||||
GfxDriver *m_gfxdrv;
|
GfxDriver *m_gfxdrv;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Display;
|
class Window;
|
||||||
|
|
||||||
struct Event
|
struct Event
|
||||||
{
|
{
|
||||||
|
|
@ -43,7 +43,7 @@ public :
|
||||||
|
|
||||||
struct SizeEvent
|
struct SizeEvent
|
||||||
{
|
{
|
||||||
Display *display;
|
Window *window;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
};
|
};
|
||||||
|
|
@ -62,7 +62,7 @@ public :
|
||||||
|
|
||||||
// Helper methods
|
// 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);
|
static Event createKey(Keyboard::Key code, bool pressed);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Display;
|
class Window;
|
||||||
|
|
||||||
class EventListener
|
class EventListener
|
||||||
{
|
{
|
||||||
public :
|
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);
|
virtual void onEvent(const Event& event);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ public :
|
||||||
|
|
||||||
void unregisterListener(EventListener *listener);
|
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);
|
virtual void onEvent(const Event& event);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
#ifndef DISPLAY_GLCONTEXT_H
|
#ifndef SPECTRE_WINDOW_GLCONTEXT_H
|
||||||
#define DISPLAY_GLCONTEXT_H
|
#define SPECTRE_WINDOW_GLCONTEXT_H
|
||||||
|
|
||||||
#include <Spectre/Math/Vector2.h>
|
#include <Spectre/Math/Vector2.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class PlatformDisplay;
|
class PlatformWindow;
|
||||||
|
|
||||||
// Platform independant interface for OpenGL Contexts.
|
// Platform independant interface for OpenGL Contexts.
|
||||||
|
|
||||||
|
|
@ -17,8 +17,8 @@ public :
|
||||||
|
|
||||||
virtual ~GLContext();
|
virtual ~GLContext();
|
||||||
|
|
||||||
// Create a GLContext for this perticular display.
|
// Create a GLContext for this perticular window.
|
||||||
virtual bool create(const PlatformDisplay* display) = 0;
|
virtual bool create(const PlatformWindow* window) = 0;
|
||||||
|
|
||||||
virtual void destroy() = 0;
|
virtual void destroy() = 0;
|
||||||
|
|
||||||
|
|
@ -44,4 +44,4 @@ public :
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
||||||
#endif /* DISPLAY_GLCONTEXT_H */
|
#endif /* SPECTRE_WINDOW_GLCONTEXT_H */
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_DISPLAY_DISPLAY_H
|
#ifndef SPECTRE_WINDOW_WINDOW_H
|
||||||
#define SPECTRE_DISPLAY_DISPLAY_H
|
#define SPECTRE_WINDOW_WINDOW_H
|
||||||
|
|
||||||
#include "DisplayMode.h"
|
#include "DisplayMode.h"
|
||||||
#include "DisplayDescription.h"
|
#include "WindowDescription.h"
|
||||||
#include <Spectre/Math/Vector2.h>
|
#include <Spectre/Math/Vector2.h>
|
||||||
#include <Spectre/Display/GLContext.h>
|
#include <Spectre/Window/GLContext.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class PlatformDisplay;
|
class PlatformWindow;
|
||||||
class GLContext;
|
class GLContext;
|
||||||
|
|
||||||
class Display
|
class Window
|
||||||
{
|
{
|
||||||
friend class PlatformDisplay;
|
friend class PlatformWindow;
|
||||||
public :
|
public :
|
||||||
enum Mode {
|
enum Mode {
|
||||||
WINDOWED = 0,
|
WINDOWED = 0,
|
||||||
|
|
@ -25,10 +25,10 @@ public :
|
||||||
};
|
};
|
||||||
|
|
||||||
public :
|
public :
|
||||||
Display();
|
Window();
|
||||||
virtual ~Display();
|
virtual ~Window();
|
||||||
|
|
||||||
bool create(DisplayDescription decription);
|
bool create(WindowDescription decription);
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
|
|
@ -78,16 +78,16 @@ protected :
|
||||||
// So it can be restored when returning to window mode.
|
// So it can be restored when returning to window mode.
|
||||||
Vector2u m_cachePos;
|
Vector2u m_cachePos;
|
||||||
|
|
||||||
DisplayDescription m_description;
|
WindowDescription m_description;
|
||||||
DisplayDescription m_cacheDesc;
|
WindowDescription m_cacheDesc;
|
||||||
|
|
||||||
std::string m_caption;
|
std::string m_caption;
|
||||||
|
|
||||||
PlatformDisplay* m_impl;
|
PlatformWindow* m_impl;
|
||||||
|
|
||||||
GLContext* m_context;
|
GLContext* m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namepsace sp
|
} // namepsace sp
|
||||||
|
|
||||||
#endif /* SPECTRE_DISPLAY_DISPLAY_H */
|
#endif /* SPECTRE_WINDOW_WINDOW_H */
|
||||||
34
include/Spectre/Window/WindowDescription.h
Normal file
34
include/Spectre/Window/WindowDescription.h
Normal file
|
|
@ -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 */
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
|
|
||||||
#include <Spectre/Display/DisplayDescription.h>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
DisplayDescription::DisplayDescription() :
|
|
||||||
mode (),
|
|
||||||
decoration (DisplayDecorate::Default)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DisplayDescription::DisplayDescription(DisplayMode mode, unsigned decoration) :
|
|
||||||
mode (mode),
|
|
||||||
decoration (decoration)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
@ -90,7 +90,7 @@ void Game::processEvents()
|
||||||
// Call message handler.
|
// Call message handler.
|
||||||
|
|
||||||
if (event.type == Event::Size) {
|
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);
|
m_messageHandler->onEvent(event);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ Graphics::Graphics(PlatformApplication *platform)
|
||||||
m_width = 800;
|
m_width = 800;
|
||||||
m_height = 600;
|
m_height = 600;
|
||||||
|
|
||||||
m_display = new Display();
|
m_window = new Window();
|
||||||
|
|
||||||
// Only have OpenGL atm.
|
// Only have OpenGL atm.
|
||||||
m_gfxdrv = new OpenGLDrv();
|
m_gfxdrv = new OpenGLDrv();
|
||||||
|
|
@ -19,16 +19,16 @@ Graphics::Graphics(PlatformApplication *platform)
|
||||||
Graphics::~Graphics()
|
Graphics::~Graphics()
|
||||||
{
|
{
|
||||||
shutdown();
|
shutdown();
|
||||||
delete m_display;
|
delete m_window;
|
||||||
delete m_gfxdrv;
|
delete m_gfxdrv;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Graphics::init()
|
bool Graphics::init()
|
||||||
{
|
{
|
||||||
DisplayMode mode(m_width, m_height);
|
DisplayMode mode(m_width, m_height);
|
||||||
DisplayDescription desc(mode);
|
WindowDescription desc(mode);
|
||||||
|
|
||||||
if (!m_display->create(desc)) {
|
if (!m_window->create(desc)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ bool Graphics::init()
|
||||||
|
|
||||||
void Graphics::shutdown()
|
void Graphics::shutdown()
|
||||||
{
|
{
|
||||||
m_display->destroy();
|
m_window->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Graphics::getVersion() const
|
std::string Graphics::getVersion() const
|
||||||
|
|
@ -49,14 +49,14 @@ std::string Graphics::getVersion() const
|
||||||
return m_gfxdrv->getVendor();
|
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)
|
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)
|
void Graphics::setViewport(int x, int y, int width, int height)
|
||||||
|
|
@ -76,7 +76,7 @@ void Graphics::clearBuffer()
|
||||||
|
|
||||||
void Graphics::swapBuffers()
|
void Graphics::swapBuffers()
|
||||||
{
|
{
|
||||||
m_display->swapBuffers();
|
m_window->swapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
GfxDriver* Graphics::getDriver()
|
GfxDriver* Graphics::getDriver()
|
||||||
|
|
@ -84,9 +84,9 @@ GfxDriver* Graphics::getDriver()
|
||||||
return m_gfxdrv;
|
return m_gfxdrv;
|
||||||
}
|
}
|
||||||
|
|
||||||
Display* Graphics::getDisplay()
|
Window* Graphics::getWindow()
|
||||||
{
|
{
|
||||||
return m_display;
|
return m_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
|
|
||||||
#include <Spectre/Display/Display.h>
|
|
||||||
#include "PlatformDisplay.h"
|
|
||||||
|
|
||||||
#ifdef SPECTRE_PLATFORM_WIN
|
|
||||||
#include <Platform/Win32/Win32Display.h>
|
|
||||||
typedef sp::Win32Display DisplayType;
|
|
||||||
#elif SPECTRE_PLATFORM_UNIX
|
|
||||||
#include <Platform/Unix/X11Display.h>
|
|
||||||
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
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#ifndef PLATFORM_MISC_H
|
#ifndef PLATFORM_MISC_H
|
||||||
#define PLATFORM_MISC_H
|
#define PLATFORM_MISC_H
|
||||||
|
|
||||||
#include <Spectre/Display/DisplayMode.h>
|
#include <Spectre/Window/DisplayMode.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
|
||||||
39
source/Platform/PlatformWindow.cpp
Normal file
39
source/Platform/PlatformWindow.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
|
||||||
|
#include <Spectre/Window/Window.h>
|
||||||
|
#include "PlatformWindow.h"
|
||||||
|
|
||||||
|
#ifdef SPECTRE_PLATFORM_WIN
|
||||||
|
#include <Platform/Win32/Win32Window.h>
|
||||||
|
typedef sp::Win32Window WindowType;
|
||||||
|
#elif SPECTRE_PLATFORM_UNIX
|
||||||
|
#include <Platform/Unix/X11Window.h>
|
||||||
|
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
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_PLATFORM_DISPLAY_H
|
#ifndef SPECTRE_PLATFORM_WINDOW_H
|
||||||
#define SPECTRE_PLATFORM_DISPLAY_H
|
#define SPECTRE_PLATFORM_WINDOW_H
|
||||||
|
|
||||||
#include <Spectre/Math/Vector2.h>
|
#include <Spectre/Math/Vector2.h>
|
||||||
#include <Spectre/Display/DisplayDescription.h>
|
#include <Spectre/Window/WindowDescription.h>
|
||||||
#include <Spectre/Display/DisplayMode.h>
|
#include <Spectre/Window/DisplayMode.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
@ -12,17 +12,17 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Display;
|
class Window;
|
||||||
|
|
||||||
class PlatformDisplay
|
class PlatformWindow
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
// Factory method.
|
// 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;
|
virtual void destroy() = 0;
|
||||||
|
|
||||||
|
|
@ -60,13 +60,13 @@ public :
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
PlatformDisplay();
|
PlatformWindow();
|
||||||
|
|
||||||
void onReshape(int width, int height);
|
void onReshape(int width, int height);
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
Display * m_parent;
|
Window * m_parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
#include "Win32Display.h"
|
#include "Win32Window.h"
|
||||||
#include "Win32Input.h"
|
#include "Win32Input.h"
|
||||||
#include <Spectre/System/MessageQueue.h>
|
#include <Spectre/System/MessageQueue.h>
|
||||||
#include <Platform/PlatformApplication.h>
|
#include <Platform/PlatformApplication.h>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#include "glad_wgl.h"
|
#include "glad_wgl.h"
|
||||||
|
|
||||||
#include <Platform/PlatformDisplay.h>
|
#include <Platform/PlatformWindow.h>
|
||||||
#include <Spectre/System/Log.h>
|
#include <Spectre/System/Log.h>
|
||||||
|
|
||||||
#include "Win32Internal.h"
|
#include "Win32Internal.h"
|
||||||
|
|
@ -43,12 +43,12 @@ Win32GLContext::~Win32GLContext()
|
||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32GLContext::create(const PlatformDisplay* display)
|
bool Win32GLContext::create(const PlatformWindow* window)
|
||||||
{
|
{
|
||||||
// If created. destroy old handles.
|
// If created. destroy old handles.
|
||||||
destroy();
|
destroy();
|
||||||
|
|
||||||
m_wnd = (HWND) display->getHandle();
|
m_wnd = (HWND) window->getHandle();
|
||||||
|
|
||||||
// Should have a valid handle here. trigger error.
|
// Should have a valid handle here. trigger error.
|
||||||
if (!m_wnd) {
|
if (!m_wnd) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
// Win32 OpenGL Context (wgl)
|
// Win32 OpenGL Context (wgl)
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <Spectre/Display/GLContext.h>
|
#include <Spectre/Window/GLContext.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@ public :
|
||||||
~Win32GLContext();
|
~Win32GLContext();
|
||||||
|
|
||||||
// Create a context associated with a display.
|
// Create a context associated with a display.
|
||||||
bool create(const PlatformDisplay* display);
|
bool create(const PlatformWindow* window);
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#include <Spectre/Window/Window.h>
|
||||||
#include <Spectre/Display/Display.h>
|
|
||||||
#include <Spectre/System/Log.h>
|
#include <Spectre/System/Log.h>
|
||||||
#include "Win32Application.h"
|
#include "Win32Application.h"
|
||||||
#include "Win32Internal.h"
|
#include "Win32Internal.h"
|
||||||
#include "Win32Display.h"
|
#include "Win32Window.h"
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
|
@ -19,7 +18,7 @@ namespace sp {
|
||||||
|
|
||||||
static bool firstTime = true;
|
static bool firstTime = true;
|
||||||
|
|
||||||
Win32Display::Win32Display() :
|
Win32Window::Win32Window() :
|
||||||
m_handle (NULL),
|
m_handle (NULL),
|
||||||
m_icon (0),
|
m_icon (0),
|
||||||
m_cursor (0),
|
m_cursor (0),
|
||||||
|
|
@ -28,7 +27,7 @@ m_minSize (200, 200)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Display::~Win32Display()
|
Win32Window::~Win32Window()
|
||||||
{
|
{
|
||||||
if (m_icon) {
|
if (m_icon) {
|
||||||
DestroyIcon(m_icon);
|
DestroyIcon(m_icon);
|
||||||
|
|
@ -39,7 +38,7 @@ Win32Display::~Win32Display()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Display::create(DisplayDescription description)
|
bool Win32Window::create(WindowDescription description)
|
||||||
{
|
{
|
||||||
DWORD flags;
|
DWORD flags;
|
||||||
Vector2i pos, actual_size;
|
Vector2i pos, actual_size;
|
||||||
|
|
@ -72,7 +71,7 @@ bool Win32Display::create(DisplayDescription description)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Display::destroy()
|
void Win32Window::destroy()
|
||||||
{
|
{
|
||||||
if (m_handle) {
|
if (m_handle) {
|
||||||
DestroyWindow(m_handle);
|
DestroyWindow(m_handle);
|
||||||
|
|
@ -80,23 +79,23 @@ void Win32Display::destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Win32Display::getHandle() const
|
void* Win32Window::getHandle() const
|
||||||
{
|
{
|
||||||
return m_handle;
|
return m_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Display::isValid()
|
bool Win32Window::isValid()
|
||||||
{
|
{
|
||||||
return m_handle != NULL;
|
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);
|
Vector2i s = calculateSize(GetWindowLong(m_handle, GWL_STYLE), width, height);
|
||||||
::SetWindowPos(m_handle, NULL, 0, 0, s.x, s.y, SWP_NOMOVE | SWP_NOZORDER);
|
::SetWindowPos(m_handle, NULL, 0, 0, s.x, s.y, SWP_NOMOVE | SWP_NOZORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2u Win32Display::getSize() const
|
Vector2u Win32Window::getSize() const
|
||||||
{
|
{
|
||||||
RECT rect;
|
RECT rect;
|
||||||
Vector2u size;
|
Vector2u size;
|
||||||
|
|
@ -108,44 +107,44 @@ Vector2u Win32Display::getSize() const
|
||||||
return size;
|
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);
|
::SetWindowPos(m_handle, NULL, x, y, 0, 0, SWP_NOSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2u Win32Display::getPosition() const
|
Vector2u Win32Window::getPosition() const
|
||||||
{
|
{
|
||||||
RECT r;
|
RECT r;
|
||||||
GetWindowRect(m_handle, &r);
|
GetWindowRect(m_handle, &r);
|
||||||
return Vector2u(r.left, r.top);
|
return Vector2u(r.left, r.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Display::setVisible(bool visible)
|
void Win32Window::setVisible(bool visible)
|
||||||
{
|
{
|
||||||
::ShowWindow(m_handle, visible ? SW_SHOW : SW_HIDE);
|
::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));
|
::SetWindowLong(m_handle, GWL_STYLE, getWin32Flags(decoration));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Display::minimize()
|
void Win32Window::minimize()
|
||||||
{
|
{
|
||||||
::ShowWindow(m_handle, SW_MINIMIZE);
|
::ShowWindow(m_handle, SW_MINIMIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Display::maximize()
|
void Win32Window::maximize()
|
||||||
{
|
{
|
||||||
::ShowWindow(m_handle, SW_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());
|
::SetWindowText(m_handle, caption.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Display::showCursor(bool value)
|
void Win32Window::showCursor(bool value)
|
||||||
{
|
{
|
||||||
if (value) {
|
if (value) {
|
||||||
m_cursor = ::LoadCursor(NULL, IDC_ARROW);
|
m_cursor = ::LoadCursor(NULL, IDC_ARROW);
|
||||||
|
|
@ -156,7 +155,7 @@ void Win32Display::showCursor(bool value)
|
||||||
::SetCursor(m_cursor);
|
::SetCursor(m_cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Display::grabCursor(bool value)
|
void Win32Window::grabCursor(bool value)
|
||||||
{
|
{
|
||||||
if (value) {
|
if (value) {
|
||||||
RECT rect;
|
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;
|
::HDC hdc;
|
||||||
::ICONINFO ii;
|
::ICONINFO ii;
|
||||||
|
|
@ -192,13 +191,13 @@ void Win32Display::setIcon(unsigned int width, unsigned int height, const uint8_
|
||||||
::ReleaseDC(NULL, hdc);
|
::ReleaseDC(NULL, hdc);
|
||||||
|
|
||||||
if (!bmp_color) {
|
if (!bmp_color) {
|
||||||
Log::error("Win32Display::setIcon() - Failed to create RGBA bitmap");
|
Log::error("Win32Window::setIcon() - Failed to create RGBA bitmap");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bmp_mask = CreateBitmap(width, height, 1, 1, NULL);
|
bmp_mask = CreateBitmap(width, height, 1, 1, NULL);
|
||||||
if (!bmp_mask) {
|
if (!bmp_mask) {
|
||||||
Log::error("Win32Display::setIcon() - Failed to create mask bitmap");
|
Log::error("Win32Window::setIcon() - Failed to create mask bitmap");
|
||||||
::DeleteObject(bmp_color);
|
::DeleteObject(bmp_color);
|
||||||
return;
|
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_SMALL, (LPARAM) m_icon);
|
||||||
::SendMessage(m_handle, WM_SETICON, ICON_BIG, (LPARAM) m_icon);
|
::SendMessage(m_handle, WM_SETICON, ICON_BIG, (LPARAM) m_icon);
|
||||||
} else {
|
} else {
|
||||||
Log::error("Win32Display::setIcon() - Failed to create icon");
|
Log::error("Win32Window::setIcon() - Failed to create icon");
|
||||||
}
|
}
|
||||||
|
|
||||||
::DeleteObject(bmp_color);
|
::DeleteObject(bmp_color);
|
||||||
::DeleteObject(bmp_mask);
|
::DeleteObject(bmp_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Display::registerClass()
|
void Win32Window::registerClass()
|
||||||
{
|
{
|
||||||
WNDCLASSA wndcl;
|
WNDCLASSA wndcl;
|
||||||
|
|
||||||
ZeroMemory(&wndcl, sizeof(wndcl));
|
ZeroMemory(&wndcl, sizeof(wndcl));
|
||||||
|
|
||||||
wndcl.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
|
wndcl.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
|
||||||
wndcl.lpfnWndProc = Win32Display::staticWndProc;
|
wndcl.lpfnWndProc = Win32Window::staticWndProc;
|
||||||
wndcl.hInstance = ::GetModuleHandle(NULL);
|
wndcl.hInstance = ::GetModuleHandle(NULL);
|
||||||
wndcl.lpszClassName = WND_CLASSNAME;
|
wndcl.lpszClassName = WND_CLASSNAME;
|
||||||
|
|
||||||
::RegisterClass(&wndcl);
|
::RegisterClass(&wndcl);
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD Win32Display::getWin32Flags(unsigned int flags)
|
DWORD Win32Window::getWin32Flags(unsigned int flags)
|
||||||
{
|
{
|
||||||
DWORD win32_flags = WS_VISIBLE;
|
DWORD win32_flags = WS_VISIBLE;
|
||||||
|
|
||||||
if (flags == DisplayDecorate::Empty) {
|
if (flags == WindowDecorate::Empty) {
|
||||||
win32_flags |= WS_POPUP;
|
win32_flags |= WS_POPUP;
|
||||||
} else {
|
} else {
|
||||||
if (flags & DisplayDecorate::Menu) {
|
if (flags & WindowDecorate::Menu) {
|
||||||
win32_flags |= WS_CAPTION | WS_MINIMIZEBOX;
|
win32_flags |= WS_CAPTION | WS_MINIMIZEBOX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DisplayDecorate::Resize) {
|
if (flags & WindowDecorate::Resize) {
|
||||||
win32_flags |= WS_THICKFRAME | WS_MAXIMIZEBOX;
|
win32_flags |= WS_THICKFRAME | WS_MAXIMIZEBOX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DisplayDecorate::Close) {
|
if (flags & WindowDecorate::Close) {
|
||||||
win32_flags |= WS_SYSMENU;
|
win32_flags |= WS_SYSMENU;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return win32_flags;
|
return win32_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2i Win32Display::centerWindow(int width, int height)
|
Vector2i Win32Window::centerWindow(int width, int height)
|
||||||
{
|
{
|
||||||
Vector2i v;
|
Vector2i v;
|
||||||
v.x = (::GetSystemMetrics(SM_CXSCREEN) - width) / 2;
|
v.x = (::GetSystemMetrics(SM_CXSCREEN) - width) / 2;
|
||||||
|
|
@ -279,14 +278,14 @@ Vector2i Win32Display::centerWindow(int width, int height)
|
||||||
return v;
|
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};
|
RECT r = {0, 0, width, height};
|
||||||
AdjustWindowRect(&r, flags, false);
|
AdjustWindowRect(&r, flags, false);
|
||||||
return Vector2u(r.right - r.left, r.bottom - r.top);
|
return Vector2u(r.right - r.left, r.bottom - r.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Display::enterFullscreen(DisplayMode mode)
|
void Win32Window::enterFullscreen(DisplayMode mode)
|
||||||
{
|
{
|
||||||
LONG rc;
|
LONG rc;
|
||||||
::DEVMODEW dev;
|
::DEVMODEW dev;
|
||||||
|
|
@ -331,7 +330,7 @@ void Win32Display::enterFullscreen(DisplayMode mode)
|
||||||
m_fs_mode = mode;
|
m_fs_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Display::exitFullscreen()
|
void Win32Window::exitFullscreen()
|
||||||
{
|
{
|
||||||
if (!m_fs_mode.empty()) {
|
if (!m_fs_mode.empty()) {
|
||||||
// Restore to previous mode.
|
// 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.
|
// Check if the size has actually changed.
|
||||||
if (m_size != new_size) {
|
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) {
|
switch(message) {
|
||||||
case WM_SETCURSOR :
|
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) {
|
if (message == WM_NCCREATE) {
|
||||||
|
|
||||||
LONG_PTR ptr = (LONG_PTR) ((LPCREATESTRUCT)lParam)->lpCreateParams;
|
LONG_PTR ptr = (LONG_PTR) ((LPCREATESTRUCT)lParam)->lpCreateParams;
|
||||||
::SetWindowLongPtr(handle, GWL_USERDATA, ptr);
|
::SetWindowLongPtr(handle, GWL_USERDATA, ptr);
|
||||||
|
|
||||||
display = (Win32Display*) ptr;
|
win = (Win32Window*) ptr;
|
||||||
} else {
|
} else {
|
||||||
display = (Win32Display*) ::GetWindowLongPtr(handle, GWL_USERDATA);
|
win = (Win32Window*) ::GetWindowLongPtr(handle, GWL_USERDATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (display) {
|
if (win) {
|
||||||
display->processMessage(message, wParam, lParam);
|
win->processMessage(message, wParam, lParam);
|
||||||
}
|
}
|
||||||
return DefWindowProc(handle, message, wParam, lParam);
|
return DefWindowProc(handle, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
@ -3,19 +3,19 @@
|
||||||
#define PLATFORM_WIN32_DISPLAY_H
|
#define PLATFORM_WIN32_DISPLAY_H
|
||||||
|
|
||||||
#include "Win32GLContext.h"
|
#include "Win32GLContext.h"
|
||||||
#include <Platform/PlatformDisplay.h>
|
#include <Platform/PlatformWindow.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Win32Display : public PlatformDisplay
|
class Win32Window : public PlatformWindow
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
Win32Display();
|
Win32Window();
|
||||||
virtual ~Win32Display();
|
virtual ~Win32Window();
|
||||||
|
|
||||||
virtual bool create(DisplayDescription description);
|
virtual bool create(WindowDescription description);
|
||||||
|
|
||||||
virtual void destroy();
|
virtual void destroy();
|
||||||
|
|
||||||
|
|
@ -38,10 +38,10 @@ std::string Event::MouseButtonEvent::getName() const
|
||||||
|
|
||||||
// Helper methods
|
// Helper methods
|
||||||
|
|
||||||
Event Event::createSize(Display *display, int width, int height)
|
Event Event::createSize(Window *window, int width, int height)
|
||||||
{
|
{
|
||||||
Event event(Size);
|
Event event(Size);
|
||||||
event.size.display = display;
|
event.size.window = window;
|
||||||
event.size.width = width;
|
event.size.width = width;
|
||||||
event.size.height = height;
|
event.size.height = height;
|
||||||
return event;
|
return event;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#include <Spectre/Display/Display.h>
|
#include <Spectre/Window/Window.h>
|
||||||
#include <Spectre/System/EventListener.h>
|
#include <Spectre/System/EventListener.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
void EventListener::onSizeChanged(Display* display, int width, int height)
|
void EventListener::onSizeChanged(Window* window, int width, int height)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
#include <Spectre/Display/Display.h>
|
#include <Spectre/Window/Window.h>
|
||||||
#include <Spectre/System/MessageHandler.h>
|
#include <Spectre/System/MessageHandler.h>
|
||||||
|
|
||||||
namespace sp {
|
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) {
|
for(EventListener* listener : m_listeners) {
|
||||||
listener->onSizeChanged(display, width, height);
|
listener->onSizeChanged(window, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
#include <Spectre/Display/DisplayMode.h>
|
#include <Spectre/Window/DisplayMode.h>
|
||||||
#include <Platform/PlatformMisc.h>
|
#include <Platform/PlatformMisc.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
#include <Spectre/Display/GLContext.h>
|
#include <Spectre/Window/GLContext.h>
|
||||||
|
|
||||||
#ifdef SPECTRE_PLATFORM_WIN
|
#ifdef SPECTRE_PLATFORM_WIN
|
||||||
#include <Platform/Win32/Win32GLContext.h>
|
#include <Platform/Win32/Win32GLContext.h>
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Spectre/Display/Display.h>
|
#include <Spectre/System/Event.h>
|
||||||
#include <Spectre/Display/GLContext.h>
|
#include <Spectre/System/MessageQueue.h>
|
||||||
|
#include <Spectre/System/Log.h>
|
||||||
|
#include <Spectre/Window/Window.h>
|
||||||
|
#include <Spectre/Window/GLContext.h>
|
||||||
#include <Spectre/Graphics/Image.h>
|
#include <Spectre/Graphics/Image.h>
|
||||||
#include <Platform/PlatformDisplay.h>
|
#include <Platform/PlatformWindow.h>
|
||||||
|
|
||||||
#include <Graphics/GL/gl.h>
|
#include <Graphics/GL/gl.h>
|
||||||
|
|
||||||
|
|
@ -12,22 +15,22 @@ namespace sp {
|
||||||
#define CAPTION_DEFAULT "Spectre"
|
#define CAPTION_DEFAULT "Spectre"
|
||||||
#define ICON_DEFAULT "./assets/app.ico"
|
#define ICON_DEFAULT "./assets/app.ico"
|
||||||
|
|
||||||
Display::Display()
|
Window::Window()
|
||||||
{
|
{
|
||||||
m_caption = CAPTION_DEFAULT;
|
m_caption = CAPTION_DEFAULT;
|
||||||
m_fmode = WINDOWED;
|
m_fmode = WINDOWED;
|
||||||
|
|
||||||
m_context = GLContext::create();
|
m_context = GLContext::create();
|
||||||
m_impl = PlatformDisplay::make(this);
|
m_impl = PlatformWindow::make(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Display::~Display()
|
Window::~Window()
|
||||||
{
|
{
|
||||||
delete m_context;
|
delete m_context;
|
||||||
delete m_impl;
|
delete m_impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Display::create(DisplayDescription description)
|
bool Window::create(WindowDescription description)
|
||||||
{
|
{
|
||||||
destroy();
|
destroy();
|
||||||
|
|
||||||
|
|
@ -46,7 +49,7 @@ bool Display::create(DisplayDescription description)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::init()
|
void Window::init()
|
||||||
{
|
{
|
||||||
m_impl->setCaption(m_caption);
|
m_impl->setCaption(m_caption);
|
||||||
|
|
||||||
|
|
@ -58,25 +61,25 @@ void Display::init()
|
||||||
showCursor(true);
|
showCursor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::destroy()
|
void Window::destroy()
|
||||||
{
|
{
|
||||||
m_context->destroy();
|
m_context->destroy();
|
||||||
|
|
||||||
m_impl->destroy();
|
m_impl->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::setCaption(const std::string& caption)
|
void Window::setCaption(const std::string& caption)
|
||||||
{
|
{
|
||||||
m_caption = caption;
|
m_caption = caption;
|
||||||
m_impl->setCaption(m_caption);
|
m_impl->setCaption(m_caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Display::getCaption() const
|
const std::string& Window::getCaption() const
|
||||||
{
|
{
|
||||||
return m_caption;
|
return m_caption;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::setIcon(const std::string& filename)
|
void Window::setIcon(const std::string& filename)
|
||||||
{
|
{
|
||||||
Image img;
|
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);
|
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.width = width;
|
||||||
m_description.mode.height = height;
|
m_description.mode.height = height;
|
||||||
|
|
@ -98,12 +101,12 @@ void Display::setSize(unsigned int width, unsigned int height)
|
||||||
m_impl->setSize(width, height);
|
m_impl->setSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
sp::Vector2u Display::getSize() const
|
sp::Vector2u Window::getSize() const
|
||||||
{
|
{
|
||||||
return m_impl->getSize();
|
return m_impl->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::setVideoMode(Mode mode)
|
void Window::setVideoMode(Mode mode)
|
||||||
{
|
{
|
||||||
if (m_fmode == mode) {
|
if (m_fmode == mode) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -125,7 +128,7 @@ void Display::setVideoMode(Mode mode)
|
||||||
// Windowed fullscreen.
|
// Windowed fullscreen.
|
||||||
else if (mode == WINDOWEDFULLSCREEN) {
|
else if (mode == WINDOWEDFULLSCREEN) {
|
||||||
DisplayMode desktop = DisplayMode::getDesktopMode();
|
DisplayMode desktop = DisplayMode::getDesktopMode();
|
||||||
m_impl->setDecoration(DisplayDecorate::Empty);
|
m_impl->setDecoration(WindowDecorate::Empty);
|
||||||
m_impl->setSize(desktop.width, desktop.height);
|
m_impl->setSize(desktop.width, desktop.height);
|
||||||
m_impl->setPosition(0, 0);
|
m_impl->setPosition(0, 0);
|
||||||
}
|
}
|
||||||
|
|
@ -142,27 +145,27 @@ void Display::setVideoMode(Mode mode)
|
||||||
m_fmode = mode;
|
m_fmode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Display::Mode Display::getVideoMode() const
|
enum Window::Mode Window::getVideoMode() const
|
||||||
{
|
{
|
||||||
return m_fmode;
|
return m_fmode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::setVisible(bool visible)
|
void Window::setVisible(bool visible)
|
||||||
{
|
{
|
||||||
m_impl->setVisible(visible);
|
m_impl->setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::showCursor(bool value)
|
void Window::showCursor(bool value)
|
||||||
{
|
{
|
||||||
m_impl->showCursor(value);
|
m_impl->showCursor(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::grabCursor(bool value)
|
void Window::grabCursor(bool value)
|
||||||
{
|
{
|
||||||
m_impl->grabCursor(value);
|
m_impl->grabCursor(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Display::activate(bool value)
|
bool Window::activate(bool value)
|
||||||
{
|
{
|
||||||
if (value) {
|
if (value) {
|
||||||
return m_context->activate();
|
return m_context->activate();
|
||||||
|
|
@ -170,19 +173,19 @@ bool Display::activate(bool value)
|
||||||
return m_context->deactivate();
|
return m_context->deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Display::enableVSync(bool value)
|
bool Window::enableVSync(bool value)
|
||||||
{
|
{
|
||||||
return m_context->setSwapInterval(value ? 1 : 0);
|
return m_context->setSwapInterval(value ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::swapBuffers()
|
void Window::swapBuffers()
|
||||||
{
|
{
|
||||||
if (activate(true)) {
|
if (activate(true)) {
|
||||||
m_context->swapBuffers();
|
m_context->swapBuffers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::onReshape(int width, int height)
|
void Window::onReshape(int width, int height)
|
||||||
{
|
{
|
||||||
// TODO: This should even not be here.
|
// TODO: This should even not be here.
|
||||||
// Generic Display should not have any GL calls.
|
// Generic Display should not have any GL calls.
|
||||||
18
source/Window/WindowDescription.cpp
Normal file
18
source/Window/WindowDescription.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
#include <Spectre/Window/WindowDescription.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
WindowDescription::WindowDescription() :
|
||||||
|
mode (),
|
||||||
|
decoration (WindowDecorate::Default)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowDescription::WindowDescription(DisplayMode mode, unsigned decoration) :
|
||||||
|
mode (mode),
|
||||||
|
decoration (decoration)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
Loading…
Add table
Add a link
Reference in a new issue