From d27ea7895d5b4c1e30ba7ae96bf6ff0587a2f26c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 14 May 2014 10:35:12 +0200 Subject: [PATCH] Moved background color settings from GAL to RENDER_SETTINGS. Added RENDER_SETTINGS::TranslateColor() to convert between EDA_COLOR_T and COLOR4D. --- common/draw_panel_gal.cpp | 5 ++-- common/gal/cairo/cairo_gal.cpp | 8 +++--- common/gal/opengl/opengl_gal.cpp | 4 +-- include/class_draw_panel_gal.h | 2 +- include/gal/cairo/cairo_gal.h | 5 ++-- include/gal/graphics_abstraction_layer.h | 18 ++++--------- include/gal/opengl/opengl_gal.h | 2 +- include/painter.h | 32 ++++++++++++++++++++++++ pcbnew/pcb_painter.cpp | 2 ++ 9 files changed, 52 insertions(+), 26 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 93ad978969..1b293c63ac 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 CERN + * Copyright (C) 2013-2014 CERN * @author Tomasz Wlostowski * * This program is free software; you can redistribute it and/or @@ -124,7 +124,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) m_view->UpdateItems(); m_gal->BeginDrawing(); - m_gal->ClearScreen(); + m_gal->ClearScreen( m_painter->GetSettings()->GetBackgroundColor() ); if( m_view->IsDirty() ) { @@ -228,7 +228,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) wxSize size = GetClientSize(); m_gal->ResizeScreen( size.GetX(), size.GetY() ); - m_gal->SetBackgroundColor( KIGFX::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) ); if( m_painter ) m_painter->SetGAL( m_gal ); diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 13055c7aed..a6f1429721 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -315,10 +315,10 @@ void CAIRO_GAL::Flush() } -void CAIRO_GAL::ClearScreen() +void CAIRO_GAL::ClearScreen( const COLOR4D& aColor ) { - cairo_set_source_rgb( currentContext, - backgroundColor.r, backgroundColor.g, backgroundColor.b ); + backgroundColor = aColor; + cairo_set_source_rgb( currentContext, aColor.r, aColor.g, aColor.b ); cairo_rectangle( currentContext, 0.0, 0.0, screenSize.x, screenSize.y ); cairo_fill( currentContext ); } @@ -973,7 +973,7 @@ void CAIRO_GAL::initSurface() cairo_set_antialias( context, CAIRO_ANTIALIAS_SUBPIXEL ); // Clear the screen - ClearScreen(); + ClearScreen( backgroundColor ); // Compute the world <-> screen transformations ComputeWorldScreenMatrix(); diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 5bd59303a2..568772f96a 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -589,10 +589,10 @@ void OPENGL_GAL::Flush() } -void OPENGL_GAL::ClearScreen() +void OPENGL_GAL::ClearScreen( const COLOR4D& aColor ) { // Clear screen - glClearColor( backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a ); + glClearColor( aColor.r, aColor.g, aColor.b, aColor.a ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); } diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index 766cb5d630..16de3a139c 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 CERN + * Copyright (C) 2013-2014 CERN * @author Tomasz Wlostowski * * This program is free software; you can redistribute it and/or diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index 352e262931..6b44b1d476 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -135,7 +135,7 @@ public: virtual void Flush(); /// @copydoc GAL::ClearScreen() - virtual void ClearScreen(); + virtual void ClearScreen( const COLOR4D& aColor ); // ----------------- // Attribute setting @@ -309,7 +309,7 @@ private: /// Type definition for an graphics group element typedef struct { - GRAPHICS_COMMAND command; ///< Command to execute + GRAPHICS_COMMAND command; ///< Command to execute double arguments[MAX_CAIRO_ARGUMENTS]; ///< Arguments for Cairo commands bool boolArgument; ///< A bool argument int intArgument; ///< An int argument @@ -333,6 +333,7 @@ private: unsigned int* bitmapBufferBackup; ///< Backup storage of the cairo image int stride; ///< Stride value for Cairo bool isInitialized; ///< Are Cairo image & surface ready to use + COLOR4D backgroundColor; ///< Background color // Methods void storePath(); ///< Store the actual path diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 50b5c355c7..6d904d2016 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -168,8 +168,11 @@ public: /// @brief Force all remaining objects to be drawn. virtual void Flush() = 0; - /// @brief Clear the screen. - virtual void ClearScreen() = 0; + /** + * @brief Clear the screen. + * @param aColor is the color used for clearing. + */ + virtual void ClearScreen( const COLOR4D& aColor ) = 0; // ----------------- // Attribute setting @@ -225,16 +228,6 @@ public: return strokeColor; } - /** - * @brief Set the background color. - * - * @param aColor is the color for background filling. - */ - inline virtual void SetBackgroundColor( const COLOR4D& aColor ) - { - backgroundColor = aColor; - } - /** * @brief Set the line width. * @@ -849,7 +842,6 @@ protected: bool isFillEnabled; ///< Is filling of graphic objects enabled ? bool isStrokeEnabled; ///< Are the outlines stroked ? - COLOR4D backgroundColor; ///< The background color COLOR4D fillColor; ///< The fill color COLOR4D strokeColor; ///< The color of the outlines diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index d5c97aada9..10c4fea54d 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -143,7 +143,7 @@ public: virtual void Flush(); /// @copydoc GAL::ClearScreen() - virtual void ClearScreen(); + virtual void ClearScreen( const COLOR4D& aColor ); // -------------- // Transformation diff --git a/include/painter.h b/include/painter.h index 34376d985d..afa74aa482 100644 --- a/include/painter.h +++ b/include/painter.h @@ -177,6 +177,36 @@ public: return m_worksheetLineWidth; } + /** + * Function TranslateColor + * Returns the color responding to the one of EDA_COLOR_T enum values. + * @param EDA_COLOR_T color equivalent. + */ + const COLOR4D& TranslateColor( EDA_COLOR_T aColor ) + { + return m_legacyColorMap[aColor]; + } + + /** + * Function GetBackgroundColor + * Returns current background color settings. + * @return Background color. + */ + const COLOR4D& GetBackgroundColor() const + { + return m_backgroundColor; + } + + /** + * Function SetBackgroundColor + * Sets new color for background. + * @param aColor is the new background color. + */ + void SetBackgroundColor( const COLOR4D& aColor ) + { + m_backgroundColor = aColor; + } + protected: /** * Function update @@ -203,6 +233,8 @@ protected: float m_outlineWidth; ///< Line width used when drawing outlines float m_worksheetLineWidth; ///< Line width used when drawing worksheet + COLOR4D m_backgroundColor; ///< The background color + /// Map of colors that were usually used for display std::map m_legacyColorMap; }; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 0465f450aa..7b72b47497 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -43,6 +43,8 @@ using namespace KIGFX; PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS() { + m_backgroundColor = COLOR4D( 0.0, 0.0, 0.0, 1.0 ); + // By default everything should be displayed as filled for( unsigned int i = 0; i < END_PCB_VISIBLE_LIST; ++i ) {