All pastes #24238 Raw Edit

MacSlow

public cpp v1 · immutable
#24238 ·published 2005-09-29 21:11 UTC
rendered paste body
// g++ `pkg-config libsvg-cairo gtkmm-2.4 --cflags --libs` \// cairo_matrix_translate-test.cpp -o cairo_matrix_translate-test#include <iostream>#include <gtkmm.h>#include <svg-cairo.h>#include <math.h>Gtk::Window* pWindow = NULL;Gtk::DrawingArea* pDrawingArea = NULL;cairo_t* pCairoContext = NULL;void draw_background (){	int iX;	int iY;	bool bToggle = false;	for (iX = 0; iX < 20; iX++)	{		bToggle = !bToggle;		for (iY = 0; iY < 20; iY++)		{			if (bToggle)			{				cairo_set_source_rgb (pCairoContext, 1.0f, 1.0f, 1.0f);				bToggle = !bToggle;			}			else			{				cairo_set_source_rgb (pCairoContext, 0.9f, 0.9f, 0.9f);				bToggle = !bToggle;			}			cairo_rectangle (pCairoContext,							 iX * 0.05f,							 iY * 0.05f,							 0.05f,							 0.05f);			cairo_fill (pCairoContext);		}	}}void draw_svg (){	svg_cairo_t* pSVGContext;	unsigned int uiWidth;	unsigned int uiHeight;	cairo_matrix_t matrix;		svg_cairo_create (&pSVGContext);		svg_cairo_parse (pSVGContext, "./cairo_logo.svg");	svg_cairo_get_size (pSVGContext, &uiWidth, &uiHeight);		cairo_matrix_init_identity (&matrix);	cairo_matrix_translate (&matrix, 150.5f, 256.5f);	cairo_matrix_rotate (&matrix, -15.0f * (M_PI/180.0));	cairo_matrix_scale (&matrix, 0.5f, 0.5f);	cairo_set_matrix (pCairoContext, &matrix);	svg_cairo_render (pSVGContext, pCairoContext);		svg_cairo_destroy (pSVGContext);}bool on_expose_event (GdkEventExpose* pEvent){	pCairoContext = gdk_cairo_create (pDrawingArea->get_window()->gobj ());	if (pCairoContext)	{		cairo_scale (pCairoContext,					 (double) pDrawingArea->get_allocation().get_width (),					 (double) pDrawingArea->get_allocation().get_height ());		draw_background ();		draw_svg ();		cairo_destroy (pCairoContext);	}	return true;}int main (int argc, char** argv){	Gtk::Main app (argc, argv);	pWindow = new Gtk::Window ();	if (!pWindow)		return 1;	pDrawingArea = new Gtk::DrawingArea ();	if (!pDrawingArea)		return 2;	pWindow->add (*pDrawingArea);	pWindow->set_title ("cairo_matrix_translate() test");	pWindow->show_all ();	pDrawingArea->signal_expose_event().connect (sigc::ptr_fun (on_expose_event));	pDrawingArea->set_size_request (400, 400);	app.run (*pWindow);	return 0;}