wxWidgets 2.8.12 FreeBASIC C wrapper
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
wxc-oo
I want a ButtonArray to listen to the same Listener...
to get it to work i had to change 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 ?
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
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__
so how would someone who is really a coder do this ?
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
MOD his example test02.bas in new syntax .
Joshy
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
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Hello Drago
i found out that wxEvent_GetId() is what you need :-)
http://docs.wxwidgets.org/stable/wx_wxe ... eventgetid
JoshySame 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)
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
(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
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
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
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
DC
do you have an example how to use DC or draw rectange, wxDC_DrawEllipse etc
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: DC
Hello ikeike wrote:do you have an example how to use DC or draw rectange, wxDC_DrawEllipse etc
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
Looks great and simple
Looks great and simple
Thank you!!!
Thank you!!!
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
@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
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.
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Looks great and simple
sure ?ike wrote:Looks great and simple
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
_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!!!
_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!!!