Commit 790a1f85 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Made GAL backends settings more consistent. Fixed grid line width in the OpenGL backend.

parent 1ce21605
Loading
Loading
Loading
Loading
+10 −22
Original line number Original line Diff line number Diff line
@@ -40,23 +40,16 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
                      wxEvtHandler* aPaintListener, const wxString& aName ) :
                      wxEvtHandler* aPaintListener, const wxString& aName ) :
    wxWindow( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName )
    wxWindow( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName )
{
{
    // Default values
    fillColor   = COLOR4D( 0, 0, 0, 1 );
    strokeColor = COLOR4D( 1, 1, 1, 1 );
    screenSize  = VECTOR2D( aParent->GetSize() );

    parentWindow  = aParent;
    parentWindow  = aParent;
    mouseListener = aMouseListener;
    mouseListener = aMouseListener;
    paintListener = aPaintListener;
    paintListener = aPaintListener;


    // Initialize the flags
    isGrouping          = false;
    isGrouping          = false;
    isInitialized       = false;
    isInitialized       = false;
    isDeleteSavedPixels = false;
    isDeleteSavedPixels = false;
    zoomFactor          = 1.0;
    groupCounter        = 0;
    groupCounter        = 0;


    SetSize( aParent->GetSize() );

    // Connecting the event handlers
    // Connecting the event handlers
    Connect( wxEVT_PAINT, wxPaintEventHandler( CAIRO_GAL::onPaint ) );
    Connect( wxEVT_PAINT, wxPaintEventHandler( CAIRO_GAL::onPaint ) );


@@ -73,17 +66,12 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
    Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
    Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
#endif
#endif


    // Initialize the cursor shape
    SetSize( aParent->GetSize() );
    SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    screenSize = VECTOR2D( aParent->GetSize() );
    initCursor( 21 );
    initCursor( 20 );


    // Allocate memory
    // Allocate memory for pixel storage
    allocateBitmaps();
    allocateBitmaps();

    // Set grid defaults
    SetGridColor( COLOR4D( 0.5, 0.5, 0.5, 0.3 ) );
    SetCoarseGrid( 10 );
    SetGridLineWidth( 0.5 );
}
}




@@ -557,10 +545,10 @@ void CAIRO_GAL::SetLayerDepth( double aLayerDepth )
    {
    {
        storePath();
        storePath();


//        cairo_pop_group_to_source( currentContext );
        cairo_pop_group_to_source( currentContext );
//        cairo_paint_with_alpha( currentContext, fillColor.a );
        cairo_paint_with_alpha( currentContext, fillColor.a );
//

//        cairo_push_group( currentContext );
        cairo_push_group( currentContext );
    }
    }
}
}


+82 −80
Original line number Original line Diff line number Diff line
@@ -38,15 +38,21 @@ GAL::GAL() :
    // Set the default values for the internal variables
    // Set the default values for the internal variables
    SetIsFill( false );
    SetIsFill( false );
    SetIsStroke( true );
    SetIsStroke( true );
    SetIsCursorEnabled( false );
    SetZoomFactor( 1.0 );
    SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
    SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetGridVisibility( true );
    SetIsCursorEnabled( false );
    SetGridColor( COLOR4D( 1, 1, 1, 0.1 ) );
    SetZoomFactor( 1.0 );
    SetCoarseGrid( 5 );
    SetLineWidth( 1.0 );
    SetDepthRange( VECTOR2D( -2048, 2047 ) );
    SetDepthRange( VECTOR2D( -2048, 2047 ) );
    SetLineWidth( 1.0 );

    // Set grid defaults
    SetGridVisibility( true );
    SetGridColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
    SetCoarseGrid( 10 );
    SetGridLineWidth( 0.5 );

    // Initialize the cursor shape
    SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );


    strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize );
    strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize );
}
}
@@ -65,22 +71,42 @@ void GAL::DrawGrid()
    SetTarget( TARGET_NONCACHED );
    SetTarget( TARGET_NONCACHED );


    // The grid consists of lines
    // The grid consists of lines
    // For the drawing the start points, end points and increments have to be calculated in world coordinates
    // For the drawing the start points, end points and increments have
    VECTOR2D    screenStartPoint( 0, 0 );
    // to be calculated in world coordinates
    VECTOR2D    screenEndPoint( screenSize.x, screenSize.y );
    MATRIX3x3D  inverseMatrix   = worldScreenMatrix.Inverse();
    MATRIX3x3D  inverseMatrix   = worldScreenMatrix.Inverse();
    VECTOR2D    worldStartPoint = inverseMatrix * screenStartPoint;
    VECTOR2D    worldStartPoint = inverseMatrix * VECTOR2D( 0.0, 0.0 );
    VECTOR2D    worldEndPoint   = inverseMatrix * screenEndPoint;
    VECTOR2D    worldEndPoint   = inverseMatrix * screenSize;

    int gridScreenSizeDense  = round( gridSize.x * worldScale );
    int gridScreenSizeCoarse = round( gridSize.x * static_cast<double>( gridTick ) * worldScale );

    // Compute the line width of the grid
    double width = 2.0 * gridLineWidth / worldScale;
    double doubleWidth = 2.0 * width;

    SetIsFill( false );
    SetIsStroke( true );

    // Draw the origin marker
    SetLayerDepth( 0.0 );
    double origSize = static_cast<double>( gridOriginMarkerSize ) / worldScale;
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetLineWidth( width );
    DrawLine( gridOrigin + VECTOR2D( -origSize, -origSize ),
              gridOrigin + VECTOR2D( origSize, origSize ) );
    DrawLine( gridOrigin + VECTOR2D( -origSize, origSize ),
              gridOrigin + VECTOR2D( origSize, -origSize ) );
    DrawCircle( gridOrigin, origSize * 0.7 );


    // Check if the grid would not be too dense
    if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) > gridDrawThreshold )
    {
        // Compute grid variables
        // Compute grid variables
        int gridStartX = round( worldStartPoint.x / gridSize.x );
        int gridStartX = round( worldStartPoint.x / gridSize.x );
        int gridEndX = round( worldEndPoint.x / gridSize.x );
        int gridEndX = round( worldEndPoint.x / gridSize.x );
        int gridStartY = round( worldStartPoint.y / gridSize.y );
        int gridStartY = round( worldStartPoint.y / gridSize.y );
        int gridEndY = round( worldEndPoint.y / gridSize.y );
        int gridEndY = round( worldEndPoint.y / gridSize.y );


    int gridScreenSizeDense  = round( gridSize.x * worldScale );
    int gridScreenSizeCoarse = round( gridSize.x * (double) gridTick * worldScale );

        // Swap the coordinates, if they have not the right order
        // Swap the coordinates, if they have not the right order
        SWAP( gridEndX, <, gridStartX );
        SWAP( gridEndX, <, gridStartX );
        SWAP( gridEndY, <, gridStartY );
        SWAP( gridEndY, <, gridStartY );
@@ -91,31 +117,10 @@ void GAL::DrawGrid()
        gridEndX    += 1;
        gridEndX    += 1;
        gridEndY    += 1;
        gridEndY    += 1;


    double  savedLineWidth  = GetLineWidth();
        // Draw the grid behind all layers
    COLOR4D savedColor      = GetStrokeColor();
        SetLayerDepth( depthRange.y * 0.75 );

    // Compute the line width of the grid
    ComputeWorldScale();
    double  width = gridLineWidth / worldScale;
    double  doubleWidth = 2 * width;

    SetLayerDepth( 0.0 );

    // Draw the origin marker
    double origSize = (double) gridOriginMarkerSize / worldScale;
    SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
    SetLineWidth( width );
    SetIsFill( false );
    DrawLine( gridOrigin + VECTOR2D( -origSize, -origSize ), gridOrigin + VECTOR2D( origSize, origSize ) );
    DrawLine( gridOrigin + VECTOR2D( -origSize, origSize ),  gridOrigin + VECTOR2D( origSize, -origSize ) );
    DrawCircle( gridOrigin, origSize * 0.7 );

        SetStrokeColor( gridColor );
        SetStrokeColor( gridColor );


    if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) < gridDrawThreshold )
        return;

    SetLayerDepth( 0.0 );
        // Now draw the grid, every coarse grid line gets the double width
        // Now draw the grid, every coarse grid line gets the double width
        for( int j = gridStartY; j < gridEndY; j += 1 )
        for( int j = gridStartY; j < gridEndY; j += 1 )
        {
        {
@@ -154,10 +159,7 @@ void GAL::DrawGrid()
                              VECTOR2D( i * gridSize.x, gridEndY * gridSize.y ) );
                              VECTOR2D( i * gridSize.x, gridEndY * gridSize.y ) );
            }
            }
        }
        }

    }
    // Restore old values
    SetLineWidth( savedLineWidth );
    SetStrokeColor( savedColor );
}
}




