Page 1 of 1

wxWidgets and PureBasic

Posted: Sat Dec 18, 2004 3:15 am
by FloHimself
hi,

after reading at http://briancbecker.com/site/index.php?id=0 that on http://sourceforge.net/project/showfile ... _id=290546 is a dll containing wxWidgets with C API, i converted an example:

Code: Select all

#wxBOTH                  = $0004 | $0008
#wxDEFAULT_FRAME_STYLE   = 541068864

#wxWIDGETS_LIB = 0

Global wx_app
Global wx_frame
Global wx_panel
Global wx_button

Procedure ButtonClick(*event.l, iListener.l)
  wx_msgbox_size = CallCFunction(#wxWIDGETS_LIB, "wxSize_ctor", 150, 50)
  CallCFunction(#wxWIDGETS_LIB, "wxMsgBox", wx_frame, "I'm going bye-bye!", "Bye!", 0, wx_msgbox_size);
  CallCFunction(#wxWIDGETS_LIB, "wxWindow_Close", wx_frame, #True)
  ProcedureReturn 0
EndProcedure

Procedure wxApp_OnInit(*self.l)
  wx_frame = CallCFunction(#wxWIDGETS_LIB, "wxFrame_ctor")
  If wx_frame
    wx_frame_pos  = CallCFunction(#wxWIDGETS_LIB, "wxSize_ctor", 200, 200)
    wx_frame_size = CallCFunction(#wxWIDGETS_LIB, "wxSize_ctor", 500, 300)
    If CallCFunction(#wxWIDGETS_LIB, "wxFrame_Create", wx_frame, 0, -1, "Welcome To WX-C", wx_frame_pos, wx_frame_size, #wxDEFAULT_FRAME_STYLE, "frame")
      
      wx_panel = CallCFunction(#wxWIDGETS_LIB, "wxPanel_ctor")
      CallCFunction(#wxWIDGETS_LIB, "wxPanel_Create", wx_panel, wx_frame, 1, 0, 0, 0, 0)
     
      wx_button       = CallCFunction(#wxWIDGETS_LIB, "wxButton_ctor")
      wx_button_pos   = CallCFunction(#wxWIDGETS_LIB, "wxSize_ctor", 150, 100)
      wx_button_size  = CallCFunction(#wxWIDGETS_LIB, "wxSize_ctor", 100, 30)
  
      CallCFunction(#wxWIDGETS_LIB, "wxButton_Create", wx_button, wx_panel, 2, "Exit!", wx_button_pos, wx_button_size , 0, 0, 0);
 
      CallCFunction(#wxWIDGETS_LIB, "wxEvtHandler_proxy", wx_frame, @ButtonClick())
      wxEvent_EVT_COMMAND_BUTTON_CLICKED = CallCFunction(#wxWIDGETS_LIB, "wxEvent_EVT_COMMAND_BUTTON_CLICKED")
      Debug wxEvent_EVT_COMMAND_BUTTON_CLICKED
      CallCFunction(#wxWIDGETS_LIB, "wxEvtHandler_Connect", wx_frame, wxEvent_EVT_COMMAND_BUTTON_CLICKED, 2, -1, 0)
      CallCFunction(#wxWIDGETS_LIB, "wxWindow_CenterOnScreen", wx_frame, #wxBOTH)
      CallCFunction(#wxWIDGETS_LIB, "wxWindow_Show", wx_frame, #True)
    EndIf
  EndIf
  ProcedureReturn CallCFunction(#wxWIDGETS_LIB, "wxApp_OnInit", wx_app)
EndProcedure

Procedure wxApp_OnExit(*self.l)
  ProcedureReturn CallCFunction(#wxWIDGETS_LIB, "wxApp_OnExit", wx_app)
EndProcedure

If OpenLibrary(#wxWIDGETS_LIB,"wx-c.dll")
  wx_app = CallCFunction(#wxWIDGETS_LIB, "wxApp_ctor")
  If CallCFunction(#wxWIDGETS_LIB, "wxApp_RegisterVirtual", wx_app, @wxApp_OnInit(),  @wxApp_OnExit())
    CallCFunction(#wxWIDGETS_LIB, "wxApp_Run", 1, "")
  EndIf
EndIf
you will need the wx-c.dll from this http://alphafern.com/BrianCBecker/Downl ... c/wx_c.zip archive to test it. there is a linux lib called libwx-c.so also. maybe someone can test this on a linux box??

best regards,
flo

Posted: Sat Dec 18, 2004 3:51 am
by Dare2
Heya FloHimself,

Thanks for this!

Posted: Sat Dec 18, 2004 11:17 am
by Num3
Woah!

Cool!

ImageImageImageImageImage

Posted: Sat Dec 18, 2004 11:25 am
by PB
Post a screenshot so I can see! (I don't want to install the widgets yet).

Posted: Sat Dec 18, 2004 11:28 am
by gnozal
Very nice ; waiting for userLib :wink:

Posted: Sat Dec 18, 2004 11:51 am
by Num3
PB wrote:Post a screenshot so I can see! (I don't want to install the widgets yet).
No need, just download that zip file that contains the dll and save the pb source in the same dir!

Posted: Sat Dec 18, 2004 2:06 pm
by Flype
ho yes very good topic...

In the past, 2 years ago, i made a Tetris game in Python and wxPython.
It was very nice and smooth with transparency effect and joystick support.
Almost finished until i crash accidently my harddrive :cry:
I recognize all those functions. And i remember how interessant it was to
create GUI thanx wx stuff. Very powerfull and efficient API.
A wxPB userlib would be very welcome :P But i know it's a huge work.
Only a well organized PB-team can make it :twisted:

Posted: Sat Dec 18, 2004 3:17 pm
by FloHimself
i would go with a include file for the dll for varius reasons.. but is someone able to test this on a linux box???

Posted: Sat Dec 18, 2004 7:06 pm
by NetSlayer
On Linux it does absolutely nothing. I replaced CallCFunction() with CallFunction() (CallCFunction() is not available on Linux) and removed the "Debug" line. I compiled and executed it but nothing really happens.

Edit: It sucks on opening the library, that doesn't work.

Posted: Sat Dec 18, 2004 8:02 pm
by eddy
widget ? What's that ? a better GUI system

Posted: Sat Dec 18, 2004 8:22 pm
by FloHimself
NetSlayer wrote:On Linux it does absolutely nothing. I replaced CallCFunction() with CallFunction() (CallCFunction() is not available on Linux) and removed the "Debug" line. I compiled and executed it but nothing really happens.

Edit: It sucks on opening the library, that doesn't work.
you used linux lib libwx-c.so from http://prdownloads.sourceforge.net/wxne ... z?download ??

Posted: Sun Dec 19, 2004 12:24 pm
by Num3
NetSlayer wrote:On Linux it does absolutely nothing. I replaced CallCFunction() with CallFunction() (CallCFunction() is not available on Linux) and removed the "Debug" line. I compiled and executed it but nothing really happens.

Edit: It sucks on opening the library, that doesn't work.
That's weird...

I had the same problem with FMOD.so !!!

I can get OpenLibrary to open the damn thing!

Can this be a linux bug !?

Posted: Sun Dec 19, 2004 1:23 pm
by NetSlayer
FloHimself wrote:
NetSlayer wrote:On Linux it does absolutely nothing. I replaced CallCFunction() with CallFunction() (CallCFunction() is not available on Linux) and removed the "Debug" line. I compiled and executed it but nothing really happens.

Edit: It sucks on opening the library, that doesn't work.
you used linux lib libwx-c.so from http://prdownloads.sourceforge.net/wxne ... z?download ??
Yes, I did.

@Num3:
Really seems to be a bug. We should tell Fred.

Posted: Sun Dec 19, 2004 2:00 pm
by Num3
I've posted the OpenLibrary possible bug on the Bug Reports thread...