FLTK headers for FreeBasic OOP (no C wrapper)

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

demosthenesk wrote: Aug 07, 2023 10:58 Example code in Debian 13 Trixie (testing), it works fine, no errors, run successfully

Example1

Code: Select all

#include "FLTK_main/Fl_Window.bi"
#include "FLTK_main/Fl_Box.bi"

Dim As ZString * 13 str1 => "hello, world"
Dim fWindow as Fl_Window = Fl_Window(0, 0, 340, 180, str1)
	Dim fBox as Fl_Box = Fl_Box(20, 40, 300, 100, str1)
	fBox.box(FL_UP_BOX)
	fBox.labelfont(FL_BOLD + FL_ITALIC)
	fBox.labelsize(36)
	fBox.labeltype(FL_SHADOW_LABEL)
fWindow.end_()

fWindow.show

Fl.run_()

Example2 equivalent with Example1

Code: Select all

#include "FLTK_main/Fl_Window.bi"
#include "FLTK_main/Fl_Box.bi"

Dim fWindow As Fl_Window Ptr
Dim fBox As Fl_Box Ptr
Dim As ZString * 13 str1 => "hello, world"

fWindow  = New Fl_Window(0, 0, 340, 180, str1)
	fBox = New Fl_Box(20, 40, 300, 100, str1)
	fBox->box(FL_UP_BOX)
	fBox->labelfont(FL_BOLD + FL_ITALIC)
	fBox->labelsize(36)
	fBox->labeltype(FL_SHADOW_LABEL)
fWindow->end_()
fWindow->show()

Fl.run_()

which coding style do you prefer ?
Example1 with methods or Example2 with pointers ?
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

In the following examle i get errors:

Code: Select all

#include once "FLTK/Fl_Window.bi"
#include once "FLTK/Fl_Button.bi"
#include once "FLTK/Fl_Light_Button.bi"
#include once "FLTK/Fl_Round_Button.bi"

Dim w as Fl_Window = Fl_Window(200,200,"Window")
	Dim button as Fl_button = Fl_button(10, 10, 100, 20, "FL_Button")
	Dim lbutton as Fl_Light_Button = Fl_Light_Button(10, 50, 100, 20, "FL_Light")
	Dim rbutton as Fl_Round_Button = Fl_Round_Button(10, 90, 100, 20, "FL_Round")
	
	button.type_(FL_NORMAL_BUTTON)
	lbutton.type_(FL_TOGGLE_BUTTON)
	rbutton.type_(FL_RADIO_BUTTON)
	
w.end_()

w.show
fl.run_
Building Project: Buttons......

/home/user/Bin/FreeBASIC/FreeBASIC-1.10.0-source/bin/fbc -x "Buttons" -m "buttons" -b "buttons.bas" -i "/home/user/Bin/FreeBASIC/FreeBASIC-1.10.0-source/inc" -p "/home/user/Bin/FreeBASIC/FreeBASIC-1.10.0-source/lib/freebasic/linux-x86_64" -l Xrender -l Xcursor -l Xfixes -l Xext -l Xft -l fontconfig -l Xinerama -l pthread -l m -l X11 -l png -l z -l jpeg

/home/user/Documents/DEVELOPMENT/FreeBasic/Getting_started_with_FLTK_and_FreeBASIC/Projects/002-buttons/buttons.bas(11) error 42: Variable not declared, FL_NORMAL_BUTTON in 'button.type_(FL_NORMAL_BUTTON)'
/home/user/Documents/DEVELOPMENT/FreeBasic/Getting_started_with_FLTK_and_FreeBASIC/Projects/002-buttons/buttons.bas(12) error 42: Variable not declared, FL_TOGGLE_BUTTON in 'lbutton.type_(FL_TOGGLE_BUTTON)'
/home/user/Documents/DEVELOPMENT/FreeBasic/Getting_started_with_FLTK_and_FreeBASIC/Projects/002-buttons/buttons.bas(13) error 42: Variable not declared, FL_RADIO_BUTTON in 'rbutton.type_(FL_RADIO_BUTTON)'


Compile Error...
angros47
Posts: 2331
Joined: Jun 21, 2005 19:04

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by angros47 »

Ok: Add the line:

Code: Select all

#define FL_RESERVED_TYPE 100
to Fl_Widget.bi

and the lines:

Code: Select all

#define FL_NORMAL_BUTTON	0
#define FL_TOGGLE_BUTTON	1
#define FL_RADIO_BUTTON		(FL_RESERVED_TYPE+2)
#define FL_HIDDEN_BUTTON	3
to Fl_Button.bi
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

angros47 wrote: Aug 10, 2023 20:27 Ok: Add the line:

Code: Select all

#define FL_RESERVED_TYPE 100
to Fl_Widget.bi

and the lines:

Code: Select all

#define FL_NORMAL_BUTTON	0
#define FL_TOGGLE_BUTTON	1
#define FL_RADIO_BUTTON		(FL_RESERVED_TYPE+2)
#define FL_HIDDEN_BUTTON	3
to Fl_Button.bi
ok,
compilation is ok now
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

i get errors for Valuators scrollbar widget

Code: Select all

#include once "FLTK/Fl_Window.bi"
#include once "FLTK/Fl_Scrollbar.bi"

Dim w as Fl_Window = Fl_Window(400,200,"Window")
	Dim vScrollBar As Fl_Scrollbar(10,50,100,50,"Scrollbar")
	vScrollBar.type_(FL_HORIZONTAL)
	vScrollBar.minimum(0.00)
	vScrollBar.maximum(100.00)
	vScrollBar.value(50.00)
w.end_()

w.show
fl.run_
Building Project: valuator......

/home/user/Bin/FreeBASIC/FreeBASIC-1.10.0-source/bin/fbc -x "valuator" -m "scrollbar" -b "scrollbar.bas" -i "/home/user/Bin/FreeBASIC/FreeBASIC-1.10.0-source/inc" -p "/home/user/Bin/FreeBASIC/FreeBASIC-1.10.0-source/lib/freebasic/linux-x86_64" -l Xrender -l Xcursor -l Xfixes -l Xext -l Xft -l fontconfig -l Xinerama -l pthread -l m -l X11 -l png -l z -l jpeg

/home/user/Documents/DEVELOPMENT/FreeBasic/Getting_started_with_FLTK_and_FreeBASIC/Projects/004-valuator/scrollbar.bas(5) error 183: TYPE or CLASS has no default constructor, found '(' in 'Dim vScrollBar As Fl_Scrollbar(10,50,100,50,"Scrollbar")'


Compile Error...

-----------------------------------
Also there is no type_ method
angros47
Posts: 2331
Joined: Jun 21, 2005 19:04

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by angros47 »

Should have been:

Code: Select all

	Dim vScrollBar As Fl_Scrollbar=Fl_Scrollbar(10,50,100,50,"Scrollbar")
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

angros47 wrote: Aug 11, 2023 19:38 Should have been:

Code: Select all

	Dim vScrollBar As Fl_Scrollbar=Fl_Scrollbar(10,50,100,50,"Scrollbar")
oh my God.....i am so stupid........
thanks angros47
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

Code for shortcuts does not work:

Code: Select all

#include once "FLTK/Fl_Window.bi"
#include once "FLTK/Fl_Button.bi"
#include once "FLTK/Fl_Light_Button.bi"
#include once "FLTK/Fl_Round_Button.bi"

Dim w as Fl_Window = Fl_Window(200,200,"Window")
	Dim button as Fl_button = Fl_button(10, 10, 100, 20, "FL_Button")
	Dim lbutton as Fl_Light_Button = Fl_Light_Button(10, 50, 130, 20, "FL_Light_Button")
	Dim rbutton as Fl_Round_Button = Fl_Round_Button(10, 90, 100, 20, "FL_Round_Button")

	button.type_(FL_NORMAL_BUTTON)
	lbutton.type_(FL_TOGGLE_BUTTON)
	rbutton.type_(FL_RADIO_BUTTON)
	
	button.shortcut(FL_CTRL + 'b')
w.end_()

w.show
fl.run_
also
button.shortcut(FL_SHIFT + ’b’)
button.shortcut(FL_CTRL + ’b’)
button.shortcut(FL_ALT + ’b’)

FL_SHIFT
FL_CTRL
FL_ALT
do not exist

home/user/Documents/DEVELOPMENT/FreeBasic/Getting_started_with_FLTK_and_FreeBASIC/Projects/002-buttons/buttons.bas(15) error 42: Variable not declared, FL_CTRL in 'button.shortcut(FL_CTRL + ’b’)'
angros47
Posts: 2331
Joined: Jun 21, 2005 19:04

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by angros47 »

Use __FL_CTRL, __FL_ALT and __FL_SHIFT

I had to add the underscore to prevent symbol conflicts, since C++ is case sensitive, FreeBasic isn't.
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

angros47 wrote: Aug 11, 2023 20:33 Use __FL_CTRL, __FL_ALT and __FL_SHIFT

I had to add the underscore to prevent symbol conflicts, since C++ is case sensitive, FreeBasic isn't.
ok, this works
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

i created an example of callback but it throws error

Code: Select all

#include once "FLTK/Fl_Double_Window.bi"
#include once "FLTK/Fl_Button.bi"

declare sub rename_me(o as Fl_Widget)

sub rename_me(o as Fl_Widget)
	o.label("Renamed")
	o.redraw()
end sub

Dim As ZString * 13 str1 => "Test text"
Dim w as Fl_Double_Window = Fl_Double_Window(200, 105, "Window")
	Dim b1 as Fl_button = Fl_button(20, 10, 160, 35, str1)
	Dim cb as Fl_Callback = Fl_Callback(@rename_me)
	b1.callback(cb)
w.end_()
w.resizable(@b1)
w.show()

fl.run_
callbacks.bas(16) error 42: Variable not declared, Fl_Callback in 'Dim cb as Fl_Callback = Fl_Callback(@rename_me)'
Last edited by demosthenesk on Aug 13, 2023 16:04, edited 1 time in total.
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

demosthenesk wrote: Aug 13, 2023 11:16 i created an example of callback but it throws error

Code: Select all

#include once "FLTK/Fl_Double_Window.bi"
#include once "FLTK/Fl_Button.bi"

declare sub rename_me(o as Fl_Widget)

sub rename_me(o as Fl_Widget)
	o.label("Renamed")
	o.redraw()
end sub

Dim As ZString * 13 str1 => "Test text"
Dim w as Fl_Double_Window = Fl_Double_Window(200, 105, "Window")
	Dim b1 as Fl_button = Fl_button(20, 10, 160, 35, str1)
	Dim cb as Fl_Callback = Fl_Callback(@rename_me)
	b1.callback(cb)
w.end_()
w.resizable(@b1)
w.show()

fl.run_
callbacks.bas(16) error 42: Variable not declared, Fl_Callback in 'Dim cb as Fl_Callback = Fl_Callback(@rename_me)'
i found the correct code...

Code: Select all

#include once "FLTK/Fl_Double_Window.bi"
#include once "FLTK/Fl_Button.bi"

declare sub rename_me(as Fl_Widget)

sub rename_me(o as Fl_Widget)
	o.label("Renamed")
	o.redraw()
end sub

Dim As ZString * 13 str1 => "Test text"
Dim w as Fl_Double_Window = Fl_Double_Window(200, 105, "Window")
	Dim b1 as Fl_button = Fl_button(20, 10, 160, 35, str1)
	Dim cb as Fl_Callback = @rename_me
	b1.callback(cb)
w.end_()
w.resizable(@b1)
w.show()

fl.run_
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by demosthenesk »

Here is another example of callback example with an Fl_Input
We have a window, a button and a textbox.
When user clicks the button, it changes its label from the value of textbox

Code: Select all

#include once "FLTK/Fl_Double_Window.bi"
#include once "FLTK/Fl_Button.bi"
#include once "FLTK/Fl_Input.bi"

sub rename_me(o as Fl_Widget, s as Fl_Input ptr)
	o.label(s->value)
	o.redraw()
end sub

'' main program
Dim w as Fl_Double_Window = Fl_Double_Window(300, 125, "Window")
	Dim sInput1 As Fl_Input = Fl_Input(70,50,160,35,"Input:")
	Dim b1 as Fl_button = Fl_button(70, 10, 160, 35, "Change text")
	Dim cb as Fl_Callback = @rename_me
	b1.callback(cb, @sInput1)

w.end_()
w.resizable(@b1)
w.show()

fl.run_
only one question
why i get nput.bas(14) warning 4(2): Suspicious pointer assignment for line
Dim cb as Fl_Callback = @rename_me
fxm
Moderator
Posts: 12187
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FLTK headers for FreeBasic OOP (no C wrapper)

Post by fxm »

Because the type of Fl_Callback is :
SUB CDECL(AS FL_WIDGET PTR, AS ANY PTR)

Maybe:

Code: Select all

sub rename_me cdecl(o as Fl_Widget ptr, s as any ptr)
	dim s0 as Fl_Input ptr = s
	o->label(s0->value)
	o->redraw()
end sub
Post Reply