diff --git a/dlib/gui_widgets/widgets.cpp b/dlib/gui_widgets/widgets.cpp index 611703064..bdb4c13a4 100644 --- a/dlib/gui_widgets/widgets.cpp +++ b/dlib/gui_widgets/widgets.cpp @@ -6012,7 +6012,8 @@ namespace dlib part_width(15), // width part circles are drawn on the screen overlay_editing_enabled(true), highlight_timer(*this, &image_display::timer_event_unhighlight_rect), - highlighted_rect(std::numeric_limits::max()) + highlighted_rect(std::numeric_limits::max()), + holding_shift_key(false) { enable_mouse_drag(); @@ -6250,16 +6251,26 @@ namespace dlib const point origin(total_rect().tl_corner()); // draw the image on the screen + const double scale = zoom_out_scale/(double)zoom_in_scale; const rectangle img_area = total_rect().intersect(area); for (long row = img_area.top(); row <= img_area.bottom(); ++row) { + const long rc = row-c.top(); + const long rimg = (row-origin.y())*scale; for (long col = img_area.left(); col <= img_area.right(); ++col) { - assign_pixel(c[row-c.top()][col-c.left()], - img[(row-origin.y())*zoom_out_scale/zoom_in_scale][(col-origin.x())*zoom_out_scale/zoom_in_scale]); + assign_pixel(c[rc][col-c.left()], + img[rimg][(col-origin.x())*scale]); } } + // draw the mouse cross-hairs + if (holding_shift_key && total_rect().contains(lastx,lasty) ) + { + draw_line(c, point(lastx,-10000), point(lastx,100000),rgb_pixel(255,255,0), area); + draw_line(c, point(-10000,lasty), point(100000,lasty),rgb_pixel(255,255,0), area); + } + // now draw all the overlay rectangles for (unsigned long i = 0; i < overlay_rects.size(); ++i) { @@ -6393,6 +6404,20 @@ namespace dlib { scrollable_region::on_keydown(key,is_printable, state); + if (!is_printable && key==base_window::KEY_SHIFT) + { + if (!holding_shift_key) + { + holding_shift_key = true; + parent.invalidate_rectangle(rect); + } + } + else if (holding_shift_key) + { + holding_shift_key = false; + parent.invalidate_rectangle(rect); + } + if (!is_printable && !hidden && enabled && rect_is_selected && (key == base_window::KEY_BACKSPACE || key == base_window::KEY_DELETE)) { @@ -6459,6 +6484,16 @@ namespace dlib { scrollable_region::on_mouse_down(btn, state, x, y, is_double_click); + if (state&base_window::SHIFT) + { + holding_shift_key = true; + } + else if (holding_shift_key) + { + holding_shift_key = false; + parent.invalidate_rectangle(rect); + } + if (rect.contains(x,y) == false || hidden || !enabled) return; @@ -6757,6 +6792,16 @@ namespace dlib { scrollable_region::on_mouse_up(btn,state,x,y); + if (state&base_window::SHIFT) + { + holding_shift_key = true; + } + else if (holding_shift_key) + { + holding_shift_key = false; + parent.invalidate_rectangle(rect); + } + if (drawing_rect && btn == base_window::LEFT && (state&base_window::SHIFT) && !hidden && enabled) { @@ -6817,6 +6862,17 @@ namespace dlib { scrollable_region::on_mouse_move(state,x,y); + if (enabled && !hidden) + { + if (holding_shift_key) + parent.invalidate_rectangle(rect); + + if (state&base_window::SHIFT) + holding_shift_key = true; + else if (holding_shift_key) + holding_shift_key = false; + } + if (drawing_rect) { if ((state&base_window::LEFT) && (state&base_window::SHIFT) && !hidden && enabled) diff --git a/dlib/gui_widgets/widgets.h b/dlib/gui_widgets/widgets.h index 5bf442032..2246bfecc 100644 --- a/dlib/gui_widgets/widgets.h +++ b/dlib/gui_widgets/widgets.h @@ -3593,6 +3593,7 @@ namespace dlib bool overlay_editing_enabled; timer highlight_timer; unsigned long highlighted_rect; + bool holding_shift_key; bool moving_overlay; unsigned long moving_rect;