git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8815
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
CreateMyMenuBar();
CreateStatusBar(1);
CreateMyMenuBar();
CreateStatusBar(1);
- SetStatusText( "Welcome!" );
+ SetStatusText( "Welcome to wxCanvas sample!" );
SetIcon(wxICON(mondrian));
SetIcon(wxICON(mondrian));
- // wxCanvas from here
-
+ // Create wxCanvasAdmin and wxCanvas.
m_admin = new wxCanvasAdmin;
wxCanvas *canvas = new wxCanvas( m_admin, this, -1 );
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 );
m_admin->Append( canvas );
+
+ // One wxCanvas is the active one (current rendering and current
+ // world coordinates).
m_admin->SetActive( canvas );
m_admin->SetActive( canvas );
+ // One object group is the root in every canvas.
wxCanvasObjectGroup *root = new wxCanvasObjectGroup(0,0);
root->DeleteContents( TRUE );
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 );
wxBitmap bitmap( smile_xpm );
wxImage image( bitmap );
r->SetBrush( *wxRED_BRUSH );
root->Append( r );
}
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 );
}
canvas->SetRoot( root );
}
//----------------------------------------------------------------------------
// wxCanvasObject
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// wxCanvasObject
//----------------------------------------------------------------------------
wxCanvasObject::wxCanvasObject()
{
// the default event handler is just this object
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) &&
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 (wxCanvasObject*) NULL;
}
return (wxCanvasObject*) NULL;
}
{
if (obj == this)
return this;
{
if (obj == this)
return this;
return (wxCanvasObject*) NULL;
}
return (wxCanvasObject*) NULL;
}
bool wxCanvasObject::IsCapturedMouse()
{
bool wxCanvasObject::IsCapturedMouse()
{
- return m_admin->GetActive()->GetCaptured()==this;
+ return (m_admin->GetActive()->GetCaptured() == this);
{
m_objects.Insert( obj );
if (m_objects.First())
{
m_objects.Insert( obj );
if (m_objects.First())
m_bbox.Expand(obj->GetBbox());
m_bbox.Expand(obj->GetBbox());
else
{
m_bbox.SetValid(FALSE);
else
{
m_bbox.SetValid(FALSE);
{
m_objects.Append( obj );
if (m_objects.First())
{
m_objects.Append( obj );
if (m_objects.First())
m_bbox.Expand(obj->GetBbox());
m_bbox.Expand(obj->GetBbox());
else
{
m_bbox.SetValid(FALSE);
else
{
m_bbox.SetValid(FALSE);
m_objects.Insert( before, obj );
m_bbox.SetValid(FALSE);
if (m_objects.First())
m_objects.Insert( before, obj );
m_bbox.SetValid(FALSE);
if (m_objects.First())
m_bbox.Expand(obj->GetBbox());
m_bbox.Expand(obj->GetBbox());
else
{
m_bbox.SetValid(FALSE);
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
{
//KKKfirst check if within bbox
//will only work if they are always uptodate
return m_objects.IndexOf( obj );
}
return m_objects.IndexOf( obj );
}
//----------------------------------------------------------------------------
// wxCanvasObjectRef
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// wxCanvasObjectRef
//----------------------------------------------------------------------------
wxCanvasObjectRef::wxCanvasObjectRef(double x, double y, wxCanvasObject* obj)
: wxCanvasObject()
{
wxCanvasObjectRef::wxCanvasObjectRef(double x, double y, wxCanvasObject* obj)
: wxCanvasObject()
{
m_obj = obj;
m_bbox.SetValid(FALSE);
m_obj = obj;
m_bbox.SetValid(FALSE);
- m_orgw=m_image.GetWidth();
- m_orgh=m_image.GetHeight();
+ m_orgw = m_image.GetWidth();
+ m_orgh = m_image.GetHeight();
- m_visible = FALSE;
-//KKK m_visible=TRUE;
void wxCanvasImage::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 )
}
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_background = *wxWHITE;
m_lastMouse = (wxCanvasObject*)NULL;
m_captureMouse = (wxCanvasObject*)NULL;
m_oldDeviceX = 0;
m_oldDeviceY = 0;
m_scrolled=FALSE;
m_oldDeviceX = 0;
m_oldDeviceY = 0;
m_scrolled=FALSE;
// make mappingmatrix
m_mapping_matrix.Identity();
if (!border)
// 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);
// 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
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;
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);
- 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);
- 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);
}
// coordinates conversions
}
// coordinates conversions