]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/canvas/canvas.cpp
5f0b37105ad3722531183403011de6151a6947ae
1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Robert Roebling
5 // Copyright: 2000 (c) Robert Roebling
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "canvas.cpp"
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
20 #include "wx/canvas/canvas.h"
24 #include <gdk/gdkrgb.h>
25 #include "wx/gtk/win_gtk.h"
28 // WDR: class implementations
30 //----------------------------------------------------------------------------
32 //----------------------------------------------------------------------------
34 wxCanvasObject::wxCanvasObject( int x
, int y
, int width
, int height
)
40 m_area
.height
= height
;
46 void wxCanvasObject::Move( int x
, int y
)
56 // TODO: sometimes faster to merge into 1 Update or
57 // to break up into four
58 m_owner
->Update( old_x
, old_y
, m_area
.width
, m_area
.height
);
59 m_owner
->Update( x
, y
, m_area
.width
, m_area
.height
);
63 void wxCanvasObject::WriteSVG( wxTextOutputStream
&stream
)
67 void wxCanvasObject::Render( int clip_x
, int clip_y
, int clip_width
, int clip_height
)
71 //----------------------------------------------------------------------------
73 //----------------------------------------------------------------------------
75 wxCanvasImage::wxCanvasImage( const wxImage
&image
, int x
, int y
)
76 : wxCanvasObject( x
, y
, image
.GetWidth(), image
.GetHeight() )
82 void wxCanvasImage::Render( int clip_x
, int clip_y
, int clip_width
, int clip_height
)
84 m_owner
->GetBuffer()->Paste( m_image
, m_area
.x
, m_area
.y
);
87 void wxCanvasImage::WriteSVG( wxTextOutputStream
&stream
)
92 //----------------------------------------------------------------------------
94 //----------------------------------------------------------------------------
96 IMPLEMENT_CLASS(wxCanvas
,wxScrolledWindow
)
98 BEGIN_EVENT_TABLE(wxCanvas
,wxScrolledWindow
)
99 EVT_CHAR( wxCanvas::OnChar
)
100 EVT_PAINT( wxCanvas::OnPaint
)
101 EVT_SIZE( wxCanvas::OnSize
)
102 EVT_IDLE( wxCanvas::OnIdle
)
103 EVT_MOUSE_EVENTS( wxCanvas::OnMouse
)
104 EVT_SET_FOCUS( wxCanvas::OnSetFocus
)
105 EVT_KILL_FOCUS( wxCanvas::OnKillFocus
)
108 wxCanvas::wxCanvas( wxWindow
*parent
, wxWindowID id
,
109 const wxPoint
&position
, const wxSize
& size
, long style
) :
110 wxScrolledWindow( parent
, id
, position
, size
, style
)
112 m_needUpdate
= FALSE
;
113 m_objects
.DeleteContents( TRUE
);
116 wxCanvas::~wxCanvas()
118 wxNode
*node
= m_updateRects
.First();
121 wxRect
*rect
= (wxRect
*) node
->Data();
123 m_updateRects
.DeleteNode( node
);
124 node
= m_updateRects
.First();
128 void wxCanvas::SetArea( int width
, int height
)
130 m_buffer
= wxImage( width
, height
);
131 SetScrollbars( 10, 10, width
/10, height
/10 );
134 void wxCanvas::Update( int x
, int y
, int width
, int height
)
138 m_updateRects
.Append(
139 (wxObject
*) new wxRect( x
,y
,width
,height
) );
141 // speed up with direct access
143 for (yy
= y
; yy
< y
+height
; yy
++)
144 for (xx
= x
; xx
< x
+width
; xx
++)
145 m_buffer
.SetRGB( xx
, yy
, 0, 0, 0 );
147 wxNode
*node
= m_objects
.First();
150 wxCanvasObject
*obj
= (wxCanvasObject
*) node
->Data();
153 ww
= obj
->GetWidth();
154 hh
= obj
->GetHeight();
158 obj
->Render( x
, y
, width
, height
);
165 void wxCanvas::UpdateNow()
167 if (!m_needUpdate
) return;
169 wxClientDC
dc( this );
172 wxNode
*node
= m_updateRects
.First();
175 wxRect
*rect
= (wxRect
*) node
->Data();
176 wxImage
sub_image( m_buffer
.GetSubImage( *rect
) );
178 // DirectDraw here, please
181 int bpp
= wxDisplayDepth();
184 // the init code is doubled in wxImage
185 static bool s_hasInitialized
= FALSE
;
187 if (!s_hasInitialized
)
190 s_hasInitialized
= TRUE
;
195 CalcScrolledPosition( x
, y
, &x
, &y
);
197 gdk_draw_rgb_image( GTK_PIZZA(m_wxwindow
)->bin_window
,
198 m_wxwindow
->style
->black_gc
,
200 sub_image
.GetWidth(), sub_image
.GetHeight(),
203 sub_image
.GetWidth()*3 );
207 wxBitmap
bitmap( sub_image
.ConvertToBitmap() );
208 dc
.DrawBitmap( bitmap
, rect
->x
, rect
->y
);
213 wxBitmap
bitmap( sub_image
.ConvertToBitmap() );
214 dc
.DrawBitmap( bitmap
, rect
->x
, rect
->y
);
218 m_updateRects
.DeleteNode( node
);
219 node
= m_updateRects
.First();
223 void wxCanvas::Prepend( wxCanvasObject
* obj
)
225 m_objects
.Insert( obj
);
227 obj
->SetOwner( this );
229 if (!obj
->IsControl())
230 Update( obj
->GetX(), obj
->GetY(), obj
->GetWidth(), obj
->GetHeight() );
233 void wxCanvas::Append( wxCanvasObject
* obj
)
235 m_objects
.Append( obj
);
237 obj
->SetOwner( this );
239 if (!obj
->IsControl())
240 Update( obj
->GetX(), obj
->GetY(), obj
->GetWidth(), obj
->GetHeight() );
243 void wxCanvas::Insert( size_t before
, wxCanvasObject
* obj
)
245 m_objects
.Insert( before
, obj
);
247 obj
->SetOwner( this );
249 if (!obj
->IsControl())
250 Update( obj
->GetX(), obj
->GetY(), obj
->GetWidth(), obj
->GetHeight() );
253 void wxCanvas::Remove( wxCanvasObject
* obj
)
257 int w
= obj
->GetWidth();
258 int h
= obj
->GetHeight();
259 bool ic
= obj
->IsControl();
261 m_objects
.DeleteObject( obj
);
264 Update( x
, y
, w
, h
);
267 void wxCanvas::OnPaint(wxPaintEvent
&event
)
275 wxRegionIterator
it( GetUpdateRegion() );
280 CalcUnscrolledPosition( x
, y
, &x
, &y
);
282 int w
= it
.GetWidth();
283 int h
= it
.GetHeight();
284 if (x
+ w
> m_buffer
.GetWidth())
285 w
= m_buffer
.GetWidth()-x
;
286 if (y
+ h
> m_buffer
.GetHeight())
287 h
= m_buffer
.GetHeight()-y
;
289 m_updateRects
.Append( (wxObject
*) new wxRect( x
, y
, w
, h
) );
295 void wxCanvas::OnMouse(wxMouseEvent
&event
)
297 // Propagate to objects here
300 void wxCanvas::OnSize(wxSizeEvent
&event
)
305 void wxCanvas::OnIdle(wxIdleEvent
&event
)
311 void wxCanvas::OnSetFocus(wxFocusEvent
&event
)
315 void wxCanvas::OnKillFocus(wxFocusEvent
&event
)
319 void wxCanvas::OnChar(wxKeyEvent
&event
)