The OpenD Programming Language

NVGWindow

A SimpleWindow subclass that encapsulates some nanovega defaults. You just set a redrawNVGScene delegate and, optionally, your normal event handlers for simpledisplay, and the rest is set up for you.

version(!nanovg_bindbc_opengl_bindings && nanovg_builtin_opengl_bindings)
class NVGWindow : SimpleWindow {
NVGContext nvg;
}

Constructors

this
this(int width, int height, string title)

Members

Functions

redrawNVGSceneNow
void redrawNVGSceneNow()

Variables

clearOnEachFrame
bool clearOnEachFrame;
redrawNVGScene
void delegate(NVGContext nvg) redrawNVGScene;

Inherited Members

From SimpleWindow

takeScreenshot
TrueColorImage takeScreenshot()

Copies the window's current state into a TrueColorImage.

actualDpi
int actualDpi()

Returns the actual logical DPI for the window on its current display monitor. If the window straddles monitors, it will return the value of one or the other in a platform-defined manner.

onDpiChanged
void delegate() onDpiChanged;

Sent when the window is moved to a new DPI context, for example, when it is dragged between monitors or if the window is moved to a new remote connection or a monitor is hot-swapped.

setRequestedInputFocus
SimpleWindow delegate() setRequestedInputFocus;

Used iff WindowFlags.managesChildWindowFocus is set when the window is created. The delegate will be called when the window manager asks you to take focus.

grabInput
void grabInput(bool keyboard, bool mouse, bool confine)

Grabs exclusive input from the user until you release it with releaseInputGrab.

setIMEPopupLocation
void setIMEPopupLocation(Point location)
void setIMEPopupLocation(int x, int y)

Sets the location for the IME (input method editor) to pop up when the user activates it.

setIMEFocused
void setIMEFocused(bool value)

Tells the IME whether or not an input field is currently focused in the window.

nativeWindowHandle
NativeWindowHandle nativeWindowHandle()

Returns the native window.

releaseInputGrab
void releaseInputGrab()

Releases the grab acquired by grabInput.

focus
void focus()

Sets the input focus to this window.

requestAttention
void requestAttention()

Requests attention from the user for this window.

closeQuery
void delegate() closeQuery;

This will be called when WM wants to close your window (i.e. user clicked "close" icon, for example). You'll have to call close() manually if you set this delegate.

visibilityChanged
void delegate(bool becomesVisible) visibilityChanged;

This will be called when window visibility was changed.

closed
bool closed [@property getter]

Returns true if the window has been closed.

focused
bool focused [@property getter]

Returns true if the window is focused.

visible
bool visible [@property getter]

Returns true if the window is visible (mapped).

close
void close()

Closes the window. If there are no more open windows, the event loop will terminate.

close
void close()

close is one of the few methods that can be called from other threads. This shared overload reflects that.

maximize
void maximize()
fullscreen
void fullscreen(bool yes)

not fully implemented but planned for a future release

minimize
void minimize()

Note: only implemented on Windows. No-op on other platforms. You may want to use hide instead.

show
void show()

Alias for hidden = false

hide
void hide()

Alias for hidden = true

hideCursor
void hideCursor()

Hide cursor when it enters the window.

showCursor
void showCursor()

Don't hide cursor when it enters the window.

warpMouse
bool warpMouse(int x, int y)

"Warp" mouse pointer to coordinates relative to window top-left corner. Return "success" flag.

sendDummyEvent
void sendDummyEvent()

Send dummy window event to ping event loop. Required to process NotificationIcon on X11, for example.

setMinSize
void setMinSize(int minwidth, int minheight)

Set window minimal size.

setMaxSize
void setMaxSize(int maxwidth, int maxheight)

Set window maximal size.

setResizeGranularity
void setResizeGranularity(int granx, int grany)

Set window resize step (window size will be changed with the given granularity on supported platforms). Currently only supported on X11.

move
void move(int x, int y)
void move(Point p)

Move window.

resize
void resize(int w, int h)

Resize window.

moveResize
void moveResize(int x, int y, int w, int h)

Move and resize window (this can be faster and more visually pleasant than doing it separately).

hidden
bool hidden [@property getter]

Returns true if the window is hidden.

hidden
bool hidden [@property setter]

Shows or hides the window based on the bool argument.

opacity
void opacity(double opacity)

Sets the window opacity. On X11 this requires a compositor to be running. On windows the WindowFlags.extraComposite must be set at window creation.

setEventHandlers
void setEventHandlers(T eventHandlers)

Sets your event handlers, without entering the event loop. Useful if you have multiple windows - set the handlers on each window, then only do eventLoop on your main window or call EventLoop.get.run();.

eventLoop
int eventLoop(long pulseTimeout, T eventHandlers)
int eventLoop(T eventHandlers)

The event loop automatically returns when the window is closed pulseTimeout is given in milliseconds. If pulseTimeout == 0, no pulse timer is created. The event loop will block until an event arrives or the pulse timer goes off.

eventLoopWithBlockingMode
int eventLoopWithBlockingMode(BlockingMode blockingMode, long pulseTimeout, T eventHandlers)

This is the function eventLoop forwards to. It, in turn, forwards to EventLoop.get.run.

draw
ScreenPainter draw()
ScreenPainter draw(bool manualInvalidations)

This lets you draw on the window (or its backing buffer) using basic 2D primitives.

width
int width [@property getter]

Width of the window's drawable client area, in pixels.

height
int height [@property getter]

Height of the window's drawable client area, in pixels.

actualWindowSize
Size actualWindowSize [@property getter]

Returns the actual size of the window, bypassing the logical illusions of Resizability.automaticallyScaleIfPossible.

isOpenGL
bool isOpenGL [@property getter]

true if OpenGL was initialized for this window.

mtLock
void mtLock()

"Lock" this window handle, to do multithreaded synchronization. You probably won't need to call this, as it's not recommended to share window between threads.

mtUnlock
void mtUnlock()

"Unlock" this window handle, to do multithreaded synchronization. You probably won't need to call this, as it's not recommended to share window between threads.

beep
void beep()

Emit a beep to get user's attention.

redrawOpenGlScene
void delegate() redrawOpenGlScene;

Put your code in here that you want to be drawn automatically when your window is uncovered. Set a handler here *before* entering your event loop any time you pass OpenGlOptions.yes to the constructor. Ideally, you will set this delegate immediately after constructing the SimpleWindow.

vsync
bool vsync [@property setter]

This will allow you to change OpenGL vsync state.

useGLFinish
bool useGLFinish;

Set this to false if you don't need to do glFinish() after swapOpenGlBuffers(). Note that at least NVidia proprietary driver may segfault if you will modify texture fast enough without waiting 'em to finish their frame business.

redrawOpenGlSceneNow
void redrawOpenGlSceneNow()

call this to invoke your delegate. It automatically sets up the context and flips the buffer. If you need to redraw the scene in response to an event, call this.

redrawOpenGlSceneSoon
void redrawOpenGlSceneSoon()

Queues an opengl redraw as soon as the other pending events are cleared.

setAsCurrentOpenGlContext
void setAsCurrentOpenGlContext()

Makes all gl* functions target this window until changed. This is only valid if you passed OpenGlOptions.yes to the constructor.

setAsCurrentOpenGlContextNT
bool setAsCurrentOpenGlContextNT()

Makes all gl* functions target this window until changed. This is only valid if you passed OpenGlOptions.yes to the constructor. This doesn't throw, returning success flag instead.

releaseCurrentOpenGlContext
bool releaseCurrentOpenGlContext()

Releases OpenGL context, so it can be reused in, for example, different thread. This is only valid if you passed OpenGlOptions.yes to the constructor. This doesn't throw, returning success flag instead.

swapOpenGlBuffers
void swapOpenGlBuffers()

simpledisplay always uses double buffering, usually automatically. This manually swaps the OpenGL buffers.

title
string title [@property setter]

Set the window title, which is visible on the window manager title bar, operating system taskbar, etc.

title
string title [@property getter]

Gets the title

getRealTitle
string getRealTitle()

Get the title as set by the window manager. May not match what you attempted to set.

icon
MemoryImage icon [@property setter]

Set the icon that is seen in the title bar or taskbar, etc., for the user. If passed null, does nothing.

image
Image image [@property setter]

Draws an image on the window. This is meant to provide quick look of a static image generated elsewhere.

cursor
MouseCursor cursor [@property setter]

Changes the cursor for the window. If the cursor is hidden via hideCursor, this has no effect.

