Applied patch [ 735948 ] wxStaticPicture contrib
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20826 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
c8e4fa8b2d
commit
fca36d9a03
141
contrib/include/wx/gizmos/statpict.h
Normal file
141
contrib/include/wx/gizmos/statpict.h
Normal file
@ -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_
|
@ -122,5 +122,9 @@ SOURCE=.\splittree.cpp
|
|||||||
|
|
||||||
SOURCE=.\ledctrl.cpp
|
SOURCE=.\ledctrl.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\statpict.cpp
|
||||||
|
# End Source File
|
||||||
# End Target
|
# End Target
|
||||||
# End Project
|
# End Project
|
||||||
|
@ -14,9 +14,9 @@ LIBVERSION_AGE=@WX_AGE@
|
|||||||
HEADER_PATH=$(top_srcdir)/contrib/include/wx
|
HEADER_PATH=$(top_srcdir)/contrib/include/wx
|
||||||
HEADER_SUBDIR=gizmos
|
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)
|
DEPFILES=$(OBJECTS:.o=.d)
|
||||||
|
|
||||||
APPEXTRADEFS=-I$(top_srcdir)/contrib/include
|
APPEXTRADEFS=-I$(top_srcdir)/contrib/include
|
||||||
|
@ -19,6 +19,7 @@ OBJECTS = \
|
|||||||
$(OBJ_PATH)\editlbox.obj \
|
$(OBJ_PATH)\editlbox.obj \
|
||||||
$(OBJ_PATH)\dynamicsash.obj \
|
$(OBJ_PATH)\dynamicsash.obj \
|
||||||
$(OBJ_PATH)\ledctrl.obj \
|
$(OBJ_PATH)\ledctrl.obj \
|
||||||
|
$(OBJ_PATH)\statpict.obj \
|
||||||
|
|
||||||
!include $(WXDIR)\src\makelib.b32
|
!include $(WXDIR)\src\makelib.b32
|
||||||
|
|
||||||
@ -27,4 +28,5 @@ $(OBJ_PATH)\splittree.obj : splittree.cpp
|
|||||||
$(OBJ_PATH)\editlbox.obj : editlbox.cpp
|
$(OBJ_PATH)\editlbox.obj : editlbox.cpp
|
||||||
$(OBJ_PATH)\dynamicsash.obj : dynamicsash.cpp
|
$(OBJ_PATH)\dynamicsash.obj : dynamicsash.cpp
|
||||||
$(OBJ_PATH)\ledctrl.obj : ledctrl.cpp
|
$(OBJ_PATH)\ledctrl.obj : ledctrl.cpp
|
||||||
|
$(OBJ_PATH)\statpict.obj : statpict.cpp
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
WXDIR = ../../..
|
WXDIR = ../../..
|
||||||
|
|
||||||
LIBTARGET=$(WXDIR)/lib/libgizmos.a
|
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
|
include $(WXDIR)/src/makelib.g95
|
||||||
|
|
||||||
|
@ -17,7 +17,9 @@ LIB_CPP_SRC=\
|
|||||||
multicell.o\
|
multicell.o\
|
||||||
editlbox.o\
|
editlbox.o\
|
||||||
splittree.o\
|
splittree.o\
|
||||||
dynamicsash.o
|
dynamicsash.o\
|
||||||
|
ledctrl.o\
|
||||||
|
statpict.o
|
||||||
|
|
||||||
all: $(GIZMOSLIB)
|
all: $(GIZMOSLIB)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ LOCALDOCDIR=$(WXDIR)\contrib\docs\latex\gizmos
|
|||||||
|
|
||||||
!include $(WXDIR)\src\makevc.env
|
!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
|
LIBTARGET=$(WXDIR)\lib\gizmos$(LIBEXT).lib
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@ OBJECTS = &
|
|||||||
$(OUTPUTDIR)\splittree.obj &
|
$(OUTPUTDIR)\splittree.obj &
|
||||||
$(OUTPUTDIR)\editlbox.obj &
|
$(OUTPUTDIR)\editlbox.obj &
|
||||||
$(OUTPUTDIR)\dynamicsash.obj &
|
$(OUTPUTDIR)\dynamicsash.obj &
|
||||||
$(OUTPUTDIR)\ledctrl.obj
|
$(OUTPUTDIR)\ledctrl.obj &
|
||||||
|
$(OUTPUTDIR)\statpict.obj
|
||||||
|
|
||||||
!include $(WXDIR)\src\makelib.wat
|
!include $(WXDIR)\src\makelib.wat
|
||||||
|
|
||||||
|
157
contrib/src/gizmos/statpict.cpp
Normal file
157
contrib/src/gizmos/statpict.cpp
Normal file
@ -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");
|
34
contrib/src/gizmos/statpict.txt
Normal file
34
contrib/src/gizmos/statpict.txt
Normal file
@ -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.
|
Loading…
Reference in New Issue
Block a user