Glfwx  0.1.0
C++ wrapper for GLFW
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Glfwx::Window Class Reference

C++ wrapper for a GLFW window. More...

#include <Glfwx/Window.h>

Public Types

enum  Hint {
  FOCUSED = GLFW_FOCUSED, ICONIFIED = GLFW_ICONIFIED, RESIZABLE = GLFW_RESIZABLE, VISIBLE = GLFW_VISIBLE,
  DECORATED = GLFW_DECORATED, AUTO_ICONIFY = GLFW_AUTO_ICONIFY, FLOATING = GLFW_FLOATING, MAXIMIZED = GLFW_MAXIMIZED,
  CENTER_CURSOR = GLFW_CENTER_CURSOR, TRANSPARENT_FRAMEBUFFER = GLFW_TRANSPARENT_FRAMEBUFFER, HOVERED = GLFW_HOVERED, FOCUS_ON_SHOW = GLFW_FOCUS_ON_SHOW,
  RED_BITS = GLFW_RED_BITS, GREEN_BITS = GLFW_GREEN_BITS, BLUE_BITS = GLFW_BLUE_BITS, ALPHA_BITS = GLFW_ALPHA_BITS,
  DEPTH_BITS = GLFW_DEPTH_BITS, STENCIL_BITS = GLFW_STENCIL_BITS, ACCUM_RED_BITS = GLFW_ACCUM_RED_BITS, ACCUM_GREEN_BITS = GLFW_ACCUM_GREEN_BITS,
  ACCUM_BLUE_BITS = GLFW_ACCUM_BLUE_BITS, ACCUM_ALPHA_BITS = GLFW_ACCUM_ALPHA_BITS, AUX_BUFFERS = GLFW_AUX_BUFFERS, STEREO = GLFW_STEREO,
  SAMPLES = GLFW_SAMPLES, SRGB_CAPABLE = GLFW_SRGB_CAPABLE, REFRESH_RATE = GLFW_REFRESH_RATE, DOUBLEBUFFER = GLFW_DOUBLEBUFFER,
  CLIENT_API = GLFW_CLIENT_API, CONTEXT_VERSION_MAJOR = GLFW_CONTEXT_VERSION_MAJOR, CONTEXT_VERSION_MINOR = GLFW_CONTEXT_VERSION_MINOR, CONTEXT_REVISION = GLFW_CONTEXT_REVISION,
  CONTEXT_ROBUSTNESS = GLFW_CONTEXT_ROBUSTNESS, OPENGL_FORWARD_COMPAT = GLFW_OPENGL_FORWARD_COMPAT, OPENGL_DEBUG_CONTEXT = GLFW_OPENGL_DEBUG_CONTEXT, OPENGL_PROFILE = GLFW_OPENGL_PROFILE,
  CONTEXT_RELEASE_BEHAVIOR = GLFW_CONTEXT_RELEASE_BEHAVIOR, CONTEXT_NO_ERROR = GLFW_CONTEXT_NO_ERROR, CONTEXT_CREATION_API = GLFW_CONTEXT_CREATION_API, SCALE_TO_MONITOR = GLFW_SCALE_TO_MONITOR,
  COCOA_RETINA_FRAMEBUFFER = GLFW_COCOA_RETINA_FRAMEBUFFER, COCOA_FRAME_NAME = GLFW_COCOA_FRAME_NAME, COCOA_GRAPHICS_SWITCHING = GLFW_COCOA_GRAPHICS_SWITCHING, X11_CLASS_NAME = GLFW_X11_CLASS_NAME,
  X11_INSTANCE_NAME = GLFW_X11_INSTANCE_NAME, JOYSTICK_HAT_BUTTONS = GLFW_JOYSTICK_HAT_BUTTONS, COCOA_CHDIR_RESOURCES = GLFW_COCOA_CHDIR_RESOURCES, COCOA_MENUBAR = GLFW_COCOA_MENUBAR
}
 Window hints. More...
 
