Simulate photoprint open source program

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
dkaip
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 202
Joined: Wed Jan 20, 2010 1:15 pm

Simulate photoprint open source program

Postby dkaip » Tue May 29, 2018 6:45 pm

Hello. I am trying to simulate photoprint open source program with wxWidgets framework.
I have a class iconsPanel to see on wxPanel images in matrix. So iconsPanel is very simple.
Next class is photoprint derived from wxDialog, and then class photoprintDialog from photoprint in wich i have iconsPanel* panel;

Program works 50% well. Times all pictures are ok, times i have not pictures at all.

I must have error in class design about windows relationships.
Any idea???

Code: Select all

class iconsPanel : public wxPanel
{
   private:
   
   protected:
      wxBoxSizer* bSizer4;
      
      // Virtual event handlers, overide them in your derived class
      virtual void OnPaint1( wxPaintEvent& event ) { event.Skip(); }
      
   
   public:
      wxStaticBitmap* m_bitmap1;
      
      iconsPanel( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 197,88 ), long style = wxTAB_TRAVERSAL );
      ~iconsPanel();
   
};

iconsPanel::iconsPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style )
{
   this->SetBackgroundColour( wxColour( 0, 255, 10 ) );
   
   bSizer4 = new wxBoxSizer( wxVERTICAL );
   
   m_bitmap1 = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
   bSizer4->Add( m_bitmap1, 1, wxALL|wxEXPAND, 5 );
   
   
   this->SetSizer( bSizer4 );
   this->Layout();
   
   // Connect Events
   this->Connect( wxEVT_PAINT, wxPaintEventHandler( iconsPanel::OnPaint1 ) );
}


class photoprint : public wxDialog
{
   private:
   
   protected:
      wxBitmapButton* m_bpButton1;
      wxBitmapButton* m_bpButton3;
................

      wxBoxSizer* bSizer19;
      wxStaticText* m_staticText1;
      wxSpinCtrl* m_spinCtrl9;
      wxStaticText* m_staticText2;
      wxSpinCtrl* m_spinCtrl10;
      wxStaticText* m_staticText3;
      wxSpinCtrl* m_spinCtrl11;

}




class photoprintDialog: public photoprint
{
public:
    photoprintDialog(wxDialog *dlg);
    ~photoprintDialog();
private:
    virtual void OnClose(wxCloseEvent& event);
    void OnPaint( wxPaintEvent& event );

    iconsPanel* panel;
    int screenDX,screenDY;
    float w,h;
    int nx,ny;
    int gapx,gapy;
    int Lm,Tm;
    int a,b;
    int page;
    void SetPage();

    double fa;

    int paperWidth,paperHight;
    int paperSizeDX,paperSizeDY;

    virtual void OnColumns( wxSpinEvent& event );
    virtual void OnGapX( wxSpinEvent& event );
    virtual void OnRows( wxSpinEvent& event );
    virtual void OnGapY( wxSpinEvent& event );
    virtual void OnPage( wxCommandEvent& event );
    virtual void on_a( wxSpinEvent& event );
    virtual void on_b( wxSpinEvent& event ) ;

    wxString& gallery;

};




photoprintDialog::photoprintDialog(wxDialog *dlg)
    : photoprint(dlg)
{

    wxInitAllImageHandlers();

    panel=new iconsPanel(this,wxID_ANY,wxDefaultPosition,wxSize(screenDX,screenDY));

    wxDisplay display(wxDisplay::GetFromWindow(this));
    wxRect screen = display.GetClientArea();

    SetBackgroundStyle(wxBG_STYLE_PAINT );
    Bind(wxEVT_PAINT, &photoprintDialog::OnPaint, this);
    bSizer12->Add(panel,0, wxALL|wxEXPAND, 0 );

    wxSize bs=bSizer8->GetSize();
    screenDX=screen.GetWidth()-bs.GetWidth();
    bs=bSizer19->GetSize();
    screenDY=screen.GetHeight()-bs.GetHeight();

    screenDY-=60;

    nx=1; ny=1; a=b=0; gapx=gapy=5;

    paperWidth=210; paperHight=297;

    Maximize();

    SetPage();

    Refresh();
    Update();

}

