|
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.
Window.
If you're working on a game, you will probably be interested in investigating
the following functions: disableAutoPageFlip, flipPage, isKeyDown,
isButtonDown, isModifierDown, and Window (fullscreen mode).
| 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 |
disableAutoPageFlip()
By default each window will handle refreshing the graphics automatically for the user. |
void |
disableFullScreen()
Deprecated. Do not use. This works only on some systems. To ensure that you will always go into fullscreen mode, use the constructor Window. |
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 |
enableAutoPageFlip()
Enabled by default; everything you draw will automatically appear on screen. |
void |
enableFullScreen( int bitdepth = 16, int refreshrate = 60 )
Deprecated. Do not use. This works only on some systems. To ensure that you will always go into fullscreen mode, use the constructor Window. |
void |
flipPage()
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 |
isAutoPageFlipEnabled()
Will return whether or not auto page flipping is enabled. |
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) |
TimerEvent |
registerNewTimerEvent( const int milliseconds )
Deprecated. This has unnecessary overhead. Use startTimer instead. |
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 );
This is the appropriate way to go into full screen mode. 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
To create a fullscreen window, pass true as the fourth parameter:
Window myFullScreenWindow(640,480,"my full screen window",true);If the dimensions of the window are not a standard dimension or one that is not supported by your video card, the window will probably not be constructed and no error will be reported. Dimensions such as 320x200, 320x240, 400x300, 640x480, 800x600, 1024x768, etc. are recommended for full screen mode.
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
getKeyboardEventpublic void addMouseEvent( const MouseEvent& mouse );
Note: calling this function will not set the button to be down
getMouseEventpublic void addTimerEvent( const TimerEvent& timer );
getTimerEvent, registerNewTimerEventpublic 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, isModifierDownpublic 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, isMouseQueueEmptypublic 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, registerNewTimerEventpublic 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 );
Image, drawImagepublic void disableAntialiasing();
public void disableAutoPageFlip();
disableAutoPageFlip
to disable automatic refreshes and then flipPage whenever you want to
show what you've drawn. enableAutoPageFlip may then be used to enable automatic refreshes.
enableAutoPageFlip, flipPage, isAutoPageFlipEnabledpublic void disableFullScreen();
Window.
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 );
drawImage(constImage&,constint,constint,constTransform&), Imagepublic void drawImage( const Image& image, const int x, const int y, const Transform& transform );
drawImage(constImage&,constint,constint), Imagepublic 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.
EditableImagepublic 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 );
drawText(constStyle&,constFont&,constint,constint,conststring&,constTransform&), numberToString(int), numberToString(double)public void drawText( const Style& s, const Font& f, const int x, const int y, const std::string& text, const Transform& transform );
drawText(constStyle&,constFont&,constint,constint,conststring&,constTransform&), numberToString(int), numberToString(double)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 enableAutoPageFlip();
flipPage and disableAutoPageFlip.
disableAutoPageFlip, flipPage, isAutoPageFlipEnabledpublic void enableFullScreen( int bitdepth = 16, int refreshrate = 60 );
Window.
public void flipPage();
disableAutoPageFlip, enableAutoPageFlip, isAutoPageFlipEnabledpublic void flushKeyboardQueue();
autoFlushKeyboardQueue, getKeyboardEvent, isKeyboardQueueEmpty, isKeyDown, waitForKeyboardEventpublic void flushMouseQueue();
autoFlushMouseQueue, getMouseEvent, isButtonDown, isMouseQueueEmpty, waitForMouseEventpublic void flushTimerQueue();
autoFlushTimerQueue, getTimerCount, getTimerEvent, isTimerQueueEmpty, registerNewTimerEvent, waitForTimerEventpublic int getHeight() const;
getWidthpublic KeyboardEvent getKeyboardEvent();
isKeyDown if you're interested in less precise input processing (i.e. when you're making a game).
flushKeyboardQueue, ignoreKeyRepeat, isKeyboardQueueEmpty, isKeyDown, waitForKeyboardEventpublic KeyboardEvent getKeyboardFilter();
setKeyboardFilterpublic MouseEvent getMouseEvent();
isButtonDown if you're interested in less precise input processing (i.e. when you're making a game).
flushMouseQueue, isButtonDown, isMouseQueueEmpty, waitForMouseEventpublic MouseEvent getMouseFilter();
setMouseFilterpublic int getMouseX() const;
getMouseEvent, getMouseY, isButtonDownpublic int getMouseY() const;
getMouseEvent, getMouseX, isButtonDownpublic void getPosition( int& x, int& y );
x - [out] x position of the window
y - [out] y position of the windowresize, setTitle, setPositionpublic 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, setTimerCountpublic TimerEvent getTimerEvent();
getTimerCount to get lower-overhead event processing.
flushTimerEvent, isTimerQueueEmpty, waitForTimerEvent, registerNewTimerEventpublic TimerEvent getTimerFilter();
setTimerFilterpublic int getWidth() const;
getHeightpublic virtual void handleIdleEvent();
WindowManagerpublic virtual void handleKeyboardEvent( const KeyboardEvent& event );
WindowManagerpublic virtual void handleMouseEvent( const MouseEvent& event );
WindowManagerpublic virtual void handleTimerEvent( const TimerEvent& event );
WindowManagerpublic void hide();
isHidden, showpublic void ignoreKeyRepeat( bool ignore );
autoFlushKeyboardQueue, getKeyboardEvent, isKeyDownpublic bool isAutoPageFlipEnabled();
disableAutoPageFlip, enableAutoPageFlip, flipPagepublic 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, waitForMouseEventpublic bool isHidden();
hide, showpublic bool isKeyboardQueueEmpty();
flushKeyboardQueue, getKeyboardEvent, waitForKeyboardEventpublic 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, waitForKeyboardEventpublic bool isModifierDown( KeyModifiers km );
isButtonDown, isKeyDownpublic bool isMouseQueueEmpty();
flushMouseQueue, getMouseEvent, waitForMouseEventpublic bool isTimerQueueEmpty();
flushTimerQueue, getTimerEvent, waitForTimerEvent, registerNewTimerEventpublic static std::string numberToString( int n );
drawText(constStyle&,constFont&,constint,constint,conststring&,constTransform&), drawText(constStyle&,constFont&,constint,constint,conststring&,constTransform&), int)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 TimerEvent registerNewTimerEvent( const int milliseconds );
startTimer instead.
Register a timer event to occur after the specified number of milliseconds. Only causes the timer to go off once. If you want repeated occurrences, you must re-register when you recieve the event.
getTimerCount, getTimerEvent, setTimerCount, startTimer, stopTimerpublic void resize( int newwidth, int newheight );
getPosition, setPosition, setTitlepublic void setKeyboardFilter( const KeyboardEvent& filter );
getKeyboardFilterpublic void setMouseFilter( const MouseEvent& filter );
getMouseFilterpublic void setPosition( int x, int y );
getPosition, resize, setTitlepublic void setTimerCount( const TimerEvent& te, int count = 0 );
getTimerCount, getTimerEvent, registerNewTimerEventpublic void setTimerFilter( const TimerEvent& filter );
getTimerFilterpublic void setTitle( const std::string& title );
getPosition, setPosition, resizepublic void show();
hide, isHiddenpublic TimerEvent startTimer( int milliseconds );
stopTimer.
getTimerCount, getTimerEvent, isTimerQueueEmpty, setTimerCount, stopTimerpublic void stopTimer( const TimerEvent& timer );
startTimer.
getTimerCount, getTimerEvent, isTimerQueueEmpty, setTimerCount, startTimerpublic KeyboardEvent waitForKeyboardEvent();
flushKeyboardQueue, getKeyboardEvent, ignoreKeyRepeat, isKeyboardQueueEmpty, isKeyDownpublic MouseEvent waitForMouseEvent();
flushMouseQueue, getMouseEvent, isButtonDown, isMouseQueueEmptypublic TimerEvent waitForTimerEvent();
flushTimerQueue, getTimerCount, getTimerEvent, registerNewTimerEvent, isTimerQueueEmpty
|
CarnegieMellonGraphics | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||