wxDev.fr, le portail francophone consacré à wxWidgets ! ( The french portal for wxWidgets )  
Esp. membre
Recheche rapide



Recherche avancée
Statistiques
Membres inscrits :2359

Membres en ligne : 0
Invités en ligne : 5

Valid XHTML 1.0 Transitional

Valid CSS2

Menu forum (navigation):
Pages: 1  
 
Accueil » Accueil forums » Développement C/C++
» Problème avec wxScrolledWindow
Conversation (Résolue) : Problème avec wxScrolledWindow
07-06-2010 10:01:23  Problème avec wxScrolledWindow #1
yannp (Membre)
Inscrit le : 02-06-2010
Messages: 61
Snippets: 0
Tutoriels: 0
Hors ligne
Bonjour à tous,

J'ai un souci. Je voudrais "dessiner" sur un wxScrolledWindow et .... ca ne marche pas, du moins, les "griboullis" n'apparaissent pas !!!
Si quelqu'un peut m'aider !!! voici mon code :

.h :

Code:

 
#include <wx/wx.h>
#include <wx/notebook.h>
 
class winComposition : public wxMDIChildFrame
{
    public:
        winComposition (wxMDIParentFrame *parent, const wxString& title);
        ~winComposition();
 
        void OnPaint (wxPaintEvent & event);
 
    protected:
        wxPanel* m_panel44;
        wxPanel* m_panel45;
        wxScrolledWindow* Affichagepartition;
        wxNotebook* m_notebook4;
        wxPanel* m_panel47;
        wxPanel* m_panel48;
        wxStatusBar* m_statusBar1;
    DECLARE_EVENT_TABLE()
};
 

.cpp :

Code:

 
#include <wx/msgdlg.h>
#include <wx/dcbuffer.h>
 
#include "windowsComposition.h"
#include "general.h"
 
