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
  • interface
scribblearea.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU 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 <QPoint>
29#include <QWidget>
30#include <QPixmapCache>
31
32#include "movemode.h"
33#include "pencildef.h"
34#include "bitmapimage.h"
35#include "canvaspainter.h"
36#include "overlaypainter.h"
37#include "preferencemanager.h"
38#include "selectionpainter.h"
39#include "camerapainter.h"
40#include "tiledbuffer.h"
41
42class Layer;
43class Editor;
44class BaseTool;
45class PointerEvent;
46class BitmapImage;
47class VectorImage;
48
49
50class ScribbleArea : public QWidget
51{
52 Q_OBJECT
53
54 friend class MoveTool;
55 friend class SmudgeTool;
56 friend class BucketTool;
57
58public:
59 ScribbleArea(QWidget* parent);
60 ~ScribbleArea() override;
61
62 bool init();
63 void setEditor(Editor* e) { mEditor = e; }
64 Editor* editor() const { return mEditor; }
65
66 void deleteSelection();
67
68 void applyTransformedSelection();
69 void cancelTransformedSelection();
70
71 void setEffect(SETTING e, bool isOn);
72
73 LayerVisibility getLayerVisibility() const { return mLayerVisibility; }
74 qreal getCurveSmoothing() const { return mCurveSmoothingLevel; }
75 bool makeInvisible() const { return mMakeInvisible; }
76
77 QPointF getCentralPoint();
78
81 void updateFrame();
82
84 void onScrubbed(int frameNumber);
85
87 void onFramesModified();
88
90 void onPlayStateChanged();
91
93 void onViewChanged();
94
96 void onFrameModified(int frameNumber);
97
99 void onLayerChanged();
100
102 void onSelectionChanged();
103
106 void onOnionSkinTypeChanged();
107
109 void onObjectLoaded();
110
112 void onToolPropertyUpdated(ToolType, ToolPropertyType);
113
115 void onToolChanged(ToolType);
116
117 void endStroke();
118
119 void flipSelection(bool flipVertical);
120
121 BaseTool* currentTool() const;
122
123 bool isMouseInUse() const { return mMouseInUse; }
124 bool isTabletInUse() const { return mTabletInUse; }
125 bool isPointerInUse() const { return mMouseInUse || mTabletInUse; }
126
127 void keyEvent(QKeyEvent* event);
128 void keyEventForSelection(QKeyEvent* event);
129
130signals:
131 void multiLayerOnionSkinChanged(bool);
132 void selectionUpdated();
133
134public slots:
135 void clearImage();
136 void setCurveSmoothing(int);
137 void toggleThinLines();
138 void increaseLayerVisibilityIndex();
139 void decreaseLayerVisibilityIndex();
140 void setLayerVisibility(LayerVisibility visibility);
141
142 void updateToolCursor();
143 void paletteColorChanged(QColor);
144
145 void showLayerNotVisibleWarning();
146 void onTileUpdated(TiledBuffer* tiledBuffer, Tile* tile);
147 void onTileCreated(TiledBuffer* tiledBuffer, Tile* tile);
148
149protected:
150 bool event(QEvent *event) override;
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
162public:
163 void drawPolyline(QPainterPath path, QPen pen, bool useAA);
164 void drawPath(QPainterPath path, QPen pen, QBrush brush, QPainter::CompositionMode cm);
165 void drawPen(QPointF thePoint, qreal brushWidth, QColor fillColor, bool useAA = true);
166 void drawPencil(QPointF thePoint, qreal brushWidth, qreal fixedBrushFeather, QColor fillColor, qreal opacity);
167 void drawBrush(QPointF thePoint, qreal brushWidth, qreal offset, QColor fillColor, QPainter::CompositionMode compMode, qreal opacity, bool usingFeather = true, bool useAA = false);
168 void blurBrush(BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_);
169 void liquifyBrush(BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_);
170
171 void paintBitmapBuffer();
172 void clearDrawingBuffer();
173 void setGaussianGradient(QGradient &gradient, QColor color, qreal opacity, qreal offset);
174
175 void pointerPressEvent(PointerEvent*);
176 void pointerMoveEvent(PointerEvent*);
177 void pointerReleaseEvent(PointerEvent*);
178
181 void handleDrawingOnEmptyFrame();
182
183 TiledBuffer mTiledBuffer;
184private:
185
190 void invalidatePainterCaches();
191
193 void invalidateCacheForFrame(int frameNumber);
194
197 void invalidateAllCache();
198
200 void invalidateCacheForDirtyFrames();
201
203 void invalidateOnionSkinsCacheAround(int frame);
204
205 void prepOverlays(int frame);
206 void prepCameraPainter(int frame);
207 void prepCanvas(int frame);
208 void drawCanvas(int frame, QRect rect);
209 void settingUpdated(SETTING setting);
210 void paintSelectionVisuals(QPainter &painter);
211
212 BitmapImage* currentBitmapImage(Layer* layer) const;
213 VectorImage* currentVectorImage(Layer* layer) const;
214
215 Editor* mEditor = nullptr;
216
217 LayerVisibility mLayerVisibility = LayerVisibility::ALL;
218 bool mMakeInvisible = false;
219 qreal mCurveSmoothingLevel = 0.0;
220 int mDeltaFactor = 1;
221
222 /* Under certain circumstances a mouse press event will fire after a tablet release event.
223 This causes unexpected behaviours for some of the tools, eg. the bucket.
224 The problem only seems to occur on windows and only when tapping.
225 prior to this fix the event queue would look like this:
226 eg: TabletPress -> TabletRelease -> MousePress
227 The following will filter mouse events created after a tablet release event.
228 */
229 void tabletReleaseEventFired();
230 bool mMouseInUse = false;
231 bool mTabletInUse = false;
232 qreal mDevicePixelRatio = 1.;
233
234 // Double click handling for tablet input
235 void handleDoubleClick();
236 bool mIsFirstClick = true;
237 int mDoubleClickMillis = 0;
238 // Microsoft suggests that a double click action should be no more than 500 ms
239 const int DOUBLE_CLICK_THRESHOLD = 500;
240 QTimer* mDoubleClickTimer = nullptr;
241 QPointF mTabletPressPos;
242 int mTabletReleaseMillisAgo;
243 const int MOUSE_FILTER_THRESHOLD = 200;
244
245 QTimer* mMouseFilterTimer = nullptr;
246
247 PreferenceManager* mPrefs = nullptr;
248
249 QPixmap mCanvas;
250 CanvasPainter mCanvasPainter;
251 OverlayPainter mOverlayPainter;
252 SelectionPainter mSelectionPainter;
253 CameraPainter mCameraPainter;
254
255 QPolygonF mOriginalPolygonF = QPolygonF();
256
257 // Pixmap Cache keys
258 QMap<unsigned int, QPixmapCache::Key> mPixmapCacheKeys;
259
260 // debug
261 QLoggingCategory mLog{ "ScribbleArea" };
262};
263
264#endif
BaseTool
Definition: basetool.h:70
BitmapImage
Definition: bitmapimage.h:28
BucketTool
Definition: buckettool.h:30
CameraPainter
Definition: camerapainter.h:38
CanvasPainter
Definition: canvaspainter.h:54
Editor
Definition: editor.h:71
Layer
Definition: layer.h:33
MoveTool
Definition: movetool.h:31
OverlayPainter
Definition: overlaypainter.h:38
PointerEvent
Definition: pointerevent.h:8
PreferenceManager
Definition: preferencemanager.h:28
ScribbleArea
Definition: scribblearea.h:51
ScribbleArea::onScrubbed
void onScrubbed(int frameNumber)
Frame scrubbed, invalidate relevant cache.
Definition: scribblearea.cpp:326
ScribbleArea::onToolPropertyUpdated
void onToolPropertyUpdated(ToolType, ToolPropertyType)
Tool property updated, invalidate cache and frame if needed.
Definition: scribblearea.cpp:290
ScribbleArea::onViewChanged
void onViewChanged()
View updated, invalidate relevant cache.
Definition: scribblearea.cpp:352
ScribbleArea::onObjectLoaded
void onObjectLoaded()
Object updated, invalidate all cache.
Definition: scribblearea.cpp:374
ScribbleArea::invalidateCacheForDirtyFrames
void invalidateCacheForDirtyFrames()
invalidate cache for dirty keyframes.
Definition: scribblearea.cpp:208
ScribbleArea::updateFrame
void updateFrame()
Update frame.
Definition: scribblearea.cpp:199
ScribbleArea::handleDrawingOnEmptyFrame
void handleDrawingOnEmptyFrame()
Call this when starting to use a paint tool.
Definition: scribblearea.cpp:827
ScribbleArea::invalidatePainterCaches
void invalidatePainterCaches()
Invalidate the layer pixmap and camera painter caches.
Definition: scribblearea.cpp:283
ScribbleArea::invalidateOnionSkinsCacheAround
void invalidateOnionSkinsCacheAround(int frame)
invalidate onion skin cache around frame
Definition: scribblearea.cpp:219
ScribbleArea::onSelectionChanged
void onSelectionChanged()
Selection was changed, keep cache.
Definition: scribblearea.cpp:362
ScribbleArea::onOnionSkinTypeChanged
void onOnionSkinTypeChanged()
Onion skin type changed, all frames will be affected.
Definition: scribblearea.cpp:369
ScribbleArea::onFramesModified
void onFramesModified()
Multiple frames modified, invalidate cache for affected frames.
Definition: scribblearea.cpp:333
ScribbleArea::onToolChanged
void onToolChanged(ToolType)
Tool changed, invalidate cache and frame if needed.
Definition: scribblearea.cpp:302
ScribbleArea::onPlayStateChanged
void onPlayStateChanged()
Playstate changed, invalidate relevant cache.
Definition: scribblearea.cpp:312
ScribbleArea::invalidateAllCache
void invalidateAllCache()
Invalidate all cache.
Definition: scribblearea.cpp:260
ScribbleArea::invalidateCacheForFrame
void invalidateCacheForFrame(int frameNumber)
Invalidate cache for the given frame.
Definition: scribblearea.cpp:272
ScribbleArea::onLayerChanged
void onLayerChanged()
Layer changed, invalidate relevant cache.
Definition: scribblearea.cpp:357
ScribbleArea::onFrameModified
void onFrameModified(int frameNumber)
Frame modified, invalidate cache for frame if any.
Definition: scribblearea.cpp:342
SelectionPainter
Definition: selectionpainter.h:37
SmudgeTool
Definition: smudgetool.h:24
Tile
Definition: tile.h:24
TiledBuffer
Definition: tiledbuffer.h:49
VectorImage
Definition: vectorimage.h:32
QBrush
QColor
QEvent
QGradient
QKeyEvent
QLoggingCategory
QMap
QMouseEvent
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
QObject::parent
QObject * parent() const const
QPainter
QPainter::CompositionMode
CompositionMode
QPainterPath
QPaintEvent
QPen
QPixmap
QPointF
QPolygonF
QRect
QResizeEvent
QTabletEvent
QTimer
QWheelEvent
QWidget
QWidget::rect
rect
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39