From 46401b064104c93f86948209243d5f904b9fbc53 Mon Sep 17 00:00:00 2001 From: Davis King Date: Thu, 3 Sep 2009 21:29:40 +0000 Subject: [PATCH] Changed the image_window so that it doesn't resize itself if you keep giving it images that are the same size. This way if you are sending video data to it will allow the user to change the size of the window without having it snap right back. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403181 --- dlib/gui_widgets/widgets.cpp | 4 +++- dlib/gui_widgets/widgets.h | 28 ++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/dlib/gui_widgets/widgets.cpp b/dlib/gui_widgets/widgets.cpp index dd724401c..2b28a2c71 100644 --- a/dlib/gui_widgets/widgets.cpp +++ b/dlib/gui_widgets/widgets.cpp @@ -5806,7 +5806,9 @@ namespace dlib image_window:: image_window( ) : - gui_img(*this) + gui_img(*this), + nr(0), + nc(0) { // show this window on the screen show(); diff --git a/dlib/gui_widgets/widgets.h b/dlib/gui_widgets/widgets.h index 670c0d219..f6ef23699 100644 --- a/dlib/gui_widgets/widgets.h +++ b/dlib/gui_widgets/widgets.h @@ -3077,8 +3077,15 @@ namespace dlib ) { auto_mutex M(m); + + // if the new image has a different size when compared to the previous image + // then we should readjust the total rectangle size. + if (new_img.nr() != img.nr() || new_img.nc() != img.nc()) + set_total_rect_size(new_img.nc(), new_img.nr()); + else + parent.invalidate_rectangle(rect); + assign_image(img,new_img); - set_total_rect_size(img.nc(), img.nr()); } struct overlay_rect @@ -3162,7 +3169,7 @@ namespace dlib template < typename image_type > image_window( const image_type& img - ) : gui_img(*this) { set_image(img); show(); } + ) : gui_img(*this), nr(0), nc(0) { set_image(img); show(); } ~image_window( ); @@ -3176,11 +3183,19 @@ namespace dlib auto_mutex M(wm); gui_img.set_image(img); - // set the size of this window to match the size of the input image - set_size(img.nc()+padding*2,img.nr()+padding*2); + // 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) + { + // set the size of this window to match the size of the input image + set_size(img.nc()+padding*2,img.nr()+padding*2); - // call this to make sure everything else is setup properly - on_window_resized(); + // call this to make sure everything else is setup properly + on_window_resized(); + + nr = img.nr(); + nc = img.nc(); + } } void add_overlay ( @@ -3212,6 +3227,7 @@ namespace dlib image_window& operator= (image_window&); image_display gui_img; + long nr, nc; }; // ----------------------------------------------------------------------------------------