Small mods to wxCanvas.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8815 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2000-11-25 20:07:21 +00:00
parent 6c7873e1a5
commit f03b31e838
2 changed files with 43 additions and 30 deletions

View File

@@ -47,28 +47,29 @@ MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
CreateMyMenuBar(); CreateMyMenuBar();
CreateStatusBar(1); 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; m_admin = new wxCanvasAdmin;
wxCanvas *canvas = new wxCanvas( m_admin, this, -1 ); 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); wxCanvasObjectGroup *root = new wxCanvasObjectGroup(0,0);
root->DeleteContents( TRUE ); root->DeleteContents( TRUE );
wxCanvasRect *rect; // Bunch of rects and images.
rect = new wxCanvasRect( 120,10,120,140 );
rect->SetBrush( *wxRED_BRUSH );
root->Append( rect );
/*
wxBitmap bitmap( smile_xpm ); wxBitmap bitmap( smile_xpm );
wxImage image( bitmap ); wxImage image( bitmap );
@@ -92,8 +93,12 @@ MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
r->SetBrush( *wxRED_BRUSH ); r->SetBrush( *wxRED_BRUSH );
root->Append( r ); 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 );
} }

View File

@@ -50,6 +50,7 @@ FT_Library g_freetypeLibrary;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxCanvasObject // wxCanvasObject
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
wxCanvasObject::wxCanvasObject() wxCanvasObject::wxCanvasObject()
{ {
// the default event handler is just this object // the default event handler is just this object
@@ -367,9 +368,11 @@ wxCanvasObject* wxCanvasObject::IsHitWorld( double x, double y, double margin )
if ((x >= m_bbox.GetMinX()-margin) && if ((x >= m_bbox.GetMinX()-margin) &&
(x <= m_bbox.GetMaxX()+margin) && (x <= m_bbox.GetMaxX()+margin) &&
(y >= m_bbox.GetMinY()-margin) && (y >= m_bbox.GetMinY()-margin) &&
(y <= m_bbox.GetMaxY()+margin) (y <= m_bbox.GetMaxY()+margin))
) {
return this; return this;
}
return (wxCanvasObject*) NULL; return (wxCanvasObject*) NULL;
} }
@@ -377,6 +380,7 @@ wxCanvasObject* wxCanvasObject::Contains( wxCanvasObject* obj )
{ {
if (obj == this) if (obj == this)
return this; return this;
return (wxCanvasObject*) NULL; return (wxCanvasObject*) NULL;
} }
@@ -392,7 +396,7 @@ void wxCanvasObject::ReleaseMouse()
bool wxCanvasObject::IsCapturedMouse() bool wxCanvasObject::IsCapturedMouse()
{ {
return m_admin->GetActive()->GetCaptured()==this; return (m_admin->GetActive()->GetCaptured() == this);
} }
@@ -510,7 +514,9 @@ void wxCanvasObjectGroup::Prepend( wxCanvasObject* obj )
{ {
m_objects.Insert( obj ); m_objects.Insert( obj );
if (m_objects.First()) if (m_objects.First())
{
m_bbox.Expand(obj->GetBbox()); m_bbox.Expand(obj->GetBbox());
}
else else
{ {
m_bbox.SetValid(FALSE); m_bbox.SetValid(FALSE);
@@ -522,7 +528,9 @@ void wxCanvasObjectGroup::Append( wxCanvasObject* obj )
{ {
m_objects.Append( obj ); m_objects.Append( obj );
if (m_objects.First()) if (m_objects.First())
{
m_bbox.Expand(obj->GetBbox()); m_bbox.Expand(obj->GetBbox());
}
else else
{ {
m_bbox.SetValid(FALSE); m_bbox.SetValid(FALSE);
@@ -535,7 +543,9 @@ void wxCanvasObjectGroup::Insert( size_t before, wxCanvasObject* obj )
m_objects.Insert( before, obj ); m_objects.Insert( before, obj );
m_bbox.SetValid(FALSE); m_bbox.SetValid(FALSE);
if (m_objects.First()) if (m_objects.First())
{
m_bbox.Expand(obj->GetBbox()); m_bbox.Expand(obj->GetBbox());
}
else else
{ {
m_bbox.SetValid(FALSE); m_bbox.SetValid(FALSE);
@@ -711,8 +721,6 @@ int wxCanvasObjectGroup::IndexOf( wxCanvasObject* obj )
return m_objects.IndexOf( obj ); return m_objects.IndexOf( obj );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxCanvasObjectRef // wxCanvasObjectRef
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@@ -1425,8 +1433,6 @@ wxCanvasImage::wxCanvasImage( const wxImage &image, double x, double y, double w
m_orgh = m_image.GetHeight(); m_orgh = m_image.GetHeight();
m_isImage = TRUE; m_isImage = TRUE;
m_visible = FALSE;
//KKK m_visible=TRUE;
CalcBoundingBox(); CalcBoundingBox();
} }
@@ -1902,7 +1908,7 @@ wxCanvas::wxCanvas( wxCanvasAdmin* admin, wxWindow *parent, wxWindowID id,
m_background = *wxWHITE; m_background = *wxWHITE;
m_lastMouse = (wxCanvasObject*)NULL; m_lastMouse = (wxCanvasObject*)NULL;
m_captureMouse = (wxCanvasObject*)NULL; m_captureMouse = (wxCanvasObject*)NULL;
m_frozen = TRUE; m_frozen = FALSE;
m_oldDeviceX = 0; m_oldDeviceX = 0;
m_oldDeviceY = 0; m_oldDeviceY = 0;
m_scrolled=FALSE; m_scrolled=FALSE;
@@ -2607,11 +2613,13 @@ void wxCanvas::SetMappingScroll( double vx1, double vy1, double vx2, double v
// make mappingmatrix // make mappingmatrix
m_mapping_matrix.Identity(); m_mapping_matrix.Identity();
if (!border) if (!border)
{
// translate the drawing to 0,0 // translate the drawing to 0,0
if (m_yaxis) if (m_yaxis)
m_mapping_matrix.Translate(-m_virt_minX,-m_virt_maxY); m_mapping_matrix.Translate(-m_virt_minX,-m_virt_maxY);
else else
m_mapping_matrix.Translate(-m_virt_minX,-m_virt_minY); m_mapping_matrix.Translate(-m_virt_minX,-m_virt_minY);
}
else else
{ {
// make a small white border around the drawing // make a small white border around the drawing
@@ -2673,17 +2681,17 @@ void wxCanvas::SetScroll(double vx1,double vy1,double vx2,double vy2)
double dmvx = m_virtm_maxX - m_virtm_minX; double dmvx = m_virtm_maxX - m_virtm_minX;
double dmvy = m_virtm_maxY - m_virtm_minY; 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) 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 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 // coordinates conversions