Give all GAL canvases access to a GAL_DISPLAY_OPTIONS structure instance

Also loads the gal options when loading a canvas, as the canvas
otherwise might not register the initial settings.
This commit is contained in:
John Beard 2017-02-13 19:43:28 +08:00 committed by Maciej Suminski
parent cdfcc9a2ab
commit ddded86a06
12 changed files with 122 additions and 94 deletions

View File

@ -39,7 +39,10 @@
using namespace KIGFX; using namespace KIGFX;
BASIC_GAL basic_gal; KIGFX::GAL_DISPLAY_OPTIONS basic_displayOptions;
// the basic GAL doesn't get an external display option object
BASIC_GAL basic_gal( basic_displayOptions );
const VECTOR2D BASIC_GAL::transform( const VECTOR2D& aPoint ) const const VECTOR2D BASIC_GAL::transform( const VECTOR2D& aPoint ) const
{ {

View File

@ -114,15 +114,12 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
Connect( m_onShowTimer.GetId(), wxEVT_TIMER, Connect( m_onShowTimer.GetId(), wxEVT_TIMER,
wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onShowTimer ), NULL, this ); wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onShowTimer ), NULL, this );
m_onShowTimer.Start( 10 ); m_onShowTimer.Start( 10 );
LoadGalSettings();
} }
EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL() EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL()
{ {
StopDrawing(); StopDrawing();
SaveGalSettings();
assert( !m_drawing ); assert( !m_drawing );
@ -353,7 +350,7 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
break; break;
case GAL_TYPE_CAIRO: case GAL_TYPE_CAIRO:
new_gal = new KIGFX::CAIRO_GAL( this, this, this ); new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this );
break; break;
default: default:
@ -363,19 +360,21 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
case GAL_TYPE_NONE: case GAL_TYPE_NONE:
// KIGFX::GAL is a stub - it actually does cannot display anything, // KIGFX::GAL is a stub - it actually does cannot display anything,
// but prevents code relying on GAL canvas existence from crashing // but prevents code relying on GAL canvas existence from crashing
new_gal = new KIGFX::GAL(); new_gal = new KIGFX::GAL( m_options );
break; break;
} }
} }
catch( std::runtime_error& err ) catch( std::runtime_error& err )
{ {
new_gal = new KIGFX::GAL(); new_gal = new KIGFX::GAL( m_options );
aGalType = GAL_TYPE_NONE; aGalType = GAL_TYPE_NONE;
DisplayError( m_parent, wxString( err.what() ) ); DisplayError( m_parent, wxString( err.what() ) );
result = false; result = false;
} }
SaveGalSettings(); // trigger update of the gal options in case they differ
// from the defaults
m_options.NotifyChanged();
assert( new_gal ); assert( new_gal );
delete m_gal; delete m_gal;
@ -391,49 +390,11 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
m_view->SetGAL( m_gal ); m_view->SetGAL( m_gal );
m_backend = aGalType; m_backend = aGalType;
LoadGalSettings();
return result; return result;
} }
bool EDA_DRAW_PANEL_GAL::SaveGalSettings()
{
if( !m_edaFrame || !m_gal )
return false;
wxConfigBase* cfg = Kiface().KifaceSettings();
wxString baseCfgName = m_edaFrame->GetName();
if( !cfg )
return false;
if( !cfg->Write( baseCfgName + GRID_STYLE_CFG, (long) GetGAL()->GetGridStyle() ) )
return false;
return true;
}
bool EDA_DRAW_PANEL_GAL::LoadGalSettings()
{
if( !m_edaFrame || !m_gal )
return false;
wxConfigBase* cfg = Kiface().KifaceSettings();
wxString baseCfgName = m_edaFrame->GetName();
if( !cfg )
return false;
long gridStyle;
cfg->Read( baseCfgName + GRID_STYLE_CFG, &gridStyle, (long) KIGFX::GRID_STYLE::GRID_STYLE_DOTS );
GetGAL()->SetGridStyle( (KIGFX::GRID_STYLE) gridStyle );
return true;
}
void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent )
{ {
if( m_lostFocus ) if( m_lostFocus )

View File

@ -42,8 +42,10 @@ using namespace KIGFX;
CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, CAIRO_GAL::CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions,
wxWindow* aParent, wxEvtHandler* aMouseListener,
wxEvtHandler* aPaintListener, const wxString& aName ) : wxEvtHandler* aPaintListener, const wxString& aName ) :
GAL( aDisplayOptions ),
wxWindow( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName ) wxWindow( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName )
{ {
parentWindow = aParent; parentWindow = aParent;
@ -103,6 +105,20 @@ CAIRO_GAL::~CAIRO_GAL()
} }
bool CAIRO_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions )
{
bool refresh = false;
if( super::updatedGalDisplayOptions( aOptions ) )
{
Refresh();
refresh = true;
}
return refresh;
}
void CAIRO_GAL::BeginDrawing() void CAIRO_GAL::BeginDrawing()
{ {
initSurface(); initSurface();

View File

@ -26,7 +26,11 @@
using namespace KIGFX; using namespace KIGFX;
static const wxString GalGLAntialiasingKeyword( wxT( "OpenGLAntialiasingMode" ) ); /*
* Config option strings
*/
static const wxString GalGLAntialiasingKeyword( "OpenGLAntialiasingMode" );
GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS() GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS()
: gl_antialiasing_mode( OPENGL_ANTIALIASING_MODE::NONE ) : gl_antialiasing_mode( OPENGL_ANTIALIASING_MODE::NONE )
@ -36,8 +40,8 @@ GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS()
void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase* aCfg, wxString aBaseName ) void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase* aCfg, wxString aBaseName )
{ {
aCfg->Read( aBaseName + GalGLAntialiasingKeyword, aCfg->Read( aBaseName + GalGLAntialiasingKeyword,
reinterpret_cast<long*>(&gl_antialiasing_mode), reinterpret_cast<long*>( &gl_antialiasing_mode ),
(long)KIGFX::OPENGL_ANTIALIASING_MODE::NONE ); static_cast<long>( KIGFX::OPENGL_ANTIALIASING_MODE::NONE ) );
NotifyChanged(); NotifyChanged();
} }
@ -46,7 +50,7 @@ void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase* aCfg, wxString aBaseName )
void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase* aCfg, wxString aBaseName ) void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase* aCfg, wxString aBaseName )
{ {
aCfg->Write( aBaseName + GalGLAntialiasingKeyword, aCfg->Write( aBaseName + GalGLAntialiasingKeyword,
static_cast<long>(gl_antialiasing_mode) ); static_cast<long>( gl_antialiasing_mode ) );
} }

View File

@ -37,7 +37,8 @@ using namespace KIGFX;
const double GAL::METRIC_UNIT_LENGTH = 1e9; const double GAL::METRIC_UNIT_LENGTH = 1e9;
GAL::GAL() : GAL::GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions ) :
options( aDisplayOptions ),
strokeFont( this ) strokeFont( this )
{ {
// Set the default values for the internal variables // Set the default values for the internal variables
@ -68,6 +69,9 @@ GAL::GAL() :
SetCursorEnabled( false ); SetCursorEnabled( false );
strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize ); strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize );
// subscribe for settings updates
observerLink = options.Subscribe( this );
} }
@ -75,6 +79,23 @@ GAL::~GAL()
{ {
} }
void GAL::OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& aOptions )
{
// defer to the child class first
updatedGalDisplayOptions( aOptions );
// there is no refresh to do at this level
}
bool GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions )
{
bool refresh = false;
// tell the derived class if the base class needs an update or not
return refresh;
}
void GAL::SetTextAttributes( const EDA_TEXT* aText ) void GAL::SetTextAttributes( const EDA_TEXT* aText )
{ {

View File

@ -66,9 +66,10 @@ SHADER* OPENGL_GAL::shader = NULL;
OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent,
wxEvtHandler* aMouseListener, wxEvtHandler* aPaintListener, wxEvtHandler* aMouseListener, wxEvtHandler* aPaintListener,
const wxString& aName ) : const wxString& aName ) :
GAL( aDisplayOptions ),
wxGLCanvas( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize, wxGLCanvas( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize,
wxEXPAND, aName ), wxEXPAND, aName ),
options( aDisplayOptions ), mouseListener( aMouseListener ), paintListener( aPaintListener ) mouseListener( aMouseListener ), paintListener( aPaintListener )
{ {
if( glMainContext == NULL ) if( glMainContext == NULL )
{ {
@ -101,8 +102,6 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent,
SetViewWantsBestResolution( true ); SetViewWantsBestResolution( true );
#endif #endif
observerLink = options.Subscribe( this );
// Connecting the event handlers // Connecting the event handlers
Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) ); Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
@ -182,18 +181,27 @@ OPENGL_GAL::~OPENGL_GAL()
GL_CONTEXT_MANAGER::Get().DestroyCtx( glMainContext ); GL_CONTEXT_MANAGER::Get().DestroyCtx( glMainContext );
glMainContext = NULL; glMainContext = NULL;
} }
} }
void OPENGL_GAL::OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& aDisplayOptions ) bool OPENGL_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions )
{ {
bool refresh = false;
if( options.gl_antialiasing_mode != compositor->GetAntialiasingMode() ) if( options.gl_antialiasing_mode != compositor->GetAntialiasingMode() )
{ {
compositor->SetAntialiasingMode( options.gl_antialiasing_mode ); compositor->SetAntialiasingMode( options.gl_antialiasing_mode );
isFramebufferInitialized = false; isFramebufferInitialized = false;
Refresh(); refresh = true;
} }
if( super::updatedGalDisplayOptions( aOptions ) || refresh )
{
Refresh();
refresh = true;
}
return refresh;
} }

View File

@ -64,7 +64,8 @@ private:
std::stack <TRANSFORM_PRM> m_transformHistory; std::stack <TRANSFORM_PRM> m_transformHistory;
public: public:
BASIC_GAL() BASIC_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions ) :
GAL( aDisplayOptions )
{ {
m_DC = NULL; m_DC = NULL;
m_Color = RED; m_Color = RED;

View File

@ -177,18 +177,6 @@ public:
return m_edaFrame; return m_edaFrame;
} }
/**
* Function SaveGalSettings()
* Stores GAL related settings in the configuration storage.
*/
virtual bool SaveGalSettings();
/**
* Function LoadGalSettings()
* Loads GAL related settings from the configuration storage.
*/
virtual bool LoadGalSettings();
/** /**
* Function OnShow() * Function OnShow()
* Called when the window is shown for the first time. * Called when the window is shown for the first time.

View File

@ -81,7 +81,8 @@ public:
* *
* @param aName is the name of this window for use by wxWindow::FindWindowByName() * @param aName is the name of this window for use by wxWindow::FindWindowByName()
*/ */
CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener = NULL, CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions,
wxWindow* aParent, wxEvtHandler* aMouseListener = NULL,
wxEvtHandler* aPaintListener = NULL, const wxString& aName = wxT( "CairoCanvas" ) ); wxEvtHandler* aPaintListener = NULL, const wxString& aName = wxT( "CairoCanvas" ) );
virtual ~CAIRO_GAL(); virtual ~CAIRO_GAL();
@ -352,6 +353,9 @@ private:
int wxBufferWidth; int wxBufferWidth;
///> Cairo-specific update handlers
bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) override;
void flushPath(); void flushPath();
// Methods // Methods
void storePath(); ///< Store the actual path void storePath(); ///< Store the actual path

View File

