mirror of https://github.com/davisking/dlib.git
Switched the gui stuff over to the new 2D dlib::vector object.
--HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402740
This commit is contained in:
parent
7ae1d3a3e2
commit
4f6f436e2a
|
@ -2071,9 +2071,9 @@ namespace dlib
|
|||
parent.invalidate_rectangle(rect+old);
|
||||
|
||||
const double old_scale = scale;
|
||||
const vector<double> old_gr_orig(gr_orig);
|
||||
const vector<double,2> old_gr_orig(gr_orig);
|
||||
scale = min_scale;
|
||||
gr_orig = vector<double>(0,0,0);
|
||||
gr_orig = vector<double,2>(0,0);
|
||||
lr_point = gui_to_graph_space(point(display_rect_.right(),display_rect_.bottom()));
|
||||
scale = old_scale;
|
||||
|
||||
|
@ -2148,24 +2148,22 @@ namespace dlib
|
|||
|
||||
point zoomable_region::
|
||||
graph_to_gui_space (
|
||||
const vector<double>& p
|
||||
const vector<double,2>& p
|
||||
) const
|
||||
{
|
||||
const point rect_corner(display_rect_.left(), display_rect_.top());
|
||||
const dlib::vector<double> v(p);
|
||||
return (v - gr_orig)*scale + rect_corner;
|
||||
return (p - gr_orig)*scale + rect_corner;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
vector<double> zoomable_region::
|
||||
vector<double,2> zoomable_region::
|
||||
gui_to_graph_space (
|
||||
const point& p
|
||||
) const
|
||||
{
|
||||
const point rect_corner(display_rect_.left(), display_rect_.top());
|
||||
const dlib::vector<double> v(p - rect_corner);
|
||||
return v/scale + gr_orig;
|
||||
return (p - rect_corner)/scale + gr_orig;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
@ -2217,7 +2215,7 @@ namespace dlib
|
|||
|
||||
void zoomable_region::
|
||||
center_display_at_graph_point (
|
||||
const vector<double>& p
|
||||
const vector<double,2>& p
|
||||
)
|
||||
{
|
||||
// find the point in the center of the graph area
|
||||
|
@ -2363,11 +2361,11 @@ namespace dlib
|
|||
void zoomable_region::
|
||||
adjust_origin (
|
||||
const point& gui_p,
|
||||
const vector<double>& graph_p
|
||||
const vector<double,2>& graph_p
|
||||
)
|
||||
{
|
||||
const point rect_corner(display_rect_.left(), display_rect_.top());
|
||||
const dlib::vector<double> v(gui_p - rect_corner);
|
||||
const dlib::vector<double,2> v(gui_p - rect_corner);
|
||||
gr_orig = graph_p - v/scale;
|
||||
|
||||
|
||||
|
@ -2380,8 +2378,8 @@ namespace dlib
|
|||
// make sure the lower right corner of the display_rect_ doesn't map to a point beyond lr_point
|
||||
point lr_rect_corner(display_rect_.right(), display_rect_.bottom());
|
||||
point p = graph_to_gui_space(lr_point);
|
||||
vector<double> lr_rect_corner_graph_space(gui_to_graph_space(lr_rect_corner));
|
||||
vector<double> delta(lr_point - lr_rect_corner_graph_space);
|
||||
vector<double,2> lr_rect_corner_graph_space(gui_to_graph_space(lr_rect_corner));
|
||||
vector<double,2> delta(lr_point - lr_rect_corner_graph_space);
|
||||
if (lr_rect_corner.x() > p.x())
|
||||
{
|
||||
gr_orig.x() += delta.x();
|
||||
|
@ -2393,7 +2391,7 @@ namespace dlib
|
|||
}
|
||||
|
||||
|
||||
const vector<double> ul_rect_corner_graph_space(gui_to_graph_space(rect_corner));
|
||||
const vector<double,2> ul_rect_corner_graph_space(gui_to_graph_space(rect_corner));
|
||||
lr_rect_corner_graph_space = gui_to_graph_space(lr_rect_corner);
|
||||
// now adjust the scroll bars
|
||||
|
||||
|
|
|
@ -2155,10 +2155,10 @@ namespace dlib
|
|||
protected:
|
||||
|
||||
point graph_to_gui_space (
|
||||
const vector<double>& p
|
||||
const vector<double,2>& p
|
||||
) const;
|
||||
|
||||
vector<double> gui_to_graph_space (
|
||||
vector<double,2> gui_to_graph_space (
|
||||
const point& p
|
||||
) const;
|
||||
|
||||
|
@ -2176,7 +2176,7 @@ namespace dlib
|
|||
);
|
||||
|
||||
void center_display_at_graph_point (
|
||||
const vector<double>& p
|
||||
const vector<double,2>& p
|
||||
);
|
||||
|
||||
// ----------- event handlers ---------------
|
||||
|
@ -2227,7 +2227,7 @@ namespace dlib
|
|||
|
||||
void adjust_origin (
|
||||
const point& gui_p,
|
||||
const vector<double>& graph_p
|
||||
const vector<double,2>& graph_p
|
||||
);
|
||||
/*!
|
||||
ensures
|
||||
|
@ -2237,8 +2237,8 @@ namespace dlib
|
|||
!*/
|
||||
|
||||
|
||||
vector<double> gr_orig; // point in graph space such that it's gui space point is the upper left of display_rect_
|
||||
vector<double> lr_point; // point in graph space such that it is at the lower right corner of the screen at max zoom
|
||||
vector<double,2> gr_orig; // point in graph space such that it's gui space point is the upper left of display_rect_
|
||||
vector<double,2> lr_point; // point in graph space such that it is at the lower right corner of the screen at max zoom
|
||||
|
||||
mutable std::ostringstream sout;
|
||||
|
||||
|
@ -2249,7 +2249,7 @@ namespace dlib
|
|||
rectangle display_rect_;
|
||||
|
||||
bool mouse_drag_screen; // true if the user is dragging the white background area
|
||||
vector<double> drag_screen_point; // the starting point the mouse was at in graph space for the background area drag
|
||||
vector<double,2> drag_screen_point; // the starting point the mouse was at in graph space for the background area drag
|
||||
|
||||
scroll_bar vsb;
|
||||
scroll_bar hsb;
|
||||
|
|
|
@ -1599,9 +1599,6 @@ namespace dlib
|
|||
determined automatically from the size of this object's on screen
|
||||
rectangle and the value of min_zoom_scale() which determines how far
|
||||
out you can zoom.
|
||||
|
||||
Also note that while dlib::vector<double> is used to represent graph points
|
||||
the z field is always ignored by this object.
|
||||
*/
|
||||
|
||||
public:
|
||||
|
@ -1719,7 +1716,7 @@ namespace dlib
|
|||
!*/
|
||||
|
||||
point graph_to_gui_space (
|
||||
const vector<double>& graph_point
|
||||
const vector<double,2>& graph_point
|
||||
) const;
|
||||
/*!
|
||||
requires
|
||||
|
@ -1729,7 +1726,7 @@ namespace dlib
|
|||
to the given point in Cartesian graph space
|
||||
!*/
|
||||
|
||||
vector<double> gui_to_graph_space (
|
||||
vector<double,2> gui_to_graph_space (
|
||||
const point& pixel_point
|
||||
) const;
|
||||
/*!
|
||||
|
@ -1740,7 +1737,7 @@ namespace dlib
|
|||
pixel location
|
||||
!*/
|
||||
|
||||
vector<double> max_graph_point (
|
||||
vector<double,2> max_graph_point (
|
||||
) const;
|
||||
/*!
|
||||
requires
|
||||
|
@ -1782,7 +1779,7 @@ namespace dlib
|
|||
!*/
|
||||
|
||||
void center_display_at_graph_point (
|
||||
const vector<double>& graph_point
|
||||
const vector<double,2>& graph_point
|
||||
);
|
||||
/*!
|
||||
requires
|
||||
|
|
|
@ -2091,11 +2091,11 @@ namespace dlib
|
|||
}
|
||||
|
||||
bool click_hit_node = false;
|
||||
dlib::vector<double> p(gui_to_graph_space(point(x,y)));
|
||||
dlib::vector<double,2> p(gui_to_graph_space(point(x,y)));
|
||||
// check if this click is on an existing node
|
||||
for (unsigned long i = 0; i < graph_.number_of_nodes(); ++i)
|
||||
{
|
||||
dlib::vector<double> n(graph_.node(i).data.p);
|
||||
dlib::vector<double,2> n(graph_.node(i).data.p);
|
||||
if ((p-n).length() < radius)
|
||||
{
|
||||
click_hit_node = true;
|
||||
|
@ -2135,10 +2135,10 @@ namespace dlib
|
|||
{
|
||||
for (unsigned long n = 0; n < graph_.number_of_nodes() && edge_selected == false; ++n)
|
||||
{
|
||||
const dlib::vector<double> parent_center(graph_to_gui_space(graph_.node(n).data.p));
|
||||
const dlib::vector<double,2> parent_center(graph_to_gui_space(graph_.node(n).data.p));
|
||||
for (unsigned long e = 0; e < graph_.node(n).number_of_children() && edge_selected == false; ++e)
|
||||
{
|
||||
const dlib::vector<double> child_center(graph_to_gui_space(graph_.node(n).child(e).data.p));
|
||||
const dlib::vector<double,2> child_center(graph_to_gui_space(graph_.node(n).child(e).data.p));
|
||||
|
||||
rectangle area;
|
||||
area += parent_center;
|
||||
|
@ -2149,7 +2149,7 @@ namespace dlib
|
|||
p = point(x,y);
|
||||
const dlib::vector<double> z(0,0,1);
|
||||
// find the distance from the line between the two nodes
|
||||
const dlib::vector<double> perpendicular(z.cross(parent_center-child_center).normalize());
|
||||
const dlib::vector<double,2> perpendicular(z.cross(parent_center-child_center).normalize());
|
||||
double distance = std::abs((child_center-p).dot(perpendicular));
|
||||
if (distance < 8)
|
||||
{
|
||||
|
@ -2197,11 +2197,11 @@ namespace dlib
|
|||
(state & base_window::SHIFT) &&
|
||||
selected_node != graph_.number_of_nodes() )
|
||||
{
|
||||
dlib::vector<double> p(gui_to_graph_space(point(x,y)));
|
||||
dlib::vector<double,2> p(gui_to_graph_space(point(x,y)));
|
||||
// check if this click is on an existing node
|
||||
for (unsigned long i = 0; i < graph_.number_of_nodes(); ++i)
|
||||
{
|
||||
dlib::vector<double> n(graph_.node(i).data.p);
|
||||
dlib::vector<double,2> n(graph_.node(i).data.p);
|
||||
if ((p-n).length() < radius)
|
||||
{
|
||||
// add the edge if it doesn't already exist and isn't an edge back to
|
||||
|
@ -2272,7 +2272,7 @@ namespace dlib
|
|||
color.red = 255;
|
||||
// we need to be careful when drawing this line to not draw it over the node dots since it
|
||||
// has a different color from them and would look weird
|
||||
dlib::vector<double> v(p-center);
|
||||
dlib::vector<double,2> v(p-center);
|
||||
v = v.normalize()*rad;
|
||||
draw_line(c,center+v,p-v ,color, area);
|
||||
}
|
||||
|
@ -2285,11 +2285,11 @@ namespace dlib
|
|||
// draw the triangle pointing to this node
|
||||
if (area.intersect(circle_area).is_empty() == false)
|
||||
{
|
||||
dlib::vector<double> v(p-center);
|
||||
dlib::vector<double,2> v(p-center);
|
||||
v = v.normalize();
|
||||
|
||||
dlib::vector<double> cross = z.cross(v).normalize();
|
||||
dlib::vector<double> r(center + v*rad);
|
||||
dlib::vector<double,2> cross = z.cross(v).normalize();
|
||||
dlib::vector<double,2> r(center + v*rad);
|
||||
for (double i = 0; i < 8*zoom_scale(); i += 0.1)
|
||||
draw_line(c,(r+v*i)+cross*i, (r+v*i)-cross*i,color,area);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue