mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
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.
This commit is contained in:
parent
9bae1b6cae
commit
fe08f96266
@ -5689,6 +5689,26 @@ namespace dlib
|
||||
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::
|
||||
@ -6207,9 +6227,7 @@ namespace dlib
|
||||
image_window::
|
||||
image_window(
|
||||
) :
|
||||
gui_img(*this),
|
||||
nr(0),
|
||||
nc(0)
|
||||
gui_img(*this)
|
||||
{
|
||||
// show this window on the screen
|
||||
show();
|
||||
|
@ -3252,6 +3252,7 @@ namespace dlib
|
||||
parent.invalidate_rectangle(rect);
|
||||
}
|
||||
|
||||
rect_is_selected = false;
|
||||
assign_image_scaled(img,new_img);
|
||||
}
|
||||
|
||||
@ -3304,6 +3305,9 @@ namespace dlib
|
||||
void clear_overlay (
|
||||
);
|
||||
|
||||
rectangle get_image_display_rect (
|
||||
) const;
|
||||
|
||||
std::vector<overlay_rect> get_overlay_rects (
|
||||
) const;
|
||||
|
||||
@ -3444,7 +3448,7 @@ namespace dlib
|
||||
template < typename image_type >
|
||||
image_window(
|
||||
const image_type& img
|
||||
) : gui_img(*this), nr(0), nc(0) { set_image(img); show(); }
|
||||
) : gui_img(*this) { set_image(img); show(); }
|
||||
|
||||
~image_window(
|
||||
);
|
||||
@ -3458,18 +3462,16 @@ namespace dlib
|
||||
auto_mutex M(wm);
|
||||
gui_img.set_image(img);
|
||||
|
||||
// Only readjust the size of the window if the new image has a different size
|
||||
// than the last image given to this object.
|
||||
if (img.nr() != nr || img.nc() != nc)
|
||||
const rectangle r = gui_img.get_image_display_rect();
|
||||
if (image_rect != r)
|
||||
{
|
||||
// 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
|
||||
on_window_resized();
|
||||
|
||||
nr = img.nr();
|
||||
nc = img.nc();
|
||||
image_rect = r;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3502,7 +3504,7 @@ namespace dlib
|
||||
image_window& operator= (image_window&);
|
||||
|
||||
image_display gui_img;
|
||||
long nr, nc;
|
||||
rectangle image_rect;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
@ -2545,6 +2545,18 @@ namespace dlib
|
||||
(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 <
|
||||
typename T
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user