BEGIN_EVENT_TABLE(winComposition, wxMDIChildFrame)
END_EVENT_TABLE()
 
 
winComposition::winComposition(wxMDIParentFrame *parent, const wxString& title)
       : wxMDIChildFrame(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
                         wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
{
 
    this->SetSizeHints( wxSize( 500,300 ), wxDefaultSize );
 
    wxBoxSizer* bSizer12;
    bSizer12 = new wxBoxSizer( wxVERTICAL );
 
    bSizer12->SetMinSize( wxSize( 500,300 ) );
    wxBoxSizer* bSizer13;
    bSizer13 = new wxBoxSizer( wxHORIZONTAL );
 
    bSizer13->SetMinSize( wxSize( 500,300 ) );
    m_panel44 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 200,-1 ), 0 );
    m_panel44->SetMinSize( wxSize( 200,-1 ) );
    m_panel44->SetMaxSize( wxSize( 200,-1 ) );
 
    bSizer13->Add( m_panel44, 0, wxALL|wxEXPAND, 1 );
 
    m_panel45 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 200,-1 ), wxTAB_TRAVERSAL );
    m_panel45->SetMinSize( wxSize( 200,-1 ) );
 
    wxBoxSizer* bSizer18;
    bSizer18 = new wxBoxSizer( wxVERTICAL );
 
    Affichagepartition = new wxScrolledWindow( m_panel45, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
    Affichagepartition->SetScrollRate( 5, 5 );
    Affichagepartition->SetMinSize( wxSize( 300,-1 ) );
    Affichagepartition->SetBackgroundColour( wxColour( 255, 255, 255 ) );
 
    bSizer18->Add( Affichagepartition, 1, wxALL|wxEXPAND, 1 );
 
    m_notebook4 = new wxNotebook( m_panel45, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
    m_notebook4->SetMaxSize( wxSize( -1,100 ) );
 
    m_panel47 = new wxPanel( m_notebook4, wxID_ANY, wxDefaultPosition, wxSize( -1,80 ), wxTAB_TRAVERSAL );
    m_panel47->SetMinSize( wxSize( -1,80 ) );
    m_panel47->SetMaxSize( wxSize( -1,80 ) );
 
    m_notebook4->AddPage( m_panel47, wxT("a page"), true );
    m_panel48 = new wxPanel( m_notebook4, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
    m_notebook4->AddPage( m_panel48, wxT("a page"), false );
 
    bSizer18->Add( m_notebook4, 0, wxEXPAND | wxALL, 5 );
 
    m_panel45->SetSizer( bSizer18 );
    m_panel45->Layout();
    bSizer13->Add( m_panel45, 1, wxALL|wxEXPAND, 1 );
 
    bSizer12->Add( bSizer13, 1, wxALL|wxEXPAND|wxFIXED_MINSIZE, 1 );
 
    this->SetSizer( bSizer12 );
    this->Layout();
    m_statusBar1 = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
 
    SetSizeHints(200, 200);
}
 
winComposition::~winComposition()
{
 
}
 
void winComposition::OnPaint (wxPaintEvent & event)
{
    wxPaintDC dc (this->Affichagepartition) ;
 
    dc.DrawLine(0, 0, 200, 200);
    dc.DrawText(_T("Ceci est un essai"), 10, 10);
    dc.DrawCircle(300,70,50) ;
}
 
07-06-2010 10:28:06  Re: Problème avec wxScrolledWindow #2
Sem (Membre)
Inscrit le : 31-05-2008
Messages: 64
Snippets: 0
Tutoriels: 0
Hors ligne
bonjour,
pourquoi ne pas surcharger wxScrolledWindow plutôt?
Quelquechose comme cela :

Code wxWidgets:

public partition : public wxScrolledWindow
{
public:
   partition(wxWindow *parent,
                     wxWindowID winid = wxID_ANY,
                     const wxPoint& pos = wxDefaultPosition,
                     const wxSize& size = wxDefaultSize,
                     long style = wxScrolledWindowStyle,
                     const wxString& name = wxPanelNameStr);
   void OnDraw( wxDC &dc );
};
 
partition::partition(wxWindow *parent,
                     wxWindowID winid,
                     const wxPoint& pos,
                     const wxSize& size,
                     long style,
                     const wxString& name) :
wxScrolledWindow(parent, winid, pos, size, style, name)
{
}
 
void partition::OnDraw(wxDC &dc )
{
    dc.DrawLine(0, 0, 200, 200);
    dc.DrawText(_T("Ceci est un essai"), 10, 10);
    dc.DrawCircle(300,70,50) ;
}


Cela dit il te manque peut-être simplement le

Code wxWidgets:

 
PrepareDC(dc);
 

dans ton OnPaint pour fonctionner.


Sem

Dernière modification par Sem (07-06-2010 10:33:35)

07-06-2010 11:19:10  Re: Problème avec wxScrolledWindow #3
Xaviou (Administrateur)
Lieu: Annecy (74)
Inscrit le : 27-08-2007
Messages: 1390
Snippets: 25
Tutoriels: 6
Site web
Hors ligne
Sem:
Cela dit il te manque peut-être simplement le

Code wxWidgets:

 
PrepareDC(dc);
 

dans ton OnPaint pour fonctionner.
Ou tout simplement, il manque l'entrée de la table d'événements correspondant au OnPaint :

Code wxWidgets:

BEGIN_EVENT_TABLE(winComposition, wxMDIChildFrame)
    EVT_PAINT(winComposition::OnPaint)
END_EVENT_TABLE()


@+
Xav'

Le nouveau portail wxWidgets francophone : www.wxdev.fr
Ben en fait, vous y êtes déjà... et effectivement, depuis le temps, ce n'est plus tellement nouveau....
07-06-2010 11:34:26  Re: Problème avec wxScrolledWindow #4
Sem (Membre)
Inscrit le : 31-05-2008
Messages: 64
Snippets: 0
Tutoriels: 0
Hors ligne
bonjour,
exacte, j'avais même pas fait attention. Cela dit pour faire un canvas scrollable, je pense que surcharger wxSrolledWindow avec le OnDraw reste plus propre.
a+
Sem
07-06-2010 11:37:00  Re: Problème avec wxScrolledWindow #5
yannp (Membre)
Inscrit le : 02-06-2010
Messages: 61
Snippets: 0
Tutoriels: 0
Hors ligne
Ok parfait, ça marche nickel !!! vous êtes trop fort ..
J'ai cependant encore une petite demande : je voudrais y ajouter des scrollbars !!!

J'avais rajouté une donnée membre de type wxScrollBar dans la classe partition. Alors ca marche... Mais je me demandais si wxScrollWindows ne gère pas automatiquement les scrollbars d'où mon :

"this->SetScrollbar (20, 20, 50, 50);"

(et en commentaire l'ancien code)

Code:

 
partition::partition(   wxWindow *parent, wxWindowID winid,
                        const wxPoint& pos,
                        const wxSize& size,
                        long style,
                        const wxString& name) :wxScrolledWindow(parent, winid, pos, size, style, name)
{
    this->SetScrollbar (20, 20, 50, 50);
    /*
    scrollBar= new wxScrollBar( parent, WINDOWS_COMPOSITION_SCROLLBAR, wxPoint (parent->GetwxDefaultPosition, wxDefaultSize,
                                wxSB_HORIZONTAL,
                                wxDefaultValidator, _T("scrollBar"));
    //scrollBar->SetScrollbar (20, 20, 50, 50);
    */
    SetMinSize( wxSize( 300,-1 ) );
    SetBackgroundColour( wxColour( 255, 255, 255 ) );
}
 

Encore merci !!!
07-06-2010 11:44:53  Re: Problème avec wxScrolledWindow #6
Sem (Membre)
Inscrit le : 31-05-2008
Messages: 64
Snippets: 0
Tutoriels: 0
Hors ligne
coucou,
tu n'as pas à gérer les scrollsbar de cette façon. La scrolledwindow va directement s'adapter aux tailles souhaiter ( par exemple : tu as une fenêtre de 100 pixels par 100 pixels, si tu y dessines une image de 200 x 200, il y aura automatiquement les scrollsbar).
Pourque cela fonctionne, tu dois indiquer la vitesse du scroll ( SetScrollRate ) et la taille virtuelle ( dans notre exemple ca aurait été la taille de l'image par exemple ).

Code wxWidgets:

 
partition::partition(   wxWindow *parent, wxWindowID winid,
                        const wxPoint& pos,
                        const wxSize& size,
                        long style,
                        const wxString& name) :
wxScrolledWindow(parent, winid, pos, size, style, name)
{
   SetScrollRate( 10, 10 );
   SetVirtualSize( 600, 600 ); // Si tu veux que ton dessin soit sur 600/600
   // Si la fenetre ( size ) est plus petite que cela, ca fera des barres de scrolls
 
    SetBackgroundColour( wxColour( 255, 255, 255 ) );
}
 


Sem
07-06-2010 13:57:53  Re: Problème avec wxScrolledWindow #7
yannp (Membre)
Inscrit le : 02-06-2010
Messages: 61
Snippets: 0
Tutoriels: 0
Hors ligne
Merci.. Encore une fois ça marche ...

J'ai encore une question ... ou du moins un problème ... Lorsque je fais défiler le dessin à l'aide des scrollbars, le dessin s'affiche de manière  "saccadé" visiblement il faut surement le rafraichir ou le réafficher ... Comment faut-il gérer tout cela ?
Merci d'avance ...
07-06-2010 14:16:16  Re: Problème avec wxScrolledWindow #8
Sem (Membre)
Inscrit le : 31-05-2008
Messages: 64
Snippets: 0
Tutoriels: 0
Hors ligne
coucou,
je pense tu parles du problème de clignotement ? As tu essayé de dessiner en deux temps ?

Code wxWidgets:

void partition::OnDraw(wxDC &dc)
{
   wxMemoryDC MemoryDC;
 
   MemoryDC.DrawLine(0, 0, 200, 200);
   MemoryDC.DrawText(_T("Ceci est un essai"), 10, 10);
   MemoryDC.DrawCircle(300,70,50) ;
 
   // 400x400 a remplacer en fonction de la taille du dessin
   dc.Blit(0, 0, 400, 400, &MemoryDC, 0, 0);
}


Avec ce système, on dessine en mémoire, et a la fin quand c'est dessiné, on copie avec Blit:
voir la doc ici.
Sem

Dernière modification par Sem (07-06-2010 14:32:37)

07-06-2010 14:25:07  Re: Problème avec wxScrolledWindow #9
yannp (Membre)
Inscrit le : 02-06-2010
Messages: 61
Snippets: 0
Tutoriels: 0
Hors ligne
Ok parfait ...

Ca marche... Je mets comme résolu !!!

Merci
Menu forum (navigation):
Pages: 1  
 
Accueil » Accueil forums » Développement C/C++
» Problème avec wxScrolledWindow