Rescale images automatically with informations about internal requirements (Jaakko Salli).
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42111 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
e44d5a5892
commit
dc5a84857d
@ -46,18 +46,18 @@
|
|||||||
#include "wx/sizer.h"
|
#include "wx/sizer.h"
|
||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
#include "wx/dir.h"
|
#include "wx/dir.h"
|
||||||
|
#include "wx/msgdlg.h"
|
||||||
#include "wx/filename.h"
|
#include "wx/filename.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
#include "wx/imaglist.h"
|
#include "wx/imaglist.h"
|
||||||
#include "wx/bmpcbox.h"
|
#include "wx/bmpcbox.h"
|
||||||
|
|
||||||
|
|
||||||
#include "widgets.h"
|
#include "widgets.h"
|
||||||
|
|
||||||
#include "icons/bmpcombobox.xpm"
|
#include "icons/bmpcombobox.xpm"
|
||||||
|
|
||||||
// Images loaded from file are reduced this width and height, if larger
|
// Images loaded from file are reduced this width and height, if larger
|
||||||
#define IMG_SIZE_TRUNC 150
|
#define IMG_SIZE_TRUNC 256
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -152,13 +152,16 @@ protected:
|
|||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
wxTextCtrl **ppText);
|
wxTextCtrl **ppText);
|
||||||
|
|
||||||
|
#if wxUSE_IMAGE
|
||||||
|
void RescaleImage(wxImage& image, int w, int h);
|
||||||
|
#endif
|
||||||
|
|
||||||
// the controls
|
// the controls
|
||||||
// ------------
|
// ------------
|
||||||
|
|
||||||
// the checkboxes for styles
|
// the checkboxes for styles
|
||||||
wxCheckBox *m_chkSort,
|
wxCheckBox *m_chkSort,
|
||||||
*m_chkReadonly,
|
*m_chkReadonly;
|
||||||
*m_chkScaleimages;
|
|
||||||
|
|
||||||
// the combobox itself and the sizer it is in
|
// the combobox itself and the sizer it is in
|
||||||
wxBitmapComboBox *m_combobox;
|
wxBitmapComboBox *m_combobox;
|
||||||
@ -234,8 +237,7 @@ BitmapComboBoxWidgetsPage::BitmapComboBoxWidgetsPage(WidgetsBookCtrl *book,
|
|||||||
{
|
{
|
||||||
// init everything
|
// init everything
|
||||||
m_chkSort =
|
m_chkSort =
|
||||||
m_chkReadonly =
|
m_chkReadonly = (wxCheckBox *)NULL;
|
||||||
m_chkScaleimages = (wxCheckBox *)NULL;
|
|
||||||
|
|
||||||
m_combobox = (wxBitmapComboBox *)NULL;
|
m_combobox = (wxBitmapComboBox *)NULL;
|
||||||
m_sizerCombo = (wxSizer *)NULL;
|
m_sizerCombo = (wxSizer *)NULL;
|
||||||
@ -293,8 +295,6 @@ void BitmapComboBoxWidgetsPage::CreateContent()
|
|||||||
|
|
||||||
wxSizer *sizerOptions = new wxStaticBoxSizer(box, wxVERTICAL);
|
wxSizer *sizerOptions = new wxStaticBoxSizer(box, wxVERTICAL);
|
||||||
|
|
||||||
m_chkScaleimages = CreateCheckBoxAndAddToSizer(sizerOptions, _T("&Scale loaded images to fit"));
|
|
||||||
|
|
||||||
sizerRow = CreateSizerWithSmallTextAndLabel(_T("Control &height:"),
|
sizerRow = CreateSizerWithSmallTextAndLabel(_T("Control &height:"),
|
||||||
BitmapComboBoxPage_ChangeHeight,
|
BitmapComboBoxPage_ChangeHeight,
|
||||||
&m_textChangeHeight);
|
&m_textChangeHeight);
|
||||||
@ -382,7 +382,6 @@ void BitmapComboBoxWidgetsPage::Reset()
|
|||||||
{
|
{
|
||||||
m_chkSort->SetValue(false);
|
m_chkSort->SetValue(false);
|
||||||
m_chkReadonly->SetValue(true);
|
m_chkReadonly->SetValue(true);
|
||||||
m_chkScaleimages->SetValue(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapComboBoxWidgetsPage::CreateCombo()
|
void BitmapComboBoxWidgetsPage::CreateCombo()
|
||||||
@ -559,6 +558,33 @@ void BitmapComboBoxWidgetsPage::OnButtonAddSeveralWithImages(wxCommandEvent& WXU
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if wxUSE_IMAGE
|
||||||
|
void BitmapComboBoxWidgetsPage::RescaleImage(wxImage& image, int w, int h)
|
||||||
|
{
|
||||||
|
if ( image.GetWidth() == w && image.GetHeight() == h )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( w <= 0 || h <= 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
static bool isFirstScale = true;
|
||||||
|
|
||||||
|
if ( isFirstScale && m_combobox->GetCount() > 0 )
|
||||||
|
{
|
||||||
|
wxMessageBox( wxT("wxBitmapComboBox normally only supports images of one size. ")
|
||||||
|
wxT("However, for demonstration purposes, loaded bitmaps are scaled to fit ")
|
||||||
|
wxT("using wxImage::Rescale."),
|
||||||
|
wxT("Notice"),
|
||||||
|
wxOK,
|
||||||
|
this );
|
||||||
|
|
||||||
|
isFirstScale = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
image.Rescale(w, h);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void BitmapComboBoxWidgetsPage::LoadWidgetImages( wxArrayString* strings, wxImageList* images )
|
void BitmapComboBoxWidgetsPage::LoadWidgetImages( wxArrayString* strings, wxImageList* images )
|
||||||
{
|
{
|
||||||
wxFileName fn;
|
wxFileName fn;
|
||||||
@ -616,8 +642,7 @@ void BitmapComboBoxWidgetsPage::LoadWidgetImages( wxArrayString* strings, wxImag
|
|||||||
wxASSERT(fn.FileExists());
|
wxASSERT(fn.FileExists());
|
||||||
wxImage image(fn.GetFullPath());
|
wxImage image(fn.GetFullPath());
|
||||||
wxASSERT(image.Ok());
|
wxASSERT(image.Ok());
|
||||||
if ( m_chkScaleimages->GetValue() && foundSize.x > 0 )
|
RescaleImage(image, foundSize.x, foundSize.y);
|
||||||
image.Rescale(foundSize.x, foundSize.y);
|
|
||||||
wxBitmap bmp(image);
|
wxBitmap bmp(image);
|
||||||
wxASSERT( bmp.Ok() );
|
wxASSERT( bmp.Ok() );
|
||||||
#else
|
#else
|
||||||
@ -744,8 +769,8 @@ wxBitmap BitmapComboBoxWidgetsPage::LoadBitmap(const wxString& filepath)
|
|||||||
// Have some reasonable maximum size
|
// Have some reasonable maximum size
|
||||||
if ( foundSize.x <= 0 )
|
if ( foundSize.x <= 0 )
|
||||||
{
|
{
|
||||||
foundSize.x = 256;
|
foundSize.x = IMG_SIZE_TRUNC;
|
||||||
foundSize.y = 256;
|
foundSize.y = IMG_SIZE_TRUNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxImage image(filepath);
|
wxImage image(filepath);
|
||||||
@ -765,7 +790,7 @@ wxBitmap BitmapComboBoxWidgetsPage::LoadBitmap(const wxString& filepath)
|
|||||||
if ( h > foundSize.y )
|
if ( h > foundSize.y )
|
||||||
h = foundSize.y;
|
h = foundSize.y;
|
||||||
|
|
||||||
image.Rescale(w, h);
|
RescaleImage(image, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wxBitmap(image);
|
return wxBitmap(image);
|
||||||
@ -804,6 +829,8 @@ wxBitmap BitmapComboBoxWidgetsPage::QueryBitmap(wxString* pStr)
|
|||||||
bitmap = LoadBitmap(filepath);
|
bitmap = LoadBitmap(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxLogDebug(wxT("%i, %i"),bitmap.GetWidth(), bitmap.GetHeight());
|
||||||
|
|
||||||
::wxSetCursor( *wxSTANDARD_CURSOR );
|
::wxSetCursor( *wxSTANDARD_CURSOR );
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
|
Loading…
Reference in New Issue
Block a user