Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | Public Attributes | Static Protected Member Functions | Protected Attributes | List of all members
G3D::CallbackWidget Class Reference

A widget that takes std::functions for its event handlers, avoiding the need to subclass Widget for basic "heartbeat" functions. More...

Inherits G3D::Widget.

Public Member Functions

virtual Rect2D bounds () const override
 Inherited from Surface2D. More...
 
virtual float depth () const override
 Inherited from Surface2D. More...
 
virtual void fireEvent (const GEvent &event)
 Fire an event on the containing window. More...
 
WidgetManagermanager () const
 
virtual void onAfterEvents ()
 Invoked after all onEvent handlers for the current frame and before onUserInput for any other Widget. More...
 
virtual void onAI ()
 
virtual void onBeforeGraphics () override
 Invoked by WidgetManager immediately before GApp::onGraphics runs. More...
 
virtual bool onEvent (const GEvent &event)
 Returning true consumes the event and prevents other GModules from seeing it. More...
 
virtual void onNetwork ()
 
virtual void onPose (Array< shared_ptr< Surface > > &surfaceArray, Array< shared_ptr< Surface2D > > &surface2DArray) override
 
Appends a posed model for this object to the array, if it has a graphic representation. More...
 
virtual void onSimulation (RealTime rdt, SimTime sdt, SimTime idt) override
 
virtual void onUserInput (UserInput *ui)
 
virtual float positionalEventZ (const Point2 &pixel) const
 The camera-space z position that this Widget considers this pixel to be at. More...
 
virtual void render (RenderDevice *rd) const override
 Inherited from Surface2D. More...
 
virtual void setDepth (float d)
 Called by the WidgetManager. More...
 
virtual void setManager (WidgetManager *m)
 Called by the WidgetManager when this module is added to it. More...
 
virtual OSWindowwindow () const
 Returns the operating system window that is currently rendering this Widget. More...
 

Static Public Member Functions

static shared_ptr< CallbackWidgetcreate ()
 
static void sort (Array< shared_ptr< Surface2D >> &array)
 Sorts from farthest to nearest. More...
 
static void sortAndRender (RenderDevice *rd, Array< shared_ptr< Surface2D >> &array)
 Calls sort, RenderDevice::push2D, and then render on all elements. More...
 

Public Attributes

std::function< void()> beforeGraphicsCallback
 
std::function< void(Array< shared_ptr< Surface > > &surfaceArray, Array< shared_ptr< Surface2D > > &surface2DArray)> poseCallback
 
std::function< void(RealTime rdt, SimTime sdt, SimTime idt)> simulationCallback
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

float m_depth
 
WidgetManagerm_manager
 The manager, set by setManager(). More...
 

Detailed Description

A widget that takes std::functions for its event handlers, avoiding the need to subclass Widget for basic "heartbeat" functions.

Member Function Documentation

◆ bounds()

virtual Rect2D G3D::Widget::bounds ( ) const
inlineoverridevirtualinherited

Inherited from Surface2D.

Implements G3D::Surface2D.

Reimplemented in G3D::GuiWindow, G3D::GConsole, and G3D::FullScreenWidget.

◆ create()

static shared_ptr<CallbackWidget> G3D::CallbackWidget::create ( )
inlinestatic

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ depth()

virtual float G3D::Widget::depth ( ) const
inlineoverridevirtualinherited

Inherited from Surface2D.

Controls the depth of objects when rendering. Subclasses may override this but it can interfere with the normal handling of rendering and event delivery. depth = 0 is usually the "top" widget and depth = 1 is usually the "bottom" widget.

Implements G3D::Surface2D.

Reimplemented in G3D::GuiWindow, G3D::GConsole, and G3D::FullScreenWidget.

◆ fireEvent()

virtual void G3D::Widget::fireEvent ( const GEvent event)
virtualinherited

Fire an event on the containing window.

Reimplemented in G3D::WidgetManager.

◆ manager()

WidgetManager* G3D::Widget::manager ( ) const
inlineinherited

◆ onAfterEvents()

virtual void G3D::Widget::onAfterEvents ( )
inlinevirtualinherited

Invoked after all onEvent handlers for the current frame and before onUserInput for any other Widget.

Reimplemented in G3D::WidgetManager, and G3D::GameController.

◆ onAI()

virtual void G3D::Widget::onAI ( )
inlinevirtualinherited

◆ onBeforeGraphics()

virtual void G3D::CallbackWidget::onBeforeGraphics ( )
inlineoverridevirtual

Invoked by WidgetManager immediately before GApp::onGraphics runs.

Reimplemented from G3D::Widget.

◆ onEvent()

virtual bool G3D::Widget::onEvent ( const GEvent event)
inlinevirtualinherited

