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

#include <sgl.h>

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

Public Member Functions

 ObjectWindow (const std::string &title, int left, int top, int width, int height, double min_x, double max_x, double min_y, double max_y)
 
 ObjectWindow (const std::string &title, int width, int height)
 
 ObjectWindow (const std::string &title, double min_x, double max_x, double min_y, double max_y)
 
 ObjectWindow ()
 
 ~ObjectWindow ()
 
void prepaint () override
 
void postpaint () override
 
void mouse_pressed (double x, double y, MouseButton button) override
 
void mouse_released (double x, double y, MouseButton button) override
 
void mouse_moved (double x, double y) override
 
void mouse_dragged (double x, double y) override
 
void key_pressed (int k, double x, double y) override
 
void internal_add (GraphicalObject *obj)
 
template<typename T , typename... Args>
T * add (Args &&... args)
 
void remove (GraphicalObject *obj)
 
void remove_all ()
 
GraphicalObjecthit (double x, double y) const
 
std::vector< GraphicalObject * >::iterator begin ()
 
std::vector< GraphicalObject * >::iterator end ()
 
- Public Member Functions inherited from sgl::Window
 Window (const std::string &title, int left, int top, int width, int height, double min_x, double max_x, double min_y, double max_y)
 
 Window (const std::string &title, int width, int height)
 
 Window (const std::string &title, double min_x, double max_x, double min_y, double max_y)
 
 Window ()
 
virtual ~Window ()
 
virtual void clear ()
 
virtual void set_title (const std::string &str)
 
virtual void set_background_color (const Color &color)
 
virtual void set_position (int x, int y)
 
virtual void set_size (int width, int height)
 
virtual void set_viewport (double left, double right, double bottom, double top)
 
virtual void set_visible (bool visible)
 
virtual CursorShape set_cursor (CursorShape cursor)
 
virtual CursorShape get_cursor ()
 
virtual void run ()
 
virtual void repaint ()
 
virtual void paint ()=0
 
virtual void paint_all ()
 
virtual int get_x () const
 
virtual int get_y () const
 
virtual int get_width () const
 
virtual int get_height () const
 
virtual void set_window_size (int w, int h)
 
virtual void resized (int w, int h)
 
virtual double get_min_x () const
 
virtual double get_max_x () const
 
virtual double get_min_y () const
 
virtual double get_max_y () const
 
virtual void draw_axes (double x_inc, double y_inc) const
 
virtual void mouse_entered ()
 
virtual void mouse_exited ()
 
KeyModifier get_key_modifiers () const
 
void set_key_modifiers (KeyModifier mod)
 
virtual void start_timer (int msec)
 
virtual void timer_expired ()
 

Protected Attributes

std::vector< GraphicalObject * > object_list
 
GraphicalObjectactive_object
 
- Protected Attributes inherited from sgl::Window
double min_x
 
double max_x
 
double min_y
 
double max_y
 
CursorShape normal_cursor
 
KeyModifier key_mods
 

Additional Inherited Members

- Protected Member Functions inherited from sgl::Window
void initialize (const std::string &title, int left, int top, int width, int height, double min_x, double max_x, double min_y, double max_y)
 

Detailed Description

The class representing window objects that can contain graphical objects that the user can manipulate.

Constructor & Destructor Documentation

◆ ObjectWindow() [1/4]

sgl::ObjectWindow::ObjectWindow ( const std::string &  title,
int  left,
int  top,
int  width,
int  height,
double  min_x,
double  max_x,
double  min_y,
double  max_y 
)

Constructor that provides the most control to the client. Creates a window with detailed information.

Parameters
titlethe text to appear within the window's titlebar
leftthe x coordinate in screen coordinates of the window's left-top corner
topthe y coordinate in screen coordinates of the window's left-top corner
widththe width in screen coordinates of the window
heightthe height in screen coordinates of the window
min_xthe smallest x value representing the left-most position within the viewport
max_xthe largest x value representing the right-most position within the viewport
min_ythe smallest y value representing the bottom-most position within the viewport
max_ythe largest y value representing the top-most position within the viewport

◆ ObjectWindow() [2/4]

sgl::ObjectWindow::ObjectWindow ( const std::string &  title,
int  width,
int  height 
)

Creates a window of a specified width and height

Parameters
titlethe text to appear within the window's titlebar
widththe width in screen coordinates of the window
heightthe height in screen coordinates of the window

◆ ObjectWindow() [3/4]

sgl::ObjectWindow::ObjectWindow ( const std::string &  title,
double  min_x,
double  max_x,
double  min_y,
double  max_y 
)

Creates a window with a default position and size.

Parameters
titlethe text to appear within the window's titlebar
min_xthe smallest x value representing the left-most position within the viewport
max_xthe largest x value representing the right-most position within the viewport
min_ythe smallest y value representing the bottom-most position within the viewport
max_ythe largest y value representing the top-most position within the viewport

◆ ObjectWindow() [4/4]

sgl::ObjectWindow::ObjectWindow ( )

Create a default, plain window

◆ ~ObjectWindow()

sgl::ObjectWindow::~ObjectWindow ( )

Destroys an object window object.

Member Function Documentation

◆ add()

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

Creates and adds a graphical object to the window. 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 window
Parameters
argsforwards the method parameters to the graphical object's constructor
Returns
a pointer to the newly and added created graphical object

