Commit db74de74 authored by Maciej Suminski's avatar Maciej Suminski

Added possibility to change cached layer color (for the purpose of high contrast display).

parent 0bac4a1e
......@@ -801,6 +801,24 @@ void CAIRO_GAL::DrawGroup( int aGroupNumber )
}
void CAIRO_GAL::ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor )
{
storePath();
for( Group::iterator it = groups[aGroupNumber].begin();
it != groups[aGroupNumber].end(); ++it )
{
if( it->command == CMD_SET_FILLCOLOR || it->command == CMD_SET_STROKECOLOR )
{
it->arguments[0] = aNewColor.r;
it->arguments[1] = aNewColor.g;
it->arguments[2] = aNewColor.b;
it->arguments[3] = aNewColor.a;
}
}
}
void CAIRO_GAL::Flush()
{
storePath();
......
......@@ -1628,6 +1628,13 @@ void OPENGL_GAL::DrawGroup( int aGroupNumber )
}
void OPENGL_GAL::ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor )
{
vboItems[aGroupNumber]->ChangeColor( aNewColor );
vboNeedsUpdate = true;
}
void OPENGL_GAL::computeUnitCircle()
{
displayListCircle = glGenLists( 1 );
......
......@@ -79,18 +79,17 @@ VBO_VERTEX* VBO_ITEM::GetVertices()
void VBO_ITEM::ChangeColor( const COLOR4D& aColor )
{
wxASSERT_MSG( false, wxT( "This was not tested yet" ) );
if( m_isDirty )
Finish();
// Point to color of vertices
VBO_VERTEX* vertexPtr = GetVertices();
const GLfloat newColor[] = { aColor.r, aColor.g, aColor.b, aColor.a };
for( unsigned int i = 0; i < m_size; ++i )
{
memcpy( &vertexPtr->r, newColor, ColorByteSize );
vertexPtr->r = aColor.r;
vertexPtr->g = aColor.g;
vertexPtr->b = aColor.b;
vertexPtr->a = aColor.a;
// Move on to the next vertex
vertexPtr++;
......
......@@ -307,6 +307,55 @@ void VIEW::SetLayerOrder( int aLayer, int aRenderingOrder )
}
struct VIEW::updateItemsColor
{
updateItemsColor( int aLayer, PAINTER* aPainter, GAL* aGal ) :
layer( aLayer ), painter( aPainter), gal( aGal )
{
}
void operator()( VIEW_ITEM* aItem )
{
// Obtain the color that should be used for coloring the item
const COLOR4D color = painter->GetColor( aItem, layer );
int group = aItem->getGroup( layer );
gal->ChangeGroupColor( group, color );
}
int layer;
PAINTER* painter;
GAL* gal;
};
void VIEW::UpdateLayerColor( int aLayer )
{
BOX2I r;
r.SetMaximum();
updateItemsColor visitor( aLayer, m_painter, m_gal );
m_layers[aLayer].items->Query( r, visitor );
}
void VIEW::UpdateAllLayersColor()
{
BOX2I r;
r.SetMaximum();
for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i )
{
VIEW_LAYER* l = &( ( *i ).second );
updateItemsColor visitor( l->id, m_painter, m_gal );
l->items->Query( r, visitor );
}
}
void VIEW::SetTopLayer( int aLayer )
{
// Restore previous order
......@@ -561,13 +610,13 @@ void VIEW::clearGroupCache()
BOX2I r;
r.SetMaximum();
clearItemCache visitor( this );
for( LayerMapIter i = m_layers.begin(); i != m_layers.end(); ++i )
{
VIEW_LAYER* l = & ( ( *i ).second );
clearItemCache visitor( this );
l->items->Query( r, visitor );
};
}
}
......
......@@ -209,6 +209,9 @@ public:
/// @copydoc GAL::DrawGroup()
virtual void DrawGroup( int aGroupNumber );
/// @copydoc GAL::ChangeGroupColor()
virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor );
/// @copydoc GAL::DeleteGroup()
virtual void DeleteGroup( int aGroupNumber );
......
......@@ -363,6 +363,14 @@ public:
*/
virtual void DrawGroup( int aGroupNumber ) = 0;
/**
* @brief Changes the color used to draw the group.
*
* @param aGroupNumber is the group number.
* @param aNewColor is the new color.
*/
virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) = 0;
/**
* @brief Delete the group from the memory.
*
......
......@@ -234,6 +234,9 @@ public:
/// @copydoc GAL::DrawGroup()
virtual void DrawGroup( int aGroupNumber );
/// @copydoc GAL::ChangeGroupColor()
virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor );
/// @copydoc GAL::DeleteGroup()
virtual void DeleteGroup( int aGroupNumber );
......
......@@ -82,7 +82,7 @@ public:
* (eg. highlighted, so it differs from other layers).
* @param aLayerId is a layer number that should be displayed in a specific mode.
*/
void SetActiveLayer( int aLayerId )
inline void SetActiveLayer( int aLayerId )
{
m_activeLayer = aLayerId;
}
......@@ -94,7 +94,7 @@ public:
* @param aNetCode is optional and if specified, turns on higlighting only for the net with
* number given as the parameter.
*/
void SetHighlight( bool aEnabled, int aNetcode = -1 )
inline void SetHighlight( bool aEnabled, int aNetcode = -1 )
{
m_highlightEnabled = aEnabled;
......@@ -107,7 +107,7 @@ public:
* Turns on/off high contrast display mode.
* @param aEnabled determines if high contrast display mode should be enabled or not.
*/
void SetHighContrast( bool aEnabled )
inline void SetHighContrast( bool aEnabled )
{
m_hiContrastEnabled = aEnabled;
}
......@@ -200,7 +200,7 @@ public:
/**
* Function Draw
* Takes an instance of EDA_ITEM and passes it to a function that know how to draw the item.
* Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the item.
* @param aItem is an item to be drawn.
* @param aLayer tells which layer is currently rendered so that draw functions
* may know what to draw (eg. for pads there are separate layers for holes, because they
......@@ -208,8 +208,17 @@ public:
*/
virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) = 0;
protected:
/**
* Function GetColor
* Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer
* using currently used render settings.
* @param aItem is the VIEW_ITEM.
* @param aLayer is the layer.
* @return The color.
*/
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) = 0;
protected:
/**
* Function getLayerColor
* is used for obtaining color that should be used for specific layer/net
......
......@@ -61,8 +61,8 @@ public:
/**
* Constructor.
* @param aIsDynamic: decides whether we are creating a static or a dynamic VIEW.
* @param aUseGroups: fixme
* @param aIsDynamic decides whether we are creating a static or a dynamic VIEW.
* @param aUseGroups tells if items added to the VIEW should be stored in groups.
*/
VIEW( bool aIsDynamic = true, bool aUseGroups = false );
......@@ -264,6 +264,21 @@ public:
*/
void SetLayerOrder( int aLayer, int aRenderingOrder );
/**
* Function UpdateLayerColor()
* Applies the new coloring scheme held by RENDER_SETTINGS in case that it has changed.
* @param aLayer is a number of the layer to be updated.
* @see RENDER_SETTINGS
*/
void UpdateLayerColor( int aLayer );
/**
* Function UpdateAllLayersColor()
* Applies the new coloring scheme to all layers. The used scheme is held by RENDER_SETTINGS.
* @see RENDER_SETTINGS
*/
void UpdateAllLayersColor();
/**
* Function SetTopLayer()
* Sets given layer to be displayed on the top or sets back the default order of layers.
......@@ -313,7 +328,6 @@ public:
static const int TOP_LAYER; ///* layer number for displaying items on the top
private:
struct VIEW_LAYER
{
bool enabled; ///* is the layer to be rendered?
......@@ -338,6 +352,7 @@ private:
struct unlinkItem;
struct recacheItem;
struct drawItem;
struct updateItemsColor;
///* Saves current top layer settings in order to restore it when it's not top anymore
VIEW_LAYER m_topLayer;
......
......@@ -161,6 +161,12 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
{
int id = event.GetId();
bool state = event.IsChecked();
#ifdef KICAD_GAL
KiGfx::PCB_PAINTER* painter =
static_cast<KiGfx::PCB_PAINTER*> ( m_galCanvas->GetView()->GetPainter() );
KiGfx::PCB_RENDER_SETTINGS* settings =
static_cast<KiGfx::PCB_RENDER_SETTINGS*> ( painter->GetSettings() );
#endif /* KICAD_GAL */
switch( id )
{
......@@ -221,7 +227,12 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
case ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE:
DisplayOpt.ContrastModeDisplay = state;
#ifdef KICAD_GAL
// Apply new display options to the GAL canvas
settings->LoadDisplayOptions( DisplayOpt );
m_galCanvas->GetView()->EnableTopLayer( state );
m_galCanvas->GetView()->UpdateAllLayersColor();
if( !IsGalCanvasActive() )
#endif /* KICAD_GAL */
m_canvas->Refresh();
break;
......@@ -250,16 +261,7 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
}
#ifdef KICAD_GAL
// Apply new display options to the GAL canvas
KiGfx::PCB_PAINTER* painter =
static_cast<KiGfx::PCB_PAINTER*> ( m_galCanvas->GetView()->GetPainter() );
KiGfx::PCB_RENDER_SETTINGS* settings =
static_cast<KiGfx::PCB_RENDER_SETTINGS*> ( painter->GetSettings() );
settings->LoadDisplayOptions( DisplayOpt );
if( IsGalCanvasActive() )
{
m_galCanvas->Refresh();
}
#endif
#endif /* KICAD_GAL */
}
......@@ -117,6 +117,19 @@ PCB_PAINTER::PCB_PAINTER( GAL* aGal ) :
}
const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer )
{
int netCode = 0;
// Try to obtain the netcode for the item
const BOARD_CONNECTED_ITEM* item = dynamic_cast<const BOARD_CONNECTED_ITEM*>( aItem );
if( item )
netCode = item->GetNet();
return getLayerColor( aLayer, netCode );
}
const COLOR4D& PCB_PAINTER::getLayerColor( int aLayer, int aNetCode ) const
{
if( m_pcbSettings->m_hiContrastEnabled && m_pcbSettings->m_activeLayer != aLayer )
......@@ -211,7 +224,7 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
break;
default:
// Painter does not knowNetwork: how to draw the object
// Painter does not know how to draw the object
return false;
break;
}
......
......@@ -126,8 +126,10 @@ public:
m_pcbSettings = dynamic_cast<PCB_RENDER_SETTINGS*> ( aSettings );
}
protected:
/// @copydoc PAINTER::GetColor()
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer );
protected:
PCB_RENDER_SETTINGS* m_pcbSettings;
/// @copydoc PAINTER::getLayerColor()
......
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