|
3 | 3 | namespace canvas {
|
4 | 4 | Canvas::Canvas(int width, int height)
|
5 | 5 | {
|
6 |
| - surface = SkSurface::MakeRasterN32Premul(width, height); |
| 6 | + this->surface = SkSurface::MakeRasterN32Premul(width, height); |
7 | 7 | //canvas = std::make_unique<SkCanvas>(surface->getCanvas());
|
8 | 8 | }
|
9 | 9 |
|
10 |
| - Canvas::~Canvas() |
| 10 | + Canvas Canvas::clone() |
11 | 11 | {
|
| 12 | + int width = this->get_width(); |
| 13 | + int height = this->get_height(); |
| 14 | + Canvas canvas = Canvas(width, width); |
| 15 | + canvas.draw_image(this->snapshot(), SkRect::MakeLTRB(0, 0, width, height)); |
| 16 | + return canvas; |
| 17 | + } |
12 | 18 |
|
| 19 | + Canvas::~Canvas() |
| 20 | + { |
13 | 21 | }
|
14 | 22 |
|
15 |
| - void Canvas::drawImage(Image image, SkRect dstRect) |
| 23 | + void Canvas::draw_image(Image image, SkRect dstRect) |
16 | 24 | {
|
17 | 25 | surface->getCanvas()->drawImageRect(image.getImage(), dstRect, SkSamplingOptions());
|
18 | 26 | }
|
19 | 27 |
|
| 28 | + Canvas Canvas::crop(const SkRect& cropRect) |
| 29 | + { |
| 30 | + Canvas croppedCanvas = Canvas(cropRect.fRight - cropRect.fLeft, cropRect.fTop - cropRect.fBottom); |
| 31 | + croppedCanvas.draw_image(this->surface->makeImageSnapshot(), cropRect); |
| 32 | + return croppedCanvas; |
| 33 | + } |
| 34 | + |
| 35 | + Canvas Canvas::stretch(const SkPoint& stretchVector) |
| 36 | + { |
| 37 | + Canvas stretchedCanvas = Canvas(stretchVector.fX, stretchVector.fY); |
| 38 | + stretchedCanvas.draw_image(this->surface->makeImageSnapshot(), SkRect::MakeXYWH(0, 0, stretchVector.fX, stretchVector.fY)); |
| 39 | + return stretchedCanvas; |
| 40 | + } |
| 41 | + |
| 42 | + sk_sp<SkImage> Canvas::snapshot() |
| 43 | + { |
| 44 | + return this->surface->makeImageSnapshot(); |
| 45 | + } |
| 46 | + |
20 | 47 | void Canvas::clear()
|
21 | 48 | {
|
22 | 49 | surface->getCanvas()->clear(SK_ColorTRANSPARENT);
|
|
0 commit comments