29
29
using namespace std;
31
// The constructor needs a parent frame as argument
32
CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxSize aScreenSize ) :
33
wxWindow( aParent, wxID_ANY )
31
CAIRO_GAL::CAIRO_GAL( wxWindow *aParent, wxEvtHandler* aMouseListener,
32
wxEvtHandler* aPaintListener, const wxString& aName ) :
33
wxWindow( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName )
36
m_fillColor = COLOR4D( 0, 0, 0, 1 );
36
m_fillColor = COLOR4D( 0, 0, 0, 1 );
37
37
m_strokeColor = COLOR4D( 1, 1, 1, 1 );
39
m_screenSize.x = (double) aScreenSize.x;
40
m_screenSize.y = (double) aScreenSize.y;
39
m_screenSize = VECTOR2D(20, 20); // window will be soon resized
42
m_parentFrame = aParent;
42
m_mouse_listener = aMouseListener;
43
m_paint_listener = aPaintListener;
44
45
m_isGrouping = false;
57
58
this->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
59
60
// Initialize line attributes map
60
lineCapMap[LINE_CAP_BUTT] = CAIRO_LINE_CAP_BUTT;
61
lineCapMap[LINE_CAP_ROUND] = CAIRO_LINE_CAP_ROUND;
61
lineCapMap[LINE_CAP_BUTT] = CAIRO_LINE_CAP_BUTT;
62
lineCapMap[LINE_CAP_ROUND] = CAIRO_LINE_CAP_ROUND;
62
63
lineCapMap[LINE_CAP_SQUARED] = CAIRO_LINE_CAP_SQUARE;
64
lineJoinMap[LINE_JOIN_NONE] = CAIRO_LINE_JOIN_ROUND;
65
lineJoinMap[LINE_JOIN_NONE] = CAIRO_LINE_JOIN_ROUND;
65
66
lineJoinMap[LINE_JOIN_BEVEL] = CAIRO_LINE_JOIN_BEVEL;
66
67
lineJoinMap[LINE_JOIN_ROUND] = CAIRO_LINE_JOIN_ROUND;
74
75
// Create buffer, use the system independent CAIRO image back end
75
// m_stride = cairo_format_stride_for_width( CAIRO_FORMAT_RGB24, aScreenSize.x );
76
m_stride = aScreenSize.x * 4;
76
// m_stride = cairo_format_stride_for_width( CAIRO_FORMAT_RGB24, m_screenSize.x );
77
m_stride = m_screenSize.x * 4;
78
m_screenSizeY = aScreenSize.y;
79
m_screenSizeY = m_screenSize.y;
81
m_bitmapBuffer = (unsigned char*) malloc( m_stride * aScreenSize.y * 4 );
82
m_bitmapBuffer = (unsigned char*) malloc( m_stride * m_screenSize.y * 4 );
83
84
#if wxCHECK_VERSION( 2, 9, 0 )
84
m_wxBitmap = new wxBitmap( m_stride, aScreenSize.y, wxBITMAP_SCREEN_DEPTH );
85
m_wxBitmap = new wxBitmap( m_stride, m_screenSize.y, wxBITMAP_SCREEN_DEPTH );
86
m_wxBitmap = new wxBitmap( m_stride, aScreenSize.y, 32 );
87
m_wxBitmap = new wxBitmap( m_stride, m_screenSize.y, 32 );
91
93
CAIRO_GAL::~CAIRO_GAL()
93
95
// TODO Deleting of list contents like groups and paths
95
97
free( m_bitmapBuffer );
96
delete ( m_wxBitmap );
99
102
void CAIRO_GAL::onPaint( wxPaintEvent& aEvent )
101
wxPaintDC dc( this );
104
// wxPaintDC dc( this );
103
// Post the redraw event to the parent
104
wxCommandEvent redrawEvent( EVT_GAL_REDRAW );
105
wxPostEvent( m_parent->GetEventHandler(), redrawEvent );
108
110
void CAIRO_GAL::onSize( wxSizeEvent& aEvent )
110
112
wxSize newSize = aEvent.GetSize();
127
129
m_wxBitmap = new wxBitmap( m_stride, newSize.y, 32 );
130
m_screenSize.x = (double) newSize.x;
131
m_screenSize.y = (double) newSize.y;
132
m_screenSize = newSize;
133
// Post the redraw event to the parent
134
wxCommandEvent redrawEvent( EVT_GAL_REDRAW );
135
wxPostEvent( m_parent->GetEventHandler(), redrawEvent );
138
138
void CAIRO_GAL::skipMouseEvent( wxMouseEvent& aEvent )
140
// Post the mouse wheel event to the parent
141
wxPostEvent( m_parent->GetEventHandler(), aEvent );
140
// Post the mouse event to the event listener registered in constructor, if any
141
if( m_mouse_listener )
142
wxPostEvent( m_mouse_listener, aEvent );
144
146
void CAIRO_GAL::BeginDrawing() throw (int)
146
148
// The size of the client area needs to be greater than zero
147
m_clientRectangle = m_parentFrame->GetClientRect();
149
m_clientRectangle = m_parent->GetClientRect();
149
151
if (m_clientRectangle.width == 0 || m_clientRectangle.height == 0)
150
152
throw EXCEPTION_ZERO_CLIENT_RECTANGLE;