added groups of canvasobject and references to groups

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8307 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Hock
2000-09-08 18:42:57 +00:00
parent afdefa8e84
commit fcbb6b37bf
3 changed files with 586 additions and 155 deletions
+96 -7
View File
@@ -41,7 +41,7 @@ public:
// These are for screen output only therefore use
// int as coordinates.
virtual bool IsHit( int x, int y, int margin = 0 );
virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
// use doubles later
virtual void Move( int x, int y );
@@ -55,7 +55,7 @@ public:
virtual void WriteSVG( wxTextOutputStream &stream );
wxCanvas *GetOwner() { return m_owner; }
void SetOwner( wxCanvas *owner ) { m_owner = owner; }
virtual void SetOwner( wxCanvas *owner ) { m_owner = owner; }
bool IsControl() { return m_isControl; }
bool IsVector() { return m_isVector; }
@@ -74,11 +74,99 @@ protected:
bool m_isControl;
bool m_isVector;
bool m_isImage;
//relative boundingbox in parent in pixels
wxRect m_area;
friend class wxCanvas;
};
//----------------------------------------------------------------------------
// wxCanvasObjectGroup
//----------------------------------------------------------------------------
class wxCanvasObjectGroup
{
public:
wxCanvasObjectGroup();
void SetOwner(wxCanvas* canvas);
wxCanvas *GetOwner() { return m_owner; }
virtual void Prepend( wxCanvasObject* obj );
virtual void Append( wxCanvasObject* obj );
virtual void Insert( size_t before, wxCanvasObject* obj );
virtual void Remove( wxCanvasObject* obj );
virtual void Recreate();
void DeleteContents( bool );
virtual void Render(int xabs, int yabs,int x, int y, int width, int height );
virtual void WriteSVG( wxTextOutputStream &stream );
virtual bool IsHit( int x, int y, int margin );
virtual wxCanvasObject* IsHitObject( int x, int y, int margin );
void ExtendArea(int x, int y);
inline int GetXMin() { return m_minx; }
inline int GetYMin() { return m_miny; }
inline int GetXMax() { return m_maxx; }
inline int GetYMax() { return m_maxy; }
protected:
wxCanvas *m_owner;
//bounding box
double m_minx;
double m_miny;
double m_maxx;
double m_maxy;
bool m_validbounds;
wxList m_objects;
friend class wxCanvas;
};
//----------------------------------------------------------------------------
// wxCanvasObjectGroupRef
//----------------------------------------------------------------------------
class wxCanvasObjectGroupRef: public wxCanvasObject
{
public:
wxCanvasObjectGroupRef(double x, double y,wxCanvasObjectGroup* group);
void SetOwner(wxCanvas* canvas);
virtual void Recreate();
virtual void Render(int xabs, int yabs,int x, int y, int width, int height );
virtual void WriteSVG( wxTextOutputStream &stream );
virtual bool IsHit( int x, int y, int margin );
void Move( int x, int y );
inline int GetPosX() { return m_x; }
inline int GetPosY() { return m_y; }
void ExtendArea(int x, int y);
virtual wxCanvasObject* IsHitObject( int x, int y, int margin );
protected:
//position of the group
double m_x;
double m_y;
//reference to the group
wxCanvasObjectGroup* m_group;
//bounding box
double m_minx;
double m_miny;
double m_maxx;
double m_maxy;
bool m_validbounds;
};
//----------------------------------------------------------------------------
// wxCanvasRect
//----------------------------------------------------------------------------
@@ -91,7 +179,7 @@ public:
virtual void Recreate();
virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
virtual void WriteSVG( wxTextOutputStream &stream );
private:
@@ -117,7 +205,7 @@ public:
virtual void Recreate();
virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
virtual void WriteSVG( wxTextOutputStream &stream );
private:
@@ -142,7 +230,7 @@ public:
virtual void Recreate();
virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
virtual void WriteSVG( wxTextOutputStream &stream );
private:
@@ -185,7 +273,7 @@ public:
void Recreate();
virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
virtual void WriteSVG( wxTextOutputStream &stream );
void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
@@ -264,7 +352,8 @@ private:
int m_bufferY;
bool m_needUpdate;
wxList m_updateRects;
wxList m_objects;
wxCanvasObjectGroup* m_root;
unsigned char m_green,m_red,m_blue;
bool m_frozen;
bool m_requestNewBuffer;
+86 -5
View File
@@ -76,6 +76,53 @@ void MywxCanvasImage::OnMouse(wxMouseEvent &event)
}
}
class MywxCanvasObjectGroupRef: public wxCanvasObjectGroupRef
{
public:
MywxCanvasObjectGroupRef(double x, double y, wxCanvasObjectGroup* group);
void OnMouse(wxMouseEvent &event);
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(MywxCanvasObjectGroupRef,wxCanvasObjectGroupRef)
EVT_MOUSE_EVENTS( MywxCanvasObjectGroupRef::OnMouse )
END_EVENT_TABLE()
MywxCanvasObjectGroupRef::MywxCanvasObjectGroupRef(double x, double y,wxCanvasObjectGroup* group)
:wxCanvasObjectGroupRef(x,y,group)
{
}
void MywxCanvasObjectGroupRef::OnMouse(wxMouseEvent &event)
{
static bool first=false;
static dx=0;
static dy=0;
//new position of object
int x = m_owner->GetDeviceX( event.GetX());
int y = m_owner->GetDeviceY( event.GetY());
if (event.m_leftDown)
{ if (!first)
{
first=true;
dx=x;
dy=y;
}
Move(m_x+x-dx,m_y+y-dy);
CaptureMouse();
}
else if (IsCapturedMouse())
{
ReleaseMouse();
first=false;
dx=0;dy=0;
}
}
class MyFrame;
class MyApp;
@@ -97,6 +144,10 @@ public:
wxCanvasObject *m_sm2;
wxCanvasObject *m_sm3;
wxCanvasObject *m_sm4;
MywxCanvasObjectGroupRef *m_ref;
MywxCanvasObjectGroupRef *m_ref2;
wxTimer *m_timer;
wxTextCtrl *m_log;
@@ -137,7 +188,7 @@ END_EVENT_TABLE()
MyFrame::MyFrame()
: wxFrame( (wxFrame *)NULL, -1, "wxCanvas sample",
wxPoint(20,20), wxSize(470,460) )
wxPoint(20,20), wxSize(470,860) )
{
wxMenu *file_menu = new wxMenu();
file_menu->Append( ID_ABOUT, "&About...");
@@ -158,12 +209,13 @@ MyFrame::MyFrame()
m_canvas->SetArea( 1400, 600 );
m_canvas->SetColour( 255, 255, 255 );
wxBitmap bitmap( smile_xpm );
wxImage image( bitmap );
m_sm1 = new wxCanvasImage( image, 0,70,16,16 );
m_canvas->Append( m_sm1 );
int i;
for (i = 10; i < 300; i+=10)
m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) );
@@ -189,9 +241,35 @@ MyFrame::MyFrame()
m_sm4 = new MywxCanvasImage( image, 0,270,64,32 );
m_canvas->Append( m_sm4 );
// m_canvas->Append( new wxCanvasLine( 10,-1500e6,50,300000e6, 0,255,0 ) );
// m_canvas->Append( new wxCanvasLine( 10,-150000,50,300000, 0,255,0 ) );
//make a group of wxCanvasObjects
wxCanvasObjectGroup* group1 = new wxCanvasObjectGroup();
group1->Prepend( new wxCanvasLine( 10,-35,50,190,100,255,0 ) );
group1->Prepend( new wxCanvasImage( image, 4,38,32,32 ) );
group1->Prepend( new wxCanvasRect(20,-20,50,170,0,20,240 ) );
group1->Prepend( new wxCanvasRect(10,20,104,52,0,240,240 ) );
//make another group of wxCanvasObjects
wxCanvasObjectGroup* group2 = new wxCanvasObjectGroup();
group2->Prepend( new wxCanvasImage( image, 60,38,52,32 ) );
group2->Prepend( new wxCanvasRect(10,20,104,52,10,40,10 ) );
//this a reference to group2 put into group1
wxCanvasObjectGroupRef* m_subref = new wxCanvasObjectGroupRef(60,50, group2);
group1->Prepend( m_subref );
//now make two refrences to group1 into root group of the canvas
m_ref = new MywxCanvasObjectGroupRef(40,200, group1);
m_canvas->Prepend( m_ref );
m_ref2 = new MywxCanvasObjectGroupRef(80,350, group1);
m_canvas->Prepend( m_ref2 );
m_log = new wxTextCtrl( this, -1, "", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
delete old_log;
@@ -220,11 +298,13 @@ void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
void MyFrame::OnTimer( wxTimerEvent &WXUNUSED(event) )
{
m_sm1->Move( m_sm1->GetX()+1, m_sm1->GetY() );
m_sm1->Move( m_sm1->GetX()+1, m_sm1 ->GetY() );
m_sm2->Move( m_sm2->GetX()+1, m_sm2->GetY() );
m_sm3->Move( m_sm3->GetX()+1, m_sm3->GetY() );
m_sm4->Move( m_sm4->GetX()+1, m_sm4->GetY() );
m_sm4->Move( m_sm4->GetX()+2, m_sm4->GetY() );
m_ref->Move( m_ref->GetPosX()+1, m_ref->GetPosY() );
m_ref2->Move( m_ref2->GetPosX()+2, m_ref2->GetPosY() );
wxWakeUpIdle();
}
@@ -242,6 +322,7 @@ void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
bool MyApp::OnInit()
{
m_fontpath = getenv("TRUETYPE");
m_fontpath = "c:\WINNT\Fonts\times.ttf";
if ( !m_fontpath )
{
wxLogError("Please set env var TRUETYPE to the path where times.ttf lives.");
File diff suppressed because it is too large Load Diff