wxWidgets 2.8.12 FreeBASIC C wrapper

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

@Drago there are more constructors with wxPoint and wxSize.

wxComboBox
wxCheckListBox
wxRadioBox
wxSplashScreen
wxSplashScreenWindow
wxToolBar
wxTreeCtrl
Drago
Posts: 116
Joined: Aug 10, 2005 13:15

Post by Drago »

Hmmm...
so it is up to you...

but curious.... if i would build something like wxwidgets I prefere a stringent method..

all wxPoint....or all x,y

but anyway... our oo-Style wxWrapper look great...
I think that is my way to go...
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

I rebuild both wx-c libs and all constructors works with x,y,w,h now.
(download is the same link as before)

Joshy
Drago
Posts: 116
Joined: Aug 10, 2005 13:15

wxc-oo

Post by Drago »

I want a ButtonArray to listen to the same Listener...

Code: Select all

#define DEBUG ' eanble dprint(string) macro
#include once "inc/wx_object.bi"

dim shared as wxFrame Frame
dim shared as wxButton Button(10)
dim shared as wxApp    App = wxAPP(@OnInit,@OnExit)
App.Run

sub EventListener APICALL(event as _wxEvent ptr, iListener as wxInt)
  static as wxInt nClicks=0
  nClicks+=1
  Button(iListener).Caption "nClick " & nClicks
  print "iList:" & iListener
end sub

function OnInit APICALL as wxBool
  dim as wxInt widths(2)={50,100,-1}
  Frame.Create("wxFrame")
  Frame.CreateStatusBar(3,SB_FLAT)
  Frame.SetStatusWidths(3,@Widths(0))
  Frame.SetStatusText("field I"  ,0)
  Frame.SetStatusText("field II" ,1)
  Frame.SetStatusText("field III",2)
  Button(0).Create(Frame,0,"Button 1",10,10,100,30,0)
  Button(1).Create(Frame,1,"Button 2",10,50,100,30,0)
  Button(2).Create(Frame,2,"Button 3",10,90,100,30,0)
  
  Button(0).RegisterEventListener(@EventListener)
  Button(1).RegisterEventListener(@EventListener)
  Button(2).RegisterEventListener(@EventListener)

  Frame.Show
  return App.OnInit()
end function

function OnExit APICALL as wxInt
  return App.OnExit()
end function
to get it to work i had to change Button_object.bi

Code: Select all

#ifndef __button_object_bi__
#define __button_object_bi__

#include once "button.bi"
#include once "evthandler.bi"
#include once "event.bi"

type wxButton
  declare destructor
  declare constructor
  declare function Create(parent as _wxWindow ptr=WX_NULL, _
                          id    as wxInt=-1, _
                          byval labelArg as String="", _
                          x     as wxInt=-1, _
                          y     as wxInt=-1, _
                          w     as wxInt=-1, _
                          h     as wxInt=-1, _
                          style as wxInt= 0, _
                          validator as _wxValidator ptr=WX_NULL, _
                          byval nameArg as String="") as wxBool
  declare sub      SetDefault
  declare sub      GetDefaultSize(size as _wxSize ptr)
  declare sub      SetImageLabel(bitmap as _wxBitmap ptr)
  declare sub      SetImageMargins(x as wxCoord, y as wxCoord)
  declare sub      Caption(byval txt as String)
  declare sub      RegisterEventListener(el as EventListener)
  private:
  as _wxButton ptr self
  as wxInt ButtonID                 <-this one
end type
destructor wxButton
  dprint("wxButton~")
end destructor
constructor wxButton
  dprint("wxButton()")
  self=wxButton_ctor()
end constructor

function wxButton.Create(parent as _wxWindow ptr, id as wxInt, byval labelArg as String, _
                         x as wxInt, y as wxInt, w as wxInt, h as wxInt, _
                         style as wxInt, validator as _wxValidator ptr, byval nameArg as String) as wxBool
  ButtonID = id                       <- this one
  if labelArg="" and nameArg="" then
    return wxButton_create(self,parent,id,WX_NULL,x,y,w,h,style,validator,WX_NULL)
  elseif labelArg<>"" and nameArg<>"" then
    return wxButton_create(self,parent,id,wxString(labelArg),x,y,w,h,style,validator,wxString(nameArg))
  elseif labelArg<>"" then
    return wxButton_create(self,parent,id,wxString(labelArg),x,y,w,h,style,validator,WX_NULL)
  else
    return wxButton_create(self,parent,id,WX_NULL,x,y,w,h,style,validator,wxString(nameArg))
  end if
end function

sub wxButton.Caption(byval txt as String)
  wxButton_SetLabel(self,wxString(txt))
end sub

sub wxButton.RegisterEventListener(el as EventListener)
  wxEvtHandler_proxy(self, el)
  wxEvtHandler_Connect(self, wxEvent_EVT_COMMAND_BUTTON_CLICKED(),,,ButtonID)  '<- this one
end sub

#endif ' __button_object_bi__
I'll know the ID seems to be used to create standard button....
so how would someone who is really a coder do this ?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

MOD his example test02.bas in new syntax .

Joshy

Code: Select all

#Include "inc/wx_object.bi"

Dim shared As wxTextCtrl TextCtrl
Dim Shared As wxApp App = wxAPP(@OnInit,@OnExit)
App.Run

Sub button_event APICALL(event As _wxEvent Ptr, iListener As wxInt )
  TextCtrl.Value = "Blabla"
End Sub

function OnInit APICALL as wxBool
  dim as wxFrame      Frame
  dim as wxPanel      Panel
  dim as wxButton     Button
  dim as wxStaticLine StaticLine
  dim as wxStaticBox  StaticBox
  Dim As wxCheckBox   CheckBox(2)
  
  Frame.Create("My WX-C Project",,, 390, 390, _
               wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX _
               Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER)

  Panel.Create(Frame)

  Button.Create(Panel,,"Button", 70, 270, 250, 60)
  Button.RegisterEventListener(@button_event)
 
  StaticLine.Create(Panel,, 30, 250 ,330, 10)

  StaticBox.Create(Panel,,"StaticBox", 10, 10, 120, 90)
  
  for i as integer = 0 to 2
    CheckBox(i).Create(Panel,,"CheckBox" & i, 20, 30+i*20)
  next

  TextCtrl.Create(Panel,,"TextCtrl", 40, 220, 310, 21)

  wxWindow.Show(Frame)
  return App.OnInit()
End function

function OnExit APICALL as wxInt
  return App.OnExit()
End function
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Hello Drago

i found out that wxEvent_GetId() is what you need :-)
http://docs.wxwidgets.org/stable/wx_wxe ... eventgetid

Joshy

Code: Select all

#include once "inc/wx_object.bi"
const MAX_BUTTONS = 10
dim shared as wxButton Button(MAX_BUTTONS-1)
dim shared as wxApp    App = wxAPP(@OnInit,@OnExit)
App.Run

sub EventListener APICALL(event as _wxEvent ptr, iListener as wxInt)
  static as wxInt nClicks(MAX_BUTTONS-1)
  dim as wxInt id = wxEvent_GetId(event)
  nClicks(id)+=1
  Button(id).Caption "nClick " & nClicks(id)
end sub

function OnInit APICALL as wxBool
  dim as wxFrame Frame
  Frame.Create("wxFrame",,,120,50+MAX_BUTTONS*40)
  for i as integer =0 to MAX_BUTTONS-1
    Button(i).Create(Frame,i,"Button " & str(i+1),10,10+i*40,100,30,0)
    Button(i).RegisterEventListener(@EventListener)
  next
  wxWindow.Show Frame
  return App.OnInit()
end function

function OnExit APICALL as wxInt
  return App.OnExit()
end function
Same as before but a wxPanel under the wxButtons and the buttons are flat now.
(wxNO_BORDER style not importand but i must learn wxWidgets too)

Code: Select all

#include once "inc/wx_object.bi"
const MAX_BUTTONS = 10
dim shared as wxButton Button(MAX_BUTTONS-1)
dim shared as wxApp    App = wxAPP(@OnInit,@OnExit)
App.Run

sub EventListener APICALL(event as _wxEvent ptr, iListener as wxInt)
  static as wxInt nClicks(MAX_BUTTONS-1)
  dim as wxInt id = wxEvent_GetId(event)
  nClicks(id)+=1
  Button(id).Caption "nClick " & nClicks(id)
end sub

function OnInit APICALL as wxBool
  dim as wxFrame Frame
  dim AS wxPanel Panel
  Frame.Create("wxFrame",,,150,50+MAX_BUTTONS*40)
  Panel.Create(Frame)
  for i as integer =0 to MAX_BUTTONS-1
    Button(i).Create(Panel,i,"Button " & str(i+1),10,10+i*40,120,30,wxNO_BORDER)
    Button(i).RegisterEventListener(@EventListener)
  next
  wxWindow.Show Frame
  return App.OnInit()
end function

function OnExit APICALL as wxInt
  return App.OnExit()
end function
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Hello wxWidgets users
if you take a look to the last ButtonArray example you will see this wxWindow.Show Frame
this isn't an error I removed the show methode from the wxFrame object.

wxFrame, wxPanel, wxButton ...

all this kind of wxWidgets are wxWindows too

wxWindow.Show is a static method that means you don't need to create an wxWindow object to use the Show method.

Joshy
MOD
Posts: 558
Joined: Jun 11, 2009 20:15

Post by MOD »

Maybe it would be a better idea to follow the wxWidgets-doc instead of wx.Net with the OOP-version. With inheritance added to the compiler we had just to add the EXTENDS and 'frame.show()' would work like in wxWidgets.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

DC

Post by ike »

do you have an example how to use DC or draw rectange, wxDC_DrawEllipse etc
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Post by Coolman »

MOD wrote:Maybe it would be a better idea to follow the wxWidgets-doc instead of wx.Net with the OOP-version. With inheritance added to the compiler we had just to add the EXTENDS and 'frame.show()' would work like in wxWidgets.
+1
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: DC

Post by D.J.Peters »

ike wrote:do you have an example how to use DC or draw rectange, wxDC_DrawEllipse etc
Hello ike
here are my first try

If i create the wxDC class (after the wxPen, wxBrush, wxFont, ... classes)
it will be easy to use all the wxDC classes

(wxBufferedDC, wxBufferedPaintDC, wxDC, wxPostScriptDC, wxMetafileDC, wxMemoryDC, wxPrinterDC, wxScreenDC, wxClientDC, wxPaintDC, wxWindowDC)

A wxDC is a device context onto which you can draw graphics and text it exist different DC's for different targets.

Joshy

wxClientDC.bas

Code: Select all

#Include "inc/wx_object.bi"

' NOTE: I define the Panel as global var
' it must exist outside of OnInit() so we can get it's curent wxClientDC 
dim shared as wxPanel      Panel
Dim shared As wxTextCtrl TextCtrl
Dim Shared As wxApp App = wxAPP(@OnInit,@OnExit)
App.Run

Sub button_event APICALL(event As _wxEvent Ptr, iListener As wxInt )
  ' allocate a client DC
  dim as _wxDC ptr dc = cptr(any ptr,wxClientDC_ctor2(Panel))
  ' use it
  wxDC_Clear(dc)
  for i as integer = 1 to 3
    wxDC_DrawCircle(dc, rnd*640, rnd*480, 1+rnd*240)
  next
  for i as integer = 1 to 30
    wxDC_DrawLine  (dc, rnd*640, rnd*480, rnd*640, rnd*480)
  next
  for i as integer = 1 to 10
    wxDC_DrawRotatedText(dc, wxString("Hello ike!"), rnd*640, rnd*480, rnd*360)
  next
  ' release it
  wxDc_dtor(dc)
End Sub

function OnInit APICALL as wxBool
  dim as wxFrame Frame
  Frame.Create("wxClientDC",,, 640,480, _
               wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX _
               Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER)

  Panel.Create(Frame)
  
  dim as wxButton Button
  Button.Create(Panel,,"click me", 70, 270, 250, 60)
  Button.RegisterEventListener(@button_event)

  wxWindow.Show(Frame)
  return App.OnInit()
End function

function OnExit APICALL as wxInt
  return App.OnExit()
End function
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Looks great and simple

Post by ike »

Looks great and simple

Thank you!!!
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

@Coolman and @MOD

I know about you are talking or dreaming :lol:

But trust me EXTENDS isn't the secret wappon to handle all none C++ RTTI of the wxPackage.

For my needs it's ok if an wxFrame returns an wxWindow if the situation need it.
I name it automatic type casting and it's safe (more than any ptr).
I mean you can't put for example an wxBitmap as an wrong wxDC param in my simple version of an oop framework.

By the way the new FB features EXTENDS, BASE, OBJECT isn't in the last official version.

How ever let me show your advanced OOP framework.

Joshy
Last edited by D.J.Peters on Jul 09, 2011 6:44, edited 3 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Looks great and simple

Post by D.J.Peters »

ike wrote:Looks great and simple
sure ?
How do you will set the curent pen or brush ?
or the color of the curent pen ?
...

If i create the wxDC class it will look something like this

Joshy

Code: Select all

Sub button_event APICALL(event As _wxEvent Ptr, iListener As wxInt )
  dim as wxDC DC = wxDC(Panel)

  DC.ClearColor = RGB(0,255,0)
  DC.Clear
  for i as integer = 1 to 3
    DC.FillColor = RGB(rnd*255,rnd*255,rnd*255)
    DC.Circle rnd*640, rnd*480, 1+rnd*240
  next
  for i as integer = 1 to 30
    DC.PenColor = RGB(rnd*255,rnd*255,rnd*255)
    DC.Line rnd*640, rnd*480, rnd*640, rnd*480
  next
  for i as integer = 1 to 10
    DC.TextColor = RGB(rnd*255,rnd*255,rnd*255)
    DC.RoatatedText "Hello ike!", rnd*640, rnd*480, rnd*360
  next
End Sub
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Post by ike »

_DS(wxDC_SetBrush)(self as _wxDC ptr, brush as _wxBrush ptr)
_DF(wxDC_GetBrush)(self as _wxDC ptr) as _wxBrush ptr
_DS(wxDC_SetBackground)(self as _wxDC ptr, brush as _wxBrush ptr)
_DF(wxDC_GetBackground)(self as _wxDC ptr) as _wxBrush ptr
_DS(wxDC_SetPen)(self as _wxDC ptr, pen as _wxPen ptr)
_DF(wxDC_GetPen)(self as _wxDC ptr) as _wxPen ptr



But if you create classes it would be much better!!!
Post Reply