X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fstate_gradient.cpp;h=c8461b5deb23a299f941434e8434e1ed26842245;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=d4cf949e89519b0839553c5daf12c51f3c881c8f;hpb=837b63e9fb829d66d43f4f169861f8979f76820d;p=synfig.git diff --git a/synfig-studio/trunk/src/gtkmm/state_gradient.cpp b/synfig-studio/trunk/src/gtkmm/state_gradient.cpp index d4cf949..c8461b5 100644 --- a/synfig-studio/trunk/src/gtkmm/state_gradient.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_gradient.cpp @@ -6,6 +6,7 @@ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2008 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -51,6 +52,8 @@ #include "widget_enum.h" #include +#include "general.h" + #endif /* === U S I N G =========================================================== */ @@ -96,7 +99,9 @@ class studio::StateGradient_Context : public sigc::trackable Gtk::Table options_table; Gtk::Entry entry_id; Widget_Enum enum_type; +#ifdef BLEND_METHOD_IN_TOOL_OPTIONS Widget_Enum enum_blend; +#endif // BLEND_METHOD_IN_TOOL_OPTIONS public: synfig::String get_id()const { return entry_id.get_text(); } @@ -105,8 +110,10 @@ public: int get_type()const { return enum_type.get_value(); } void set_type(int x) { return enum_type.set_value(x); } +#ifdef BLEND_METHOD_IN_TOOL_OPTIONS int get_blend()const { return enum_blend.get_value(); } void set_blend(int x) { return enum_blend.set_value(x); } +#endif // BLEND_METHOD_IN_TOOL_OPTIONS Smach::event_result event_stop_handler(const Smach::event& x); @@ -133,10 +140,10 @@ public: void increment_id(); void make_gradient(const Point& p1, const Point& p2); - 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; } @@ -178,10 +185,12 @@ StateGradient_Context::load_settings() else set_type(GRADIENT_INTERPOLATION_LINEAR); +#ifdef BLEND_METHOD_IN_TOOL_OPTIONS if(settings.get_value("gradient.blend",value)) set_blend(atoi(value.c_str())); else set_blend(Color::BLEND_COMPOSITE); +#endif // BLEND_METHOD_IN_TOOL_OPTIONS } void @@ -189,7 +198,9 @@ StateGradient_Context::save_settings() { settings.set_value("gradient.id",get_id().c_str()); settings.set_value("gradient.type",strprintf("%d",get_type())); +#ifdef BLEND_METHOD_IN_TOOL_OPTIONS settings.set_value("gradient.blend",strprintf("%d",get_blend())); +#endif // BLEND_METHOD_IN_TOOL_OPTIONS } void @@ -214,7 +225,10 @@ StateGradient_Context::increment_id() 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()); @@ -245,13 +259,13 @@ StateGradient_Context::StateGradient_Context(CanvasView* canvas_view): is_working(*canvas_view), duckmatic_push(get_work_area()), settings(synfigapp::Main::get_selected_input_device()->settings()), - prev_workarea_layer_status_(get_work_area()->allow_layer_clicks), + prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()), entry_id() { - no_egress_on_selection_change=false; + egress_on_selection_change=true; // Set up the tool options dialog - ///options_table.attach(*manage(new Gtk::Label(_("Gradient 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(*manage(new Gtk::Label(_("Gradient 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); enum_type.set_param_desc(ParamDesc("type") .set_local_name(_("Gradient Type")) @@ -262,14 +276,18 @@ StateGradient_Context::StateGradient_Context(CanvasView* canvas_view): .add_enum_value(GRADIENT_CONICAL,"conical",_("Conical")) .add_enum_value(GRADIENT_SPIRAL,"spiral",_("Spiral"))); +#ifdef BLEND_METHOD_IN_TOOL_OPTIONS enum_blend.set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method") .set_local_name(_("Blend Method")) .set_description(_("The blend method the gradient will use"))); +#endif // BLEND_METHOD_IN_TOOL_OPTIONS load_settings(); options_table.attach(enum_type, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); +#ifdef BLEND_METHOD_IN_TOOL_OPTIONS options_table.attach(enum_blend, 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); +#endif // BLEND_METHOD_IN_TOOL_OPTIONS options_table.show_all(); refresh_tool_options(); @@ -277,7 +295,7 @@ StateGradient_Context::StateGradient_Context(CanvasView* canvas_view): // Turn off layer clicking - get_work_area()->allow_layer_clicks=false; + get_work_area()->set_allow_layer_clicks(false); get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR); @@ -292,8 +310,8 @@ StateGradient_Context::StateGradient_Context(CanvasView* canvas_view): // Hide the tables if they are showing 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::StateGradient_Context::on_user_click)); @@ -311,7 +329,7 @@ StateGradient_Context::refresh_tool_options() } Smach::event_result -StateGradient_Context::event_refresh_tool_options(const Smach::event& x) +StateGradient_Context::event_refresh_tool_options(const Smach::event& /*x*/) { refresh_tool_options(); return Smach::RESULT_ACCEPT; @@ -322,15 +340,14 @@ StateGradient_Context::~StateGradient_Context() save_settings(); // Restore layer clicking -// get_work_area()->allow_layer_clicks=prev_workarea_layer_status_; - get_work_area()->allow_layer_clicks=true; +// get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_); + get_work_area()->set_allow_layer_clicks(true); 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(); @@ -338,6 +355,8 @@ StateGradient_Context::~StateGradient_Context() // Refresh the work area get_work_area()->queue_draw(); + get_canvas_view()->queue_rebuild_ducks(); + //get_canvas_view()->show_tables(); get_work_area()->refresh_cursor(); @@ -346,13 +365,13 @@ StateGradient_Context::~StateGradient_Context() } Smach::event_result -StateGradient_Context::event_stop_handler(const Smach::event& x) +StateGradient_Context::event_stop_handler(const Smach::event& /*x*/) { throw Smach::egress_exception(); } Smach::event_result -StateGradient_Context::event_refresh_handler(const Smach::event& x) +StateGradient_Context::event_refresh_handler(const Smach::event& /*x*/) { refresh_ducks(); return Smach::RESULT_ACCEPT; @@ -385,6 +404,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2) case GRADIENT_INTERPOLATION_LINEAR: layer=get_canvas_interface()->add_layer_to("linear_gradient",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer->set_param("p1",p1); get_canvas_interface()->signal_layer_param_changed()(layer,"p1"); layer->set_param("p2",p2); @@ -392,6 +417,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2) break; case GRADIENT_RADIAL: layer=get_canvas_interface()->add_layer_to("radial_gradient",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer->set_param("center",p1); get_canvas_interface()->signal_layer_param_changed()(layer,"center"); layer->set_param("radius",(p2-p1).mag()); @@ -399,6 +430,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2) break; case GRADIENT_CONICAL: layer=get_canvas_interface()->add_layer_to("conical_gradient",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer->set_param("center",p1); get_canvas_interface()->signal_layer_param_changed()(layer,"center"); { @@ -409,6 +446,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2) break; case GRADIENT_SPIRAL: layer=get_canvas_interface()->add_layer_to("spiral_gradient",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer->set_param("center",p1); get_canvas_interface()->signal_layer_param_changed()(layer,"center"); layer->set_param("radius",(p2-p1).mag()); @@ -424,16 +467,22 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2) return; } +#ifdef BLEND_METHOD_IN_TOOL_OPTIONS layer->set_param("blend_method",get_blend()); get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method"); +#endif // BLEND_METHOD_IN_TOOL_OPTIONS layer->set_description(get_id()); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); - no_egress_on_selection_change=true; + egress_on_selection_change=false; + synfigapp::SelectionManager::LayerList layer_selection; + if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION")) + layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers(); 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; + layer_selection.push_back(layer); + get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection); + egress_on_selection_change=true; reset(); increment_id(); @@ -469,6 +518,7 @@ StateGradient_Context::event_mouse_click_handler(const Smach::event& x) if(event.key==EVENT_WORKAREA_MOUSE_BUTTON_DRAG && event.button==BUTTON_LEFT) { + if (!point2_duck) return Smach::RESULT_OK; point2_duck->set_point(get_work_area()->snap_point_to_grid(event.pos)); get_work_area()->queue_draw(); return Smach::RESULT_ACCEPT;