Simple Graphics Library  0.9.5
SGL API
Public Member Functions | Protected Attributes | List of all members
sgl::CompositeObject Class Reference

#include <sgl.h>

Inheritance diagram for sgl::CompositeObject:
Inheritance graph
[legend]
Collaboration diagram for sgl::CompositeObject:
Collaboration graph
[legend]

Public Member Functions

 CompositeObject ()
 
void paint () const override
 
void move_to (double x, double y) override
 
void internal_add (GraphicalObject *obj)
 
template<typename T , typename... Args>
T * add (Args &&... args)
 
- Public Member Functions inherited from sgl::GraphicalObject
 GraphicalObject (double left, double bottom, double width, double height)
 
 GraphicalObject (const GraphicalObject &other)
 
GraphicalObjectoperator= (const GraphicalObject &other)
 
virtual ~GraphicalObject ()
 
virtual double get_left () const
 
virtual double get_bottom () const
 
virtual double get_width () const
 
virtual double get_height () const
 
virtual void set (double x, double y, double width, double height)
 
virtual void mouse_pressed (double x, double y, MouseButton button)
 
virtual void mouse_released (double x, double y, MouseButton button)
 
virtual void mouse_moved (double x, double y)
 
virtual void mouse_dragged (double x, double y)
 
virtual void key_pressed (int k, double x, double y)
 
virtual bool hit (double x, double y)
 
virtual Windowset_window (ObjectWindow *win)
 
virtual Windowget_window () const
 
virtual void set_mouse_over (bool flag)
 
virtual CursorShape set_cursor (CursorShape cursor)
 
virtual CursorShape get_cursor ()
 

Protected Attributes

std::vector< GraphicalObject * > objects
 
- Protected Attributes inherited from sgl::GraphicalObject
ObjectWindowwindow
 
double x_hit_offset
 
double y_hit_offset
 
double left
 
double bottom
 
double width
 
double height
 
CursorShape cursor
 
bool mouse_over
 

Additional Inherited Members

- Public Attributes inherited from sgl::GraphicalObject
const unsigned id
 

Detailed Description

A composite object aggregates a collection of graphical objects (even other composite objects into a single graphical object.

Constructor & Destructor Documentation

◆ CompositeObject()

sgl::CompositeObject::CompositeObject ( )

The constructor makes an initially empty container.

Member Function Documentation

◆ add()

template<typename T , typename... Args>
T* sgl::CompositeObject::add ( Args &&...  args)
inline

Creates and adds a graphical object to the composite object. Clients specify the exact type of the graphical object as the template parameter and pass any arguments required by that object's constructor in the parameter list.

Template Parameters
Tthe type of graphical object to add to this composite object
Parameters
argsforwards the method parameters to the graphical object's constructor
Returns
a pointer to the newly and added created graphical object

◆ internal_add()

void sgl::CompositeObject::internal_add ( GraphicalObject obj)

Adds a graphical object to this container. Adjusts the container's size accordingly.

Parameters
obja pointer to the graphical object to add.
Returns
nothing.

Adds a graphical object to this container. Adjusts the container's size accordingly. Clients ordinarily call add method instead; the add method allocates space for the added object and relieves the client of memory management.

Parameters
obja pointer to the graphical object to add.
Returns
nothing.

◆ move_to()

void sgl::CompositeObject::move_to ( double  x,
double  y 
)
overridevirtual

Repositions the lower-left corner of the composite object's boundng box to (x,y). The positions of the contained graphical objects are updated accordingly.

Reimplemented from sgl::GraphicalObject.

◆ paint()

void sgl::CompositeObject::paint ( ) const
overridevirtual

Draws each object that makes up the composite object.

Returns
nothing.

Implements sgl::GraphicalObject.

Member Data Documentation

◆ objects

std::vector<GraphicalObject *> sgl::CompositeObject::objects
protected

The collection of contained graphical objects.


The documentation for this class was generated from the following files: