Commit cbec733d authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Refactored code responsible for high contrast mode. Now it allows to have more...

Refactored code responsible for high contrast mode. Now it allows to have more than one layer on the top.
Selecting layer using the dropdown list on the toolbar influences the layer displayed in high contrast mode.
parent 20c86db7
Loading
Loading
Loading
Loading
+53 −48
Original line number Original line Diff line number Diff line
@@ -39,11 +39,6 @@


using namespace KiGfx;
using namespace KiGfx;


// Static constants
const int VIEW::VIEW_MAX_LAYERS = 64;
// Top layer depth
const int VIEW::TOP_LAYER       = -1;

void VIEW::AddLayer( int aLayer, bool aDisplayOnly )
void VIEW::AddLayer( int aLayer, bool aDisplayOnly )
{
{
    if( m_layers.find( aLayer ) == m_layers.end() )
    if( m_layers.find( aLayer ) == m_layers.end() )
@@ -140,14 +135,12 @@ int VIEW::Query( const BOX2I& aRect, std::vector<LayerItemPair>& aResult )




VIEW::VIEW( bool aIsDynamic ) :
VIEW::VIEW( bool aIsDynamic ) :
    m_enableTopLayer( false ),
    m_enableOrderModifier( false ),
    m_scale ( 1.0 ),
    m_scale ( 1.0 ),
    m_painter( NULL ),
    m_painter( NULL ),
    m_gal( NULL ),
    m_gal( NULL ),
    m_dynamic( aIsDynamic )
    m_dynamic( aIsDynamic )
{
{
    // By default there is no layer on the top
    m_topLayer.enabled = false;
}
}




@@ -395,63 +388,75 @@ void VIEW::ChangeLayerDepth( int aLayer, int aDepth )
}
}




void VIEW::SetTopLayer( int aLayer )
void VIEW::SetTopLayer( int aLayer, bool aEnabled )
{
    // Restore previous order
    if( m_topLayer.enabled )
{
{
        m_layers[m_topLayer.id].renderingOrder = m_topLayer.renderingOrder;
    if( aEnabled )
        ChangeLayerDepth( m_topLayer.id, m_topLayer.renderingOrder );
    }

    if( aLayer >= 0 && aLayer < VIEW_MAX_LAYERS )
    {
    {
        // Save settings, so it can be restored later
        if( m_topLayers.count( aLayer ) == 1 )
        m_topLayer.renderingOrder = m_layers[aLayer].renderingOrder;
            return;
        m_topLayer.id = m_layers[aLayer].id;


        // Apply new settings only if the option is enabled
        m_topLayers.insert( aLayer );
        if( m_enableTopLayer )
        {
            m_layers[aLayer].renderingOrder = TOP_LAYER;
            ChangeLayerDepth( aLayer, TOP_LAYER );
        }


        // Set the flag saying that settings stored in m_topLayer are valid
        // Move the layer closer to front
        m_topLayer.enabled = true;
        if( m_enableOrderModifier )
            m_layers[aLayer].renderingOrder += TOP_LAYER_MODIFIER;
    }
    }
    else
    else
    {
    {
        // There are no valid settings in m_topLayer
        if( m_topLayers.count( aLayer ) == 0 )
        m_topLayer.enabled = false;
            return;
    }


    sortLayers();
        m_topLayers.erase( aLayer );

        // Restore the previous rendering order
        if( m_enableOrderModifier )
            m_layers[aLayer].renderingOrder -= TOP_LAYER_MODIFIER;
    }
}
}




