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
))
93 wxSize sz
= GetSize();
94 wxSize
bmpsz( Bitmap
.GetWidth(), Bitmap
.GetHeight() );
95 float sx
= 1.0f
, sy
= 1.0f
;
97 if ( Scale
& wxSCALE_UNIFORM
)
99 float _sx
= (float)sz
.GetWidth() / (float)bmpsz
.GetWidth();
100 float _sy
= (float)sz
.GetHeight() / (float)bmpsz
.GetHeight();
101 sx
= sy
= _sx
< _sy
? _sx
: _sy
;
104 if ( Scale
& wxSCALE_CUSTOM
)
111 if ( Scale
& wxSCALE_HORIZONTAL
)
112 sx
= (float)sz
.x
/(float)bmpsz
.x
;
113 if ( Scale
& wxSCALE_VERTICAL
)
114 sy
= (float)sz
.y
/(float)bmpsz
.y
;
117 bmpsz
= wxSize( (int)(bmpsz
.x
*sx
), (int)(bmpsz
.y
*sy
) );
121 if ( Align
& wxALIGN_CENTER_HORIZONTAL
) pos
.x
= (sz
.x
-bmpsz
.x
)/2;
122 else if ( Align
& wxALIGN_RIGHT
) pos
.x
= sz
.x
-bmpsz
.x
;
124 if ( Align
& wxALIGN_CENTER_VERTICAL
) pos
.y
= (sz
.y
-bmpsz
.y
)/2;
125 else if ( Align
& wxALIGN_BOTTOM
) pos
.y
= sz
.y
-bmpsz
.y
;
131 dc
.GetUserScale( &ux
, &uy
);
132 dc
.SetUserScale( ux
*sx
, uy
*sy
);
133 dc
.DrawBitmap( Bitmap
, (int)((float)pos
.x
/sx
), (int)((float)pos
.y
/sy
) );
134 dc
.SetUserScale( ux
, uy
);
136 if ( LastScaleX
!= sx
|| LastScaleY
!= sy
)
140 ScaledBitmap
= wxBitmap( OriginalImage
.Scale( bmpsz
.x
, bmpsz
.y
) );
142 dc
.DrawBitmap( ScaledBitmap
, pos
.x
, pos
.y
);
146 dc
.DrawBitmap( Bitmap
, pos
.x
, pos
.y
);