1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticPicture
4 // Author: Wade Brainerd (wadeb@wadeb.com)
8 // Copyright: (c) Wade Brainerd
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "statpict.h"
16 #include "wx/wxprec.h"
19 #include "wx/gizmos/statpict.h"
20 #include "wx/dcclient.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxStaticPicture
, wxControl
)
23 WXDLLIMPEXP_GIZMOS
const wxChar
* wxStaticPictureNameStr
= wxT("staticPicture");
29 BEGIN_EVENT_TABLE(wxStaticPicture
, wxControl
)
30 EVT_PAINT(wxStaticPicture::OnPaint
)
33 bool wxStaticPicture::Create(wxWindow
*parent
, wxWindowID id
,
34 const wxBitmap
& bitmap
,
45 if ( size
.x
== wxDefaultCoord
)
46 size
.x
= bitmap
.GetWidth() ;
47 if ( size
.y
== wxDefaultCoord
)
48 size
.y
= bitmap
.GetHeight() ;
51 m_backgroundColour
= parent
->GetBackgroundColour() ;
52 m_foregroundColour
= parent
->GetForegroundColour() ;
60 LastScaleX
= LastScaleY
= -1;
62 OriginalImage
= Bitmap
.ConvertToImage();
66 m_windowId
= (int)NewControlId();
70 m_windowStyle
= style
;
72 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
79 void wxStaticPicture::SetBitmap( const wxBitmap
& bmp
)
84 OriginalImage
= Bitmap
.ConvertToImage();
85 LastScaleX
= LastScaleY
= -1;
89 void wxStaticPicture::OnPaint(wxPaintEvent
& WXUNUSED(event
))
98 wxSize sz
= GetSize();
99 wxSize
bmpsz( Bitmap
.GetWidth(), Bitmap
.GetHeight() );
100 float sx
= 1.0f
, sy
= 1.0f
;
102 if ( Scale
& wxSCALE_UNIFORM
)
104 float _sx
= (float)sz
.GetWidth() / (float)bmpsz
.GetWidth();
105 float _sy
= (float)sz
.GetHeight() / (float)bmpsz
.GetHeight();
106 sx
= sy
= _sx
< _sy
? _sx
: _sy
;
109 if ( Scale
& wxSCALE_CUSTOM
)
116 if ( Scale
& wxSCALE_HORIZONTAL
)
117 sx
= (float)sz
.x
/(float)bmpsz
.x
;
118 if ( Scale
& wxSCALE_VERTICAL
)
119 sy
= (float)sz
.y
/(float)bmpsz
.y
;
122 bmpsz
= wxSize( (int)(bmpsz
.x
*sx
), (int)(bmpsz
.y
*sy
) );
126 if ( Align
& wxALIGN_CENTER_HORIZONTAL
) pos
.x
= (sz
.x
-bmpsz
.x
)/2;
127 else if ( Align
& wxALIGN_RIGHT
) pos
.x
= sz
.x
-bmpsz
.x
;
129 if ( Align
& wxALIGN_CENTER_VERTICAL
) pos
.y
= (sz
.y
-bmpsz
.y
)/2;
130 else if ( Align
& wxALIGN_BOTTOM
) pos
.y
= sz
.y
-bmpsz
.y
;
136 dc
.GetUserScale( &ux
, &uy
);
137 dc
.SetUserScale( ux
*sx
, uy
*sy
);
138 dc
.DrawBitmap( Bitmap
, (int)((float)pos
.x
/sx
), (int)((float)pos
.y
/sy
) );
139 dc
.SetUserScale( ux
, uy
);
141 if ( LastScaleX
!= sx
|| LastScaleY
!= sy
)
145 ScaledBitmap
= wxBitmap( OriginalImage
.Scale( bmpsz
.x
, bmpsz
.y
) );
147 dc
.DrawBitmap( ScaledBitmap
, pos
.x
, pos
.y
);
151 dc
.DrawBitmap( Bitmap
, pos
.x
, pos
.y
);