◆ begin()

std::vector< GraphicalObject * >::iterator sgl::ObjectWindow::begin ( )

Returns an iterator to the begining of the vector of graphical objects this window contains.

Returns
an iterator to the begining of the vector of graphical objects this window contains.

◆ end()

std::vector< GraphicalObject * >::iterator sgl::ObjectWindow::end ( )

Returns an iterator just past the end of the vector of graphical objects this window contains.

Returns
an iterator just past the end of the vector of graphical objects this window contains.

◆ hit()

GraphicalObject * sgl::ObjectWindow::hit ( double  x,
double  y 
) const

Returns the first graphical object in the list of graphical objects with a bounding box that intersects the given viewport coordinates.

Parameters
xthe x coordinate in viewport coordinates of a location within the viewport
ythe y coordinate in viewport coordinates of a location within the viewport
Returns
a contained graphical object with a bounding box that intersects the given position within the viewport. Returns null if no contained graphical object intersects the given point

◆ internal_add()

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

Adds a graphical object to the window. Clients generally call the add method (which calls this method indirectly) rather than calling this method directly. That way the the window is responsible for managing the Graphical object's memory.

Parameters
objthe graphical object to add to this window
Returns
nothing

◆ key_pressed()

void sgl::ObjectWindow::key_pressed ( int  k,
double  x,
double  y 
)
overridevirtual

Called by the event manager when the user types a key when the window has keyboard focus. The key pressed and the location of the mouse pointer in viewport coordinates is reported.

Parameters
kthe key typed by the user
xthe x coordinate in viewport coordinates of the location of the mouse pointer within the window
ythe y coordinate in viewport coordinates of the location of the mouse pointer within the window
Returns
nothing

Reimplemented from sgl::Window.

Reimplemented in sgl::ProceduralWindow.

◆ mouse_dragged()

void sgl::ObjectWindow::mouse_dragged ( double  x,
double  y 
)
overridevirtual

Called by the event manager when the user drags the mouse (moves the mouse while holding down a mouse button) when the mouse pointer is within the window. The location reported is given in viewport coordinates.

Parameters
xthe x coordinate in viewport coordinates of the location of the mouse pointer within the window during the most recent mouse event.
ythe y coordinate in viewport coordinates of the location of the mouse pointer within the window during the most recent mouse event.
Returns
nothing

Reimplemented from sgl::Window.

Reimplemented in sgl::ProceduralWindow.

◆ mouse_moved()

void sgl::ObjectWindow::mouse_moved ( double  x,
double  y 
)
overridevirtual

Called by the event manager when the user moves the mouse when the mouse pointer is within the window. The location reported is given in viewport coordinates.

Parameters
xthe x coordinate in viewport coordinates of the location of the mouse pointer within the window during the most recent mouse event.
ythe y coordinate in viewport coordinates of the location of the mouse pointer within the window during the most recent mouse event.
Returns
nothing

Reimplemented from sgl::Window.

Reimplemented in sgl::ProceduralWindow.

◆ mouse_pressed()

void sgl::ObjectWindow::mouse_pressed ( double  x,
double  y,
MouseButton  button 
)
overridevirtual

Called by the event loop when the user depresses any mouse button when the mouse pointer is within the window.

Parameters
xthe x coordinate in viewport coordinates of the mouse pointer location within the window during the current mouse event.
ythe y coordinate in viewport coordinates of the mouse pointer location within the window during the current mouse event.
buttonthe button that was depressed, left (LEFT_BUTTON) or right (RIGHT_BUTTON) during the current mouse event.
Returns
nothing

Reimplemented from sgl::Window.

Reimplemented in sgl::ProceduralWindow.

◆ mouse_released()

void sgl::ObjectWindow::mouse_released ( double  x,
double  y,
MouseButton  button 
)
overridevirtual

Called by the event manager when the user releases any mouse button when the mouse pointer is within the window.

Parameters
xthe x coordinate in viewport coordinates of the mouse pointer location within the window during the current mouse event.
ythe y coordinate in viewport coordinates of the mouse pointer location within the window during the current mouse event.
buttonthe button that was released, left (LEFT_BUTTON) or right (RIGHT_BUTTON) during the current mouse event.
Returns
nothing

Reimplemented from sgl::Window.

Reimplemented in sgl::ProceduralWindow.

◆ postpaint()

void sgl::ObjectWindow::postpaint ( )
overridevirtual

Code executed after the call to paint

Returns
nothing

Reimplemented from sgl::Window.

◆ prepaint()

void sgl::ObjectWindow::prepaint ( )
overridevirtual

Code executed before the call to paint

Returns
nothing

Reimplemented from sgl::Window.

◆ remove()

void sgl::ObjectWindow::remove ( GraphicalObject obj)

Removes a graphical object from the window. Frees up the memory held by the graphical object.

Parameters
objthe graphical object to remove from the window.
Returns
nothing

◆ remove_all()

void sgl::ObjectWindow::remove_all ( )

Removes all the graphical objects from the list of contained graphical objects. Frees up the memory allocated for the graphical objects.

Returns
nothing

Member Data Documentation

◆ object_list

std::vector<GraphicalObject *> sgl::ObjectWindow::object_list
protected

The list of graphical objects contained in this window.


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