guideline.cpp revision 3f2f2d9a36c8132d316033e29bb2bc116292dc9a
/*
* Horizontal/vertical but can also be angled line
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Johan Engelen
* Maximilian Albert <maximilian.albert@gmail.com>
* Jon A. Cruz <jon@joncruz.org>
*
* 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 "sp-canvas-util.h"
#include "sp-ctrlpoint.h"
#include "guideline.h"
#include "display/cairo-utils.h"
#include "inkscape.h" // for inkscape_active_desktop()
#include "desktop.h"
#include "sp-namedview.h"
#include "display/sp-canvas.h"
#include "ui/control-manager.h"
using Inkscape::ControlManager;
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.
Geom::Point normal_dt = /*unit_vector*/(gl->normal_to_line * gl->affine.withoutTranslation()); // note that normal_dt does not have unit length
}
} 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.left() - point_on_line_dt[Geom::X]) * parallel_to_line[Geom::Y] / parallel_to_line[Geom::X] + point_on_line_dt[Geom::Y];
// intersects with left vertical!
double y_intersect_right = (buf->rect.right() - point_on_line_dt[Geom::X]) * parallel_to_line[Geom::Y] / parallel_to_line[Geom::X] + point_on_line_dt[Geom::Y];
sp_guideline_drawline (buf, buf->rect.left(), static_cast<gint>(round(y_intersect_left)), buf->rect.right(), static_cast<gint>(round(y_intersect_right)), gl->rgba);
goto end;
}
//try to intersect with right vertical of rect
double y_intersect_right = (buf->rect.right() - point_on_line_dt[Geom::X]) * parallel_to_line[Geom::Y] / parallel_to_line[Geom::X] + point_on_line_dt[Geom::Y];
// intersects with right vertical!
sp_guideline_drawline (buf, buf->rect.right(), static_cast<gint>(round(y_intersect_right)), buf->rect.left(), static_cast<gint>(round(y_intersect_left)), gl->rgba);
goto end;
}
//try to intersect with top horizontal of rect
double x_intersect_top = (buf->rect.top() - point_on_line_dt[Geom::Y]) * parallel_to_line[Geom::X] / parallel_to_line[Geom::Y] + point_on_line_dt[Geom::X];
// intersects with top horizontal!
double x_intersect_bottom = (buf->rect.bottom() - point_on_line_dt[Geom::Y]) * parallel_to_line[Geom::X] / parallel_to_line[Geom::Y] + point_on_line_dt[Geom::X];
sp_guideline_drawline (buf, static_cast<gint>(round(x_intersect_top)), buf->rect.top(), static_cast<gint>(round(x_intersect_bottom)), buf->rect.bottom(), gl->rgba);
goto end;
}
//try to intersect with bottom horizontal of rect
double x_intersect_bottom = (buf->rect.bottom() - point_on_line_dt[Geom::Y]) * parallel_to_line[Geom::X] / parallel_to_line[Geom::Y] + point_on_line_dt[Geom::X];
// intersects with bottom horizontal!
sp_guideline_drawline (buf, static_cast<gint>(round(x_intersect_bottom)), buf->rect.bottom(), static_cast<gint>(round(x_intersect_top)), buf->rect.top(), gl->rgba);
goto end;
}
}
end:
}
{
}
if (gl->is_horizontal()) {
sp_canvas_update_bbox (item, -1000000, round(pol_transformed[Geom::Y] - 16), 1000000, round(pol_transformed[Geom::Y] + 1));
} else if (gl->is_vertical()) {
sp_canvas_update_bbox (item, round(pol_transformed[Geom::X]), -1000000, round(pol_transformed[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
{
}
*actual_item = item;
}
SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point point_on_line, Geom::Point normal)
{
SPCanvasItem *origin = ControlManager::getManager().createControl(parent, Inkscape::CTRL_TYPE_ORIGIN);
return item;
}
{
}
}
{
}
{
}
{
}
{
}
{
//gtk_object_destroy(GTK_OBJECT(gl->origin));
}
static void
{
}
/*
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 :