MQCanvas class

(new in Rev4.02)

MQCanvas class is contained in MQWidgetPaintParam structure on an painting event. A drawing to the screen is performed by this class.

Class
MQCanvas Constructor
~MQCanvas Destructor
Member functions
SetColor Set a color
SetGradientColor Set a gradation color
SetStrokeWidth Set a stroke width
SetStrokeCap Set a stroke cap
SetStrokeJoin Set a stroke join
SetStrokeMiterLimit Set a miter limit
SetStrokeDash Set a dash line
SetFont Set a font
SetFontSize Set a font size
SetFontRateSize Set a font rate size
SetAntiAlias Set an anti-alias
PushClipRect Set a clipping rectangle
PopClipRect Restore a clipping rectangle
Clear Fill the whole canvas
DrawLine Draw a line
DrawPolyline Draw a polyline
DrawCircle Draw a circle
FillCircle Fill a circle
DrawEllipse Draw an ellipse
FillEllipse Fill an ellipse
DrawRect Draw a rectangle
FillRect Fill a rectangle
DrawRoundRect Draw a round rectangle
FillRoundRect Fill a round rectangle
DrawPolygon Draw a polygon
FillPolygon Fill a polygon
DrawDIB Draw a bitmap
DrawText Draw a text
MeasureText Calculate a drawing size for a text

MQCanvas::MQCanvas(void *ptr);

MQCanvas::MQCanvas(int x1, int y1, int x2, int y2);

ptr
A widget ID created outside the plug-in
x1
X coordinate on the left top
y1
Y coordinate on the left top
x2
Width
y2
Height

It is a constructor.

It is not necessary to call this method immediately. A class created automatically in SDK is provided to a plug-in.

(new in Rev4.60)

x1,y1,x2,y2 are parameters for an offscreen canvas.


MQCanvas::~MQCanvas();

This method is a destructor.


void MQCanvas::GetBitmap(unsigned char*& buffer, size_t& row_bytes);

buffer
A bitmap buffer
row_bytes
Bytes per row

(new in Rev4.60)

It returns a bitmap buffer for an offscreen canvas.


void MQCanvas::GetCanvasRect(int& x, int& y, int& width, int& height);

x
X coordinate on the left top
y
Y coordinate on the left top
width
Width
height
Height

(new in Rev4.60)

It returns a rectangle of a canvas.


void MQCanvas::SetColor(int r, int g, int b, int a);

void MQCanvas::SetColor(const MQCanvasColor& col)

r
Red (0 to 255)
g
Green (0 to 255)
b
Blue (0 to 255)
a
Opacity (0 to 255)

It specifies a color used in each drawing function.


void MQCanvas::SetGradientColor(int x1, int y1, int x2, int y2, const std::vector& colors, const std::vector& segments);

void MQCanvas::SetGradientColor(float x1, float y1, float x2, float y2, const std::vector& colors, const std::vector& segments);

x1
X coordinate of a start point
y1
Y coordinate of a start point
x2
X coordinate of an end point
y2
Y coordinate of an end point
colors
Colors
segments
Positions from the begin point to the end point (from 0 to 1)

It specifies a gradation color transferring between the begin point and the end point.

A gradation color is canceled by calling SetColor().


void MQCanvas::SetStrokeWidth(float width);

width
A line width

It specifies a width for drawing a line.


void MQCanvas::SetStrokeCap(MQCANVAS_CAP_TYPE cap);

cap
A method of drawing a line cap
[MQCanvas::CAP_BUTT] Butt
[MQCanvas::CAP_ROUND] Round
[MQCanvas::CAP_SQUARE] Square

It specifies a method of drawing a line cap.


void MQCanvas::SetStrokeJoin(MQCANVAS_JOIN_TYPE join);

join
A method of drawing a line joint
[MQCanvas::JOIN_MITER] Miter
[MQCanvas::JOIN_ROUND] Round
[MQCanvas::JOIN_BEVEL] Bevel

It specifies a method of drawing a line joint.


void MQCanvas::SetStrokeMiterLimit(float limit);

limit
A miter limit

It specifies a miter limit.


void MQCanvas::SetStrokeDash(const std::vector& intervals);

intervals
Intervals of dashes

It specifies a length and an interval for a dash line.

Please specify an empty array when you want to finish drawing a dash line.


void MQCanvas::SetFont(const wchar_t *fontname, bool bold);

fontname
A font name
bold
Bold

It specifies a font for drawing a text.

The font name must exist in the system, and the font must correspond to the drawing character code.


void MQCanvas::SetFontSize(int size);

size
A font size

It specifies a font size.


void MQCanvas::SetFontRateSize(float rate);

rate
A rate for a font size

It specifies a font size by the ratio of the default font.


void MQCanvas::SetAntiAlias(bool val);

val
Anti-alias

It specifies whether an anti-alias is enabled or disabled.


void MQCanvas::PushClipRect(int x, int y, int w, int h);

x
X coodinate of a left-top point
y
Y coodinate of a left-top point
w
Width
h
Height

It specifies a clipping rectangle.

It is necessary to call PopClipRect() after drawing. When PushClipRect() was called several times, PopClipRect() must be call same times.


