NDEVR
API Documentation
WindowInstance.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Graphics
28File: WindowInstance
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#if NDEVR_VIEWPORT
35#include <NDEVR/KeyController.h>
36#include <NDEVR/Pointer.h>
37#include <NDEVR/Camera.h>
38#include <functional>
39namespace NDEVR
40{
42 class MouseEvent;
43 class KeyEvent;
44 class Camera;
45 class MouseController;
47
55 class NDEVR_DESIGN_API WindowInstance
56 {
57 public:
74 void setLookup(DesignObjectLookup* lookup) { m_lookup = lookup; }
77 virtual Vector<2, uint04> pixelSize() const { return (m_device_pixel_ratio * m_size.as<2, fltp08>()).as<2, uint04>(); };
80 virtual Vector<2, uint04> logicalSize() const { return m_size; };
89 virtual void setSize(const Vector<2, uint04>& size);
92 virtual void setReferenceSize(fltp08 size);
95 void addMouseEvent(const std::function<void(MouseEvent)>& mouse_event) { m_mouse_events.add(mouse_event); }
98 void addKeyboardEvent(const std::function<void(KeyEvent)>& key_event) { m_key_events.add(key_event); };
101 virtual bool visible() const { return true; }
104 virtual bool shouldExit() const { return false; }
107 virtual void* getSurface() = 0;
109 virtual void updateInstance() {};
116 virtual uint04 getGrabImageSize() { return 0; }
119 virtual void finishFrame(GraphicsUpdateArguments& args) {};
125 virtual ConstPointer<Camera> camera() const { return m_camera; }
128 virtual const DynamicPointer<Camera>& camera() { return m_camera; }
131 const void* lockptr() const { return this; }
134 void createEvent(const MouseEvent& event);
137 void createEvent(const KeyEvent& event);
140 void setDevicePixelRatio(const fltp08 ratio) { m_device_pixel_ratio = ratio; };
144 protected:
147 void setExposed(bool exposed);
148 private:
150 void init();
151 protected:
152 Buffer<std::function<void(MouseEvent)>> m_mouse_events;
153 Buffer<std::function<void(KeyEvent)>> m_key_events;
155
161 bool m_is_exposed = false;
162 };
163}
164#endif
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core object representing a user view as well as convenience functions for moving this view through ...
Definition Camera.h:95
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
A core class where all Design Objects including models, materials, and geometries are stored.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Options that are used for performing an update on a Graphics Engine call.
A top-level controller that dispatches key events to registered sub-controllers.
Describes a user key press event used to trigger behavior in the NDEVR API.
Definition Event.h:49
Contains logic for executing actions based on user mouse inputs.
Describes a mouse or touch input event with position, button, and modifier information.
Definition Event.h:316
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
constexpr decltype(auto) as() const
Returns the vector as a new time of vector.
Definition Vector.hpp:301
Buffer< std::function< void(KeyEvent)> > m_key_events
Registered keyboard event callbacks.
virtual void setSize(const Vector< 2, uint04 > &size)
Sets the logical size of the window.
void setLookup(DesignObjectLookup *lookup)
Sets the design object lookup used for scene queries.
Time m_surface_update_time
Timestamp of the last surface update.
fltp08 devicePixelRatio() const
Returns the current device pixel ratio.
void addKeyboardEvent(const std::function< void(KeyEvent)> &key_event)
Registers a callback to be invoked when a keyboard event occurs.
bool m_is_exposed
Whether the window surface is currently exposed.
void createEvent(const KeyEvent &event)
Dispatches a keyboard event to all registered keyboard event callbacks.
WindowInstance(const DynamicPointer< Camera > &camera, DesignObjectLookup *lookup)
Constructs a WindowInstance with a given camera and design object lookup.
virtual void finishFrame(GraphicsUpdateArguments &args)
Called at the end of a frame to perform any finalization work.
virtual void setReferenceSize(fltp08 size)
Sets the reference size used for scaling calculations.
virtual void updateInstance()
Called to update the window instance state.
void setDevicePixelRatio(const fltp08 ratio)
Sets the device pixel ratio (physical pixels per logical pixel).
virtual ConstPointer< Camera > camera() const
Returns a const pointer to the current camera.
void addMouseEvent(const std::function< void(MouseEvent)> &mouse_event)
Registers a callback to be invoked when a mouse event occurs.
virtual Vector< 2, uint04 > pixelSize() const
Returns the size of the window in physical pixels, accounting for the device pixel ratio.
virtual void * getSurface()=0
Returns a platform-specific pointer to the rendering surface.
Time getSurfaceUpdateTime() const
Returns the timestamp of the last surface update.
WindowInstance()
Default constructor.
fltp08 m_reference_size
Reference size used for scaling calculations.
virtual Vector< 2, uint04 > logicalSize() const
Returns the logical (device-independent) size of the window.
virtual fltp08 referencePixelSize()
Returns the reference size in physical pixels, accounting for the device pixel ratio.
virtual void setCamera(const DynamicPointer< Camera > &camera)
Sets the camera associated with this window.
virtual fltp08 referenceSize()
Returns the reference size used for scaling calculations.
Vector< 2, uint04 > m_size
Logical size of the window.
MouseController & getMouseController()
Returns the mouse controller associated with this window.
virtual bool shouldExit() const
Returns whether this window should exit or close.
virtual uint04 getGrabImageSize()
Returns the size for image grabbing operations.
~WindowInstance()
Destructor.
virtual const DynamicPointer< Camera > & camera()
Returns a reference to the dynamic camera pointer.
DesignObjectLookup * m_lookup
Pointer to the design object lookup for scene queries.
KeyController & getKeyController()
Returns the keyboard controller associated with this window.
DynamicPointer< Camera > m_camera
The camera used for rendering in this window.
void setExposed(bool exposed)
Sets whether the window surface is currently exposed (visible and ready for rendering).
void createEvent(const MouseEvent &event)
Dispatches a mouse event to all registered mouse event callbacks.
Buffer< std::function< void(MouseEvent)> > m_mouse_events
Registered mouse event callbacks.
virtual bool visible() const
Returns whether this window is currently visible.
const void * lockptr() const
Returns a pointer that can be used as a lock identifier for this instance.
fltp08 m_device_pixel_ratio
Ratio of physical pixels to logical pixels.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.