X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fwidget_curves.cpp;h=2260dad0bf4e8426fad1223ed574191946325f87;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=45f68cf90f7bd79c7fd307d4cabc62abd2d6cdc0;hpb=3a3c4bca3a17137bec5d7960560934b91ef4146e;p=synfig.git diff --git a/synfig-studio/trunk/src/gtkmm/widget_curves.cpp b/synfig-studio/trunk/src/gtkmm/widget_curves.cpp index 45f68cf..2260dad 100644 --- a/synfig-studio/trunk/src/gtkmm/widget_curves.cpp +++ b/synfig-studio/trunk/src/gtkmm/widget_curves.cpp @@ -1,20 +1,22 @@ -/* === S I N F G =========================================================== */ +/* === S Y N F I G ========================================================= */ /*! \file widget_curves.cpp ** \brief Template File ** -** $Id: widget_curves.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 Gerco Ballintijn ** -** 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 */ /* ========================================================================= */ @@ -37,13 +39,15 @@ #include #include +#include "general.h" + #endif /* === U S I N G =========================================================== */ using namespace std; using namespace etl; -using namespace sinfg; +using namespace synfig; using namespace studio; /* === M A C R O S ========================================================= */ @@ -54,35 +58,35 @@ using namespace studio; /* void -studio::render_color_to_window(const Glib::RefPtr& window,const Gdk::Rectangle& ca,const sinfg::Color &color) +studio::render_color_to_window(const Glib::RefPtr& window,const Gdk::Rectangle& ca,const synfig::Color &color) { const int height(ca.get_height()); const int width(ca.get_width()); - + const int square_size(height/2); - + Glib::RefPtr gc(Gdk::GC::create(window)); - + if(color.get_alpha()!=1.0) { // In this case we need to render the alpha squares - + const Color bg1(Color::blend(color,Color(0.75, 0.75, 0.75),1.0).clamped()); const Color bg2(Color::blend(color,Color(0.5, 0.5, 0.5),1.0).clamped()); - - Gdk::Color gdk_c1(colorconv_sinfg2gdk(bg1)); - Gdk::Color gdk_c2(colorconv_sinfg2gdk(bg2)); + + Gdk::Color gdk_c1(colorconv_synfig2gdk(bg1)); + Gdk::Color gdk_c2(colorconv_synfig2gdk(bg2)); bool toggle(false); for(int i=0;iset_rgb_fg_color(gdk_c1); - window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), square_width, square_size); - + window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), square_width, square_size); + gc->set_rgb_fg_color(gdk_c2); window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y()+square_size, square_width, square_size); toggle=false; @@ -90,8 +94,8 @@ studio::render_color_to_window(const Glib::RefPtr& window,const G else { gc->set_rgb_fg_color(gdk_c2); - window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), square_width, square_size); - + window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), square_width, square_size); + gc->set_rgb_fg_color(gdk_c1); window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y()+square_size, square_width, square_size); toggle=true; @@ -101,9 +105,9 @@ studio::render_color_to_window(const Glib::RefPtr& window,const G else { // In this case we have a solid color to use - Gdk::Color gdk_c1(colorconv_sinfg2gdk(color)); + Gdk::Color gdk_c1(colorconv_synfig2gdk(color)); - gc->set_rgb_fg_color(gdk_c1); + gc->set_rgb_fg_color(gdk_c1); window->draw_rectangle(gc, true, ca.get_x(), ca.get_y(), width-1, height-1); } gc->set_rgb_fg_color(Gdk::Color("#ffffff")); @@ -119,17 +123,17 @@ studio::render_color_to_window(const Glib::RefPtr& window,const G struct studio::Widget_Curves::Channel { - sinfg::String name; + synfig::String name; Gdk::Color color; - std::map values; + std::map values; }; struct studio::Widget_Curves::CurveStruct : sigc::trackable { - sinfgapp::ValueDesc value_desc; + synfigapp::ValueDesc value_desc; std::vector channels; - CurveStruct(const sinfgapp::ValueDesc& x): + CurveStruct(const synfigapp::ValueDesc& x): value_desc(x) { switch(value_desc.get_value_type()) @@ -188,7 +192,7 @@ struct studio::Widget_Curves::CurveStruct : sigc::trackable channels.push_back(Channel()); channels.back().name="v.y"; channels.back().color=Gdk::Color("#7f3f00"); - + channels.push_back(Channel()); channels.back().name="width"; channels.back().color=Gdk::Color("#000000"); @@ -200,7 +204,7 @@ struct studio::Widget_Curves::CurveStruct : sigc::trackable channels.push_back(Channel()); channels.back().name="tsplit"; channels.back().color=Gdk::Color("#ff00ff"); - + channels.push_back(Channel()); channels.back().name="t1.x"; channels.back().color=Gdk::Color("#ff0000"); @@ -216,29 +220,28 @@ struct studio::Widget_Curves::CurveStruct : sigc::trackable channels.back().color=Gdk::Color("#7f7f00"); break; default: - throw sinfg::Exception::BadType("Bad type for curves"); + throw synfig::Exception::BadType("Bad type for curves"); } } - + void clear_all_values() { - DEBUGPOINT(); std::vector::iterator iter; for(iter=channels.begin();iter!=channels.end();++iter) iter->values.clear(); } - - sinfg::Real get_value(int chan, sinfg::Real time, sinfg::Real tolerance) + + synfig::Real get_value(int chan, synfig::Real time, synfig::Real tolerance) { - std::map::iterator iter; - + std::map::iterator iter; + // First check to see if we have a value // that is "close enough" to the time // we are looking for iter=channels[chan].values.lower_bound(time); if(iter!=channels[chan].values.end() && iter->first-time<=tolerance) return -iter->second; - + // Since that didn't work, we now need // to go ahead and figure out what the // actual value is at that time. @@ -284,9 +287,18 @@ struct studio::Widget_Curves::CurveStruct : sigc::trackable default: return 0; } - + return -channels[chan].values[time]; } + + static bool is_not_supported(const synfigapp::ValueDesc& x) + { + return x.get_value_type() == ValueBase::TYPE_STRING + || x.get_value_type() == ValueBase::TYPE_CANVAS + || x.get_value_type() == ValueBase::TYPE_GRADIENT + || x.get_value_type() == ValueBase::TYPE_LIST + || x.get_value_type() == ValueBase::TYPE_SEGMENT; + } }; /* === M E T H O D S ======================================================= */ @@ -309,10 +321,10 @@ Widget_Curves::Widget_Curves(): ) ); //set_vadjustment(*range_adjustment_); - + signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Curves::redraw)); add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); - + } Widget_Curves::~Widget_Curves() @@ -356,18 +368,20 @@ Widget_Curves::refresh() } void -Widget_Curves::set_value_descs(std::list value_descs) +Widget_Curves::set_value_descs(std::list value_descs) { curve_list_.clear(); - - std::list::iterator iter; + + std::list::iterator iter; for(iter=value_descs.begin();iter!=value_descs.end();++iter) { + if (CurveStruct::is_not_supported(*iter)) + continue; + try { curve_list_.push_back(*iter); if(iter->is_value_node()) { - DEBUGPOINT(); iter->get_value_node()->signal_changed().connect( sigc::mem_fun( *this, @@ -377,7 +391,6 @@ Widget_Curves::set_value_descs(std::list value_descs) } if(iter->parent_is_value_node()) { - DEBUGPOINT(); iter->get_parent_value_node()->signal_changed().connect( sigc::mem_fun( *this, @@ -387,7 +400,6 @@ Widget_Curves::set_value_descs(std::list value_descs) } if(iter->parent_is_layer_param()) { - DEBUGPOINT(); iter->get_layer()->signal_changed().connect( sigc::mem_fun( *this, @@ -395,7 +407,7 @@ Widget_Curves::set_value_descs(std::list value_descs) ) ); } - }catch(sinfg::Exception::BadType) + }catch(synfig::Exception::BadType) { continue; } @@ -429,7 +441,7 @@ Widget_Curves::on_event(GdkEvent *event) } return true; - + /* switch(event->type) { case GDK_BUTTON_PRESS: @@ -444,7 +456,7 @@ Widget_Curves::on_event(GdkEvent *event) return true; } break; - + default: break; } @@ -453,17 +465,20 @@ Widget_Curves::on_event(GdkEvent *event) } bool -Widget_Curves::redraw(GdkEventExpose*bleh) +Widget_Curves::redraw(GdkEventExpose */*bleh*/) { const int h(get_height()); - const int w(get_width()); + const int w(get_width()); get_window()->clear(); - + if(!time_adjustment_ || !range_adjustment_ || !h || !w) return false; - + + if(!curve_list_.size()) + return false; + Glib::RefPtr gc(Gdk::GC::create(get_window())); - + const Real t_begin(time_adjustment_->get_lower()); const Real t_end(time_adjustment_->get_upper()); const Real dt((t_end-t_begin)/w); @@ -473,7 +488,7 @@ Widget_Curves::redraw(GdkEventExpose*bleh) const Real dr((r_top-r_bottom)/h); Real r_max(-100000000); Real r_min(100000000); - + std::list::iterator curve_iter; vector points[10]; @@ -485,10 +500,41 @@ Widget_Curves::redraw(GdkEventExpose*bleh) gc->set_rgb_fg_color(Gdk::Color("#4f4f4f")); get_window()->draw_rectangle(gc, false, 0, round_to_int((0-r_bottom)/dr), w, 0); + // This try to find a valid vanvas to show the keyframes of those + // valuenodes. If not canvas found then no keyframes marks are shown. + synfig::Canvas::Handle canvas=0; + for(curve_iter=curve_list_.begin();curve_iter!=curve_list_.end();++curve_iter) + { + canvas=curve_iter->value_desc.get_canvas(); + if(canvas) + break; + } + + if(canvas) + { + // Draw vertical lines for the keyframes marks. + const synfig::KeyframeList& keyframe_list(canvas->keyframe_list()); + synfig::KeyframeList::const_iterator iter; + + for(iter=keyframe_list.begin();iter!=keyframe_list.end();++iter) + { + if(!iter->get_time().is_valid()) + continue; + + const int x((int)((float)w/(t_end-t_begin)*(iter->get_time()-t_begin))); + if(iter->get_time()>=t_begin && iter->get_time()set_rgb_fg_color(Gdk::Color("#a07f7f")); // It should be user selectable + get_window()->draw_rectangle(gc, true, x, 0, 1, h); + } + } + } + // Draw current time - gc->set_rgb_fg_color(Gdk::Color("#00007f")); + gc->set_rgb_fg_color(Gdk::Color("#0000ff")); // It should be user selectable get_window()->draw_rectangle(gc, false, round_to_int((time_adjustment_->get_value()-t_begin)/dt), 0, 0, h); + // Draw curves for the valuenodes stored in the curve list for(curve_iter=curve_list_.begin();curve_iter!=curve_list_.end();++curve_iter) { Real t; @@ -520,23 +566,23 @@ Widget_Curves::redraw(GdkEventExpose*bleh) for(int chan=0;chanset_rgb_fg_color(curve_iter->channels[chan].color); - + // Draw the curve get_window()->draw_lines(gc, Glib::ArrayHandle(points[chan])); Glib::RefPtr layout(Pango::Layout::create(get_pango_context())); - - layout->set_text(curve_iter->channels[chan].name); - get_window()->draw_layout(gc, 1, points[chan][0].get_y()+1, layout); + + layout->set_text(curve_iter->channels[chan].name); + get_window()->draw_layout(gc, 1, points[chan][0].get_y()+1, layout); } } - + if(!curve_list_.empty()) { range_adjustment_->set_upper(r_max+range_adjustment_->get_page_size()/2); range_adjustment_->set_lower(r_min-range_adjustment_->get_page_size()/2); } get_window()->get_update_area(); - + return true; }