Blame c++/vector/context.cpp

2fb9fd
2fb9fd
2fb9fd
#include <cmath></cmath>
2fb9fd
2fb9fd
#include "activepoint.h"
2fb9fd
2fb9fd
#include "context.h"
2fb9fd
2fb9fd
2fb9fd
Real Context::pixelsize_sqr() const {
2fb9fd
	Cairo::Matrix m;
2fb9fd
	ctx()->get_matrix(m);
2fb9fd
	return 0.25*sqrt(m.xx*m.xx + m.xy*m.xy + m.yx*m.yx + m.yy*m.yy);
2fb9fd
}
2fb9fd
2fb9fd
Real Context::pixelsize() const {
2fb9fd
	return sqrt(pixelsize_sqr());
2fb9fd
}
2fb9fd
2fb9fd
void Context::point(const ActivePoint &point) const {
2fb9fd
	if (!point.visible) return;
2fb9fd
2fb9fd
	Color color = point.color;
2fb9fd
	Color stroke_color = Color::black();
2fb9fd
	if (!point.enabled) {
2fb9fd
		color = color.mergecolor(Color::gray()).mulalpha();
2fb9fd
		stroke_color = stroke_color.mergecolor(Color::gray()).mulalpha();
2fb9fd
	}
2fb9fd
2fb9fd
	ctx()->save();
2fb9fd
	ctx()->arc(point.position.x, point.position.y, point.radius, 0, 2*pi);
2fb9fd
	set_source_rgba(color);
2fb9fd
	ctx()->fill_preserve();
2fb9fd
	set_line_width_px(point.active ? 2 : 1);
2fb9fd
	set_source_rgba(stroke_color);
2fb9fd
	ctx()->stroke();
2fb9fd
2fb9fd
	ctx()->restore();
2fb9fd
}
2fb9fd
2fb9fd
void Context::segment(const Segment &segment) const {
2fb9fd
	line_to(segment.p0);
2fb9fd
	Vector b0 = segment.p0 + segment.t0/3;
2fb9fd
	Vector b1 = segment.p1 - segment.t1/3;
2fb9fd
	ctx()->curve_to(b0.x, b0.y, b1.x, b1.y, segment.p1.x, segment.p1.y);
2fb9fd
}