Class Screen

Inheritance Relationships

Base Type

Class Documentation

class nanogui::Screen

Represents a display surface (i.e. a full-screen or windowed GLFW window) and forms the root element of a hierarchy of nanogui widgets.

Inherits from nanogui::Widget

Public Functions

Screen(const Vector2i &size, const std::string &caption, bool resizable = true, bool fullscreen = false, int colorBits = 8, int alphaBits = 8, int depthBits = 24, int stencilBits = 8, int nSamples = 0, unsigned int glMajor = 3, unsigned int glMinor = 3)

Create a new Screen instance

Parameters
  • size: Size in pixels at 96 dpi (on high-DPI screens, the actual resolution in terms of hardware pixels may be larger by an integer factor)
  • caption: Window title (in UTF-8 encoding)
  • resizable: If creating a window, should it be resizable?
  • fullscreen: Specifies whether to create a windowed or full-screen view
  • colorBits: Number of bits per pixel dedicated to the R/G/B color components
  • alphaBits: Number of bits per pixel dedicated to the alpha channel
  • depthBits: Number of bits per pixel dedicated to the Z-buffer
  • stencilBits: Number of bits per pixel dedicated to the stencil buffer (recommended to set this to 8. NanoVG can draw higher-quality strokes using a stencil buffer)
  • nSamples: Number of MSAA samples (set to 0 to disable)
  • glMajor: The requested OpenGL Major version number. Default is 3, if changed the value must correspond to a forward compatible core profile (for portability reasons). For example, set this to 4 and glMinor to 1 for a forward compatible core OpenGL 4.1 profile. Requesting an invalid profile will result in no context (and therefore no GUI) being created.
  • glMinor: The requested OpenGL Minor version number. Default is 3, if changed the value must correspond to a forward compatible core profile (for portability reasons). For example, set this to 1 and glMajor to 4 for a forward compatible core OpenGL 4.1 profile. Requesting an invalid profile will result in no context (and therefore no GUI) being created.

virtual ~Screen()

Release all resources.

const std::string &caption() const

Get the window title bar caption.

void setCaption(const std::string &caption)

Set the window title bar caption.

const Color &background() const

Return the screen’s background color.

void setBackground(const Color &background)

Set the screen’s background color.

void setVisible(bool visible)

Set the top-level window visibility (no effect on full-screen windows)

void setSize(const Vector2i &size)

Set window size.

virtual void drawAll()

Draw the Screen contents.

virtual void drawContents()

Draw the window contents put your OpenGL draw calls here.

float pixelRatio() const

Return the ratio between pixel and device coordinates (e.g. >= 2 on Mac Retina displays)

virtual bool dropEvent(const std::vector<std::string>&)

Handle a file drop event.

virtual bool keyboardEvent(int key, int scancode, int action, int modifiers)

Default keyboard event handler.

virtual bool keyboardCharacterEvent(unsigned int codepoint)

Text input event handler: codepoint is native endian UTF-32 format.

virtual bool resizeEvent(const Vector2i &size)

Window resize event handler.

std::function<void(Vector2i)> resizeCallback() const

Set the resize callback.

void setResizeCallback(const std::function<void(Vector2i)> &callback)
Vector2i mousePos() const

Return the last observed mouse position value.

GLFWwindow *glfwWindow()

Return a pointer to the underlying GLFW window data structure.

NVGcontext *nvgContext()

Return a pointer to the underlying nanoVG draw context.

void setShutdownGLFWOnDestruct(bool v)
bool shutdownGLFWOnDestruct()
void performLayout()

Compute the layout of all widgets.

Screen()

Default constructor.

Performs no initialization at all. Use this if the application is responsible for setting up GLFW, OpenGL, etc.

In this case, override Screen and call initalize() with a pointer to an existing GLFWwindow instance

You will also be responsible in this case to deliver GLFW callbacks to the appropriate callback event handlers below

void initialize(GLFWwindow *window, bool shutdownGLFWOnDestruct)

Initialize the Screen.

bool cursorPosCallbackEvent(double x, double y)
bool mouseButtonCallbackEvent(int button, int action, int modifiers)
bool keyCallbackEvent(int key, int scancode, int action, int mods)
bool charCallbackEvent(unsigned int codepoint)
bool dropCallbackEvent(int count, const char **filenames)
bool scrollCallbackEvent(double x, double y)
bool resizeCallbackEvent(int width, int height)
void updateFocus(Widget *widget)
void disposeWindow(Window *window)
void centerWindow(Window *window)
void moveWindowToFront(Window *window)
void drawWidgets()

Protected Attributes

GLFWwindow *mGLFWWindow
NVGcontext *mNVGContext
GLFWcursor *mCursors[(int) Cursor::CursorCount]
Cursor mCursor
std::vector<Widget *> mFocusPath
Vector2i mFBSize
float mPixelRatio
int mMouseState
int mModifiers
Vector2i mMousePos
bool mDragActive
Widget *mDragWidget = nullptr
double mLastInteraction
bool mProcessEvents
Color mBackground
std::string mCaption
bool mShutdownGLFWOnDestruct
bool mFullscreen
std::function<void(Vector2i)> mResizeCallback