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


Manages a group of G3D::Widget. More...

Inherits G3D::Widget.

Classes

class  DelayedEvent
 Manages events that have been delayed by a lock. More...
 

Public Member Functions

void add (const shared_ptr< Widget > &m)
 If a lock is in effect, the add may be delayed until the unlock. More...
 
void beginLock ()
 
Between beginLock and endLock, add and remove operations are delayed so that iteration is safe. More...
 
virtual Rect2D bounds () const override
 Inherited from Surface2D. More...
 
void clear ()
 
Removes all widgets on this manager. More...
 
bool contains (const shared_ptr< Widget > &m) const
 If this widget has been added to the WidgetManager, or has a pending add (but not a subsequent pending remove) while in a lock. More...
 
void defocusWidget (const shared_ptr< Widget > &m)
 Removes focus from this module if it had focus, otherwise does nothing. More...
 
virtual float depth () const override
 Inherited from Surface2D. More...
 
void endLock ()
 
void fireEvent (const GEvent &event)
 Queues an event on the window associated with this manager. More...
 
shared_ptr< WidgetfocusedWidget () const
 At most one Widget has focus at a time. More...
 
WidgetManagermanager () const
 
void moveWidgetToBack (const shared_ptr< Widget > &widget)
 Pushes this widget to the back of the z order. More...
 
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 ()
 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 > > &posedArray, Array< shared_ptr< Surface2D > > &posed2DArray)
 Calls onPose on all children. More...
 
virtual void onSimulation (RealTime rdt, SimTime sdt, SimTime idt)
 
virtual void onUserInput (UserInput *ui)
 
const shared_ptr< Widget > & operator[] (int i) const
 Returns a module by index number. More...
 
virtual float positionalEventZ (const Point2 &pixel) const
 The camera-space z position that this Widget considers this pixel to be at. More...
 
void remove (const shared_ptr< Widget > &m)
 If a lock is in effect, then the remove will be delayed until the unlock. More...
 
virtual void render (RenderDevice *rd) const override
 Inherited from Surface2D. More...
 
virtual void setDepth (float d)
 Called by the WidgetManager. More...
 
void setFocusedWidget (const shared_ptr< Widget > &m, bool bringToFront=true)
 The Widget must have already been added. More...
 
virtual void setManager (WidgetManager *m)
 Called by the WidgetManager when this module is added to it. More...
 
int size () const
 Number of installed widgets. More...
 
const Array< shared_ptr< Widget > > & widgetArray () const
 Widgets currently executing. More...
 
virtual OSWindowwindow () const
 Returns the operating system window that is currently rendering this Widget. More...
 

Static Public Member Functions

static shared_ptr< WidgetManagercreate (OSWindow *window)
 
static bool onEvent (const GEvent &event, shared_ptr< WidgetManager > &a, shared_ptr< WidgetManager > &b)
 
static bool onEvent (const GEvent &event, shared_ptr< WidgetManager > &a)
 
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...
 

Protected Member Functions

 WidgetManager ()
 
void updateWidgetDepths ()
 Assigns a depth to each widget based on its current position in m_moduleArray and then sorts by depth. More...
 

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

Array< DelayedEventm_delayedEvent
 To be processed in endLock. More...
 
float m_depth
 
shared_ptr< Widgetm_focusedModule
 The widget that will receive events first. More...
 
bool m_locked
 
WidgetManagerm_manager
 The manager, set by setManager(). More...
 
Array< shared_ptr< Widget > > m_moduleArray
 Events are delivered in DECREASING index order. More...
 
OSWindowm_window
 Operating system window. More...
 

Detailed Description


Manages a group of G3D::Widget.

This is used internally by G3D::GApp to process its modules. It also enables use of Widgets without the G3D::GApp infrastructure. Most users do not need to use this class.

You can use G3D::Widget without this class.

Constructor & Destructor Documentation

◆ WidgetManager()

G3D::WidgetManager::WidgetManager ( )
protected

Member Function Documentation

◆ add()

void G3D::WidgetManager::add ( const shared_ptr< Widget > &  m)

If a lock is in effect, the add may be delayed until the unlock.

Priorities should generally not be used; they are largely for supporting debugging components at HIGH_PRIORITY that intercept events before they can hit the regular infrastructure.

◆ beginLock()

void G3D::WidgetManager::beginLock ( )


Between beginLock and endLock, add and remove operations are delayed so that iteration is safe.

Locks may not be executed recursively; only one level of locking is allowed. If using with G3D::GApp, allow the G3D::GApp to perform the locking for you.

◆ bounds()

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

Inherited from Surface2D.

Implements G3D::Surface2D.

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

◆ clear()

void G3D::WidgetManager::clear ( )


Removes all widgets on this manager.

◆ contains()

bool G3D::WidgetManager::contains ( const shared_ptr< Widget > &  m) const

If this widget has been added to the WidgetManager, or has a pending add (but not a subsequent pending remove) while in a lock.

◆ create()

static shared_ptr<WidgetManager> G3D::WidgetManager::create ( OSWindow window)
static
Parameters
windowThe window that generates events for this manager.

◆ 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>.

◆ defocusWidget()

void G3D::WidgetManager::defocusWidget ( const shared_ptr< Widget > &  m)

