Split wxCanvas into two (wxVectorCanvas).
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8833 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -28,8 +28,6 @@
|
|||||||
// decls
|
// decls
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
#define IMAGE_CANVAS 0
|
|
||||||
|
|
||||||
class wxCanvas;
|
class wxCanvas;
|
||||||
class wxCanvasAdmin;
|
class wxCanvasAdmin;
|
||||||
|
|
||||||
@@ -584,7 +582,7 @@ private:
|
|||||||
// The area of the drawing in world coordinates that is visible on the canvas
|
// The area of the drawing in world coordinates that is visible on the canvas
|
||||||
// can be set. Parts of this area can be zoomed into resulting in scroll bars
|
// can be set. Parts of this area can be zoomed into resulting in scroll bars
|
||||||
// to be displayed.
|
// to be displayed.
|
||||||
class wxCanvas: public wxWindow
|
class wxCanvas: public wxScrolledWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructors and destructors
|
// constructors and destructors
|
||||||
@@ -594,9 +592,6 @@ public:
|
|||||||
long style = wxScrolledWindowStyle );
|
long style = wxScrolledWindowStyle );
|
||||||
virtual ~wxCanvas();
|
virtual ~wxCanvas();
|
||||||
|
|
||||||
//intercept scroll events
|
|
||||||
virtual void OnScroll(wxScrollWinEvent& event);
|
|
||||||
|
|
||||||
//background colour for the canvas
|
//background colour for the canvas
|
||||||
virtual void SetColour( const wxColour& background );
|
virtual void SetColour( const wxColour& background );
|
||||||
|
|
||||||
@@ -613,16 +608,12 @@ public:
|
|||||||
//allow canvas activety
|
//allow canvas activety
|
||||||
virtual void Thaw();
|
virtual void Thaw();
|
||||||
|
|
||||||
#if IMAGE_CANVAS
|
|
||||||
inline wxImage *GetBuffer() { return &m_buffer; }
|
|
||||||
#else
|
|
||||||
//get the buffer that is used for rendering in general
|
//get the buffer that is used for rendering in general
|
||||||
inline wxBitmap *GetBuffer() { return &m_buffer; }
|
inline wxBitmap *GetBuffer() { return &m_buffer; }
|
||||||
//get the DC that is used for rendering
|
//get the DC that is used for rendering
|
||||||
inline wxDC *GetDC() { return m_renderDC; }
|
inline wxDC *GetDC() { return m_renderDC; }
|
||||||
//set the DC that is used for rendering
|
//set the DC that is used for rendering
|
||||||
inline void SetDC(wxDC* dc) { m_renderDC=dc; }
|
inline void SetDC(wxDC* dc) { m_renderDC=dc; }
|
||||||
#endif
|
|
||||||
|
|
||||||
inline int GetBufferWidth() { return m_buffer.GetWidth(); }
|
inline int GetBufferWidth() { return m_buffer.GetWidth(); }
|
||||||
inline int GetBufferHeight() { return m_buffer.GetHeight(); }
|
inline int GetBufferHeight() { return m_buffer.GetHeight(); }
|
||||||
@@ -645,15 +636,85 @@ public:
|
|||||||
//get root group that is displayed on the canvas
|
//get root group that is displayed on the canvas
|
||||||
wxCanvasObjectGroup* GetRoot(){return m_root;}
|
wxCanvasObjectGroup* GetRoot(){return m_root;}
|
||||||
|
|
||||||
|
//scroll the window in device coordinates
|
||||||
|
virtual void ScrollWindow( int dx, int dy,
|
||||||
|
const wxRect* rect = (wxRect *) NULL );
|
||||||
|
|
||||||
|
//get y axis orientation
|
||||||
|
virtual bool GetYaxis() { return FALSE; }
|
||||||
|
|
||||||
|
//get the visible part in world coordinates
|
||||||
|
virtual double GetMinX() const;
|
||||||
|
virtual double GetMinY() const;
|
||||||
|
virtual double GetMaxX() const;
|
||||||
|
virtual double GetMaxY() const;
|
||||||
|
|
||||||
|
//convert from window to virtual coordinates
|
||||||
|
virtual double DeviceToLogicalX(int x) const;
|
||||||
|
virtual double DeviceToLogicalY(int y) const;
|
||||||
|
virtual double DeviceToLogicalXRel(int x) const;
|
||||||
|
virtual double DeviceToLogicalYRel(int y) const;
|
||||||
|
virtual int LogicalToDeviceX(double x) const;
|
||||||
|
virtual int LogicalToDeviceY(double y) const;
|
||||||
|
virtual int LogicalToDeviceXRel(double x) const;
|
||||||
|
virtual int LogicalToDeviceYRel(double y) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
wxBitmap m_buffer;
|
||||||
|
|
||||||
|
//always available and m_buffer selected
|
||||||
|
wxDC* m_renderDC;
|
||||||
|
|
||||||
|
bool m_needUpdate;
|
||||||
|
wxList m_updateRects;
|
||||||
|
wxCanvasObjectGroup* m_root;
|
||||||
|
|
||||||
|
wxColour m_background;
|
||||||
|
bool m_frozen;
|
||||||
|
wxCanvasObject *m_lastMouse;
|
||||||
|
wxCanvasObject *m_captureMouse;
|
||||||
|
|
||||||
|
int m_oldDeviceX,m_oldDeviceY;
|
||||||
|
|
||||||
|
wxCanvasAdmin* m_admin;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_bufferX,m_bufferY;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void OnMouse( wxMouseEvent &event );
|
||||||
|
void OnPaint( wxPaintEvent &event );
|
||||||
|
void OnSize( wxSizeEvent &event );
|
||||||
|
void OnIdle( wxIdleEvent &event );
|
||||||
|
void OnSetFocus( wxFocusEvent &event );
|
||||||
|
void OnKillFocus( wxFocusEvent &event );
|
||||||
|
void OnEraseBackground( wxEraseEvent &event );
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_CLASS(wxCanvas)
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class wxVectorCanvas: public wxCanvas
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructors and destructors
|
||||||
|
wxVectorCanvas( wxCanvasAdmin* admin ,wxWindow *parent, wxWindowID id = -1,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxScrolledWindowStyle );
|
||||||
|
|
||||||
//scroll the window in device coordinates
|
//scroll the window in device coordinates
|
||||||
virtual void ScrollWindow( int dx, int dy,
|
virtual void ScrollWindow( int dx, int dy,
|
||||||
const wxRect* rect = (wxRect *) NULL );
|
const wxRect* rect = (wxRect *) NULL );
|
||||||
|
|
||||||
//set if the Yaxis goes up or down
|
//set if the Yaxis goes up or down
|
||||||
void SetYaxis(bool up){m_yaxis=up;}
|
void SetYaxis(bool up) { m_yaxis=up; }
|
||||||
|
|
||||||
//get currently used Yaxis setting
|
//get currently used Yaxis setting
|
||||||
bool GetYaxis(){return m_yaxis;}
|
virtual bool GetYaxis() { return m_yaxis; }
|
||||||
|
|
||||||
//to set the total area in world coordinates that can be scrolled.
|
//to set the total area in world coordinates that can be scrolled.
|
||||||
// when totaly zoomed out (SetMappingScroll same size as given here),
|
// when totaly zoomed out (SetMappingScroll same size as given here),
|
||||||
@@ -678,34 +739,23 @@ public:
|
|||||||
wxTransformMatrix GetMappingMatrix();
|
wxTransformMatrix GetMappingMatrix();
|
||||||
|
|
||||||
//get minimum X of the visible part in world coordinates
|
//get minimum X of the visible part in world coordinates
|
||||||
inline double GetMinX(){return m_virt_minX;};
|
virtual double GetMinX() const;
|
||||||
//get minimum Y of the visible part in world coordinates
|
virtual double GetMinY() const;
|
||||||
inline double GetMinY(){return m_virt_minY;};
|
virtual double GetMaxX() const;
|
||||||
//get maximum X of the visible part in world coordinates
|
virtual double GetMaxY() const;
|
||||||
inline double GetMaxX(){return m_virt_maxX;};
|
|
||||||
//get maximum Y of the visible part in world coordinates
|
//convert from window to virtual coordinates and back
|
||||||
inline double GetMaxY(){return m_virt_maxY;};
|
virtual double DeviceToLogicalX(int x) const;
|
||||||
|
virtual double DeviceToLogicalY(int y) const;
|
||||||
|
virtual double DeviceToLogicalXRel(int x) const;
|
||||||
//convert from window to virtual coordinates
|
virtual double DeviceToLogicalYRel(int y) const;
|
||||||
double DeviceToLogicalX(int x) const;
|
virtual int LogicalToDeviceX(double x) const;
|
||||||
//convert from window to virtual coordinates
|
virtual int LogicalToDeviceY(double y) const;
|
||||||
double DeviceToLogicalY(int y) const;
|
virtual int LogicalToDeviceXRel(double x) const;
|
||||||
//convert from window to virtual coordinates relatif
|
virtual int LogicalToDeviceYRel(double y) const;
|
||||||
double DeviceToLogicalXRel(int x) const;
|
|
||||||
//convert from window to virtual coordinates relatif
|
|
||||||
double DeviceToLogicalYRel(int y) const;
|
|
||||||
//convert from virtual to window coordinates
|
|
||||||
int LogicalToDeviceX(double x) const;
|
|
||||||
//convert from virtual to window coordinates
|
|
||||||
int LogicalToDeviceY(double y) const;
|
|
||||||
//convert from virtual to window coordinates relatif
|
|
||||||
int LogicalToDeviceXRel(double x) const;
|
|
||||||
//convert from virtual to window coordinates relatif
|
|
||||||
int LogicalToDeviceYRel(double y) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// up or down
|
||||||
bool m_yaxis;
|
bool m_yaxis;
|
||||||
|
|
||||||
// holds the matrix for mapping from virtual to screen coordinates
|
// holds the matrix for mapping from virtual to screen coordinates
|
||||||
@@ -727,46 +777,17 @@ protected:
|
|||||||
bool m_scrolled;
|
bool m_scrolled;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if IMAGE_CANVAS
|
void OnScroll(wxScrollWinEvent& event);
|
||||||
wxImage m_buffer;
|
|
||||||
#else
|
|
||||||
wxBitmap m_buffer;
|
|
||||||
|
|
||||||
//always available and m_buffer selected
|
|
||||||
wxDC* m_renderDC;
|
|
||||||
#endif
|
|
||||||
bool m_needUpdate;
|
|
||||||
wxList m_updateRects;
|
|
||||||
wxCanvasObjectGroup* m_root;
|
|
||||||
|
|
||||||
wxColour m_background;
|
|
||||||
bool m_frozen;
|
|
||||||
wxCanvasObject *m_lastMouse;
|
|
||||||
wxCanvasObject *m_captureMouse;
|
|
||||||
|
|
||||||
int m_oldDeviceX,m_oldDeviceY;
|
|
||||||
|
|
||||||
wxCanvasAdmin* m_admin;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
void OnMouse( wxMouseEvent &event );
|
|
||||||
|
|
||||||
private:
|
|
||||||
void OnChar( wxKeyEvent &event );
|
void OnChar( wxKeyEvent &event );
|
||||||
void OnPaint( wxPaintEvent &event );
|
|
||||||
void OnSize( wxSizeEvent &event );
|
void OnSize( wxSizeEvent &event );
|
||||||
void OnIdle( wxIdleEvent &event );
|
|
||||||
void OnSetFocus( wxFocusEvent &event );
|
|
||||||
void OnKillFocus( wxFocusEvent &event );
|
|
||||||
void OnEraseBackground( wxEraseEvent &event );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_CLASS(wxCanvas)
|
DECLARE_CLASS(wxVectorCanvas)
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//:defenition
|
//:defenition
|
||||||
//Contains a list of wxCanvas Objects that will be maintained through this class.
|
//Contains a list of wxCanvas Objects that will be maintained through this class.
|
||||||
//Each wxCanvasObject can be displayed on several wxCanvas Objects at the same time.
|
//Each wxCanvasObject can be displayed on several wxCanvas Objects at the same time.
|
||||||
|
@@ -55,8 +55,7 @@ MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
|
|||||||
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->SetScrollbars( 10, 10, 40, 40 );
|
||||||
canvas->SetMappingScroll( 0, 0, 400, 600, FALSE );
|
|
||||||
|
|
||||||
// The wxCanvasAdmin need to know about all Admin wxCanvas objects.
|
// The wxCanvasAdmin need to know about all Admin wxCanvas objects.
|
||||||
m_admin->Append( canvas );
|
m_admin->Append( canvas );
|
||||||
@@ -76,6 +75,11 @@ MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
|
|||||||
m_smile1 = new wxCanvasImage( image, 0,70,32,32 );
|
m_smile1 = new wxCanvasImage( image, 0,70,32,32 );
|
||||||
root->Append( m_smile1 );
|
root->Append( m_smile1 );
|
||||||
|
|
||||||
|
wxCanvasRect *rect = new wxCanvasRect( 20,20,100,100 );
|
||||||
|
rect->SetBrush( *wxRED_BRUSH );
|
||||||
|
root->Append( rect );
|
||||||
|
|
||||||
|
/*
|
||||||
int i;
|
int i;
|
||||||
for (i = 10; i < 300; i+=10)
|
for (i = 10; i < 300; i+=10)
|
||||||
{
|
{
|
||||||
@@ -83,16 +87,19 @@ MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
|
|||||||
r->SetBrush( *wxRED_BRUSH );
|
r->SetBrush( *wxRED_BRUSH );
|
||||||
root->Append( r );
|
root->Append( r );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
m_smile2 = new wxCanvasImage( image, 0,110,32,32 );
|
m_smile2 = new wxCanvasImage( image, 0,110,32,32 );
|
||||||
root->Append( m_smile2 );
|
root->Append( m_smile2 );
|
||||||
|
|
||||||
|
/*
|
||||||
for (i = 15; i < 300; i+=10)
|
for (i = 15; i < 300; i+=10)
|
||||||
{
|
{
|
||||||
wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
|
wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
|
||||||
r->SetBrush( *wxRED_BRUSH );
|
r->SetBrush( *wxRED_BRUSH );
|
||||||
root->Append( r );
|
root->Append( r );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// This will call all object and children recursivly so
|
// This will call all object and children recursivly so
|
||||||
// all know what their wxCanvasAdmin is. Call at the end.
|
// all know what their wxCanvasAdmin is. Call at the end.
|
||||||
|
@@ -647,13 +647,13 @@ void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
|
|||||||
|
|
||||||
// the event tables connect the wxWindows events with the functions (event
|
// the event tables connect the wxWindows events with the functions (event
|
||||||
// handlers) which process them.
|
// handlers) which process them.
|
||||||
BEGIN_EVENT_TABLE(MyCanvas,wxCanvas)
|
BEGIN_EVENT_TABLE(MyCanvas,wxVectorCanvas)
|
||||||
EVT_MOUSE_EVENTS (MyCanvas::OnMouseEvent)
|
EVT_MOUSE_EVENTS (MyCanvas::OnMouseEvent)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
MyCanvas::MyCanvas(wxCanvasAdmin* admin, MySplitterWindow *parent, wxWindowID id,
|
MyCanvas::MyCanvas(wxCanvasAdmin* admin, MySplitterWindow *parent, wxWindowID id,
|
||||||
const wxPoint &position, const wxSize& size, long style ) :
|
const wxPoint &position, const wxSize& size, long style ) :
|
||||||
wxCanvas( admin, parent, id, position, size, style )
|
wxVectorCanvas( admin, parent, id, position, size, style )
|
||||||
{
|
{
|
||||||
m_parent=parent;
|
m_parent=parent;
|
||||||
}
|
}
|
||||||
@@ -708,7 +708,7 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxCanvas::OnMouse(event);
|
wxVectorCanvas::OnMouse(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -64,7 +64,7 @@ class MySplitterWindow : public wxSplitterWindow
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MySplitterWindow(wxFrame *parent, wxWindowID id)
|
MySplitterWindow(wxFrame *parent, wxWindowID id)
|
||||||
: wxSplitterWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxSP_3D | wxSP_LIVE_UPDATE)
|
: wxSplitterWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxSP_3D )
|
||||||
{
|
{
|
||||||
m_frame = parent;
|
m_frame = parent;
|
||||||
}
|
}
|
||||||
@@ -163,7 +163,7 @@ enum
|
|||||||
#define CANVAS1 102
|
#define CANVAS1 102
|
||||||
#define CANVAS2 103
|
#define CANVAS2 103
|
||||||
|
|
||||||
class MyCanvas: public wxCanvas
|
class MyCanvas: public wxVectorCanvas
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyCanvas( wxCanvasAdmin* admin, MySplitterWindow *parent, wxWindowID id = -1,
|
MyCanvas( wxCanvasAdmin* admin, MySplitterWindow *parent, wxWindowID id = -1,
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user