Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
09-28-2005, 04:40 AM
#1
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Rep:
Need book/good tut on wxWidgets. Know of any?
That's what I need (for free, of course).
Tuts at the official site are small, and therefore bad.
I need to make a form with 3 buttons on the left and an OpenGL window on the right.
Anyone knows of any good wxWidgets tut(s)?
Thanks.
09-28-2005, 11:04 AM
#2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep:
Re: Need book/good tut on wxWidgets. Know of any?
Quote:
Originally posted by kornerr
Tuts at the official site are small, and therefore bad.
Yes, that maybe true, but there's a quite complete collection of example programs with commented sources. This helps a lot, but you'll need to be familiar with C++ (or python).
Also, the API-documentation is rather terse, but it is complete.
09-29-2005, 09:40 AM
#3
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Original Poster
Rep:
Yahoo! I got it! Again I found myself REALLY stupid!
I didn't understand the use of sizers at first... but they are VERY important here.
So here's an easy (now
) code for a frame with 2 buttons on the left and
an OpenGL window on the right.
window icon (remove ".jpg"):
sample.xpm.jpg
basic.h:
Code:
#ifndef BASIC_H
#define BASIC_H
#include <wx/wx.h>
#include <wx/glcanvas.h>
#include "sample.xpm"
class MyApp: public wxApp {
public:
virtual bool OnInit();
};
class TestGLCanvas: public wxGLCanvas {
public:
TestGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = _T("TestGLCanvas"), int *gl_attrib = NULL);
~TestGLCanvas(){};
void OnPaint(wxPaintEvent& event);
void OnSize(wxSizeEvent& event);
void OnMouseEvent(wxMouseEvent& event);
private:
DECLARE_EVENT_TABLE()
};
class BasicPanel: public wxPanel {
public:
BasicPanel (wxFrame* parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style);
~BasicPanel ();
private:
TestGLCanvas *m_canvas;
};
class BasicFrame: public wxFrame {
public:
BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height);
~BasicFrame();
BasicPanel *panel;
void OnExit (wxCommandEvent &event);
private:
DECLARE_EVENT_TABLE()
};
#endif
basic.cpp:
Code:
#include "basic.h"
#include <iostream>
using namespace std;
static void draw1() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
//----
glPopMatrix();
glFlush();
}
static void Init(void) {
}
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit() {
BasicFrame *frame = new BasicFrame ("Game Editor", 100, 100, 640, 480);
wxMenu *file_menu = new wxMenu;
file_menu->Append(wxID_EXIT, _T("&Exit"));
wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, _T("&File"));
frame->SetMenuBar(menu_bar);
frame->Show (true);
return true;
}
BEGIN_EVENT_TABLE(BasicFrame, wxFrame)
EVT_MENU(wxID_EXIT, BasicFrame::OnExit)
END_EVENT_TABLE()
;
BasicFrame::BasicFrame(const wxChar *title, const int xpos, int ypos, int width,
int height):
wxFrame((wxFrame*)NULL, -1, title, wxPoint (xpos, ypos),
wxSize (width, height)) {
panel = (BasicPanel*)NULL;
panel = new BasicPanel (this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
panel->Show (true);
SetIcon(wxIcon(sample_xpm));
}
BasicFrame::~BasicFrame() {
}
BasicPanel::BasicPanel (wxFrame *parent, wxWindowID id, const wxPoint &pos,
const wxSize &size, long style):
wxPanel (parent, id, pos, size, style) {
int gl_attrib[20] = { WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1,
WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1,
WX_GL_DOUBLEBUFFER, None };
m_canvas = NULL;
this->m_canvas = new TestGLCanvas(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
0, _T("TestGLCanvas"), gl_attrib );
this->m_canvas->SetCurrent();
Init();
wxBoxSizer *top_sizer = new wxBoxSizer (wxHORIZONTAL);
wxBoxSizer *button_sizer = new wxBoxSizer (wxVERTICAL);
button_sizer->Add (new wxButton (this, wxID_OK, "OK"), 0, wxALL, 10);
button_sizer->Add (new wxButton (this, wxID_CANCEL, "Cancel"), 0, wxALL, 10);
top_sizer->Add (button_sizer, 0, wxALIGN_LEFT);
top_sizer->Add (m_canvas, 1, wxEXPAND | wxALL, 10);
SetAutoLayout (true);
SetSizer (top_sizer);
top_sizer->Fit (this);
top_sizer->SetSizeHints (this);
}
BasicPanel::~BasicPanel () {
delete m_canvas;
}
void BasicFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) {
Close(true);
}
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
EVT_SIZE(TestGLCanvas::OnSize)
EVT_PAINT(TestGLCanvas::OnPaint)
EVT_MOUSE_EVENTS(TestGLCanvas::OnMouseEvent)
END_EVENT_TABLE()
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style,
const wxString& name, int* gl_attrib): wxGLCanvas (
parent, id, pos, size,
style|wxFULL_REPAINT_ON_RESIZE, name, gl_attrib) {
parent->Show(true);
SetCurrent();
}
void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) ) {
wxPaintDC dc(this);
SetCurrent();
draw1();
SwapBuffers();
}
void TestGLCanvas::OnSize(wxSizeEvent& event) {
// this is also necessary to update the context on some platforms
//wxGLCanvas::OnSize(event);
// set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
int w, h;
GetClientSize(&w, &h);
//SetCurrent();
//glViewport(0, 0, (GLint) w, (GLint) h);
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (-200, 200, -200, 200, -2000, 2000);
glMatrixMode (GL_MODELVIEW);
}
void TestGLCanvas::OnMouseEvent(wxMouseEvent& event) {
// printf("%f %f\n", event.m_x, event.GetY());
wxPoint aaa = event.GetPosition ();
cout << aaa.x << " " << aaa.y << endl;
}
Makefile:
Code:
LIBS = `wx-config --libs` `wx-config --cxxflags` -lwx_gtk2_gl-2.6 -lGL -lGLU
basic: basic.h basic.cpp
g++ -o basic basic.cpp $(CXXFLAGS) $(LIBS)
clean:
rm -f basic *.o *~
Thanks.
Last edited by kornerr; 09-29-2005 at 09:41 AM .
09-29-2005, 09:43 AM
#4
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Original Poster
Rep:
Although, I'm still looking for a good wxWidgets tut...
10-31-2006, 01:24 PM
#5
Member
Registered: Oct 2006
Location: New Jersey (US)
Distribution: Arch Linux
Posts: 58
Rep:
All times are GMT -5. The time now is 02:11 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News