Dessiner avec wxWidgets

cs_satellite34 Messages postés 688 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 2 juin 2006 - 26 juil. 2005 à 01:51
cs_satellite34 Messages postés 688 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 2 juin 2006 - 27 juil. 2005 à 11:50
salut, je voudrai savoir comment dessinner un point aux coordonnées x,y avec wxWidgets
voila mon code:

void Mp3PlayerFrm::spectrum01 (wxCommandEvent& event)
{
const float *spectrumData = FSOUND_DSP_GetSpectrum(); //recupere les 512 cannaux separés
int spectrumValue;
wxColour MaCouleur(0,0,255);
wxPen MonCrayon(MaCouleur,10,wxSOLID);

for ( int i = 0; i < 512; ++i )
{
spectrumValue = int( 100 * spectrumData[ i ] );
m_DC->SetPen(MonCrayon);
m_DC->DrawRectangle(500, 100, 300, 250);
m_DC->DrawPoint(i, 100*spectrumValue);
}
}


/*/////////////////////////////////////////////////////////////////////////////////////////////////////
*Clik sur spectrum dans le menu
*//////////////////////////////////////////////////////////////////////////////////////////////////////


void Mp3PlayerFrm::MnuSpectrum(wxCommandEvent& event)
{
FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), true);
if (!FSOUND_DSP_GetActive(FSOUND_DSP_GetFFTUnit()))
{wxString msg;
msg.Printf( _T("Oups le spectrum n' est pas actif\nLe spectrum ne fonctionne que lorsqu' un stream est ouvert\nOuvrez un fichier"));
wxMessageBox(msg, _T("Infos"), wxOK | wxICON_EXCLAMATION | wxCENTRE, this);return;
}//si le spectrum est actif....
this->SetSize(0, 0, 800, 380);
this->Center();
spectrum01(event);
}

en fait, comme vous aurez pu le remarquer c'est pour afficher un spectrum.

donc , 0 erreurs de compile mais rien qui se dessinne

si vous pourriez m'expliquer comment dessinner ds une fonction void Mp3PlayerFrm::spectrum01 (wxCommandEvent& event) ca serai super cool car la je craque.

merci pour votre aide

++

6 réponses

fredcl Messages postés 547 Date d'inscription mercredi 8 janvier 2003 Statut Membre Dernière intervention 7 octobre 2007 1
26 juil. 2005 à 15:51
Bonjour,



Ce code devrais logiquement fonctionner, mais il faut surement l'adapter plus précisément.

// Attention wxWindows correspont à la classe ancétre si

// Mp3PlayerFrm est un wxFrame il faut mettre wxFrame à la place de wxWindow



BEGIN_EVENT_TABLE(Mp3PlayerFrm, wxWindow)

EVT_PAINT(Mp3PlayerFrm::OnPaint)

END_EVENT_TABLE()



void Mp3PlayerFrm::OnPaint(wxPaintEvent& event)

{

int spectrumValue;



// Préparation du Device Context et du pinceaux

wxPaintDC dcPaint(this);

wxColour MaCouleur(0,0,255);

wxPen MonCrayon(MaCouleur,10,wxSOLID);



dcPaint.BeginDrawing();

dcPaint.SetPen(MonCrayon);



// recupere les 512 cannaux separés

const float *spectrumData = FSOUND_DSP_GetSpectrum();



for ( int i = 0; i < 512; ++i )

{

spectrumValue = int( 100 * spectrumData[ i ] );

dcPaint.SetPen(MonCrayon);

dcPaint.DrawRectangle(500, 100, 300, 250);

dcPaint.DrawPoint(i, 100*spectrumValue);

}



dcPaint.SetPen(wxNullPen);

dcPaint.SetBrush(wxNullBrush);

dcPaint.EndDrawing();

}





A+



FredCL
0
cs_satellite34 Messages postés 688 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 2 juin 2006 1
26 juil. 2005 à 16:03
oki, merci

mais je veux pas faire un paintevent
j'ai réussi ce que je voulais faire mais le truk c'est que g un bugg d'affichage

#include "Mp3PlayerFrm.h"


/*/////////////////////////////////////////////////////////////////////////////////////////////////////
*Clik sur spectrum dans le menu
*//////////////////////////////////////////////////////////////////////////////////////////////////////


void Mp3PlayerFrm::MnuSpectrum(wxCommandEvent& event)
{
FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), true); //active le spectrum.....

