LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 09-28-2005, 04:40 AM   #1
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Rep: Reputation: 35
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.
 
Old 09-28-2005, 11:04 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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.
 
Old 09-29-2005, 09:40 AM   #3
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
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.
 
Old 09-29-2005, 09:43 AM   #4
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Although, I'm still looking for a good wxWidgets tut...
 
Old 10-31-2006, 01:24 PM   #5
josenj
Member
 
Registered: Oct 2006
Location: New Jersey (US)
Distribution: Arch Linux
Posts: 58

Rep: Reputation: 15
Talking

http://www.phptr.com/content/images/...73816_book.pdf

Enjoy!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wxwidgets book - very necessary saied Programming 4 10-31-2006 01:04 PM
A good book uselpa Red Hat 2 10-13-2005 09:11 AM
Good C++ book? vi0lat0r Programming 13 04-30-2004 11:32 PM
any good book ? WannaLearnLinux Linux - Newbie 18 08-30-2003 10:38 PM
A good book? teyesahr Linux - Newbie 10 07-31-2003 09:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration