2000-08-29 08:54:17 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: canvas.h
|
|
|
|
// Author: Robert Roebling
|
|
|
|
// Created: XX/XX/XX
|
|
|
|
// Copyright: 2000 (c) Robert Roebling
|
|
|
|
// Licence: wxWindows Licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef __WXCANVAS_H__
|
|
|
|
#define __WXCANVAS_H__
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface "canvas.cpp"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/image.h"
|
|
|
|
#include "wx/txtstrm.h"
|
|
|
|
|
|
|
|
class wxCanvas;
|
|
|
|
|
|
|
|
// WDR: class declarations
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// wxCanvasObject
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxCanvasObject: public wxEvtHandler
|
|
|
|
{
|
|
|
|
public:
|
2000-09-04 15:39:52 +00:00
|
|
|
wxCanvasObject();
|
|
|
|
|
|
|
|
// Area occupied by object. Used for clipping, intersection,
|
|
|
|
// mouse enter etc. Screen coordinates
|
|
|
|
void SetArea( int x, int y, int width, int height );
|
|
|
|
void SetArea( wxRect rect );
|
2000-08-29 08:54:17 +00:00
|
|
|
|
2000-09-03 16:38:53 +00:00
|
|
|
// These are for screen output only therefore use
|
|
|
|
// int as coordinates.
|
2000-09-02 18:01:32 +00:00
|
|
|
virtual bool IsHit( int x, int y, int margin = 0 );
|
2000-08-29 08:54:17 +00:00
|
|
|
virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
|
2000-09-03 16:38:53 +00:00
|
|
|
|
2000-09-04 15:39:52 +00:00
|
|
|
// use doubles later
|
|
|
|
virtual void Move( int x, int y );
|
|
|
|
|
2000-09-03 16:38:53 +00:00
|
|
|
// Once we have world coordinates in doubles, this will get
|
|
|
|
// called for every object if the world coordinate system
|
|
|
|
// changes (zooming).
|
2000-09-04 15:39:52 +00:00
|
|
|
virtual void Recreate();
|
2000-09-03 16:38:53 +00:00
|
|
|
|
|
|
|
// Later...
|
2000-08-29 08:54:17 +00:00
|
|
|
virtual void WriteSVG( wxTextOutputStream &stream );
|
|
|
|
|
|
|
|
wxCanvas *GetOwner() { return m_owner; }
|
|
|
|
void SetOwner( wxCanvas *owner ) { m_owner = owner; }
|
|
|
|
|
|
|
|
bool IsControl() { return m_isControl; }
|
|
|
|
bool IsVector() { return m_isVector; }
|
|
|
|
bool IsImage() { return m_isImage; }
|
|
|
|
inline int GetX() { return m_area.x; }
|
|
|
|
inline int GetY() { return m_area.y; }
|
|
|
|
inline int GetWidth() { return m_area.width; }
|
|
|
|
inline int GetHeight() { return m_area.height; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxCanvas *m_owner;
|
|
|
|
bool m_isControl;
|
|
|
|
bool m_isVector;
|
|
|
|
bool m_isImage;
|
|
|
|
wxRect m_area;
|
|
|
|
|
|
|
|
friend class wxCanvas;
|
|
|
|
};
|
|
|
|
|
2000-09-01 10:25:39 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// wxCanvasRect
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxCanvasRect: public wxCanvasObject
|
|
|
|
{
|
|
|
|
public:
|
2000-09-04 15:39:52 +00:00
|
|
|
wxCanvasRect( double x, double y, double w, double h,
|
|
|
|
unsigned char red, unsigned char green, unsigned char blue );
|
|
|
|
|
|
|
|
virtual void Recreate();
|
2000-09-01 10:25:39 +00:00
|
|
|
|
|
|
|
virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
|
|
|
|
virtual void WriteSVG( wxTextOutputStream &stream );
|
|
|
|
|
|
|
|
private:
|
2000-09-04 15:39:52 +00:00
|
|
|
double m_x;
|
|
|
|
double m_y;
|
|
|
|
double m_width;
|
|
|
|
double m_height;
|
|
|
|
|
2000-09-01 10:25:39 +00:00
|
|
|
unsigned char m_red;
|
|
|
|
unsigned char m_green;
|
|
|
|
unsigned char m_blue;
|
|
|
|
};
|
|
|
|
|
2000-09-02 18:01:32 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// wxCanvasLine
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxCanvasLine: public wxCanvasObject
|
|
|
|
{
|
|
|
|
public:
|
2000-09-04 15:39:52 +00:00
|
|
|
wxCanvasLine( double x1, double y1, double x1, double y1,
|
|
|
|
unsigned char red, unsigned char green, unsigned char blue );
|
|
|
|
|
|
|
|
virtual void Recreate();
|
2000-09-02 18:01:32 +00:00
|
|
|
|
|
|
|
virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
|
|
|
|
virtual void WriteSVG( wxTextOutputStream &stream );
|
|
|
|
|
|
|
|
private:
|
2000-09-04 15:39:52 +00:00
|
|
|
double m_x1;
|
|
|
|
double m_y1;
|
|
|
|
double m_x2;
|
|
|
|
double m_y2;
|
|
|
|
|
2000-09-02 18:01:32 +00:00
|
|
|
unsigned char m_red;
|
|
|
|
unsigned char m_green;
|
|
|
|
unsigned char m_blue;
|
|
|
|
};
|
|
|
|
|
2000-08-29 08:54:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// wxCanvasImage
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxCanvasImage: public wxCanvasObject
|
|
|
|
{
|
|
|
|
public:
|
2000-09-04 15:39:52 +00:00
|
|
|
wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
|
|
|
|
|
|
|
|
virtual void Recreate();
|
2000-08-29 08:54:17 +00:00
|
|
|
|
|
|
|
virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
|
|
|
|
virtual void WriteSVG( wxTextOutputStream &stream );
|
|
|
|
|
|
|
|
private:
|
2000-09-04 15:39:52 +00:00
|
|
|
double m_x;
|
|
|
|
double m_y;
|
|
|
|
double m_width;
|
|
|
|
double m_height;
|
|
|
|
|
2000-08-29 08:54:17 +00:00
|
|
|
wxImage m_image;
|
2000-09-04 15:39:52 +00:00
|
|
|
wxImage m_tmp;
|
2000-08-29 08:54:17 +00:00
|
|
|
};
|
|
|
|
|
2000-08-29 20:06:25 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// wxCanvasControl
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxCanvasControl: public wxCanvasObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxCanvasControl( wxWindow *control );
|
|
|
|
~wxCanvasControl();
|
|
|
|
|
2000-09-04 15:39:52 +00:00
|
|
|
virtual void Recreate();
|
|
|
|
|
2000-08-29 20:06:25 +00:00
|
|
|
virtual void Move( int x, int y );
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxWindow *m_control;
|
|
|
|
};
|
|
|
|
|
2000-08-30 13:05:24 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// wxCanvasText
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxCanvasText: public wxCanvasObject
|
|
|
|
{
|
|
|
|
public:
|
2000-09-04 15:39:52 +00:00
|
|
|
wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
|
2000-08-30 13:05:24 +00:00
|
|
|
~wxCanvasText();
|
|
|
|
|
2000-09-04 15:39:52 +00:00
|
|
|
void Recreate();
|
|
|
|
|
2000-08-30 13:05:24 +00:00
|
|
|
virtual void Render( 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 );
|
|
|
|
void SetFlag( int flag );
|
2000-09-02 18:01:32 +00:00
|
|
|
int GetFlag() { return m_flag; }
|
2000-08-30 13:05:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxString m_text;
|
2000-09-04 15:39:52 +00:00
|
|
|
double m_x;
|
|
|
|
double m_y;
|
2000-08-30 13:05:24 +00:00
|
|
|
unsigned char *m_alpha;
|
|
|
|
void *m_faceData;
|
|
|
|
int m_flag;
|
|
|
|
int m_red;
|
|
|
|
int m_green;
|
|
|
|
int m_blue;
|
2000-08-30 16:20:37 +00:00
|
|
|
wxString m_fontFileName;
|
|
|
|
int m_size;
|
2000-08-30 13:05:24 +00:00
|
|
|
};
|
|
|
|
|
2000-08-29 08:54:17 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// wxCanvas
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxCanvas: public wxScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructors and destructors
|
|
|
|
wxCanvas( wxWindow *parent, wxWindowID id = -1,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxScrolledWindowStyle );
|
|
|
|
virtual ~wxCanvas();
|
|
|
|
|
|
|
|
virtual void SetArea( int width, int height );
|
2000-08-30 16:20:37 +00:00
|
|
|
virtual void SetColour( unsigned char red, unsigned char green, unsigned char blue );
|
2000-08-29 08:54:17 +00:00
|
|
|
virtual void Update( int x, int y, int width, int height );
|
|
|
|
virtual void UpdateNow();
|
|
|
|
|
2000-09-02 18:01:32 +00:00
|
|
|
virtual void Freeze();
|
|
|
|
virtual void Thaw();
|
|
|
|
|
2000-08-29 08:54:17 +00:00
|
|
|
virtual void Prepend( wxCanvasObject* obj );
|
|
|
|
virtual void Append( wxCanvasObject* obj );
|
|
|
|
virtual void Insert( size_t before, wxCanvasObject* obj );
|
|
|
|
virtual void Remove( wxCanvasObject* obj );
|
|
|
|
|
2000-09-04 15:39:52 +00:00
|
|
|
// override these to change your coordiate system ...
|
|
|
|
virtual int GetDeviceX( double x );
|
|
|
|
virtual int GetDeviceY( double y );
|
|
|
|
virtual int GetDeviceWidth( double width );
|
|
|
|
virtual int GetDeviceHeight( double height );
|
|
|
|
|
|
|
|
// ... and call this to tell all objets to recreate then
|
|
|
|
virtual void Recreate();
|
|
|
|
|
|
|
|
void CaptureMouse( wxCanvasObject *obj );
|
|
|
|
void ReleaseMouse();
|
|
|
|
|
2000-08-29 08:54:17 +00:00
|
|
|
wxImage *GetBuffer() { return &m_buffer; }
|
|
|
|
bool NeedUpdate() { return m_needUpdate; }
|
2000-09-03 16:38:53 +00:00
|
|
|
bool IsFrozen() { return m_frozen; }
|
2000-08-29 08:54:17 +00:00
|
|
|
|
2000-08-29 20:06:25 +00:00
|
|
|
void BlitBuffer( wxDC &dc );
|
|
|
|
|
2000-08-29 08:54:17 +00:00
|
|
|
private:
|
2000-09-02 18:01:32 +00:00
|
|
|
wxImage m_buffer;
|
|
|
|
bool m_needUpdate;
|
|
|
|
wxList m_updateRects;
|
|
|
|
wxList m_objects;
|
|
|
|
unsigned char m_green,m_red,m_blue;
|
|
|
|
bool m_frozen;
|
|
|
|
wxCanvasObject *m_lastMouse;
|
2000-09-04 15:39:52 +00:00
|
|
|
wxCanvasObject *m_captureMouse;
|
2000-09-02 18:01:32 +00:00
|
|
|
|
2000-08-29 08:54:17 +00:00
|
|
|
friend class wxCanvasObject;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void OnChar( wxKeyEvent &event );
|
|
|
|
void OnPaint( wxPaintEvent &event );
|
|
|
|
void OnMouse( wxMouseEvent &event );
|
|
|
|
void OnSize( wxSizeEvent &event );
|
|
|
|
void OnIdle( wxIdleEvent &event );
|
|
|
|
void OnSetFocus( wxFocusEvent &event );
|
|
|
|
void OnKillFocus( wxFocusEvent &event );
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_CLASS(wxCanvas)
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// WXCANVAS
|
|
|
|
|