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,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();