From 2081f34927d55fee5c3de25b5ed4bc81e2de216f Mon Sep 17 00:00:00 2001 From: Nikita Kitaev Date: Sat, 22 May 2010 15:09:35 -0700 Subject: [PATCH] Change mirror tool options Mirror vertically by default, horizontally if shift key is pressed. Remove checkbox options so that they don't conflict with the keyboard. --- .../src/gtkmm/mod_mirror/state_mirror.cpp | 97 ++++++---------------- 1 file changed, 24 insertions(+), 73 deletions(-) diff --git a/synfig-studio/src/gtkmm/mod_mirror/state_mirror.cpp b/synfig-studio/src/gtkmm/mod_mirror/state_mirror.cpp index 9316b29..89b39c9 100644 --- a/synfig-studio/src/gtkmm/mod_mirror/state_mirror.cpp +++ b/synfig-studio/src/gtkmm/mod_mirror/state_mirror.cpp @@ -95,40 +95,25 @@ class studio::StateMirror_Context : public sigc::trackable etl::handle canvas_view_; CanvasView::IsWorking is_working; - synfigapp::Settings& settings; - - sigc::connection keypress_connect; - sigc::connection keyrelease_connect; - etl::handle duck_dragger_; Gtk::Table options_table; - Gtk::RadioButton::Group radiobutton_group; - Gtk::RadioButton radiobutton_axis_x; - Gtk::RadioButton radiobutton_axis_y; - public: - Axis get_axis()const { return radiobutton_axis_x.get_active()?AXIS_X:AXIS_Y; } + Axis get_axis()const { return duck_dragger_->axis; } void set_axis(Axis a) { - if(a==AXIS_X) - radiobutton_axis_x.set_active(true); - else - radiobutton_axis_y.set_active(true); - - duck_dragger_->axis=get_axis(); - } - - void update_axes() - { - duck_dragger_->axis=get_axis(); - get_work_area()->set_cursor(get_axis() == AXIS_X?Gdk::SB_H_DOUBLE_ARROW:Gdk::SB_V_DOUBLE_ARROW); + if (duck_dragger_->axis != a) + { + duck_dragger_->axis = a; + get_work_area()->set_cursor(get_axis() == AXIS_X?Gdk::SB_H_DOUBLE_ARROW:Gdk::SB_V_DOUBLE_ARROW); + } } Smach::event_result event_stop_handler(const Smach::event& x); Smach::event_result event_refresh_tool_options(const Smach::event& x); + Smach::event_result event_mouse_motion_handler(const Smach::event& x); void refresh_tool_options(); @@ -141,10 +126,6 @@ public: synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();} WorkArea * get_work_area()const{return canvas_view_->get_work_area();} - void load_settings(); - void save_settings(); - - bool key_event(GdkEventKey *event); }; // END of class StateMirror_Context /* === M E T H O D S ======================================================= */ @@ -154,43 +135,22 @@ StateMirror::StateMirror(): { insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateMirror_Context::event_refresh_tool_options)); insert(event_def(EVENT_STOP,&StateMirror_Context::event_stop_handler)); + insert(event_def(EVENT_WORKAREA_MOUSE_MOTION, &StateMirror_Context::event_mouse_motion_handler)); + insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG, &StateMirror_Context::event_mouse_motion_handler)); } StateMirror::~StateMirror() { } -void -StateMirror_Context::load_settings() -{ - String value; - - settings.get_value("mirror.axis",value); - set_axis((Axis)atoi(value.c_str())); -} - -void -StateMirror_Context::save_settings() -{ - settings.set_value("mirror.lock_aspect",strprintf("%d",(int)get_axis())); -} - StateMirror_Context::StateMirror_Context(CanvasView* canvas_view): canvas_view_(canvas_view), is_working(*canvas_view), - settings(synfigapp::Main::get_selected_input_device()->settings()), - duck_dragger_(new DuckDrag_Mirror()), - radiobutton_axis_x(radiobutton_group,_("Horizontal")), - radiobutton_axis_y(radiobutton_group,_("Vertical")) + duck_dragger_(new DuckDrag_Mirror()) { // Set up the tool options dialog options_table.attach(*manage(new Gtk::Label(_("Mirror Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(radiobutton_axis_x, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(radiobutton_axis_y, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - options_table.attach(*manage(new Gtk::Label(_("(Shift key toggles axis)"))), 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - - radiobutton_axis_x.signal_toggled().connect(sigc::mem_fun(*this,&StateMirror_Context::update_axes)); - radiobutton_axis_y.signal_toggled().connect(sigc::mem_fun(*this,&StateMirror_Context::update_axes)); + options_table.attach(*manage(new Gtk::Label(_("Shift to mirror horizontally"), Gtk::ALIGN_LEFT)), 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); options_table.show_all(); refresh_tool_options(); @@ -199,28 +159,12 @@ StateMirror_Context::StateMirror_Context(CanvasView* canvas_view): get_work_area()->set_allow_layer_clicks(true); get_work_area()->set_duck_dragger(duck_dragger_); - keypress_connect=get_work_area()->signal_key_press_event().connect(sigc::mem_fun(*this,&StateMirror_Context::key_event),false); - keyrelease_connect=get_work_area()->signal_key_release_event().connect(sigc::mem_fun(*this,&StateMirror_Context::key_event),false); - get_work_area()->set_cursor(Gdk::SB_H_DOUBLE_ARROW); // get_work_area()->reset_cursor(); App::toolbox->refresh(); - set_axis(AXIS_X); - load_settings(); -} - -bool -StateMirror_Context::key_event(GdkEventKey *event) -{ - if (event->keyval==GDK_Shift_L || event->keyval==GDK_Shift_R ) - { - set_axis(get_axis()==AXIS_X ? AXIS_Y:AXIS_X); - update_axes(); - } - - return false; //Pass on the event to other handlers, just in case + set_axis(AXIS_Y); } void @@ -246,16 +190,23 @@ StateMirror_Context::event_stop_handler(const Smach::event& /*x*/) return Smach::RESULT_OK; } -StateMirror_Context::~StateMirror_Context() +Smach::event_result +StateMirror_Context::event_mouse_motion_handler(const Smach::event& x) { - save_settings(); + // synfig::info("STATE NORMAL: Received mouse button down Event"); + + const EventMouse& event(*reinterpret_cast(&x)); + + set_axis(event.modifier&GDK_SHIFT_MASK ? AXIS_X : AXIS_Y); + return Smach::RESULT_OK; +} + +StateMirror_Context::~StateMirror_Context() +{ get_work_area()->clear_duck_dragger(); get_work_area()->reset_cursor(); - keypress_connect.disconnect(); - keyrelease_connect.disconnect(); - App::dialog_tool_options->clear(); App::toolbox->refresh(); -- 2.7.4