Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-studio / trunk / src / gtkmm / widget_gradient.cpp
index 8086b52..c964599 100644 (file)
@@ -2,19 +2,21 @@
 /*!    \file widget_gradient.cpp
 **     \brief Template File
 **
-**     $Id: widget_gradient.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) 2007 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
 */
 /* ========================================================================= */
@@ -34,6 +36,8 @@
 #include <synfig/exception.h>
 #include <ETL/misc>
 
+#include "general.h"
+
 #endif
 
 /* === U S I N G =========================================================== */
@@ -72,13 +76,13 @@ studio::render_gradient_to_window(const Glib::RefPtr<Gdk::Drawable>& window,cons
                gushort r2(256*App::gamma.r_F32_to_U8(c2.get_r()));
                gushort g2(256*App::gamma.g_F32_to_U8(c2.get_g()));
                gushort b2(256*App::gamma.b_F32_to_U8(c2.get_b()));
-                               
+
                if((i*2/height)&1)
                {
                        gdk_c.set_rgb(r1,g1,b1);
                        gc->set_rgb_fg_color(gdk_c);
-                       window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y(), 1, height/2);                              
-       
+                       window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y(), 1, height/2);
+
                        gdk_c.set_rgb(r2,g2,b2);
                        gc->set_rgb_fg_color(gdk_c);
                        window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y()+height/2, 1, height/2);
@@ -87,8 +91,8 @@ studio::render_gradient_to_window(const Glib::RefPtr<Gdk::Drawable>& window,cons
                {
                        gdk_c.set_rgb(r2,g2,b2);
                        gc->set_rgb_fg_color(gdk_c);
-                       window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y(), 1, height/2);                              
-       
+                       window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y(), 1, height/2);
+
                        gdk_c.set_rgb(r1,g1,b1);
                        gc->set_rgb_fg_color(gdk_c);
                        window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y()+height/2, 1, height/2);
@@ -111,18 +115,18 @@ Widget_Gradient::Widget_Gradient():
        add_events(Gdk::BUTTON1_MOTION_MASK);
 
 }
-       
+
 Widget_Gradient::~Widget_Gradient()
 {
 }
 
 #define CONTROL_HEIGHT         16
 bool
-Widget_Gradient::redraw(GdkEventExpose*bleh)
+Widget_Gradient::redraw(GdkEventExpose */*bleh*/)
 {
        const int h(get_height());
        const int w(get_width());
-       
+
        Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
        Gdk::Rectangle area(0,0,w,h);
        if(!editable_)
@@ -161,7 +165,7 @@ Widget_Gradient::redraw(GdkEventExpose*bleh)
                        show_selected=true;
                }
        }
-       
+
        // we do this so that we can be sure that
        // the selected marker is shown on top
        if(show_selected)
@@ -181,7 +185,7 @@ Widget_Gradient::redraw(GdkEventExpose*bleh)
                        CONTROL_HEIGHT
                );
        }
-       
+
        return true;
 }
 
@@ -202,6 +206,7 @@ void
 Widget_Gradient::remove_cpoint(float x)
 {
        gradient_.erase(gradient_.proximity(x));
+       signal_value_changed_();
        queue_draw();
 }
 
@@ -209,7 +214,8 @@ void
 Widget_Gradient::popup_menu(float x)
 {
        Gtk::Menu* menu(manage(new Gtk::Menu()));
-       
+       menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
+
        menu->items().clear();
 
        menu->items().push_back(
@@ -234,7 +240,7 @@ Widget_Gradient::popup_menu(float x)
                        )
                );
        }
-       
+
        menu->popup(0,0);
 }
 
@@ -283,14 +289,15 @@ Widget_Gradient::on_event(GdkEvent *event)
                float pos((float)x/(float)get_width());
                if(pos<0.0f)pos=0.0f;
                if(pos>1.0f)pos=1.0f;
-       
+
                switch(event->type)
                {
                case GDK_MOTION_NOTIFY:
                        if(editable_ && y>get_height()-CONTROL_HEIGHT)
                        {
+                               if(!gradient_.size()) return true;
                                Gradient::iterator iter(gradient_.find(selected_cpoint));
-                               
+                               //! Use SHIFT to stack two CPoints together.
                                if(event->button.state&GDK_SHIFT_MASK)
                                {
                                        float begin(-100000000),end(100000000);
@@ -305,20 +312,20 @@ Widget_Gradient::on_event(GdkEvent *event)
                                        {
                                                end=after->pos;
                                        }
-                                       
+
                                        if(pos>end)
                                                pos=end;
                                        if(pos<begin)
                                                pos=begin;
-                                       
-                                       iter->pos=pos;                                  
+
+                                       iter->pos=pos;
                                }
                                else
                                {
                                        iter->pos=pos;
                                        gradient_.sort();
                                }
-                               
+
 //                             signal_value_changed_();
                                changed_=true;
                                queue_draw();
@@ -358,6 +365,6 @@ Widget_Gradient::on_event(GdkEvent *event)
                        break;
                }
        }
-       
+
        return false;
 }