Refresh drawing



Hello, I'm trying to refresh a Cairo::ImageSurface after scaling it to
show it resized, but I don't know how to do it.
The structure of my program is the following. I have a Gtk::Window, I
create a imagesurface and map it to the window
to show it. Then, through the motion event I try to scale the
imagesurface, but it doesn't work, and I don't know why.
Here it is the relevant part of the code:

Cairo::RefPtr<Cairo::ImageSurface> image;
boost::shared_ptr<Gtk::Window> w;
bool pressedbutton = false;
bool pressedbuttonright = false;

int xpointer, ypointer;
double scalex = 1.0, scaley = 1.0;

bool on_button_press_event(GdkEventButton * buttonev)
{
	xpointer = buttonev->x_root;
	ypointer = buttonev->y_root;

	if (buttonev->button == 1)
		pressedbutton = true;
	if (buttonev->button == 3)
		pressedbuttonright = true;

	return true;
}


bool on_button_release_event(GdkEventButton * buttonev)
{
	pressedbutton = false;
	pressedbuttonright = false;
	return true;
}



bool on_motion_notify_event(GdkEventMotion * evt)
{
	if (pressedbutton) {
		int x, y;
		int wx, wy;
		w->get_position(wx, wy);
		x = evt->x_root - xpointer;	
		y = evt->y_root - ypointer;
		w->move(wx + x, wy + y);
		xpointer = evt->x_root;
		ypointer = evt->y_root;
	}
	else if (pressedbuttonright)
	{
		std::cout  << "Entrado\n" << std::endl;
		int x, y;
		int wx, wy;
		w->get_position(wx, wy);
		x = evt->x_root - xpointer;	
		y = evt->y_root - ypointer;
		
	
		if (y < 0) scalex = scaley = 0.0 + -(y) * 0.05;
		else scalex = scaley = 0.0 + y * 0.05;

		w->queue_draw();
		//image->mark_dirty();
		xpointer = evt->x_root;
		ypointer = evt->y_root;
		scalex = scaley = 0.5;
	}
	return true;
}



bool
on_expose_event(GdkEventExpose *event)
{
	Cairo::RefPtr<Cairo::Context> context;


	Glib::RefPtr<Gdk::Window> window = w->get_window();
    if (window)
    {
        Cairo::RefPtr<Cairo::Context> context = window->create_cairo_context();
		context->set_source(image, 0, 0);
		std::cout  << scalex << " " << scaley << std::endl;
		context->scale(scalex, scaley);
		context->paint();
	
  		return true;
	}
}

The scale function is called in on_expose_event, but I don't know why,
after painting,
it has no effect. Any clue how to solve this? The image is shown at
the beginning of the application,
but there's no way to resize it. Thanks in advance.


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