From c9199ea80a11a90b26e03b185f6c904a9c46df7a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 25 Jul 2013 18:04:15 +0200 Subject: [PATCH] Fixed high contrast mode in OpenGL. Split display settings loading into more appropriate places. --- common/gal/opengl/gpu_manager.cpp | 2 +- common/gal/opengl/vertex_manager.cpp | 12 +++-- include/gal/opengl/vertex_container.h | 12 ++++- pcbnew/basepcbframe.cpp | 69 ++++++++++++--------------- pcbnew/initpcb.cpp | 8 +++- pcbnew/pcbframe.cpp | 13 ++++- 6 files changed, 69 insertions(+), 47 deletions(-) diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index 04341ed0d4..ffb12b342b 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -111,7 +111,7 @@ void GPU_CACHED_MANAGER::BeginDrawing() { wxASSERT( !m_isDrawing ); - if( m_container->isDirty() ) + if( m_container->IsDirty() ) uploadToGpu(); // Number of vertices to be drawn in the EndDrawing() diff --git a/common/gal/opengl/vertex_manager.cpp b/common/gal/opengl/vertex_manager.cpp index d3b9e00f66..7ffdd74922 100644 --- a/common/gal/opengl/vertex_manager.cpp +++ b/common/gal/opengl/vertex_manager.cpp @@ -101,12 +101,14 @@ void VERTEX_MANAGER::ChangeItemColor( const VERTEX_ITEM& aItem, const COLOR4D& a VERTEX* vertex = m_container->GetVertices( offset ); for( unsigned int i = 0; i < size; ++i ) { - vertex->r = aColor.r; - vertex->g = aColor.g; - vertex->b = aColor.b; - vertex->a = aColor.a; + vertex->r = aColor.r * 255.0; + vertex->g = aColor.g * 255.0; + vertex->b = aColor.b * 255.0; + vertex->a = aColor.a * 255.0; vertex++; } + + m_container->SetDirty(); } @@ -121,6 +123,8 @@ void VERTEX_MANAGER::ChangeItemDepth( const VERTEX_ITEM& aItem, GLfloat aDepth ) vertex->z = aDepth; vertex++; } + + m_container->SetDirty(); } diff --git a/include/gal/opengl/vertex_container.h b/include/gal/opengl/vertex_container.h index 3cf544c473..efca90b2f8 100644 --- a/include/gal/opengl/vertex_container.h +++ b/include/gal/opengl/vertex_container.h @@ -111,7 +111,7 @@ public: * returns information about container cache state. Clears the flag after calling the function. * @return true in case the vertices have to be reuploaded. */ - inline bool isDirty() + inline bool IsDirty() { bool state = m_dirty; @@ -120,6 +120,16 @@ public: return state; } + /** + * Function SetDirty() + * sets the dirty flag, so vertices in the container are going to be reuploaded to the GPU on + * the next frame. + */ + inline void SetDirty() + { + m_dirty = true; + } + protected: VERTEX_CONTAINER( unsigned int aSize = defaultInitSize ); diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index cc21eaf0cf..9580ea9e6c 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -182,45 +182,6 @@ void PCB_BASE_FRAME::SetBoard( BOARD* aBoard ) view->Add( zone ); } - // Apply layer coloring scheme & display options - if( view->GetPainter() ) - { - KiGfx::PCB_RENDER_SETTINGS* settings = new KiGfx::PCB_RENDER_SETTINGS(); - - // Load layers' colors from PCB data - settings->ImportLegacyColors( m_Pcb->GetColorsSettings() ); - view->GetPainter()->ApplySettings( settings ); - - // Load display options (such as filled/outline display of items) - settings->LoadDisplayOptions( DisplayOpt ); - } - - // Set rendering order of layers - for( LAYER_NUM i = 0; i < sizeof(GalLayerOrder) / sizeof(LAYER_NUM); ++i ) - { - wxASSERT( i < KiGfx::VIEW::VIEW_MAX_LAYERS ); - - view->SetLayerOrder( GalLayerOrder[i], i ); - } - - // Netnames are drawn only when scale is sufficient (level of details) - // so there is no point in caching them - for( LAYER_NUM layer = FIRST_NETNAME_LAYER; layer <= LAST_NETNAME_LAYER; ++layer ) - { - view->SetLayerTarget( layer, KiGfx::TARGET_NONCACHED ); - } - - // Load layer & elements visibility settings - for( LAYER_NUM i = 0; i < NB_LAYERS; ++i ) - { - view->SetLayerVisible( i, m_Pcb->IsLayerVisible( i ) ); - } - - for( LAYER_NUM i = 0; i < END_PCB_VISIBLE_LIST; ++i ) - { - view->SetLayerVisible( ITEM_GAL_LAYER( i ), m_Pcb->IsElementVisible( i ) ); - } - view->RecacheAllItems( true ); if( m_galCanvasActive ) m_galCanvas->Refresh(); @@ -827,6 +788,36 @@ void PCB_BASE_FRAME::LoadSettings() if( m_DisplayModText < LINE || m_DisplayModText > SKETCH ) m_DisplayModText = FILLED; + // Apply display settings for GAL + KiGfx::VIEW* view = m_galCanvas->GetView(); + // Set rendering order of layers + for( LAYER_NUM i = 0; i < sizeof(GalLayerOrder) / sizeof(LAYER_NUM); ++i ) + { + wxASSERT( i < KiGfx::VIEW::VIEW_MAX_LAYERS ); + + view->SetLayerOrder( GalLayerOrder[i], i ); + } + + // Netnames are drawn only when scale is sufficient (level of details) + // so there is no point in caching them + for( LAYER_NUM layer = FIRST_NETNAME_LAYER; layer <= LAST_NETNAME_LAYER; ++layer ) + { + view->SetLayerTarget( layer, KiGfx::TARGET_NONCACHED ); + } + + // Apply layer coloring scheme & display options + if( view->GetPainter() ) + { + KiGfx::PCB_RENDER_SETTINGS* settings = new KiGfx::PCB_RENDER_SETTINGS(); + + // Load layers' colors from PCB data + settings->ImportLegacyColors( m_Pcb->GetColorsSettings() ); + view->GetPainter()->ApplySettings( settings ); + + // Load display options (such as filled/outline display of items) + settings->LoadDisplayOptions( DisplayOpt ); + } + // WxWidgets 2.9.1 seems call setlocale( LC_NUMERIC, "" ) // when reading doubles in config, // but forget to back to current locale. So we call SetLocaleTo_Default diff --git a/pcbnew/initpcb.cpp b/pcbnew/initpcb.cpp index 5d180ab66c..8b3b398995 100644 --- a/pcbnew/initpcb.cpp +++ b/pcbnew/initpcb.cpp @@ -4,6 +4,9 @@ #include #include +#include +#include +#include #include #include @@ -67,9 +70,12 @@ bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery ) // Default copper layers count set to 2: double layer board GetBoard()->SetCopperLayerCount( 2 ); - // Update display: + // Update display GetBoard()->SetVisibleLayers( ALL_LAYERS ); + // Set currently selected layer to be shown in high contrast mode, when enabled` + setHighContrastLayer( GetScreen()->m_Active_Layer ); + ReFillLayerWidget(); Zoom_Automatique( false ); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 8b8c85f296..0eddda4f60 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -472,7 +472,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, DisplayError( this, msg ); } } - } @@ -813,6 +812,18 @@ void PCB_EDIT_FRAME::syncRenderStates() void PCB_EDIT_FRAME::syncLayerVisibilities() { m_Layers->SyncLayerVisibilities(); + + KiGfx::VIEW* view = m_galCanvas->GetView(); + // Load layer & elements visibility settings + for( LAYER_NUM i = 0; i < NB_LAYERS; ++i ) + { + view->SetLayerVisible( i, m_Pcb->IsLayerVisible( i ) ); + } + + for( LAYER_NUM i = 0; i < END_PCB_VISIBLE_LIST; ++i ) + { + view->SetLayerVisible( ITEM_GAL_LAYER( i ), m_Pcb->IsElementVisible( i ) ); + } }