X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/61b64bd92a02df762e59c368536b52d76516ce8c..fb20fa43a07ce52feb43a4b26514fc7a6a11a6f5:/contrib/include/wx/canvas/canvas.h diff --git a/contrib/include/wx/canvas/canvas.h b/contrib/include/wx/canvas/canvas.h index 325d5dcfed..f1255760b3 100644 --- a/contrib/include/wx/canvas/canvas.h +++ b/contrib/include/wx/canvas/canvas.h @@ -19,10 +19,16 @@ #include "wx/image.h" #include "wx/txtstrm.h" +#include "wx/geometry.h" -class wxCanvas; -// WDR: class declarations +//---------------------------------------------------------------------------- +// decls +//---------------------------------------------------------------------------- + +#define IMAGE_CANVAS 0 + +class wxCanvas; //---------------------------------------------------------------------------- // wxCanvasObject @@ -41,7 +47,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 +61,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 +80,170 @@ 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(); + virtual ~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(double x, double y); + + inline double GetXMin() { return m_minx; } + inline double GetYMin() { return m_miny; } + inline double GetXMax() { return m_maxx; } + inline double 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 double GetPosX() { return m_x; } + inline double GetPosY() { return m_y; } + + void ExtendArea(double x, double 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; + +}; + +//---------------------------------------------------------------------------- +// wxCanvasPolygon +//---------------------------------------------------------------------------- + +class wxCanvasPolygon: public wxCanvasObject +{ +public: + wxCanvasPolygon( int n, wxPoint2DDouble points[] ); + ~wxCanvasPolygon(); + void SetBrush(wxBrush& brush) { m_brush = brush; }; + void SetPen(wxPen& pen) { m_pen = pen; }; + + virtual void Recreate(); + + 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: + void ExtendArea(double x, double y); + + wxBrush m_brush; + wxPen m_pen; + + int m_n; + wxPoint2DDouble* m_points; + + //bounding box + double m_minx; + double m_miny; + double m_maxx; + double m_maxy; + bool m_validbounds; + +}; + +//---------------------------------------------------------------------------- +// wxCanvasPolyline +//---------------------------------------------------------------------------- + +class wxCanvasPolyline: public wxCanvasObject +{ +public: + wxCanvasPolyline(int n, wxPoint2DDouble points[]); + ~wxCanvasPolyline(); + void SetPen(wxPen& pen) { m_pen = pen; }; + + virtual void Recreate(); + + 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: + void ExtendArea(double x, double y); + + wxPen m_pen; + + int m_n; + wxPoint2DDouble* m_points; + + //bounding box + double m_minx; + double m_miny; + double m_maxx; + double m_maxy; + bool m_validbounds; + +}; + + + //---------------------------------------------------------------------------- // wxCanvasRect //---------------------------------------------------------------------------- @@ -86,23 +251,23 @@ protected: class wxCanvasRect: public wxCanvasObject { public: - wxCanvasRect( double x, double y, double w, double h, - unsigned char red, unsigned char green, unsigned char blue ); + wxCanvasRect( double x, double y, double w, double h ); + void SetBrush(wxBrush& brush) { m_brush = brush; }; + void SetPen(wxPen& pen) { m_pen = pen; }; 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: + wxPen m_pen; + wxBrush m_brush; + double m_x; double m_y; double m_width; double m_height; - - unsigned char m_red; - unsigned char m_green; - unsigned char m_blue; }; //---------------------------------------------------------------------------- @@ -112,23 +277,21 @@ private: class wxCanvasLine: public wxCanvasObject { public: - wxCanvasLine( double x1, double y1, double x2, double y2, - unsigned char red, unsigned char green, unsigned char blue ); + wxCanvasLine( double x1, double y1, double x2, double y2 ); + void SetPen(wxPen& pen) { m_pen = pen; }; 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: + wxPen m_pen; + double m_x1; double m_y1; double m_x2; double m_y2; - - unsigned char m_red; - unsigned char m_green; - unsigned char m_blue; }; //---------------------------------------------------------------------------- @@ -142,7 +305,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: @@ -152,7 +315,11 @@ private: double m_height; wxImage m_image; +#if IMAGE_CANVAS wxImage m_tmp; +#else + wxBitmap m_tmp; +#endif }; //---------------------------------------------------------------------------- @@ -185,7 +352,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 ); @@ -242,7 +409,12 @@ public: // ... and call this to tell all objets to recreate then virtual void Recreate(); +#if IMAGE_CANVAS inline wxImage *GetBuffer() { return &m_buffer; } +#else + inline wxBitmap *GetBuffer() { return &m_buffer; } + inline wxMemoryDC *GetDC() { return m_renderDC; } +#endif inline int GetBufferX() { return m_bufferX; } inline int GetBufferY() { return m_bufferY; } inline int GetBufferWidth() { return m_buffer.GetWidth(); } @@ -259,17 +431,24 @@ public: const wxRect* rect = (wxRect *) NULL ); private: +#if IMAGE_CANVAS wxImage m_buffer; +#else + wxBitmap m_buffer; + wxMemoryDC *m_renderDC; +#endif int m_bufferX; 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; wxCanvasObject *m_lastMouse; wxCanvasObject *m_captureMouse; + + int m_oldDeviceX,m_oldDeviceY; friend class wxCanvasObject;