BEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_MENU(ID_QUIT, MyFrame::OnQuit)
EVT_CLOSE(MyFrame::OnCloseWindow)
+ EVT_TIMER(-1, MyFrame::OnTimer)
END_EVENT_TABLE()
MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
m_smile1 = new wxCanvasImage( image, 0,70,32,32 );
root->Append( m_smile1 );
- wxCanvasRect *rect = new wxCanvasRect( 20,20,100,100 );
- rect->SetBrush( *wxRED_BRUSH );
- root->Append( rect );
+ wxCanvasCircle *circ = new wxCanvasCircle( 170,70,50 );
+ circ->SetBrush( *wxBLUE_BRUSH );
+ root->Append( circ );
-/*
int i;
for (i = 10; i < 300; i+=10)
{
r->SetBrush( *wxRED_BRUSH );
root->Append( r );
}
-*/
m_smile2 = new wxCanvasImage( image, 0,110,32,32 );
root->Append( m_smile2 );
-/*
for (i = 15; i < 300; i+=10)
{
wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
r->SetBrush( *wxRED_BRUSH );
root->Append( r );
}
-*/
// This will call all object and children recursivly so
// all know what their wxCanvasAdmin is. Call at the end.
// One object group is the root object.
canvas->SetRoot( root );
+
+ m_timer = new wxTimer( this );
+ m_timer->Start( 80, FALSE );
+}
+
+MyFrame::~MyFrame()
+{
+ delete m_timer;
}
void MyFrame::CreateMyMenuBar()
Destroy();
}
+void MyFrame::OnTimer( wxTimerEvent &event )
+{
+ m_smile1->MoveRelative( 1, 0);
+ m_smile2->MoveRelative( 1, 0);
+
+ wxWakeUpIdle();
+}
+
//------------------------------------------------------------------------------
// MyApp
//------------------------------------------------------------------------------
if (!obj->IsControl() )
{
- if (obj->IsHitWorld(x,y,margin))
+ if (obj->IsHitWorld(xh,yh,margin))
{
return obj;
}
CalcBoundingBox();
}
+void wxCanvasImage::SetPosXY( double x, double y)
+{
+ m_x = x;
+ m_y = y;
+ CalcBoundingBox();
+}
+
void wxCanvasImage::TransLate( double x, double y )
{
m_x += x;
void wxCanvasImage::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height )
{
if (!m_visible) return;
-
+
wxRect tmparea;
tmparea.x = m_admin->LogicalToDeviceXRel( m_bbox.GetMinX());
y = m_admin->LogicalToDeviceY(y);
+ // What is this???
if ( m_orgw*5 < m_admin->LogicalToDeviceXRel( m_bbox.GetWidth() ) ||
m_orgw/5 > m_admin->LogicalToDeviceXRel( m_bbox.GetWidth() ) ||
m_orgh*5 < m_admin->LogicalToDeviceYRel( m_bbox.GetHeight() ) ||
dc->DestroyClippingRegion();
return;
}
+
+ wxImage tmp;
+ bool is_cashed = FALSE;
- if ((m_admin->LogicalToDeviceXRel( m_bbox.GetWidth() ) == m_image.GetWidth()) &&
- (m_admin->LogicalToDeviceYRel( m_bbox.GetHeight() ) == m_image.GetHeight()))
+ if (m_cImage.Ok() && (m_cW == m_bbox.GetWidth()) && (m_cH == m_bbox.GetHeight()))
{
- m_tmp = m_image;
+ // use cached image
+ tmp = m_cImage;
+ is_cashed = TRUE;
}
else
{
- m_tmp = m_image.Scale( m_admin->LogicalToDeviceXRel( m_bbox.GetWidth()),
- m_admin->LogicalToDeviceYRel( m_bbox.GetHeight()) );
+ if ((m_admin->LogicalToDeviceXRel( m_bbox.GetWidth() ) == m_image.GetWidth()) &&
+ (m_admin->LogicalToDeviceYRel( m_bbox.GetHeight() ) == m_image.GetHeight()))
+ {
+ tmp = m_image;
+ }
+ else
+ {
+ tmp = m_image.Scale( m_admin->LogicalToDeviceXRel( m_bbox.GetWidth()),
+ m_admin->LogicalToDeviceYRel( m_bbox.GetHeight()) );
+ }
+
+ // create cached image
+ m_cImage = tmp;
+ m_cW = tmp.GetWidth();
+ m_cH = tmp.GetHeight();
}
- wxBitmap bmp;
// wxPoint centr(m_admin->LogicalToDeviceX(m_x),m_admin->LogicalToDeviceY(m_y));
wxPoint centr(0,0);
- if (cworld->GetRotation())
+ wxBitmap bmp;
+
+ if (m_cBitmap.Ok() && is_cashed && (m_cR == cworld->GetRotation()))
{
- bmp=m_tmp.Rotate(-cworld->GetRotation()/180.0 * pi,centr, TRUE, NULL).ConvertToBitmap();
+ bmp = m_cBitmap;
}
else
{
- bmp = m_tmp.ConvertToBitmap();
+ if (cworld->GetRotation())
+ tmp = tmp.Rotate(-cworld->GetRotation()/180.0 * pi, centr, TRUE, NULL );
+
+ bmp = tmp.ConvertToBitmap();
+
+ // create cached bitmap
+ m_cBitmap = bmp;
+ m_cR = cworld->GetRotation();
}
wxDC *dc = m_admin->GetActive()->GetDC();
}
else
{
- //TODO clipping not right
-// dc->DrawPoint(centr2);
-// dc->DrawPoint(x,y);
-
- if ((clip_x == x) &&
- (clip_y == y) &&
- (clip_width == tmparea.width) &&
- (clip_height == tmparea.height))
- {
- dc->DrawBitmap( m_tmp, clip_x, clip_y, TRUE );
- }
- else
- {
- int start_x = clip_x - (int)x;
- int start_y = clip_y - (int)y;
-
- //dc->DrawBitmap( bmp, x, y, TRUE );
- wxMemoryDC dcm;
- dcm.SelectObject(bmp);
- dc->Blit(clip_x, clip_y,clip_width, clip_height,&dcm,start_x,start_y,wxCOPY,TRUE);
- dcm.SelectObject(wxNullBitmap);
- }
+ dc->SetClippingRegion( clip_x, clip_y, clip_width, clip_height );
+ dc->DrawBitmap( bmp, x, y, TRUE );
+ dc->DestroyClippingRegion();
}
}