source: synfigstudio/trunk/fuentes/src/gui/workarearenderer/renderer_dragbox.cpp @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 7.0 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file renderer_dragbox.cpp
3**  \brief Renderer_Dragbox classe is used to display in the workarea
4**  the interactive selection box, and select workarea objects (actually handles)
5**  accordingly to the shift/control modifier keys.
6**
7**      $Id$
8**
9**      \legal
10**      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
11**  Copyright (c) 2011 Nikita Kitaev
12**  Copyright (c) 2015 Blanchi Jérôme
13**
14**      This package is free software; you can redistribute it and/or
15**      modify it under the terms of the GNU General Public License as
16**      published by the Free Software Foundation; either version 2 of
17**      the License, or (at your option) any later version.
18**
19**      This package is distributed in the hope that it will be useful,
20**      but WITHOUT ANY WARRANTY; without even the implied warranty of
21**      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22**      General Public License for more details.
23**      \endlegal
24*/
25/* ========================================================================= */
26
27/* === H E A D E R S ======================================================= */
28
29#ifdef USING_PCH
30#       include "pch.h"
31#else
32#ifdef HAVE_CONFIG_H
33#       include <config.h>
34#endif
35
36#include "renderer_dragbox.h"
37#include "workarea.h"
38#include <ETL/misc>
39
40#include "general.h"
41
42#endif
43
44/* === U S I N G =========================================================== */
45
46using namespace std;
47using namespace etl;
48using namespace synfig;
49using namespace studio;
50
51/* === M A C R O S ========================================================= */
52
53/* === G L O B A L S ======================================================= */
54
55/* === P R O C E D U R E S ================================================= */
56
57/* === M E T H O D S ======================================================= */
58
59Renderer_Dragbox::~Renderer_Dragbox()
60{
61}
62
63const synfig::Point&
64Renderer_Dragbox::get_drag_point()const
65{
66        return get_work_area()->get_drag_point();
67}
68
69const synfig::Point&
70Renderer_Dragbox::get_curr_point()const
71{
72        return get_work_area()->get_cursor_pos();
73}
74
75bool
76Renderer_Dragbox::get_enabled_vfunc()const
77{
78        return get_work_area()->get_dragging_mode()==WorkArea::DRAG_BOX;
79}
80
81bool
82Renderer_Dragbox::event_vfunc(GdkEvent* event)
83{
84    switch(event->type)
85    {
86    case GDK_BUTTON_PRESS:
87        {
88// Seems to be not received ! event_mask ?
89        }
90        break;
91    case GDK_MOTION_NOTIFY:
92    {
93        //!TODO : Make HARDCODED shortcut key access configure ready.
94        if(get_work_area()->get_dragging_mode() == WorkArea::DRAG_BOX)
95        {
96            if (drag_paused)
97            {
98                //! Save the handles (ducks) selection and global context
99                handles_all_ = get_work_area()->get_duck_list();
100                handles_selected_= get_work_area()->get_selected_ducks();
101                DuckList::const_iterator iter;
102                //! The selection context guid set is used for quicker lookup
103                handles_selected_guid_.clear();
104                for(iter=handles_selected_.begin();iter!=handles_selected_.end();++iter)
105                    handles_selected_guid_.insert((*iter)->get_guid());
106
107                drag_paused = false;
108                //! Do nothing this time.
109                break;
110            }
111            const synfig::Point& curr_point(get_curr_point());
112            const synfig::Point& drag_point(get_drag_point());
113            Gdk::ModifierType modifier(Gdk::ModifierType(0));
114            modifier = Gdk::ModifierType(event->button.state);
115
116            // UI SPECIFICATION : When dragging a box around some handles (ducks):
117            // SHIFT selects; CTRL toggles; SHIFT+CTRL unselects; <none> clears all then selects
118            // CTRL Has priority under SHIFT
119
120            //! Start by cleaning the field
121            get_work_area()->clear_selected_ducks();
122            if(modifier&(GDK_SHIFT_MASK|GDK_CONTROL_MASK))
123            {
124
125                DuckList::const_iterator iter;
126                for(iter=handles_selected_.begin();iter!=handles_selected_.end();++iter)
127                {
128                    get_work_area()->select_duck((*iter));
129                }
130
131                if (modifier&GDK_CONTROL_MASK)
132                {
133                   //! Treat what's in the box accordingly to the selection context
134                    DuckList handles_in_box = get_work_area()->get_ducks_in_box(drag_point,curr_point);
135                    for(iter=handles_in_box.begin();iter!=handles_in_box.end();++iter)
136                    {
137                        //! Do the job only on selectable handles (not origin handle)
138                        if(get_work_area()->is_duck_group_selectable(*iter))
139                        {
140                            if(!handles_selected_guid_.count((*iter)->get_guid()))
141                                get_work_area()->select_duck((*iter));
142                            else
143                                get_work_area()->unselect_duck((*iter));
144                        }
145                    }
146                }
147            }
148
149            if (!(modifier&GDK_CONTROL_MASK))
150            {
151                get_work_area()->select_ducks_in_box(drag_point,curr_point);
152            }
153        }
154    }
155    break;
156    case GDK_BUTTON_RELEASE:
157    {
158        drag_paused = true;
159    }
160        break;
161
162    default:
163        break;
164    }
165
166    return false;
167}
168
169void
170Renderer_Dragbox::render_vfunc(
171        const Glib::RefPtr<Gdk::Window>& drawable,
172        const Gdk::Rectangle& /*expose_area*/
173)
174{
175        assert(get_work_area());
176        if(!get_work_area() || drag_paused)
177                return;
178
179        // const synfig::Vector focus_point(get_work_area()->get_focus_point());
180    // Warning : Unused focus_point
181    //int drawable_w = drawable->get_width();
182    // Warning : Unused drawable_w
183    //int drawable_h = drawable->get_height();
184    // Warning : Unused drawable_h
185
186        Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context();
187
188        const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
189        const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
190        const float pw(get_pw()),ph(get_ph());
191
192        const synfig::Point& curr_point(get_curr_point());
193        const synfig::Point& drag_point(get_drag_point());
194
195        {
196            //!TODO : make HARDCODED Ui specification configure ready
197                cr->save();
198                cr->set_line_cap(Cairo::LINE_CAP_BUTT);
199                cr->set_line_join(Cairo::LINE_JOIN_MITER);
200                cr->set_antialias(Cairo::ANTIALIAS_NONE);
201
202                cr->set_line_width(1.0);
203                cr->set_source_rgb(0,0,0);
204                std::valarray<double> dashes(2);
205                dashes[0]=5.0;
206                dashes[1]=5.0;
207                cr->set_dash(dashes, 0);
208
209                Point tl(std::min(drag_point[0],curr_point[0]),std::min(drag_point[1],curr_point[1]));
210                Point br(std::max(drag_point[0],curr_point[0]),std::max(drag_point[1],curr_point[1]));
211
212                tl[0]=(tl[0]-window_startx)/pw;
213                tl[1]=(tl[1]-window_starty)/ph;
214                br[0]=(br[0]-window_startx)/pw;
215                br[1]=(br[1]-window_starty)/ph;
216                if(tl[0]>br[0])
217                        swap(tl[0],br[0]);
218                if(tl[1]>br[1])
219                        swap(tl[1],br[1]);
220
221                cr->rectangle(
222                        tl[0],
223                        tl[1],
224                        br[0]-tl[0],
225                        br[1]-tl[1]
226                );
227                cr->stroke();
228
229                cr->restore();
230        }
231}
Note: See TracBrowser for help on using the repository browser.