Article View: comp.windows.interviews
Article #40pick a line
From: Joerg Ringel
Date: Sat, 31 Oct 1992 18:24
Date: Sat, 31 Oct 1992 18:24
85 lines
2648 bytes
2648 bytes
Hey,
at the moment I'm working with IV3.1beta2.
My problem is the following:
I'm writing the pick function for an InputHandler (GoalLine).
The InputHandler is a line from one of the upper corners to one
of the down corners of the allocation.
I want to make the target only if the mouse button is pressed at
a line position with a given epsilon (+- 10).
The problem is, if the line has a little gradient the difference
between the real point and the display point is to big.
I've tested the to_pixels function of Canvas but it doesn't work.
Perhaps I'm making something wrong.
Who can help me ??
Thank's in advance,
Joerg (ringel@forwiss.uni-passau.de)
Here is the function:
---------------------------------------------------------------
void GoalLine::pick(Canvas* c, const Allocation& a, int depth, Hit& h) {
Coord act_x = h.event()->pointer_x();
Coord act_y = h.event()->pointer_y();
Coord y1 = a.top();
Coord y2 = a.bottom();
Coord x1;
Coord x2;
Coord top_x = to_node->father()->x_coord();
Coord bottom_x = to_node->x_coord();
if (Math::abs(top_x - bottom_x) < 1.0) {
x1 = x2 = a.x();
}
else {
if (top_x < bottom_x) {
x1 = a.left();
x2 = a.right();
}
else {
x1 = a.right();
x2 = a.left();
}
}
Coord diff_x = x2 - x1;
Coord diff_y = y2 - y1;
if (diff_x == 0 || diff_y == 0) {
if (diff_x == 0) {
if (Math::equal(x1, act_x, epsilon) && act_y < y1 && act_y > y2) {
h.target(depth, this, 0, handler());
}
}
else {
if (Math::equal(y1, act_y, epsilon) &&
act_y < Math::max(x1, x2) &&
act_y > Math::min(x1, x2)) {
h.target(depth, this, 0, handler());
}
}
}
else {
Coord steigung1 = (diff_x / diff_y);
Coord x_on_line = x1 + steigung1 * (act_y - y1);
if (Math::equal(x_on_line, act_x, epsilon)) {
Coord steigung2 = (diff_y / diff_x);
Coord y_on_line = y1 + steigung2 * (act_x - x1);
if (Math::equal(y_on_line, act_y, epsilon)) {
h.target(depth, this, 0, handler());
}
}
}
}
Technical Details
Message-ID:
<1992Oct31.182409.27899@tom.rz.uni-passau.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!math.fu-berlin.de!informatik.tu-muenchen.de!rz.uni-passau.de!forwiss.uni-passau.de!ringelShow Full Headers
Complete Article Headers
Newsgroups: comp.windows.interviews Path: arc1-ca.pugleaf.net!sparky!uunet!math.fu-berlin.de!informatik.tu-muenchen.de!rz.uni-passau.de!forwiss.uni-passau.de!ringel From: ringel@forwiss.uni-passau.de (Joerg Ringel) Subject: pick a line Message-ID: <1992Oct31.182409.27899@tom.rz.uni-passau.de> Sender: news@tom.rz.uni-passau.de (News-Operator) Nntp-Posting-Host: elrond.forwiss.uni-passau.de Organization: University of Passau, Germany Date: Sat, 31 Oct 1992 18:24:09 GMT Lines: 86