![]() |
ImFusion SDK 4.3
|
#include <ImFusion/GUI/Display.h>
Basic version of a display surface hosting a set of Views, rendering them, and distributing input events to them. More...
Inheritance diagram for Display:Basic version of a display surface hosting a set of Views, rendering them, and distributing input events to them.
A Display represents a rectangular viewport in OpenGL space into which it will render the views. The arrangement of the views inside the viewport is determined by the DisplayLayout member. The default implementation will simply arrange all views horizontally next to each other while subclasses can customize this behavior. Furthermore, you can always override the layouting from the outside.
Display provides the handleInputEvent() function to handle keyboard/mouse/touch events from the user. Those events are forwarded to the views according their current layouting position.
In order to bring the Display into your application you will usually need to wrap it inside an OpenGL-capable container widget corresponding to the used GUI toolkit/windowing platform. That wrapper must take care of setting the viewport correctly and calling render() from the correct OpenGL context. Furthermore, it needs to convert the platform-specific user input events to the corresponding ImFusion InputEvents and pass them to handleInputEvent(). The resulting generic GUI::EventResult can then be used to yield the intended platform-specific effects. QtDisplayWidget provides a ready-to-use implementation for a QtWidgets-based application.
Public Member Functions | |
| virtual void | addView (std::unique_ptr< View > view) |
| Adds the given view to this display surface. | |
| virtual std::unique_ptr< View > | removeView (View *view) |
| Remove view from this display surface again. | |
| std::vector< View * > | views () const override |
| Returns all views hosted by this display. | |
| DisplayLayout & | layout () override |
| Returns the DisplayLayout determining how views are distributed within the viewport. | |
| GL::Viewport | viewport () const override |
| Returns the viewport of this display surface in OpenGL coordinates (origin in lower-left corner). | |
| virtual void | setViewport (const GL::Viewport &viewport) |
| Sets the viewport size of this display surface in OpenGL coordinates (origin in lower-left corner) and re-layouts the layout() if applicable. | |
| const std::optional< vec3 > & | backgroundColor () const |
| Returns the optional background color of the rendering area. | |
| void | setBackgroundColor (const std::optional< vec3 > &value) |
| Sets the optional background color of the rendering area. | |
| void | setWatermark (const SharedImage &image) |
| Sets a watermark image to be rendered on top of the display. | |
| virtual void | render (std::string *outCriticalGlErrorMessage=nullptr) const |
| Perform OpenGL-based rendering of the Display and all its Views. | |
| EventResult | handleInputEvent (const InputEvent &event) |
| Entry point for the dispatching of input events from users. | |
| void | requestUpdate () override |
| Request an update of the rendered display content. | |
Public Member Functions inherited from SignalReceiver | |
| SignalReceiver ()=default | |
| Default constructor. | |
| SignalReceiver (const SignalReceiver &other) | |
| Copy constructor, does not copy any existing signal connections from other. | |
| SignalReceiver & | operator= (SignalReceiver rhs) |
| Assignment operator, disconnects all existing connections, does not copy any existing signal connections from rhs. | |
| virtual | ~SignalReceiver () |
| Virtual destructor disconnects from all connected signals. | |
Public Attributes | |
| Signal< View * > | signalViewAdded |
| Signal emitted when a View was added. | |
| Signal< View * > | signalViewRemoved |
| Signal emitted when a View was removed. | |
| Signal | signalUpdateRequested |
| Signal emitted when scene has changed and a re-render is requested. | |
Protected Member Functions | |
| virtual std::optional< DisplayLayoutConfig > | defaultLayoutConfig () const |
| virtual EventResult | handleKeyEvent (const KeyEvent &event) |
| virtual EventResult | handleMouseEvent (const MouseEvent &event) |
| virtual EventResult | handleTouchEvent (const TouchEvent &event) |
| virtual EventResult | handleContextMenuEvent (const ContextMenuEvent &event) |
Protected Member Functions inherited from SignalReceiver | |
| void | disconnectAll () |
| Disconnects all existing connections. | |
Protected Attributes | |
| std::vector< std::unique_ptr< View > > | m_views |
| DisplayLayout | m_layout |
| std::shared_ptr< DataDisplayDispatcher > | m_dataDisplayDispatcher |
| GL::Viewport | m_viewport |
| std::optional< vec3 > | m_backgroundColor = vec3::Zero() |
| std::unique_ptr< GL::VertexBuffer > | m_vbo |
| std::shared_ptr< const GlImage > | m_watermark |
| View * | m_mouseEventReceiver = nullptr |
| View where the mouse was pressed and that therefore has the mouse focus. | |
| View * | m_touchEventReceiver = nullptr |
| View where a touch event was pressed and that therefore has the touch focus. | |
| View * | m_lastEnteredView = nullptr |
| View that where the last mouse enter event was posted to. | |
|
virtual |
Adds the given view to this display surface.
The default implementation will reset the DisplayLayout with the return value of defaultLayoutConfig() if valid.
Reimplemented in RadiologyDisplay.
|
virtual |
Remove view from this display surface again.
The default implementation will reset the DisplayLayout with the return value of defaultLayoutConfig() if valid.
Reimplemented in RadiologyDisplay.
|
overridevirtual |
Returns all views hosted by this display.
Implements DisplayBase.
|
inlineoverridevirtual |
Returns the DisplayLayout determining how views are distributed within the viewport.
Implements DisplayBase.
|
inlineoverridevirtual |
Returns the viewport of this display surface in OpenGL coordinates (origin in lower-left corner).
Implements DisplayBase.
|
virtual |
Perform OpenGL-based rendering of the Display and all its Views.
Call this function from the correct OpenGL context and your framebuffer [object] setup correctly. If a background color is set it will clear the framebuffer with it. Then it will call View::render() for each view.
At the end of the rendering the function will check the OpenGL error flag. After the third frame where a critical error occurred (e.g. out-of-memory) the Display will disable all rendering to avoid further corruption of the system. This shall give the application the opportunity to at least perform a graceful shutdown. Callers can be notified about this by passing a pointer-to-string to the optional outCriticalGlErrorMessage parameter.
| EventResult handleInputEvent | ( | const InputEvent & | event | ) |
Entry point for the dispatching of input events from users.
Usually, this function is called by the platform-specific wrapper class of the Display (e.g. QtDisplayWidget) after converting the platform-specific event to the generic InputEvent type. It will forward the event to the DisplayLayout and all Views and return an EventResult instance, which the wrapper class shall handle accordingly.
The default implementation will switch on the type of event and forward to either handleKeyEvent(), handleMouseEvent(), handleTouchEvent(), or handleContextMenuEvent(). Thus, if you need to implement custom logic you should override those member functions.
|
overridevirtual |
Request an update of the rendered display content.
Subclasses are not required to perform the update immediately but may postpone it to a later point in time (e.g. by using the application's event loop) in order to collect and combine multiple update requests into one.
Implements DisplayBase.