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

#include <sgl.h>

Inheritance diagram for sgl::Window:
Inheritance graph
[legend]

Public Member Functions

 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 prepaint ()
 
virtual void postpaint ()
 
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_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 mouse_entered ()
 
virtual void mouse_exited ()
 
virtual void key_pressed (int k, double x, double y)
 
KeyModifier get_key_modifiers () const
 
void set_key_modifiers (KeyModifier mod)
 
virtual void start_timer (int msec)
 
virtual void timer_expired ()
 

Protected Member Functions

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)
 

Protected Attributes

double min_x
 
double max_x
 
double min_y
 
double max_y
 
CursorShape normal_cursor
 
KeyModifier key_mods
 

Detailed Description

The class representing basic graphical window objects. This simple window class does not support contained graphical objects, but the derived class ObjectWindow does.

Constructor & Destructor Documentation

◆ Window() [1/4]

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 constructor that provides the most control to the client. Creates a window with detailed information. After intializing instrance variables, the constructor defers the actual work to the initialize method.

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

◆ Window() [2/4]

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

Creates a window with a default position. After intializing instrance variables, the constructor defers the actual work to the initialize method. The virtual viewport's range is 0.0...width by 0.0...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

◆ Window() [3/4]

sgl::Window::Window ( 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. After intializing instrance variables, the constructor defers the actual work to the initialize method.

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

◆ Window() [4/4]

sgl::Window::Window ( )

Create a default, plain window

◆ ~Window()

sgl::Window::~Window ( )
virtual

Destroys a graphical window object.

Member Function Documentation

◆ clear()

void sgl::Window::clear ( )
virtual

Erase all the drawing within the window. Does not remove any added graphical objects.

Returns
nothing

◆ draw_axes()

void sgl::Window::draw_axes ( double  x_inc,
double  y_inc 
) const
virtual

Draws the x and y axes for the viewport. Draws grid lines at the specified intervals. To avoid drawing grid lines, clients should specify x_inc and/or y_inc values greater than the range of viewport coordinates.

◆ get_cursor()

CursorShape sgl::Window::get_cursor ( )
virtual

Gets the window's curent cursor shape

Returns
the window's current cursor shape

◆ get_height()

int sgl::Window::get_height ( ) const
virtual

Returns the height in screen coordinates of the physical window.

Returns
the height in screen coordinates of the window

◆ get_key_modifiers()

KeyModifier sgl::Window::get_key_modifiers ( ) const

Returns the active key modifier: SHIFT, CTRL, and/or ALT, if any. The return value is the bitwise ORed combination of active key modifiers.

Returns
the active key modifier

◆ get_max_x()

double sgl::Window::get_max_x ( ) const
virtual

Returns the viewport's right-most (highest) x value in viewport coordinates.

Returns
the viewport's right-most (highest) x value in viewport coordinates

◆ get_max_y()

double sgl::Window::get_max_y ( ) const
virtual

Returns the viewport's top-most (highest) y value in viewport coordinates.

Returns
the viewport's top-most (highest) y value in viewport coordinates

◆ get_min_x()

double sgl::Window::get_min_x ( ) const
virtual

Returns the viewport's left-most (lowest) x value in viewport coordinates.

Returns
the viewport's left-most (lowest) x value in viewport coordinates

◆ get_min_y()

double sgl::Window::get_min_y ( ) const
virtual

Returns the viewport's bottom-most (lowest) y value in viewport coordinates.

Returns
the viewport's bottom-most (lowest) y value in viewport coordinates

◆ get_width()

int sgl::Window::get_width ( ) const
virtual

Returns the width in screen coordinates of the physical window.

Returns
the width in screen coordinates of the window

◆ get_x()

int sgl::Window::get_x ( ) const
virtual

Returns the x value in screen coordinates of the left-top corner of the physical window.

Returns
the x value in screen coordinates of the left-top corner of the window

◆ get_y()

int sgl::Window::get_y ( ) const
virtual

Returns the y value in screen coordinates of the left-top corner of the physical window.

Returns
the y value in screen coordinates of the left-top corner of the window

◆ initialize()

void sgl::Window::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 
)
protected

Initialization routine used by the window constructors.

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
Returns
nothing

◆ key_pressed()

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

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 in sgl::ProceduralWindow, and sgl::ObjectWindow.

◆ mouse_dragged()

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

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 in sgl::ProceduralWindow, and sgl::ObjectWindow.

◆ mouse_entered()

void sgl::Window::mouse_entered ( )
virtual

Called by the event manager when the mouse pointer enters the window.

Returns
nothing

◆ mouse_exited()

void sgl::Window::mouse_exited ( )
virtual

Called by the event manager when the mouse pointer exits the window.

Returns
nothing

◆ mouse_moved()

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

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 in sgl::ProceduralWindow, and sgl::ObjectWindow.

◆ mouse_pressed()

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

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 in sgl::ProceduralWindow, and sgl::ObjectWindow.

◆ mouse_released()

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

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 in sgl::ProceduralWindow, and sgl::ObjectWindow.

