freehandsketcher.h

00001 /***************************************************************************
00002 *   Copyright (C) 2004 by Rick L. Vinyard, Jr.                            *
00003 *   rvinyard@cs.nmsu.edu                                                  *
00004 *                                                                         *
00005 *   This program is free software; you can redistribute it and/or modify  *
00006 *   it under the terms of the GNU Lesser General Public License as        *
00007 *   published by the Free Software Foundation version 2.1.                *
00008 *                                                                         *
00009 *   This program is distributed in the hope that it will be useful,       *
00010 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012 *   GNU General Public License for more details.                          *
00013 *                                                                         *
00014 *   You should have received a copy of the GNU Lesser General Public      *
00015 *   License along with this library; if not, write to the                 *
00016 *   Free Software Foundation, Inc.,                                       *
00017 *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018 ***************************************************************************/
00019 #ifndef PAPYRUSFREEHANDSKETCHER_H
00020 #define PAPYRUSFREEHANDSKETCHER_H
00021 
00022 #include <set>
00023 
00024 #include <papyrus/smart_pointer.h>
00025 #include <papyrus/linestyle.h>
00026 #include <papyrus/controller.h>
00027 #include <papyrus/group.h>
00028 #include <papyrus/polygon.h>
00029 
00030 namespace Papyrus {
00031 
00032 typedef enum SKETCH {
00033   SKETCH_LINE,
00034   SKETCH_POLYGON
00035 } SKETCH;
00036 
00040 class FreehandSketcher: public Controller {
00041 public:
00042   typedef PapyrusSmartPointer<FreehandSketcher> pointer;
00043   typedef std::set<Group::pointer> Sketchpads;
00044 
00045   FreehandSketcher(SKETCH mode=SKETCH_LINE, const LineStyle& linestyle=LineStyle());
00046 
00047   static FreehandSketcher::pointer create( SKETCH mode=SKETCH_LINE, const LineStyle& linestyle=LineStyle() );
00048 
00049     virtual ~FreehandSketcher();
00050 
00051     const Sketchpads& sketchpads();
00052     void add_sketchpad( Group::pointer sketchpad );
00053     void remove_sketchpad( Group::pointer sketchpad );
00054 
00055     SKETCH sketch_mode();
00056     void set_sketch_mode(SKETCH mode);
00057 
00058     LineStyle& line_style();
00059     void set_line_style( const LineStyle& line_style );
00060 
00061     Cairo::RefPtr<Cairo::Pattern> get_fill();
00062     void set_fill(Cairo::RefPtr<Cairo::Pattern> fill);
00063 
00064     void set_movement_threshhold(double t);
00065     double get_movement_threshhold();
00066 
00067 protected:
00068   typedef std::map< Group::pointer, Polyline::pointer > Lines;
00069 
00070   SKETCH m_mode;
00071   LineStyle m_line_style;
00072   Lines m_lines;
00073   Papyrus::Polyline::pointer m_current_line;
00074   Sketchpads m_sketchpads;
00075   bool m_drawing;
00076   double m_last_position[2], m_movement_threshhold;
00077     Cairo::RefPtr<Cairo::Pattern> m_fill;
00078 
00079     virtual bool on_button_press(const Event::ButtonPress& event);
00080     virtual bool on_button_release(const Event::ButtonRelease& event);
00081     virtual bool on_motion(const Event::Motion& event);
00082 
00083 };
00084 
00085 }
00086 
00087 #endif

Generated on Sun Mar 11 10:01:28 2007 by  doxygen 1.5.1