handleKeyEvent
void delegate(KeyEvent ke) handleKeyEvent;

What follows are the event handlers. These are set automatically by the eventLoop function, but are still public so you can change them later. wasPressed == true means key down. false == key up. Handles a low-level keyboard event. Settable through setEventHandlers.

handleCharEvent
void delegate(dchar c) handleCharEvent;

Handles a higher level keyboard event - c is the character just pressed. Settable through setEventHandlers.

handlePulse
void delegate() handlePulse;

Handles a timer pulse. Settable through setEventHandlers.

onFocusChange
void delegate(bool) onFocusChange;

Called when the focus changes, param is if we have it (true) or are losing it (false).

onClosing
void delegate() onClosing;

Called inside close() method. Our window is still alive, and we can free various resources. * Sometimes it is easier to setup the delegate instead of subclassing.

onDestroyed
void delegate() onDestroyed;

Called when we received destroy notification. At this stage we cannot do much with our window * (as it is already dead, and it's native handle cannot be used), but we still can do some * last minute cleanup.

handleExpose
bool delegate(int x, int y, int width, int height, int eventsLeft) handleExpose;

Called when Expose event comes. See Xlib manual to understand the arguments. * Return false if you want Simpledisplay to copy backbuffer, or true if you did it yourself. * You will probably never need to setup this handler, it is for very low-level stuff. * * WARNING! Xlib is multithread-locked when this handles is called!

handleMouseEvent
void delegate(MouseEvent) handleMouseEvent;

Mouse event handler. Settable through setEventHandlers.

paintingFinished
void delegate() paintingFinished;

use to redraw child widgets if you use system apis to add stuff

windowResized
void delegate(int width, int height) windowResized;

handle a resize, after it happens. You must construct the window with Resizability.allowResizing for this to ever happen.

handleNativeEvent_
NativeEventHandler handleNativeEvent_;

Platform specific - handle any native message this window gets.

handleNativeGlobalEvent
NativeEventHandler handleNativeGlobalEvent;

This is the same as handleNativeEvent, but static so it can hook ALL events in the loop. If you used to use handleNativeEvent depending on it being static, just change it to use this instead and it will work the same way.

impl
mixin NativeSimpleWindowImplementation!() impl

The native implementation is available, but you shouldn't use it unless you are familiar with the underlying operating system, don't mind depending on it, and know simpledisplay.d's internals too. It is virtually private; you can hopefully do what you need to do with handleNativeEvent instead.

eventQueueEmpty
bool eventQueueEmpty [@property getter]

Is our custom event queue empty? Can be used in simple cases to prevent "spamming" window with events it can't cope with. It is safe to call this from non-UI threads.

eventQueued
bool eventQueued [@property getter]

Does our custom event queue contains at least one with the given type? Can be used in simple cases to prevent "spamming" window with events it can't cope with. It is safe to call this from non-UI threads.

eventUncaughtException
void delegate(Exception e) nothrow eventUncaughtException;

Event listeners added with addEventListener have their exceptions swallowed by the event loop. This delegate can handle them again before it proceeds.

addEventListener
uint addEventListener(void delegate(ET) dg)

Add listener for custom event. Can be used like this:

removeEventListener
void removeEventListener(uint id)

Remove event listener. It is safe to pass invalid event id here.

Don't use this method in object destructors!
postTimeout
bool postTimeout(ET evt, uint timeoutmsecs, bool replace)

Post event to queue. It is safe to call this from non-UI threads. If timeoutmsecs is greater than zero, the event will be delayed for at least timeoutmsecs milliseconds. if replace is true, replace all existing events typed ET with the new one (if evt is empty, remove 'em all) Returns true if event was queued. Always returns false if evt is null.

postEvent
bool postEvent(ET evt, bool replace)

Post event to queue. It is safe to call this from non-UI threads. if replace is true, replace all existing events typed ET with the new one (if evt is empty, remove 'em all) Returns true if event was queued. Always returns false if evt is null.

suppressAutoOpenglViewport
bool suppressAutoOpenglViewport;

When in opengl mode and automatically resizing, it will set the opengl viewport to stretch.

cornerStyle
CornerStyle cornerStyle()
void cornerStyle(CornerStyle corner)

Style of the window's corners

Meta

History

Added January 22, 2021 (version 9.2 release)