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 onToolChanged(ToolType);
113
114 void endStroke();
115
116 void flipSelection(bool flipVertical);
117
118 BaseTool* currentTool() const;
119
120 bool isMouseInUse() const { return mMouseInUse; }
121 bool isTabletInUse() const { return mTabletInUse; }
122 bool isPointerInUse() const { return mMouseInUse || mTabletInUse; }
123
124 void keyEvent(QKeyEvent* event);
125 void keyEventForSelection(QKeyEvent* event);
126
127signals:
128 void multiLayerOnionSkinChanged(bool);
129 void selectionUpdated();
130
131public slots:
132 void clearImage();
133 void setCurveSmoothing(int);
134 void toggleThinLines();
135 void increaseLayerVisibilityIndex();
136 void decreaseLayerVisibilityIndex();
137 void setLayerVisibility(LayerVisibility visibility);
138
139 void updateToolCursor();
140 void paletteColorChanged(QColor);
141
142 void showLayerNotVisibleWarning();
143 void onTileUpdated(TiledBuffer* tiledBuffer, Tile* tile);
144 void onTileCreated(TiledBuffer* tiledBuffer, Tile* tile);
145
146protected:
147 bool event(QEvent *event) override;
148 void tabletEvent(QTabletEvent*) override;
149 void wheelEvent(QWheelEvent*) override;
150 void mousePressEvent(QMouseEvent*) override;
151 void mouseMoveEvent(QMouseEvent*) override;
152 void mouseReleaseEvent(QMouseEvent*) override;
153 void mouseDoubleClickEvent(QMouseEvent*) override;
154 void keyPressEvent(QKeyEvent*) override;
155 void keyReleaseEvent(QKeyEvent*) override;
156 void paintEvent(QPaintEvent*) override;
157 void resizeEvent(QResizeEvent*) override;
158
159public:
160 void drawPolyline(QPainterPath path, QPen pen, bool useAA);
161 void drawPath(QPainterPath path, QPen pen, QBrush brush, QPainter::CompositionMode cm);
162 void drawPen(QPointF thePoint, qreal brushWidth, QColor fillColor, bool useAA = true);
163 void drawPencil(QPointF thePoint, qreal brushWidth, qreal fixedBrushFeather, QColor fillColor, qreal opacity);
164 void drawBrush(QPointF thePoint, qreal brushWidth, qreal offset, QColor fillColor, QPainter::CompositionMode compMode, qreal opacity, bool usingFeather = true, bool useAA = false);
165 void blurBrush(BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_);
166 void liquifyBrush(BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_);
167
168 void paintBitmapBuffer();
169 void clearDrawingBuffer();
170 void setGaussianGradient(QGradient &gradient, QColor color, qreal opacity, qreal offset);
171
172 void pointerPressEvent(PointerEvent*);
173 void pointerMoveEvent(PointerEvent*);
174 void pointerReleaseEvent(PointerEvent*);
175
178 void handleDrawingOnEmptyFrame();
179
180 TiledBuffer mTiledBuffer;
181private:
182
187 void invalidatePainterCaches();
188
190 void invalidateCacheForFrame(int frameNumber);
191
194 void invalidateAllCache();
195
197 void invalidateCacheForDirtyFrames();
198
200 void invalidateOnionSkinsCacheAround(int frame);
201
202 void prepOverlays(int frame);
203 void prepCameraPainter(int frame);
204 void prepCanvas(int frame);
205 void drawCanvas(int frame, QRect rect);
206 void settingUpdated(SETTING setting);
207 void paintSelectionVisuals(QPainter &painter);
208
209 BitmapImage* currentBitmapImage(Layer* layer) const;
210 VectorImage* currentVectorImage(Layer* layer) const;
211
212 Editor* mEditor = nullptr;
213
214 LayerVisibility mLayerVisibility = LayerVisibility::ALL;
215 bool mMakeInvisible = false;
216 qreal mCurveSmoothingLevel = 0.0;
217 int mDeltaFactor = 1;
218
219 /* Under certain circumstances a mouse press event will fire after a tablet release event.
220 This causes unexpected behaviours for some of the tools, eg. the bucket.
221 The problem only seems to occur on windows and only when tapping.
222 prior to this fix the event queue would look like this:
223 eg: TabletPress -> TabletRelease -> MousePress
224 The following will filter mouse events created after a tablet release event.
225 */
226 void tabletReleaseEventFired();
227 bool mMouseInUse = false;
228 bool mTabletInUse = false;
229 qreal mDevicePixelRatio = 1.;
230
231 // Double click handling for tablet input
232 void handleDoubleClick();
233 bool mIsFirstClick = true;
234 int mDoubleClickMillis = 0;
235 // Microsoft suggests that a double click action should be no more than 500 ms
236 const int DOUBLE_CLICK_THRESHOLD = 500;
237 QTimer* mDoubleClickTimer = nullptr;
238 QPointF mTabletPressPos;
239 int mTabletReleaseMillisAgo;
240 const int MOUSE_FILTER_THRESHOLD = 200;
241
242 QTimer* mMouseFilterTimer = nullptr;
243
244 PreferenceManager* mPrefs = nullptr;
245
246 QPixmap mCanvas;
247 CanvasPainter mCanvasPainter;
248 OverlayPainter mOverlayPainter;
249 SelectionPainter mSelectionPainter;
250 CameraPainter mCameraPainter;
251
252 QPolygonF mOriginalPolygonF = QPolygonF();
253
254 // Pixmap Cache keys
255 QMap<unsigned int, QPixmapCache::Key> mPixmapCacheKeys;
256
257 // debug
258 QLoggingCategory mLog{ "ScribbleArea" };
259};
260
261#endif
BaseTool
Definition: basetool.h:47
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:315
ScribbleArea::onViewChanged
void onViewChanged()
View updated, invalidate relevant cache.
Definition: scribblearea.cpp:341
ScribbleArea::onObjectLoaded
void onObjectLoaded()
Object updated, invalidate all cache.
Definition: scribblearea.cpp:363
ScribbleArea::invalidateCacheForDirtyFrames
void invalidateCacheForDirtyFrames()
invalidate cache for dirty keyframes.
Definition: scribblearea.cpp:209
ScribbleArea::updateFrame
void updateFrame()
Update frame.
Definition: scribblearea.cpp:200
ScribbleArea::handleDrawingOnEmptyFrame
void handleDrawingOnEmptyFrame()
Call this when starting to use a paint tool.
Definition: scribblearea.cpp:812
ScribbleArea::invalidatePainterCaches
void invalidatePainterCaches()
Invalidate the layer pixmap and camera painter caches.
Definition: scribblearea.cpp:284
ScribbleArea::invalidateOnionSkinsCacheAround
void invalidateOnionSkinsCacheAround(int frame)
invalidate onion skin cache around frame
Definition: scribblearea.cpp:220
ScribbleArea::onSelectionChanged
void onSelectionChanged()
Selection was changed, keep cache.
Definition: scribblearea.cpp:351
ScribbleArea::onOnionSkinTypeChanged
void onOnionSkinTypeChanged()
Onion skin type changed, all frames will be affected.
Definition: scribblearea.cpp:358
ScribbleArea::onFramesModified
void onFramesModified()
Multiple frames modified, invalidate cache for affected frames.
Definition: scribblearea.cpp:322
ScribbleArea::onToolChanged
void onToolChanged(ToolType)
Tool changed, invalidate cache and frame if needed.
Definition: scribblearea.cpp:291
ScribbleArea::onPlayStateChanged
void onPlayStateChanged()
Playstate changed, invalidate relevant cache.
Definition: scribblearea.cpp:301
ScribbleArea::invalidateAllCache
void invalidateAllCache()
Invalidate all cache.
Definition: scribblearea.cpp:261
ScribbleArea::invalidateCacheForFrame
void invalidateCacheForFrame(int frameNumber)
Invalidate cache for the given frame.
Definition: scribblearea.cpp:273
ScribbleArea::onLayerChanged
void onLayerChanged()
Layer changed, invalidate relevant cache.
Definition: scribblearea.cpp:346
ScribbleArea::onFrameModified
void onFrameModified(int frameNumber)
Frame modified, invalidate cache for frame if any.
Definition: scribblearea.cpp:331
SelectionPainter
Definition: selectionpainter.h:38
SmudgeTool
Definition: smudgetool.h:24
Tile
Definition: tile.h:24
TiledBuffer
Definition: tiledbuffer.h:50
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 Tue Jan 6 2026 11:38:51 for Pencil2D by doxygen 1.9.6 based on revision f91a96748ec6712509b9b0ff47979db9c34d556f