00001 /*************************************************************************** 00002 * Copyright (C) 2004 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the papyrus library. * 00006 * * 00007 * papyrus is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU Lesser General Public License * 00009 * version 3.0 as published by the Free Software Foundation. * 00010 * * 00011 * papyrus is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU Lesser General Public License version 3.0 for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the papyrus library. If not, see * 00018 * <http://www.gnu.org/licenses/>. * 00019 ***************************************************************************/ 00020 #ifndef PAPYRUSFREEHANDSKETCHER_H 00021 #define PAPYRUSFREEHANDSKETCHER_H 00022 00023 #include <set> 00024 00025 #include <papyrus/pointer.h> 00026 #include <papyrus/stroke.h> 00027 #include <papyrus/controller.h> 00028 #include <papyrus/group.h> 00029 #include <papyrus/polygon.h> 00030 00031 namespace Papyrus 00032 { 00033 00034 typedef enum SKETCH 00035 { 00036 SKETCH_LINE, 00037 SKETCH_POLYGON 00038 } SKETCH; 00039 00043 class FreehandSketcher: public Controller 00044 { 00045 protected: 00046 00047 FreehandSketcher ( const Glib::ustring& id, SKETCH mode=SKETCH_LINE, Stroke::pointer stroke=Stroke::pointer() ); 00048 00049 public: 00050 typedef PapyrusPointer<FreehandSketcher> pointer; 00051 typedef std::set<Group::pointer> Sketchpads; 00052 00053 static FreehandSketcher::pointer create ( const Glib::ustring& id, SKETCH mode=SKETCH_LINE, Stroke::pointer stroke=Stroke::pointer() ); 00054 00055 static FreehandSketcher::pointer create ( SKETCH mode=SKETCH_LINE, Stroke::pointer stroke=Stroke::pointer() ); 00056 00057 virtual ~FreehandSketcher(); 00058 00059 const Sketchpads& sketchpads(); 00060 void add_sketchpad ( Group::pointer sketchpad ); 00061 void remove_sketchpad ( Group::pointer sketchpad ); 00062 00063 SKETCH sketch_mode(); 00064 void set_sketch_mode ( SKETCH mode ); 00065 00066 Stroke::pointer stroke(); 00067 void set_stroke ( Stroke::pointer stroke ); 00068 00069 Fill::pointer fill(); 00070 void set_fill ( Fill::pointer fill ); 00071 00072 void set_movement_threshhold ( double t ); 00073 double get_movement_threshhold(); 00074 00075 protected: 00076 typedef std::map< Group::pointer, Polyline::pointer > Lines; 00077 00078 SKETCH m_mode; 00079 Fill::pointer m_fill; 00080 Stroke::pointer m_stroke; 00081 Lines m_lines; 00082 Papyrus::Polyline::pointer m_current_line; 00083 Sketchpads m_sketchpads; 00084 bool m_drawing; 00085 double m_last_position[2], m_movement_threshhold; 00086 00087 virtual bool on_button_press ( const Event::ButtonPress& event ); 00088 virtual bool on_button_release ( const Event::ButtonRelease& event ); 00089 virtual bool on_motion ( const Event::Motion& event ); 00090 00091 }; 00092 00093 } 00094 00095 #endif