enum  Attribute {
  FOCUSED = GLFW_FOCUSED, ICONIFIED = GLFW_ICONIFIED, VISIBLE = GLFW_VISIBLE, DECORATED = GLFW_DECORATED,
  AUTO_ICONIFY = GLFW_AUTO_ICONIFY, RESIZABLE = GLFW_RESIZABLE, FLOATING = GLFW_FLOATING, MAXIMIZED = GLFW_MAXIMIZED,
  TRANSPARENT_FRAMEBUFFER = GLFW_TRANSPARENT_FRAMEBUFFER, HOVERED = GLFW_HOVERED, FOCUS_ON_SHOW = GLFW_FOCUS_ON_SHOW, CLIENT_API = GLFW_CLIENT_API,
  CONTEXT_VERSION_MAJOR = GLFW_CONTEXT_VERSION_MAJOR, CONTEXT_VERSION_MINOR = GLFW_CONTEXT_VERSION_MINOR, CONTEXT_REVISION = GLFW_CONTEXT_REVISION, CONTEXT_ROBUSTNESS = GLFW_CONTEXT_ROBUSTNESS,
  OPENGL_FORWARD_COMPAT = GLFW_OPENGL_FORWARD_COMPAT, OPENGL_DEBUG_CONTEXT = GLFW_OPENGL_DEBUG_CONTEXT, OPENGL_PROFILE = GLFW_OPENGL_PROFILE, CONTEXT_RELEASE_BEHAVIOR = GLFW_CONTEXT_RELEASE_BEHAVIOR,
  CONTEXT_NO_ERROR = GLFW_CONTEXT_NO_ERROR, CONTEXT_CREATION_API = GLFW_CONTEXT_CREATION_API
}
 Window attributes. More...
 

Public Member Functions

 Window (int width, int height, char const *title, Monitor *monitor=nullptr, GLFWwindow *share=nullptr)
 Constructor. More...
 
virtual ~Window ()
 Destructor. More...
 
void setTitle (char const *title)
 Sets the title. More...
 
void setIcon (std::vector< GLFWimage > images=std::vector< GLFWimage >())
 Sets the window's icon. More...
 
void setPosition (int x, int y)
 Sets the window's position. More...
 
void position (int &x, int &y) const
 Returns the window's position. More...
 
void setSize (int width, int height)
 Sets the size of the window. More...
 
void size (int &width, int &height) const
 Returns the width and height of the window. More...
 
void contentScale (float &x, float &y) const
 Returns the content scale. More...
 
void setSizeLimits (int minWidth=-1, int minHeight=-1, int maxWidth=-1, int maxHeight=-1)
 Limits the size of the window. More...
 
void setAspectRatio (int n, int d)
 Sets the window's aspect ratio. More...
 
void framebufferSize (int &width, int &height) const
 Returns the width and height of the window's framebuffer. More...
 
void frame (int &left, int &top, int &right, int &bottom) const
 Returns the locations of the edges of the window's frame. More...
 
void iconify ()
 Reduces the window to an icon.
 
void restore ()
 Displays the window normally.
 
void maximize ()
 Fits the window to the size of the screen.
 
void show (bool shown=true)
 Shows or hides the window. More...
 
void focus ()
 Sets the focus to the window.
 
Monitor monitor () const
 Returns the window's monitor. More...
 
void setMonitor (GLFWmonitor *monitor, int x, int y, int width, int height, int refreshRate)
 Sets the window's monitor parameters. More...
 
void setAttribute (Attribute id, int value)
 Sets the value of the specified attribute. More...
 
int attribute (Attribute id) const
 Returns the value of the specified attribute. More...
 
void setContext (void *context)
 Saves a context for the window. More...
 
void * context () const
 Returns the previously set context, or nullptr.
 
int processEvents ()
 Processes any window activity. More...
 
int waitEvents ()
 Waits for any window activity and processes it. More...
 
Vulkan-specific

