Commit 402f3c6f authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Added brightened mode for selecting items using disambiguation menu.

parent cc5c0383
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -25,14 +25,13 @@
 */

#include <painter.h>
#include <gal/graphics_abstraction_layer.h>

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 );
}
+9 −4
Original line number Diff line number Diff line
@@ -510,7 +510,7 @@ 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());
                    aItem->ViewDraw( currentLayer->id, gal, BOX2I() ); // Alternative drawing method
                gal->EndGroup();
            }
        }
@@ -518,7 +518,12 @@ struct VIEW::drawItem
        {
            // Immediate mode
            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 );
        }
    }

+3 −3
Original line number Diff line number Diff line
@@ -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();

+21 −15
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ class VIEW_ITEM;
class RENDER_SETTINGS
{
public:

    RENDER_SETTINGS();
    virtual ~RENDER_SETTINGS();

@@ -125,21 +124,19 @@ protected:
    std::set<unsigned int> 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_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_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

    COLOR4D m_selectionBorderColor; /// Color of selection box border
    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

    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<EDA_COLOR_T, COLOR4D> 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

+11 −8
Original line number Diff line number Diff line
@@ -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<int> 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;