From 402f3c6f2ca578dd702915b077ea29dcd8f6c6e4 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 8 Aug 2013 12:30:00 +0200 Subject: [PATCH] Added brightened mode for selecting items using disambiguation menu. --- common/painter.cpp | 27 ++++++++++++++++++++++--- common/view/view.cpp | 13 ++++++++---- include/base_struct.h | 6 +++--- include/painter.h | 36 +++++++++++++++++++-------------- pcbnew/tools/selection_tool.cpp | 19 +++++++++-------- 5 files changed, 68 insertions(+), 33 deletions(-) diff --git a/common/painter.cpp b/common/painter.cpp index 799fdc39e8..5787b5427c 100644 --- a/common/painter.cpp +++ b/common/painter.cpp @@ -25,14 +25,13 @@ */ #include +#include using namespace KiGfx; RENDER_SETTINGS::RENDER_SETTINGS() { // Set the default initial values - m_selectionBorderColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 ); - m_highlightFactor = 0.5; m_selectFactor = 0.5; m_layerOpacity = 0.8; @@ -65,7 +64,7 @@ void RENDER_SETTINGS::update() PAINTER::PAINTER( GAL* aGal ) : - m_gal( aGal ), m_settings( NULL ) + m_gal( aGal ), m_settings( NULL ), m_brightenedColor( 0.0, 1.0, 0.0, 0.9 ) { } @@ -80,3 +79,25 @@ void PAINTER::SetGAL( GAL* aGal ) { m_gal = aGal; } + + +void PAINTER::DrawBrightened( const VIEW_ITEM* aItem ) +{ + BOX2I box = aItem->ViewBBox(); + + RenderTarget oldTarget = m_gal->GetTarget(); + m_gal->SetTarget( TARGET_OVERLAY ); + + m_gal->PushDepth(); + m_gal->SetLayerDepth( -1.0 ); + + // Draw semitransparent box that marks items as brightened + m_gal->SetIsStroke( true ); + m_gal->SetLineWidth( 100000.0 ); + m_gal->SetStrokeColor( m_brightenedColor ); + + m_gal->DrawRectangle( box.GetOrigin(), box.GetOrigin() + box.GetSize() ); + m_gal->PopDepth(); + + m_gal->SetTarget( oldTarget ); +} diff --git a/common/view/view.cpp b/common/view/view.cpp index 2c0104f470..85248b04aa 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -509,16 +509,21 @@ struct VIEW::drawItem { group = gal->BeginGroup(); aItem->setGroup( currentLayer->id, group ); - if(!view->m_painter->Draw( aItem, currentLayer->id )) - aItem->ViewDraw(currentLayer->id, gal, BOX2I()); + if( !view->m_painter->Draw( aItem, currentLayer->id ) ) + aItem->ViewDraw( currentLayer->id, gal, BOX2I() ); // Alternative drawing method gal->EndGroup(); } } else { // Immediate mode - if(!view->m_painter->Draw( aItem, currentLayer->id )) - aItem->ViewDraw(currentLayer->id, gal, BOX2I()); + if( !view->m_painter->Draw( aItem, currentLayer->id ) ) + aItem->ViewDraw( currentLayer->id, gal, BOX2I() ); // Alternative drawing method + } + + if( static_cast( aItem )->IsBrightened() ) + { + view->m_painter->DrawBrightened( aItem ); } } diff --git a/include/base_struct.h b/include/base_struct.h index 30ef9d3c66..67e427eae6 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -472,13 +472,13 @@ public: inline bool IsHighlighted() const { return m_Flags & HIGHLIGHTED; } inline bool IsBrightened() const { return m_Flags & BRIGHTENED; } - inline void SetBrightened() { SetFlags( BRIGHTENED ); ViewUpdate( APPEARANCE ); } inline void SetSelected() { SetFlags( SELECTED ); ViewUpdate( APPEARANCE ); } - inline void SetHighlighted() { SetFlags( HIGHLIGHTED ); ViewUpdate( APPEARANCE | GEOMETRY ); } + inline void SetHighlighted() { SetFlags( HIGHLIGHTED ); ViewUpdate( APPEARANCE ); } + inline void SetBrightened() { SetFlags( BRIGHTENED ); ViewUpdate( APPEARANCE ); } inline void ClearSelected() { ClearFlags( SELECTED ); ViewUpdate( APPEARANCE ); } inline void ClearHighlighted() { ClearFlags( HIGHLIGHTED ); ViewUpdate( APPEARANCE ); } - inline void ClearBrightened() { ClearFlags( BRIGHTENED ); ViewUpdate( APPEARANCE | GEOMETRY ); } + inline void ClearBrightened() { ClearFlags( BRIGHTENED ); ViewUpdate( APPEARANCE ); } void SetModified(); diff --git a/include/painter.h b/include/painter.h index 8ab5c22b30..d546981369 100644 --- a/include/painter.h +++ b/include/painter.h @@ -55,7 +55,6 @@ class VIEW_ITEM; class RENDER_SETTINGS { public: - RENDER_SETTINGS(); virtual ~RENDER_SETTINGS(); @@ -125,21 +124,19 @@ protected: std::set m_activeLayers; /// Stores active layers number /// Parameters for display modes - bool m_hiContrastEnabled; /// High contrast display mode on/off - COLOR4D m_hiContrastColor; /// Color used for high contrast display mode - float m_hiContrastFactor; /// Factor used for computing high contrast color + bool m_hiContrastEnabled; ///< High contrast display mode on/off + COLOR4D m_hiContrastColor; ///< Color used for high contrast display mode + float m_hiContrastFactor; ///< Factor used for computing high contrast color - bool m_highlightEnabled; /// Highlight display mode on/off - int m_highlightNetcode; /// Net number that is displayed in highlight - /// -1 means that there is no specific net, and whole active - /// layer is highlighted - float m_highlightFactor; /// Factor used for computing hightlight color + bool m_highlightEnabled; ///< Highlight display mode on/off + int m_highlightNetcode; ///< Net number that is displayed in highlight + ///< -1 means that there is no specific net, and whole active + ///< layer is highlighted + float m_highlightFactor; ///< Factor used for computing hightlight color - COLOR4D m_selectionBorderColor; /// Color of selection box border - - float m_selectFactor; /// Specifies how color of selected items is changed - float m_layerOpacity; /// Determines opacity of all layers - float m_outlineWidth; /// Line width used when drawing outlines + float m_selectFactor; ///< Specifies how color of selected items is changed + float m_layerOpacity; ///< Determines opacity of all layers + float m_outlineWidth; ///< Line width used when drawing outlines /// Map of colors that were usually used for display std::map m_legacyColorMap; @@ -161,7 +158,6 @@ protected: class PAINTER { public: - /* * Constructor PAINTER( GAL* ) * initializes this object for painting on any of the polymorphic @@ -214,6 +210,13 @@ public: */ virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) = 0; + /** + * Function DrawBrightened + * Draws a special marking for the item. + * @param aItem is the item that is going to be marked. + */ + virtual void DrawBrightened( const VIEW_ITEM* aItem ); + /** * Function GetColor * Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer @@ -231,6 +234,9 @@ protected: /// Colors and display modes settings that are going to be used when drawing items. RENDER_SETTINGS* m_settings; + + /// Color of brightened item frame + COLOR4D m_brightenedColor; }; } // namespace KiGfx diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 19d25b95e4..97e6c1200a 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -89,10 +89,12 @@ void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem, bool aAdditive ) { aItem->ClearSelected(); m_selectedItems.erase( aItem ); - } else + } + else { if( !aAdditive ) clearSelection(); + aItem->SetSelected(); m_selectedItems.insert( aItem ); } @@ -237,19 +239,20 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR *aCollector ) if( evt->Action() == TA_ContextMenuUpdate ) { if( current ) - current->ClearSelected(); + current->ClearBrightened(); int id = *evt->GetCommandId(); + if( id >= 0 ) { current = ( *aCollector )[id]; - current->SetSelected(); - } else + current->SetBrightened(); + } + else current = NULL; - - } else if( evt->Action() == TA_ContextMenuChoice ) + } + else if( evt->Action() == TA_ContextMenuChoice ) { - optional id = evt->GetCommandId(); if( current ) @@ -261,9 +264,9 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR *aCollector ) current->SetSelected(); return current; } + return NULL; } - } return NULL;