Re: Help to connect a signal gtkmm



Lebon Sylvain wrote:

Andrew E. Makeev a écrit :

Lebon Sylvain wrote:


Ok so i want to resize  an Gtk::Image each time  that the window  has a
rescale / resize.

this->signal_configure_event().connect(sigc::mem_fun(*this,
&function_resize_and_show_image));

And this doesn't work , i can't figure out why. this is a Gtk::Window


replace signal_configure_event with signal_expose_event, and use saved_width, saved_height values to optimize performance.

Ok i have got the same problem (it's surely my fault :p ) when i compile it:

this->signal_configure_event().connect(sigc::mem_fun(*this,
&function_resize_and_show_image));  or
this->signal_expose_event().connect(sigc::mem_fun(*this,
&function_resize_and_show_image));

the compiler tel me an error (see down). I precise that i am usign devcpp . And that all is working perfetly so i suposed there is somethong wrong in my code.
t [with T_return = void, T_obj = ExampleWindow]
C:/Dev-Cpp/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:84: error: return-statement with a value, in function returning 'void'

It says that function declared as void (*func)(), but has return value.
Guess, your call back should be declared as "bool func(GdkEventExpose*);" and "return false;" at the end, either you must retype function type using sigc-namespace adaptors.

See my example.

#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/image.h>

#include <vector>
#include <iostream>

using namespace std;

class MyApp : public Gtk::Window
{
public:
   MyApp () : saved_w (0), saved_h (0)
   {
       m_orig = Gdk::Pixbuf::create_from_file ("image.png");

//       Gtk::ScrolledWindow* sw = manage (new Gtk::ScrolledWindow);
//       sw->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
//       add (*sw);
       Glib::RefPtr<Gdk::Pixbuf> buff = m_orig->copy ();
       m_image.set (buff);
       m_image.show ();
       add (m_image);

       show_all_children ();

       signal_expose_event ().connect
	   (SigC::slot (*this, &MyApp::resize_cb));
       set_default_size (m_orig->get_width (), m_orig->get_height ());
       cout << "shrink: " << property_allow_shrink () << endl;
       property_allow_shrink () = true;
   }
   ~MyApp ()
   {
   }

   bool resize_cb (GdkEventExpose*)
   {
       int width, height;
       get_size (width, height);
       if (width == saved_w && height == saved_h) return false;
       cout << "new w/h: "  << width << "/" << height << endl;
       saved_w = width;
       saved_h = height;

       Glib::RefPtr<Gdk::Pixbuf> buff =
	   m_orig->scale_simple (width, height, Gdk::INTERP_BILINEAR);
       m_image.set (buff);

       return false;
   }

private:
   int saved_w, saved_h;
   Gtk::Image m_image;
   Glib::RefPtr<Gdk::Pixbuf> m_orig;
};

int main (int argc, char *argv[])
{
    Gtk::Main kit (argc, argv);
    MyApp app;

    kit.run (app);
    return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]