|
CarnegieMellonGraphics | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The Window class is used to represent that actual drawing surfaces. Currently on creating a new window object, a new window will open in user's operating environment. The background color is black by default.
Two different input paradigms have been provided. One is event based, and requires deriving a new Window class and then starting the CarnegieMellonGraphics event handler (described below). For this derived class to do something interesting, one or more of the "handle" member functions listed below must be overridden.
The other method of input works within the standard structured programming framework, and involves polling the "isQueueEmpty" functions to see if an event has occurred, removing the event from the queue, and processing it as desired.
Drawing into the window is then simply a matter of calling the appropriate member functions on the window.
Updates:
isKeyDown
and isButtonDown
.
flipPage
method
is still available, but it is an alias for
reDraw
which redraws and swaps buffers.
erase(Color)
method clears
the display buffer and fills the background with Color
Constructor Summary | |
|
Window( const int width = 640, const int height = 480, const std::string& title = std::string("CarnegieMellonGraphics Window" ), bool fullscreen = false, int bitdepth = 32, int refreshrate = 60 )
Construct a new window with the specified size and title. |
|
Window( int xpos, int ypos, int width, int height, const std::string& title = std::string("CarnegieMellonGraphics Window" ), bool fullscreen = false, int bitdepth = 32, int refreshrate = 60 )
An alternate constructor where you get to choose the position of the window as well as all of the other usual parameters. |
private |
Window( const Window& window )
|
|
virtual ~Window()
|
Method Summary | |
void |
addKeyboardEvent( const KeyboardEvent& keyboard )
Functions to add events to the input queues. |
void |
addMouseEvent( const MouseEvent& mouse )
Functions to add events to the input queues. |
void |
addTimerEvent( const TimerEvent& timer )
Functions to add events to the input queues. |
void |
autoFlushKeyboardQueue( bool enable )
Automatically lets you ignore the events in the keyboard message queue. |
void |
autoFlushMouseQueue( bool enable )
Automatically lets you ignore the events in the mouse message queue. |
void |
autoFlushTimerQueue( bool enable )
Automatically lets you ignore the events in the timer message queue. |
void |
copyRegion( const int x1, const int y1, const int x2, const int y2, const int width, const int height )
Copy the rectangular region at (x1, y1) to (x2, y2) |
Image |
createImage( const int x, const int y, const int width, const int height )
Create an image from the rectangular region with an upper-left hand corner at (x, y) |
void |
disableAntialiasing()
Renderer dependent capability. |
void |
drawArc( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end )
Draw an elliptical arc from angle start to end in degrees. |
void |
drawBezierCurve( const Style& s, const std::vector< int >& xcoords, const std::vector< int >& ycoords )
Draw a bezier curve using the specified style, and the two vectors specifying the control points |
void |
drawChordFilled( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end )
Draw a filled elliptical chord with from start to end degrees The two points (x1, y1) and (x2, y2) specify the bounding box |
void |
drawChordOutline( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end )
Draw an elliptical chord outline with from start to end degrees The two points (x1, y1) and (x2, y2) specify the bounding box |
void |
drawCircleFilled( const Style& s, const int x, const int y, const int radius )
Draw a filled circle with style s and the specified radius at point (x, y) |
void |
drawCircleOutline( const Style& s, const int x, const int y, const int radius )
Draw a circle outline with style s and the specified radius at point (x, y) |
void |
drawEllipseFilled( const Style& s, const int x1, const int y1, const int x2, const int y2 )
Draw a filled ellipse with inside the bounding box specfied by the two points (x1, y1) and (x2, y2) |
void |
drawEllipseOutline( const Style& s, const int x1, const int y1, const int x2, const int y2 )
Draw an ellipse outline with inside the bounding box specified by the two points (x1, y1) and (x2, y2) |
void |
drawImage( const Image& image, const int x, const int y )
Draw the image at with its upper right-hand corner located at (x,y) |
void |
drawImage( const Image& image, const int x, const int y, const Transform& transform )
Draw the image at with its upper right-hand corner located at (x,y) using the specified transform |
void |
drawLine( const Style& s, const int x1, const int y1, const int x2, const int y2 )
Draw a line from (x1,y1) to (x2, y2) with style s |
void |
drawPixel( const Style& s, const int x, const int y )
Draw a pixel at (x,y) with style s. |
void |
drawPolygonFilled( const Style& s, const std::vector< int >& xcoords, const std::vector< int >& ycoords )
Draw a filled polygon using the specified style and the two vectors to specifiy vertices |
void |
drawPolygonOutline( const Style& s, const std::vector< int >& xcoords, const std::vector< int >& ycoords )
Draw a polygon outline using the specified style and the two vectors to specifiy vertices |
void |
drawPolyLine( const Style& s, const std::vector< int >& xcoords, const std::vector< int >& ycoords )
Draw a polyline using the specified style and the two vectors to specifiy vertices |
void |
drawRectangleFilled( const Style& s, const int x1, const int y1, const int x2, const int y2 )
Draw a filled rectangle with (x1, y1) as the upper left-hand corner, and (x2, y2) as the lower right-hand corner with style s |
void |
drawRectangleOutline( const Style& s, const int x1, const int y1, const int x2, const int y2 )
Draw a rectangle outline with (x1, y1) as the upper left-hand corner, and (x2, y2) as the lower right-hand corner with style s |
void |
drawText( const Style& s, const Font& f, const int x, const int y, const std::string& text )
Draw text in the specified font and style |
void |
drawText( const Style& s, const Font& f, const int x, const int y, const std::string& text, const Transform& transform )
Draw text in the specified font and style, using the specified transform |
void |
drawTriangleFilled( const Style& s, const int x1, const int y1, const int x2, const int y2, const int x3, const int y3 )
Draw a filled triangle with vertices (x1, y1), (x2, y2), (x3, y3) with in style s |
void |
drawTriangleOutline( const Style& s, const int x1, const int y1, const int x2, const int y2, const int x3, const int y3 )
Draw a triangle outline with vertices (x1, y1), (x2, y2), (x3, y3) with in style s |
void |
drawWedgeFilled( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end )
Draw a filled elliptical wedge with from start to end degrees The two points (x1, y1) and (x2, y2) specify the bounding box |
void |
drawWedgeOutline( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end )
Draw an elliptical wedge outline with from start to end degrees The two points (x1, y1) and (x2, y2) specify the bounding box |
void |
enableAntialiasing()
Renderer dependent capability. |
void |
erase()
Erases drawing and fills background. |
void |
flipPage()
Deprecated. This is an alias for reDraw()
Make the changes that you've made appear on screen. |
void |
flushKeyboardQueue()
Remove all pending messages in the keyboard event queue. |
void |
flushMouseQueue()
Remove all pending messages in the mouse event queue. |
void |
flushTimerQueue()
Remove all pending messages in the timer event queue. |
int |
getHeight() const
Return the height of the window. |
KeyboardEvent |
getKeyboardEvent()
Pull events off the front of the Keyboard event queue. |
KeyboardEvent |
getKeyboardFilter()
Set filters on the input queues, useful in eliminating non-interesting events. |
MouseEvent |
getMouseEvent()
Pull events off the front of the Mouse event queue Use isButtonDown if you're interested in less precise input processing (i.e. when you're making a game). |
MouseEvent |
getMouseFilter()
Set filters on the input queues, useful in eliminating non-interesting events. |
int |
getMouseX() const
Return the last location of mouse X position. |
int |
getMouseY() const
Return the last location of mouse Y position. |
void |
getPosition( int& x, int& y )
Retrieves the current position of the window. |
int |
getTimerCount( const TimerEvent& te )
Get the number of times this timer event has occurred. |
TimerEvent |
getTimerEvent()
Pull events off the front of the Timer event queue Use getTimerCount to get lower-overhead event processing. |
TimerEvent |
getTimerFilter()
Set filters on the input queues, useful in eliminating non-interesting events. |
int |
getWidth() const
Return the width of the window. |
virtual void |
handleIdleEvent()
Event handlers for when in event handling mode. |
virtual void |
handleKeyboardEvent( const KeyboardEvent& event )
Event handlers for when in event handling mode. |
virtual void |
handleMouseEvent( const MouseEvent& event )
Event handlers for when in event handling mode. |
virtual void |
handleTimerEvent( const TimerEvent& event )
Event handlers for when in event handling mode. |
void |
hide()
Hide this window. |
void |
ignoreKeyRepeat( bool ignore )
Ignore repeated keystrokes sent to this window. |
bool |
isButtonDown( MouseEvent::Button b )
Tells whether a specified mouse button is down. |
bool |
isHidden()
Tell if this window is hidden or not. |
bool |
isKeyboardQueueEmpty()
Check whether there is input sitting in the Keyboard Queue. |
bool |
isKeyDown( int key )
Tells whether the specified key is down. |
bool |
isModifierDown( KeyModifiers km )
Tells whether the specified modifier was pressed during the last recorded mouse or keyboard event. |
bool |
isMouseQueueEmpty()
Check whether there is input sitting in the Mouse Queue. |
bool |
isTimerQueueEmpty()
Check whether there is input sitting in the Timer Queue. |
static std::string |
numberToString( int n )
Convert the given number to a string. |
static std::string |
numberToString( double d, int precision =-1 )
Convert the given double number to a string. |
Color |
readPixel( const int x, const int y )
Return the color at point (x, y) |
void |
reDraw()
Make the changes that you've made appear on screen. All drawing is done off screen, this will show the user the off-screen page. |
void |
resize( int newwidth, int newheight )
Changes the size of the window after creation. |
void |
setKeyboardFilter( const KeyboardEvent& filter )
Change the filter for the keyboard queue. |
void |
setMouseFilter( const MouseEvent& filter )
Change the filter for the mouse queue. |
void |
setPosition( int x, int y )
Changes the position of the window after creation. |
void |
setTimerCount( const TimerEvent& te, int count = 0 )
Changes the count for a timer. |
void |
setTimerFilter( const TimerEvent& filter )
Change the filter for the timer queue. |
void |
setTitle( const std::string& title )
Changes the title of the window after creation. |
void |
show()
Show this window. |
TimerEvent |
startTimer( int milliseconds )
Register a timer event to occur every specified interval until you stop it using stopTimer . |
void |
stopTimer( const TimerEvent& timer )
Stop a timer that was started with startTimer . |
KeyboardEvent |
waitForKeyboardEvent()
Wait for a keyboard event to occur and then return the event. |
MouseEvent |
waitForMouseEvent()
Wait for a mouse event to occur and then return the event. |
TimerEvent |
waitForTimerEvent()
Wait for a timer event to occur and then return the event. |
Constructor Detail |
public Window( const int width = 640, const int height = 480, const std::string& title = std::string("CarnegieMellonGraphics Window" ), bool fullscreen = false, int bitdepth = 32, int refreshrate = 60 );
To create a regular windowed application, construct a window as follows:
Window myWindow();
or
Window myWindow(640,480,"my window"); // the last parameter defaults to false
The fourth parameter fullscreen
should be left false.
Fullscreen mode is unlikely to work on most systems.
public Window( int xpos, int ypos, int width, int height, const std::string& title = std::string("CarnegieMellonGraphics Window" ), bool fullscreen = false, int bitdepth = 32, int refreshrate = 60 );
private Window( const Window& window );
public virtual ~Window();
Method Detail |
public void addKeyboardEvent( const KeyboardEvent& keyboard );
Note: calling this function will not set the key to be down
getKeyboardEvent
public void addMouseEvent( const MouseEvent& mouse );
Note: calling this function will not set the button to be down
getMouseEvent
public void addTimerEvent( const TimerEvent& timer );
getTimerEvent
, registerNewTimerEvent
public void autoFlushKeyboardQueue( bool enable );
isKeyDown
. It is possible that the queue will at some point contain
messages, but it will be flushed eventually.
autoFlushMouseQueue
, autoFlushTimerQueue
, flushKeyboardQueue
, getKeyboardEvent
, isKeyboardQueueEmpty
, isKeyDown
, isModifierDown
public void autoFlushMouseQueue( bool enable );
isButtonDown
. It is possible that the queue will at some point contain
messages, but it will be flushed eventually.
autoFlushKeyboardQueue
, autoFlushTimerQueue
, flushMouseQueue
, getMouseEvent
, isButtonDown
, isModifierDown
, isMouseQueueEmpty
public void autoFlushTimerQueue( bool enable );
getTimerCount
. It is possible that the queue will at some point contain
messages, but it will be flushed eventually.
autoFlushKeyboardQueue
, autoFlushMouseQueue
, flushTimerQueue
, getTimerCount
, getTimerEvent
, isTimerQueueEmpty
, registerNewTimerEvent
public void copyRegion( const int x1, const int y1, const int x2, const int y2, const int width, const int height );
public Image createImage( const int x, const int y, const int width, const int height );
public void disableAntialiasing();
public void drawArc( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end );
public void drawBezierCurve( const Style& s, const std::vector< int >& xcoords, const std::vector< int >& ycoords );
public void drawChordFilled( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end );
public void drawChordOutline( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end );
public void drawCircleFilled( const Style& s, const int x, const int y, const int radius );
public void drawCircleOutline( const Style& s, const int x, const int y, const int radius );
public void drawEllipseFilled( const Style& s, const int x1, const int y1, const int x2, const int y2 );
public void drawEllipseOutline( const Style& s, const int x1, const int y1, const int x2, const int y2 );
public void drawImage( const Image& image, const int x, const int y );
public void drawImage( const Image& image, const int x, const int y, const Transform& transform );
drawImage(constImage&,constint,constint)
, Image
public void drawLine( const Style& s, const int x1, const int y1, const int x2, const int y2 );
public void drawPixel( const Style& s, const int x, const int y );
EditableImage
.
drawPixel can be slow if you do a lot of pixel-level editing.
EditableImage
public void drawPolygonFilled( const Style& s, const std::vector< int >& xcoords, const std::vector< int >& ycoords );
public void drawPolygonOutline( const Style& s, const std::vector< int >& xcoords, const std::vector< int >& ycoords );
public void drawPolyLine( const Style& s, const std::vector< int >& xcoords, const std::vector< int >& ycoords );
public void drawRectangleFilled( const Style& s, const int x1, const int y1, const int x2, const int y2 );
public void drawRectangleOutline( const Style& s, const int x1, const int y1, const int x2, const int y2 );
public void drawText( const Style& s, const Font& f, const int x, const int y, const std::string& text );
public void drawText( const Style& s, const Font& f, const int x, const int y, const std::string& text, const Transform& transform );
public void drawTriangleFilled( const Style& s, const int x1, const int y1, const int x2, const int y2, const int x3, const int y3 );
public void drawTriangleOutline( const Style& s, const int x1, const int y1, const int x2, const int y2, const int x3, const int y3 );
public void drawWedgeFilled( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end );
public void drawWedgeOutline( const Style& s, const int x1, const int y1, const int x2, const int y2, const double start, const double end );
public void enableAntialiasing();
public void erase( Color background )();
public void flipPage();
reDraw()
reDraw
public void flushKeyboardQueue();
public void flushMouseQueue();
public void flushTimerQueue();
public int getHeight() const;
getWidth
public KeyboardEvent getKeyboardEvent();
isKeyDown
if you're interested in less precise input processing (i.e. when you're making a game).
public KeyboardEvent getKeyboardFilter();
setKeyboardFilter
public MouseEvent getMouseEvent();
isButtonDown
if you're interested in less precise input processing (i.e. when you're making a game).
flushMouseQueue
, isButtonDown
, isMouseQueueEmpty
, waitForMouseEvent
public MouseEvent getMouseFilter();
setMouseFilter
public int getMouseX() const;
getMouseEvent
, getMouseY
, isButtonDown
public int getMouseY() const;
getMouseEvent
, getMouseX
, isButtonDown
public void getPosition( int& x, int& y );
x
- [out] x position of the window
y
- [out] y position of the windowresize
, setTitle
, setPosition
public int getTimerCount( const TimerEvent& te );
@setTimerCount
, this is very good for making sure
that your program keeps a time (like maintaining a framerate).
getTimerEvent
, registerNewTimerEvent
, setTimerCount
public TimerEvent getTimerEvent();
getTimerCount
to get lower-overhead event processing.
public TimerEvent getTimerFilter();
setTimerFilter
public int getWidth() const;
getHeight
public virtual void handleIdleEvent();
WindowManager
public virtual void handleKeyboardEvent( const KeyboardEvent& event );
WindowManager
public virtual void handleMouseEvent( const MouseEvent& event );
WindowManager
public virtual void handleTimerEvent( const TimerEvent& event );
WindowManager
public void hide();
public void ignoreKeyRepeat( bool ignore );
autoFlushKeyboardQueue
, getKeyboardEvent
, isKeyDown
public bool isButtonDown( MouseEvent::Button b );
if (isButtonDown(MouseEvent::LEFT_BUTTON) && isButtonDown(MouseEvent::RIGHT_BUTTON)) // do something if both buttons are down
This is the recommended method of input if you are writing a game. If you need absolute precision, then do not use this function. There is no guarantee that if a button is pressed checking it in this fashion will ever show that it has been pressed.
This should probably be used in conjuction with autoFlushMouseQueue
.
autoFlushMouseQueue
, flushMouseQueue
, getMouseEvent
, isButtonDown
, isModifierDown
, isMouseQueueEmpty
, waitForMouseEvent
public bool isHidden();
public bool isKeyboardQueueEmpty();
flushKeyboardQueue
, getKeyboardEvent
, waitForKeyboardEvent
public bool isKeyDown( int key );
NamedKey
, like NamedKey::ESCAPE
. isKeyDown will
always return the same value for lowercase and uppercase version of the same letter.
This is because there are ways to have a key be pressed in its lowercase form and then be
raised in its uppercase form (e.g. press 'a', then press shift, then release 'a'). You can
use isModifierDown
to test if a modifier was pressed at the time that the character was.
autoFlushKeyboardQueue
, flushKeyboardQueue
, getKeyboardEvent
, ignoreKeyRepeat
, isKeyboardQueueEmpty
, isKeyDown
, isModifierDown
, waitForKeyboardEvent
public bool isModifierDown( KeyModifiers km );
isButtonDown
, isKeyDown
public bool isMouseQueueEmpty();
flushMouseQueue
, getMouseEvent
, waitForMouseEvent
public bool isTimerQueueEmpty();
public static std::string numberToString( int n );
public static std::string numberToString( double d, int precision =-1 );
d
- [in] number to convert to string
precision
- [in, optional] number of digits of precision (numbers after decimal point)drawText(constStyle&,constFont&,constint,constint,conststring&,constTransform&)
, drawText(constStyle&,constFont&,constint,constint,conststring&,constTransform&)
, numberToString(int)
public Color readPixel( const int x, const int y );
public void reDraw();
public void resize( int newwidth, int newheight );
getPosition
, setPosition
, setTitle
public void setKeyboardFilter( const KeyboardEvent& filter );
getKeyboardFilter
public void setMouseFilter( const MouseEvent& filter );
getMouseFilter
public void setPosition( int x, int y );
getPosition
, resize
, setTitle
public void setTimerCount( const TimerEvent& te, int count = 0 );
getTimerCount
, getTimerEvent
, registerNewTimerEvent
public void setTimerFilter( const TimerEvent& filter );
getTimerFilter
public void setTitle( const std::string& title );
getPosition
, setPosition
, resize
public void show();
public TimerEvent startTimer( int milliseconds );
stopTimer
.
getTimerCount
, getTimerEvent
, isTimerQueueEmpty
, setTimerCount
, stopTimer
public void stopTimer( const TimerEvent& timer );
startTimer
.
getTimerCount
, getTimerEvent
, isTimerQueueEmpty
, setTimerCount
, startTimer
public KeyboardEvent waitForKeyboardEvent();
public MouseEvent waitForMouseEvent();
flushMouseQueue
, getMouseEvent
, isButtonDown
, isMouseQueueEmpty
public TimerEvent waitForTimerEvent();
|
CarnegieMellonGraphics | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |