Commit cbec733d authored by Maciej Suminski's avatar Maciej Suminski

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
......@@ -39,11 +39,6 @@
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 )
{
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 ) :
m_enableTopLayer( false ),
m_enableOrderModifier( false ),
m_scale ( 1.0 ),
m_painter( NULL ),
m_gal( NULL ),
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 )
if( aEnabled )
{
m_layers[m_topLayer.id].renderingOrder = m_topLayer.renderingOrder;
ChangeLayerDepth( m_topLayer.id, m_topLayer.renderingOrder );
}
if( m_topLayers.count( aLayer ) == 1 )
return;
if( aLayer >= 0 && aLayer < VIEW_MAX_LAYERS )
m_topLayers.insert( aLayer );
// Move the layer closer to front
if( m_enableOrderModifier )
m_layers[aLayer].renderingOrder += TOP_LAYER_MODIFIER;
}
else
{
// Save settings, so it can be restored later
m_topLayer.renderingOrder = m_layers[aLayer].renderingOrder;
m_topLayer.id = m_layers[aLayer].id;
if( m_topLayers.count( aLayer ) == 0 )
return;
// Apply new settings only if the option is enabled
if( m_enableTopLayer )
{
m_layers[aLayer].renderingOrder = TOP_LAYER;
ChangeLayerDepth( aLayer, TOP_LAYER );
}
m_topLayers.erase( aLayer );
// Set the flag saying that settings stored in m_topLayer are valid
m_topLayer.enabled = true;
// Restore the previous rendering order
if( m_enableOrderModifier )
m_layers[aLayer].renderingOrder -= TOP_LAYER_MODIFIER;
}
}
void VIEW::EnableTopLayer( bool aEnable )
{
if( aEnable == m_enableOrderModifier ) return;
m_enableOrderModifier = aEnable;
std::set<unsigned int>::iterator it;
if( aEnable )
{
for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
m_layers[*it].renderingOrder += TOP_LAYER_MODIFIER;
}
else
{
// There are no valid settings in m_topLayer
m_topLayer.enabled = false;
for( it = m_topLayers.begin(); it != m_topLayers.end(); ++it )
m_layers[*it].renderingOrder -= TOP_LAYER_MODIFIER;
}
sortLayers();
}
void VIEW::EnableTopLayer( bool aEnable )
void VIEW::ClearTopLayers()
{
if( aEnable == m_enableTopLayer ) return;
std::set<unsigned int>::iterator it;
// Use stored settings only if applicable
// (topLayer.enabled == false means there are no valid settings stored)
if( m_topLayer.enabled )
if( m_enableOrderModifier )
{
if( aEnable )
{
m_layers[m_topLayer.id].renderingOrder = TOP_LAYER;
ChangeLayerDepth( m_topLayer.id, TOP_LAYER );
}
else
{
m_layers[m_topLayer.id].renderingOrder = m_topLayer.renderingOrder;
ChangeLayerDepth( m_topLayer.id, m_topLayer.renderingOrder );
}
// 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();
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 );
m_gal->SetLayerDepth( static_cast<double>( l->renderingOrder ) );
m_gal->SetLayerDepth( l->renderingOrder );
l->items->Query( aRect, drawFunc );
l->isDirty = false;
}
......@@ -703,7 +708,7 @@ void VIEW::RecacheAllItems( bool aImmediately )
if( l->cached )
{
m_gal->SetLayerDepth( (double) l->renderingOrder );
m_gal->SetLayerDepth( l->renderingOrder );
recacheLayer visitor( this, m_gal, l->id, aImmediately );
l->items->Query( r, visitor );
}
......
......@@ -26,6 +26,7 @@
#define __VIEW_H
#include <vector>
#include <set>
#include <boost/unordered/unordered_map.hpp>
#include <math/box2.h>
......@@ -305,7 +306,7 @@ public:
* @param aLayer: the layer or -1 in case when no particular layer should
* be displayed on the top.
*/
void SetTopLayer( int aLayer );
void SetTopLayer( int aLayer, bool aEnabled = true );
/**
* Function EnableTopLayer()
......@@ -316,6 +317,20 @@ public:
*/
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()
* Immediately redraws the whole view.
......@@ -344,8 +359,7 @@ public:
*/
bool IsDynamic() const { return m_dynamic; }
static const int VIEW_MAX_LAYERS; ///* maximum number of layers that may be shown
static const int TOP_LAYER; ///* layer number for displaying items on the top
static const int VIEW_MAX_LAYERS = 64; ///* maximum number of layers that may be shown
private:
struct VIEW_LAYER
......@@ -377,11 +391,8 @@ private:
struct updateItemsColor;
struct changeItemsDepth;
///* Saves current top layer settings in order to restore it when it's not top anymore
VIEW_LAYER m_topLayer;
///* Whether to use top layer settings or not
bool m_enableTopLayer;
///* Whether to use rendering order modifier or not
bool m_enableOrderModifier;
///* Redraws contents within rect aRect
void redrawRect( const BOX2I& aRect );
......@@ -412,6 +423,9 @@ private:
/// Sorted list of pointers to members of m_layers.
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)
VECTOR2D m_center;
......@@ -427,6 +441,9 @@ private:
/// Dynamic VIEW (eg. display PCB in window) allows changes once it is built,
/// static (eg. image/PDF) - does not.
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
......
......@@ -133,13 +133,7 @@ protected:
* will change the currently active layer to \a aLayer and also
* update the PCB_LAYER_WIDGET.
*/
void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true )
{
( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;
if( doLayerWidgetUpdate )
syncLayerWidgetLayer();
}
void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true );
/**
* Function getActiveLayer
......
......@@ -258,13 +258,9 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
view->SetLayerVisible( ITEM_GAL_LAYER( i ), m_Pcb->IsElementVisible( i ) );
}
view->SetTopLayer( m_Pcb->GetLayer() );
view->RecacheAllItems( true );
if( m_galCanvasActive )
{
m_galCanvas->Refresh();
}
}
}
......
......@@ -356,21 +356,10 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( LAYER_NUM aLayer )
// false from this function.
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 )
OnLayerSelected();
else if(DisplayOpt.ContrastModeDisplay)
{
if( myframe->IsGalCanvasActive() )
myframe->GetGalCanvas()->Refresh();
else
myframe->GetCanvas()->Refresh();
}
else if( DisplayOpt.ContrastModeDisplay )
myframe->GetCanvas()->Refresh();
return true;
}
......
......@@ -232,16 +232,27 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
break;
case ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE:
{
DisplayOpt.ContrastModeDisplay = state;
// Apply new display options to the GAL canvas (this is faster than recaching)
settings->LoadDisplayOptions( DisplayOpt );
m_galCanvas->GetView()->EnableTopLayer( state );
m_galCanvas->GetView()->UpdateAllLayersColor();
KiGfx::VIEW* view = m_galCanvas->GetView();
LAYER_NUM layer = getActiveLayer();
view->GetPainter()->GetSettings()->SetActiveLayer( layer );
view->UpdateAllLayersColor();
view->EnableTopLayer( state );
view->ClearTopLayers();
view->SetTopLayer( layer );
view->UpdateAllLayersOrder();
if( !IsGalCanvasActive() )
m_canvas->Refresh();
break;
}
case ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE:
m_show_microwave_tools = state;
......
......@@ -56,6 +56,8 @@
#include <dialog_helpers.h>
#include <dialog_plot.h>
#include <convert_from_iu.h>
#include <view/view.h>
#include <painter.h>
#if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
......@@ -741,6 +743,31 @@ bool PCB_EDIT_FRAME::IsMicroViaAcceptable( void )
}
void PCB_EDIT_FRAME::setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate )
{
( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;
// Set display settings for high contrast mode
KiGfx::VIEW* view = m_galCanvas->GetView();
if( DisplayOpt.ContrastModeDisplay )
{
view->GetPainter()->GetSettings()->SetActiveLayer( aLayer );
view->UpdateAllLayersColor();
view->ClearTopLayers();
view->SetTopLayer( aLayer );
view->UpdateAllLayersOrder();
if( m_galCanvasActive )
m_galCanvas->Refresh();
}
if( doLayerWidgetUpdate )
syncLayerWidgetLayer();
}
void PCB_EDIT_FRAME::syncLayerWidgetLayer()
{
m_Layers->SelectLayer( getActiveLayer() );
......
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