wxShapeFramework

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5420
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

wxShapeFramework

Post by ONEEYEMAN »

Hi,
Does anybody uses wxSF?

Id like to discuss some problem...

Thank you.
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxShapeFramework

Post by iwbnwif »

Hi, yes I use it quite a lot.

What is the problem?
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5420
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxShapeFramework

Post by ONEEYEMAN »

Hi,
I'm using it to create some database view (similar to what CodeLite does).
By default when the table is selected it shows handles.
I changed so that it loos like in the attachment.
issue.PNG
issue.PNG (5.84 KiB) Viewed 1818 times
However, as you can see the selected table is not painted correctly.

This is the code for the table I modified:

Code: Select all

#include <string>
#include <algorithm>
#include "database.h"
#include "wxsf/RoundRectShape.h"
#include "wxsf/BitmapShape.h"
#include "wxsf/CommonFcn.h"
#include "wxsf/TextShape.h"
#include "wxsf/FlexGridShape.h"
#include "wxsf/DiagramManager.h"
#include "constraint.h"
#include "constraintsign.h"
#include "HeaderGrid.h"
#include "GridTableShape.h"
#include "FieldShape.h"
#include "fieldtypeshape.h"
#include "commentfieldshape.h"
#include "commenttableshape.h"
#include "MyErdTable.h"
#include "res/gui/key-p.xpm"
#include "res/gui/key-f.xpm"

using namespace wxSFCommonFcn;

XS_IMPLEMENT_CLONABLE_CLASS(MyErdTable, wxSFRoundRectShape);

MyErdTable::MyErdTable() : wxSFRoundRectShape()
{
    SetFill( wxBrush( wxColour( 254, 253, 211 ) ) );
    AcceptConnection( wxT( "All" ) );
    AcceptTrgNeighbour( wxT( "All" ) );
    AcceptSrcNeighbour( wxT( "All" ) );
    AddStyle( sfsLOCK_CHILDREN );
    AddStyle( sfsSHOW_SHADOW );
    SetBorder( wxPen( wxColour( 70, 125, 170 ), 1, wxPENSTYLE_SOLID ) );
    SetFill( wxBrush( wxColour( 210, 225, 245 ) ) );
    SetRadius( 15 );
    m_header = new HeaderGrid();
    m_pLabel = new wxSFTextShape();
    m_comment = new CommentTableShape();
    m_pGrid = new GridTableShape( DatabaseView );
    m_pLabel->SetId( 1000 );
    m_comment->SetId( 1001 );
    if( m_header && m_pLabel && m_comment && m_pGrid )
    {
        // set table header
        m_header->SetRelativePosition( 0, 1 );
        m_header->SetStyle( sfsALWAYS_INSIDE | sfsPROCESS_DEL |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION | sfsLOCK_CHILDREN );
        m_header->SetDimensions( 1, 2 );
        m_header->SetFill( *wxTRANSPARENT_BRUSH );
        m_header->SetBorder( *wxTRANSPARENT_PEN );
        m_header->AcceptChild( wxT( "wxSFTextShape" ) );
        m_header->Activate( false );
        SF_ADD_COMPONENT( m_header, wxT( "header" ) );
        //table name
        if( m_header->InsertToGrid( 0, 0, m_pLabel ) )
        {
            m_pLabel->SetVAlign( wxSFShapeBase::valignTOP );
            m_pLabel->GetFont().SetPointSize( 8 );
            m_pLabel->GetFont().SetWeight( wxFONTWEIGHT_BOLD );
            m_pLabel->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
//            SF_ADD_COMPONENT( m_pLabel, wxT( "title" ) );
        }
        // table comment
        if( m_header->InsertToGrid( 0, 1, m_comment ) )
        {
            m_comment->SetVAlign( wxSFShapeBase::valignTOP );
            m_comment->SetHAlign( wxSFShapeBase::halignRIGHT );
            m_comment->GetFont().SetPointSize( 8 );
            m_comment->GetFont().SetWeight( wxFONTWEIGHT_BOLD );
            m_comment->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
//            SF_ADD_COMPONENT( m_comment, wxT( "comment" ) );
        }
        // set grid
        m_pGrid->SetRelativePosition( 0, 17 );
        m_pGrid->SetStyle( sfsALWAYS_INSIDE | sfsPROCESS_DEL |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION | sfsLOCK_CHILDREN );
        m_pGrid->SetDimensions( 1, 3 );
        m_pGrid->SetFill( *wxTRANSPARENT_BRUSH );
        m_pGrid->SetBorder( *wxTRANSPARENT_PEN );
        m_pGrid->SetHAlign( wxSFShapeBase::halignLEFT );
        m_pGrid->SetVBorder( 13 );
        m_pGrid->SetHBorder( 5 );
        m_pGrid->AcceptChild( wxT( "FieldShape" ) );
        m_pGrid->AcceptChild( wxT( "wxSFTextShape" ) );
        m_pGrid->AcceptChild( wxT( "wxSFBitmapShape" ) );
        m_pGrid->AcceptChild( wxT( "wxSFShapeBase" ) );
        m_pGrid->AcceptChild( wxT( "FieldTypeShape" ) );
        m_pGrid->Activate( true );
        SF_ADD_COMPONENT( m_pGrid, wxT( "main_grid" ) );
    }
}

