Added brightened mode for selecting items using disambiguation menu.

This commit is contained in:
Maciej Suminski 2013-08-08 12:30:00 +02:00
parent cc5c038362
commit 402f3c6f2c
5 changed files with 68 additions and 33 deletions

View File

@ -25,14 +25,13 @@
*/ */
#include <painter.h> #include <painter.h>
#include <gal/graphics_abstraction_layer.h>
using namespace KiGfx; using namespace KiGfx;
RENDER_SETTINGS::RENDER_SETTINGS() RENDER_SETTINGS::RENDER_SETTINGS()
{ {
// Set the default initial values // Set the default initial values
m_selectionBorderColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 );
m_highlightFactor = 0.5; m_highlightFactor = 0.5;
m_selectFactor = 0.5; m_selectFactor = 0.5;
m_layerOpacity = 0.8; m_layerOpacity = 0.8;
@ -65,7 +64,7 @@ void RENDER_SETTINGS::update()
PAINTER::PAINTER( GAL* aGal ) : 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; 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 );
}

View File

@ -509,16 +509,21 @@ struct VIEW::drawItem
{ {
group = gal->BeginGroup(); group = gal->BeginGroup();
aItem->setGroup( currentLayer->id, group ); aItem->setGroup( currentLayer->id, group );
if(!view->m_painter->Draw( aItem, currentLayer->id )) if( !view->m_painter->Draw( aItem, currentLayer->id ) )
aItem->ViewDraw(currentLayer->id, gal, BOX2I()); aItem->ViewDraw( currentLayer->id, gal, BOX2I() ); // Alternative drawing method
gal->EndGroup(); gal->EndGroup();
} }
} }
else else
{ {
// Immediate mode // Immediate mode
if(!view->m_painter->Draw( aItem, currentLayer->id )) if( !view->m_painter->Draw( aItem, currentLayer->id ) )
aItem->ViewDraw(currentLayer->id, gal, BOX2I()); aItem->ViewDraw( currentLayer->id, gal, BOX2I() ); // Alternative drawing method
}
if( static_cast<const EDA_ITEM*>( aItem )->IsBrightened() )
{
view->m_painter->DrawBrightened( aItem );
} }
} }

View File

@ -472,13 +472,13 @@ public:
inline bool IsHighlighted() const { return m_Flags & HIGHLIGHTED; } inline bool IsHighlighted() const { return m_Flags & HIGHLIGHTED; }
inline bool IsBrightened() const { return m_Flags & BRIGHTENED; } inline bool IsBrightened() const { return m_Flags & BRIGHTENED; }
inline void SetBrightened() { SetFlags( BRIGHTENED ); ViewUpdate( APPEARANCE ); }
inline void SetSelected() { SetFlags( SELECTED ); 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 ClearSelected() { ClearFlags( SELECTED ); ViewUpdate( APPEARANCE ); }
inline void ClearHighlighted() { ClearFlags( HIGHLIGHTED ); 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(); void SetModified();

View File

@ -55,7 +55,6 @@ class VIEW_ITEM;
class RENDER_SETTINGS class RENDER_SETTINGS
{ {
public: public:
RENDER_SETTINGS(); RENDER_SETTINGS();
virtual ~RENDER_SETTINGS(); virtual ~RENDER_SETTINGS();
@ -125,21 +124,19 @@ protected:
std::set<unsigned int> m_activeLayers; /// Stores active layers number std::set<unsigned int> m_activeLayers; /// Stores active layers number
/// Parameters for display modes /// Parameters for display modes
bool m_hiContrastEnabled; /// High contrast display mode on/off bool m_hiContrastEnabled; ///< High contrast display mode on/off
COLOR4D m_hiContrastColor; /// Color used for high contrast display mode COLOR4D m_hiContrastColor; ///< Color used for high contrast display mode
float m_hiContrastFactor; /// Factor used for computing high contrast color float m_hiContrastFactor; ///< Factor used for computing high contrast color
bool m_highlightEnabled; /// Highlight display mode on/off bool m_highlightEnabled; ///< Highlight display mode on/off
int m_highlightNetcode; /// Net number that is displayed in highlight int m_highlightNetcode; ///< Net number that is displayed in highlight
/// -1 means that there is no specific net, and whole active ///< -1 means that there is no specific net, and whole active
/// layer is highlighted ///< layer is highlighted
float m_highlightFactor; /// Factor used for computing hightlight color 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_selectFactor; /// Specifies how color of selected items is changed float m_outlineWidth; ///< Line width used when drawing outlines
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 /// Map of colors that were usually used for display
std::map<EDA_COLOR_T, COLOR4D> m_legacyColorMap; std::map<EDA_COLOR_T, COLOR4D> m_legacyColorMap;
@ -161,7 +158,6 @@ protected:
class PAINTER class PAINTER
{ {
public: public:
/* /*
* Constructor PAINTER( GAL* ) * Constructor PAINTER( GAL* )
* initializes this object for painting on any of the polymorphic * 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; 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 * Function GetColor
* Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer * 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. /// Colors and display modes settings that are going to be used when drawing items.
RENDER_SETTINGS* m_settings; RENDER_SETTINGS* m_settings;
/// Color of brightened item frame
COLOR4D m_brightenedColor;
}; };
} // namespace KiGfx } // namespace KiGfx

View File

@ -89,10 +89,12 @@ void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem, bool aAdditive )
{ {
aItem->ClearSelected(); aItem->ClearSelected();
m_selectedItems.erase( aItem ); m_selectedItems.erase( aItem );
} else }
else
{ {
if( !aAdditive ) if( !aAdditive )
clearSelection(); clearSelection();
aItem->SetSelected(); aItem->SetSelected();
m_selectedItems.insert( aItem ); m_selectedItems.insert( aItem );
} }
@ -237,19 +239,20 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR *aCollector )
if( evt->Action() == TA_ContextMenuUpdate ) if( evt->Action() == TA_ContextMenuUpdate )
{ {
if( current ) if( current )
current->ClearSelected(); current->ClearBrightened();
int id = *evt->GetCommandId(); int id = *evt->GetCommandId();
if( id >= 0 ) if( id >= 0 )
{ {
current = ( *aCollector )[id]; current = ( *aCollector )[id];
current->SetSelected(); current->SetBrightened();
} else }
else
current = NULL; current = NULL;
}
} else if( evt->Action() == TA_ContextMenuChoice ) else if( evt->Action() == TA_ContextMenuChoice )
{ {
optional<int> id = evt->GetCommandId(); optional<int> id = evt->GetCommandId();
if( current ) if( current )
@ -261,9 +264,9 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR *aCollector )
current->SetSelected(); current->SetSelected();
return current; return current;
} }
return NULL; return NULL;
} }
} }
return NULL; return NULL;