Removes focus from this module if it had focus, otherwise does nothing.

The widget will move down one z-order level in focus. See moveWidgetToBack() to push it all of the way to the back.

Referenced by G3D::GuiWindow::setVisible().

◆ 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.

◆ endLock()

void G3D::WidgetManager::endLock ( )

◆ fireEvent()

void G3D::WidgetManager::fireEvent ( const GEvent event)
virtual

Queues an event on the window associated with this manager.

Reimplemented from G3D::Widget.

◆ focusedWidget()

shared_ptr<Widget> G3D::WidgetManager::focusedWidget ( ) const

At most one Widget has focus at a time.

May be nullptr.

Note that a G3D::GuiWindow is a single Widget that then delegates key focus to one GuiControl within itself.

◆ manager()

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

◆ moveWidgetToBack()

void G3D::WidgetManager::moveWidgetToBack ( const shared_ptr< Widget > &  widget)

Pushes this widget to the back of the z order.

This window will render first and receive events last. This is the opposite of focussing a window.

◆ onAfterEvents()

virtual void G3D::WidgetManager::onAfterEvents ( )
virtual

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

Reimplemented from G3D::Widget.

◆ onAI()

virtual void G3D::WidgetManager::onAI ( )
virtual

Reimplemented from G3D::Widget.

◆ onBeforeGraphics()

virtual void G3D::WidgetManager::onBeforeGraphics ( )
virtual

Invoked by WidgetManager immediately before GApp::onGraphics runs.

Reimplemented from G3D::Widget.

◆ onEvent() [1/3]

static bool G3D::WidgetManager::onEvent ( const GEvent event,
shared_ptr< WidgetManager > &  a,
shared_ptr< WidgetManager > &  b 
)
static
Deprecated:
Runs the event handles of each manager interlaced, as if all the modules from b were in a.

◆ onEvent() [2/3]

static bool G3D::WidgetManager::onEvent ( const GEvent event,
shared_ptr< WidgetManager > &  a 
)
static

◆ onEvent() [3/3]

virtual bool G3D::WidgetManager::onEvent ( const GEvent event)
virtual

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 from G3D::Widget.

◆ onNetwork()

virtual void G3D::WidgetManager::onNetwork ( )
virtual

Reimplemented from G3D::Widget.

◆ onPose()

virtual void G3D::WidgetManager::onPose ( Array< shared_ptr< Surface > > &  posedArray,
Array< shared_ptr< Surface2D > > &  posed2DArray 
)
virtual

Calls onPose on all children.

Reimplemented from G3D::Widget.

◆ onSimulation()

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

Reimplemented from G3D::Widget.

◆ onUserInput()

virtual void G3D::WidgetManager::onUserInput ( UserInput ui)
virtual

Reimplemented from G3D::Widget.

◆ operator[]()

const shared_ptr<Widget>& G3D::WidgetManager::operator[] ( int  i) const

Returns a module by index number.

The highest index is the one that receives events first.

◆ 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.

◆ remove()

void G3D::WidgetManager::remove ( const shared_ptr< Widget > &  m)

If a lock is in effect, then the remove will be delayed until the unlock.

◆ 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.

◆ setFocusedWidget()

void G3D::WidgetManager::setFocusedWidget ( const shared_ptr< Widget > &  m,
bool  bringToFront = true 
)

The Widget must have already been added.

This widget will be moved to the top of the priority list (i.e., it will receive events first). You can set the focussed widget to nullptr.

If you change the focus during a lock, the actual focus change will not take effect until the lock is released.

Setting the focus automatically brings a module to the front of the event processing list unless bringToFront is false

◆ setManager()

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

◆ size()

int G3D::WidgetManager::size ( ) const

Number of installed widgets.

◆ 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.

◆ updateWidgetDepths()

void G3D::WidgetManager::updateWidgetDepths ( )
protected

Assigns a depth to each widget based on its current position in m_moduleArray and then sorts by depth.

The sorting pass is needed because some widgets will not accept their assigned position and will move up or down the array anyway.

◆ widgetArray()

const Array<shared_ptr<Widget> >& G3D::WidgetManager::widgetArray ( ) const
inline

Widgets currently executing.

Note that some widgets may have already been added but if the WidgetManager is locked they will not appear in this array yet.

◆ window()

virtual OSWindow* G3D::WidgetManager::window ( ) const
virtual

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

Reimplemented from G3D::Widget.

Member Data Documentation

◆ m_delayedEvent

Array<DelayedEvent> G3D::WidgetManager::m_delayedEvent
protected

To be processed in endLock.

◆ m_depth

float G3D::Widget::m_depth
protectedinherited

◆ m_focusedModule

shared_ptr<Widget> G3D::WidgetManager::m_focusedModule
protected

The widget that will receive events first.

This is usually but not always the top Widget in m_moduleArray.

◆ m_locked

bool G3D::WidgetManager::m_locked
protected

◆ 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().

◆ m_moduleArray

Array<shared_ptr<Widget> > G3D::WidgetManager::m_moduleArray
protected

Events are delivered in DECREASING index order.

Referenced by widgetArray().

◆ m_window

OSWindow* G3D::WidgetManager::m_window
protected

Operating system window.


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