gal: minor cleanup & formatting

This commit is contained in:
Tomasz Włostowski 2019-02-16 20:25:10 +01:00
parent bbee30671a
commit 85a7ab7795
6 changed files with 22 additions and 13 deletions

View File

@ -93,6 +93,7 @@ void CAIRO_GAL_BASE::updateWorldScreenMatrix()
cairo_matrix_multiply( &currentWorld2Screen, &currentXform, &cairoWorldScreenMatrix ); cairo_matrix_multiply( &currentWorld2Screen, &currentXform, &cairoWorldScreenMatrix );
} }
const VECTOR2D CAIRO_GAL_BASE::xform( double x, double y ) const VECTOR2D CAIRO_GAL_BASE::xform( double x, double y )
{ {
VECTOR2D rv; VECTOR2D rv;
@ -102,11 +103,13 @@ const VECTOR2D CAIRO_GAL_BASE::xform( double x, double y )
return rv; return rv;
} }
const VECTOR2D CAIRO_GAL_BASE::xform( const VECTOR2D& aP ) const VECTOR2D CAIRO_GAL_BASE::xform( const VECTOR2D& aP )
{ {
return xform(aP.x, aP.y); return xform( aP.x, aP.y );
} }
const double CAIRO_GAL_BASE::xform( double x ) const double CAIRO_GAL_BASE::xform( double x )
{ {
double dx = currentWorld2Screen.xx * x; double dx = currentWorld2Screen.xx * x;
@ -114,14 +117,16 @@ const double CAIRO_GAL_BASE::xform( double x )
return sqrt( dx * dx + dy * dy ); return sqrt( dx * dx + dy * dy );
} }
static double roundp( double x ) static double roundp( double x )
{ {
return floor( x + 0.5 ) + 0.5; return floor( x + 0.5 ) + 0.5;
} }
const VECTOR2D CAIRO_GAL_BASE::roundp( const VECTOR2D& v ) const VECTOR2D CAIRO_GAL_BASE::roundp( const VECTOR2D& v )
{ {
if ( lineWidthIsOdd ) if( lineWidthIsOdd )
return VECTOR2D( ::roundp( v.x ), ::roundp( v.y ) ); return VECTOR2D( ::roundp( v.x ), ::roundp( v.y ) );
else else
return VECTOR2D( floor( v.x + 0.5 ), floor( v.y + 0.5 ) ); return VECTOR2D( floor( v.x + 0.5 ), floor( v.y + 0.5 ) );
@ -165,6 +170,7 @@ void CAIRO_GAL_BASE::syncLineWidth( bool aForceWidth, double aWidth )
lineWidthInPixels = w; lineWidthInPixels = w;
} }
void CAIRO_GAL_BASE::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, void CAIRO_GAL_BASE::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint,
double aWidth ) double aWidth )
{ {
@ -223,7 +229,7 @@ void CAIRO_GAL_BASE::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
auto r = ::roundp( xform( aRadius ) ); auto r = ::roundp( xform( aRadius ) );
cairo_new_sub_path( currentContext ); cairo_new_sub_path( currentContext );
cairo_arc( currentContext, c.x, c.y, r, 0.0, 2 * M_PI); cairo_arc( currentContext, c.x, c.y, r, 0.0, 2 * M_PI );
cairo_close_path( currentContext ); cairo_close_path( currentContext );
flushPath(); flushPath();
isElementAdded = true; isElementAdded = true;
@ -265,7 +271,7 @@ void CAIRO_GAL_BASE::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, doub
SetStrokeColor( fgcolor ); SetStrokeColor( fgcolor );
} }
cairo_set_line_width(currentContext, lineWidthInPixels ); cairo_set_line_width( currentContext, lineWidthInPixels );
cairo_new_sub_path( currentContext ); cairo_new_sub_path( currentContext );
cairo_arc( currentContext, c.x, c.y, r, aStartAngle, aEndAngle ); cairo_arc( currentContext, c.x, c.y, r, aStartAngle, aEndAngle );
flushPath(); flushPath();
@ -849,6 +855,7 @@ void CAIRO_GAL_BASE::drawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D&
cairo_stroke( currentContext ); cairo_stroke( currentContext );
} }
void CAIRO_GAL_BASE::drawGridPoint( const VECTOR2D& aPoint, double aSize ) void CAIRO_GAL_BASE::drawGridPoint( const VECTOR2D& aPoint, double aSize )
{ {
auto p = roundp( xform( aPoint ) ); auto p = roundp( xform( aPoint ) );
@ -861,12 +868,12 @@ void CAIRO_GAL_BASE::drawGridPoint( const VECTOR2D& aPoint, double aSize )
cairo_set_line_join( currentContext, CAIRO_LINE_JOIN_MITER ); cairo_set_line_join( currentContext, CAIRO_LINE_JOIN_MITER );
cairo_set_line_cap( currentContext, CAIRO_LINE_CAP_BUTT ); cairo_set_line_cap( currentContext, CAIRO_LINE_CAP_BUTT );
cairo_set_line_width( currentContext, 1.0 ); //floor( aSize + 0.5 ) - 0.5 ); cairo_set_line_width( currentContext, 1.0 );
cairo_move_to( currentContext, p.x - s, p.y - s); cairo_move_to( currentContext, p.x - s, p.y - s );
cairo_line_to( currentContext, p.x + s, p.y - s); cairo_line_to( currentContext, p.x + s, p.y - s );
cairo_line_to( currentContext, p.x + s, p.y + s); cairo_line_to( currentContext, p.x + s, p.y + s );
cairo_line_to( currentContext, p.x - s, p.y + s); cairo_line_to( currentContext, p.x - s, p.y + s );
cairo_close_path( currentContext ); cairo_close_path( currentContext );
cairo_fill( currentContext ); cairo_fill( currentContext );
@ -1342,7 +1349,6 @@ void CAIRO_GAL::setCompositor()
compositor->Resize( screenSize.x, screenSize.y ); compositor->Resize( screenSize.x, screenSize.y );
compositor->SetAntialiasingMode( options.cairo_antialiasing_mode ); compositor->SetAntialiasingMode( options.cairo_antialiasing_mode );
// Prepare buffers // Prepare buffers
mainBuffer = compositor->CreateBuffer(); mainBuffer = compositor->CreateBuffer();
overlayBuffer = compositor->CreateBuffer(); overlayBuffer = compositor->CreateBuffer();
@ -1388,6 +1394,7 @@ bool CAIRO_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions )
return refresh; return refresh;
} }
void CAIRO_GAL_BASE::DrawGrid() void CAIRO_GAL_BASE::DrawGrid()
{ {
SetTarget( TARGET_NONCACHED ); SetTarget( TARGET_NONCACHED );

View File

@ -213,7 +213,6 @@ double GAL::computeMinGridSpacing() const
} }
VECTOR2D GAL::GetGridPoint( const VECTOR2D& aPoint ) const VECTOR2D GAL::GetGridPoint( const VECTOR2D& aPoint ) const
{ {
#if 0 #if 0

View File

@ -405,6 +405,7 @@ void OPENGL_COMPOSITOR::clean()
m_initialized = false; m_initialized = false;
} }
int OPENGL_COMPOSITOR::GetAntialiasSupersamplingFactor() const int OPENGL_COMPOSITOR::GetAntialiasSupersamplingFactor() const
{ {
switch( m_currentAntialiasingMode ) switch( m_currentAntialiasingMode )

View File

@ -346,12 +346,14 @@ bool OPENGL_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions )
return refresh; return refresh;
} }
double OPENGL_GAL::getWorldPixelSize() const double OPENGL_GAL::getWorldPixelSize() const
{ {
auto matrix = GetScreenWorldMatrix(); auto matrix = GetScreenWorldMatrix();
return std::min( std::abs( matrix.GetScale().x ), std::abs( matrix.GetScale().y ) ); return std::min( std::abs( matrix.GetScale().x ), std::abs( matrix.GetScale().y ) );
} }
VECTOR2D OPENGL_GAL::getScreenPixelSize() const VECTOR2D OPENGL_GAL::getScreenPixelSize() const
{ {
auto sf = GetBackingScaleFactor(); auto sf = GetBackingScaleFactor();

View File

@ -309,7 +309,7 @@ protected:
*/ */
unsigned int getNewGroupNumber(); unsigned int getNewGroupNumber();
void syncLineWidth( bool aForceWidth = false, double aWidth = 0.0); void syncLineWidth( bool aForceWidth = false, double aWidth = 0.0 );
void updateWorldScreenMatrix(); void updateWorldScreenMatrix();
const VECTOR2D roundp( const VECTOR2D& v ); const VECTOR2D roundp( const VECTOR2D& v );