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_kage);
53 virtual ~KageStage();
54
55 enum ToolMode {
70 };
71 const unsigned int _NO_SELECTION = -1;
72 static ColorData fillColor;
73 static StrokeColorData stroke;
74 //any changes on color/stroke during use of Pencil will be stored on Pencil only
77 static ToolMode toolMode;
78 static GdkPoint moveStageXY;
79 double fpsElapse;
80 double propX = 0;
81 int propXindex1;
82 int propXindex2;
83 double propY = 0;
84 int propYindex1;
85 int propYindex2;
86 double propWidth = 0;
87 double propHeight = 0;
88 double nodeX = 0;
89 double nodeY = 0;
90 unsigned int nodeIndexX = 0;
91 unsigned int nodeIndexY = 0;
92
94 void cleanSlate();
97
98 void setFill(Gdk::Color p_Color);
99 Gdk::Color getFill();
100 void setStroke(Gdk::Color p_Color);
101 Gdk::Color getStroke();
102 double currentScale;
103 void clearScreen(Cairo::RefPtr<Cairo::Context> p_context);
104 void renderFrame(Cairo::RefPtr<Cairo::Context> p_context, bool p_force = false);
105 void renderOnionFrame(Cairo::RefPtr<Cairo::Context> p_context, vector<VectorData> p_vectorData, double p_alpha);
106 void renderFrame(Cairo::RefPtr<Cairo::Context> p_context, vector<VectorData> p_vectorData, double p_alpha = 1.0);
107 void renderFrameOffset(Cairo::RefPtr<Cairo::Context> p_context, bool p_force = false, double p_offsetX = 0.0, double p_offsetY = 0.0);
108 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);
109 unsigned int addImage(unsigned int p_ID);
118 void handleShapes_moveShape(double p_diffX, double p_diffY);
119 void handleShapes_updateAnchors(double p_x, double p_y);
128 bool handleNodes_getNearestShape(double p_x, double p_y, unsigned int p_index, vector<VectorData> p_v);
139 void handleStroke(); //needed?
142 void handleFill(); //needed?
147 Glib::RefPtr<Gdk::Pixbuf> _bg;
148 Cairo::RefPtr<Cairo::Surface> _bgcr;
149
160
162 bool isSelectedNode(unsigned int p_index);
163 void addSelectedNode(unsigned int p_index);
164 bool isSelectedShape(unsigned int p_index);
165 void addSelectedShape(unsigned int p_index);
169 unsigned int getShape(unsigned int p_index, vector<VectorData> p_v);
170
171
172 void updateShapeColor(bool p_doFill = true, bool p_doStroke = true);
173 void updateShapeX(double p_value, bool p_stackDo = true);
174 void updateShapeY(double p_value, bool p_stackDo = true);
175 void updateShapeWidth(double p_value);
176 void updateShapeHeight(double p_value);
177 void updateNodeX(double p_value, bool p_stackDo = true);
178 void updateNodeY(double p_value, bool p_stackDo = true);
179 bool _stackDo = false;
180 vector<VectorData> _vectorDataCopyBuffer;
181 vector<VectorData> _vectorDataZOrderBufferA;
182 vector<VectorData> _vectorDataZOrderBufferB;
183 vector<VectorData> _vectorDataZOrderBufferC;
184
185 bool renderToPNG(string p_path, bool p_transparent);
186 bool renderToPNGOffset(string p_path, bool p_transparent, double p_offsetX = 0.0, double p_offsetY = 0.0);
187 void renderFrameToPNG(Cairo::RefPtr<Cairo::Context> p_context);
188 void renderFrameToPNGOffset(Cairo::RefPtr<Cairo::Context> p_context, double p_offsetX = 0.0, double p_offsetY = 0.0);
189
190 Cairo::RefPtr<Cairo::Context> cr;
192
194
195 double _zoomRatio;
196 double _zoomValue;
200
202
204 void applyZoom();
205 vector<VectorData> applyZoom(vector<VectorData> p_v);
206
207 bool _rotateMode;
208 bool _rotateApply;
209
210 void setSelectedShapes(vector<unsigned int> p_selectedShapes);
211 vector<unsigned int> getSelectedShapes();
212
214
215 vector<Cairo::RefPtr<Cairo::ImageSurface>> cairoPNG;
216 static Cairo::RefPtr<Cairo::ImageSurface> cairoImageSurface;
217 protected:
218 ToolMode prevTool; //used by Hand-tool shortcut [spacebar]
226 short int drawFreeCtr;
227 GdkPoint drawConstraint;
228 double polyXhead, polyYhead;
229 double polyXtail, polyYtail;
231 Glib::RefPtr<Gdk::Window> window;
232 bool mouseDown;
233 GdkPoint _mouseLocation;
234 unsigned int _mouseLocationShapeIndex;
235 GdkPoint _copyBufferMouse;
236 bool draw;
237 unsigned int drawCtr;
238 //Override default signal handler:
239 virtual bool on_expose_event(GdkEventExpose *e);
240 virtual bool on_key_press_event(GdkEventKey *e) override;
241 virtual bool on_key_release_event(GdkEventKey *e) override;
242 virtual bool on_event(GdkEvent *e) override;
243
244 bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
245
247 unsigned int mouseOnNode;
249 unsigned int mouseOnNodeHover;
250 unsigned int mouseOnNodeIndex;
251 unsigned int selectedNode;
252 unsigned int mouseOnShape;
253 unsigned int selectedShape;
254 vector<unsigned int> selectedNodes;
255 vector<unsigned int> selectedShapes;
256
258 void renderNode(double p_x, double p_y, unsigned int p_state = 5);
259 void renderNodeControl(double p_x, double p_y, bool p_selected);
260 bool isMouseOnNode(double p_x, double p_y, unsigned int p_buffer = 5);
261
266 bool isNodeOnSelectionBox(double p_nodeX, double p_nodeY);
267
269
270 bool deleteSelectedNode(unsigned int p_index);
271
272 unsigned int getSelectedShapeViaNode(unsigned int p_index, vector<VectorData> p_v);
274
278
279 AnchorData anchor_rotate; //for global use rotation-anchor
280
281 bool keyShiftDown;
282 bool keyControlDown;
283 bool keyUpDown;
284 bool keyDownDown;
285 bool keyLeftDown;
286 bool keyRightDown;
287
288 int _registerWidth;
289 int _registerHeight;
290
292 };
293#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
Kage * _kage
Definition: stage.h:219
AnchorData anchor_lowerRight
Definition: stage.h:275
void setSelectedShapes(vector< unsigned int > p_selectedShapes)
void renderOnionFrame(Cairo::RefPtr< Cairo::Context > p_context, vector< VectorData > p_vectorData, double p_alpha)
bool on_draw(const Cairo::RefPtr< Cairo::Context > &cr) override
bool isSelectedShape(unsigned int p_index)
virtual bool on_key_press_event(GdkEventKey *e) override
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)
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_045
Definition: stage.h:42
void handleShapes_scaleNorth()
double polyXtail
Definition: stage.h:227
GdkPoint _mouseLocation
Definition: stage.h:231
bool deleteSelectedNodes()
double nodeX
Definition: stage.h:87
PointData draw1
Definition: stage.h:218
bool renderToPNG(string p_path, bool p_transparent)
void clearScreen(Cairo::RefPtr< Cairo::Context > p_context)
for use with zoom; default value is _kage->_document.Project._width; can be changed as preferred
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()
unsigned int getSelectedShapeViaNode(unsigned int p_index, vector< VectorData > p_v)
unsigned int selectedNode
Definition: stage.h:249
double propY
Definition: stage.h:82
Cairo::RefPtr< Cairo::Context > cr
Definition: stage.h:191
void handleFill()
vector< unsigned int > selectedNodes
Definition: stage.h:252
void handleStrokeMouseUp()
void renderFrameOffset(Cairo::RefPtr< Cairo::Context > p_context, bool p_force=false, double p_offsetX=0.0, double p_offsetY=0.0)
unsigned int mouseOnNodeIndex
Definition: stage.h:248
PointData applyZoomRatio(PointData p_value)
vector< Cairo::RefPtr< Cairo::ImageSurface > > cairoPNG
Definition: stage.h:215
Gdk::Color getStroke()
bool keyDownDown
Definition: stage.h:282
static Cairo::RefPtr< Cairo::ImageSurface > cairoImageSurface
Definition: stage.h:216
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)
AnchorData anchor_rotate
Definition: stage.h:277
PointData _rotateReference
Definition: stage.h:202
bool pasteSelectedShapes()
bool toggleLineSelectedNodes()
void invalidateToRender()
PointData selectionBox2
Definition: stage.h:261
Cairo::RefPtr< Cairo::Surface > _bgcr
Definition: stage.h:149
bool keyUpDown
Definition: stage.h:281
void handleShapes_modifyingShape()
double fpsElapse
Definition: stage.h:78
PointData _zoomReference
Definition: stage.h:198
const unsigned int _NO_SELECTION
Definition: stage.h:71
bool deleteSelectedShapes()
bool keyLeftDown
Definition: stage.h:283
bool keyShiftDown
Definition: stage.h:279
void applyZoom()
short int drawFreeCtr
Definition: stage.h:224
PointData origin
Definition: stage.h:192
void handleDrawOvalMouseUp()
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_090
Definition: stage.h:43
void normalizeSelectionBox()
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)
void handlePoly()
unsigned int nodeIndexX
Definition: stage.h:89
PointData drawFree4
Definition: stage.h:223
PointData draw2
Definition: stage.h:219
bool isSelectedNode(unsigned int p_index)
void handleDrawPolyMouseUp()
double propX
Definition: stage.h:79
void handleShapes_scaleEast()
void renderNodeControl(double p_x, double p_y, bool p_selected)
void handleNodes_rendering()
double propWidth
Definition: stage.h:85
void updateShapeXY()
PointData selectionBox1
Definition: stage.h:260
void handleDrawPencilMouseUp()
void handleDrawRectMouseUp()
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_MOVE
Definition: stage.h:45
int _registerWidth
Definition: stage.h:286
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)
void handleEyedrop()
virtual bool on_event(GdkEvent *e) override
void initNodeTool()
void handleDrawPencilMouseMove(PointData p_point)
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)
void trySingleSelectShape()
double nodeY
Definition: stage.h:88
virtual ~KageStage()
int propXindex2
Definition: stage.h:81
int propYindex2
Definition: stage.h:84
void handleShapesMouseDown()
void handleNodes_selection()
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()
void handleStroke()
void updateShapeHeight(double p_value)
Gdk::Color getFill()
void renderFrame(Cairo::RefPtr< Cairo::Context > p_context, bool p_force=false)
void renderNode(double p_x, double p_y, unsigned int p_state=5)
static GdkPoint moveStageXY
Definition: stage.h:76
void drawSelectionArea()
bool isSelectionBoxNormalized()
void handleFillMouseUp()
bool keyRightDown
Definition: stage.h:284
void handleNodes_relocation()
void handleShapes_modifyingShapeRotate()
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_SE
Definition: stage.h:49
PointData __stageArea
Definition: stage.h:200
void tryMultiSelectShapes_populateShapes()
void handleShapes_updateAnchors(double p_x, double p_y)
void addSelectedShape(unsigned int p_index)
void setStroke(Gdk::Color p_Color)
void handleShapesMouseUp()
double polyYtail
Definition: stage.h:227
void handlePencil()
KageStage(Kage *p_kage)
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()
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)
void handleNodesMouseUp()
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()
bool renderToPNGOffset(string p_path, bool p_transparent, double p_offsetX=0.0, double p_offsetY=0.0)
bool cutSelectedShapes()
void handleShapes_scaleSouth()
void setFill(Gdk::Color p_Color)
double _zoomRatio
Definition: stage.h:196
void handleEyedropMouseUp()
vector< VectorData > applyZoom(vector< VectorData > p_v)
AnchorData::type mouseOnAnchor
Definition: stage.h:255
void handleShapes_scaleWest()
bool deleteSelectedNode(unsigned int p_index)
void addSelectedNode(unsigned int p_index)
int _registerHeight
Definition: stage.h:287
bool copySelectedShapes()
virtual bool on_expose_event(GdkEventExpose *e)
void renderFrameToPNG(Cairo::RefPtr< Cairo::Context > p_context)
void updateShapeX(double p_value, bool p_stackDo=true)
bool _rotateApply
Definition: stage.h:209
unsigned int getShape(unsigned int p_index, vector< VectorData > p_v)
void handleEyedropMouseMove()
AnchorData anchor_upperLeft
Definition: stage.h:273
void handleShapes_moveShape(double p_diffX, double p_diffY)
void handleRect()
unsigned int _mouseLocationShapeIndex
Definition: stage.h:232
static ColorData pencilFillColor
direct use for get only
Definition: stage.h:75
unsigned int addImage(unsigned int p_ID)
This will return an Cairo::ImageSurface array-index to be used as ID for rendering on Stage or Librar...
Definition: stage.cpp:1363
PointData mouseOnNodeOffset
Definition: stage.h:246
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_SW
Definition: stage.h:48
void tryMultiSelectShapes()
vector< VectorData > _vectorDataCopyBuffer
Definition: stage.h:181
Glib::RefPtr< Gdk::Window > window
Definition: stage.h:229
void handleNodesMouseDown()
void updateNodeX(double p_value, bool p_stackDo=true)
bool _invalidated
Definition: stage.h:96
bool cancelDrawingPoly()
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()
vector< VectorData > _vectorDataZOrderBufferC
Definition: stage.h:184
bool mouseDown
Definition: stage.h:230
bool deselectSelectedShapes()
void updateShapeY(double p_value, bool p_stackDo=true)
void handleNodes()
bool selectAllShapes()
void printVectors()
static StrokeColorData stroke
direct use for get only
Definition: stage.h:74
static Glib::RefPtr< Gdk::Pixbuf > imageSHAPE_ROTATE
Definition: stage.h:50
ToolMode prevTool
Definition: stage.h:216
static ColorData fillColor
direct use for get only
Definition: stage.h:73
void cleanSlate()
void handleDrawPencilMouseDown(PointData p_point)
bool deselectSelectedNodes()
virtual bool on_key_release_event(GdkEventKey *e) override
void renderFrameToPNGOffset(Cairo::RefPtr< Cairo::Context > p_context, double p_offsetX=0.0, double p_offsetY=0.0)
static StrokeColorData pencilStroke
direct use for get only
Definition: stage.h:76
bool isNodeOnSelectionBox(double p_nodeX, double p_nodeY)
void handleStrokeMouseMove()
void renderFrame(Cairo::RefPtr< Cairo::Context > p_context, vector< VectorData > p_vectorData, double p_alpha=1.0)
Definition: point.h:27
Definition: strokecolor.h:27
Definition: vectordatamanager.h:37