2014-03-18 15:31:21 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/drawing/pluginsample.cpp
|
|
|
|
// Purpose: Sample plugin for the wxGraphicsContext test
|
|
|
|
// Author: Armel Asselin
|
|
|
|
// Created: 2014-02-21
|
|
|
|
// Copyright: (c) 2014 Ellié Computing <opensource@elliecomputing.com>
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
#if wxUSE_TEST_GC_DRAWING
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// plugin implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SampleDrawingTestGCFactory: public DrawingTestGCFactory {
|
|
|
|
public:
|
|
|
|
SampleDrawingTestGCFactory() {
|
|
|
|
wxImage::AddHandler (new wxBMPHandler());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~SampleDrawingTestGCFactory() {
|
|
|
|
}
|
2018-09-21 13:46:49 -04:00
|
|
|
virtual wxString GetIdForFileName () const wxOVERRIDE { return "sample-plg"; }
|
|
|
|
virtual wxString GetExtensionForFileName () const wxOVERRIDE { return "bmp"; }
|
2014-03-18 15:31:21 -04:00
|
|
|
|
|
|
|
// Bitmaps are handled by wx code they should be binarily equal
|
2018-09-21 13:46:49 -04:00
|
|
|
virtual bool UseImageComparison() const wxOVERRIDE { return false; }
|
2014-03-18 15:31:21 -04:00
|
|
|
|
|
|
|
// We use wxGraphicsContext, its implementation is not platform independent
|
|
|
|
// and returns may slightly vary
|
2018-09-21 13:46:49 -04:00
|
|
|
virtual bool PlatformIndependent() const wxOVERRIDE { return false; }
|
2014-03-18 15:31:21 -04:00
|
|
|
|
|
|
|
virtual wxGraphicsContext *BuildNewContext (wxSize expectedSize,
|
2018-09-21 13:46:49 -04:00
|
|
|
double WXUNUSED(pointsPerInch), const wxFileName &targetFileName) wxOVERRIDE {
|
2014-03-18 15:31:21 -04:00
|
|
|
m_image = new wxImage (expectedSize);
|
|
|
|
m_image->InitAlpha();
|
|
|
|
|
|
|
|
m_targetFileName = targetFileName.GetFullPath();
|
|
|
|
|
|
|
|
// we should probably pass the number of points per inches somewhere...
|
|
|
|
// but I don't see where yet...
|
|
|
|
return wxGraphicsContext::Create(*m_image);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's the opportunity to actually save the context and associated data
|
|
|
|
// If saving requires deleting the wxGraphicsContext object the
|
|
|
|
// implementer is free to do it but @c gc must then be nulled
|
2018-09-21 13:46:49 -04:00
|
|
|
virtual void SaveBuiltContext (wxGraphicsContext *&gc) wxOVERRIDE {
|
2014-03-18 15:31:21 -04:00
|
|
|
wxDELETE(gc);
|
|
|
|
|
|
|
|
m_image->SaveFile (m_targetFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleans @c gc and internal data if any
|
2018-09-21 13:46:49 -04:00
|
|
|
virtual void CleanUp (wxGraphicsContext *gc) wxOVERRIDE {
|
2014-03-18 15:31:21 -04:00
|
|
|
delete gc;
|
|
|
|
m_targetFileName.Empty();
|
|
|
|
wxDELETE(m_image);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxImage *m_image;
|
|
|
|
wxString m_targetFileName;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" WXEXPORT DrawingTestGCFactory * CreateDrawingTestLifeCycle()
|
|
|
|
{
|
|
|
|
return new SampleDrawingTestGCFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" WXEXPORT void DestroyDrawingTestLifeCycle (DrawingTestGCFactory* lc)
|
|
|
|
{
|
|
|
|
delete lc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_TEST_GC_DRAWING
|