MyErdTable::MyErdTable(DatabaseTable *table, ViewType type) : wxSFRoundRectShape()
{
    m_type = type;
    m_table = table;
    std::vector<TableField *> fields = m_table->GetFields();
    SetBorder( wxPen( wxColour( 70, 125, 170 ), 1, wxPENSTYLE_SOLID ) );
    SetFill( wxBrush( wxColour( 210, 225, 245 ) ) );
    AcceptConnection( wxT( "All" ) );
    AcceptTrgNeighbour( wxT( "All" ) );
    AcceptSrcNeighbour( wxT( "All" ) );
    AddStyle( sfsLOCK_CHILDREN );
    SetRadius(15);
    m_header = new HeaderGrid();
    m_pLabel = new wxSFTextShape();
    m_comment = new CommentTableShape( table );
    m_pGrid = new GridTableShape( type );
    m_pLabel->SetId( 1000 );
    m_comment->SetId( 1001 );
    if( m_header && m_pLabel && m_comment && m_pGrid )
    {
        // set table header
        m_header->SetRelativePosition( 0, 1 );
        m_header->SetVAlign( wxSFShapeBase::valignTOP );
        m_header->SetStyle( sfsALWAYS_INSIDE | sfsPROCESS_DEL |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION | sfsLOCK_CHILDREN );
        m_header->SetDimensions( 1, 2 );
        m_header->SetFill( *wxTRANSPARENT_BRUSH );
        m_header->SetBorder( *wxTRANSPARENT_PEN);
        m_header->AcceptChild( wxT( "wxSFTextShape" ) );
        m_header->AcceptChild( wxT( "CommentTableShape" ) );
        m_header->Activate( false );
        SF_ADD_COMPONENT( m_header, wxT( "header" ) );
        //table name
        if( m_header->InsertToGrid( 0, 0, m_pLabel ) )
        {
            m_pLabel->SetVAlign( wxSFShapeBase::valignTOP );
            m_pLabel->GetFont().SetPointSize( 8 );
            m_pLabel->GetFont().SetWeight( wxFONTWEIGHT_BOLD );
            m_pLabel->SetText( m_table->GetTableName() );
            m_pLabel->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
            m_pLabel->Activate( false );
//            SF_ADD_COMPONENT( m_pLabel, wxT( "title" ) );
        }
        // table comment
        if( m_header->InsertToGrid( 0, 1, m_comment ) )
        {
            m_comment->SetVAlign( wxSFShapeBase::valignTOP );
            m_comment->SetHAlign( wxSFShapeBase::halignLEFT );
            m_comment->GetFont().SetPointSize( 8 );
            m_comment->GetFont().SetWeight( wxFONTWEIGHT_BOLD );
            m_comment->SetText( m_table->GetTableProperties().m_comment );
            m_comment->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
            m_comment->Activate( false );
//            SF_ADD_COMPONENT( m_comment, wxT( "comment" ) );
        }
        // set grid
        m_pGrid->SetRelativePosition( 0, 17 );
        m_pGrid->SetStyle( sfsALWAYS_INSIDE | sfsPROCESS_DEL |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION | sfsLOCK_CHILDREN );
        m_pGrid->SetCellSpace( 8 );
        m_pGrid->SetDimensions( 1, 3 );
        m_pGrid->SetFill( *wxTRANSPARENT_BRUSH );
        m_pGrid->SetBorder( *wxTRANSPARENT_PEN);
        m_pGrid->SetHAlign( wxSFShapeBase::halignLEFT );
        m_pGrid->SetVBorder( 13 );
        m_pGrid->SetHBorder( 5 );
        m_pGrid->AcceptChild( wxT( "FieldShape" ) );
        m_pGrid->AcceptChild( wxT( "wxSFTextShape" ) );
        m_pGrid->AcceptChild( wxT( "wxSFBitmapShape" ) );
        m_pGrid->AcceptChild( wxT( "wxSFShapeBase" ) );
        m_pGrid->AcceptChild( wxT( "CommentFieldShape" ) );
        m_pGrid->AcceptChild( wxT( "FieldTypeShape" ) );
        m_pGrid->Activate( false );
        SF_ADD_COMPONENT( m_pGrid, wxT( "main_grid" ) );
    }
}

