CreateMyMenuBar();
CreateStatusBar(1);
- SetStatusText( "Welcome!" );
+ SetStatusText( "Welcome to wxCanvas sample!" );
SetIcon(wxICON(mondrian));
- // wxCanvas from here
-
+ // Create wxCanvasAdmin and wxCanvas.
m_admin = new wxCanvasAdmin;
wxCanvas *canvas = new wxCanvas( m_admin, this, -1 );
+
+ canvas->SetScroll( 0, 0, 400, 600 );
+ canvas->SetMappingScroll( 0, 0, 400, 600, FALSE );
+
+ // The wxCanvasAdmin need to know about all Admin wxCanvas objects.
m_admin->Append( canvas );
+
+ // One wxCanvas is the active one (current rendering and current
+ // world coordinates).
m_admin->SetActive( canvas );
-
+ // One object group is the root in every canvas.
wxCanvasObjectGroup *root = new wxCanvasObjectGroup(0,0);
root->DeleteContents( TRUE );
- wxCanvasRect *rect;
-
- rect = new wxCanvasRect( 120,10,120,140 );
- rect->SetBrush( *wxRED_BRUSH );
- root->Append( rect );
-
-/*
+ // Bunch of rects and images.
wxBitmap bitmap( smile_xpm );
wxImage image( bitmap );
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.
+ root->SetAdmin( m_admin );
+
+ // One object group is the root object.
canvas->SetRoot( root );
}
//----------------------------------------------------------------------------
// wxCanvasObject
//----------------------------------------------------------------------------
+
wxCanvasObject::wxCanvasObject()
{
// the default event handler is just this object
if ((x >= m_bbox.GetMinX()-margin) &&
(x <= m_bbox.GetMaxX()+margin) &&
(y >= m_bbox.GetMinY()-margin) &&
- (y <= m_bbox.GetMaxY()+margin)
- )
+ (y <= m_bbox.GetMaxY()+margin))
+ {
return this;
+ }
+
return (wxCanvasObject*) NULL;
}
{
if (obj == this)
return this;
+
return (wxCanvasObject*) NULL;
}
bool wxCanvasObject::IsCapturedMouse()
{
- return m_admin->GetActive()->GetCaptured()==this;
+ return (m_admin->GetActive()->GetCaptured() == this);
}
{
m_objects.Insert( obj );
if (m_objects.First())
+ {
m_bbox.Expand(obj->GetBbox());
+ }
else
{
m_bbox.SetValid(FALSE);
{
m_objects.Append( obj );
if (m_objects.First())
+ {
m_bbox.Expand(obj->GetBbox());
+ }
else
{
m_bbox.SetValid(FALSE);
m_objects.Insert( before, obj );
m_bbox.SetValid(FALSE);
if (m_objects.First())
+ {
m_bbox.Expand(obj->GetBbox());
+ }
else
{
m_bbox.SetValid(FALSE);
{
}
-wxCanvasObject* wxCanvasObjectGroup::IsHitWorld( double x, double y, double margin )
+wxCanvasObject* wxCanvasObjectGroup::IsHitWorld( double x, double y, double margin )
{
//KKKfirst check if within bbox
//will only work if they are always uptodate
return m_objects.IndexOf( obj );
}
-
-
//----------------------------------------------------------------------------
// wxCanvasObjectRef
//----------------------------------------------------------------------------
wxCanvasObjectRef::wxCanvasObjectRef(double x, double y, wxCanvasObject* obj)
: wxCanvasObject()
{
- lworld.Translate(x,y);
+ lworld.Translate(x,y);
m_obj = obj;
m_bbox.SetValid(FALSE);
m_image = image;
- m_orgw=m_image.GetWidth();
- m_orgh=m_image.GetHeight();
+ m_orgw = m_image.GetWidth();
+ m_orgh = m_image.GetHeight();
m_isImage = TRUE;
- m_visible = FALSE;
-//KKK m_visible=TRUE;
CalcBoundingBox();
}
void wxCanvasImage::CalcBoundingBox()
{
- m_bbox.SetMin( m_x , m_y);
- m_bbox.SetMax( m_x + m_width , m_y + m_height);
+ m_bbox.SetMin( m_x, m_y );
+ m_bbox.SetMax( m_x + m_width, m_y + m_height );
}
void wxCanvasImage::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height )
m_background = *wxWHITE;
m_lastMouse = (wxCanvasObject*)NULL;
m_captureMouse = (wxCanvasObject*)NULL;
- m_frozen = TRUE;
+ m_frozen = FALSE;
m_oldDeviceX = 0;
m_oldDeviceY = 0;
m_scrolled=FALSE;
// make mappingmatrix
m_mapping_matrix.Identity();
if (!border)
+ {
// translate the drawing to 0,0
if (m_yaxis)
m_mapping_matrix.Translate(-m_virt_minX,-m_virt_maxY);
else
m_mapping_matrix.Translate(-m_virt_minX,-m_virt_minY);
+ }
else
{
// make a small white border around the drawing
double dmvx = m_virtm_maxX - m_virtm_minX;
double dmvy = m_virtm_maxY - m_virtm_minY;
- SetScrollbar(wxHORIZONTAL,(m_virt_minX-m_virtm_minX)/dmvx *1000,dvx/dmvx *1000,1000,true);
+ SetScrollbar(wxHORIZONTAL,(m_virt_minX-m_virtm_minX)/dmvx *1000,dvx/dmvx *1000,1000,FALSE);
if (m_yaxis)
{
- SetScrollbar(wxVERTICAL,(m_virtm_maxY-m_virt_maxY)/dmvy *1000,dvy/dmvy *1000,1000,true);
+ SetScrollbar(wxVERTICAL,(m_virtm_maxY-m_virt_maxY)/dmvy *1000,dvy/dmvy *1000,1000,FALSE);
}
else
{
- SetScrollbar(wxVERTICAL,(m_virt_minY-m_virtm_minY)/dmvy *1000,dvy/dmvy *1000,1000,true);
+ SetScrollbar(wxVERTICAL,(m_virt_minY-m_virtm_minY)/dmvy *1000,dvy/dmvy *1000,1000,FALSE);
}
- m_scrolled=true;
+ m_scrolled=TRUE;
}
// coordinates conversions