1
0
Fork 0

Rename Display to Window.

It makes more sense to be consistent and always call it window.
This commit is contained in:
Henrik Hautakoski 2023-08-22 07:12:47 +02:00
parent 416a71f744
commit 24da7f45e0
33 changed files with 257 additions and 255 deletions

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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

View file

@ -2,7 +2,7 @@
#ifndef PLATFORM_MISC_H
#define PLATFORM_MISC_H
#include <Spectre/Display/DisplayMode.h>
#include <Spectre/Window/DisplayMode.h>
#include <vector>
namespace sp {

View 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

View file

@ -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 <Spectre/Math/Vector2.h>
#include <Spectre/Display/DisplayDescription.h>
#include <Spectre/Display/DisplayMode.h>
#include <Spectre/Window/WindowDescription.h>
#include <Spectre/Window/DisplayMode.h>
#include <string>
#include <cstdint>
@ -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

View file

@ -4,7 +4,7 @@
#include <Windows.h>
#include "Win32Display.h"
#include "Win32Window.h"
#include "Win32Input.h"
#include <Spectre/System/MessageQueue.h>
#include <Platform/PlatformApplication.h>

View file

@ -1,7 +1,7 @@
#include "glad_wgl.h"
#include <Platform/PlatformDisplay.h>
#include <Platform/PlatformWindow.h>
#include <Spectre/System/Log.h>
#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) {

View file

@ -5,7 +5,7 @@
// Win32 OpenGL Context (wgl)
#include <Windows.h>
#include <Spectre/Display/GLContext.h>
#include <Spectre/Window/GLContext.h>
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();

View file

@ -1,12 +1,11 @@
#include <Windows.h>
#include <Spectre/Display/Display.h>
#include <Spectre/Window/Window.h>
#include <Spectre/System/Log.h>
#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);
}

View file

@ -3,19 +3,19 @@
#define PLATFORM_WIN32_DISPLAY_H
#include "Win32GLContext.h"
#include <Platform/PlatformDisplay.h>
#include <Platform/PlatformWindow.h>
#include <cstdint>
#include <Windows.h>
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();

View file

@ -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;

View file

@ -1,9 +1,9 @@
#include <Spectre/Display/Display.h>
#include <Spectre/Window/Window.h>
#include <Spectre/System/EventListener.h>
namespace sp {
void EventListener::onSizeChanged(Display* display, int width, int height)
void EventListener::onSizeChanged(Window* window, int width, int height)
{
}

View file

@ -1,5 +1,5 @@
#include <Spectre/Display/Display.h>
#include <Spectre/Window/Window.h>
#include <Spectre/System/MessageHandler.h>
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);
}
}

View file

@ -1,5 +1,5 @@
#include <Spectre/Display/DisplayMode.h>
#include <Spectre/Window/DisplayMode.h>
#include <Platform/PlatformMisc.h>
#include <algorithm>

View file

@ -1,5 +1,5 @@
#include <Spectre/Display/GLContext.h>
#include <Spectre/Window/GLContext.h>
#ifdef SPECTRE_PLATFORM_WIN
#include <Platform/Win32/Win32GLContext.h>

View file

@ -1,9 +1,12 @@
#include <iostream>
#include <Spectre/Display/Display.h>
#include <Spectre/Display/GLContext.h>
#include <Spectre/System/Event.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 <Platform/PlatformDisplay.h>
#include <Platform/PlatformWindow.h>
#include <Graphics/GL/gl.h>
@ -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.

View 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