Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
scribblearea.h
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2017 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 
19 #ifndef SCRIBBLEAREA_H
20 #define SCRIBBLEAREA_H
21 
22 #include <cstdint>
23 #include <ctime>
24 #include <deque>
25 #include <memory>
26 
27 #include <QColor>
28 #include <QTransform>
29 #include <QPoint>
30 #include <QWidget>
31 #include <QPixmapCache>
32 
33 #include "log.h"
34 #include "pencildef.h"
35 #include "vectorimage.h"
36 #include "bitmapimage.h"
37 #include "colourref.h"
38 #include "vectorselection.h"
39 #include "colormanager.h"
40 #include "viewmanager.h"
41 #include "canvasrenderer.h"
42 #include "preferencemanager.h"
43 
44 
45 class Layer;
46 class Editor;
47 class BaseTool;
48 class StrokeManager;
49 class ColorManager;
50 
51 
52 class ScribbleArea : public QWidget
53 {
54  Q_OBJECT
55 
56  friend class MoveTool;
57  friend class EditTool;
58  friend class SmudgeTool;
59 
60 public:
61  ScribbleArea( QWidget *parent );
62  ~ScribbleArea();
63 
64  bool init();
65  void setCore( Editor* pCore ) { mEditor = pCore; }
66 
67  void deleteSelection();
68  void setSelection( QRectF rect, bool );
69  void displaySelectionProperties();
71  QRectF getSelection() const { return mySelection; }
72  bool somethingSelected;
73  QRectF mySelection, myTransformedSelection, myTempTransformedSelection;
74  qreal myRotatedAngle;
75 
76  bool areLayersSane() const;
77  bool isLayerPaintable() const;
78 
79  void flipSelection(bool flipVertical);
80 
81  QVector<QPoint> calcSelectionCenterPoints();
82 
83  void setEffect( SETTING e, bool isOn );
84 
85  int showAllLayers() const { return mShowAllLayers; }
86  qreal getCurveSmoothing() const { return mCurveSmoothingLevel; }
87  bool usePressure() const { return mUsePressure; }
88  bool makeInvisible() const { return mMakeInvisible; }
89 
90  enum MoveMode { MIDDLE, TOPLEFT, TOPRIGHT, BOTTOMLEFT, BOTTOMRIGHT, ROTATION, SYMMETRY, NONE };
91  MoveMode getMoveMode() const { return mMoveMode; }
92  void setMoveMode( MoveMode moveMode ) { mMoveMode = moveMode; }
93 
94  QTransform getView();
95  QRectF getViewRect();
96  QRectF getCameraRect();
97  QPointF getCentralPoint();
98 
99  void updateCurrentFrame();
100  void updateFrame( int frame );
101  void updateAllFrames();
102  void updateAllVectorLayersAtCurrentFrame();
103  void updateAllVectorLayersAt( int frame );
104  void updateAllVectorLayers();
105 
106  bool shouldUpdateAll() const { return mNeedUpdateAll; }
107  void setAllDirty() { mNeedUpdateAll = true; }
108 
109  BaseTool* currentTool();
110  BaseTool* getTool( ToolType eToolMode );
111  void setCurrentTool( ToolType eToolMode );
112  void setTemporaryTool( ToolType eToolMode );
113  void setPrevTool();
114 
115  StrokeManager* getStrokeManager() const { return mStrokeManager.get(); }
116 
117  Editor* editor() { return mEditor; }
118 
119  void floodFillError( int errorType );
120 
121  bool isMouseInUse() { return mMouseInUse; }
122 
123 signals:
124  void modification();
125  void modification( int );
126  void multiLayerOnionSkinChanged( bool );
127  void refreshPreview();
128 
129 public slots:
130  void clearImage();
131  void calculateSelectionRect();
132  QTransform getSelectionTransformation() { return selectionTransformation; }
133  void calculateSelectionTransformation();
134  void paintTransformedSelection();
135  void applyTransformedSelection();
136  void cancelTransformedSelection();
137  void setModified( int layerNumber, int frameNumber );
138 
139  void selectAll();
140  void deselectAll();
141 
142  void setCurveSmoothing( int );
143  void toggleThinLines();
144  void toggleOutlines();
145  void toggleShowAllLayers();
146 
147  void updateToolCursor();
148  void paletteColorChanged(QColor);
149 
150 protected:
151  void tabletEvent( QTabletEvent* ) override;
152  void wheelEvent( QWheelEvent* ) override;
153  void mousePressEvent( QMouseEvent* ) override;
154  void mouseMoveEvent( QMouseEvent* ) override;
155  void mouseReleaseEvent( QMouseEvent* ) override;
156  void mouseDoubleClickEvent( QMouseEvent* ) override;
157  void keyPressEvent( QKeyEvent* ) override;
158  void keyReleaseEvent( QKeyEvent* ) override;
159  void paintEvent( QPaintEvent* ) override;
160  void resizeEvent( QResizeEvent* ) override;
161 
162 public:
163  void drawPolyline(QPainterPath path, QPen pen, bool useAA );
164  void drawLine( QPointF P1, QPointF P2, QPen pen, QPainter::CompositionMode cm );
165  void drawPath( QPainterPath path, QPen pen, QBrush brush, QPainter::CompositionMode cm );
166  void drawPen( QPointF thePoint, qreal brushWidth, QColor fillColour, bool useAA = true );
167  void drawPencil( QPointF thePoint, qreal brushWidth, QColor fillColour, qreal opacity );
168  void drawBrush( QPointF thePoint, qreal brushWidth, qreal offset, QColor fillColour, qreal opacity, bool usingFeather = true, int useAA = 0 );
169  void blurBrush( BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_ );
170  void liquifyBrush( BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_ );
171 
172  void paintBitmapBuffer();
173  void paintBitmapBufferRect( QRect rect );
174  void paintCanvasCursor( QPainter& painter );
175  void clearBitmapBuffer();
176  void refreshBitmap( const QRectF& rect, int rad );
177  void refreshVector( const QRectF& rect, int rad );
178  void setGaussianGradient( QGradient &gradient, QColor colour, qreal opacity, qreal offset );
179 
180  void updateCanvasCursor();
181 
182  BitmapImage* mBufferImg = nullptr; // used to pre-draw vector modifications
183  BitmapImage* mStrokeImg = nullptr; // used for brush strokes before they are finalized
184 
185  QPixmap mCursorImg;
186 
187 private:
188  void drawCanvas( int frame, QRect rect );
189  void settingUpdated(SETTING setting);
190 
191  MoveMode mMoveMode = MIDDLE;
192  ToolType mPrevTemporalToolType;
193  ToolType mPrevToolType = PEN; // previous tool (except temporal)
194 
195  BitmapImage mBitmapSelection; // used to temporary store a transformed portion of a bitmap image
196  bool isTransforming = false;
197 
198  std::unique_ptr< StrokeManager > mStrokeManager;
199 
200  Editor* mEditor = nullptr;
201 
202  bool mIsSimplified = false;
203  bool mShowThinLines = false;
204  bool mQuickSizing = true;
205  int mShowAllLayers;
206  bool mUsePressure = true;
207  bool mMakeInvisible = false;
208  bool mToolCursors = true;
209  qreal mCurveSmoothingLevel = 0.0;
210  bool mMultiLayerOnionSkin; // future use. If required, just add a checkbox to updated it.
211  QColor mOnionColor;
212 
213  bool mNeedUpdateAll = false;
214 
215 
216 private:
217  bool mKeyboardInUse = false;
218  bool mMouseInUse = false;
219  bool mMouseRightButtonInUse = false;
220  QPointF mLastPixel;
221  QPointF mCurrentPixel;
222  QPointF mLastPoint;
223  QPointF mCurrentPoint;
224 
225  qreal tol;
226  QList<int> mClosestCurves;
227  QList<VertexRef> mClosestVertices;
228  QPointF mOffset;
229 
230  //instant tool (temporal eg. eraser)
231  bool instantTool = false; //whether or not using temporal tool
232 
233  VectorSelection vectorSelection;
234  QTransform selectionTransformation;
235 
236  PreferenceManager *mPrefs = nullptr;
237 
238  QPixmap mCanvas;
239  CanvasRenderer mCanvasRenderer;
240 
241  // Pixmap Cache keys
242  std::vector<QPixmapCache::Key> mPixmapCacheKeys;
243 
244  // debug
245  QRectF mDebugRect;
246  QLoggingCategory mLog;
247  std::deque< clock_t > mDebugTimeQue;
248 };
249 
250 #endif
Definition: layer.h:32
void resetSelectionProperties()
ScribbleArea::resetSelectionProperties should be used whenever translate, rotate, transform...
QVector< QPoint > calcSelectionCenterPoints()
ScribbleArea::calculateSelectionCenter.
void flipSelection(bool flipVertical)
ScribbleArea::flipSelection flip selection along the X or Y axis.
Definition: editor.h:45