@ -29,9 +29,16 @@
class wxConfigBase; class wxConfigBase;
class wxString; class wxString;
namespace KIGFX { namespace KIGFX
{
class GAL_DISPLAY_OPTIONS; /**
* GridStyle: Type definition of the grid style
*/
enum GRID_STYLE
{
GRID_STYLE_LINES, ///< Use lines for the grid
GRID_STYLE_DOTS ///< Use dots for the grid
};
enum class OPENGL_ANTIALIASING_MODE : long enum class OPENGL_ANTIALIASING_MODE : long
{ {
@ -42,6 +49,8 @@ namespace KIGFX {
SUPERSAMPLING_X4 = 4 SUPERSAMPLING_X4 = 4
}; };
class GAL_DISPLAY_OPTIONS;
class GAL_DISPLAY_OPTIONS_OBSERVER class GAL_DISPLAY_OPTIONS_OBSERVER
{ {
public: public:
@ -53,12 +62,12 @@ namespace KIGFX {
public: public:
GAL_DISPLAY_OPTIONS(); GAL_DISPLAY_OPTIONS();
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode;
void ReadConfig ( wxConfigBase* aCfg, wxString aBaseName ); void ReadConfig ( wxConfigBase* aCfg, wxString aBaseName );
void WriteConfig( wxConfigBase* aCfg, wxString aBaseName ); void WriteConfig( wxConfigBase* aCfg, wxString aBaseName );
void NotifyChanged(); void NotifyChanged();
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode;
}; };
} }

View File

@ -36,6 +36,7 @@
#include <gal/color4d.h> #include <gal/color4d.h>
#include <gal/definitions.h> #include <gal/definitions.h>
#include <gal/stroke_font.h> #include <gal/stroke_font.h>
#include <gal/gal_display_options.h>
#include <newstroke_font.h> #include <newstroke_font.h>
class SHAPE_LINE_CHAIN; class SHAPE_LINE_CHAIN;
@ -43,15 +44,6 @@ class SHAPE_POLY_SET;
namespace KIGFX namespace KIGFX
{ {
/**
* GridStyle: Type definition of the grid style
*/
enum GRID_STYLE
{
GRID_STYLE_LINES, ///< Use lines for the grid
GRID_STYLE_DOTS ///< Use dots for the grid
};
/** /**
* @brief Class GAL is the abstract interface for drawing on a 2D-surface. * @brief Class GAL is the abstract interface for drawing on a 2D-surface.
@ -63,11 +55,11 @@ enum GRID_STYLE
* for drawing purposes these are transformed to screen units with this layer. So zooming is handled here as well. * for drawing purposes these are transformed to screen units with this layer. So zooming is handled here as well.
* *
*/ */
class GAL class GAL: GAL_DISPLAY_OPTIONS_OBSERVER
{ {
public: public:
// Constructor / Destructor // Constructor / Destructor
GAL(); GAL( GAL_DISPLAY_OPTIONS& aOptions );
virtual ~GAL(); virtual ~GAL();
/// @brief Returns the initalization status for the canvas. /// @brief Returns the initalization status for the canvas.
@ -975,6 +967,10 @@ public:
static const double METRIC_UNIT_LENGTH; static const double METRIC_UNIT_LENGTH;
protected: protected:
GAL_DISPLAY_OPTIONS& options;
UTIL::LINK observerLink;
std::stack<double> depthStack; ///< Stored depth values std::stack<double> depthStack; ///< Stored depth values
VECTOR2I screenSize; ///< Screen size in screen coordinates VECTOR2I screenSize; ///< Screen size in screen coordinates
@ -1043,6 +1039,25 @@ protected:
/// Depth level on which the grid is drawn /// Depth level on which the grid is drawn
static const int GRID_DEPTH; static const int GRID_DEPTH;
// ---------------
// Settings observer interface
// ---------------
/**
* Handler for observer settings changes
*/
void OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& aOptions ) override;
/**
* Function updatedGalDisplayOptions
*
* @brief handler for updated display options. Derived classes
* should call up to this to set base-class methods.
*
* @return true if the new settings changed something. Derived classes
* can use this information to refresh themselves
*/
virtual bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions );
private: private:
struct TEXT_PROPERTIES struct TEXT_PROPERTIES
{ {

View File

@ -62,7 +62,7 @@ class SHADER;
* and quads. The purpose is to provide a fast graphics interface, that takes advantage of modern * and quads. The purpose is to provide a fast graphics interface, that takes advantage of modern
* graphics card GPUs. All methods here benefit thus from the hardware acceleration. * graphics card GPUs. All methods here benefit thus from the hardware acceleration.
*/ */
class OPENGL_GAL : public GAL, public wxGLCanvas, GAL_DISPLAY_OPTIONS_OBSERVER class OPENGL_GAL : public GAL, public wxGLCanvas
{ {
public: public:
/** /**
@ -99,8 +99,6 @@ public:
return IsShownOnScreen(); return IsShownOnScreen();
} }
void OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& ) override;
// --------------- // ---------------
// Drawing methods // Drawing methods
// --------------- // ---------------
@ -282,9 +280,6 @@ private:
/// Super class definition /// Super class definition
typedef GAL super; typedef GAL super;
GAL_DISPLAY_OPTIONS& options;
UTIL::LINK observerLink;
static const int CIRCLE_POINTS = 64; ///< The number of points for circle approximation static const int CIRCLE_POINTS = 64; ///< The number of points for circle approximation
static const int CURVE_POINTS = 32; ///< The number of points for curve approximation static const int CURVE_POINTS = 32; ///< The number of points for curve approximation
@ -322,6 +317,9 @@ private:
///< when the window is visible ///< when the window is visible
bool isGrouping; ///< Was a group started? bool isGrouping; ///< Was a group started?
///< Update handler for OpenGL settings
bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) override;
// Polygon tesselation // Polygon tesselation
/// The tessellator /// The tessellator
GLUtesselator* tesselator; GLUtesselator* tesselator;