~kicad-product-committers/kicad/kicad-gal

« back to all changes in this revision

Viewing changes to gal/cairo/cairo_gal.cpp

  • Committer: Dick Hollenbeck
  • Date: 2011-11-01 08:01:43 UTC
  • Revision ID: dick@softplc.com-20111101080143-w8xn75wd1tuhczhi
unify CAIRO_GAL and OPENGL_GAL constructors, generalize the event listeners

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
using namespace std;
30
30
 
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 )
34
34
{
35
35
    // default values
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 );
38
38
 
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
41
40
 
42
 
    m_parentFrame = aParent;
 
41
    m_parent = aParent;
 
42
    m_mouse_listener = aMouseListener;
 
43
    m_paint_listener = aPaintListener;
43
44
 
44
45
    m_isGrouping = false;
45
46
 
57
58
    this->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
58
59
 
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;
63
64
 
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;
67
68
 
72
73
    initCursor( 20 );
73
74
 
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;
77
78
 
78
 
    m_screenSizeY = aScreenSize.y;
 
79
    m_screenSizeY = m_screenSize.y;
79
80
 
80
81
    // Allocate memory
81
 
    m_bitmapBuffer = (unsigned char*) malloc( m_stride * aScreenSize.y * 4 );
 
82
    m_bitmapBuffer = (unsigned char*) malloc( m_stride * m_screenSize.y * 4 );
82
83
 
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 );
85
86
#else
86
 
    m_wxBitmap = new wxBitmap( m_stride, aScreenSize.y, 32 );
 
87
    m_wxBitmap = new wxBitmap( m_stride, m_screenSize.y, 32 );
87
88
#endif
88
89
 
89
90
}
90
91
 
 
92
 
91
93
CAIRO_GAL::~CAIRO_GAL()
92
94
{
93
95
    // TODO Deleting of list contents like groups and paths
94
96
 
95
97
    free( m_bitmapBuffer );
96
 
    delete ( m_wxBitmap );
 
98
    delete m_wxBitmap;
97
99
}
98
100
 
 
101
 
99
102
void CAIRO_GAL::onPaint( wxPaintEvent& aEvent )
100
103
{
101
 
    wxPaintDC dc( this );
 
104
    // wxPaintDC dc( this );
102
105
 
103
 
    // Post the redraw event to the parent
104
 
    wxCommandEvent redrawEvent( EVT_GAL_REDRAW );
105
 
    wxPostEvent( m_parent->GetEventHandler(), redrawEvent );
 
106
    PostPaint();
106
107
}
107
108
 
 
109
 
108
110
void CAIRO_GAL::onSize( wxSizeEvent& aEvent )
109
111
{
110
112
    wxSize newSize = aEvent.GetSize();
127
129
    m_wxBitmap = new wxBitmap( m_stride, newSize.y, 32 );
128
130
#endif
129
131
 
130
 
    m_screenSize.x = (double) newSize.x;
131
 
    m_screenSize.y = (double) newSize.y;
 
132
    m_screenSize = newSize;
132
133
 
133
 
    // Post the redraw event to the parent
134
 
    wxCommandEvent redrawEvent( EVT_GAL_REDRAW );
135
 
    wxPostEvent( m_parent->GetEventHandler(), redrawEvent );
 
134
    PostPaint();
136
135
}
137
136
 
 
137
 
138
138
void CAIRO_GAL::skipMouseEvent( wxMouseEvent& aEvent )
139
139
{
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 );
142
143
}
143
144
 
 
145
 
144
146
void CAIRO_GAL::BeginDrawing() throw (int)
145
147
{
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();
148
150
 
149
151
    if (m_clientRectangle.width == 0 || m_clientRectangle.height == 0)
150
152
        throw EXCEPTION_ZERO_CLIENT_RECTANGLE;