These methods are specific to Vulkan and defined only when GLFW_INCLUDE_VULKAN is defined

VkSurfaceKHR createSurface (VkInstance instance, VkAllocationCallbacks *allocator) const
 Creates a device-specific Vulkan surface. More...
 

Static Public Member Functions

static void resetHints ()
 Resets all window hints back to default values. More...
 
static void hint (Hint id, int value)
 Provides some window initialization context. More...
 

Static Public Attributes

Client API attribute values
Note
as of GLFW 3.3.2
See also
CLIENT_API
static int constexpr NO_API = GLFW_NO_API
 
static int constexpr OPENGL_API = GLFW_OPENGL_API
 
static int constexpr OPENGL_ES_API = GLFW_OPENGL_ES_API
 
Context robustness attribute values
Note
as of GLFW 3.3.2
See also
CONTEXT_ROBUSTNESS
static int constexpr NO_ROBUSTNESS = GLFW_NO_ROBUSTNESS
 
static int constexpr NO_RESET_NOTIFICATION = GLFW_NO_RESET_NOTIFICATION
 
static int constexpr LOSE_CONTEXT_ON_RESET = GLFW_LOSE_CONTEXT_ON_RESET
 
OpenGL profile attribute values
Note
as of GLFW 3.3.2
See also
OPENGL_PROFILE
static int constexpr OPENGL_ANY_PROFILE = GLFW_OPENGL_ANY_PROFILE
 
static int constexpr OPENGL_CORE_PROFILE = GLFW_OPENGL_CORE_PROFILE
 
static int constexpr OPENGL_COMPAT_PROFILE = GLFW_OPENGL_COMPAT_PROFILE
 
Context release behavior attribute values
Note
as of GLFW 3.3.2
See also
CONTEXT_RELEASE_BEHAVIOR
static int constexpr ANY_RELEASE_BEHAVIOR = GLFW_ANY_RELEASE_BEHAVIOR
 
static int constexpr RELEASE_BEHAVIOR_FLUSH = GLFW_RELEASE_BEHAVIOR_FLUSH
 
static int constexpr RELEASE_BEHAVIOR_NONE = GLFW_RELEASE_BEHAVIOR_NONE
 
Context creation API attribute values
Note
as of GLFW 3.3.2
See also
CONTEXT_CREATION_API
static int constexpr NATIVE_CONTEXT_API = GLFW_NATIVE_CONTEXT_API
 
static int constexpr EGL_CONTEXT_API = GLFW_EGL_CONTEXT_API
 
static int constexpr OSMESA_CONTEXT_API = GLFW_OSMESA_CONTEXT_API
 

Private Member Functions

Overridable Notifications

These methods must be overridden in order to receive the appropriate notifications.

virtual void onPositionChanged (int x, int y)
 Called when the window position is changed. More...
 
virtual void onSizeChanged (int width, int height)
 Called when the size of the window is changed. More...
 
virtual void onClose ()
 Called before the window is closed. More...
 
virtual void onRefresh ()
 Called when the contents of the window need to be refreshed. More...
 
virtual void onFocusChanged (int gained)
 Called when the window focused has changed to or from the window. More...
 
virtual void onIconifyChanged (int iconified)
 Called when the window has changed to or from the icon state. More...
 
virtual void onMaximizeChanged (int maximized)
 Called when the when changes to or from maximized state. More...
 
virtual void onFramebufferSizeChanged (int width, int height)
 Called when the size of the window's framebuffer changes. More...
 
virtual void onContentScaleChanged (float x, float y)
 Called when the window's content scale changes. More...
 

Detailed Description

C++ wrapper for a GLFW window.

See also
GLFWwindow

Member Enumeration Documentation

◆ Attribute

Window attributes.

Note
as of GLFW 3.3.2

◆ Hint

enum Glfwx::Window::Hint
strong

Window hints.

Note
as of GLFW 3.3.2

Constructor & Destructor Documentation