void photoprintDialog::SetPage()
{
    int pages=images.size()/(nx*ny)+1;

    for(int i=0; i<pages; i++)
        m_choice1->Append(wxString::Format(wxT("%d"),i+1));
    }
    m_choice1->SetSelection(0);
}

void photoprintDialog::OnPaint( wxPaintEvent& event )
{
    wxPaintDC dc(panel->m_bitmap1);
    dc.Clear();

    if (paperWidth/screenDX<=paperHight/screenDY)
        fa=(float)screenDY/paperHight;
    else
        fa=(float)screenDX/paperWidth;

    int paperSizeDX=fa*paperWidth;
    int paperSizeDY=fa*paperHight;

    int Lm=(screenDX-paperSizeDX)/2.0;
    int Tm=(screenDY-paperSizeDY)/2.0;

    dc.DrawRectangle(Lm,Tm,paperSizeDX,paperSizeDY);

    int xi,yi,xj,yj;

    w=(float)(paperSizeDX-(ny-1)*gapx)/ny-2.0*a;
    h=(float)(paperSizeDY-(nx-1)*gapy)/nx-2.0*b;

    wxString image;

    int k=nx*ny*(page-1);

    for(int i=0; i<nx; i++)
        for(int j=0; j<ny; j++)
        {
            xi=a+j*(w+gapx*1.0);
            xj=xi+w;
            yi=b+i*(h+gapy*1.0);
            yj=yi+h;

                image=images[k++];

                if(wxFileName::Exists(image))
                {
                    wxImage img(image);
                    int bmpDX=img.GetWidth();
                    int bmpDY=img.GetHeight();

                    float f;
                    if ((float)w*1.0/bmpDX<=(float)h*1.0/bmpDY)
                        f=(float)w/bmpDX;
                    else
                        f=(float)h/bmpDY;

                    //new image dimensions
                    float new_w=(float)f*bmpDX-2*a;
                    float new_h=(float)f*bmpDY-2*b;

                    // distanses from left and to in rect
                    float aa=(w-new_w)/2.0;
                    float bb=(h-new_h)/2.0;

                    wxImage scaled=img.Scale(new_w,new_h,wxIMAGE_QUALITY_HIGH);
                    dc.DrawBitmap(wxBitmap(scaled),Lm+aa+xi,Tm+bb+yi,false);
                }
            }
        }
}

------

void photoprintDialog::OnPage( wxCommandEvent& event )
{
    page=m_choice1->GetSelection()+1;
    Refresh();
    Update();
}


User avatar
doublemax
Moderator
Moderator
Posts: 12795
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Simulate photoprint open source program

Postby doublemax » Tue May 29, 2018 8:30 pm

It's a little hard to follow, but there are at least issues with the paint event handler.

Code: Select all

this->Connect( wxEVT_PAINT, wxPaintEventHandler( iconsPanel::OnPaint1 ) );
This still connects to the empty paint event handler, which is not overwritten anywhere. And the paint event handler itself *must* create a wxPaintDC, even it you don't use it.

Code: Select all

void photoprintDialog::OnPaint( wxPaintEvent& event )
{
    wxPaintDC dc(panel->m_bitmap1);
You can't do this. In a paint event handler you are only allowed to draw onto the window that generated the event. You can't just paint onto a another window here.

In addition to that, m_bitmap1 is a wxStaticBitmap. A wxStaticBitmap draws itself, you don't have to mess with its paint event handler.

Try to fix these things and see if it improves the situation.

And maybe post a screenshot, so i can get an idea of how it should look like.
Use the source, Luke!

dkaip
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 202
Joined: Wed Jan 20, 2010 1:15 pm

Re: Simulate photoprint open source program

Postby dkaip » Thu Jun 14, 2018 2:17 pm

Sorry for my delay... Here is a photoprint ... in linux. I never use windows ...
ep.png
ep.png (26.11 KiB) Viewed 195 times


Return to “C++ Development”

Who is online

Users browsing this forum: Google [Bot] and 27 guests