MyErdTable::~MyErdTable()
{
}

void MyErdTable::UpdateTable()
{
    std::vector<TableField *> fields = m_table->GetFields();
    int i = 0;
    ClearGrid();
    ClearConnections();
    SetRectSize( GetRectSize().x, 0 );
    ShapeList list;
    wxSFDiagramManager *manager = GetShapeManager();
    if( manager )
        manager->GetShapes( CLASSINFO( MyErdTable ), list );
    for( std::vector<TableField *>::iterator it = fields.begin(); it < fields.end(); it++ )
    {
        AddColumn( (*it), i, (*it)->IsPrimaryKey() ? Constraint::primaryKey : (*it)->IsForeignKey() ? Constraint::foreignKey : Constraint::noKey );
        i += 3;
    }
    m_pGrid->Update();
    Update();
}

void MyErdTable::SetTableComment(const wxString &comment)
{
    m_table->GetTableProperties().m_comment = comment.ToStdWstring();
    m_comment->SetText( m_table->GetTableProperties().m_comment );
}

void MyErdTable::ClearGrid()
{
    m_pGrid->RemoveChildren();
    // re-initialize grid control
    m_pGrid->ClearGrid();
    m_pGrid->SetDimensions( 1, 3 );
    m_pGrid->SetCellSpace( 2 );
    Refresh();
}

void MyErdTable::ClearConnections()
{
}

void MyErdTable::DrawDetail(wxDC &dc)
{
    dc.SetPen( *wxWHITE_PEN );
    dc.SetBrush( *wxLIGHT_GREY_BRUSH );
    dc.DrawRectangle( Conv2Point( GetAbsolutePosition() + wxRealPoint( 1, m_nRadius ) ), Conv2Size( m_nRectSize - wxRealPoint( 2, 2 * m_nRadius - 2 ) ) );
}
/*
void MyErdTable::DrawHighlighted(wxDC &dc)
{
    wxSFRoundRectShape::DrawHighlighted( dc );
    DrawDetail( dc );
}
*/
void MyErdTable::DrawHover(wxDC &dc)
{
    wxSFRoundRectShape::DrawHover( dc );
    DrawDetail( dc );
}

void MyErdTable::DrawNormal(wxDC &dc)
{
    if( this->m_fSelected && m_type == DatabaseView )
    {
        m_header->SetFill( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ) );
    }
    wxSFRoundRectShape::DrawNormal( dc );
    DrawDetail( dc );
}