◆ Window()

Glfwx::Window::Window ( int  width,
int  height,
char const *  title,
Monitor monitor = nullptr,
GLFWwindow *  share = nullptr 
)

Constructor.

Parameters
widthThe desired width of the window (must be > 0)
heightThe desired height of the window (must be > 0)
titleThe initial UTF-8 window title
monitorThe monitor to use for full screen mode, or nullptr for windowed mode (optional)
shareThe window whose context to share resources with, or nullptr to not share resources (optional)
See also
hint()
Warning
GLFW requires that the window be constructed in the main thread.

◆ ~Window()

virtual Glfwx::Window::~Window ( )
virtual

Destructor.

See also
glfwDestroyWindow

Member Function Documentation

◆ attribute()

int Glfwx::Window::attribute ( Attribute  id) const

Returns the value of the specified attribute.

Parameters
idThe attribute to query
Returns
The attribute's value

◆ contentScale()

void Glfwx::Window::contentScale ( float &  x,
float &  y 
) const

Returns the content scale.

Parameters
[out]xScale
[out]yScale

◆ createSurface()

VkSurfaceKHR Glfwx::Window::createSurface ( VkInstance  instance,
VkAllocationCallbacks *  allocator 
) const

Creates a device-specific Vulkan surface.

Parameters
instanceVulkan instance
allocatorVulkan allocator
Returns
Vulkan surface
See also
glfwCreateWindowSurface

◆ frame()

void Glfwx::Window::frame ( int &  left,
int &  top,
int &  right,
int &  bottom 
) const

Returns the locations of the edges of the window's frame.

Parameters
[out]leftLocation of the left edge
[out]topLocation of the top edge
[out]rightLocation of the right edge
[out]bottomLocation of the bottom edge

◆ framebufferSize()

void Glfwx::Window::framebufferSize ( int &  width,
int &  height 
) const

Returns the width and height of the window's framebuffer.

Parameters
[out]widthWidth
[out]heightHeight

◆ hint()

static void Glfwx::Window::hint ( Hint  id,
int  value 
)
static

Provides some window initialization context.

Parameters
idHint ID
valueValue
See also
Hint
glfwWindowHint

◆ monitor()

Monitor Glfwx::Window::monitor ( ) const

Returns the window's monitor.

Returns
The window's monitor

◆ onClose()

virtual void Glfwx::Window::onClose ( )
privatevirtual

Called before the window is closed.

Note
Override this method to be notified of this event

◆ onContentScaleChanged()

virtual void Glfwx::Window::onContentScaleChanged ( float  x,
float  y 
)
privatevirtual

Called when the window's content scale changes.

Parameters
xNew scale
yNew scale
Note
Override this method to be notified of this event

◆ onFocusChanged()

virtual void Glfwx::Window::onFocusChanged ( int  gained)
privatevirtual

Called when the window focused has changed to or from the window.

Parameters
gained1 if the window gains focus. 0 if the window loses focus.
Note
Override this method to be notified of this event

◆ onFramebufferSizeChanged()

virtual void Glfwx::Window::onFramebufferSizeChanged ( int  width,
int  height 
)
privatevirtual

Called when the size of the window's framebuffer changes.

Parameters
widthNew framebuffer size
heightNew framebuffer size
Note
Override this method to be notified of this event

◆ onIconifyChanged()

virtual void Glfwx::Window::onIconifyChanged ( int  iconified)
privatevirtual

Called when the window has changed to or from the icon state.

Parameters
iconified1 if the window is iconified. 0 if the window is opened.
Note
Override this method to be notified of this event

◆ onMaximizeChanged()

virtual void Glfwx::Window::onMaximizeChanged ( int  maximized)
privatevirtual

Called when the when changes to or from maximized state.

Parameters
maximized1 if the window is maximized, 0 if the window returns to normal
Note
Override this method to be notified of this event

◆ onPositionChanged()

virtual void Glfwx::Window::onPositionChanged ( int  x,
int  y 
)
privatevirtual

Called when the window position is changed.

Parameters
xNew location
yNew location
Note
Override this method to be notified of this event

◆ onRefresh()

virtual void Glfwx::Window::onRefresh ( )
privatevirtual

Called when the contents of the window need to be refreshed.

Note
Override this method to be notified of this event

◆ onSizeChanged()

virtual void Glfwx::Window::onSizeChanged ( int  width,
int  height 
)
privatevirtual

Called when the size of the window is changed.

Parameters
widthNew size
heightNew size
Note
Override this method to be notified of this event

◆ position()

void Glfwx::Window::position ( int &  x,
int &  y 
) const

Returns the window's position.

Parameters
[out]xHorizontal position
[out]yVertical position
See also
glfwGetWindowPos

◆ processEvents()

int Glfwx::Window::processEvents ( )

Processes any window activity.

Returns
The close value
See also
glfwPollEvents
glfwWindowShouldClose

◆ resetHints()

static void Glfwx::Window::resetHints ( )
static

Resets all window hints back to default values.

See also
Hint
glfwDefaultWindowHints

◆ setAspectRatio()

void Glfwx::Window::setAspectRatio ( int  n,
int  d 
)

Sets the window's aspect ratio.

The aspect ratio is set the value of the fraction n/d.

Parameters
nnumerator
ddenominator

◆ setAttribute()

void Glfwx::Window::setAttribute ( Attribute  id,
int  value 
)

Sets the value of the specified attribute.

Parameters
idThe attribute to change
valueTHe value to set
See also
Attribute

◆ setContext()

void Glfwx::Window::setContext ( void *  context)

Saves a context for the window.

Parameters
contextValue to set

◆ setIcon()

void Glfwx::Window::setIcon ( std::vector< GLFWimage >  images = std::vector<GLFWimage>())

Sets the window's icon.

Parameters
imagesicon images (default: reset to default)
See also
glfwSetWindowIcon
GLFWimage

◆ setMonitor()

void Glfwx::Window::setMonitor ( GLFWmonitor *  monitor,
int  x,
int  y,
int  width,
int  height,
int  refreshRate 
)

Sets the window's monitor parameters.

Parameters
monitorMonitor to display window
xLocation
yLocation
widthSize
heightSize
refreshRateRefresh rate

◆ setPosition()

void Glfwx::Window::setPosition ( int  x,
int  y 
)

Sets the window's position.

Parameters
xHorizontal position
yVertical position
See also
glfwSetWindowPos

◆ setSize()

void Glfwx::Window::setSize ( int  width,
int  height 
)

Sets the size of the window.

Parameters
widthSize
heightSize

◆ setSizeLimits()

void Glfwx::Window::setSizeLimits ( int  minWidth = -1,
int  minHeight = -1,
int  maxWidth = -1,
int  maxHeight = -1 
)

Limits the size of the window.

Parameters
minWidthMinimum size (-1 = no limit, optional, default is -1)
minHeightMinimum size (-1 = no limit, optional, default is -1)
maxWidthMaximum size (-1 = no limit, optional, default is -1)
maxHeightMaximum size (-1 = no limit, optional, default is -1)
See also
glfwSetWindowSizeLimits

◆ setTitle()

void Glfwx::Window::setTitle ( char const *  title)

Sets the title.

Parameters
titleNew title
See also
glfwSetWindowTitle

◆ show()

void Glfwx::Window::show ( bool  shown = true)

Shows or hides the window.

Parameters
shownShows if true, hides if false (optional, default is true)

◆ size()

void Glfwx::Window::size ( int &  width,
int &  height 
) const

Returns the width and height of the window.

Parameters
[out]widthSize
[out]heightSize

◆ waitEvents()

int Glfwx::Window::waitEvents ( )

Waits for any window activity and processes it.

Returns
The close value
See also
glfwWaitEvents
glfwWindowShouldClose