Loading...
Searching...
No Matches
Windowabstract

#include <AppCore/Window.h>

Overview

A platform-specific window.

This class describes a platform-specific window and provides methods for managing it.

Creating a Window

To create a new Window, use the static Window::Create method:

auto window = Window::Create(monitor, 1024, 768, false, kWindowFlags_Titled);
static RefPtr< Window > Create(Monitor *monitor, uint32_t width, uint32_t height, bool fullscreen, unsigned int window_flags)
Create a new Window.
@ kWindowFlags_Titled
Definition Window.h:78

Setting a WindowListener

To receive callbacks for window-related events, set a WindowListener:

class MyWindowListener : public WindowListener {
virtual void OnClose(Window* window) override {
printf("Window closed!\n");
}
};
auto listener = new MyWindowListener();
window->set_listener(listener);
A platform-specific window.
Definition Window.h:123
virtual WindowListener * listener()=0
Get the WindowListener, if any.
Interface for all Window-related events.
Definition Window.h:27

Coordinate Systems

Monitors and may windows may have a device scale applied by the OS (for example, a Retina display on macOS may have a 2x or 3x DPI scale).

To convert between screen coordinates and pixel coordinates, use the following equation:

pixel_coordinate = round(screen_coordinate * scale)
virtual double scale() const =0
The DPI scale of the window.
Inheritance diagram for Window:
RefCounted

Static Public Member Functions

static RefPtr< WindowCreate (Monitor *monitor, uint32_t width, uint32_t height, bool fullscreen, unsigned int window_flags)
 Create a new Window.
 

Public Member Functions

virtual void set_listener (WindowListener *listener)=0
 Set a WindowListener to receive callbacks for window-related events.
 
virtual WindowListenerlistener ()=0
 Get the WindowListener, if any.
 
virtual uint32_t screen_width () const =0
 Get the window width (in screen coordinates).
 
virtual uint32_t width () const =0
 Get the window width (in pixels).
 
virtual uint32_t screen_height () const =0
 Get the window height (in screen coordinates).
 
virtual uint32_t height () const =0
 Get the window height (in pixels).
 
virtual void MoveTo (int x, int y)=0
 Move the window to a new position (in screen coordinates) relative to the top-left of the monitor area.
 
virtual void MoveToCenter ()=0
 Move the window to the center of the monitor.
 
virtual int x () const =0
 Get the x-position of the window (in screen coordinates) relative to the top-left of the monitor area.
 
virtual int y () const =0
 Get the y-position of the window (in screen coordinates) relative to the top-left of the monitor area.
 
virtual bool is_fullscreen () const =0
 Whether or not the window is fullscreen.
 
virtual bool is_accelerated () const =0
 Whether or not the window is GPU accelerated.
 
virtual uint32_t render_buffer_id () const =0
 The render buffer id of the the window's backing texture.
 
virtual double scale () const =0
 The DPI scale of the window.
 
virtual void SetTitle (const char *title)=0
 Set the window title.
 
virtual void SetCursor (ultralight::Cursor cursor)=0
 Set the cursor.
 
virtual void Show ()=0
 Show the window (if it was previously hidden).
 
virtual void Hide ()=0
 Hide the window.
 
virtual bool is_visible () const =0
 Whether or not the window is currently visible (not hidden).
 
virtual void Close ()=0
 Close the window.
 
virtual int ScreenToPixels (int val) const =0
 Convert screen coordinates to pixels using the current DPI scale.
 
virtual int PixelsToScreen (int val) const =0
 Convert pixels to screen coordinates using the current DPI scale.
 
virtual void DrawSurface (int x, int y, Surface *surface)
 Draw a surface directly to window, used only by CPU renderer.
 
virtual void * native_handle () const =0
 Get the underlying native window handle.
 
virtual void EnableFrameStatistics ()
 Display frame statistics (FPS, frame times, etc.) in the titlebar.
 
- Public Member Functions inherited from RefCounted
virtual void AddRef () const =0
 
virtual void Release () const =0
 
virtual int ref_count () const =0
 

Protected Member Functions

virtual ~Window ()
 
virtual bool platform_always_uses_cpu_renderer () const =0
 
virtual OverlayManager * overlay_manager () const =0
 
- Protected Member Functions inherited from RefCounted
virtual ~RefCounted ()
 

Friends

class OverlayImpl
 

Constructor & Destructor Documentation

◆ ~Window()