void MyErdTable::AddColumn(TableField *field, int id, Constraint::constraintType type)
{
    if( m_type == DatabaseView )
    {
        if( type != Constraint::noKey )
        {
            // key bitmap
            wxSFBitmapShape* pBitmap = new wxSFBitmapShape();
            if( pBitmap )
            {
                pBitmap->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
                pBitmap->SetId( id + 10000 );
                pBitmap->Activate( true );
                pBitmap->RemoveStyle( sfsSHOW_HANDLES );
                if( m_pGrid->InsertToTableGrid( pBitmap ) )
                {
                    if( type == Constraint::primaryKey )
                    {
                        pBitmap->CreateFromXPM( key_p_xpm );
                    }
                    else
                        pBitmap->CreateFromXPM( key_f_xpm );
                    SetCommonProps( pBitmap );
                }
                else
                    delete pBitmap;
            }
        }
        else
        {
            // spacer
            wxSFShapeBase* pSpacer = new wxSFShapeBase();
            pSpacer->Activate( true );
            pSpacer->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
            if( pSpacer )
            {
                pSpacer->SetId( id + 10000 );
                pSpacer->Activate( true );
                pSpacer->RemoveStyle( sfsSHOW_HANDLES );
                if( m_pGrid->InsertToTableGrid( pSpacer ) )
                {
                    SetCommonProps( pSpacer );
                }
                else
                    delete pSpacer;
            }
        }
        // label
        FieldShape *pCol = new FieldShape();
        if( pCol )
        {
            pCol->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
            pCol->SetId( id + 10000 + 1 );
            pCol->Activate( true );
            pCol->RemoveStyle( sfsSHOW_HANDLES );
            if( m_pGrid->InsertToTableGrid( pCol ) )
            {
                SetCommonProps( pCol );
                pCol->GetFont().SetPointSize( 8 );
                pCol->SetText( field->GetFieldName() );
                pCol->SetField( field );
            }
            else
                delete pCol;
        }
        CommentFieldShape *comment_shape = new CommentFieldShape();
        if( comment_shape )
        {
            comment_shape->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
            comment_shape->SetId( id + 10000 + 2 );
            comment_shape->Activate( true );
            comment_shape->RemoveStyle( sfsSHOW_HANDLES );
            if( m_pGrid->InsertToTableGrid( comment_shape ) )
            {
                SetCommonProps( comment_shape );
                comment_shape->SetField( field );
                comment_shape->GetFont().SetPointSize( 8 );
                comment_shape->SetText( field->GetFieldProperties().m_comment );
            }
            else
                delete comment_shape;
        }
    }
    else
    {
        // label
        FieldShape *pCol = new FieldShape();
        if( pCol )
        {
            pCol->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
            pCol->SetId( id + 10000 );
            pCol->Activate( true );
            pCol->RemoveStyle( sfsSHOW_HANDLES );
            if( m_pGrid->InsertToTableGrid( pCol ) )
            {
                SetCommonProps( pCol );
                pCol->GetFont().SetPointSize( 8 );
                pCol->SetText( field->GetFieldName() );
                pCol->SetField( field );
            }
            else
                delete pCol;
        }
        FieldTypeShape *type_shape = new FieldTypeShape();
        if( type_shape )
        {
            type_shape->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
            type_shape->SetId( id + 10000 + 1 );
            type_shape->Activate( true );
            type_shape->RemoveStyle( sfsSHOW_HANDLES );
            if( m_pGrid->InsertToTableGrid( type_shape ) )
            {
                SetCommonProps( type_shape );
                type_shape->GetFont().SetPointSize( 8 );
                type_shape->SetText( field->GetFullType() );
                type_shape->SetField( field );
            }
            else
                delete type_shape;
        }
        CommentFieldShape *comment_shape = new CommentFieldShape();
        if( comment_shape )
        {
            comment_shape->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
            comment_shape->SetId( id + 10000 + 2 );
            comment_shape->Activate( true );
            comment_shape->RemoveStyle( sfsSHOW_HANDLES );
            if( m_pGrid->InsertToTableGrid( comment_shape ) )
            {
                SetCommonProps( comment_shape );
                comment_shape->GetFont().SetPointSize( 8 );
                comment_shape->SetText( field->GetFieldProperties().m_comment );
            }
            else
                delete comment_shape;
        }
    }
}

void MyErdTable::SetCommonProps(wxSFShapeBase* shape)
{
    shape->EnableSerialization( false );
    shape->SetStyle( sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
    shape->SetHAlign( wxSFShapeBase::halignLEFT );
    shape->SetVAlign( wxSFShapeBase::valignMIDDLE );
    shape->SetVBorder( 0 );
    shape->SetHBorder( 0 );
}

const DatabaseTable *MyErdTable::GetTable()
{
    return m_table;
}

wxSFTextShape *MyErdTable::GetLabel()
{
    return m_pLabel;
}

GridTableShape *MyErdTable::GetFieldGrid()
{
    return m_pGrid;
}

std::wstring &MyErdTable::GetTableName()
{
    return const_cast<std::wstring &>( m_table->GetTableName() );
}

void MyErdTable::DrawSelected(wxDC& dc)
{
    if( m_type == DatabaseView )
        wxSFRoundRectShape::DrawSelected( dc );
}
Thank you.
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxShapeFramework

Post by iwbnwif »

Is the layout being performed in the GridTableShape class?

If that class is derived from wxSFTextShape then that might be the problem as I think the layout is pretty basic.

I have always tended to overload a wxSF class with my own rendering code for anything more complex than a simple line of text. You might like to consider using wxHtmlDCRenderer in your ::DrawNormal etc. methods as this gives more flexibility with the content.

On the other hand it might be a bit slow if you are rendering a lot of 'tables' because there is no caching in wxSF AFAIK. This is something that I would like to look at some time too.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5420
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxShapeFramework

Post by ONEEYEMAN »

Hi,
No, the table is RoundRectShape. Just look at the code I posted.
The header is based n the wxSFGridShape which contains text shapes.

And yes - the layout is pretty basic, and the code should work.

Than you.

Code: Select all

#include "wxsf/GridShape.h"
#include "HeaderGrid.h"

HeaderGrid::HeaderGrid(void) : wxSFGridShape()
{
}

HeaderGrid::~HeaderGrid(void)
{
}

void HeaderGrid::DoChildrenLayout()
{
    if( !m_nCols || !m_nRows )
        return;
    wxSFShapeBase *pShape;
    wxRect currRect1, currRect2, maxRect0 = wxRect( 0, 0, 0, 0 ), maxRect1 = wxRect( 0, 0, 0, 0 );
    int nIndex = 0, nCol = 0, nRow = -1;
    wxRect maxRect;
    SerializableList::compatibility_iterator node = GetFirstChildNode();
    pShape = (wxSFShapeBase*) node->GetData();
    currRect1 = pShape->GetBoundingBox();
    if( ( pShape->GetHAlign() != halignEXPAND ) && ( currRect1.GetWidth() > maxRect0.GetWidth() ) )
        maxRect0.SetWidth( currRect1.GetWidth() );
    if( ( pShape->GetVAlign() != valignEXPAND ) && ( currRect1.GetHeight() > maxRect0.GetHeight() ) )
        maxRect0.SetHeight( currRect1.GetHeight() );
    node = node->GetNext();
    pShape = (wxSFShapeBase*) node->GetData();
    currRect2 = pShape->GetBoundingBox();
    if( ( pShape->GetHAlign() != halignEXPAND ) && ( currRect2.GetWidth() > maxRect1.GetWidth() ) )
        maxRect1.SetWidth( currRect2.GetWidth() );
    if( ( pShape->GetVAlign() != valignEXPAND ) && ( currRect2.GetHeight() > maxRect1.GetHeight() ) )
        maxRect1.SetHeight( currRect2.GetHeight() );
    for( size_t i = 0; i < m_arrCells.GetCount(); i++ )
    {
        pShape = (wxSFShapeBase*) GetChild( m_arrCells[i] );
        if( pShape )
        {
            if( nIndex++ % m_nCols == 0 )
            {
                nCol = 0; nRow++;
            }
            else
                nCol++;
            if( nCol == 0 )
                FitShapeToRect( pShape, wxRect( nCol * maxRect0.GetWidth() + ( nCol + 1 ) * m_nCellSpace, nRow * maxRect0.GetHeight() + ( nRow + 1 ) * m_nCellSpace,
                                            maxRect0.GetWidth(), maxRect0.GetHeight() ) );
            if( nCol == 1 )
                FitShapeToRect( pShape, wxRect( nCol * maxRect0.GetWidth() + ( nCol + 1 ) * m_nCellSpace, nRow * maxRect0.GetHeight() + ( nRow + 1 ) * m_nCellSpace,
                                            maxRect1.GetWidth(), maxRect1.GetHeight() ) );
        }
    }
}
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxShapeFramework

Post by iwbnwif »

Sorry, please clarify what is not being painted correctly.

I can see that the header "owners" has a solid blue background - is that test code or is that the problem?

I have not used wxSFGridShape or wxSFFlexGridShape, so it maybe that I can't help you. I generally find that compound shapes in wxSF don't behave as expected, so mostly do my own rendering.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5420
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxShapeFramework

Post by ONEEYEMAN »

Hi,
Compare leagues table with owners table.
Leagues is round shaped and everything is inside.
Owners header is rect shaped and its not inside the table.

Leagues is correct and owners is not.

Thank you.
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxShapeFramework

Post by iwbnwif »

I suspect it is because of your ::DrawNormal code:

Code: Select all

void MyErdTable::DrawNormal(wxDC &dc)
{
    if( this->m_fSelected && m_type == DatabaseView )
    {
        m_header->SetFill( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ) );
    }
    wxSFRoundRectShape::DrawNormal( dc );
    DrawDetail( dc );
}
If the item is selected then you are instructing the header to be filled with the system highlight colour. The wxSFTextShapes within the header will be rectangles and the whole rectangle will be filled, not clipped to the parent shape's boundary.