void MQCanvas::PopClipRect();

It restores a clipping rectangle set by PushClipRect()/


void MQCanvas::Clear(int r, int g, int b, int a);

void MQCanvas::Clear(const MQCanvasColor& col);

r
Red (0 to 255)
g
Green (0 to 255)
b
Blue (0 to 255)
a
Opacity (0 to 255)

It fills the whole canvas with the speicifed color.


void MQCanvas::DrawLine(int x1, int y1, int x2, int y2);

void MQCanvas::DrawLine(float x1, float y1, float x2, float y2);

x1
X coordinate of a start point
y1
Y coordinate of a start point
x2
X coordinate of an end point
y2
Y coordinate of an end point

It draws a line between specified two points.


void MQCanvas::DrawPolyline(POINT *points, int num_points);

void MQCanvas::DrawPolyline(MQCanvasPoint *points, int num_points);

points
An array of points
num_points
A number of points

It draws a polyline.


void MQCanvas::DrawCircle(int x, int y, float r);

void MQCanvas::DrawCircle(float x, float y, float r);

x
X coordinate of a center
y
Y coordinate of a center
r
A radius

It draws a circle.


void MQCanvas::FillCircle(int x, int y, float r);

void MQCanvas::FillCircle(float x, float y, float r);

x
X coordinate of a center
y
Y coordinate of a center
r
A radius

It fills in a circle.


void MQCanvas::DrawEllipse(int x, int y, float rx, float ry);

void MQCanvas::DrawEllipse(float x, float y, float rx, float ry);

x
X coordinate of a center
y
Y coordinate of a center
rx
A horizontal radius
ry
A vertical radius

It draws a circle.


void MQCanvas::FillEllipse(int x, int y, float rx, float ry);

void MQCanvas::FillEllipse(float x, float y, float rx, float ry);

x
X coordinate of a center
y
Y coordinate of a center
rx
A horizontal radius
ry
A vertical radius

It fills in an ellipse.


void MQCanvas::DrawRect(int x, int y, int w, int h);

void MQCanvas::DrawRect(float x, float y, float w, float h);

x
X coodinate of a left-top point
y
Y coodinate of a left-top point
w
Width
h
Height

It draws a rectangle.


void MQCanvas::FillRect(int x, int y, int w, int h);

void MQCanvas::FillRect(float x, float y, float w, float h);

x
X coodinate of a left-top point
y
Y coodinate of a left-top point
w
Width
h
Height

It fills in a rectangle.


void MQCanvas::DrawRoundRect(int x, int y, int w, int h, int rx, int ry);

void MQCanvas::DrawRoundRect(float x, float y, float w, float h, float rx, float ry);

x
X coodinate of a left-top point
y
Y coodinate of a left-top point
w
Width
h
Height
rx
A horizontal radius for a corner round
ry
A vertical radius for a corner round

It draws a rectangle with a corner round.


void MQCanvas::FillRoundRect(int x, int y, int w, int h, int rx, int ry);

void MQCanvas::FillRoundRect(float x, float y, float w, float h, float rx, float ry);

x
X coodinate of a left-top point
y
Y coodinate of a left-top point
w
Width
h
Height
rx
A horizontal radius for a corner round
ry
A vertical radius for a corner round

It fills in a rectangle with a corner round.


void MQCanvas::DrawPolygon(POINT *points, int num_points);

void MQCanvas::DrawPolygon(MQCanvasPoint *points, int num_points);

points
An array of points
num_points
A number of points

It draws a polygon.


void MQCanvas::FillPolygon(POINT *points, int num_points);

void MQCanvas::FillPolygon(MQCanvasPoint *points, int num_points);

points
An array of points
num_points
A number of points

It fills in a polygon.


void MQCanvas::DrawDIB(void *header, void *buffer, int x, int y);

void MQCanvas::DrawDIB(void *header, void *buffer, int x, int y, int w, int h);

header
DIB header
buffer
DIB image buffer
x
X coodinate of a left-top point of a target
y
Y coodinate of a left-top point of a target
w
A width of a target
h
A height of a target

It draws a DIB (Device Independent Bitmap) at the specified position.

header contains BITMAPINFOHEADER structure, and RGBQUAD arrays (in 8bit or less image)

buffer contains an image data.


void MQCanvas::DrawSVG(MQSVGDraw *svg, int x, int y, int w, int h);

svg
SVG data
x
X coodinate of a left-top point of a target
y
Y coodinate of a left-top point of a target
w
A width of a target
h
A height of a target

(new in Rev4.60)

指定した位置にSVGを描画します。


void MQCanvas::DrawText(const wchar_t *str, int x, int y, int w, int h, bool horz_center, bool vert_center = true);

str
A text
x
X coodinate of a left-top point of a target
y
Y coodinate of a left-top point of a target
w
A width of a target
h
A height of a target
horz_center
Horizontal centering
vert_center
Vertical centering

It draws a string in the speicified area.


POINT MQCanvas::MeasureText(const wchar_t *str);

str
A text
Return value
A drawing size

It calculates a drawing size for the specified text.