1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
5 ** $Id: duckmatic.h,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_STUDIO_DUCKMATIC_H
26 #define __SYNFIG_STUDIO_DUCKMATIC_H
28 /* === H E A D E R S ======================================================= */
34 #include <ETL/smart_ptr>
37 #include <synfig/vector.h>
38 #include <synfig/string.h>
39 #include <synfig/real.h>
40 #include <sigc++/signal.h>
41 #include <sigc++/object.h>
42 #include <synfig/time.h>
43 #include <synfig/color.h>
44 #include <ETL/smart_ptr>
47 #include <synfig/color.h>
48 #include <synfig/guidset.h>
50 /* === M A C R O S ========================================================= */
52 #define HASH_MAP_H <ext/hash_map>
56 #ifndef __STRING_HASH__
57 #define __STRING_HASH__
60 __gnu_cxx::hash<const char*> hasher_;
62 size_t operator()(const synfig::String& x)const
64 return hasher_(x.c_str());
72 /* === T Y P E D E F S ===================================================== */
74 /* === C L A S S E S & S T R U C T S ======================================= */
76 namespace synfigapp { class ValueDesc; }
77 namespace synfig { class ParamDesc; }
85 class DuckDrag_Base : public etl::shared_object
88 virtual void begin_duck_drag(Duckmatic* duckmatic, const synfig::Vector& begin)=0;
89 virtual bool end_duck_drag(Duckmatic* duckmatic)=0;
90 virtual void duck_drag(Duckmatic* duckmatic, const synfig::Vector& vector)=0;
93 class DuckDrag_Translate : public DuckDrag_Base
95 synfig::Vector last_translate_;
96 synfig::Vector drag_offset_;
98 std::vector<synfig::Vector> positions;
101 void begin_duck_drag(Duckmatic* duckmatic, const synfig::Vector& begin);
102 bool end_duck_drag(Duckmatic* duckmatic);
103 void duck_drag(Duckmatic* duckmatic, const synfig::Vector& vector);
108 ** This class helps organize any of the devices displayed in
109 ** the work area that the user may want to interact with.
110 ** This includes ducks, beziers, and strokes
112 ** \note At some point I'll probably rename this class to "DuckOMatic".
116 friend class DuckDrag_Base;
117 friend class DuckDrag_Translate;
120 -- ** -- P U B L I C T Y P E S ---------------------------------------------
126 typedef __gnu_cxx::hash_map<synfig::GUID,etl::smart_ptr<synfig::Point>,synfig::GUIDHash> DuckDataMap;
128 typedef std::map<synfig::GUID,etl::smart_ptr<synfig::Point> > DuckDataMap;
131 typedef studio::DuckMap DuckMap;
133 typedef studio::Duck Duck;
143 typedef Duck::Type Type;
145 typedef std::list<float> GuideList;
148 -- ** -- P R I V A T E D A T A ---------------------------------------------
157 DuckDataMap duck_data_share_map;
159 std::list<etl::handle<Stroke> > stroke_list_;
161 std::list<etl::handle<Stroke> > persistant_stroke_list_;
163 synfig::GUIDSet selected_ducks;
165 synfig::GUID last_duck_guid;
167 std::list<etl::handle<Bezier> > bezier_list_;
169 //! I cannot recall what this is for
170 //synfig::Vector snap;
172 etl::handle<DuckDrag_Base> duck_dragger_;
174 sigc::signal<void> signal_duck_selection_changed_;
176 sigc::signal<void> signal_strokes_changed_;
178 sigc::signal<void> signal_grid_changed_;
180 mutable sigc::signal<void> signal_sketch_saved_;
182 GuideList guide_list_x_;
183 GuideList guide_list_y_;
185 mutable synfig::String sketch_filename_;
188 -- ** -- P R O T E C T E D D A T A -----------------------------------------
193 etl::handle<Bezier> selected_bezier;
195 synfig::Time cur_time;
197 //! This flag is set if operations should snap to the grid
198 /*! \todo perhaps there should be two of these flags, one for each axis?
199 ** \see show_grid, grid_size */
204 //! This vector describes the grid size.
205 /*! \see grid_snap, show_grid */
206 synfig::Vector grid_size;
208 bool show_persistant_strokes;
213 -- ** -- P R I V A T E M E T H O D S ---------------------------------------
218 synfig::Vector last_translate_;
219 synfig::Vector drag_offset_;
221 //etl::handle<Duck> selected_duck;
225 -- ** -- P U B L I C M E T H O D S -----------------------------------------
231 virtual ~Duckmatic();
233 sigc::signal<void>& signal_duck_selection_changed() { return signal_duck_selection_changed_; }
234 sigc::signal<void>& signal_strokes_changed() { return signal_strokes_changed_; }
235 sigc::signal<void>& signal_grid_changed() { return signal_grid_changed_; }
236 sigc::signal<void>& signal_sketch_saved() { return signal_sketch_saved_; }
238 GuideList& get_guide_list_x() { return guide_list_x_; }
239 GuideList& get_guide_list_y() { return guide_list_y_; }
240 const GuideList& get_guide_list_x()const { return guide_list_x_; }
241 const GuideList& get_guide_list_y()const { return guide_list_y_; }
243 void set_guide_snap(bool x=true);
244 bool get_guide_snap()const { return guide_snap; }
245 void toggle_guide_snap() { set_guide_snap(!get_guide_snap()); }
247 //! Sets the state of the grid snap flag
248 void set_grid_snap(bool x=true);
250 //! Gets the state of the grid snap flag
251 bool get_grid_snap()const { return grid_snap; }
253 void enable_grid_snap() { set_grid_snap(true); }
255 void disable_grid_snap() { set_grid_snap(false); }
257 void toggle_grid_snap() { set_grid_snap(!grid_snap); }
259 synfig::Point snap_point_to_grid(const synfig::Point& x, float radius=0.1)const;
261 bool get_show_persistant_strokes()const { return show_persistant_strokes; }
262 void set_show_persistant_strokes(bool x);
264 //! Sets the size of the grid
265 void set_grid_size(const synfig::Vector &s);
267 //! Returns the size of the grid
268 const synfig::Vector &get_grid_size()const { return grid_size; }
271 const synfig::Time &get_time()const { return cur_time; }
273 bool get_axis_lock()const { return axis_lock; }
274 void set_axis_lock(bool x) { axis_lock=x; }
276 void set_time(synfig::Time x) { cur_time=x; }
278 bool is_duck_group_selectable(const etl::handle<Duck>& x)const;
280 //const DuckMap& duck_map()const { return duck_map; }
281 DuckList get_duck_list()const;
283 const std::list<etl::handle<Bezier> >& bezier_list()const { return bezier_list_; }
285 const std::list<etl::handle<Stroke> >& stroke_list()const { return stroke_list_; }
287 const std::list<etl::handle<Stroke> >& persistant_stroke_list()const { return persistant_stroke_list_; }
289 std::list<etl::handle<Stroke> >& persistant_stroke_list() { return persistant_stroke_list_; }
291 //! \todo We should modify this to support multiple selections
292 etl::handle<Duck> get_selected_duck()const;
294 DuckList get_selected_ducks()const;
296 //! Returns \a true if the given duck is currently selected
297 bool duck_is_selected(const etl::handle<Duck> &duck)const;
300 void refresh_selected_ducks();
302 void clear_selected_ducks();
304 int count_selected_ducks()const;
306 void toggle_select_duck(const etl::handle<Duck> &duck);
308 void select_duck(const etl::handle<Duck> &duck);
310 void select_ducks_in_box(const synfig::Vector& tl,const synfig::Vector& br);
312 void unselect_duck(const etl::handle<Duck> &duck);
314 void start_duck_drag(const synfig::Vector& offset);
315 void translate_selected_ducks(const synfig::Vector& vector);
316 bool end_duck_drag();
318 void signal_edited_selected_ducks();
320 void signal_user_click_selected_ducks(int button);
323 etl::handle<Duck> find_similar_duck(etl::handle<Duck> duck);
324 etl::handle<Duck> add_similar_duck(etl::handle<Duck> duck);
326 void add_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color=synfig::Color(0,0,0));
328 void add_persistant_stroke(etl::smart_ptr<std::list<synfig::Point> > stroke_point_list, const synfig::Color& color=synfig::Color(0,0,0));
330 void clear_persistant_strokes();
332 void add_duck(const etl::handle<Duck> &duck);
334 void add_bezier(const etl::handle<Bezier> &bezier);
336 void erase_duck(const etl::handle<Duck> &duck);
338 void erase_bezier(const etl::handle<Bezier> &bezier);
340 //! Returns the last duck added
341 etl::handle<Duck> last_duck()const;
343 etl::handle<Bezier> last_bezier()const;
345 //! \note parameter is in canvas coordinates
346 /*! A radius of "zero" will have an unlimited radius */
347 etl::handle<Duck> find_duck(synfig::Point pos, synfig::Real radius=0, Duck::Type type=Duck::TYPE_DEFAULT);
349 GuideList::iterator find_guide_x(synfig::Point pos, float radius=0.1);
350 GuideList::iterator find_guide_y(synfig::Point pos, float radius=0.1);
351 GuideList::const_iterator find_guide_x(synfig::Point pos, float radius=0.1)const { return const_cast<Duckmatic*>(this)->find_guide_x(pos,radius); }
352 GuideList::const_iterator find_guide_y(synfig::Point pos, float radius=0.1)const { return const_cast<Duckmatic*>(this)->find_guide_y(pos,radius); }
354 //! \note parameter is in canvas coordinates
355 /*! A radius of "zero" will have an unlimited radius */
356 //etl::handle<Bezier> find_bezier(synfig::Point pos, synfig::Real radius=0);
358 //! \note parameter is in canvas coordinates
359 /*! A radius of "zero" will have an unlimited radius */
360 etl::handle<Bezier> find_bezier(synfig::Point pos, synfig::Real radius=0, float* location=0);
362 etl::handle<Bezier> find_bezier(synfig::Point pos, synfig::Real scale, synfig::Real radius, float* location=0);
364 bool add_to_ducks(const synfigapp::ValueDesc& value_desc,etl::handle<CanvasView> canvas_view, const synfig::TransformStack& transform_stack_, synfig::ParamDesc *param_desc=0, int multiple=0);
367 void set_type_mask(Type x) { type_mask=x; }
370 Type get_type_mask()const { return type_mask; }
372 void select_all_ducks();
376 bool save_sketch(const synfig::String& filename)const;
377 bool load_sketch(const synfig::String& filename);
378 const synfig::String& get_sketch_filename()const { return sketch_filename_; }
380 void set_duck_dragger(etl::handle<DuckDrag_Base> x) { duck_dragger_=x; }
381 etl::handle<DuckDrag_Base> get_duck_dragger()const { return duck_dragger_; }
382 void clear_duck_dragger() { duck_dragger_=new DuckDrag_Translate(); }
383 }; // END of class Duckmatic
386 /*! \class Duckmatic::Push
388 class Duckmatic::Push
390 Duckmatic *duckmatic_;
392 std::list<etl::handle<Bezier> > bezier_list_;
393 std::list<etl::handle<Stroke> > stroke_list_;
394 DuckDataMap duck_data_share_map;
395 etl::handle<DuckDrag_Base> duck_dragger_;
400 Push(Duckmatic *duckmatic_);
403 }; // END of class Duckmatic::Push
405 /*! \struct Duckmatic::Bezier
407 struct Duckmatic::Bezier : public etl::shared_object
410 sigc::signal<void,float> signal_user_click_[5];
413 etl::handle<Duck> p1,p2,c1,c2;
414 bool is_valid()const { return p1 && p2 && c1 && c2; }
416 sigc::signal<void,float> &signal_user_click(int i=0) { assert(i>=0); assert(i<5); return signal_user_click_[i]; }
417 }; // END of struct Duckmatic::Bezier
419 /*! \struct Duckmatic::Stroke
421 struct Duckmatic::Stroke : public etl::shared_object
424 sigc::signal<void,float> signal_user_click_[5];
427 etl::smart_ptr<std::list<synfig::Point> > stroke_data;
431 bool is_valid()const { return (bool)stroke_data; }
433 sigc::signal<void,float> &signal_user_click(int i=0) { assert(i>=0); assert(i<5); return signal_user_click_[i]; }
434 }; // END of struct Duckmatic::Bezier
436 }; // END of namespace studio
438 /* === E N D =============================================================== */