Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
canvaspainter.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2012-2020 Matthew Chiawen Chang
5
6This program is free software; you can redistribute it and/or
7modify it under the terms of the GNU General Public License
8as published by the Free Software Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15*/
16
17#ifndef CANVASPAINTER_H
18#define CANVASPAINTER_H
19
20#include <memory>
21#include <QCoreApplication>
22#include <QObject>
23#include <QTransform>
24#include <QPainter>
25#include "log.h"
26#include "pencildef.h"
27
28#include "layer.h"
29
30#include "onionskinpainteroptions.h"
31#include "onionskinsubpainter.h"
32
33
34class TiledBuffer;
35class Object;
36class BitmapImage;
37class ViewManager;
38
39struct CanvasPainterOptions
40{
41 bool bAntiAlias = false;
42 bool bThinLines = false;
43 bool bOutlines = false;
44
45 LayerVisibility eLayerVisibility = LayerVisibility::RELATED;
46 float fLayerVisibilityThreshold = 0.f;
47 bool bOnionSkinMultiLayer = false;
48 float scaling = 1.0f;
49 QPainter::CompositionMode cmBufferBlendMode = QPainter::CompositionMode_SourceOver;
50 OnionSkinPainterOptions mOnionSkinOptions;
51};
52
53class CanvasPainter
54{
55 Q_DECLARE_TR_FUNCTIONS(CanvasPainter)
56public:
57 explicit CanvasPainter(QPixmap& canvas);
58 virtual ~CanvasPainter();
59
60 void reset();
61 void setViewTransform(const QTransform view, const QTransform viewInverse);
62
63 void setOnionSkinOptions(const OnionSkinPainterOptions& onionSkinOptions) { mOnionSkinPainterOptions = onionSkinOptions;}
64 void setOptions(const CanvasPainterOptions& p) { mOptions = p; }
65 void setTransformedSelection(QRect selection, QTransform transform);
66 void ignoreTransformedSelection();
67
68 void setPaintSettings(const Object* object, int currentLayer, int frame, TiledBuffer* tilledBuffer);
69 void paint(const QRect& blitRect);
70 void paintCached(const QRect& blitRect);
71 void resetLayerCache();
72
73private:
74
82 void initializePainter(QPainter& painter, QPaintDevice& device, const QRect& blitRect);
83
84 void paintOnionSkinOnLayer(QPainter& painter, const QRect& blitRect, Layer* layer);
85 void paintOnionSkin(QPainter& painter, const QRect& blitRect);
86
87 void renderPostLayers(QPainter& painter, const QRect& blitRect);
88 void renderPreLayers(QPainter& painter, const QRect& blitRect);
89
90 void paintCurrentFrame(QPainter& painter, const QRect& blitRect, int startLayer, int endLayer);
91
92 void paintTransformedSelection(QPainter& painter, BitmapImage* bitmapImage, const QRect& selection) const;
93
94 void paintBitmapOnionSkinFrame(QPainter& painter, const QRect& blitRect, Layer* layer, int nFrame, bool colorize);
95 void paintVectorOnionSkinFrame(QPainter& painter, const QRect& blitRect, Layer* layer, int nFrame, bool colorize);
96 void paintOnionSkinFrame(QPainter& painter, QPainter& onionSkinPainter, int nFrame, bool colorize, qreal frameOpacity);
97
98 void paintCurrentBitmapFrame(QPainter& painter, const QRect& blitRect, Layer* layer, bool isCurrentLayer);
99 void paintCurrentVectorFrame(QPainter& painter, const QRect& blitRect, Layer* layer, bool isCurrentLayer);
100
101 CanvasPainterOptions mOptions;
102
103 const Object* mObject = nullptr;
104 QPixmap& mCanvas;
105 QTransform mViewTransform;
106 QTransform mViewInverse;
107
108 int mCurrentLayerIndex = 0;
109 int mFrameNumber = 0;
110 TiledBuffer* mTiledBuffer = nullptr;
111
112 QImage mScaledBitmap;
113
114 // Handle selection transformation
115 bool mRenderTransform = false;
116 QRect mSelection;
117 QTransform mSelectionTransform;
118
119 // Caches specifically for when drawing on the canvas
120 QPixmap mPostLayersPixmap;
121 QPixmap mPreLayersPixmap;
122 QPixmap mCurrentLayerPixmap;
123 QPixmap mOnionSkinPixmap;
124 bool mPreLayersPixmapCacheValid = false;
125 bool mPostLayersPixmapCacheValid = false;
126
127 // There's a considerable amount of overhead in simply allocating a QPointF on the fly.
128 // Since we just need to draw it at 0,0, we might as well make a const value for that purpose
129 const QPointF mPointZero;
130
131
132 OnionSkinSubPainter mOnionSkinSubPainter;
133 OnionSkinPainterOptions mOnionSkinPainterOptions;
134
135 const static int OVERLAY_SAFE_CENTER_CROSS_SIZE = 25;
136};
137
138#endif // CANVASRENDERER_H
BitmapImage
Definition: bitmapimage.h:28
CanvasPainter
Definition: canvaspainter.h:54
CanvasPainter::initializePainter
void initializePainter(QPainter &painter, QPaintDevice &device, const QRect &blitRect)
CanvasPainter::initializePainter Enriches the painter with a context and sets it's initial matrix.
Definition: canvaspainter.cpp:125
CanvasPainter::paintCurrentFrame
void paintCurrentFrame(QPainter &painter, const QRect &blitRect, int startLayer, int endLayer)
Paints layers within the specified range for the current frame.
Definition: canvaspainter.cpp:412
Layer
Definition: layer.h:33
Object
Definition: object.h:42
OnionSkinSubPainter
A Sub Painter class is meant to be used in existing painter classes It does not and should not cary t...
Definition: onionskinsubpainter.h:32
TiledBuffer
Definition: tiledbuffer.h:49
ViewManager
Definition: viewmanager.h:26
QImage
QPaintDevice
QPainter
QPainter::CompositionMode
CompositionMode
QPixmap
QPointF
QRect
QTransform
CanvasPainterOptions
Definition: canvaspainter.h:40
OnionSkinPainterOptions
Definition: onionskinpainteroptions.h:20
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39