Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-studio / trunk / src / gtkmm / state_zoom.cpp
index e7d2707..57a2522 100644 (file)
@@ -1,20 +1,22 @@
 /* === S Y N F I G ========================================================= */
 /*!    \file state_zoom.cpp
-**     \brief Zoom Toole Implementation File
+**     \brief Zoom Tool Implementation File
 **
-**     $Id: state_zoom.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
+**     $Id$
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**  Copyright (c) 2008 Chris Moore
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **     \endlegal
 */
 /* ========================================================================= */
 #include "canvasview.h"
 #include "workarea.h"
 #include "app.h"
-#include "dialog_tooloptions.h"
 #include "toolbox.h"
 #include <synfigapp/main.h>
 
+#include "general.h"
+
 #endif
 
 /* === U S I N G =========================================================== */
@@ -66,26 +69,17 @@ class studio::StateZoom_Context : public sigc::trackable
 {
        etl::handle<CanvasView> canvas_view_;
        CanvasView::IsWorking is_working;
-       
+
        Point p1,p2;
-       
+
        bool prev_workarea_layer_status_;
-               
-       //Toolbox settings
-       synfigapp::Settings& settings;
-       
-       //Toolbox display
-       Gtk::Table options_table;
-       
-public:
 
-       void refresh_tool_options(); //to refresh the toolbox   
+public:
 
        //events
        Smach::event_result event_stop_handler(const Smach::event& x);
        Smach::event_result event_refresh_handler(const Smach::event& x);
        Smach::event_result event_mouse_click_handler(const Smach::event& x);
-       Smach::event_result event_refresh_tool_options(const Smach::event& x);
 
        //constructor destructor
        StateZoom_Context(CanvasView* canvas_view);
@@ -96,15 +90,10 @@ public:
        etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
        synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
        WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
-       
-       //Modifying settings etc.
-       void load_settings();
-       void save_settings();
-       void reset();
-       
+
        //void zoom(const Point& p1, const Point& p2);
-       
-};     // END of class StateGradient_Context
+
+};     // END of class StateZoom_Context
 
 /* === M E T H O D S ======================================================= */
 
@@ -118,69 +107,33 @@ StateZoom::StateZoom():
        insert(event_def(EVENT_WORKAREA_BOX,&StateZoom_Context::event_mouse_click_handler));
        //insert(event_def(EVENT_WORKAREA_BUTTON_CLICK,&StateZoom_Context::event_mouse_click_handler));
        insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateZoom_Context::event_mouse_click_handler));
-       insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateZoom_Context::event_refresh_tool_options));
-}      
-
-StateZoom::~StateZoom()
-{
 }
 
-void
-StateZoom_Context::load_settings()
-{      
-       String value;
-       
-       //parse the arguments yargh!
-       /*if(settings.get_value("circle.feather",value))
-               set_feather(atof(value.c_str()));
-       else
-               set_feather(0);*/       
-}
-
-void
-StateZoom_Context::save_settings()
-{
-       //settings.set_value("circle.fallofftype",strprintf("%d",get_falloff()));
-}
-
-void
-StateZoom_Context::reset()
+StateZoom::~StateZoom()
 {
-       //refresh_ducks();
 }
 
 StateZoom_Context::StateZoom_Context(CanvasView* canvas_view):
        canvas_view_(canvas_view),
        is_working(*canvas_view),
-       prev_workarea_layer_status_(get_work_area()->allow_layer_clicks),
-       settings(synfigapp::Main::get_selected_input_device()->settings())
+       prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks())
 {
-       // Set up the tool options dialog
-       //options_table.attach(*manage(new Gtk::Label(_("Zoom Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);        
-       
-       load_settings();
-
-       options_table.show_all();
-       
-       refresh_tool_options();
-       App::dialog_tool_options->present();
-
        // Turn off layer clicking
-       get_work_area()->allow_layer_clicks=false;
-       
+       get_work_area()->set_allow_layer_clicks(false);
+
        // clear out the ducks
        get_work_area()->clear_ducks(); //???
-       
+
        // Refresh the work area
        get_work_area()->queue_draw();
-       
+
        // Hide the tables if they are showing
        //prev_table_status=get_canvas_view()->tables_are_visible();
        //if(prev_table_status)get_canvas_view()->hide_tables();
-               
-       // Hide the time bar
-       //get_canvas_view()->hide_timebar();
-       
+
+       // Disable the time bar
+       //get_canvas_view()->set_sensitive_timebar(false);
+
        // Connect a signal
        //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateZoom_Context::on_user_click));
        get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR);
@@ -188,39 +141,18 @@ StateZoom_Context::StateZoom_Context(CanvasView* canvas_view):
        App::toolbox->refresh();
 }
 
-void
-StateZoom_Context::refresh_tool_options()
-{
-       App::dialog_tool_options->clear();
-       App::dialog_tool_options->set_widget(options_table);
-       App::dialog_tool_options->set_local_name(_("Zoom Tool"));
-       App::dialog_tool_options->set_name("zoom");
-}
-
-Smach::event_result
-StateZoom_Context::event_refresh_tool_options(const Smach::event& x)
-{
-       refresh_tool_options();
-       return Smach::RESULT_ACCEPT;
-}
-
 StateZoom_Context::~StateZoom_Context()
 {
-       save_settings();
-
        // Restore layer clicking
-       get_work_area()->allow_layer_clicks=prev_workarea_layer_status_;
+       get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
        get_canvas_view()->work_area->reset_cursor();
 
-       App::dialog_tool_options->clear();
-
-       // Show the time bar
-       if(get_canvas_view()->get_canvas()->rend_desc().get_time_start()!=get_canvas_view()->get_canvas()->rend_desc().get_time_end())
-               get_canvas_view()->show_timebar();
+       // Enable the time bar
+       //get_canvas_view()->set_sensitive_timebar(true);
 
        // Bring back the tables if they were out before
        //if(prev_table_status)get_canvas_view()->show_tables();
-                       
+
        // Refresh the work area
        get_work_area()->queue_draw();
 
@@ -230,13 +162,13 @@ StateZoom_Context::~StateZoom_Context()
 }
 
 Smach::event_result
-StateZoom_Context::event_stop_handler(const Smach::event& x)
+StateZoom_Context::event_stop_handler(const Smach::event& /*x*/)
 {
        throw Smach::egress_exception();
 }
 
 Smach::event_result
-StateZoom_Context::event_refresh_handler(const Smach::event& x)
+StateZoom_Context::event_refresh_handler(const Smach::event& /*x*/)
 {
        return Smach::RESULT_ACCEPT;
 }
@@ -247,68 +179,65 @@ StateZoom_Context::event_mouse_click_handler(const Smach::event& x)
        if(x.key==EVENT_WORKAREA_BOX)
        {
                const EventBox& event(*reinterpret_cast<const EventBox*>(&x));
-               
+
                if(event.button==BUTTON_LEFT)
                {
-                       //respond to event box...
-                       
-                       
-                       //Center the new position at the center of the box
-                       
-                       //OH MY GOD HACK - the space is -1* and offset (by the value of the center of the canvas)...
+                       Point tl = get_work_area()->get_window_tl();
+                       Point br = get_work_area()->get_window_br();
+                       Vector  window_span = br - tl, window_middle = (br+tl)/2;
+                       Vector  box_span = event.p2 - event.p1, box_middle = (event.p1+event.p2)/2;
                        Point newpos;
+                       float zoom;
+
+                       if(event.modifier & Gdk::CONTROL_MASK) //zoom out...
                        {
-                               const Point evcenter = (event.p1+event.p2)/2;
-                               const Point realcenter = (get_work_area()->get_window_tl() + get_work_area()->get_window_br())/2;
-                               newpos = -(evcenter - realcenter) + get_work_area()->get_focus_point();
+                               if (window_span[0] == 0 || window_span[1] == 0) zoom = 1;
+                               else zoom = max(abs(box_span[0]/window_span[0]), abs(box_span[1]/window_span[1]));
+
+                               // focus_point is -1 times the real position for some reason...
+                               // center the window so the old contents fill the drawn box
+                               newpos = -((window_middle - box_middle)/zoom + window_middle);
                        }
-                       
-                       //The zoom will be whatever the required factor to convert current box size to desired box size
-                       Point tl = get_work_area()->get_window_tl();
-                       Point br = get_work_area()->get_window_br();
-                       
-                       Vector  span = br - tl;
-                       Vector  v = event.p2 - event.p1;
-       
-                       //get the minimum zoom as long as it's greater than 1...
-                       v[0] = abs(v[0])/abs(span[0]);
-                       v[1] = abs(v[1])/abs(span[1]);
-                       
-                       float zdiv = max(v[0],v[1]);
-                       if(zdiv < 1 && zdiv > 0) //must be zoomable
+                       else                            // zoom in
                        {
-                               get_work_area()->set_focus_point(newpos);                       
-                               get_work_area()->set_zoom(get_work_area()->get_zoom()/zdiv);
+                               if (box_span[0] == 0 || box_span[1] == 0) zoom = 1;
+                               else zoom = min(abs(window_span[0]/box_span[0]), abs(window_span[1]/box_span[1]));
+
+                               // center the window at the center of the box
+                               newpos = -(-get_work_area()->get_focus_point() + (box_middle - window_middle));
                        }
-                       
+
+                       get_work_area()->set_focus_point(newpos);
+                       get_work_area()->set_zoom(get_work_area()->get_zoom()*zoom);
+
                        return Smach::RESULT_ACCEPT;
                }
        }
-       
+
        if(x.key==EVENT_WORKAREA_MOUSE_BUTTON_UP)
        {
                const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
-               
+
                if(event.button==BUTTON_LEFT)
                {
                        Point evpos;
-                       
+
                        //make the event pos be in the same space...
                        //   The weird ass inverted center normalized space...
                        {
                                const Point realcenter = (get_work_area()->get_window_tl() + get_work_area()->get_window_br())/2;
                                evpos = -(event.pos - realcenter) + get_work_area()->get_focus_point();
                        }
-                       
+
                        /*      Zooming:
                                focus point must zoom about the point evpos...
-                       
+
                                trans about an origin not 0:
                                p' = A(p - o) + o
                        */
-                       
+
                        Vector v = get_work_area()->get_focus_point() - evpos;
-                       
+
                        if(event.modifier & Gdk::CONTROL_MASK) //zoom out...
                        {
                                v*=ZOOMFACTOR;
@@ -322,7 +251,7 @@ StateZoom_Context::event_mouse_click_handler(const Smach::event& x)
                                get_work_area()->set_focus_point(evpos + v);
                                get_work_area()->set_zoom(get_work_area()->get_zoom()*ZOOMFACTOR);
                        }
-               
+
                        return Smach::RESULT_ACCEPT;
                }
        }