Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
canvasrenderer.h
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2012-2017 Matthew Chiawen Chang
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 */
16 
17 #ifndef CANVASRENDERER_H
18 #define CANVASRENDERER_H
19 
20 
21 #include <QObject>
22 #include <QTransform>
23 #include <QPainter>
24 #include <memory>
25 #include "log.h"
26 
27 
28 class Object;
29 class Layer;
30 
31 
33 {
34  bool bPrevOnionSkin = false;
35  bool bNextOnionSkin = false;
36  int nPrevOnionSkinCount = 3;
37  int nNextOnionSkinCount = 3;
38  float fOnionSkinMaxOpacity = 0.5f;
39  float fOnionSkinMinOpacity = 0.1f;
40  bool bColorizePrevOnion = false;
41  bool bColorizeNextOnion = false;
42  bool bAntiAlias = false;
43  bool bGrid = false;
44  int nGridSize = 50; /* This is the grid size IN PIXELS. The grid will scale with the image, though */
45  bool bAxis = false;
46  bool bThinLines = false;
47  bool bOutlines = false;
48  int nShowAllLayers = 3;
49  bool bIsOnionAbsolute = false;
50 };
51 
52 
53 class CanvasRenderer : public QObject
54 {
55  Q_OBJECT
56 
57 public:
58  explicit CanvasRenderer( QObject* parent = 0 );
59  virtual ~CanvasRenderer();
60 
61  void setCanvas( QPixmap* canvas );
62  void setViewTransform( QTransform viewTransform );
63  void setOptions( RenderOptions p ) { mOptions = p; }
64  void setTransformedSelection( QRect selection, QTransform transform );
65  void ignoreTransformedSelection();
66  QRect getCameraRect();
67 
68  void paint( Object* object, int layer, int frame, QRect rect );
69  void renderGrid(QPainter& painter);
70 
71 private:
72  void paintBackground();
73  void paintOnionSkin( QPainter& painter );
74  void paintCurrentFrame( QPainter& painter );
75 
76  void paintBitmapFrame( QPainter&, int layerId, int nFrame, bool colorize = false , bool useLastKeyFrame = true );
77  void paintVectorFrame(QPainter&, int layerId, int nFrame, bool colorize = false , bool useLastKeyFrame = true );
78 
79  void paintTransformedSelection( QPainter& painter );
80  void paintGrid( QPainter& painter );
81  void paintCameraBorder(QPainter &painter);
82  void paintAxis( QPainter& painter );
83 
84 private:
85  QPixmap* mCanvas = nullptr;
86  Object* mObject = nullptr;
87  QTransform mViewTransform;
88  QRect mCameraRect;
89 
90  int mLayerIndex = 0;
91  int mFrameNumber = 0;
92 
93  bool bMultiLayerOnionSkin = false;
94 
95  RenderOptions mOptions;
96 
97  // Handle selection transformation
98  //
99  bool mRenderTransform = false;
100  QRect mSelection;
101  QTransform mSelectionTransform;
102 
103  QLoggingCategory mLog;
104 
105 };
106 
107 #endif // CANVASRENDERER_H
Definition: layer.h:32
Definition: object.h:71