Kage Studio 0.7.230612
A Simple Free and Open Source 2D Animation Software
Loading...
Searching...
No Matches
stage.h
Go to the documentation of this file.
1/*
2 * Kage Studio - a simple free and open source vector-based 2D animation software
3 * Copyright (C) 2011~2022 Mj Mendoza IV
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
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 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301, USA. Or, see <https://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef GTKMM_KAGE_STAGE_H
23 #define GTKMM_KAGE_STAGE_H
24
25 #include <gtkmm/drawingarea.h>
26 #include <iostream>
27
28 #include "data/anchor.h"
29 #include "data/color.h"
30 #include "data/strokecolor.h"
31 #include "data/vectordata.h"
32 #include "vectordatamanager.h"
33 #include <cairomm/context.h>
34 #include <gdkmm/general.h> // set_source_pixbuf()
35 #include "../util/cairo/cairo_kage.h"
36
37 class Kage; //forward declaration
38
39 class KageStage : public Gtk::DrawingArea {
40 public:
41 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_000;
42 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_045;
43 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_090;
44 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_135;
45 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_MOVE;
46 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_NE;
47 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_NW;
48 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_SW;
49 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_SE;
50 static Glib::RefPtr<Gdk::Pixbuf> imageSHAPE_ROTATE;
51
52 KageStage(Kage *p_win);
53 virtual ~KageStage();
54
55 enum ToolMode {
70 };
71 const unsigned int _NO_SELECTION = -1;
76 static GdkPoint moveStageXY;
77 unsigned int fps;
78 double fpsElapse;
79 double propX = 0;
82 double propY = 0;
85 double propWidth = 0;
86 double propHeight = 0;
87 double nodeX = 0;
88 double nodeY = 0;
89 unsigned int nodeIndexX = 0;
90 unsigned int nodeIndexY = 0;
91
92 void printVectors();
93 void cleanSlate();
94 void invalidateToRender();
95
96 void setStageBG(Gdk::Color p_Color);
97 Gdk::Color getStageBG();
98 void setFill(Gdk::Color p_Color);
99 Gdk::Color getFill();
100 void setStroke(Gdk::Color p_Color);
101 Gdk::Color getStroke();
102 double stageWidth; //direct use for get only
103 double stageHeight; //direct use for get only
105 void clearScreen(Cairo::RefPtr<Cairo::Context> p_context);
106 void renderFrame(Cairo::RefPtr<Cairo::Context> p_context, bool p_force = false);
107 void renderOnionFrame(Cairo::RefPtr<Cairo::Context> p_context, vector<VectorData> p_vectorData, double p_alpha);
108 void renderFrame(Cairo::RefPtr<Cairo::Context> p_context, vector<VectorData> p_vectorData, double p_alpha = 1.0);
109 void renderFrameOffset(Cairo::RefPtr<Cairo::Context> p_context, bool p_force = false, double p_offsetX = 0.0, double p_offsetY = 0.0);
110 void renderFrameOffset(Cairo::RefPtr<Cairo::Context> p_context, vector<VectorData> p_vectorData, double p_alpha = 1.0, double p_offsetX = 0.0, double p_offsetY = 0.0);
111 void initNodeTool();
112 void handleShapes();
119 void handleShapes_moveShape(double p_diffX, double p_diffY);
120 void handleShapes_updateAnchors(double p_x, double p_y);
122 void handleShapesMouseUp();
123 void handleNodes();
128 void handleNodesMouseUp();
129 bool handleNodes_getNearestShape(double p_x, double p_y, unsigned int p_index, vector<VectorData> p_v);
136 void handleOval();
137 void handleRect();
138 void handlePoly();
139 void handlePencil();
140 void handleStroke(); //needed?
142 void handleStrokeMouseUp();
143 void handleFill(); //needed?
144 void handleFillMouseUp();
145 void handleEyedrop();
148 Glib::RefPtr<Gdk::Pixbuf> _bg;
149 Cairo::RefPtr<Cairo::Surface> _bgcr;
150
151 bool selectAllShapes();
154 bool cancelDrawingPoly();
155 bool cutSelectedShapes();
156 bool copySelectedShapes();
157 bool pasteSelectedShapes();
159 bool deleteSelectedNodes();
161
162 void updateNodeXY();
163 bool isSelectedNode(unsigned int p_index);
164 void addSelectedNode(unsigned int p_index);
165 bool isSelectedShape(unsigned int p_index);
166 void addSelectedShape(unsigned int p_index);
170 unsigned int getShape(unsigned int p_index, vector<VectorData> p_v);
171
172
173 void updateShapeColor(bool p_doFill = true, bool p_doStroke = true);
174 void updateShapeX(double p_value, bool p_stackDo = true);
175 void updateShapeY(double p_value, bool p_stackDo = true);
176 void updateShapeWidth(double p_value);
177 void updateShapeHeight(double p_value);
178 void updateNodeX(double p_value, bool p_stackDo = true);
179 void updateNodeY(double p_value, bool p_stackDo = true);
180 bool _stackDo = false;
181 vector<VectorData> _vectorDataCopyBuffer;
182 vector<VectorData> _vectorDataZOrderBufferA;
183 vector<VectorData> _vectorDataZOrderBufferB;
184 vector<VectorData> _vectorDataZOrderBufferC;
185
186 bool renderToPNG(string p_path, bool p_transparent);
187 bool renderToPNGOffset(string p_path, bool p_transparent, double p_offsetX = 0.0, double p_offsetY = 0.0);
188 void renderFrameToPNG(Cairo::RefPtr<Cairo::Context> p_context);
189 void renderFrameToPNGOffset(Cairo::RefPtr<Cairo::Context> p_context, double p_offsetX = 0.0, double p_offsetY = 0.0);
190
191 Cairo::RefPtr<Cairo::Context> cr;
193
195
201
203
205 void applyZoom();
206 vector<VectorData> applyZoom(vector<VectorData> p_v);
207
210
211 void setSelectedShapes(vector<unsigned int> p_selectedShapes);
212 vector<unsigned int> getSelectedShapes();
213
214 void unpressKeys();
215 protected:
216 ToolMode prevTool; //used by Hand-tool shortcut [spacebar]
224 short int drawFreeCtr;
229 Glib::RefPtr<Gdk::Window> window;
234 bool draw;
235 unsigned int drawCtr;
236 //Override default signal handler:
237 virtual bool on_expose_event(GdkEventExpose *e);
238 virtual bool on_key_press_event(GdkEventKey *e) override;
239 virtual bool on_key_release_event(GdkEventKey *e) override;
240 virtual bool on_event(GdkEvent *e) override;
241
242 bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
243
245 unsigned int mouseOnNode;
247 unsigned int mouseOnNodeHover;
248 unsigned int mouseOnNodeIndex;
249 unsigned int selectedNode;
250 unsigned int mouseOnShape;
251 unsigned int selectedShape;
252 vector<unsigned int> selectedNodes;
253 vector<unsigned int> selectedShapes;
254
256 void renderNode(double p_x, double p_y, unsigned int p_state = 5);
257 void renderNodeControl(double p_x, double p_y, bool p_selected);
258 bool isMouseOnNode(double p_x, double p_y, unsigned int p_buffer = 5);
259
264 bool isNodeOnSelectionBox(double p_nodeX, double p_nodeY);
265
266 void drawSelectionArea();
267
268 bool deleteSelectedNode(unsigned int p_index);
269
270 unsigned int getSelectedShapeViaNode(unsigned int p_index, vector<VectorData> p_v);
272
276
277 AnchorData anchor_rotate; //for global use rotation-anchor
278
285
288
289 void updateShapeXY();
290 };
291#endif // GTKMM_KAGE_STAGE_H
Definition: anchor.h:28
type
Definition: anchor.h:30
Definition: color.h:28
Definition: kage.h:69
Definition: stage.h:39
AnchorData anchor_lowerRight
Definition: stage.h:275
void setSelectedShapes(vector< unsigned int > p_selectedShapes)
Definition: shape.cpp:28
void renderOnionFrame(Cairo::RefPtr< Cairo::Context > p_context, vector< VectorData > p_vectorData, double p_alpha)
Definition: stage.cpp:1148
bool on_draw(const Cairo::RefPtr< Cairo::Context > &cr) override
Definition: stage.cpp:929
bool isSelectedShape(unsigned int p_index)
Definition: shape.cpp:36
double polyXhead
Definition: stage.h:226
unsigned int mouseOnNode
Definition: stage.h:245
unsigned int drawCtr
Definition: stage.h:235
double polyYhead
Definition: stage.h:226
AnchorData anchor_center
Definition: stage.h:274
bool isMouseOnNode(double p_x, double p_y, unsigned int p_buffer=5)
Definition: node.cpp:949
unsigned int fps
Definition: stage.h:77
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_045
Definition: stage.h:42
void handleShapes_scaleNorth()
Definition: shape.cpp:57
double polyXtail
Definition: stage.h:227
GdkPoint _mouseLocation
Definition: stage.h:231
bool deleteSelectedNodes()
Definition: node.cpp:973
double nodeX
Definition: stage.h:87
PointData draw1
Definition: stage.h:218
bool renderToPNG(string p_path, bool p_transparent)
Definition: stage.cpp:1037
void clearScreen(Cairo::RefPtr< Cairo::Context > p_context)
for use with zoom; default value is stageWidth; can be changed as preferred
Definition: stage.cpp:1003
double propHeight
Definition: stage.h:86
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_NW
Definition: stage.h:47
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_135
Definition: stage.h:44
PointData drawFree2
Definition: stage.h:221
void updateNodeXY()
Definition: node.cpp:1137
unsigned int getSelectedShapeViaNode(unsigned int p_index, vector< VectorData > p_v)
Definition: node.cpp:743
unsigned int selectedNode
Definition: stage.h:249
double propY
Definition: stage.h:82
Cairo::RefPtr< Cairo::Context > cr
Definition: stage.h:191
void handleFill()
Definition: stage.cpp:1540
vector< unsigned int > selectedNodes
Definition: stage.h:252
void handleStrokeMouseUp()
Definition: stage.cpp:1533
void renderFrameOffset(Cairo::RefPtr< Cairo::Context > p_context, bool p_force=false, double p_offsetX=0.0, double p_offsetY=0.0)
Definition: stage.cpp:1131
unsigned int mouseOnNodeIndex
Definition: stage.h:248
PointData applyZoomRatio(PointData p_value)
Definition: stage.cpp:625
Gdk::Color getStroke()
Definition: stage.cpp:752
bool keyDownDown
Definition: stage.h:282
VectorDataManager _polyVectors
Definition: stage.h:228
PointData drawFree1
Definition: stage.h:220
vector< unsigned int > selectedShapes
Definition: stage.h:253
Glib::RefPtr< Gdk::Pixbuf > _bg
Definition: stage.h:148
void updateNodeY(double p_value, bool p_stackDo=true)
Definition: node.cpp:121
AnchorData anchor_rotate
Definition: stage.h:277
PointData _rotateReference
Definition: stage.h:202
bool pasteSelectedShapes()
Definition: shape.cpp:1290
bool toggleLineSelectedNodes()
Definition: node.cpp:1083
void invalidateToRender()
Definition: stage.cpp:914
PointData selectionBox2
Definition: stage.h:261
Cairo::RefPtr< Cairo::Surface > _bgcr
Definition: stage.h:149
bool keyUpDown
Definition: stage.h:281
void handleShapes_modifyingShape()
Definition: shape.cpp:691
double fpsElapse
Definition: stage.h:78
PointData _zoomReference
Definition: stage.h:198
const unsigned int _NO_SELECTION
Definition: stage.h:71
bool deleteSelectedShapes()
Definition: shape.cpp:1324
bool keyLeftDown
Definition: stage.h:283
bool keyShiftDown
Definition: stage.h:279
virtual bool on_key_press_event(GdkEventKey *e) override
Definition: stage.cpp:65
void applyZoom()
Definition: stage.cpp:654
short int drawFreeCtr
Definition: stage.h:224
PointData origin
Definition: stage.h:192
void handleDrawOvalMouseUp()
Definition: oval.cpp:28
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_090
Definition: stage.h:43
void normalizeSelectionBox()
Definition: node.cpp:912
int propXindex1
Definition: stage.h:80
bool _isModifyingShape
Definition: stage.h:194
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_000
Definition: stage.h:41
void updateShapeColor(bool p_doFill=true, bool p_doStroke=true)
Definition: shape.cpp:337
void handlePoly()
Definition: poly.cpp:88
unsigned int nodeIndexX
Definition: stage.h:89
PointData drawFree4
Definition: stage.h:223
PointData draw2
Definition: stage.h:219
Kage * win
Definition: stage.h:217
bool isSelectedNode(unsigned int p_index)
Definition: node.cpp:38
void handleDrawPolyMouseUp()
Definition: poly.cpp:28
double propX
Definition: stage.h:79
void handleShapes_scaleEast()
Definition: shape.cpp:113
virtual bool on_key_release_event(GdkEventKey *e) override
Definition: stage.cpp:158
void renderNodeControl(double p_x, double p_y, bool p_selected)
Definition: node.cpp:890
void handleNodes_rendering()
Definition: node.cpp:487
double propWidth
Definition: stage.h:85
void updateShapeXY()
Definition: shape.cpp:1371
PointData selectionBox1
Definition: stage.h:260
void handleDrawPencilMouseUp()
Definition: pencil.cpp:78
void handleDrawRectMouseUp()
Definition: rect.cpp:28
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_MOVE
Definition: stage.h:45
int _registerWidth
Definition: stage.h:286
virtual bool on_event(GdkEvent *e) override
Definition: stage.cpp:260
bool on_timeout()
bool draw
Definition: stage.h:234
bool _rotateMode
Definition: stage.h:208
GdkPoint _copyBufferMouse
Definition: stage.h:233
void updateShapeWidth(double p_value)
Definition: shape.cpp:501
static ColorData stageBG
Definition: stage.h:72
void handleEyedrop()
Definition: stage.cpp:1551
void initNodeTool()
Definition: node.cpp:28
void handleDrawPencilMouseMove(PointData p_point)
Definition: pencil.cpp:47
void trySingleSelectShape()
Definition: shape.cpp:1083
double nodeY
Definition: stage.h:88
int propXindex2
Definition: stage.h:81
int propYindex2
Definition: stage.h:84
void handleShapesMouseDown()
void handleNodes_selection()
Definition: node.cpp:182
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_NE
Definition: stage.h:46
unsigned int selectedShape
Definition: stage.h:251
double currentScale
Definition: stage.h:104
PointData drawFree3
Definition: stage.h:222
GdkPoint drawConstraint
Definition: stage.h:225
void unpressKeys()
Definition: stage.cpp:248
void handleStroke()
void updateShapeHeight(double p_value)
Definition: shape.cpp:558
Gdk::Color getStageBG()
void setStageBG(Gdk::Color p_Color)
Gdk::Color getFill()
Definition: stage.cpp:726
void renderFrame(Cairo::RefPtr< Cairo::Context > p_context, bool p_force=false)
Definition: stage.cpp:1076
void renderNode(double p_x, double p_y, unsigned int p_state=5)
Definition: node.cpp:869
static GdkPoint moveStageXY
Definition: stage.h:76
void drawSelectionArea()
Definition: stage.cpp:1510
bool isSelectionBoxNormalized()
Definition: node.cpp:906
void handleFillMouseUp()
Definition: stage.cpp:1544
bool keyRightDown
Definition: stage.h:284
void handleNodes_relocation()
Definition: node.cpp:301
void handleShapes_modifyingShapeRotate()
Definition: shape.cpp:618
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_SE
Definition: stage.h:49
PointData __stageArea
Definition: stage.h:200
void tryMultiSelectShapes_populateShapes()
Definition: shape.cpp:1111
void handleShapes_updateAnchors(double p_x, double p_y)
Definition: shape.cpp:322
void addSelectedShape(unsigned int p_index)
Definition: shape.cpp:48
void setStroke(Gdk::Color p_Color)
Definition: stage.cpp:740
void handleShapesMouseUp()
Definition: shape.cpp:1179
double polyYtail
Definition: stage.h:227
void handlePencil()
Definition: pencil.cpp:115
bool keyControlDown
Definition: stage.h:280
unsigned int mouseOnShape
Definition: stage.h:250
static ToolMode toolMode
direct use for get only
Definition: stage.h:75
vector< unsigned int > getSelectedShapes()
Definition: shape.cpp:32
int propYindex1
Definition: stage.h:83
unsigned int mouseOnNodeHover
Definition: stage.h:247
bool handleNodes_getNearestShape(double p_x, double p_y, unsigned int p_index, vector< VectorData > p_v)
Definition: node.cpp:710
void handleNodesMouseUp()
Definition: node.cpp:646
double _zoomValue
Definition: stage.h:197
vector< VectorData > _vectorDataZOrderBufferA
Definition: stage.h:182
double _nodeToMouseDistance
Definition: stage.h:271
bool _stackDo
Definition: stage.h:180
void handleOval()
Definition: oval.cpp:75
bool renderToPNGOffset(string p_path, bool p_transparent, double p_offsetX=0.0, double p_offsetY=0.0)
Definition: stage.cpp:1091
bool cutSelectedShapes()
Definition: shape.cpp:1188
void handleShapes_scaleSouth()
Definition: shape.cpp:225
void setFill(Gdk::Color p_Color)
Definition: stage.cpp:714
double _zoomRatio
Definition: stage.h:196
void handleEyedropMouseUp()
Definition: stage.cpp:1627
AnchorData::type mouseOnAnchor
Definition: stage.h:255
void handleShapes_scaleWest()
Definition: shape.cpp:169
double stageHeight
Definition: stage.h:103
bool deleteSelectedNode(unsigned int p_index)
Definition: node.cpp:1005
void addSelectedNode(unsigned int p_index)
Definition: node.cpp:53
int _registerHeight
Definition: stage.h:287
bool copySelectedShapes()
Definition: shape.cpp:1210
void renderFrameToPNG(Cairo::RefPtr< Cairo::Context > p_context)
Definition: stage.cpp:1073
void updateShapeX(double p_value, bool p_stackDo=true)
Definition: shape.cpp:378
bool _rotateApply
Definition: stage.h:209
unsigned int getShape(unsigned int p_index, vector< VectorData > p_v)
Definition: shape.cpp:1166
void handleEyedropMouseMove()
Definition: stage.cpp:1619
AnchorData anchor_upperLeft
Definition: stage.h:273
void handleShapes_moveShape(double p_diffX, double p_diffY)
Definition: shape.cpp:281
void handleRect()
Definition: rect.cpp:58
unsigned int _mouseLocationShapeIndex
Definition: stage.h:232
PointData mouseOnNodeOffset
Definition: stage.h:246
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_SW
Definition: stage.h:48
void tryMultiSelectShapes()
Definition: shape.cpp:1121
vector< VectorData > _vectorDataCopyBuffer
Definition: stage.h:181
Glib::RefPtr< Gdk::Window > window
Definition: stage.h:229
void handleNodesMouseDown()
Definition: node.cpp:643
void updateNodeX(double p_value, bool p_stackDo=true)
Definition: node.cpp:63
bool cancelDrawingPoly()
Definition: poly.cpp:132
unsigned int nodeIndexY
Definition: stage.h:90
vector< VectorData > _vectorDataZOrderBufferB
Definition: stage.h:183
PointData __origin
Definition: stage.h:199
ToolMode
Definition: stage.h:55
@ MODE_SELECT
Definition: stage.h:57
@ MODE_MOVE_STAGE
Definition: stage.h:63
@ MODE_NONE
Definition: stage.h:56
@ MODE_ZOOM
Definition: stage.h:62
@ MODE_DRAW_TEXT
Definition: stage.h:65
@ MODE_FILL
Definition: stage.h:60
@ MODE_DRAW_POLY
Definition: stage.h:66
@ MODE_DRAW_RECT
Definition: stage.h:64
@ MODE_STROKE
Definition: stage.h:59
@ MODE_NODE
Definition: stage.h:58
@ MODE_DRAW_OVAL
Definition: stage.h:67
@ MODE_DRAW_PENCIL
Definition: stage.h:69
@ MODE_EYEDROP
Definition: stage.h:61
@ MODE_DRAW_LINE
Definition: stage.h:68
void handleShapes()
Definition: shape.cpp:917
vector< VectorData > _vectorDataZOrderBufferC
Definition: stage.h:184
bool mouseDown
Definition: stage.h:230
bool deselectSelectedShapes()
Definition: shape.cpp:1268
void updateShapeY(double p_value, bool p_stackDo=true)
Definition: shape.cpp:439
void handleNodes()
Definition: node.cpp:177
bool selectAllShapes()
Definition: shape.cpp:1245
void printVectors()
Definition: stage.cpp:766
static StrokeColorData stroke
direct use for get only
Definition: stage.h:74
double stageWidth
Definition: stage.h:102
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_ROTATE
Definition: stage.h:50
virtual bool on_expose_event(GdkEventExpose *e)
Definition: stage.cpp:242
ToolMode prevTool
Definition: stage.h:216
static ColorData fillColor
direct use for get only
Definition: stage.h:73
void cleanSlate()
Definition: stage.cpp:875
void handleDrawPencilMouseDown(PointData p_point)
Definition: pencil.cpp:28
bool deselectSelectedNodes()
Definition: node.cpp:957
void renderFrameToPNGOffset(Cairo::RefPtr< Cairo::Context > p_context, double p_offsetX=0.0, double p_offsetY=0.0)
Definition: stage.cpp:1127
bool isNodeOnSelectionBox(double p_nodeX, double p_nodeY)
Definition: node.cpp:940
void handleStrokeMouseMove()
Definition: stage.cpp:1529
virtual ~KageStage()
Definition: stage.cpp:61
Definition: point.h:27
Definition: strokecolor.h:27
Definition: vectordatamanager.h:37