void VIEW::EnableTopLayer( bool aEnable )
void VIEW::EnableTopLayer( bool aEnable )
{
{
    if( aEnable == m_enableTopLayer ) return;
    if( aEnable == m_enableOrderModifier ) return;
    m_enableOrderModifier = aEnable;


    // Use stored settings only if applicable
    std::set<unsigned int>::iterator it;
    // (topLayer.enabled == false means there are no valid settings stored)
    if( m_topLayer.enabled )
    {
    if( aEnable )
    if( aEnable )
    {
    {
            m_layers[m_topLayer.id].renderingOrder = TOP_LAYER;
        for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
            ChangeLayerDepth( m_topLayer.id, TOP_LAYER );
            m_layers[*it].renderingOrder += TOP_LAYER_MODIFIER;
    }
    }
    else
    else
    {
    {
            m_layers[m_topLayer.id].renderingOrder = m_topLayer.renderingOrder;
        for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
            ChangeLayerDepth( m_topLayer.id, m_topLayer.renderingOrder );
            m_layers[*it].renderingOrder -= TOP_LAYER_MODIFIER;
    }
    }
}
}


void VIEW::ClearTopLayers()
{
    std::set<unsigned int>::iterator it;

    if( m_enableOrderModifier )
    {
        // Restore the previous rendering order for layers that were marked as top
        for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
            m_layers[*it].renderingOrder -= TOP_LAYER_MODIFIER;
    }

    m_topLayers.clear();
}


void VIEW::UpdateAllLayersOrder()
{
    sortLayers();
    sortLayers();


    m_enableTopLayer = aEnable;
    BOOST_FOREACH( LayerMap::value_type& l, m_layers )
    {
        ChangeLayerDepth( l.first, l.second.renderingOrder );
    }
}
}




@@ -513,7 +518,7 @@ void VIEW::redrawRect( const BOX2I& aRect )
        {
        {
            drawItem drawFunc( this, l );
            drawItem drawFunc( this, l );


            m_gal->SetLayerDepth( static_cast<double>( l->renderingOrder ) );
            m_gal->SetLayerDepth( l->renderingOrder );
            l->items->Query( aRect, drawFunc );
            l->items->Query( aRect, drawFunc );
            l->isDirty = false;
            l->isDirty = false;
        }
        }
@@ -703,7 +708,7 @@ void VIEW::RecacheAllItems( bool aImmediately )


        if( l->cached )
        if( l->cached )
        {
        {
            m_gal->SetLayerDepth( (double) l->renderingOrder );
            m_gal->SetLayerDepth( l->renderingOrder );
            recacheLayer visitor( this, m_gal, l->id, aImmediately );
            recacheLayer visitor( this, m_gal, l->id, aImmediately );
            l->items->Query( r, visitor );
            l->items->Query( r, visitor );
        }
        }
+25 −8
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
#define __VIEW_H
#define __VIEW_H


#include <vector>
#include <vector>
#include <set>
#include <boost/unordered/unordered_map.hpp>
#include <boost/unordered/unordered_map.hpp>


#include <math/box2.h>
#include <math/box2.h>
@@ -305,7 +306,7 @@ public:
     * @param aLayer: the layer or -1 in case when no particular layer should
     * @param aLayer: the layer or -1 in case when no particular layer should
     * be displayed on the top.
     * be displayed on the top.
     */
     */
    void    SetTopLayer( int aLayer );
    void    SetTopLayer( int aLayer, bool aEnabled = true );


    /**
    /**
     * Function EnableTopLayer()
     * Function EnableTopLayer()
@@ -316,6 +317,20 @@ public:
     */
     */
    void    EnableTopLayer( bool aEnable );
    void    EnableTopLayer( bool aEnable );


    /**
     * Function ClearTopLayers()
     * Removes all layers from the on-the-top set (they are no longer displayed over the rest of
     * layers).
     */
    void    ClearTopLayers();

    /**
     * Function UpdateLayerOrder()
     * Does everything that is needed to apply the rendering order of layers. It has to be called
     * after modification of renderingOrder field of LAYER.
     */
    void    UpdateAllLayersOrder();

    /**
    /**
     * Function Redraw()
     * Function Redraw()
     * Immediately redraws the whole view.
     * Immediately redraws the whole view.
@@ -344,8 +359,7 @@ public:
     */
     */
    bool IsDynamic() const { return m_dynamic; }
    bool IsDynamic() const { return m_dynamic; }


    static const int VIEW_MAX_LAYERS;            ///* maximum number of layers that may be shown
    static const int VIEW_MAX_LAYERS = 64;       ///* maximum number of layers that may be shown
    static const int TOP_LAYER;                  ///* layer number for displaying items on the top


