A drawing area widget. This class provides general purpose
drawing functions and generates events for low-level windowing
system events. It also provides functions to draw and measure
text in various fonts. The top-left origin coordinate is (0, 0).
Important note: Drawing functions
can only be called from within the Paint() event handler!
Calling drawing functions from outside this method will result in
undefined behavior. Furthermore, changing the font, color, or
line style outside of the Paint method may work in some contexts, but
not others. To force the Canvas to generated a paint event,
call the redraw() method.
Paint | The canvas needs to be repainted. |
Resize | The canvas was resized. |
MouseMove | The mouse moved without a button being pressed. |
MouseDrag | The mouse moved while a button was being held down. |
MousePress | A mouse button was pressed. |
MouseRelease | A mouse button was released. |
KeyDown | A key was pressed. |
KeyUp | A key was released. |
MouseEnter | The mouse cursor entered the canvas area. |
MouseLeave | The mouse cursor left the canvas area. |
GotFocus | The canvas received the input focus. |
LostFocus | The canvas lost the input focus. |
Method Summary: | ||
Canvas::Canvas | (); | |
void | Canvas::setState | (int pState); |
int | Canvas::getState | (); |
void | Canvas::setColor | (const Color& pColor); |
void | Canvas::setColor | (const String& pName); |
void | Canvas::setColor | (unsigned char r, unsigned char g, unsigned char b); |
void | Canvas::setFont | (Font pFont, FontStyle pStyle, int pSize); |
void | Canvas::setDrawMode | (DrawMode pMode); |
void | Canvas::setLineStyle | (LineStyle pStyle, int (=0) pWidget); |
void | Canvas::pushClip | (int pX, int pY, int pWidth, int pHeight); |
void | Canvas::popClip | (); |
void | Canvas::drawPoint | (int pX, int pY); |
void | Canvas::drawLine | (int pX1, int pY1, int pX2, int pY2); |
void | Canvas::drawRect | (int pX, int pY, int pWidth, int pHeight); |
void | Canvas::fillRect | (int pX, int pY, int pWidth, int pHeight); |
void | Canvas::drawArc | (int pX, int pY, int pWidth, int pHeight, double pAngle1, double pAngle2); |
void | Canvas::fillArc | (int pX, int pY, int pWidth, int pHeight, double pAngle1, double pAngle2); |
bool | Canvas::drawXpm | (char** pData, int pX, int pY); |
Size | Canvas::getXpmSize | (char** pData); |
void | Canvas::drawImage | (unsigned char* pData, int pX, int pY, int pWidth, int pHeight, int(=3) pDepth); |
void | Canvas::drawMonoImage | (unsigned char* pData, int pX, int pY, int pWidth, int pHeight); |
void | Canvas::drawString | (int pX, int pY, const String& pStr); |
void | Canvas::drawText | (int pX, int pY, const char* pStr, int pLen); |
void | Canvas::getTextExtent | (int& pWidth, int& pHeight); |
int | Canvas::getStringWidth | (const String& pStr); |
int | Canvas::getTextWidth | (const char* pStr, int pLen); |
int | Canvas::getFontHeight | (); |
int | Canvas::getFontDescent | (); |
Canvas::Canvas |
Canvas::Canvas(); Creates a new drawing canvas. |
void Canvas::setState | ||||||
void Canvas::setState(int pState); Sets a internal flag to indicate what should be redrawn. For example, a mouse drag might set the state to '1', and call redraw(). Then the redraw method queries the state, and if it is '1', only draws what is necessary to respond to the mouse drag event. Any integer values can be used. The Canvas class itself does not query this value. | ||||||
|
int Canvas::getState |
int Canvas::getState(); Returns the internal state variable. See setState() for more information. |
void Canvas::setColor | ||||||
void Canvas::setColor(const Color& pColor); Changes the current drawing color. | ||||||
|
void Canvas::setColor | ||||||
void Canvas::setColor(const String& pName); Changes the current drawing color. | ||||||
|
void Canvas::setColor | ||||||||||||
void Canvas::setColor(unsigned char r, unsigned char g, unsigned char b); Changes the current drawing color. | ||||||||||||
|
void Canvas::setFont | ||||||||||||
void Canvas::setFont(Font pFont, FontStyle pStyle, int pSize); Changes the current text drawing font. | ||||||||||||
|
void Canvas::setDrawMode | ||||||
void Canvas::setDrawMode(DrawMode pMode); Changes the way pixels are copied to the screen. STANDARD mode will simply copy the new pixel value over the existing one, while INVERT and XOR identify a logical function indicated how the new pixel value will be combined with the old one. | ||||||
|
void Canvas::setLineStyle | |||||||||
void Canvas::setLineStyle(LineStyle pStyle, int (=0) pWidget); Changes the current line style. | |||||||||
|
void Canvas::pushClip | |||||||||||||||
void Canvas::pushClip(int pX, int pY, int pWidth, int pHeight); Sets the current clipping region. This limits all drawing to the specified region. Anything drawn outside the region will not actually be drawn. Every call to pushClip() must be accompanied by a call to popClip(), or undefined behavior will result. | |||||||||||||||
|
void Canvas::popClip |
void Canvas::popClip(); Restores the previous clipping region state. |
void Canvas::drawPoint | |||||||||
void Canvas::drawPoint(int pX, int pY); Draws a 1 pixel by 1 pixel point on the canvas with the current color. | |||||||||
|
void Canvas::drawLine | |||||||||||||||
void Canvas::drawLine(int pX1, int pY1, int pX2, int pY2); Draws a line in the current style and color between the two points indicated. | |||||||||||||||
|
void Canvas::drawRect | |||||||||||||||
void Canvas::drawRect(int pX, int pY, int pWidth, int pHeight); Draws a 1-pixel wide rectangle within the given bounding box. | |||||||||||||||
|
void Canvas::fillRect | |||||||||||||||
void Canvas::fillRect(int pX, int pY, int pWidth, int pHeight); Fills the specified rectangular region with the current color. | |||||||||||||||
|
void Canvas::drawArc | |||||||||||||||||||||
void Canvas::drawArc(int pX, int pY, int pWidth, int pHeight, double pAngle1, double pAngle2); Draw an elliptical outline within the specified bounding box. | |||||||||||||||||||||
|
void Canvas::fillArc | |||||||||||||||||||||
void Canvas::fillArc(int pX, int pY, int pWidth, int pHeight, double pAngle1, double pAngle2); Fill an elliptical area specified by bounding box with the current color. | |||||||||||||||||||||
|
bool Canvas::drawXpm | ||||||||||||
bool Canvas::drawXpm(char** pData, int pX, int pY); Draws XPM image data with the top-left corner at the given position. The image is dithered on 8-bit displays. The current canvas color is used for transparent colors. Returns: Returns false if there was an error decoding the XPM data. Otherwise, returns true. | ||||||||||||
|
Size Canvas::getXpmSize | ||||||
Size Canvas::getXpmSize(char** pData); Returns the size of an XPM image. Returns: Returns a size of (-1,-1) if there were errors decoding the image. | ||||||
|
void Canvas::drawImage | |||||||||||||||||||||
void Canvas::drawImage(unsigned char* pData, int pX, int pY, int pWidth, int pHeight, int(=3) pDepth); Draws a 8-bit per color RGB image directly onto the canvas. Color data must be in RGB order. X, Y are where to put the top-left pixel. | |||||||||||||||||||||
|
void Canvas::drawMonoImage | ||||||||||||||||||
void Canvas::drawMonoImage(unsigned char* pData, int pX, int pY, int pWidth, int pHeight); Draws a 8-bit grayscale image directly onto the canvas. X, Y are where to put the top-left pixel. | ||||||||||||||||||
|
void Canvas::drawString | ||||||||||||
void Canvas::drawString(int pX, int pY, const String& pStr); Draws text on the canvas in the current font and style. | ||||||||||||
|
void Canvas::drawText | |||||||||||||||
void Canvas::drawText(int pX, int pY, const char* pStr, int pLen); Draws text on the canvas in the current font and style. | |||||||||||||||
|
void Canvas::getTextExtent | |||||||||
void Canvas::getTextExtent(int& pWidth, int& pHeight); Measure the size of some text in the current font. | |||||||||
|
int Canvas::getStringWidth | ||||||
int Canvas::getStringWidth(const String& pStr); Returns the width of the string in the current font. | ||||||
|
int Canvas::getTextWidth | |||||||||
int Canvas::getTextWidth(const char* pStr, int pLen); Returns the width of the text in the current font. | |||||||||
|
int Canvas::getFontHeight |
int Canvas::getFontHeight(); Returns the height of the current font from the baseline. |
int Canvas::getFontDescent |
int Canvas::getFontDescent(); Returns the number of pixels the font descends below the baseline. |