Commit d627aea9 authored by Davis King's avatar Davis King

Made the image_display widget draw mouse cross-hairs when the user holds shift.

parent 9be82fdc
......@@ -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<unsigned long>::max())
highlighted_rect(std::numeric_limits<unsigned long>::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)
......
......@@ -3593,6 +3593,7 @@ namespace dlib
bool overlay_editing_enabled;
timer<image_display> highlight_timer;
unsigned long highlighted_rect;
bool holding_shift_key;
bool moving_overlay;
unsigned long moving_rect;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment