X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fstate_polygon.cpp;h=a5498fe87733e7ed6d8c180075d237690b3925c0;hb=756c0d29ac1742f231e6615f9a577e574e35a4af;hp=cd185fcfc148f2d48c54d2aa947ca8397b4c177e;hpb=3a3c4bca3a17137bec5d7960560934b91ef4146e;p=synfig.git diff --git a/synfig-studio/trunk/src/gtkmm/state_polygon.cpp b/synfig-studio/trunk/src/gtkmm/state_polygon.cpp index cd185fc..a5498fe 100644 --- a/synfig-studio/trunk/src/gtkmm/state_polygon.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_polygon.cpp @@ -1,20 +1,22 @@ -/* === S I N F G =========================================================== */ -/*! \file rotoscope_polygon.cpp +/* === S Y N F I G ========================================================= */ +/*! \file state_polygon.cpp ** \brief Template File ** -** $Id: state_polygon.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 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 */ /* ========================================================================= */ @@ -31,20 +33,22 @@ #include #include -#include -#include +#include +#include #include "state_polygon.h" #include "canvasview.h" #include "workarea.h" #include "app.h" -#include +#include #include "event_mouse.h" #include "event_layerclick.h" #include "toolbox.h" #include "dialog_tooloptions.h" -#include +#include + +#include "general.h" #endif @@ -52,7 +56,7 @@ using namespace std; using namespace etl; -using namespace sinfg; +using namespace synfig; using namespace studio; /* === M A C R O S ========================================================= */ @@ -67,33 +71,33 @@ class studio::StatePolygon_Context : public sigc::trackable { etl::handle canvas_view_; CanvasView::IsWorking is_working; - + bool prev_table_status; bool prev_workarea_layer_status_; Gtk::Menu menu; Duckmatic::Push duckmatic_push; - - std::list polygon_point_list; - sinfgapp::Settings& settings; - - bool on_polygon_duck_change(const sinfg::Point &point, std::list::iterator iter); + std::list polygon_point_list; + synfigapp::Settings& settings; + + bool on_polygon_duck_change(const synfig::Point &point, std::list::iterator iter); - void popup_handle_menu(sinfgapp::ValueDesc value_desc); + + void popup_handle_menu(synfigapp::ValueDesc value_desc); void refresh_ducks(); - + Gtk::Table options_table; Gtk::Entry entry_id; Gtk::Button button_make; public: - sinfg::String get_id()const { return entry_id.get_text(); } - void set_id(const sinfg::String& x) { return entry_id.set_text(x); } + synfig::String get_id()const { return entry_id.get_text(); } + void set_id(const synfig::String& x) { return entry_id.set_text(x); } Smach::event_result event_stop_handler(const Smach::event& x); @@ -108,19 +112,19 @@ public: ~StatePolygon_Context(); const etl::handle& get_canvas_view()const{return canvas_view_;} - etl::handle get_canvas_interface()const{return canvas_view_->canvas_interface();} - sinfg::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();} + etl::handle 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();} - - //void on_user_click(sinfg::Point point); + + //void on_user_click(synfig::Point point); void load_settings(); void save_settings(); void reset(); void increment_id(); - bool no_egress_on_selection_change; - Smach::event_result event_layer_selection_changed_handler(const Smach::event& x) + bool egress_on_selection_change; + Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/) { - if(!no_egress_on_selection_change) + if(egress_on_selection_change) throw Smach::egress_exception(); return Smach::RESULT_OK; } @@ -139,7 +143,7 @@ StatePolygon::StatePolygon(): insert(event_def(EVENT_REFRESH_DUCKS,&StatePolygon_Context::event_refresh_handler)); insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StatePolygon_Context::event_mouse_click_handler)); insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StatePolygon_Context::event_refresh_tool_options)); -} +} StatePolygon::~StatePolygon() { @@ -147,7 +151,7 @@ StatePolygon::~StatePolygon() void StatePolygon_Context::load_settings() -{ +{ String value; if(settings.get_value("polygon.id",value)) @@ -158,7 +162,7 @@ StatePolygon_Context::load_settings() void StatePolygon_Context::save_settings() -{ +{ settings.set_value("polygon.id",get_id().c_str()); } @@ -175,22 +179,25 @@ StatePolygon_Context::increment_id() String id(get_id()); int number=1; int digits=0; - + if(id.empty()) id="Polygon"; - + // If there is a number // already at the end of the // id, then remove it. if(id[id.size()-1]<='9' && id[id.size()-1]>='0') { // figure out how many digits it is - for(digits=0;(int)id.size()-1>=digits && id[id.size()-1-digits]<='9' && id[id.size()-1-digits]>='0';digits++)while(false); - + for (digits = 0; + (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0'; + digits++) + ; + String str_number; str_number=String(id,id.size()-digits,id.size()); id=String(id,0,id.size()-digits); - + number=atoi(str_number.c_str()); } else @@ -198,15 +205,15 @@ StatePolygon_Context::increment_id() number=1; digits=3; } - + number++; - + // Add the number back onto the id { const String format(strprintf("%%0%dd",digits)); id+=strprintf(format.c_str(),number); } - + // Set the ID set_id(id); } @@ -214,19 +221,19 @@ StatePolygon_Context::increment_id() StatePolygon_Context::StatePolygon_Context(CanvasView* canvas_view): canvas_view_(canvas_view), is_working(*canvas_view), - prev_workarea_layer_status_(get_work_area()->allow_layer_clicks), + prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()), duckmatic_push(get_work_area()), - settings(sinfgapp::Main::get_selected_input_device()->settings()), + settings(synfigapp::Main::get_selected_input_device()->settings()), entry_id(), button_make(_("Make")) { - no_egress_on_selection_change=false; + egress_on_selection_change=true; load_settings(); - + // Set up the tool options dialog - //options_table.attach(*manage(new Gtk::Label(_("Polygon Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + //options_table.attach(*manage(new Gtk::Label(_("Polygon Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - //options_table.attach(button_make, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + //options_table.attach(button_make, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); button_make.signal_pressed().connect(sigc::mem_fun(*this,&StatePolygon_Context::run)); options_table.show_all(); refresh_tool_options(); @@ -234,23 +241,23 @@ StatePolygon_Context::StatePolygon_Context(CanvasView* canvas_view): // 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(); get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR); - + // 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::StatePolygon_Context::on_user_click)); @@ -288,7 +295,7 @@ StatePolygon_Context::refresh_tool_options() } Smach::event_result -StatePolygon_Context::event_refresh_tool_options(const Smach::event& x) +StatePolygon_Context::event_refresh_tool_options(const Smach::event& /*x*/) { refresh_tool_options(); return Smach::RESULT_ACCEPT; @@ -300,19 +307,18 @@ StatePolygon_Context::~StatePolygon_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_); App::dialog_tool_options->clear(); get_canvas_view()->work_area->reset_cursor(); - // 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(); @@ -320,19 +326,19 @@ StatePolygon_Context::~StatePolygon_Context() } Smach::event_result -StatePolygon_Context::event_stop_handler(const Smach::event& x) +StatePolygon_Context::event_stop_handler(const Smach::event& /*x*/) { - sinfg::info("STATE RotoPolygon: Received Stop Event"); + synfig::info("STATE RotoPolygon: Received Stop Event"); //throw Smach::egress_exception(); reset(); return Smach::RESULT_ACCEPT; - + } Smach::event_result -StatePolygon_Context::event_refresh_handler(const Smach::event& x) +StatePolygon_Context::event_refresh_handler(const Smach::event& /*x*/) { - sinfg::info("STATE RotoPolygon: Received Refresh Event"); + synfig::info("STATE RotoPolygon: Received Refresh Event"); refresh_ducks(); return Smach::RESULT_ACCEPT; } @@ -342,7 +348,7 @@ StatePolygon_Context::run() { if(polygon_point_list.empty()) return; - + if(polygon_point_list.size()<3) { get_canvas_view()->get_ui_interface()->error("You need at least 3 points to create a polygon"); @@ -351,7 +357,7 @@ StatePolygon_Context::run() Layer::Handle layer; Canvas::Handle canvas(get_canvas_view()->get_canvas()); int depth(0); - + // we are temporarily using the layer to hold something layer=get_canvas_view()->get_selection_manager()->get_selected_layer(); if(layer) @@ -361,13 +367,13 @@ StatePolygon_Context::run() } { - sinfgapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Polygon")); - sinfgapp::PushMode push_mode(get_canvas_interface(),sinfgapp::MODE_NORMAL); - + synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Polygon")); + synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); + Layer::Handle layer(get_canvas_interface()->add_layer_to("polygon",canvas,depth)); layer->set_description(get_id()); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); - + layer->disconnect_dynamic_param("vector_list"); if(!layer->set_param("vector_list",polygon_point_list)) { @@ -375,25 +381,26 @@ StatePolygon_Context::run() get_canvas_view()->get_ui_interface()->error("Unable to set layer parameter"); return; } - + { - sinfgapp::Action::Handle action(sinfgapp::Action::create("value_desc_convert")); - sinfgapp::ValueDesc value_desc(layer,"vector_list"); - action->set_param("canvas",get_canvas()); - action->set_param("canvas_interface",get_canvas_interface()); - action->set_param("value_desc",value_desc); + synfigapp::Action::Handle action(synfigapp::Action::create("value_desc_convert")); + synfigapp::ValueDesc value_desc(layer,"vector_list"); + action->set_param("canvas",get_canvas()); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("value_desc",value_desc); action->set_param("type","dynamic_list"); + action->set_param("time",get_canvas_interface()->get_time()); if(!get_canvas_interface()->get_instance()->perform_action(action)) { group.cancel(); get_canvas_view()->get_ui_interface()->error("Unable to execute action \"value_desc_convert\""); return; } - } - no_egress_on_selection_change=true; + } + egress_on_selection_change=false; get_canvas_interface()->get_selection_manager()->clear_selected_layers(); get_canvas_interface()->get_selection_manager()->set_selected_layer(layer); - no_egress_on_selection_change=false; + egress_on_selection_change=true; //get_canvas_interface()->signal_dirty_preview()(); } /* @@ -413,7 +420,7 @@ StatePolygon_Context::run() Smach::event_result StatePolygon_Context::event_mouse_click_handler(const Smach::event& x) { - sinfg::info("STATE ROTOPOLYGON: Received mouse button down Event"); + synfig::info("STATE ROTOPOLYGON: Received mouse button down Event"); const EventMouse& event(*reinterpret_cast(&x)); switch(event.button) { @@ -421,11 +428,12 @@ StatePolygon_Context::event_mouse_click_handler(const Smach::event& x) polygon_point_list.push_back(get_work_area()->snap_point_to_grid(event.pos)); refresh_ducks(); return Smach::RESULT_ACCEPT; - - case BUTTON_RIGHT: // Intercept the right-button click to short-circut the pop-up menu - return Smach::RESULT_ACCEPT; - - default: + + case BUTTON_RIGHT: // Intercept the right-button click to short-circuit the pop-up menu + if (!getenv("SYNFIG_ENABLE_POPUP_MENU_IN_ALL_TOOLS")) + return Smach::RESULT_ACCEPT; + + default: return Smach::RESULT_OK; } } @@ -435,11 +443,11 @@ void StatePolygon_Context::refresh_ducks() { get_work_area()->clear_ducks(); - + if(polygon_point_list.empty()) return; - std::list::iterator iter=polygon_point_list.begin(); - + std::list::iterator iter=polygon_point_list.begin(); + etl::handle duck; duck=new WorkArea::Duck(*iter); duck->set_editable(true); @@ -447,7 +455,7 @@ StatePolygon_Context::refresh_ducks() sigc::bind(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_polygon_duck_change),iter) ); duck->signal_user_click(0).connect(sigc::mem_fun(*this,&StatePolygon_Context::run)); - + get_work_area()->add_duck(duck); for(++iter;iter!=polygon_point_list.end();++iter) @@ -460,19 +468,19 @@ StatePolygon_Context::refresh_ducks() duck->set_name(strprintf("%x",&*iter)); duck->signal_edited().connect( sigc::bind(sigc::mem_fun(*this,&studio::StatePolygon_Context::on_polygon_duck_change),iter) - ); + ); - get_work_area()->add_duck(duck); + get_work_area()->add_duck(duck); bezier->p2=bezier->c2=duck; - get_work_area()->add_bezier(bezier); + get_work_area()->add_bezier(bezier); } - get_work_area()->queue_draw(); + get_work_area()->queue_draw(); } bool -StatePolygon_Context::on_polygon_duck_change(const sinfg::Point &point, std::list::iterator iter) +StatePolygon_Context::on_polygon_duck_change(const synfig::Point &point, std::list::iterator iter) { *iter=point; return true;