Commit fe08f962 authored by Davis King's avatar Davis King

Made the behavior of the image_window a little more convenient. Now it will

automatically size itself properly when a zoom is in effect and you place a new
image into it.
parent 9bae1b6c
...@@ -5689,6 +5689,26 @@ namespace dlib ...@@ -5689,6 +5689,26 @@ namespace dlib
parent.invalidate_rectangle(rect); parent.invalidate_rectangle(rect);
} }
// ----------------------------------------------------------------------------------------
rectangle image_display::
get_image_display_rect (
) const
{
if (zoom_in_scale != 1)
{
return rectangle(0,0, img.nc()*zoom_in_scale-1, img.nr()*zoom_in_scale-1);
}
else if (zoom_out_scale != 1)
{
return rectangle(0,0, img.nc()/zoom_out_scale-1, img.nr()/zoom_out_scale-1);
}
else
{
return dlib::get_rect(img);
}
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
void image_display:: void image_display::
...@@ -6207,9 +6227,7 @@ namespace dlib ...@@ -6207,9 +6227,7 @@ namespace dlib
image_window:: image_window::
image_window( image_window(
) : ) :
gui_img(*this), gui_img(*this)
nr(0),
nc(0)
{ {
// show this window on the screen // show this window on the screen
show(); show();
......
...@@ -3252,6 +3252,7 @@ namespace dlib ...@@ -3252,6 +3252,7 @@ namespace dlib
parent.invalidate_rectangle(rect); parent.invalidate_rectangle(rect);
} }
rect_is_selected = false;
assign_image_scaled(img,new_img); assign_image_scaled(img,new_img);
} }
...@@ -3304,6 +3305,9 @@ namespace dlib ...@@ -3304,6 +3305,9 @@ namespace dlib
void clear_overlay ( void clear_overlay (
); );
rectangle get_image_display_rect (
) const;
std::vector<overlay_rect> get_overlay_rects ( std::vector<overlay_rect> get_overlay_rects (
) const; ) const;
...@@ -3444,7 +3448,7 @@ namespace dlib ...@@ -3444,7 +3448,7 @@ namespace dlib
template < typename image_type > template < typename image_type >
image_window( image_window(
const image_type& img const image_type& img
) : gui_img(*this), nr(0), nc(0) { set_image(img); show(); } ) : gui_img(*this) { set_image(img); show(); }
~image_window( ~image_window(
); );
...@@ -3458,18 +3462,16 @@ namespace dlib ...@@ -3458,18 +3462,16 @@ namespace dlib
auto_mutex M(wm); auto_mutex M(wm);
gui_img.set_image(img); gui_img.set_image(img);
// Only readjust the size of the window if the new image has a different size const rectangle r = gui_img.get_image_display_rect();
// than the last image given to this object. if (image_rect != r)
if (img.nr() != nr || img.nc() != nc)
{ {
// set the size of this window to match the size of the input image // set the size of this window to match the size of the input image
set_size(img.nc()+padding*2,img.nr()+padding*2); set_size(r.width()+padding*2,r.height()+padding*2);
// call this to make sure everything else is setup properly // call this to make sure everything else is setup properly
on_window_resized(); on_window_resized();
nr = img.nr(); image_rect = r;
nc = img.nc();
} }
} }
...@@ -3502,7 +3504,7 @@ namespace dlib ...@@ -3502,7 +3504,7 @@ namespace dlib
image_window& operator= (image_window&); image_window& operator= (image_window&);
image_display gui_img; image_display gui_img;
long nr, nc; rectangle image_rect;
}; };
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -2545,6 +2545,18 @@ namespace dlib ...@@ -2545,6 +2545,18 @@ namespace dlib
(i.e. when the user holds shift and adds them with the mouse) (i.e. when the user holds shift and adds them with the mouse)
!*/ !*/
rectangle get_image_display_rect (
) const;
/*!
ensures
- returns a rectangle R that tells you how big the image inside the
display is when it appears on the screen. Note that it takes the
current zoom level into account.
- R.width() == the width of the displayed image
- R.height() == the height of the displayed image
- R.tl_corner() == (0,0)
!*/
template < template <
typename T typename T
> >
......
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