synfig-studio  1.0.3
layerpaint.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
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/layers/layer_bitmap.h>
31 #include <synfigapp/action.h>
32 #include <brushlib.h>
33 
34 /* === M A C R O S ========================================================= */
35 
36 /* === T Y P E D E F S ===================================================== */
37 
38 /* === C L A S S E S & S T R U C T S ======================================= */
39 
40 namespace synfigapp {
41 
42 class Instance;
43 
44 namespace Action {
45 
46 class LayerPaint :
47  public Undoable,
48  public CanvasSpecific
49 {
50 public:
51  struct PaintPoint {
52  float x, y, pressure;
53  double dtime;
54  PaintPoint(): x(0), y(0), pressure(0), dtime(0) { }
55  PaintPoint(float x, float y, float pressure, double dtime):
56  x(x), y(y), pressure(pressure), dtime(dtime) { }
57  };
58 
59  class PaintStroke {
60  private:
61  static PaintStroke *first, *last;
62  PaintStroke *prev, *next;
63  PaintStroke *prevSameLayer, *nextSameLayer;
64 
65  etl::handle<synfig::Layer_Bitmap> layer;
66  brushlib::Brush brush_;
67 
68  synfig::Surface surface;
69  synfig::Point tl;
70  synfig::Point br;
71 
72  synfig::Point new_tl;
73  synfig::Point new_br;
74 
75  std::vector<PaintPoint> points;
76  bool prepared;
77  bool applied;
78 
79  void copy_to_cairo_surface(const synfig::Surface &surface, synfig::CairoSurface &csurface);
80  void paint_prev(synfig::Surface &surface);
81  void paint_self(synfig::Surface &surface);
82  void reset(const PaintPoint &point);
83 
84  public:
85  PaintStroke();
86  ~PaintStroke();
87 
88  void set_layer(etl::handle<synfig::Layer_Bitmap> layer) { assert(!prepared); this->layer = layer; }
89  etl::handle<synfig::Layer_Bitmap> get_layer() const { return layer; }
90 
91  brushlib::Brush &brush() { assert(!prepared); return brush_; }
92  const brushlib::Brush &get_brush() const { return brush_; }
93 
94  bool is_prepared() const { return prepared; }
95 
96  void prepare();
97  void undo();
98  void apply();
99  void add_point_and_apply(const PaintPoint &point);
100  };
101 
103 
104  LayerPaint();
105 
106  static ParamVocab get_param_vocab();
107  static bool is_candidate(const ParamList &x);
108 
109  virtual bool set_param(const synfig::String& name, const Param &);
110  virtual bool is_ready()const;
111 
112  virtual void perform();
113  virtual void undo();
114 
116 };
117 
118 }; // END of namespace action
119 }; // END of namespace studio
120 
121 /* === E N D =============================================================== */
122 
123 #endif