From fca36d9a0301c9bff307361f1f94048897ce2ae5 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 1 Jun 2003 16:26:58 +0000 Subject: [PATCH] Applied patch [ 735948 ] wxStaticPicture contrib git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20826 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/gizmos/statpict.h | 141 ++++++++++++++++++++++++ contrib/src/gizmos/GizmosVC.dsp | 4 + contrib/src/gizmos/Makefile.in | 4 +- contrib/src/gizmos/makefile.b32 | 2 + contrib/src/gizmos/makefile.g95 | 2 +- contrib/src/gizmos/makefile.unx | 4 +- contrib/src/gizmos/makefile.vc | 2 +- contrib/src/gizmos/makefile.wat | 3 +- contrib/src/gizmos/statpict.cpp | 157 +++++++++++++++++++++++++++ contrib/src/gizmos/statpict.txt | 34 ++++++ 10 files changed, 347 insertions(+), 6 deletions(-) create mode 100644 contrib/include/wx/gizmos/statpict.h create mode 100644 contrib/src/gizmos/statpict.cpp create mode 100644 contrib/src/gizmos/statpict.txt diff --git a/contrib/include/wx/gizmos/statpict.h b/contrib/include/wx/gizmos/statpict.h new file mode 100644 index 0000000000..942d6d2b6b --- /dev/null +++ b/contrib/include/wx/gizmos/statpict.h @@ -0,0 +1,141 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: statpict.h +// Purpose: wxStaticPicture class +// Author: Wade Brainerd +// Modified by: +// Created: 2003-05-01 +// RCS-ID: +// Copyright: (c) Wade Brainerd +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_STATPICT_H_ +#define _WX_STATPICT_H_ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "statpict.h" +#endif + +#include "wx/control.h" + +#include "wx/icon.h" +#include "wx/bitmap.h" +#include "wx/image.h" + +enum +{ + wxSCALE_HORIZONTAL = 0x1, + wxSCALE_VERTICAL = 0x2, + wxSCALE_UNIFORM = 0x4, + wxSCALE_CUSTOM = 0x8 +}; + +//WXDLLEXPORT_DATA(extern const wxChar*) wxStaticBitmapNameStr; +extern const wxChar* wxStaticPictureNameStr; + +class /*WXDLLEXPORT*/ wxStaticPicture : public wxControl +{ + DECLARE_DYNAMIC_CLASS(wxStaticPicture) + +public: + wxStaticPicture() {} + + wxStaticPicture( wxWindow* parent, wxWindowID id, + const wxBitmap& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxStaticPictureNameStr ) + { + Create( parent, id, label, pos, size, style, name ); + } + + bool Create( wxWindow* parent, wxWindowID id, + const wxBitmap& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxStaticPictureNameStr ); + + virtual void Command(wxCommandEvent& WXUNUSED(event)) {}; + virtual void ProcessCommand(wxCommandEvent& WXUNUSED(event)) {}; + void OnPaint(wxPaintEvent& event); + + void SetBitmap( const wxBitmap& bmp ); + + wxBitmap GetBitmap() const + { + return Bitmap; + } + + // Icon interface for compatibility with wxStaticBitmap. + void SetIcon( const wxIcon& icon ) + { + wxBitmap bmp; + bmp.CopyFromIcon( icon ); + SetBitmap( bmp ); + } + + wxIcon GetIcon() const + { + wxIcon icon; + icon.CopyFromBitmap( Bitmap ); + return icon; + } + + void SetAlignment( int align ) + { + Align = align; + } + + int GetAlignment() const + { + return Align; + } + + void SetScale( int scale ) + { + Scale = scale; + } + + int GetScale() const + { + return Scale; + } + + void SetCustomScale( float sx, float sy ) + { + ScaleX = sx; + ScaleY = sy; + } + + int GetCustomScale( float* sx, float* sy ) const + { + *sx = ScaleX; + *sy = ScaleY; + } + +protected: + wxBitmap Bitmap; + + int Align; + + int Scale; + float ScaleX; + float ScaleY; + +#ifndef __WXMSW__ + // When scaling is enabled, measures are taken to improve performance on non-Windows platforms. + // - The original bitmap is stored as a wxImage, because conversion from wxBitmap to wxImage is slow. + // - The latest scaled bitmap is cached, this improves performance when the control is repainted + // but the size hasn't changed (overlapping windows, movement, etc). + wxImage OriginalImage; + float LastScaleX; + float LastScaleY; + wxBitmap ScaledBitmap; +#endif + + DECLARE_EVENT_TABLE() +}; + +#endif // #ifndef _WX_STATPICT_H_ diff --git a/contrib/src/gizmos/GizmosVC.dsp b/contrib/src/gizmos/GizmosVC.dsp index 3862a451d4..61e449c4d6 100644 --- a/contrib/src/gizmos/GizmosVC.dsp +++ b/contrib/src/gizmos/GizmosVC.dsp @@ -122,5 +122,9 @@ SOURCE=.\splittree.cpp SOURCE=.\ledctrl.cpp # End Source File +# Begin Source File + +SOURCE=.\statpict.cpp +# End Source File # End Target # End Project diff --git a/contrib/src/gizmos/Makefile.in b/contrib/src/gizmos/Makefile.in index 436da14ab3..6fb1b58331 100644 --- a/contrib/src/gizmos/Makefile.in +++ b/contrib/src/gizmos/Makefile.in @@ -14,9 +14,9 @@ LIBVERSION_AGE=@WX_AGE@ HEADER_PATH=$(top_srcdir)/contrib/include/wx HEADER_SUBDIR=gizmos -HEADERS=multicell.h splittree.h editlbox.h dynamicsash.h ledctrl.h +HEADERS=multicell.h splittree.h editlbox.h dynamicsash.h ledctrl.h statpict.h -OBJECTS=multicell.o splittree.o editlbox.o dynamicsash.o ledctrl.o +OBJECTS=multicell.o splittree.o editlbox.o dynamicsash.o ledctrl.o statpict.o DEPFILES=$(OBJECTS:.o=.d) APPEXTRADEFS=-I$(top_srcdir)/contrib/include diff --git a/contrib/src/gizmos/makefile.b32 b/contrib/src/gizmos/makefile.b32 index 55ae2e4baa..d9aa9610d0 100644 --- a/contrib/src/gizmos/makefile.b32 +++ b/contrib/src/gizmos/makefile.b32 @@ -19,6 +19,7 @@ OBJECTS = \ $(OBJ_PATH)\editlbox.obj \ $(OBJ_PATH)\dynamicsash.obj \ $(OBJ_PATH)\ledctrl.obj \ + $(OBJ_PATH)\statpict.obj \ !include $(WXDIR)\src\makelib.b32 @@ -27,4 +28,5 @@ $(OBJ_PATH)\splittree.obj : splittree.cpp $(OBJ_PATH)\editlbox.obj : editlbox.cpp $(OBJ_PATH)\dynamicsash.obj : dynamicsash.cpp $(OBJ_PATH)\ledctrl.obj : ledctrl.cpp +$(OBJ_PATH)\statpict.obj : statpict.cpp diff --git a/contrib/src/gizmos/makefile.g95 b/contrib/src/gizmos/makefile.g95 index 0601ece9e9..e4e6453d0f 100644 --- a/contrib/src/gizmos/makefile.g95 +++ b/contrib/src/gizmos/makefile.g95 @@ -10,7 +10,7 @@ WXDIR = ../../.. LIBTARGET=$(WXDIR)/lib/libgizmos.a -OBJECTS = multicell.o splittree.o editlbox.o dynamicsash.o ledctrl.o +OBJECTS = multicell.o splittree.o editlbox.o dynamicsash.o ledctrl.o statpict.o include $(WXDIR)/src/makelib.g95 diff --git a/contrib/src/gizmos/makefile.unx b/contrib/src/gizmos/makefile.unx index b070bc96af..3ab72925b1 100644 --- a/contrib/src/gizmos/makefile.unx +++ b/contrib/src/gizmos/makefile.unx @@ -17,7 +17,9 @@ LIB_CPP_SRC=\ multicell.o\ editlbox.o\ splittree.o\ - dynamicsash.o + dynamicsash.o\ + ledctrl.o\ + statpict.o all: $(GIZMOSLIB) diff --git a/contrib/src/gizmos/makefile.vc b/contrib/src/gizmos/makefile.vc index 3dfd1cae6c..0988345d06 100644 --- a/contrib/src/gizmos/makefile.vc +++ b/contrib/src/gizmos/makefile.vc @@ -23,7 +23,7 @@ LOCALDOCDIR=$(WXDIR)\contrib\docs\latex\gizmos !include $(WXDIR)\src\makevc.env -OBJECTS = $(D)\multicell.obj $(D)\splittree.obj $(D)\editlbox.obj $(D)\dynamicsash.obj $(D)\ledctrl.obj +OBJECTS = $(D)\multicell.obj $(D)\splittree.obj $(D)\editlbox.obj $(D)\dynamicsash.obj $(D)\ledctrl.obj $(D)\statpict.obj LIBTARGET=$(WXDIR)\lib\gizmos$(LIBEXT).lib diff --git a/contrib/src/gizmos/makefile.wat b/contrib/src/gizmos/makefile.wat index ab37621153..806efd6055 100644 --- a/contrib/src/gizmos/makefile.wat +++ b/contrib/src/gizmos/makefile.wat @@ -10,7 +10,8 @@ OBJECTS = & $(OUTPUTDIR)\splittree.obj & $(OUTPUTDIR)\editlbox.obj & $(OUTPUTDIR)\dynamicsash.obj & - $(OUTPUTDIR)\ledctrl.obj + $(OUTPUTDIR)\ledctrl.obj & + $(OUTPUTDIR)\statpict.obj !include $(WXDIR)\src\makelib.wat diff --git a/contrib/src/gizmos/statpict.cpp b/contrib/src/gizmos/statpict.cpp new file mode 100644 index 0000000000..e3f39f4ec8 --- /dev/null +++ b/contrib/src/gizmos/statpict.cpp @@ -0,0 +1,157 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: statpict.cpp +// Purpose: wxStaticPicture +// Author: Wade Brainerd (wadeb@wadeb.com) +// Modified by: +// Created: 2003-05-01 +// RCS-ID: +// Copyright: (c) Wade Brainerd +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ + #pragma implementation "statpict.h" +#endif + +#include "wx/defs.h" + +#include "statpict.h" +#include "wx/dcclient.h" + +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxStaticPicture, wxControl) +#endif + +/* + * wxStaticPicture + */ + +BEGIN_EVENT_TABLE(wxStaticPicture, wxControl) + EVT_PAINT(wxStaticPicture::OnPaint) +END_EVENT_TABLE() + +bool wxStaticPicture::Create(wxWindow *parent, wxWindowID id, + const wxBitmap& bitmap, + const wxPoint& pos, + const wxSize& s, + long style, + const wxString& name) +{ + SetName(name); + + wxSize size = s ; + if ( bitmap.Ok() ) + { + if ( size.x == -1 ) + size.x = bitmap.GetWidth() ; + if ( size.y == -1 ) + size.y = bitmap.GetHeight() ; + } + + m_backgroundColour = parent->GetBackgroundColour() ; + m_foregroundColour = parent->GetForegroundColour() ; + + Bitmap = bitmap; + Align = 0; + Scale = 0; + ScaleX = ScaleY = 1; + +#ifndef __WXMSW__ + LastScaleX = LastScaleY = -1; + if ( Bitmap.Ok() ) + OriginalImage = Bitmap.ConvertToImage(); +#endif + + if ( id == -1 ) + m_windowId = (int)NewControlId(); + else + m_windowId = id; + + m_windowStyle = style; + + bool ret = wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ); + + SetBestSize( size ) ; + + return ret; +} + +void wxStaticPicture::SetBitmap( const wxBitmap& bmp ) +{ + Bitmap = bmp; +#ifndef __WXMSW__ + if ( Bitmap.Ok() ) + OriginalImage = Bitmap.ConvertToImage(); + LastScaleX = LastScaleY = -1; +#endif +} + +void wxStaticPicture::OnPaint(wxPaintEvent& WXUNUSED(event)) +{ + if ( !Bitmap.Ok() ) + return; + + wxPaintDC dc( this ); + PrepareDC( dc ); + dc.BeginDrawing(); + + wxSize sz = GetSize(); + wxSize bmpsz( Bitmap.GetWidth(), Bitmap.GetHeight() ); + float sx = 1.0f, sy = 1.0f; + + if ( Scale & wxSCALE_UNIFORM ) + { + float _sx = (float)sz.GetWidth() / (float)bmpsz.GetWidth(); + float _sy = (float)sz.GetHeight() / (float)bmpsz.GetHeight(); + sx = sy = _sx < _sy ? _sx : _sy; + } + else + if ( Scale & wxSCALE_CUSTOM ) + { + sx = ScaleX; + sy = ScaleY; + } + else + { + if ( Scale & wxSCALE_HORIZONTAL ) + sx = (float)sz.x/(float)bmpsz.x; + if ( Scale & wxSCALE_VERTICAL ) + sy = (float)sz.y/(float)bmpsz.y; + } + + bmpsz = wxSize( (int)(bmpsz.x*sx), (int)(bmpsz.y*sy) ); + + wxPoint pos( 0, 0 ); + + if ( Align & wxALIGN_CENTER_HORIZONTAL ) pos.x = (sz.x-bmpsz.x)/2; + else if ( Align & wxALIGN_RIGHT ) pos.x = sz.x-bmpsz.x; + + if ( Align & wxALIGN_CENTER_VERTICAL ) pos.y = (sz.y-bmpsz.y)/2; + else if ( Align & wxALIGN_BOTTOM ) pos.y = sz.y-bmpsz.y; + + if ( Scale ) + { +#ifdef __WXMSW__ + double ux, uy; + dc.GetUserScale( &ux, &uy ); + dc.SetUserScale( ux*sx, uy*sy ); + dc.DrawBitmap( Bitmap, (int)((float)pos.x/sx), (int)((float)pos.y/sy) ); + dc.SetUserScale( ux, uy ); +#else + if ( LastScaleX != sx || LastScaleY != sy ) + { + LastScaleX = sx; + LastScaleY = sy; + ScaledBitmap = wxBitmap( OriginalImage.Scale( bmpsz.x, bmpsz.y ) ); + } + dc.DrawBitmap( ScaledBitmap, pos.x, pos.y ); +#endif + } + else + dc.DrawBitmap( Bitmap, pos.x, pos.y ); + + dc.EndDrawing(); +} + +//WXDLLEXPORT_DATA(const wxChar *) wxStaticPictureNameStr = wxT("message"); +const wxChar * wxStaticPictureNameStr = wxT("message"); diff --git a/contrib/src/gizmos/statpict.txt b/contrib/src/gizmos/statpict.txt new file mode 100644 index 0000000000..9a263285fb --- /dev/null +++ b/contrib/src/gizmos/statpict.txt @@ -0,0 +1,34 @@ +wxStaticPicture class +by Wade Brainerd (wadeb@wadeb.com) + +Description: + +This class is an improved version of wxStaticBitmap. + +Rather than using a native bitmap control, it uses DC operations to draw the +control. This makes its appearance more consistent across platforms, and +allows for additional features. + +Features include: + + wxStaticBitmap compatible API - drop-in replacement. Image alignment - top, + left, bottom, right, center vertical and/or horizontal. + Image scaling - scale horizontally and/or vertically, justified scaling + (maintains image aspect ratio). + +Platforms tested: + + wxMSW + wxGTK + wxMac + +Implementation notes: + +Under MSW wxWindows uses the operating system to do an optimized (potentially +hardware accelerated) blit in wxDC::DrawBitmap. This is usually fast enough to +do image scaling without affecting the program's interactivity. + +On wxMac and wxGTK however, wxDC::DrawBitmap implicitly calls wxImage::Scale +which is a much slower operation. Therefore, on these platforms wxStaticPicture +caches the scaled image to make updates that don't change the image (overlapping +windows, etc.) faster. -- 2.47.2