guideline.cpp revision c00898b8feb36304e4b797e0bd645bbcc6048dba
/*
* Horizontal/vertical but can also be angled line
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Johan Engelen
* Maximilian Albert <maximilian.albert@gmail.com>
*
* Copyright (C) 2000-2002 Lauris Kaplinski
* Copyright (C) 2007 Johan Engelen
* Copyright (C) 2009 Maximilian Albert
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <libnr/nr-pixops.h>
#include "sp-canvas-util.h"
#include "sp-ctrlpoint.h"
#include "guideline.h"
#include "cairo.h"
#include "inkscape-cairo.h"
static void sp_guideline_class_init(SPGuideLineClass *c);
static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags);
static void sp_guideline_drawline (SPCanvasBuf *buf, gint x0, gint y0, gint x1, gint y1, guint32 rgba);
static SPCanvasItemClass *parent_class;
{
static GType guideline_type = 0;
if (!guideline_type) {
static GTypeInfo const guideline_info = {
sizeof (SPGuideLineClass),
sizeof (SPGuideLine),
16,
NULL,
};
guideline_type = g_type_register_static(SP_TYPE_CANVAS_ITEM, "SPGuideLine", &guideline_info, (GTypeFlags) 0);
}
return guideline_type;
}
static void sp_guideline_class_init(SPGuideLineClass *c)
{
}
{
}
{
//g_return_if_fail (SP_GUIDELINE(object)->origin != NULL);
//g_return_if_fail (SP_IS_CTRLPOINT(SP_GUIDELINE(object)->origin));
} else {
// FIXME: This branch shouldn't be reached (although it seems to be harmless).
//g_error("Why can it be that gl->origin is not a valid SPCtrlPoint?\n");
}
}
{
//TODO: the routine that renders the label of a specific guideline sometimes
// ends up erasing the labels of the other guidelines.
// Maybe we should render all labels everytime.
cairo_t* ctx = nr_create_cairo_context_canvasbuf (NULL /*area*/, buf); //this function ignores the "area" parameter
cairo_set_source_rgb (ctx, 0, 0, 0);
if (gl->is_vertical()) {
return;
}
d[0] = NR_COMPOSEN11_1111(r, a, d[0]);
d += step;
}
}
} else if (gl->is_horizontal()) {
return;
}
int step = 4;
d[0] = NR_COMPOSEN11_1111(r, a, d[0]);
d += step;
}
}
} else {
// render angled line, once intersection has been detected, draw from there.
//try to intersect with left vertical of rect
double y_intersect_left = (buf->rect.x0 - gl->point_on_line[Geom::X]) * parallel_to_line[Geom::Y] / parallel_to_line[Geom::X] + gl->point_on_line[Geom::Y];
// intersects with left vertical!
double y_intersect_right = (buf->rect.x1 - gl->point_on_line[Geom::X]) * parallel_to_line[Geom::Y] / parallel_to_line[Geom::X] + gl->point_on_line[Geom::Y];
sp_guideline_drawline (buf, buf->rect.x0, static_cast<gint>(round(y_intersect_left)), buf->rect.x1, static_cast<gint>(round(y_intersect_right)), gl->rgba);
return;
}
//try to intersect with right vertical of rect
double y_intersect_right = (buf->rect.x1 - gl->point_on_line[Geom::X]) * parallel_to_line[Geom::Y] / parallel_to_line[Geom::X] + gl->point_on_line[Geom::Y];
// intersects with right vertical!
sp_guideline_drawline (buf, buf->rect.x1, static_cast<gint>(round(y_intersect_right)), buf->rect.x0, static_cast<gint>(round(y_intersect_left)), gl->rgba);
return;
}
//try to intersect with top horizontal of rect
double x_intersect_top = (buf->rect.y0 - gl->point_on_line[Geom::Y]) * parallel_to_line[Geom::X] / parallel_to_line[Geom::Y] + gl->point_on_line[Geom::X];
// intersects with top horizontal!
double x_intersect_bottom = (buf->rect.y1 - gl->point_on_line[Geom::Y]) * parallel_to_line[Geom::X] / parallel_to_line[Geom::Y] + gl->point_on_line[Geom::X];
sp_guideline_drawline (buf, static_cast<gint>(round(x_intersect_top)), buf->rect.y0, static_cast<gint>(round(x_intersect_bottom)), buf->rect.y1, gl->rgba);
return;
}
//try to intersect with bottom horizontal of rect
double x_intersect_bottom = (buf->rect.y1 - gl->point_on_line[Geom::Y]) * parallel_to_line[Geom::X] / parallel_to_line[Geom::Y] + gl->point_on_line[Geom::X];
// intersects with bottom horizontal!
sp_guideline_drawline (buf, static_cast<gint>(round(x_intersect_bottom)), buf->rect.y1, static_cast<gint>(round(x_intersect_top)), buf->rect.y0, gl->rgba);
return;
}
}
}
}
{
}
if (gl->is_horizontal()) {
sp_canvas_update_bbox (item, -1000000, (int) Inkscape::round(gl->point_on_line[Geom::Y] - 16), 1000000, (int) Inkscape::round(gl->point_on_line[Geom::Y] + 1));
} else if (gl->is_vertical()) {
sp_canvas_update_bbox (item, (int) Inkscape::round(gl->point_on_line[Geom::X]), -1000000, (int) Inkscape::round(gl->point_on_line[Geom::X] + 16), 1000000);
} else {
//TODO: labels in angled guidelines are not showing up for some reason.
}
}
// Returns 0.0 if point is on the guideline
{
return NR_HUGE;
}
*actual_item = item;
}
SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point point_on_line, Geom::Point normal)
{
return item;
}
{
}
{
sp_canvas_item_affine_absolute(SP_CANVAS_ITEM (gl->origin), Geom::Affine(Geom::Translate(point_on_line)));
}
{
}
{
}
{
}
{
//gtk_object_destroy(GTK_OBJECT(gl->origin));
}
//##########################################################
// Line rendering
#define SAFE_SETPIXEL //undefine this when it is certain that setpixel is never called with invalid params
/**
\brief This function renders a pixel on a particular buffer.
The topleft of the buffer equals
( rect.x0 , rect.y0 ) in screen coordinates
( 0 , 0 ) in setpixel coordinates
The bottomright of the buffer equals
( rect.x1 , rect,y1 ) in screen coordinates
( rect.x1 - rect.x0 , rect.y1 - rect.y0 ) in setpixel coordinates
*/
static void
{
#ifdef SAFE_SETPIXEL
#endif
guint r, g, b, a;
r = NR_RGBA32_R (rgba);
g = NR_RGBA32_G (rgba);
b = NR_RGBA32_B (rgba);
a = NR_RGBA32_A (rgba);
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
#ifdef SAFE_SETPIXEL
}
#endif
}
/**
\brief This function renders a line on a particular canvas buffer,
using Bresenham's line drawing function.
Coordinates are interpreted as SCREENcoordinates
*/
static void
{
if (fraction >= 0) {
}
}
} else {
if (fraction >= 0) {
}
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :