]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/gizmos/statpict.cpp
Only support detection of "near the edge" coordinates, if dragging grid lines
[wxWidgets.git] / contrib / src / gizmos / statpict.cpp
CommitLineData
fca36d9a
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: statpict.cpp
3// Purpose: wxStaticPicture
4// Author: Wade Brainerd (wadeb@wadeb.com)
5// Modified by:
6// Created: 2003-05-01
7// RCS-ID:
8// Copyright: (c) Wade Brainerd
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
0199503b 12#include "wx/wxprec.h"
fca36d9a
JS
13#include "wx/defs.h"
14
bce78bdc 15#include "wx/gizmos/statpict.h"
fca36d9a
JS
16#include "wx/dcclient.h"
17
fca36d9a 18IMPLEMENT_DYNAMIC_CLASS(wxStaticPicture, wxControl)
934b2e18
RD
19WXDLLIMPEXP_GIZMOS const wxChar * wxStaticPictureNameStr = wxT("staticPicture");
20
fca36d9a
JS
21/*
22 * wxStaticPicture
23 */
24
25BEGIN_EVENT_TABLE(wxStaticPicture, wxControl)
26 EVT_PAINT(wxStaticPicture::OnPaint)
27END_EVENT_TABLE()
28
29bool wxStaticPicture::Create(wxWindow *parent, wxWindowID id,
30 const wxBitmap& bitmap,
31 const wxPoint& pos,
32 const wxSize& s,
33 long style,
34 const wxString& name)
35{
36 SetName(name);
37
38 wxSize size = s ;
39 if ( bitmap.Ok() )
40 {
422d0ff0 41 if ( size.x == wxDefaultCoord )
fca36d9a 42 size.x = bitmap.GetWidth() ;
422d0ff0 43 if ( size.y == wxDefaultCoord )
fca36d9a
JS
44 size.y = bitmap.GetHeight() ;
45 }
46
47 m_backgroundColour = parent->GetBackgroundColour() ;
48 m_foregroundColour = parent->GetForegroundColour() ;
49
50 Bitmap = bitmap;
51 Align = 0;
52 Scale = 0;
53 ScaleX = ScaleY = 1;
54
55#ifndef __WXMSW__
56 LastScaleX = LastScaleY = -1;
57 if ( Bitmap.Ok() )
58 OriginalImage = Bitmap.ConvertToImage();
59#endif
60
a2d49353 61 if ( id == wxID_ANY )
fca36d9a
JS
62 m_windowId = (int)NewControlId();
63 else
64 m_windowId = id;
65
66 m_windowStyle = style;
67
68 bool ret = wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name );
69
70 SetBestSize( size ) ;
71
72 return ret;
73}
74
75void wxStaticPicture::SetBitmap( const wxBitmap& bmp )
76{
77 Bitmap = bmp;
78#ifndef __WXMSW__
79 if ( Bitmap.Ok() )
80 OriginalImage = Bitmap.ConvertToImage();
81 LastScaleX = LastScaleY = -1;
82#endif
83}
84
85void wxStaticPicture::OnPaint(wxPaintEvent& WXUNUSED(event))
86{
87 if ( !Bitmap.Ok() )
88 return;
89
90 wxPaintDC dc( this );
91 PrepareDC( dc );
fca36d9a
JS
92
93 wxSize sz = GetSize();
94 wxSize bmpsz( Bitmap.GetWidth(), Bitmap.GetHeight() );
95 float sx = 1.0f, sy = 1.0f;
96
97 if ( Scale & wxSCALE_UNIFORM )
98 {
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;
102 }
103 else
104 if ( Scale & wxSCALE_CUSTOM )
105 {
106 sx = ScaleX;
107 sy = ScaleY;
108 }
109 else
110 {
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;
115 }
116
117 bmpsz = wxSize( (int)(bmpsz.x*sx), (int)(bmpsz.y*sy) );
118
119 wxPoint pos( 0, 0 );
120
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;
123
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;
126
127 if ( Scale )
128 {
129#ifdef __WXMSW__
130 double ux, uy;
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 );
135#else
136 if ( LastScaleX != sx || LastScaleY != sy )
137 {
138 LastScaleX = sx;
139 LastScaleY = sy;
140 ScaledBitmap = wxBitmap( OriginalImage.Scale( bmpsz.x, bmpsz.y ) );
141 }
142 dc.DrawBitmap( ScaledBitmap, pos.x, pos.y );
143#endif
144 }
145 else
146 dc.DrawBitmap( Bitmap, pos.x, pos.y );
fca36d9a
JS
147}
148