From 603029b1061b9d1c9c159d7aaa20baf8609525fc Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 26 Jun 2013 16:31:52 +0200 Subject: [PATCH] High contrast mode with showing the selected layer on the top. --- common/gal/cairo/cairo_gal.cpp | 7 ++++ common/gal/opengl/opengl_gal.cpp | 7 ++++ common/gal/opengl/vbo_item.cpp | 14 +++++++ common/view/view.cpp | 49 ++++++++++++++++++++++-- include/gal/cairo/cairo_gal.h | 3 ++ include/gal/graphics_abstraction_layer.h | 8 ++++ include/gal/opengl/opengl_gal.h | 3 ++ include/gal/opengl/vbo_item.h | 7 ++++ include/view/view.h | 15 ++++++-- pcbnew/class_pcb_layer_widget.cpp | 1 + 10 files changed, 107 insertions(+), 7 deletions(-) diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 4bc1d59c87..6e30bea899 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -819,6 +819,13 @@ void CAIRO_GAL::ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) } +void CAIRO_GAL::ChangeGroupDepth( int aGroupNumber, int aDepth ) +{ + // Cairo does not have any possibilities to change the depth coordinate of stored items, + // it depends only on the order of drawing +} + + void CAIRO_GAL::Flush() { storePath(); diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 69944a5daf..951f57e586 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -1635,6 +1635,13 @@ void OPENGL_GAL::ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) } +void OPENGL_GAL::ChangeGroupDepth( int aGroupNumber, int aDepth ) +{ + vboItems[aGroupNumber]->ChangeDepth( aDepth ); + vboNeedsUpdate = true; +} + + void OPENGL_GAL::computeUnitCircle() { displayListCircle = glGenLists( 1 ); diff --git a/common/gal/opengl/vbo_item.cpp b/common/gal/opengl/vbo_item.cpp index ba68c1abb0..a10a75a675 100644 --- a/common/gal/opengl/vbo_item.cpp +++ b/common/gal/opengl/vbo_item.cpp @@ -94,6 +94,20 @@ void VBO_ITEM::ChangeColor( const COLOR4D& aColor ) } +void VBO_ITEM::ChangeDepth( int aDepth ) +{ + VBO_VERTEX* vertexPtr = GetVertices(); + + for( unsigned int i = 0; i < m_size; ++i ) + { + vertexPtr->z = aDepth; + + // Move on to the next vertex + vertexPtr++; + } +} + + void VBO_ITEM::Finish() { // The unknown-sized item has just ended, so we need to inform the container about it diff --git a/common/view/view.cpp b/common/view/view.cpp index 07114f8eaa..91c216137a 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -40,8 +40,9 @@ using namespace KiGfx; // Static constants -const unsigned int VIEW::VIEW_MAX_LAYERS = 64; -const int VIEW::TOP_LAYER = -1; +const int VIEW::VIEW_MAX_LAYERS = 64; +// Top layer depth +const int VIEW::TOP_LAYER = -1; void VIEW::AddLayer( int aLayer, bool aDisplayOnly ) { @@ -303,6 +304,7 @@ void VIEW::sortLayers() void VIEW::SetLayerOrder( int aLayer, int aRenderingOrder ) { m_layers[aLayer].renderingOrder = aRenderingOrder; + sortLayers(); } @@ -319,6 +321,7 @@ struct VIEW::updateItemsColor // Obtain the color that should be used for coloring the item const COLOR4D color = painter->GetColor( aItem, layer ); int group = aItem->getGroup( layer ); + wxASSERT( group >= 0 ); gal->ChangeGroupColor( group, color ); } @@ -356,11 +359,45 @@ void VIEW::UpdateAllLayersColor() } +struct VIEW::changeItemsDepth +{ + changeItemsDepth( int aLayer, int aDepth, GAL* aGal ) : + layer( aLayer ), depth( aDepth ), gal( aGal ) + { + } + + void operator()( VIEW_ITEM* aItem ) + { + int group = aItem->getGroup( layer ); + + if( group >= 0 ) + gal->ChangeGroupDepth( group, depth ); + } + + int layer, depth; + GAL* gal; +}; + + +void VIEW::ChangeLayerDepth( int aLayer, int aDepth ) +{ + BOX2I r; + + r.SetMaximum(); + + changeItemsDepth visitor( aLayer, aDepth, m_gal ); + m_layers[aLayer].items->Query( r, visitor ); +} + + void VIEW::SetTopLayer( int aLayer ) { // Restore previous order if( m_topLayer.enabled ) + { m_layers[m_topLayer.id].renderingOrder = m_topLayer.renderingOrder; + ChangeLayerDepth( m_topLayer.id, m_topLayer.renderingOrder ); + } if( aLayer >= 0 && aLayer < VIEW_MAX_LAYERS ) { @@ -370,7 +407,10 @@ void VIEW::SetTopLayer( int aLayer ) // Apply new settings only if the option is enabled 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 m_topLayer.enabled = true; @@ -396,12 +436,15 @@ void VIEW::EnableTopLayer( bool aEnable ) 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 ); } } + sortLayers(); m_enableTopLayer = aEnable; } @@ -416,7 +459,7 @@ struct VIEW::drawItem void operator()( VIEW_ITEM* aItem ) { - GAL* gal = view->GetGAL(); + GAL* gal = view->GetGAL(); if( view->m_useGroups ) { diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index 0af3c173fd..cd8cdf5525 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -212,6 +212,9 @@ public: /// @copydoc GAL::ChangeGroupColor() virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ); + /// @copydoc GAL::ChangeGroupDepth() + virtual void ChangeGroupDepth( int aGroupNumber, int aDepth ); + /// @copydoc GAL::DeleteGroup() virtual void DeleteGroup( int aGroupNumber ); diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 8a8cbb2036..0411c699b8 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -371,6 +371,14 @@ public: */ virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) = 0; + /** + * @brief Changes the depth (Z-axis position) of the group. + * + * @param aGroupNumber is the group number. + * @param aDepth is the new depth. + */ + virtual void ChangeGroupDepth( int aGroupNumber, int aDepth ) = 0; + /** * @brief Delete the group from the memory. * diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 9db405d7a5..1dfc6f9cc8 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -237,6 +237,9 @@ public: /// @copydoc GAL::ChangeGroupColor() virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ); + /// @copydoc GAL::ChangeGroupDepth() + virtual void ChangeGroupDepth( int aGroupNumber, int aDepth ); + /// @copydoc GAL::DeleteGroup() virtual void DeleteGroup( int aGroupNumber ); diff --git a/include/gal/opengl/vbo_item.h b/include/gal/opengl/vbo_item.h index e0e6edc8f1..865eb88466 100644 --- a/include/gal/opengl/vbo_item.h +++ b/include/gal/opengl/vbo_item.h @@ -116,6 +116,13 @@ public: */ void ChangeColor( const COLOR4D& aColor ); + /** + * Function ChangeDepth() + * Moves all vertices to the specified depth. + * @param aDepth is the new depth for vertices. + */ + void ChangeDepth( int aDepth ); + ///< Informs the container that there will be no more vertices for the current VBO_ITEM void Finish(); diff --git a/include/view/view.h b/include/view/view.h index 9577537dda..9ebc3d09c6 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -215,7 +215,6 @@ public: */ double ToScreen( double aCoord, bool aAbsolute = true ) const; - /** * Function GetScreenPixelSize() * Returns the size of the our rendering area, in pixels. @@ -232,7 +231,6 @@ public: */ void AddLayer( int aLayer, bool aDisplayOnly = false ); - /** * Function ClearLayer() * Removes all items from a given layer. @@ -279,6 +277,14 @@ public: */ void UpdateAllLayersColor(); + /** + * Function ChangeLayerDepth() + * Changes the depth of items on the given layer. + * @param aLayer is a number of the layer to be updated. + * @param aDepth is the new depth. + */ + void ChangeLayerDepth( int aLayer, int aDepth ); + /** * Function SetTopLayer() * Sets given layer to be displayed on the top or sets back the default order of layers. @@ -324,8 +330,8 @@ public: */ bool IsDynamic() const { return m_dynamic; } - static const unsigned 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; ///* maximum number of layers that may be shown + static const int TOP_LAYER; ///* layer number for displaying items on the top private: struct VIEW_LAYER @@ -353,6 +359,7 @@ private: struct recacheItem; struct drawItem; struct updateItemsColor; + struct changeItemsDepth; ///* Saves current top layer settings in order to restore it when it's not top anymore VIEW_LAYER m_topLayer; diff --git a/pcbnew/class_pcb_layer_widget.cpp b/pcbnew/class_pcb_layer_widget.cpp index 668a7efc34..d928e0ee76 100644 --- a/pcbnew/class_pcb_layer_widget.cpp +++ b/pcbnew/class_pcb_layer_widget.cpp @@ -361,6 +361,7 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( LAYER_NUM aLayer ) // Set display settings for high contrast mode KiGfx::VIEW* view = myframe->GetGalCanvas()->GetView(); view->GetPainter()->GetSettings()->SetActiveLayer( aLayer ); + view->UpdateAllLayersColor(); view->SetTopLayer( aLayer ); #endif /* KICAD_GAL */