Try commenting out the m_header->SetFill line to confirm this.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5420
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxShapeFramework

Post by ONEEYEMAN »

Hi,
OK, I will tonight.
And if yes - how do I fix it?
Should I set the text background as well?

Thank you.
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxShapeFramework

Post by iwbnwif »

Do you want to change the background of the header part when the entity is selected?

Easiest way would be to set the fill of MyErdTable which is derived from wxSFRoundRectShape. Then keep the background of the header text transparent.

If you want to change just the colour of the header part, then you will need some custom drawing code - probably using a path with arcs etc. which implies using a graphics context. Again, I would do that in MyErdTable::DrawNormal because I am not sure if wxSFGridShape would change size depending on its contents. Leave the background of the grid and text shapes transparent.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5420
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxShapeFramework

Post by ONEEYEMAN »

Hi,
When the table is selected I want to change the color of only the header.

Yes, it shouold be done at MyErdTable::DrawNormal(), just like I'm doing it right now.

I will do the test tonight and post the results and then we will talk about possible solutions.

Thank you.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5420
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxShapeFramework

Post by ONEEYEMAN »

Hi,
Commenting out that line I gt an attached results.

Thank you.
issue1.PNG
issue1.PNG (5.72 KiB) Viewed 1628 times
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: wxShapeFramework

Post by iwbnwif »

So it is now painting okay, just without the highlight?

As I mentioned, the simplest thing is to colour the whole shape using something like:

Code: Select all

    if( m_fSelected && m_type == DatabaseView )
        SetFill( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ) );
    else
        SetFill( wxBrush( wxColour( 210, 225, 245 ) ) );
If you really want only the header part to be coloured, the best way is probably to draw a filled path over the top of the default shape. Something like the following *might* work, but it is completely untested :!:

Code: Select all

void MyErdTable::DrawNormal(wxDC &dc)
{
    wxSFRoundRectShape::DrawNormal( dc );

    if( m_fSelected && m_type == DatabaseView )
    {
        wxGraphicsContext *gc = dc.GetGraphicsContext();
        
        if (gc)
        {
            wxGraphicsPath path = pgc->CreatePath();
            path.MoveToPoint( ... );
            path.ArcToPoint( ... );
            path.LineToPoint( ... );
            path.ArcToPoint( ... );
            path.CloseSubpath();
            
            pgc->SetBrush( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ) );
            pgc->SetPen( wxTRANSPARENT_PEN) ;
            pgc->StrokePath( path );
        }
    }
    DrawDetail( dc );
}
You will need to use Conv2Point(GetAbsolutePosition()) to work out the origin, along with GetRect and GetRadius to calculate the points. This is because IIRC the wxDC / wxGCDC is for the whole canvas, not just the shape.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
Post Reply