1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticPicture
4 // Author: Wade Brainerd (wadeb@wadeb.com)
8 // Copyright: (c) Wade Brainerd
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/gizmos/statpict.h"
16 #include "wx/dcclient.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxStaticPicture
, wxControl
)
19 WXDLLIMPEXP_GIZMOS
const wxChar
* wxStaticPictureNameStr
= wxT("staticPicture");
25 BEGIN_EVENT_TABLE(wxStaticPicture
, wxControl
)
26 EVT_PAINT(wxStaticPicture::OnPaint
)
29 bool wxStaticPicture::Create(wxWindow
*parent
, wxWindowID id
,
30 const wxBitmap
& bitmap
,
41 if ( size
.x
== wxDefaultCoord
)
42 size
.x
= bitmap
.GetWidth() ;
43 if ( size
.y
== wxDefaultCoord
)
44 size
.y
= bitmap
.GetHeight() ;
47 m_backgroundColour
= parent
->GetBackgroundColour() ;
48 m_foregroundColour
= parent
->GetForegroundColour() ;
56 LastScaleX
= LastScaleY
= -1;
58 OriginalImage
= Bitmap
.ConvertToImage();
62 m_windowId
= (int)NewControlId();
66 m_windowStyle
= style
;
68 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
75 void wxStaticPicture::SetBitmap( const wxBitmap
& bmp
)
80 OriginalImage
= Bitmap
.ConvertToImage();
81 LastScaleX
= LastScaleY
= -1;
85 void wxStaticPicture::OnPaint(wxPaintEvent
& WXUNUSED(event
))
94 wxSize sz
= GetSize();
95 wxSize
bmpsz( Bitmap
.GetWidth(), Bitmap
.GetHeight() );
96 float sx
= 1.0f
, sy
= 1.0f
;
98 if ( Scale
& wxSCALE_UNIFORM
)
100 float _sx
= (float)sz
.GetWidth() / (float)bmpsz
.GetWidth();
101 float _sy
= (float)sz
.GetHeight() / (float)bmpsz
.GetHeight();
102 sx
= sy
= _sx
< _sy
? _sx
: _sy
;
105 if ( Scale
& wxSCALE_CUSTOM
)
112 if ( Scale
& wxSCALE_HORIZONTAL
)
113 sx
= (float)sz
.x
/(float)bmpsz
.x
;
114 if ( Scale
& wxSCALE_VERTICAL
)
115 sy
= (float)sz
.y
/(float)bmpsz
.y
;
118 bmpsz
= wxSize( (int)(bmpsz
.x
*sx
), (int)(bmpsz
.y
*sy
) );
122 if ( Align
& wxALIGN_CENTER_HORIZONTAL
) pos
.x
= (sz
.x
-bmpsz
.x
)/2;
123 else if ( Align
& wxALIGN_RIGHT
) pos
.x
= sz
.x
-bmpsz
.x
;
125 if ( Align
& wxALIGN_CENTER_VERTICAL
) pos
.y
= (sz
.y
-bmpsz
.y
)/2;
126 else if ( Align
& wxALIGN_BOTTOM
) pos
.y
= sz
.y
-bmpsz
.y
;
132 dc
.GetUserScale( &ux
, &uy
);
133 dc
.SetUserScale( ux
*sx
, uy
*sy
);
134 dc
.DrawBitmap( Bitmap
, (int)((float)pos
.x
/sx
), (int)((float)pos
.y
/sy
) );
135 dc
.SetUserScale( ux
, uy
);
137 if ( LastScaleX
!= sx
|| LastScaleY
!= sy
)
141 ScaledBitmap
= wxBitmap( OriginalImage
.Scale( bmpsz
.x
, bmpsz
.y
) );
143 dc
.DrawBitmap( ScaledBitmap
, pos
.x
, pos
.y
);
147 dc
.DrawBitmap( Bitmap
, pos
.x
, pos
.y
);