Commit a43dd351 authored by Maciej Suminski's avatar Maciej Suminski

Assured that there are no excessive initializations

parent 1a4c6781
...@@ -47,6 +47,8 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, ...@@ -47,6 +47,8 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
paintListener = aPaintListener; paintListener = aPaintListener;
isGrouping = false; isGrouping = false;
isInitialized = false;
isDeleteSavedPixels = false;
zoomFactor = 1.0; zoomFactor = 1.0;
SetSize( aParent->GetSize() ); SetSize( aParent->GetSize() );
...@@ -76,10 +78,6 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, ...@@ -76,10 +78,6 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
lineJoinMap[LINE_JOIN_ROUND] = CAIRO_LINE_JOIN_ROUND; lineJoinMap[LINE_JOIN_ROUND] = CAIRO_LINE_JOIN_ROUND;
lineJoinMap[LINE_JOIN_MITER] = CAIRO_LINE_JOIN_MITER; lineJoinMap[LINE_JOIN_MITER] = CAIRO_LINE_JOIN_MITER;
isDeleteSavedPixels = false;
isGrouping = false;
// Initialize the cursor shape // Initialize the cursor shape
SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
initCursor( 21 ); initCursor( 21 );
...@@ -91,13 +89,13 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, ...@@ -91,13 +89,13 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
SetGridColor( COLOR4D( 0.5, 0.5, 0.5, 0.3 ) ); SetGridColor( COLOR4D( 0.5, 0.5, 0.5, 0.3 ) );
SetCoarseGrid( 10 ); SetCoarseGrid( 10 );
SetGridLineWidth( 0.5 ); SetGridLineWidth( 0.5 );
Refresh();
} }
CAIRO_GAL::~CAIRO_GAL() CAIRO_GAL::~CAIRO_GAL()
{ {
deinitSurface();
delete cursorPixels; delete cursorPixels;
delete cursorPixelsSaved; delete cursorPixelsSaved;
...@@ -139,6 +137,9 @@ void CAIRO_GAL::skipMouseEvent( wxMouseEvent& aEvent ) ...@@ -139,6 +137,9 @@ void CAIRO_GAL::skipMouseEvent( wxMouseEvent& aEvent )
void CAIRO_GAL::initSurface() void CAIRO_GAL::initSurface()
{ {
if( isInitialized )
return;
// The size of the client area needs to be greater than zero // The size of the client area needs to be greater than zero
clientRectangle = parentWindow->GetClientRect(); clientRectangle = parentWindow->GetClientRect();
...@@ -184,14 +185,21 @@ void CAIRO_GAL::initSurface() ...@@ -184,14 +185,21 @@ void CAIRO_GAL::initSurface()
lineWidth = 0; lineWidth = 0;
isDeleteSavedPixels = true; isDeleteSavedPixels = true;
isInitialized = true;
} }
void CAIRO_GAL::deinitSurface() void CAIRO_GAL::deinitSurface()
{ {
if( !isInitialized )
return;
// Destroy Cairo objects // Destroy Cairo objects
cairo_destroy( cairoImage ); cairo_destroy( cairoImage );
cairo_surface_destroy( cairoSurface ); cairo_surface_destroy( cairoSurface );
isInitialized = false;
} }
...@@ -548,12 +556,15 @@ void CAIRO_GAL::SetLayerDepth( double aLayerDepth ) ...@@ -548,12 +556,15 @@ void CAIRO_GAL::SetLayerDepth( double aLayerDepth )
{ {
super::SetLayerDepth( aLayerDepth ); super::SetLayerDepth( aLayerDepth );
if( isInitialized )
{
storePath(); storePath();
cairo_pop_group_to_source( cairoImage ); cairo_pop_group_to_source( cairoImage );
cairo_paint_with_alpha( cairoImage, fillColor.a ); cairo_paint_with_alpha( cairoImage, fillColor.a );
cairo_push_group( cairoImage ); cairo_push_group( cairoImage );
}
} }
......
...@@ -359,6 +359,7 @@ private: ...@@ -359,6 +359,7 @@ private:
unsigned int* bitmapBuffer; ///< Storage of the cairo image unsigned int* bitmapBuffer; ///< Storage of the cairo image
unsigned int* bitmapBufferBackup; ///< Backup storage of the cairo image unsigned int* bitmapBufferBackup; ///< Backup storage of the cairo image
int stride; ///< Stride value for Cairo int stride; ///< Stride value for Cairo
bool isInitialized; ///< Are Cairo image & surface ready to use
// Mapping between Cairo and GAL line attributes // Mapping between Cairo and GAL line attributes
std::map<LineCap, cairo_line_cap_t> lineCapMap; ///< Line cap style mapping std::map<LineCap, cairo_line_cap_t> lineCapMap; ///< Line cap style mapping
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment