Shame on Marc Marquez

image

2015 MotoGP championship is manipulated by Marquez criminal behaviour.

FIM and DORNA should not assign this championship to Lorenzo, because Valentino Rossi has been stopped by Marquez.

IT IS A SHAME

SHAME ON YOU MARC MARQUEZ

SHAME ON YOU JORGE LORENZO

You will never be a real Champion as Valentino Rossi.

You can finish a lap only thanks to traction control.

You are NOTHING compared to Valentino Rossi

Rip MotoGP

SpinButton e DrawingArea

Ho creato una GUI con Glade e ho ottenuto i puntatori ai vari widget.
Per far dialogare gli spinbutton con la drawingarea ho fatto così:

  • Ho derivato da Gtk::Window una nuova classe di finestra
    #include <iostream>
    #include <gtkmm/window.h>
    #include <gtkmm/builder.h>
    #include <gtkmm/spinbutton.h>
    #include "dadrawingarea.h"
    
    class DaWindow : public Gtk::Window
    {
    public:
    	DaWindow();
    	DaWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade);
    
    protected:
    	Glib::RefPtr<Gtk::Builder> builder;
    	Gtk::SpinButton *m_sbB, *m_sbH;
    	DaDrawingArea *m_da;
    	void on_spinbutton_digits_changed();
    };
    

    Aggiungo, come proprietà protette della classe, i puntatori ai widget SpinButton e DrawingArea, quest’ultima come classe derivata, per poter scrivere il suo metodo virtuale on_draw.

  • Implemento DaWindow:
    #include "dawindow.h"
    
    DaWindow::DaWindow(BaseObjectType* cobject,
                       const Glib::RefPtr<Gtk::Builder>& refGlade)
    :
    	Gtk::Window(cobject), builder(refGlade)
    {
    	m_sbB = m_sbH = 0;
    	builder->get_widget("spinbuttonB", m_sbB);
    	builder->get_widget("spinbuttonH", m_sbH);
    
    	m_sbB->set_range(0.0, 100.0);
    	m_sbB->set_value(7.0);
    	m_sbB->set_increments(0.5, 1.0);
    
    	m_sbH->set_range(0.0, 100.0);
    	m_sbH->set_value(13.0);
    	m_sbH->set_increments(0.5, 1.0);
    
    	m_sbB->signal_value_changed().connect(sigc::mem_fun(
    		*this, &DaWindow::on_spinbutton_digits_changed));
    	m_sbH->signal_value_changed()
    	.connect(sigc::mem_fun(
    		*this, &DaWindow::on_spinbutton_digits_changed));
    
    	builder->get_widget_derived("drawingarea", m_da);
    }
    
    DaWindow::DaWindow()
    {
    	return;
    }
    
    void DaWindow::on_spinbutton_digits_changed()
    {
    	m_da->set_rectangle(m_sbB->get_value(), m_sbH->get_value());
    	m_da->queue_draw();
    }
    

    Nel costruttore inizializzo i widget SpinButton, e ottengo anche il puntatore alla DaDrawingArea.

    Quando c’è un evento value_changed delle spinbutton viene chiamata DaWindow::on_spinbutton_digits_changed(): questa può chiamare i metodi della DaDrawingArea che è anche essa membro di DaWindow.

    In particolare si osservi il metodo Gtk::DrawingArea::queue_draw() : è questo che permette di ridisegnare l’ area.

  • Ho derivato la DaDrawingArea:
    #include <gtkmm/drawingarea.h>
    #include <cairomm/context.h>
    
    class DaDrawingArea : public Gtk::DrawingArea
    {
    public:
    	DaDrawingArea();
    	DaDrawingArea(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade);
    	void set_rectangle(double B, double H);
    
    protected:
    	double m_B, m_H;
    	virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
    };
    

    Ho solo aggiunto m_B e m_H.

  • Implementazione di DaDrawingArea:
    #include <iostream>
    #include <gtkmm/builder.h>
    #include "dadrawingarea.h"
    
    DaDrawingArea::DaDrawingArea(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade)
    :
    	Gtk::DrawingArea(cobject)
    {
    	m_B = m_H = 0.0;
    }
    
    void DaDrawingArea::set_rectangle(double B, double H)
    {
    	m_B = B;
    	m_H = H;
    }
    
    bool DaDrawingArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
    {
    	Gtk::Allocation allocation = get_allocation();
    	const int width = allocation.get_width();
    	const int height = allocation.get_height();
     
    	// coordinates for the center of the window
    	int xc, yc;
    	xc = width / 2;
    	yc = height / 2;
    
    	double x0 = xc - (m_B / 2);
    	double y0 = yc - (m_H / 2);
    
    	cr->rectangle(x0, y0, m_B, m_H);
    	cr->stroke();
    
    	return true;
    }
    

    Il metodo set_rectangle(double B, double H) viene usato dalle spinbutton per modificare le dimensioni.
    In on_draw si disegna il rettangolo.

  • il main
    #include <gtkmm/window.h>
    #include <gtkmm/application.h>
    #include <gtkmm/builder.h>
    #include <gtkmm/spinbutton.h>
    #include "dawindow.h"
    
    int main(int argc, char** argv)
    {
    	Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.example.altro");
    
    	Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("src/GUI.glade");
    
    	DaWindow *da = 0;
    	builder->get_widget_derived("window", da);
    
    	return app->run(*da);
    }
    

SpinButton GtkMM

ho creato una GUI con Glade.

poi ho derivato una Gtk::Window

#include <gtkmm/window.h>
#include <gtkmm/builder.h>
#include <gtkmm/spinbutton.h>
#include <iostream>

class DaWindow : public Gtk::Window
{
public:
	DaWindow();
	DaWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade);

protected:
	Glib::RefPtr<Gtk::Builder> builder;
	Gtk::SpinButton *m_sbB, *m_sbH;
	void on_spinbutton_digits_changed();
};

Per usare gli SpinButton bisogna inizializzarli: range, value, increments (accettano valori di tipo double).
L’ evento del cambio di valore è signal_value_changed().

#include "dawindow.h"

DaWindow::DaWindow(BaseObjectType* cobject,
                   const Glib::RefPtr<Gtk::Builder>& refGlade)
:
	Gtk::Window(cobject), builder(refGlade)
{
	m_sbB = m_sbH = 0;
	builder->get_widget("spinbuttonB", m_sbB);
	builder->get_widget("spinbuttonH", m_sbH);

	m_sbB->set_range(0.0, 100.0);
	m_sbB->set_value(7.0);
	m_sbB->set_increments(0.5, 1.0);

	m_sbH->set_range(0.0, 100.0);
	m_sbH->set_value(13.0);
	m_sbH->set_increments(0.5, 1.0);

	m_sbB->signal_value_changed().connect(sigc::mem_fun(
		*this, &DaWindow::on_spinbutton_digits_changed));
	m_sbH->signal_value_changed()
	.connect(sigc::mem_fun(
		*this, &DaWindow::on_spinbutton_digits_changed));
}

DaWindow::DaWindow()
{
	return;
}

void DaWindow::on_spinbutton_digits_changed()
{
	std::cout << "spin B: " << m_sbB->get_value() << std::endl;
	std::cout << "spin H: " << m_sbH->get_value() << std::endl;
}