Blob Blame Raw
#ifndef VIEW_H
#define VIEW_H


#include <vector>

#include <gtkmm/drawingarea.h>

#include "common.h"
#include "surface.h"
#include "matrix.h"


class View: public Gtk::DrawingArea {
public:
	class Point: public Shared {
	public:
		Vector2 position;
		Real radius;
		Color color;
		bool selected;
		
		Point(): radius(5.0), color(1, 1, 0, 1), selected() { }
		
		sigc::signal<void> signal_motion;
		sigc::signal<void> signal_changed;
		
		void motion() { signal_motion(); }
		void changed() { motion(); signal_changed(); }

		virtual void draw(
			const Cairo::RefPtr<Cairo::Context>& context,
			View &view );
	};

	class Layer: public Shared {
	public:
		virtual void draw(
			const Cairo::RefPtr<Cairo::Context>& context,
			View &view );
	};
	
	typedef RefPtr<Point> PointPtr;
	typedef RefPtr<Layer> LayerPtr;
	typedef std::vector<PointPtr> PointList;
	typedef std::vector<LayerPtr> LayerList;

public:
	Matrix transform;
	
	LayerList layers;
	PointList own_points;
	PointList foreign_points;

private:
	bool dragging;
	PointPtr selected_point;
	Vector2 selected_point_offset;

public:
	View();
	virtual ~View();
	
protected:
	bool on_draw(const Cairo::RefPtr<Cairo::Context>& context) override;
	bool on_motion_notify_event(GdkEventMotion *event) override;
	bool on_button_press_event(GdkEventButton *event) override;
	bool on_button_release_event(GdkEventButton *event) override;
};


#endif