
djardjar
|
Je sais qu'il n'est pas possible de dessiner dans un WxWidget avec la
SDL, mais cependant j'ai réussi avec opengl. Maintenant ce que je me
demande, c'est comment on fait pour intercepter les évenements du
clavier dans une fenetre WxWidget avec la SDL... J'utilise juste la SDL
pour les outils qu'elle propose en dehors de l'affichage ! Voici mon
code plus complet (j'avance entre temps):
#include <cassert>
#include <cmath>
#include <wx/wx.h>
#include <wx/glcanvas.h>
#include <wx/notebook.h>
#include <SDL/sdl.h>
class GL_Window : public wxGLCanvas
{
public:
GL_Window(float c, wxWindow* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style=0,
const
wxString& name="GLCanvas", int* attribList = 0, const
wxPalette& palette = wxNullPalette)
: wxGLCanvas(parent, id, pos,
size, style, name, attribList, palette), c_(c), rotate_(c) {}
virtual ~GL_Window() {}
void draw() {
rotate_ += 0.01;
SetCurrent();
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, (GLint)200, (GLint)200);
glColor3f(1.0, c_, c_);
glBegin(GL_POLYGON);
glVertex3f(-0.5, -0.5, 5*cos(rotate_));
glVertex3f(-0.5, 0.5, 5*cos(rotate_));
glVertex3f(0.5, 0.5, -5*cos(rotate_));
glVertex3f(0.5, -0.5, -5*cos(rotate_));
glEnd();
SwapBuffers();
}
void OnIdle(wxIdleEvent& event) {
SDL_Event SDLEvent;
/* Check for events */
if (SDL_PollEvent (&SDLEvent))
{
switch (SDLEvent.type)
{
case SDL_KEYDOWN:
wxMessageBox("Hello", "Hello", wxOK);
break;
default:
break;
}
}
draw();
event.RequestMore();
}
private:
float c_;
float rotate_;
DECLARE_EVENT_TABLE();
};
class MyApp: public wxApp
{
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxFrame* frame = new wxFrame((wxFrame *)NULL, -1, "Hello GL World", wxPoint(50,50), wxSize(640,480) );
GL_Window* MyGLCanvas = new GL_Window(1, frame, -1,
wxPoint(-1,-1), wxSize(640,480), wxNO_BORDER, "some text");
frame->ShowFullScreen(TRUE, wxFULLSCREEN_ALL);
frame->Show(TRUE);
return TRUE;
}
BEGIN_EVENT_TABLE(GL_Window, wxGLCanvas)
EVT_IDLE(GL_Window::OnIdle)
END_EVENT_TABLE()
|