+7 −2
Original line number Original line Diff line number Diff line
@@ -143,13 +143,18 @@ void OPENGL_COMPOSITOR::SetBuffer( unsigned int aBufferHandle )
        return;
        return;


    // Change the rendering destination to the selected attachment point
    // Change the rendering destination to the selected attachment point
    if( m_currentFbo != m_framebuffer )
    if( aBufferHandle == 0 )
    {
        glBindFramebuffer( GL_FRAMEBUFFER, 0 );
        m_currentFbo = 0;
    }
    else if( m_currentFbo != m_framebuffer )
    {
    {
        glBindFramebuffer( GL_FRAMEBUFFER, m_framebuffer );
        glBindFramebuffer( GL_FRAMEBUFFER, m_framebuffer );
        m_currentFbo = m_framebuffer;
        m_currentFbo = m_framebuffer;
    }
    }


    if( m_current != aBufferHandle - 1 )
    if( m_currentFbo != 0 && m_current != aBufferHandle - 1 )
    {
    {
        m_current = aBufferHandle - 1;
        m_current = aBufferHandle - 1;
        glDrawBuffer( m_buffers[m_current].attachmentPoint );
        glDrawBuffer( m_buffers[m_current].attachmentPoint );
+24 −46
Original line number Original line Diff line number Diff line
@@ -63,29 +63,14 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
    mouseListener   = aMouseListener;
    mouseListener   = aMouseListener;
    paintListener   = aPaintListener;
    paintListener   = aPaintListener;


    // Set the cursor size
    initCursor( 20 );
    SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );

    // Initialize the flags
    // Initialize the flags
    isGlewInitialized        = false;
    isGlewInitialized        = false;
    isFramebufferInitialized = false;
    isFramebufferInitialized = false;
    isShaderInitialized      = false;
    isShaderInitialized      = false;
    isGrouping               = false;
    isGrouping               = false;
    wxSize parentSize        = aParent->GetSize();
    groupCounter             = 0;
    groupCounter             = 0;


    SetSize( parentSize );
    // Connecting the event handlers

    screenSize.x = parentSize.x;
    screenSize.y = parentSize.y;

    // Set grid defaults
    SetGridColor( COLOR4D( 0.3, 0.3, 0.3, 0.3 ) );
    SetCoarseGrid( 10 );
    SetGridLineWidth( 1.0 );

    // Connecting the event handlers.
    Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
    Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );


    // Mouse events are skipped to the parent
    // Mouse events are skipped to the parent
@@ -101,6 +86,10 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
    Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
    Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
#endif
#endif


    SetSize( aParent->GetSize() );
    screenSize = VECTOR2D( aParent->GetSize() );
    initCursor( 20 );

    // Tesselator initialization
    // Tesselator initialization
    tesselator = gluNewTess();
    tesselator = gluNewTess();
    InitTesselatorCallbacks( tesselator );
    InitTesselatorCallbacks( tesselator );
@@ -308,6 +297,12 @@ void OPENGL_GAL::BeginDrawing()
    SetStrokeColor( strokeColor );
    SetStrokeColor( strokeColor );


    // Prepare buffers for drawing
    // Prepare buffers for drawing
    compositor.SetBuffer( mainBuffer );
    compositor.ClearBuffer();
    compositor.SetBuffer( overlayBuffer );
    compositor.ClearBuffer();
    compositor.SetBuffer( 0 );  // Unbind buffers

    nonCachedManager.Clear();
    nonCachedManager.Clear();
    overlayManager.Clear();
    overlayManager.Clear();


