29#ifndef PT_GFX_CANVAS_H
30#define PT_GFX_CANVAS_H
32#include <Pt/Gfx/Api.h>
33#include <Pt/Gfx/Size.h>
34#include <Pt/Gfx/Point.h>
35#include <Pt/Gfx/Rect.h>
36#include <Pt/Gfx/Scaling.h>
37#include <Pt/Gfx/Pen.h>
38#include <Pt/Gfx/Brush.h>
39#include <Pt/Gfx/Font.h>
40#include <Pt/Gfx/CompositionMode.h>
41#include <Pt/Gfx/FontMetrics.h>
42#include <Pt/Gfx/TextMetrics.h>
43#include <Pt/Gfx/Transform.h>
44#include <Pt/Gfx/Path.h>
65class PT_GFX_API Canvas
67 friend class PaintSurface;
72 enum DirtyFlags :
unsigned
74 DirtyTransform = 0x01,
75 DirtyComposition = 0x02,
165 void drawLine(
const PointF& from,
const PointF& to);
185 void drawEllipse(
const Gfx::PointF& topLeft,
const Gfx::SizeF& size);
189 void fillEllipse(
const Gfx::PointF& topLeft,
const Gfx::SizeF& size);
230 const Gfx::Image& image,
231 const Gfx::RectF* rect = 0);
237 const Gfx::RectF* rect = 0);
240 virtual void onBeginPaint(
const Gfx::Paint& paint) = 0;
242 virtual void onFinishPaint() = 0;
247 virtual void onApplyTransform() = 0;
251 virtual void onApplyCompositionMode() = 0;
253 virtual void onSetPen(
const Pen& pen) = 0;
255 virtual void onApplyPen() = 0;
257 virtual void onSetBrush(
const Brush& pen) = 0;
259 virtual void onApplyBrush() = 0;
261 virtual void onSetFont(
const Gfx::Font& font) = 0;
263 virtual void onApplyFont() = 0;
265 virtual void onSetClip(
const Gfx::RectF* clip) = 0;
267 virtual void onApplyClip() = 0;
270 void invalidate(
unsigned flags);
273 virtual void onDrawLine(
const PointF& from,
const PointF& to) = 0;
275 virtual void onDrawPolyline(
const Gfx::PointF* pts,
const size_t n) = 0;
277 virtual void onFillPolygon(
const Gfx::PointF* ps,
const size_t n) = 0;
279 virtual void onDrawRect(
const Gfx::RectF& rectangle) = 0;
281 virtual void onFillRect(
const Gfx::RectF& rectangle) = 0;
283 virtual void onDrawEllipse(
const Gfx::PointF& topLeft,
const Gfx::SizeF& size) = 0;
285 virtual void onFillEllipse(
const Gfx::PointF& topLeft,
const Gfx::SizeF& size) = 0;
288 virtual void onSetPath(
const Path& path) = 0;
290 virtual void onDrawPath() = 0;
292 virtual void onFillPath() = 0;
294 virtual void onDrawPath(
const Path& path) = 0;
296 virtual void onFillPath(
const Path& path) = 0;
303 virtual void onDrawText(
const Gfx::PointF& to,
308 virtual void onDrawImage(
const Gfx::PointF& to,
309 const Gfx::Image& image,
310 const Gfx::RectF* rect = 0) = 0;
316 void attachSurface(PaintSurface& surface);
318 void detachSurface(PaintSurface& surface);
320 void updateTransform();
323 PaintSurface* _surface;
324 PaintSurface* _active;
Off-screen image that can be painted.
Definition Bitmap.h:71
Fill color, gradient or texture.
Definition Brush.h:151
void drawPolyline(const Gfx::PointF *ps, const size_t n)
Draws a connected sequence of line segments.
void setClip(const RectF &clip)
Sets the clip rectangle.
void drawPath(const Path &path)
Draws the given path.
bool isActive() const
Returns true if painting is currently active.
void beginPaint(const Gfx::Paint &paint)
Begins painting with the given paint state.
virtual ~Canvas()
Destroys the canvas.
void setPath(const Path &path)
Sets the current path.
void drawImage(const Gfx::PointF &to, const Gfx::Image &image, const Gfx::RectF *rect=0)
Draws an image.
void resetTransform()
Resets the transform to the identity matrix.
void setTransform(const Gfx::Transform &tx)
Sets the current transform.
const RectF & region() const
Returns the current paint region.
const PointF & origin() const
Returns the logical origin of the current region.
const Gfx::Transform & transform() const
Returns the current transform.
void finishPaint()
Ends the current painting operation.
void drawBitmap(const Gfx::PointF &to, const Gfx::Bitmap &bitmap, const Gfx::RectF *rect=0)
Draws a bitmap.
void drawLine(const PointF &from, const PointF &to)
Draws a line between two points.
void setBrush(const Brush &brush)
Sets the current brush.
void setRegion(const RectF &r)
Sets the paint region.
const FontMetrics & fontMetrics() const
Returns metrics for the current font.
const Gfx::ImageFormat & format() const
Returns the pixel format of the target.
const Scaling & scaling() const
Returns the logical-to-physical scaling.
void resetClip()
Clears the clip rectangle.
void fillPath(const Path &path)
Fills the given path.
void setScaling(const Scaling &scaling)
Sets the logical-to-physical scaling.
void fillRect(const Gfx::RectF &rectangle)
Fills a rectangle.
void setPen(const Pen &pen)
Sets the current pen.
void setFont(const Gfx::Font &font)
Sets the current font.
void drawRect(const Gfx::RectF &rectangle)
Draws the outline of a rectangle.
void drawText(const PointF &to, const Pt::String &text, const Transform *tform=0)
Draws a line of text.
void drawPath()
Draws the current path.
void fillPolygon(const Gfx::PointF *ps, const size_t n)
Fills a polygon.
void drawEllipse(const Gfx::PointF &topLeft, const Gfx::SizeF &size)
Draws the outline of an ellipse.
TextMetrics textMetrics(const Pt::String &text) const
Measures a line of text.
void fillEllipse(const Gfx::PointF &topLeft, const Gfx::SizeF &size)
Fills an ellipse.
void setCompositionMode(const Gfx::CompositionMode &mode)
Sets the current composition mode.
void fillPath()
Fills the current path.
How new pixels combine with existing pixels.
Definition CompositionMode.h:49
Ascent, descent and line height of a font.
Definition FontMetrics.h:50
Font family, size and style.
Definition Font.h:63
Pen, brush, font and composition mode.
Definition Paint.h:53
Sequence of lines and curves.
Definition Path.h:81
Outline color, width and style.
Definition Pen.h:59
Conversion between logical units and pixels.
Definition Scaling.h:52
Width and bounds of a text run.
Definition TextMetrics.h:49
Unicode capable basic_string.
Definition Api-String.h:67
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33