if (!FSOUND_DSP_GetActive(FSOUND_DSP_GetFFTUnit())) //si le spectre est pas actf...
{wxString msg;
msg.Printf( _T("Oups le spectrum n' est pas actif\nLe spectrum ne fonctionne que lorsqu' un stream est ouvert\nOuvrez un fichier"));
wxMessageBox(msg, _T("Infos"), wxOK | wxICON_EXCLAMATION | wxCENTRE, this);return;
}//si le spectrum est actif....

wxWindowDC dc(spectrWnd); //creer un device context sur spectrWnd...
spectrWnd->Show(true); //rend visible spectrWnd...
DessineSpectre(dc);


}


/*/////////////////////////////////////////////////////////////////////////////////////////////////////
*dessine le spectrum ds le device context
*//////////////////////////////////////////////////////////////////////////////////////////////////////


void Mp3PlayerFrm::DessineSpectre(wxDC& dc)
{
//dessin du spectre.....
const float *spectrumData = FSOUND_DSP_GetSpectrum(); //recupere les 512 cannaux separés...
int spectrumValue;

wxColour MaCouleurVerte(0,255,0);
wxPen MonCrayonVert(MaCouleurVerte,6,wxSOLID);
dc.BeginDrawing();
dc.SetPen(MonCrayonVert);
for ( int i = 0 ; i < 512 ; i++ )
{
spectrumValue = int(512 * (spectrumData[ i ] + spectrumData[ i +1 ] + spectrumData[ i+2 ] + spectrumData[ i+3 ] + spectrumData[ i+4 ] )) / 5;
dc.DrawPoint(i+2, 100-spectrumValue); //dessine le spectre...
}
dc.SetPen(wxNullPen);
dc.SetBrush(wxNullBrush);
dc.EndDrawing();
}


/*////////////////////////////////////////////////////////////////////////////////////////////////////////
*timer spectre
*////////////////////////////////////////////////////////////////////////////////////////////////////////


void Mp3PlayerFrm::OnTimerSpectr(wxTimerEvent& event)
{
wxWindowDC dc(spectrWnd); //creer un device context sur spectrWnd...
dc.Clear(); //clear le device context
DessineSpectre(dc);
}
0
cs_satellite34 Messages postés 688 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 2 juin 2006 1
26 juil. 2005 à 19:46
c good ca marchouille!

thx all
0
cs_satellite34 Messages postés 688 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 2 juin 2006 1
27 juil. 2005 à 10:27
yop , une petite question autre que sur le dessin:

EVT_COMMAND_SCROLL_BOTTOM(ID_SLIDER, Mp3PlayerFrm::WxSliderBottom)

void Mp3PlayerFrm::WxSliderBottom(wxScrollEvent& event)
{
WxAvanceClick(event);
}

EVT_COMMAND_SCROLL_BOTTOM ne marche jamais!!!!!!!!!!!!!

WxSlider = new wxSlider(this, ID_SLIDER, 0, 0, 10, wxPoint(45, 220), wxSize(250, 20), wxSL_HORIZONTAL);
WxSlider->SetValue(0);

la source http://www.cppfrance.com/code.aspx?ID=32901
j' oublie qque choze ou quoi?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
fredcl Messages postés 547 Date d'inscription mercredi 8 janvier 2003 Statut Membre Dernière intervention 7 octobre 2007 1
27 juil. 2005 à 11:00
J'ai pas trop le temps de regarder plus que ça mais voici un exemple approchant avec l'événement EVT_SCROLLWIN



EVT_SCROLLWIN(wxIrcDisplay::OnScroll)



void wxIrcDisplay::OnScroll(wxScrollWinEvent& event)

{

int newPos;

int oldPos = GetScrollPos(wxVERTICAL);



if (event.GetEventType() == wxEVT_SCROLLWIN_TOP)

newPos = 0;

else if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM)

newPos = lineCount;

else if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP)

newPos = oldPos - 1;

else if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN)

newPos = oldPos + 1;

else if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP)

newPos = oldPos - linesDisplay;

else if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN)

newPos = oldPos + linesDisplay;

else if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE)||


(event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK))

newPos = event.GetPosition();

else

return;



SetScrollPos(wxVERTICAL, newPos);

newPos = GetScrollPos(wxVERTICAL);

if (oldPos != newPos)

{

SetTopLine(newPos);

Refresh();

}

event.Skip();

}



En l'adaptant à l'événement voulu ça devrais fonctionner



A+



FredCL
0
cs_satellite34 Messages postés 688 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 2 juin 2006 1
27 juil. 2005 à 11:50
thanx, yu're a chief
0
Rejoignez-nous