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

#include <sgl.h>

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

Public Member Functions

 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 paint () const =0
 
virtual void move_to (double left, double bottom)
 
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 ()
 

Public Attributes

const unsigned id
 

Protected Attributes

ObjectWindowwindow
 
double x_hit_offset
 
double y_hit_offset
 
double left
 
double bottom
 
double width
 
double height
 
CursorShape cursor
 
bool mouse_over
 

Detailed Description

Represents a persistent graphical object used within a window. A graphical object is owned by a particular window.

Constructor & Destructor Documentation

◆ GraphicalObject() [1/2]

sgl::GraphicalObject::GraphicalObject ( double  left,
double  bottom,
double  width,
double  height 
)

Constructor specifies the bounding box extent.

Parameters
leftthe x coordinate in viewport coordinates of the left-bottom corner of the graphical object's bounding box
leftthe y coordinate in viewport coordinates of the left-bottom corner of the graphical object's bounding box
widththe width in viewport coordinates of the graphical object's bounding box
heightthe height in viewport coordinates of the graphical object's bounding box

◆ GraphicalObject() [2/2]

sgl::GraphicalObject::GraphicalObject ( const GraphicalObject other)

Copy construction creates a new graphical object with identical location. The new graphical object has the same containing window but has a unique id. The pre-existing graphical object is not affected by the copy.

Parameters
otherthe graphical object from which this new graphical object is being created.

◆ ~GraphicalObject()

sgl::GraphicalObject::~GraphicalObject ( )
virtual

Destroys a graphical object.

Member Function Documentation

◆ get_bottom()

double sgl::GraphicalObject::get_bottom ( ) const
virtual

Returns the y value of the left-bottom corner of the graphical object's bounding box. The value is given in the viewport coordinate system.

Returns
the y coordinate of the graphical object's left-bottom corner

◆ get_cursor()

CursorShape sgl::GraphicalObject::get_cursor ( )
virtual

Returns the cursor shape associated with this graphical object.

Returns
the cursor shape associated with this graphical object

◆ get_height()

double sgl::GraphicalObject::get_height ( ) const
virtual

Returns the height in viewport coordinates of the graphical object's bounding box.

Returns
the height of the graphical object

◆ get_left()

double sgl::GraphicalObject::get_left ( ) const
virtual

Returns the x value of the left-bottom corner of the graphical object's bounding box. The value is given in the viewport coordinate system.

Returns
the x coordinate of the graphical object's left-bottom corner

◆ get_width()

double sgl::GraphicalObject::get_width ( ) const
virtual

Returns the width in viewport coordinates of the graphical object's bounding box.

Returns
the width of the graphical object

◆ get_window()

Window * sgl::GraphicalObject::get_window ( ) const
virtual

Get the containing window of this graphical object.

Returns
a pointer to the window that contains this graphical object.

◆ hit()

bool sgl::GraphicalObject::hit ( double  x,
double  y 
)
virtual

Returns true if the coordinate provided is within the graphical object's bounding box; otherwise, it returns false.

Parameters
xthe x coordinate in viewport coordinates of the location to check
ythe y coordinate in viewport coordinates of the location to check
Returns
true, if (x,y) intersects the bounding box of the graphical object; otherwise it returns false

◆ key_pressed()

void sgl::GraphicalObject::key_pressed ( int  k,
double  x,
double  y 
)
virtual

Called by the containing window when the user types a key when the window has keyboard focus and the mouse pointer is over the graphical object. 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

◆ mouse_dragged()

void sgl::GraphicalObject::mouse_dragged ( double  x,
double  y 
)
virtual

Called by the containing window's mouse_dragged method when the user drags the mouse By default it relocates the (left,bottom) location of the graphical object's bounding box relative to a mouse drag event. The move is relative to the location of the last mouse event on the object. This allows the user to drag the graphical object without it "jumping" slightly at first movement. The graphical object's width and height are unaffected.

Parameters
xthe x coordinate in viewport coordinates of the mouse pointer location during the current mouse event.
ythe y coordinate in viewport coordinates of the mouse pointer location during the current mouse event.
Returns
nothing

Called by the containing window's mouse_dragged method when the user drags the mouse when the mouse pointer is over the graphical object.

Parameters
xthe x coordinate in viewport coordinates of the mouse pointer location during the current mouse event.
ythe y coordinate in viewport coordinates of the mouse pointer location during the current mouse event.
Returns
nothing

Reimplemented in sgl::TimeDisplay, sgl::Multidigit, sgl::DoubleDigit, and sgl::DisplayDigit.

◆ mouse_moved()

void sgl::GraphicalObject::mouse_moved ( double  x,
double  y 
)
virtual

Called by the containing window's mouse_moved method when the user moves the mouse when the mouse pointer is over the graphical object.

Parameters
xthe x coordinate in viewport coordinates of the mouse pointer location during the current mouse event.
ythe y coordinate in viewport coordinates of the mouse pointer location during the current mouse event.
Returns
nothing

◆ mouse_pressed()

void sgl::GraphicalObject::mouse_pressed ( double  x,
double  y,
MouseButton  button 
)
virtual

Called by the containing window's mouse_pressed method when the user depresses any mouse button when the mouse pointer is over the graphical object.

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

◆ mouse_released()

void sgl::GraphicalObject::mouse_released ( double  x,
double  y,
MouseButton  button 
)
virtual

Called by the containing window's mouse_released method when the user releases any mouse button when the mouse pointer is over the graphical object.

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

◆ move_to()

void sgl::GraphicalObject::move_to ( double  left,
double  bottom 
)
virtual

Relocates the left-bottom corner of the graphical object's bounding box to the specified location. The graphical object's width and height are unaffected.

Parameters
leftthe x coordinate in viewport coordinates of the left-bottom corner of the graphical object's bounding box
bottomthe y coordinate in viewport coordinates of the left-bottom corner of the graphical object's bounding box
Returns
nothing

Reimplemented in sgl::TimeDisplay, sgl::Multidigit, and sgl::CompositeObject.

◆ operator=()

GraphicalObject & sgl::GraphicalObject::operator= ( const GraphicalObject other)

Assignment copies the location, size, and window container from another graphical object. The id of the window being assigned is not affected. The source graphical object is not affected by the copy.

Parameters
otherthe source graphical object from which this graphical object is being assigned.
Returns
a reference to this graphical object as per standard assignment operator sementics

◆ paint()

virtual void sgl::GraphicalObject::paint ( ) const
pure virtual

The paint method is called by the containing window's paint method when it renders this graphical object. This method is abstract, so concrete derived classes must provide a concrete imppementation.

Returns
nothing

Implemented in sgl::TimeDisplay, sgl::Multidigit, sgl::DoubleDigit, sgl::DisplayDigit, sgl::BitmapObject, and sgl::CompositeObject.

◆ set()

void sgl::GraphicalObject::set ( double  x,
double  y,
double  width,
double  height 
)
virtual

Sets the location and size of the graphical object. Values given are in the containing viewport's coordinates. the x coordinate of the left-bottom corner of the graphical object's bounding rectangle. the y coordinate of the left-bottom corner of the graphical object's bounding rectangle. the graphical object's width in viewport coordinates. the graphical object's height in viewport coordinates.

Returns
nothing

◆ set_cursor()

CursorShape sgl::GraphicalObject::set_cursor ( CursorShape  cursor)
virtual

Sets the graphical object's cursor shape.

Parameters
cursorthe object's cursor shape
Returns
the previous cursor shape

◆ set_mouse_over()

void sgl::GraphicalObject::set_mouse_over ( bool  flag)
virtual

Activates or deactivates the graphical object

Parameters
flagif true, activates the object; otherwise, deactivates the object
Returns
nothing

◆ set_window()

Window * sgl::GraphicalObject::set_window ( ObjectWindow win)
virtual

Set the containing window.

Parameters
wina pointer to the window to make the containing window for this graphical object.
Returns
a pointer to the previous owner of this window

Member Data Documentation

◆ bottom

double sgl::GraphicalObject::bottom
protected

y coordinate of the left-bottom corner of the graphical object's bounding box

◆ cursor

CursorShape sgl::GraphicalObject::cursor
protected

Shape that the cursor should assume when the mouse hovers over this graphical object.

◆ height

double sgl::GraphicalObject::height
protected

Height of the graphical object's bounding box in the viewport coordinate system

◆ id

const unsigned sgl::GraphicalObject::id

This graphical object's unique ID

◆ left

double sgl::GraphicalObject::left
protected

x coordinate of the left-bottom corner of the graphical object's bounding box

◆ mouse_over

bool sgl::GraphicalObject::mouse_over
protected

Indicates if this object is the one that the mouse is currently hovering over.

◆ width

double sgl::GraphicalObject::width
protected

Width of the graphical object's bounding box in the viewport coordinate system

◆ window

ObjectWindow* sgl::GraphicalObject::window
protected

The window in which this graphical object is a component

◆ x_hit_offset

double sgl::GraphicalObject::x_hit_offset
protected

Location of the mouse pointer's x coordinate relative to the graphical object's bounding box

◆ y_hit_offset

double sgl::GraphicalObject::y_hit_offset
protected

Location of the mouse pointer's y coordinate relative to the graphical object's bounding box


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