virtual ~Window ( )
protectedvirtual

Member Function Documentation

◆ Close()

virtual void Close ( )
pure virtual

Close the window.

◆ Create()

static RefPtr< Window > Create ( Monitor * monitor,
uint32_t width,
uint32_t height,
bool fullscreen,
unsigned int window_flags )
static

Create a new Window.

Parameters
monitorThe monitor to create the Window on.
widthThe width (in screen coordinates).
heightThe height (in screen coordinates).
fullscreenWhether or not the window is fullscreen.
window_flagsVarious window flags.
Note

Windows are immediately shown by default unless kWindowFlags_Hidden is set in the window_flags parameter. (They can be shown later via Window::Show())

Note

Screen coordinates are device-scale-independent and have the following relationship to pixel coordinates:

pixel_coordinate = round(screen_coordinate * scale)

◆ DrawSurface()

virtual void DrawSurface ( int x,
int y,
Surface * surface )
inlinevirtual

Draw a surface directly to window, used only by CPU renderer.

◆ EnableFrameStatistics()

virtual void EnableFrameStatistics ( )
inlinevirtual

Display frame statistics (FPS, frame times, etc.) in the titlebar.

◆ height()

virtual uint32_t height ( ) const
pure virtual

Get the window height (in pixels).

◆ Hide()

virtual void Hide ( )
pure virtual

Hide the window.

◆ is_accelerated()

virtual bool is_accelerated ( ) const
pure virtual

Whether or not the window is GPU accelerated.

◆ is_fullscreen()

virtual bool is_fullscreen ( ) const
pure virtual

Whether or not the window is fullscreen.

◆ is_visible()

virtual bool is_visible ( ) const
pure virtual

Whether or not the window is currently visible (not hidden).

◆ listener()

virtual WindowListener * listener ( )
pure virtual

Get the WindowListener, if any.

◆ MoveTo()

virtual void MoveTo ( int x,
int y )
pure virtual

Move the window to a new position (in screen coordinates) relative to the top-left of the monitor area.

◆ MoveToCenter()

virtual void MoveToCenter ( )
pure virtual

Move the window to the center of the monitor.

◆ native_handle()

virtual void * native_handle ( ) const
pure virtual

Get the underlying native window handle.

Note
This is:
  • HWND on Windows
  • NSWindow* on macOS
  • GLFWwindow* on Linux

◆ overlay_manager()

virtual OverlayManager * overlay_manager ( ) const
protectedpure virtual

◆ PixelsToScreen()

virtual int PixelsToScreen ( int val) const
pure virtual

Convert pixels to screen coordinates using the current DPI scale.

◆ platform_always_uses_cpu_renderer()

virtual bool platform_always_uses_cpu_renderer ( ) const
protectedpure virtual

◆ render_buffer_id()

virtual uint32_t render_buffer_id ( ) const
pure virtual

The render buffer id of the the window's backing texture.

(This will be 0 if the window is not accelerated).

◆ scale()

virtual double scale ( ) const
pure virtual

The DPI scale of the window.

◆ screen_height()

virtual uint32_t screen_height ( ) const
pure virtual

Get the window height (in screen coordinates).

◆ screen_width()

virtual uint32_t screen_width ( ) const
pure virtual

Get the window width (in screen coordinates).

◆ ScreenToPixels()

virtual int ScreenToPixels ( int val) const
pure virtual

Convert screen coordinates to pixels using the current DPI scale.

◆ set_listener()

virtual void set_listener ( WindowListener * listener)
pure virtual

Set a WindowListener to receive callbacks for window-related events.

Note
Ownership remains with the caller.

◆ SetCursor()

virtual void SetCursor ( ultralight::Cursor cursor)
pure virtual

Set the cursor.

◆ SetTitle()

virtual void SetTitle ( const char * title)
pure virtual

Set the window title.

◆ Show()

virtual void Show ( )
pure virtual

Show the window (if it was previously hidden).

◆ width()

virtual uint32_t width ( ) const
pure virtual

Get the window width (in pixels).

◆ x()

virtual int x ( ) const
pure virtual

Get the x-position of the window (in screen coordinates) relative to the top-left of the monitor area.

◆ y()

virtual int y ( ) const
pure virtual

Get the y-position of the window (in screen coordinates) relative to the top-left of the monitor area.

Friends And Related Symbol Documentation

◆ OverlayImpl

friend class OverlayImpl
friend

The documentation for this class was generated from the following file: