gtkmm – example 15

This is part of a more general work dedicated to gtkmm accessible here. This example shows how to use transparency in Cairo.

capture

Download


Source code


main.cpp

#include 
#include 


int main(int argc, char* argv[])
{
	// Initialize gtkmm and create the main window
	Glib::RefPtr app = Gtk::Application::create(argc, argv, "www.lucidarme.me");
	Gtk::Window window;
	
	// Create the drawing
	Drawing Dwg;
	
	// Insert the drawing in the window
	window.add(Dwg);
	
	// Show the drawing
	Dwg.show();
	
	// Start main loop
	return app->run(window);
}

drawing.h

#ifndef DRAWING_H
#define DRAWING_H

#include 
#include 

class Drawing : public Gtk::DrawingArea
{
public:
	Drawing();
	
protected:
	//Override default signal handler:
	virtual bool on_draw(const Cairo::RefPtr& cr);
	
};

#endif // DRAWING_H

drawing.cpp

#include "drawing.h"

Drawing::Drawing()
{
}


bool Drawing::on_draw(const Cairo::RefPtr& cr)
{
	// Draw the first circle
	cr->arc(75,75,50,0,2*M_PI);
	cr->set_source_rgba(0, 0, 1.0,0.5);
	cr->fill();
	cr->stroke();

	cr->set_source_rgba(0, 1, 0,0.5);
	cr->arc(100,125,50,0,2*M_PI);
	cr->fill();
	cr->stroke();

	cr->set_source_rgba(1, 0, 0,0.5);
	cr->arc(125,75,50,0,2*M_PI);
	cr->fill();
	cr->stroke();


	return true;
}

Leave a Reply

Your email address will not be published. Required fields are marked *