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

@ -0,0 +1,48 @@
#ifndef SPECTRE_DISPLAY_DISPLAYMODE_H
#define SPECTRE_DISPLAY_DISPLAYMODE_H
#include <vector>
namespace sp {
class DisplayMode
{
public :
DisplayMode();
DisplayMode(unsigned int width, unsigned int height, unsigned int bpp = 32);
static std::vector<DisplayMode> getFullscreenModes();
static DisplayMode getDesktopMode();
// Returns true if width hight and bpp are not set (eg. zero)
// useful to determine if a DisplayMode object is set or not.
// this is equal to:
// DisplayMode a;
// if (a == DisplayMode()) {
// // empty
// }
bool empty() const;
inline bool operator==(const DisplayMode& other)
{
return width == other.width
&& height == other.height
&& bpp == other.bpp;
}
inline bool operator!=(const DisplayMode& other)
{
return !(*this == other);
}
public :
unsigned int width;
unsigned int height;
unsigned int bpp; /* Bits per pixel. */
};
} // namespace sp
#endif /* SPECTRE_DISPLAY_DISPLAYMODE_H */

View file

@ -0,0 +1,47 @@
#ifndef SPECTRE_WINDOW_GLCONTEXT_H
#define SPECTRE_WINDOW_GLCONTEXT_H
#include <Spectre/Math/Vector2.h>
namespace sp {
class PlatformWindow;
// Platform independant interface for OpenGL Contexts.
class GLContext
{
public :
static GLContext* create();
virtual ~GLContext();
// Create a GLContext for this perticular window.
virtual bool create(const PlatformWindow* window) = 0;
virtual void destroy() = 0;
// Activate this context.
virtual bool activate() = 0;
// Deactivate this context.
virtual bool deactivate() = 0;
// Returns true if this context is the active one. false otherwise.
// There can only be one GL context active per thread.
virtual bool isActive() const = 0;
// Set the interval for when the front and back framebuffers should be swapped.
// The interval is the number of v-blanks that the gpu must wait before swapping buffers.
// 0 means that the gpu never waits, 1 means after exactly 1 v-blank and so on.
// This is usually refered to as enabling/disabling vertical synchronization.
virtual bool setSwapInterval(int interval) = 0;
// Swap front with back buffer and vice versa.
virtual void swapBuffers() = 0;
};
} // namespace sp
#endif /* SPECTRE_WINDOW_GLCONTEXT_H */

View file

@ -0,0 +1,93 @@
#ifndef SPECTRE_WINDOW_WINDOW_H
#define SPECTRE_WINDOW_WINDOW_H
#include "DisplayMode.h"
#include "WindowDescription.h"
#include <Spectre/Math/Vector2.h>
#include <Spectre/Window/GLContext.h>
#include <cstdint>
#include <string>
namespace sp {
class PlatformWindow;
class GLContext;
class Window
{
friend class PlatformWindow;
public :
enum Mode {
WINDOWED = 0,
FULLSCREEN = 1,
WINDOWEDFULLSCREEN = 2,
};
public :
Window();
virtual ~Window();
bool create(WindowDescription decription);
void destroy();
void setSize(unsigned int width, unsigned int height);
sp::Vector2u getSize() const;
void setCaption(const std::string& title);
const std::string& getCaption() const;
void setIcon(const std::string& filename);
void setIcon(unsigned int width, unsigned int height, const uint8_t *pixels);
void setDisplayMode(const DisplayMode& mode);
const DisplayMode& getDisplayMode() const;
void setVideoMode(Mode mode);
enum Mode getVideoMode() const;
void setVisible(bool visible);
void showCursor(bool value);
void grabCursor(bool value);
bool activate(bool value);
// Enable/Disable Vertical Sync.
bool enableVSync(bool value);
void swapBuffers();
protected :
void init();
void onReshape(int width, int height);
protected :
enum Mode m_fmode;
// Cache window position when entering fullscreen
// So it can be restored when returning to window mode.
Vector2u m_cachePos;
WindowDescription m_description;
WindowDescription m_cacheDesc;
std::string m_caption;
PlatformWindow* m_impl;
GLContext* m_context;
};
} // namepsace sp
#endif /* SPECTRE_WINDOW_WINDOW_H */

View 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 */