Pencil2D Animation
Download Community News Docs Contribute

core_lib/src/tool/stroketool.cpp Source File

  • Main Page
  • Related Pages
  • Classes
  • Files
  •  
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • tool
stroketool.cpp
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#include "stroketool.h"
19
20#include <QKeyEvent>
21#include "scribblearea.h"
22#include "strokemanager.h"
23#include "viewmanager.h"
24#include "editor.h"
25#include "toolmanager.h"
26
27#ifdef Q_OS_MAC
28extern "C" {
29 void detectWhichOSX();
30 void disableCoalescing();
31 void enableCoalescing();
32}
33#else
34extern "C" {
35 void detectWhichOSX() {}
36 void disableCoalescing() {}
37 void enableCoalescing() {}
38}
39#endif
40
41StrokeTool::StrokeTool(QObject* parent) : BaseTool(parent)
42{
43 detectWhichOSX();
44}
45
46void StrokeTool::startStroke(PointerEvent::InputType inputType)
47{
48 if (emptyFrameActionEnabled())
49 {
50 mScribbleArea->handleDrawingOnEmptyFrame();
51 }
52
53 mFirstDraw = true;
54 mLastPixel = getCurrentPixel();
55
56 mStrokePoints.clear();
57
58 //Experimental
59 QPointF startStrokes = strokeManager()->interpolateStart(mLastPixel);
60 mStrokePoints << mEditor->view()->mapScreenToCanvas(startStrokes);
61
62 mStrokePressures.clear();
63 mStrokePressures << strokeManager()->getPressure();
64
65 mCurrentInputType = inputType;
66
67 disableCoalescing();
68}
69
70bool StrokeTool::keyPressEvent(QKeyEvent *event)
71{
72 switch (event->key()) {
73 case Qt::Key_Alt:
74 if (mEditor->tools()->setTemporaryTool(EYEDROPPER, {}, Qt::AltModifier))
75 {
76 return true;
77 }
78 break;
79 case Qt::Key_Space:
80 if (mEditor->tools()->setTemporaryTool(HAND, Qt::Key_Space, Qt::NoModifier))
81 {
82 return true;
83 }
84 break;
85 }
86 return BaseTool::keyPressEvent(event);
87}
88
89bool StrokeTool::emptyFrameActionEnabled()
90{
91 return true;
92}
93
94void StrokeTool::endStroke()
95{
96 strokeManager()->interpolateEnd();
97 mStrokePressures << strokeManager()->getPressure();
98 mStrokePoints.clear();
99 mStrokePressures.clear();
100
101 enableCoalescing();
102
103 mEditor->setModified(mEditor->currentLayerIndex(), mEditor->currentFrame());
104}
105
106void StrokeTool::drawStroke()
107{
108 QPointF pixel = getCurrentPixel();
109 if (pixel != mLastPixel || !mFirstDraw)
110 {
111 // get last pixel before interpolation initializes
112 QPointF startStrokes = strokeManager()->interpolateStart(getLastPixel());
113 mStrokePoints << mEditor->view()->mapScreenToCanvas(startStrokes);
114 mStrokePressures << strokeManager()->getPressure();
115 }
116 else
117 {
118 mFirstDraw = false;
119 }
120}
BaseTool
Definition: basetool.h:70
ScribbleArea::handleDrawingOnEmptyFrame
void handleDrawingOnEmptyFrame()
Call this when starting to use a paint tool.
Definition: scribblearea.cpp:944
StrokeTool::emptyFrameActionEnabled
virtual bool emptyFrameActionEnabled()
Whether to enable the "drawing on empty frame" preference.
Definition: stroketool.cpp:89
QKeyEvent
QList::clear
void clear()
QObject
QObject::event
virtual bool event(QEvent *e)
QPointF
Qt::Key_Alt
Key_Alt
Qt::AltModifier
AltModifier
Generated on Sun Sep 24 2023 19:39:35 for Pencil2D by doxygen 1.9.6 based on revision 1395c86cb17dafbb32de44cbabe1f4c58636468d