Returning true consumes the event and prevents other GModules from seeing it.

Motion events (GEventType::MOUSEMOTION, GEventType::JOYHATMOTION, JGEventType::OYBALLMOTION, and GEventType::JOYAXISMOTION) cannot be cancelled.

Reimplemented in G3D::GuiWindow, G3D::WidgetManager, G3D::ThirdPersonManipulator, G3D::GConsole, G3D::Discovery::Client, G3D::SceneEditorWindow, G3D::FirstPersonManipulator, G3D::VideoRecordDialog, G3D::UprightSplineManipulator, G3D::CameraControlWindow, G3D::GuiMenu, G3D::ControlPointEditor, G3D::DeveloperWindow, and G3D::ArticulatedModelSpecificationEditorDialog.

◆ onNetwork()

virtual void G3D::Widget::onNetwork ( )
inlinevirtualinherited

◆ onPose()

virtual void G3D::CallbackWidget::onPose ( Array< shared_ptr< Surface > > &  surfaceArray,
Array< shared_ptr< Surface2D > > &  surface2DArray 
)
inlineoverridevirtual


Appends a posed model for this object to the array, if it has a graphic representation.

The posed model appended is allowed to reference the agent and is allowed to mutate if the agent is mutated.

Reimplemented from G3D::Widget.

◆ onSimulation()

virtual void G3D::CallbackWidget::onSimulation ( RealTime  rdt,
SimTime  sdt,
SimTime  idt 
)
inlineoverridevirtual

Reimplemented from G3D::Widget.

◆ onUserInput()

virtual void G3D::Widget::onUserInput ( UserInput ui)
inlinevirtualinherited

◆ positionalEventZ()

virtual float G3D::Widget::positionalEventZ ( const Point2 pixel) const
inlinevirtualinherited

The camera-space z position that this Widget considers this pixel to be at.

Used for positional event (e.g., mouse click) delivery. Higher means closer.

Large negative values are far away. 0 is the closest 3D object. Values greater than zero are used for 2D objects. Returning fnan() [the default] requests the WidgetManager to set hte positionalEventZ to the object's normal event zorder.

See the implementation of ControlPointEditor::positionalEventZ for an example of how to use this with a 3D object.

Reimplemented in G3D::ControlPointEditor.

◆ render()

virtual void G3D::Widget::render ( RenderDevice rd) const
inlineoverridevirtualinherited

Inherited from Surface2D.

Implements G3D::Surface2D.

Reimplemented in G3D::GConsole, G3D::GuiWindow, G3D::GuiMenu, and G3D::DebugTextWidget.

◆ setDepth()

virtual void G3D::Widget::setDepth ( float  d)
inlinevirtualinherited

Called by the WidgetManager.

This is the depth that the Widget is expected to use when posed as a Surface2D. Subclasses may override or ignore this but it can interfere with the normal handling of rendering.

◆ setManager()

virtual void G3D::Widget::setManager ( WidgetManager m)
inlinevirtualinherited

◆ sort()

static void G3D::Surface2D::sort ( Array< shared_ptr< Surface2D >> &  array)
staticinherited

Sorts from farthest to nearest.

◆ sortAndRender()

static void G3D::Surface2D::sortAndRender ( RenderDevice rd,
Array< shared_ptr< Surface2D >> &  array 
)
staticinherited

Calls sort, RenderDevice::push2D, and then render on all elements.

◆ window()

virtual OSWindow* G3D::Widget::window ( ) const
virtualinherited

Returns the operating system window that is currently rendering this Widget.

Reimplemented in G3D::WidgetManager.

Referenced by G3D::FullScreenWidget::bounds().

Member Data Documentation

◆ beforeGraphicsCallback

std::function<void()> G3D::CallbackWidget::beforeGraphicsCallback

Referenced by onBeforeGraphics().

◆ m_depth

float G3D::Widget::m_depth
protectedinherited

◆ m_manager

WidgetManager* G3D::Widget::m_manager
protectedinherited

The manager, set by setManager().

This cannot be a reference counted pointer because that would create a cycle between the Widget and its manager.

Referenced by G3D::Widget::manager(), G3D::GuiWindow::manager(), G3D::Widget::setManager(), and G3D::GuiWindow::setVisible().

◆ poseCallback

std::function<void(Array< shared_ptr<Surface> >& surfaceArray, Array< shared_ptr<Surface2D> >& surface2DArray)> G3D::CallbackWidget::poseCallback

Referenced by onPose().

◆ simulationCallback

std::function<void(RealTime rdt, SimTime sdt, SimTime idt)> G3D::CallbackWidget::simulationCallback

Referenced by onSimulation().


documentation generated on Wed Nov 24 2021 08:01:53 using doxygen 1.8.15