private:
private:
    struct VIEW_LAYER
    struct VIEW_LAYER
@@ -377,11 +391,8 @@ private:
    struct updateItemsColor;
    struct updateItemsColor;
    struct changeItemsDepth;
    struct changeItemsDepth;


    ///* Saves current top layer settings in order to restore it when it's not top anymore
    ///* Whether to use rendering order modifier or not
    VIEW_LAYER m_topLayer;
    bool m_enableOrderModifier;

    ///* Whether to use top layer settings or not
    bool m_enableTopLayer;


    ///* Redraws contents within rect aRect
    ///* Redraws contents within rect aRect
    void redrawRect( const BOX2I& aRect );
    void redrawRect( const BOX2I& aRect );
@@ -412,6 +423,9 @@ private:
    /// Sorted list of pointers to members of m_layers.
    /// Sorted list of pointers to members of m_layers.
    LayerOrder  m_orderedLayers;
    LayerOrder  m_orderedLayers;


    /// Stores set of layers that are displayed on the top
    std::set<unsigned int> m_topLayers;

    /// Center point of the VIEW (the point at which we are looking at)
    /// Center point of the VIEW (the point at which we are looking at)
    VECTOR2D    m_center;
    VECTOR2D    m_center;


@@ -427,6 +441,9 @@ private:
    /// Dynamic VIEW (eg. display PCB in window) allows changes once it is built,
    /// Dynamic VIEW (eg. display PCB in window) allows changes once it is built,
    /// static (eg. image/PDF) - does not.
    /// static (eg. image/PDF) - does not.
    bool        m_dynamic;
    bool        m_dynamic;

    /// Rendering order modifier for layers that are marked as top layers
    static const int TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS;
};
};
} // namespace KiGfx
} // namespace KiGfx


+1 −7
Original line number Original line Diff line number Diff line
@@ -133,13 +133,7 @@ protected:
     * will change the currently active layer to \a aLayer and also
     * will change the currently active layer to \a aLayer and also
     * update the PCB_LAYER_WIDGET.
     * update the PCB_LAYER_WIDGET.
     */
     */
    void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true )
    void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true );
    {
        ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;

        if( doLayerWidgetUpdate )
            syncLayerWidgetLayer();
    }


    /**
    /**
     * Function getActiveLayer
     * Function getActiveLayer
+0 −4
Original line number Original line Diff line number Diff line
@@ -258,15 +258,11 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
            view->SetLayerVisible( ITEM_GAL_LAYER( i ), m_Pcb->IsElementVisible( i ) );
            view->SetLayerVisible( ITEM_GAL_LAYER( i ), m_Pcb->IsElementVisible( i ) );
        }
        }


        view->SetTopLayer( m_Pcb->GetLayer() );

        view->RecacheAllItems( true );
        view->RecacheAllItems( true );
        if( m_galCanvasActive )
        if( m_galCanvasActive )
        {
            m_galCanvas->Refresh();
            m_galCanvas->Refresh();
    }
    }
}
}
}




void PCB_BASE_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
void PCB_BASE_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
+2 −13
Original line number Original line Diff line number Diff line
@@ -356,21 +356,10 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( LAYER_NUM aLayer )
    // false from this function.
    // false from this function.
    myframe->setActiveLayer( aLayer, false );
    myframe->setActiveLayer( aLayer, false );


    // Set display settings for high contrast mode
    KiGfx::VIEW* view = myframe->GetGalCanvas()->GetView();
    view->GetPainter()->GetSettings()->SetActiveLayer( aLayer );
    view->UpdateAllLayersColor();
    view->SetTopLayer( aLayer );

    if( m_alwaysShowActiveCopperLayer )
    if( m_alwaysShowActiveCopperLayer )
        OnLayerSelected();
        OnLayerSelected();
    else if( DisplayOpt.ContrastModeDisplay )
    else if( DisplayOpt.ContrastModeDisplay )
    {
        if( myframe->IsGalCanvasActive() )
            myframe->GetGalCanvas()->Refresh();
        else
        myframe->GetCanvas()->Refresh();
        myframe->GetCanvas()->Refresh();
    }


    return true;
    return true;
}
}
Loading