@@ -321,13 +316,11 @@ void OPENGL_GAL::EndDrawing()
{
{
    // Cached & non-cached containers are rendered to the same buffer
    // Cached & non-cached containers are rendered to the same buffer
    compositor.SetBuffer( mainBuffer );
    compositor.SetBuffer( mainBuffer );
    compositor.ClearBuffer();
    nonCachedManager.EndDrawing();
    nonCachedManager.EndDrawing();
    cachedManager.EndDrawing();
    cachedManager.EndDrawing();


    // Overlay container is rendered to a different buffer
    // Overlay container is rendered to a different buffer
    compositor.SetBuffer( overlayBuffer );
    compositor.SetBuffer( overlayBuffer );
    compositor.ClearBuffer();
    overlayManager.EndDrawing();
    overlayManager.EndDrawing();


    // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
    // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
@@ -349,11 +342,9 @@ inline void OPENGL_GAL::drawLineQuad( const VECTOR2D& aStartPoint, const VECTOR2
    if( lineLength <= 0.0 )
    if( lineLength <= 0.0 )
        return;
        return;


    VECTOR2D perpendicularVector( -startEndVector.y * scale, startEndVector.x * scale );
    glm::vec4 vector( perpendicularVector.x, perpendicularVector.y, 0.0, 0.0 );

    // The perpendicular vector also needs transformations
    // The perpendicular vector also needs transformations
    vector = currentManager->GetTransformation() * vector;
    glm::vec4 vector = currentManager->GetTransformation() *
            glm::vec4( -startEndVector.y * scale, startEndVector.x * scale, 0.0, 0.0 );


    // Line width is maintained by the vertex shader
    // Line width is maintained by the vertex shader
    currentManager->Shader( SHADER_LINE, vector.x, vector.y, lineWidth );
    currentManager->Shader( SHADER_LINE, vector.x, vector.y, lineWidth );
@@ -1151,39 +1142,26 @@ void OPENGL_GAL::DrawCursor( VECTOR2D aCursorPosition )


void OPENGL_GAL::DrawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
void OPENGL_GAL::DrawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
{
{
    // TODO change to simple drawline
    compositor.SetBuffer( mainBuffer );
    // We check, if we got a horizontal or a vertical grid line and compute the offset
    VECTOR2D perpendicularVector;


    if( aStartPoint.x == aEndPoint.x )
    // We do not need a very precise comparison here (the lineWidth is set by GAL::DrawGrid())
    if( fabs( lineWidth - 2.0 * gridLineWidth / worldScale ) < 0.1 )
    {
    {
        // Vertical grid line
        glLineWidth( 1.0 );
        perpendicularVector = VECTOR2D( 0.5 * lineWidth, 0 );
    }
    }
    else
    else
    {
    {
        // Horizontal grid line
        glLineWidth( 2.0 );
        perpendicularVector = VECTOR2D( 0, 0.5 * lineWidth );
    }
    }


    // Now we compute the edge points of the quad
    glColor4d( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
    VECTOR2D point1 = aStartPoint + perpendicularVector;
    VECTOR2D point2 = aStartPoint - perpendicularVector;
    VECTOR2D point3 = aEndPoint + perpendicularVector;
    VECTOR2D point4 = aEndPoint - perpendicularVector;

    currentManager->Color( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
    currentManager->Shader( SHADER_NONE );


    // Draw the quad for the grid line
    glBegin( GL_LINES );
    double gridDepth = depthRange.y * 0.75;
    glVertex3d( aStartPoint.x, aStartPoint.y, layerDepth );
    currentManager->Vertex( point1.x, point1.y, gridDepth );
    glVertex3d( aEndPoint.x, aEndPoint.y, layerDepth );
    currentManager->Vertex( point2.x, point2.y, gridDepth );
    glEnd();
    currentManager->Vertex( point4.x, point4.y, gridDepth );


    currentManager->Vertex( point1.x, point1.y, gridDepth );
    glColor4d( 1.0, 1.0, 1.0, 1.0 );
    currentManager->Vertex( point4.x, point4.y, gridDepth );
    currentManager->Vertex( point3.x, point3.y, gridDepth );
}
}




+1 −1
Original line number Original line Diff line number Diff line
@@ -51,7 +51,7 @@ void main()
     
     
        // Make lines appear to be at least 1 pixel wide
        // Make lines appear to be at least 1 pixel wide
        if( worldScale * lineWidth < MIN_WIDTH )
        if( worldScale * lineWidth < MIN_WIDTH )
            scale = 1.0f / ( worldScale * lineWidth );
            scale = MIN_WIDTH / ( worldScale * lineWidth );
        else
        else
            scale = 1.0f;
            scale = 1.0f;
        
        
Loading