1 /* === S Y N F I G ========================================================= */ 2 /*! \file layerpaint.h 3 ** \brief Template File 4 ** 5 ** $Id$ 6 ** 7 ** \legal 8 ** ......... ... 2014 Ivan Mahonin 9 ** 10 ** This package is free software; you can redistribute it and/or 11 ** modify it under the terms of the GNU General Public License as 12 ** published by the Free Software Foundation; either version 2 of 13 ** the License, or (at your option) any later version. 14 ** 15 ** This package is distributed in the hope that it will be useful, 16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 ** General Public License for more details. 19 ** \endlegal 20 */ 21 /* ========================================================================= */ 22 23 /* === S T A R T =========================================================== */ 24 25 #ifndef __SYNFIG_APP_ACTION_LAYERPAINT_H 26 #define __SYNFIG_APP_ACTION_LAYERPAINT_H 27 28 /* === H E A D E R S ======================================================= */ 29 30 #include <synfig/guid.h> 31 #include <synfig/layers/layer_bitmap.h> 32 33 #include <synfigapp/action.h> 34 35 #include <brushlib.h> 36 37 /* === M A C R O S ========================================================= */ 38 39 /* === T Y P E D E F S ===================================================== */ 40 41 /* === C L A S S E S & S T R U C T S ======================================= */ 42 43 namespace synfigapp { 44 45 class Instance; 46 47 namespace Action { 48 49 class LayerPaint : 50 public Undoable, 51 public CanvasSpecific 52 { 53 public: 54 struct PaintPoint { 55 float x, y, pressure; 56 double dtime; PaintPointPaintPoint57 PaintPoint(): x(0), y(0), pressure(0), dtime(0) { } PaintPointPaintPoint58 PaintPoint(float x, float y, float pressure, double dtime): 59 x(x), y(y), pressure(pressure), dtime(dtime) { } 60 }; 61 62 class PaintStroke { 63 private: 64 static PaintStroke *first, *last; 65 66 PaintStroke *prev, *next; 67 PaintStroke *prevSameLayer, *nextSameLayer; 68 69 etl::handle<synfig::Layer_Bitmap> layer; 70 brushlib::Brush brush_; 71 72 synfig::Surface surface; 73 synfig::Point tl; 74 synfig::Point br; 75 76 synfig::Point new_tl; 77 synfig::Point new_br; 78 79 std::vector<PaintPoint> points; 80 bool prepared; 81 bool applied; 82 83 void paint_prev(synfig::Surface &surface); 84 void paint_self(synfig::Surface &surface); 85 void reset(const PaintPoint &point); 86 87 public: 88 PaintStroke(); 89 ~PaintStroke(); 90 set_layer(etl::handle<synfig::Layer_Bitmap> layer)91 void set_layer(etl::handle<synfig::Layer_Bitmap> layer) { assert(!prepared); this->layer = layer; } get_layer()92 etl::handle<synfig::Layer_Bitmap> get_layer() const { return layer; } 93 brush()94 brushlib::Brush &brush() { assert(!prepared); return brush_; } get_brush()95 const brushlib::Brush &get_brush() const { return brush_; } 96 is_prepared()97 bool is_prepared() const { return prepared; } 98 99 void prepare(); 100 void undo(); 101 void apply(); 102 void add_point_and_apply(const PaintPoint &point); 103 }; 104 105 private: 106 synfig::GUID id; 107 bool applied; 108 109 public: 110 PaintStroke stroke; 111 112 LayerPaint(); 113 114 static ParamVocab get_param_vocab(); 115 static bool is_candidate(const ParamList &x); 116 117 virtual bool set_param(const synfig::String& name, const Param &); 118 virtual bool is_ready()const; 119 120 virtual void perform(); 121 virtual void undo(); 122 123 ACTION_MODULE_EXT 124 }; 125 126 }; // END of namespace action 127 }; // END of namespace studio 128 129 /* === E N D =============================================================== */ 130 131 #endif 132