◆ paint()

virtual void sgl::Window::paint ( )
pure virtual

Responsible for rendering the image in the window's viewport. This method is abstract, so concrete derived classes must provide a concrete implementation.

Returns
nothing.

Implemented in sgl::ProceduralWindow.

◆ paint_all()

void sgl::Window::paint_all ( )
virtual

Called automatically by the event loop. Calls prepaint, paint, and postpaint. Called when the window is repainted.

Returns
nothing

◆ postpaint()

void sgl::Window::postpaint ( )
virtual

Code executed after the call to paint

Returns
nothing

Reimplemented in sgl::OGLWindow, and sgl::ObjectWindow.

◆ prepaint()

void sgl::Window::prepaint ( )
virtual

Code executed before the call to paint

Returns
nothing

Reimplemented in sgl::OGLWindow, and sgl::ObjectWindow.

◆ repaint()

void sgl::Window::repaint ( )
virtual

Request the window to be redrawn.

Returns
nothing

◆ resized()

void sgl::Window::resized ( int  w,
int  h 
)
virtual

Responds to a change in the width and/or height of the physical window. The event loop calls this method when the user resizes the window.

Parameters
wthe window's new width in screen coordinates
hthe window's new height in screen coordinates
Returns
nothing

◆ set_background_color()

void sgl::Window::set_background_color ( const Color color)
virtual

Sets the background color of the window's viewport.

Parameters
colora reference to a Color object specifying the window's background color.
Returns
nothing

◆ set_cursor()

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

Sets the window's cursor shape

Parameters
cursorone of several CursorShape values
Returns
the previous cursor shape that was replaced by this call

Sets the window's cursor shape

Parameters
cursorone of several CursorShape values
Returns
nothing

◆ set_key_modifiers()

void sgl::Window::set_key_modifiers ( KeyModifier  mod)

Sets the key modifiers instance variable. This method is ordinarily used by SGL internally for preprocessing calls from the event manager; clients typically will not call this method directly.

Parameters
modthe bitwise ORed combination of key modifiers (SHIFT_KEY, CTRL_KEY, ALT_KEY)
Returns
nothing

◆ set_position()

void sgl::Window::set_position ( int  x,
int  y 
)
virtual

Sets the location of the left-top corner of the window's client area to (x,y).

Parameters
xthe x coordinate of the window's left-top corner
ythe y coordinate of the window's left-top corner
Returns
nothing

◆ set_size()

void sgl::Window::set_size ( int  width,
int  height 
)
virtual

Sets the physical window's hoizontal and vertical dimensions.

Parameters
widththe new width of the window
heightthe new height of the window
Returns
nothing

◆ set_title()

void sgl::Window::set_title ( const std::string &  str)
virtual

Sets the title of the window.

Parameters
strthe text of the new title
Returns
nothing

◆ set_viewport()

void sgl::Window::set_viewport ( double  left,
double  right,
double  bottom,
double  top 
)
virtual

Sets the horizontal and vertical ranges of the window's virtual viewport. Values given are in viewport's coordinates. the left-most (lowest) x value in viewport coordinates. the right-most (highest) x value in viewport coordinates. the bottom-most (lowest) y value in viewport coordinates. the top-most (highest) y value in viewport coordinates.

Returns
nothing

◆ set_visible()

void sgl::Window::set_visible ( bool  visible)
virtual

Shows or hides the window. viewport. Values given are in viewport's coordinates.

Parameters
visibleif true, the window is visible; otherwise, the window is invisible.
Returns
nothing

◆ set_window_size()

void sgl::Window::set_window_size ( int  w,
int  h 
)
virtual

Sets the size of the physical window.

Parameters
wthe window's new width in screen coordinates
hthe window's new height in screen coordinates
Returns
nothing

◆ start_timer()

void sgl::Window::start_timer ( int  msec)
virtual

Starts a countdown timer for this window. The event manager calls timer_expired when the timer expires.

Parameters
msecthe number of milliseconds to count
Returns
nothing

◆ timer_expired()

void sgl::Window::timer_expired ( )
virtual

Called by the event manager when the current timer expires. The timer is not automatically reset, so clients such as animations that require continuous periodic notification must call start_timer after processing each timer_expired message.

Returns
nothing

Member Data Documentation

◆ key_mods

KeyModifier sgl::Window::key_mods
protected

Records the status of the SHIFT, ALT, and CTRL keys during the the latest key press, mouse pressed, or mouse released event within the window.

◆ max_x

double sgl::Window::max_x
protected

The largest x value representing the right-most position within the viewport.

◆ max_y

double sgl::Window::max_y
protected

The largest y value representing the top-most position within the viewport.

◆ min_x

double sgl::Window::min_x
protected

The smallest x value representing the left-most position within the viewport.

◆ min_y

double sgl::Window::min_y
protected

The smallest y value representing the bottom-most position within the viewport.

◆ normal_cursor

CursorShape sgl::Window::normal_cursor
protected

The standard cursor for this window.


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