Properties: custom rendering for COLOR4D
This commit is contained in:
parent
ed6487da1e
commit
a2ff3bce7d
|
@ -17,8 +17,10 @@
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include <wx/control.h>
|
#include <wx/control.h>
|
||||||
|
#include <wx/dc.h>
|
||||||
#include <wx/propgrid/propgrid.h>
|
#include <wx/propgrid/propgrid.h>
|
||||||
#include <properties/pg_cell_renderer.h>
|
#include <properties/pg_cell_renderer.h>
|
||||||
|
#include <properties/pg_properties.h>
|
||||||
|
|
||||||
|
|
||||||
PG_CELL_RENDERER::PG_CELL_RENDERER() :
|
PG_CELL_RENDERER::PG_CELL_RENDERER() :
|
||||||
|
@ -29,21 +31,39 @@ PG_CELL_RENDERER::PG_CELL_RENDERER() :
|
||||||
bool PG_CELL_RENDERER::Render( wxDC &aDC, const wxRect &aRect, const wxPropertyGrid *aGrid,
|
bool PG_CELL_RENDERER::Render( wxDC &aDC, const wxRect &aRect, const wxPropertyGrid *aGrid,
|
||||||
wxPGProperty *aProperty, int aColumn, int aItem, int aFlags ) const
|
wxPGProperty *aProperty, int aColumn, int aItem, int aFlags ) const
|
||||||
{
|
{
|
||||||
// Default behavior for value column
|
wxPGCell cell = aGrid->GetUnspecifiedValueAppearance();
|
||||||
|
|
||||||
if( aColumn > 0 )
|
if( aColumn > 0 )
|
||||||
|
{
|
||||||
|
if( PGPROPERTY_COLOR4D* colorProp = dynamic_cast<PGPROPERTY_COLOR4D*>( aProperty ) )
|
||||||
|
{
|
||||||
|
wxAny av = colorProp->GetValue().GetAny();
|
||||||
|
KIGFX::COLOR4D color = av.IsNull() ? KIGFX::COLOR4D::UNSPECIFIED
|
||||||
|
: av.As<KIGFX::COLOR4D>();
|
||||||
|
|
||||||
|
PreDrawCell( aDC, aRect, aGrid, cell, aFlags );
|
||||||
|
|
||||||
|
wxSize swatchSize = aGrid->ConvertDialogToPixels( wxSize( 24, 16 ) );
|
||||||
|
int offset = ( aRect.GetHeight() - swatchSize.GetHeight() ) / 2;
|
||||||
|
wxRect swatch( aRect.GetPosition() + wxPoint( offset, offset ), swatchSize );
|
||||||
|
|
||||||
|
aDC.SetPen( *wxTRANSPARENT_PEN );
|
||||||
|
aDC.SetBrush( wxBrush( color.ToColour() ) );
|
||||||
|
aDC.DrawRectangle( swatch );
|
||||||
|
|
||||||
|
PostDrawCell( aDC, aGrid, cell, aFlags );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default behavior for value column
|
||||||
return wxPGDefaultRenderer::Render( aDC, aRect, aGrid, aProperty, aColumn, aItem, aFlags );
|
return wxPGDefaultRenderer::Render( aDC, aRect, aGrid, aProperty, aColumn, aItem, aFlags );
|
||||||
|
}
|
||||||
|
|
||||||
wxString text;
|
wxString text;
|
||||||
int preDrawFlags = aFlags;
|
int preDrawFlags = aFlags;
|
||||||
|
|
||||||
#if wxCHECK_VERSION( 3, 1, 0 )
|
|
||||||
wxPGCell cell = aGrid->GetUnspecifiedValueAppearance();
|
|
||||||
aProperty->GetDisplayInfo( aColumn, aItem, aFlags, &text, &cell );
|
aProperty->GetDisplayInfo( aColumn, aItem, aFlags, &text, &cell );
|
||||||
#else
|
|
||||||
const wxPGCell* cellPtr = nullptr;
|
|
||||||
aProperty->GetDisplayInfo( aColumn, aItem, aFlags, &text, &cellPtr );
|
|
||||||
const wxPGCell cell = *cellPtr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
text = wxControl::Ellipsize( text, aDC, wxELLIPSIZE_MIDDLE, aRect.GetWidth() );
|
text = wxControl::Ellipsize( text, aDC, wxELLIPSIZE_MIDDLE, aRect.GetWidth() );
|
||||||
|
|
||||||
|
@ -60,4 +80,4 @@ bool PG_CELL_RENDERER::Render( wxDC &aDC, const wxRect &aRect, const wxPropertyG
|
||||||
PostDrawCell( aDC, aGrid, cell, preDrawFlags );
|
PostDrawCell( aDC, aGrid, cell, preDrawFlags );
|
||||||
|
|
||||||
return !text.IsEmpty();
|
return !text.IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,7 +407,7 @@ const wxPGEditor* PGPROPERTY_BOOL::DoGetEditorClass() const
|
||||||
|
|
||||||
PGPROPERTY_COLOR4D::PGPROPERTY_COLOR4D( const wxString& aLabel, const wxString& aName,
|
PGPROPERTY_COLOR4D::PGPROPERTY_COLOR4D( const wxString& aLabel, const wxString& aName,
|
||||||
COLOR4D aValue ) :
|
COLOR4D aValue ) :
|
||||||
wxColourProperty( aLabel, aName, aValue.ToColour() )
|
wxStringProperty( aLabel, aName, aValue.ToCSSString() )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue, int aFlags ) cons
|
||||||
if( aValue.IsType( wxS( "COLOR4D" ) ) )
|
if( aValue.IsType( wxS( "COLOR4D" ) ) )
|
||||||
static_cast<COLOR4D_VARIANT_DATA*>( aValue.GetData() )->Write( ret );
|
static_cast<COLOR4D_VARIANT_DATA*>( aValue.GetData() )->Write( ret );
|
||||||
else
|
else
|
||||||
return wxColourProperty::ValueToString( aValue, aFlags );
|
return wxStringProperty::ValueToString( aValue, aFlags );
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <wx/propgrid/props.h>
|
#include <wx/propgrid/props.h>
|
||||||
#include <wx/propgrid/advprops.h>
|
#include <wx/propgrid/advprops.h>
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
#include <gal/color4d.h>
|
||||||
#include <origin_transforms.h>
|
#include <origin_transforms.h>
|
||||||
|
|
||||||
class PROPERTY_BASE;
|
class PROPERTY_BASE;
|
||||||
|
@ -189,11 +190,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PGPROPERTY_COLOR4D : public wxColourProperty
|
class PGPROPERTY_COLOR4D : public wxStringProperty
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PGPROPERTY_COLOR4D( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
|
PGPROPERTY_COLOR4D( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
|
||||||
COLOR4D aValue = COLOR4D::UNSPECIFIED );
|
KIGFX::COLOR4D aValue = KIGFX::COLOR4D::UNSPECIFIED );
|
||||||
|
|
||||||
virtual ~PGPROPERTY_COLOR4D() = default;
|
virtual ~PGPROPERTY_COLOR4D() = default;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue