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 #if !USE_SHARED_LIBRARY
23 IMPLEMENT_DYNAMIC_CLASS(wxStaticPicture
, wxControl
)
30 BEGIN_EVENT_TABLE(wxStaticPicture
, wxControl
)
31 EVT_PAINT(wxStaticPicture::OnPaint
)
34 bool wxStaticPicture::Create(wxWindow
*parent
, wxWindowID id
,
35 const wxBitmap
& bitmap
,
47 size
.x
= bitmap
.GetWidth() ;
49 size
.y
= bitmap
.GetHeight() ;
52 m_backgroundColour
= parent
->GetBackgroundColour() ;
53 m_foregroundColour
= parent
->GetForegroundColour() ;
61 LastScaleX
= LastScaleY
= -1;
63 OriginalImage
= Bitmap
.ConvertToImage();
67 m_windowId
= (int)NewControlId();
71 m_windowStyle
= style
;
73 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
80 void wxStaticPicture::SetBitmap( const wxBitmap
& bmp
)
85 OriginalImage
= Bitmap
.ConvertToImage();
86 LastScaleX
= LastScaleY
= -1;
90 void wxStaticPicture::OnPaint(wxPaintEvent
& WXUNUSED(event
))
99 wxSize sz
= GetSize();
100 wxSize
bmpsz( Bitmap
.GetWidth(), Bitmap
.GetHeight() );
101 float sx
= 1.0f
, sy
= 1.0f
;
103 if ( Scale
& wxSCALE_UNIFORM
)
105 float _sx
= (float)sz
.GetWidth() / (float)bmpsz
.GetWidth();
106 float _sy
= (float)sz
.GetHeight() / (float)bmpsz
.GetHeight();
107 sx
= sy
= _sx
< _sy
? _sx
: _sy
;
110 if ( Scale
& wxSCALE_CUSTOM
)
117 if ( Scale
& wxSCALE_HORIZONTAL
)
118 sx
= (float)sz
.x
/(float)bmpsz
.x
;
119 if ( Scale
& wxSCALE_VERTICAL
)
120 sy
= (float)sz
.y
/(float)bmpsz
.y
;
123 bmpsz
= wxSize( (int)(bmpsz
.x
*sx
), (int)(bmpsz
.y
*sy
) );
127 if ( Align
& wxALIGN_CENTER_HORIZONTAL
) pos
.x
= (sz
.x
-bmpsz
.x
)/2;
128 else if ( Align
& wxALIGN_RIGHT
) pos
.x
= sz
.x
-bmpsz
.x
;
130 if ( Align
& wxALIGN_CENTER_VERTICAL
) pos
.y
= (sz
.y
-bmpsz
.y
)/2;
131 else if ( Align
& wxALIGN_BOTTOM
) pos
.y
= sz
.y
-bmpsz
.y
;
137 dc
.GetUserScale( &ux
, &uy
);
138 dc
.SetUserScale( ux
*sx
, uy
*sy
);
139 dc
.DrawBitmap( Bitmap
, (int)((float)pos
.x
/sx
), (int)((float)pos
.y
/sy
) );
140 dc
.SetUserScale( ux
, uy
);
142 if ( LastScaleX
!= sx
|| LastScaleY
!= sy
)
146 ScaledBitmap
= wxBitmap( OriginalImage
.Scale( bmpsz
.x
, bmpsz
.y
) );
148 dc
.DrawBitmap( ScaledBitmap
, pos
.x
, pos
.y
);
152 dc
.DrawBitmap( Bitmap
, pos
.x
, pos
.y
);
157 //WXDLLEXPORT_DATA(const wxChar *) wxStaticPictureNameStr = wxT("message");
158 const wxChar
* wxStaticPictureNameStr
= wxT("message");