libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GtkCRNDrawingPanel.h
Go to the documentation of this file.
1 /* Copyright 2010-2016 CoReNum, INSA-Lyon, ENS-Lyon
2  *
3  * This file is part of libgtkcrnmm.
4  *
5  * libgtkcrnmm is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libgtkcrnmm is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libgtkcrnmm. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: GtkCRNDrawingPanel.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef GtkCRNDrawingPanel_HEADER
23 #define GtkCRNDrawingPanel_HEADER
24 
25 #include <libgtkcrnmm_config.h>
26 
27 #ifndef CRN_USING_GTKMM3
28 
29 #include <gtkmm.h>
31 #include <GtkCRNColorAction.h>
32 #include <GtkCRNScaleAction.h>
33 
34 namespace GtkCRN
35 {
42  class DrawingPanel: public Gtk::DrawingArea
43  {
44  public:
46  DrawingPanel();
47  virtual ~DrawingPanel() override {}
48 
57  Glib::RefPtr<Gtk::ActionGroup> get_actions() { return actions; }
59  void set_zoom(double z);
60 
62  void clear();
63 
65 #ifdef CRN_USING_GTKMM3
66  Gdk::RGBA get_background() const;
67 #else /* CRN_USING_GTKMM3 */
68  Gdk::Color get_background() const;
69 #endif /* CRN_USING_GTKMM3 */
70 
71 #ifdef CRN_USING_GTKMM3
72  void set_background(const Gdk::RGBA& col);
73 #else /* CRN_USING_GTKMM3 */
74  void set_background(const Gdk::Color& col);
75 #endif /* CRN_USING_GTKMM3 */
76 
77 #ifdef CRN_USING_GTKMM3
78  Gdk::RGBA get_foreground() const;
79 #else /* CRN_USING_GTKMM3 */
80  Gdk::Color get_foreground() const;
81 #endif /* CRN_USING_GTKMM3 */
82 
83 #ifdef CRN_USING_GTKMM3
84  void set_foreground(const Gdk::RGBA& col);
85 #else /* CRN_USING_GTKMM3 */
86  void set_foreground(const Gdk::Color& col);
87 #endif /* CRN_USING_GTKMM3 */
88 
90  Glib::RefPtr<Gdk::Pixbuf> create_image();
91 
92  private:
94  bool draw();
96  bool on_button_press(GdkEventButton *ev);
98  bool on_motion(GdkEventMotion *ev);
100 #ifdef CRN_USING_GTKMM3
101  bool on_expose(const Cairo::RefPtr<Cairo::Context> &);
102 #else /* CRN_USING_GTKMM3 */
103  bool on_expose(GdkEventExpose *ev);
104 #endif /* CRN_USING_GTKMM3 */
105 
106  void modify_thickness(double val);
108  void on_thickness_set();
109 
110  double thickness;
111  double zoom;
112  std::vector<std::vector<crn::Point2DDouble>> stroke_list;
114  Glib::RefPtr<Gtk::ActionGroup> actions;
115 #ifndef CRN_USING_GTKMM3
116  Glib::RefPtr<GtkCRN::ColorAction> bg_act, fg_act;
117  Glib::RefPtr<GtkCRN::ScaleAction> thick_act;
118 #endif
119  };
120 }
121 
122 #endif
123 
124 #endif
Glib::RefPtr< Gdk::Pixbuf > create_image()
Renders the panel to a Pixbuf.
Glib::RefPtr< Gtk::ActionGroup > get_actions()
Returns actions associated to the drawing panel. Valid actions are:
Gdk::Color get_background() const
Gets the background color.
void set_zoom(double z)
Sets the zoom level.
void set_background(const Gdk::Color &col)
Sets the background color.
void clear()
Clears the panel.
A widget that allows to draw on it.
void set_foreground(const Gdk::Color &col)
Sets the foreground color.
virtual ~DrawingPanel() override
Gdk::Color get_foreground() const
Gets the foreground color.