| 2434 | // ---------------------------------------------------------------------------------------- |
| 2435 | |
| 2436 | void zoomable_region:: |
| 2437 | adjust_origin ( |
| 2438 | const point& gui_p, |
| 2439 | const vector<double,2>& graph_p |
| 2440 | ) |
| 2441 | { |
| 2442 | const point rect_corner(display_rect_.left(), display_rect_.top()); |
| 2443 | const dlib::vector<double,2> v(gui_p - rect_corner); |
| 2444 | gr_orig = graph_p - v/scale; |
| 2445 | |
| 2446 | |
| 2447 | // make sure the origin isn't outside the point (0,0) |
| 2448 | if (gr_orig.x() < 0) |
| 2449 | gr_orig.x() = 0; |
| 2450 | if (gr_orig.y() < 0) |
| 2451 | gr_orig.y() = 0; |
| 2452 | |
| 2453 | // make sure the lower right corner of the display_rect_ doesn't map to a point beyond lr_point |
| 2454 | point lr_rect_corner(display_rect_.right(), display_rect_.bottom()); |
| 2455 | point p = graph_to_gui_space(lr_point); |
| 2456 | vector<double,2> lr_rect_corner_graph_space(gui_to_graph_space(lr_rect_corner)); |
| 2457 | vector<double,2> delta(lr_point - lr_rect_corner_graph_space); |
| 2458 | if (lr_rect_corner.x() > p.x()) |
| 2459 | { |
| 2460 | gr_orig.x() += delta.x(); |
| 2461 | } |
| 2462 | |
| 2463 | if (lr_rect_corner.y() > p.y()) |
| 2464 | { |
| 2465 | gr_orig.y() += delta.y(); |
| 2466 | } |
| 2467 | |
| 2468 | |
| 2469 | const vector<double,2> ul_rect_corner_graph_space(gui_to_graph_space(rect_corner)); |
| 2470 | lr_rect_corner_graph_space = gui_to_graph_space(lr_rect_corner); |
| 2471 | // now adjust the scroll bars |
| 2472 | |
| 2473 | hsb.set_max_slider_pos((unsigned long)std::max(lr_point.x()-(lr_rect_corner_graph_space.x()-ul_rect_corner_graph_space.x()),0.0)); |
| 2474 | vsb.set_max_slider_pos((unsigned long)std::max(lr_point.y()-(lr_rect_corner_graph_space.y()-ul_rect_corner_graph_space.y()),0.0)); |
| 2475 | // adjust slider position now. |
| 2476 | hsb.set_slider_pos(static_cast<long>(ul_rect_corner_graph_space.x())); |
| 2477 | vsb.set_slider_pos(static_cast<long>(ul_rect_corner_graph_space.y())); |
| 2478 | |
| 2479 | } |
| 2480 | |
| 2481 | // ---------------------------------------------------------------------------------------- |
| 2482 | // ---------------------------------------------------------------------------------------- |