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
angros47
Posts: 2385
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

That's great news!

I will try to provide support, but I don't guarantee anything. Anyway, FLTK gave me the impression of a stable project, that has not gone through many changes lately and is not supposed to change much in the future. Especially if we consider that the concept of desktop GUI (WIMP: Windows, Icons, Menus, Pointer) is pretty standard, by now, and hasn't changed much in the last 30 years; likely future innovations will be on different kinds of interfaces, like voice control, touch screens, gestures and so on.

By the way, I ported a new example:

resize.bi

Code: Select all

#include once "FLTK/Fl.bi"
#include once "FLTK/Fl_Double_Window.bi"
#include once "FLTK/Fl_Button.bi"
#include once "FLTK/Fl_Box.bi"
resize.bas

Code: Select all

#include "resize.bi"

private sub cb_ cdecl(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->position(w->x()-50,w->y())
end sub

private sub cb_2(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->position(w->x(),w->y()+50)
end sub

private sub cb_1(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->position(w->x()+50,w->y())
end sub

private sub cb_8(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->position(w->x(),w->y()-50)
end sub

private sub cb_grow(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->size(w->w()+20, w->h()+20)
end sub

private sub cb_shrink(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->size(w->w()-20, w->h()-20)
end sub


dim w as Fl_Double_Window ptr
scope
	dim o as Fl_Double_Window ptr = new Fl_Double_Window(366, 261)
	w = o: 
	scope
		dim o as Fl_Button ptr = new Fl_Button(20, 40, 40, 40, "@<-")
		o->callback(cast(Fl_Callback, @cb_))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(60, 80, 40, 40, "@2->")
		o->callback(cast(Fl_Callback, @cb_2))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(100, 40, 40, 40, "@->")
		o->callback(cast(Fl_Callback, @cb_1))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(60, 0, 40, 40, "@8->")
		o->callback(cast(Fl_Callback, @cb_8))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(30, 130, 110, 40, "grow")
		o->labelfont(1)
		o->labelsize(18)
		o->callback(cast(Fl_Callback, @cb_grow))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(30, 190, 110, 40, "shrink")
		o->labelfont(1)
		o->labelsize(18)
		o->callback(cast(Fl_Callback, @cb_shrink))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(150, 10, 160, 220, "This is a test of program-generated resize() of a window."_
		"  The window should move or resize once when each button is clicked.  The program and window manager should "_
		"not go into fits echoing resizes back and forth!")
		o->box(FL_BORDER_BOX)
		o->align(132 or FL_ALIGN_INSIDE)
	end scope
	o->end_()
	o->resizable(o)
end scope
w->show(__FB_ARGC__, __FB_ARGV__)
Fl.run_()

srvaldez
Posts: 3603
Joined: Sep 25, 2005 21:54

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

Post by srvaldez »

angros47, unfortunately compiling FLTK for windows is not trivial, it takes someone with a lot of expertise
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

hello, on a 15" screen with a resolution of 1920x1080, the font is too small. the code is rather complex. nothing to do with basic. i made a small modification without even looking at the documentation, referring to the example. to my great surprise, it works. the font management seems efficient. i've always said for a long time that FLTK should be included and usable with freebasic. it's done. with static compilation, the programs generated could be without any dependency. it would be nice to create a post dedicated to examples. i've always learned to use programming languages or libraries by referring to examples. it's often more efficient than documentations...

thanks to angros47 for these efforts.

slightly modified example. note that i install the includes in the same directory as the examples :

resize.bas

Code: Select all

#include once "Fl.bi"
#include once "Fl_Double_Window.bi"
#include once "Fl_Button.bi"
#include once "Fl_Box.bi"

private sub cb_ cdecl(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->position(w->x()-50,w->y())
end sub

private sub cb_2(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->position(w->x(),w->y()+50)
end sub

private sub cb_1(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->position(w->x()+50,w->y())
end sub

private sub cb_8(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->position(w->x(),w->y()-50)
end sub

private sub cb_grow(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->size(w->w()+20, w->h()+20)
end sub

private sub cb_shrink(o as Fl_Button ptr, z as any ptr)
	dim w as Fl_Window ptr = o->window()
	w->size(w->w()-20, w->h()-20)
end sub


dim w as Fl_Double_Window ptr
scope
	dim o as Fl_Double_Window ptr = new Fl_Double_Window(700, 350)
	w = o: 
	scope
		dim o as Fl_Button ptr = new Fl_Button(20, 40, 40, 40, "@<-")
		o->callback(cast(Fl_Callback, @cb_))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(60, 80, 40, 40, "@2->")
		o->callback(cast(Fl_Callback, @cb_2))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(100, 40, 40, 40, "@->")
		o->callback(cast(Fl_Callback, @cb_1))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(60, 0, 40, 40, "@8->")
		o->callback(cast(Fl_Callback, @cb_8))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(25, 140, 110, 40, "grow")
		o->labelfont(1)
		o->labelsize(25)
		o->callback(cast(Fl_Callback, @cb_grow))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(25, 200, 110, 40, "shrink")
		o->labelfont(1)
		o->labelsize(25)
		o->callback(cast(Fl_Callback, @cb_shrink))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(160, 10, 520, 320, "This is a test of program-generated resize() of a window."_
		"  The window should move or resize once when each button is clicked.  The program and window manager should "_
		"not go into fits echoing resizes back and forth!")
		o->labelfont(1)
		o->labelsize(28)
		o->box(FL_BORDER_BOX)
		o->align(132 or FL_ALIGN_INSIDE)
	end scope
	o->end_()
	o->resizable(o)
end scope
w->show(__FB_ARGC__, __FB_ARGV__)
Fl.run_()
srvaldez
Posts: 3603
Joined: Sep 25, 2005 21:54

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

Post by srvaldez »

angros47, I have msys2 installed on my PC and FLTK is available for it, I copied libfltk.dll, libfltk_forms.dll and libfltk_gl.dll from the msys2/mingw64/bin directory to a folder on the desktop, then saved your example to the same folder compiled and run, all worked ok
the reason for copying the dll's to a separate directory on the desktop was to see if there were other dll dependencies as my msys2 installation is on another drive and is not on the PATH, surprisingly no dependencies were flagged :)

if anyone is interested, here are the FLTK dlls
[edit]
while in 64-bit there were no dependencies flagged, there are dependencies
libfltk.dll
libfltk_forms.dll
libfltk_gl.dll
libfltk_images.dll
libgcc_s_seh-1.dll
libjpeg-8.dll
libpng16-16.dll
libstdc++-6.dll
libwinpthread-1.dll
zlib1.dll

for 32-bit this are the dependencies
libfltk.dll
libfltk_forms.dll
libfltk_gl.dll
libfltk_images.dll
libgcc_s_dw2-1.dll
libjpeg-8.dll
libpng16-16.dll
libstdc++-6.dll
libwinpthread-1.dll
zlib1.dll
Last edited by srvaldez on Jul 06, 2023 16:03, edited 2 times in total.
srvaldez
Posts: 3603
Joined: Sep 25, 2005 21:54

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

Post by srvaldez »

@angros47
if I run your example in 32-bit and click on Grow, it grows ok but if I click on Grow a second time it crashes, I suspect that the headers are not 32-bit clean
angros47
Posts: 2385
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

Does the same happen with the shrink button? Also, are you using Windows or Linux?

Try changing:

Code: Select all

private sub cb_grow(o as Fl_Button ptr, z as any ptr)
with

Code: Select all

private sub cb_grow cdecl(o as Fl_Button ptr, z as any ptr)
does it help?
srvaldez
Posts: 3603
Joined: Sep 25, 2005 21:54

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

Post by srvaldez »

angros47 wrote: Jul 06, 2023 19:31 Does the same happen with the shrink button? Also, are you using Windows or Linux?

Try changing:

Code: Select all

private sub cb_grow(o as Fl_Button ptr, z as any ptr)
with

Code: Select all

private sub cb_grow cdecl(o as Fl_Button ptr, z as any ptr)
does it help?
I am using Windows, and yes private sub cb_grow cdecl(o as Fl_Button ptr, z as any ptr) fixes the problem
thank you :D
angros47
Posts: 2385
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

You are welcome!
It was my fault, callbacks are supposed to use C calling convention, that is the default on Linux, while on Windows it needs to be specified.
Since I am using Linux, I often forget to put the "cdecl" part
angros47
Posts: 2385
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

valuators.bi

Code: Select all

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

#include once "FLTK/Fl_Box.bi"
#include once "FLTK/Fl_Slider.bi"
#include once "FLTK/Fl_Value_Slider.bi"
#include once "FLTK/Fl_Value_Input.bi"
#include once "FLTK/Fl_Value_Output.bi"
#include once "FLTK/Fl_Scrollbar.bi"
#include once "FLTK/Fl_Adjuster.bi"
#include once "FLTK/Fl_Counter.bi"
#include once "FLTK/Fl_Spinner.bi"
#include once "FLTK/Fl_Dial.bi"
#include once "FLTK/Fl_Roller.bi"
valuators.bas

Code: Select all

#include once "valuators.bi"

private sub callback cdecl(o as Fl_Widget ptr, z as any ptr)
  print cast(Fl_Valuator ptr,o)->value()
end sub

dim w as Fl_Double_Window ptr
scope
	dim o as Fl_Double_Window ptr = new Fl_Double_Window(580, 510, "Valuator classes, showing values for type()")
	w = o
	o->color(43)
	o->selection_color(43)
	scope
		dim o as Fl_Box ptr = new Fl_Box(10, 10, 280, 210, "Fl_Slider")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(30, 45, 20, 145, "0")
		o->tooltip("Vertical Slider")
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(70, 55, 20, 145, "FL_VERT_FILL_SLIDER")
		o->type_(2)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(105, 45, 20, 145, "FL_VERT_NICE_SLIDER")
		o->type_(4)
		o->box(FL_FLAT_BOX)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(140, 80, 130, 20, "FL_HORIZONTAL")
		o->type_(1)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(140, 120, 130, 20, "FL_HOR_FILL_SLIDER")
		o->type_(3)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(140, 160, 130, 20, "FL_HOR_NICE_SLIDER")
		o->type_(5)
		o->box(FL_FLAT_BOX)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(10, 230, 280, 210, "Fl_Value_Slider")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(30, 260, 30, 145, "0")
		o->tooltip("Value Slider")
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(70, 275, 30, 140, "FL_VERT_FILL_SLIDER")
		o->type_(2)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(110, 260, 20, 145, "FL_VERT_NICE_SLIDER")
		o->type_(4)
		o->box(FL_FLAT_BOX)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(140, 290, 130, 20, "FL_HOR_SLIDER")
		o->type_(1)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(140, 330, 130, 20, "FL_HOR_FILL_SLIDER")
		o->type_(3)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(140, 370, 130, 20, "FL_HOR_NICE_SLIDER")
		o->type_(5)
		o->box(FL_FLAT_BOX)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(10, 450, 135, 50, "Fl_Value_Input")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Value_Input ptr = new Fl_Value_Input(30, 470, 105, 25, "0")
		o->tooltip("Value Input")
		o->labelsize(8)
		o->maximum(100)
		o->step_(0.1)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(155, 450, 135, 50, "Fl_Value_Output")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Value_Output ptr = new Fl_Value_Output(170, 470, 105, 25, "0")
		o->tooltip("Value Output")
		o->labelsize(8)
		o->maximum(100)
		o->step_(0.1)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(300, 10, 130, 120, "   Fl_Scrollbar")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP_LEFT or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Scrollbar ptr = new Fl_Scrollbar(305, 65, 95, 20, "FL_HORIZONTAL")
		o->tooltip("Horizontal Scrollbar")
		o->type_(1)
		o->labelsize(8)
		o->maximum(100)
		cast(Fl_Slider ptr, o)->value(20)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Scrollbar ptr = new Fl_Scrollbar(400, 20, 20, 105, "0")
		o->tooltip("Vertical Scrollbar")
		o->labelsize(8)
		o->maximum(100)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(440, 10, 130, 120, "Fl_Adjuster")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Adjuster ptr = new Fl_Adjuster(450, 60, 75, 25, "w()>h()")
		o->tooltip("Horizontal Adjuster")
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Adjuster ptr = new Fl_Adjuster(530, 35, 25, 75, "w()<h()")
		o->tooltip("Vertical Adjuster")
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(300, 140, 130, 120, "Fl_Counter")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Counter ptr = new Fl_Counter(310, 175, 110, 25, "0")
		o->tooltip("Standard Counter")
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Counter ptr = new Fl_Counter(310, 215, 110, 25, "FL_SIMPLE_COUNTER")
		o->tooltip("Simple Counter")
		o->type_(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(440, 140, 130, 120, "Fl_Spinner")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Spinner ptr = new Fl_Spinner(465, 176, 80, 24, "FL_INT_INPUT")
		o->labelsize(8)
		o->minimum(-30)
		o->maximum(30)
		o->step_(2)
		o->value(5)
		o->align(FL_ALIGN_BOTTOM)
	end scope
	scope
		dim o as Fl_Spinner ptr = new Fl_Spinner(465, 216, 80, 24, "FL_FLOAT_INPUT")
		o->type_(1)
		o->labelsize(8)
		o->minimum(0)
		o->maximum(1)
		o->step_(0.01)
		o->value(0.05)
		o->align(FL_ALIGN_BOTTOM)
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(300, 270, 270, 105, "Fl_Dial")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Dial ptr = new Fl_Dial(320, 295, 65, 65, "0")
		o->tooltip("Standard Dial")
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->value(0.5)
		o->callback(cast(Fl_Callback,@callback))
		o->angles(0,315)
	end scope
	scope
		dim o as Fl_Dial ptr = new Fl_Dial(400, 295, 65, 65, "FL_LINE_DIAL")
		o->tooltip("Line Dial")
		o->type_(1)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->value(0.5)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Dial ptr = new Fl_Dial(480, 295, 65, 65, "FL_FILL_DIAL")
		o->tooltip("Fill Dial")
		o->type_(2)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->value(1)
		o->callback(cast(Fl_Callback,@callback))
		o->angles(0,360)
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(300, 385, 150, 115, "Fl_Roller")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Roller ptr = new Fl_Roller(315, 390, 20, 95, "0")
		o->tooltip("Vertical Roller")
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Roller ptr = new Fl_Roller(345, 430, 90, 20, "FL_HORIZONTAL")
		o->tooltip("Horizontal Roller")
		o->type_(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(460, 385, 110, 115, "Some widgets have color(FL_GREEN) and color2(FL_RED) to show the areas these effect.")
		o->box(FL_BORDER_FRAME)
		o->color(FL_FOREGROUND_COLOR)
		o->selection_color(FL_FOREGROUND_COLOR)
		o->labelsize(11)
		o->align(FL_ALIGN_WRAP)
	end scope

	o->end_()
end scope
w->show(__FB_ARGC__, __FB_ARGV__)
Fl.run_()

Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

angros47 wrote: Jul 09, 2023 20:30 valuators.bi

Code: Select all

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

#include once "FLTK/Fl_Box.bi"
#include once "FLTK/Fl_Slider.bi"
#include once "FLTK/Fl_Value_Slider.bi"
#include once "FLTK/Fl_Value_Input.bi"
#include once "FLTK/Fl_Value_Output.bi"
#include once "FLTK/Fl_Scrollbar.bi"
#include once "FLTK/Fl_Adjuster.bi"
#include once "FLTK/Fl_Counter.bi"
#include once "FLTK/Fl_Spinner.bi"
#include once "FLTK/Fl_Dial.bi"
#include once "FLTK/Fl_Roller.bi"
valuators.bas

Code: Select all

#include once "valuators.bi"

private sub callback cdecl(o as Fl_Widget ptr, z as any ptr)
  print cast(Fl_Valuator ptr,o)->value()
end sub

dim w as Fl_Double_Window ptr
scope
	dim o as Fl_Double_Window ptr = new Fl_Double_Window(580, 510, "Valuator classes, showing values for type()")
	w = o
	o->color(43)
	o->selection_color(43)
	scope
		dim o as Fl_Box ptr = new Fl_Box(10, 10, 280, 210, "Fl_Slider")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(30, 45, 20, 145, "0")
		o->tooltip("Vertical Slider")
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(70, 55, 20, 145, "FL_VERT_FILL_SLIDER")
		o->type_(2)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(105, 45, 20, 145, "FL_VERT_NICE_SLIDER")
		o->type_(4)
		o->box(FL_FLAT_BOX)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(140, 80, 130, 20, "FL_HORIZONTAL")
		o->type_(1)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(140, 120, 130, 20, "FL_HOR_FILL_SLIDER")
		o->type_(3)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Slider ptr = new Fl_Slider(140, 160, 130, 20, "FL_HOR_NICE_SLIDER")
		o->type_(5)
		o->box(FL_FLAT_BOX)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(10, 230, 280, 210, "Fl_Value_Slider")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(30, 260, 30, 145, "0")
		o->tooltip("Value Slider")
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(70, 275, 30, 140, "FL_VERT_FILL_SLIDER")
		o->type_(2)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(110, 260, 20, 145, "FL_VERT_NICE_SLIDER")
		o->type_(4)
		o->box(FL_FLAT_BOX)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(140, 290, 130, 20, "FL_HOR_SLIDER")
		o->type_(1)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(140, 330, 130, 20, "FL_HOR_FILL_SLIDER")
		o->type_(3)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Value_Slider ptr = new Fl_Value_Slider(140, 370, 130, 20, "FL_HOR_NICE_SLIDER")
		o->type_(5)
		o->box(FL_FLAT_BOX)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(10, 450, 135, 50, "Fl_Value_Input")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Value_Input ptr = new Fl_Value_Input(30, 470, 105, 25, "0")
		o->tooltip("Value Input")
		o->labelsize(8)
		o->maximum(100)
		o->step_(0.1)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(155, 450, 135, 50, "Fl_Value_Output")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Value_Output ptr = new Fl_Value_Output(170, 470, 105, 25, "0")
		o->tooltip("Value Output")
		o->labelsize(8)
		o->maximum(100)
		o->step_(0.1)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(300, 10, 130, 120, "   Fl_Scrollbar")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP_LEFT or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Scrollbar ptr = new Fl_Scrollbar(305, 65, 95, 20, "FL_HORIZONTAL")
		o->tooltip("Horizontal Scrollbar")
		o->type_(1)
		o->labelsize(8)
		o->maximum(100)
		cast(Fl_Slider ptr, o)->value(20)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Scrollbar ptr = new Fl_Scrollbar(400, 20, 20, 105, "0")
		o->tooltip("Vertical Scrollbar")
		o->labelsize(8)
		o->maximum(100)
		o->callback(cast(Fl_Callback,@callback))
		o->align(FL_ALIGN_TOP)
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(440, 10, 130, 120, "Fl_Adjuster")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Adjuster ptr = new Fl_Adjuster(450, 60, 75, 25, "w()>h()")
		o->tooltip("Horizontal Adjuster")
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Adjuster ptr = new Fl_Adjuster(530, 35, 25, 75, "w()<h()")
		o->tooltip("Vertical Adjuster")
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(300, 140, 130, 120, "Fl_Counter")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Counter ptr = new Fl_Counter(310, 175, 110, 25, "0")
		o->tooltip("Standard Counter")
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Counter ptr = new Fl_Counter(310, 215, 110, 25, "FL_SIMPLE_COUNTER")
		o->tooltip("Simple Counter")
		o->type_(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(440, 140, 130, 120, "Fl_Spinner")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Spinner ptr = new Fl_Spinner(465, 176, 80, 24, "FL_INT_INPUT")
		o->labelsize(8)
		o->minimum(-30)
		o->maximum(30)
		o->step_(2)
		o->value(5)
		o->align(FL_ALIGN_BOTTOM)
	end scope
	scope
		dim o as Fl_Spinner ptr = new Fl_Spinner(465, 216, 80, 24, "FL_FLOAT_INPUT")
		o->type_(1)
		o->labelsize(8)
		o->minimum(0)
		o->maximum(1)
		o->step_(0.01)
		o->value(0.05)
		o->align(FL_ALIGN_BOTTOM)
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(300, 270, 270, 105, "Fl_Dial")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Dial ptr = new Fl_Dial(320, 295, 65, 65, "0")
		o->tooltip("Standard Dial")
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->value(0.5)
		o->callback(cast(Fl_Callback,@callback))
		o->angles(0,315)
	end scope
	scope
		dim o as Fl_Dial ptr = new Fl_Dial(400, 295, 65, 65, "FL_LINE_DIAL")
		o->tooltip("Line Dial")
		o->type_(1)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->value(0.5)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Dial ptr = new Fl_Dial(480, 295, 65, 65, "FL_FILL_DIAL")
		o->tooltip("Fill Dial")
		o->type_(2)
		o->color(10)
		o->selection_color(1)
		o->labelsize(8)
		o->value(1)
		o->callback(cast(Fl_Callback,@callback))
		o->angles(0,360)
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(300, 385, 150, 115, "Fl_Roller")
		o->box(FL_ENGRAVED_BOX)
		o->labelfont(1)
		o->align(FL_ALIGN_TOP or FL_ALIGN_INSIDE)
	end scope
	scope
		dim o as Fl_Roller ptr = new Fl_Roller(315, 390, 20, 95, "0")
		o->tooltip("Vertical Roller")
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Roller ptr = new Fl_Roller(345, 430, 90, 20, "FL_HORIZONTAL")
		o->tooltip("Horizontal Roller")
		o->type_(1)
		o->labelsize(8)
		o->callback(cast(Fl_Callback,@callback))
	end scope
	scope
		dim o as Fl_Box ptr = new Fl_Box(460, 385, 110, 115, "Some widgets have color(FL_GREEN) and color2(FL_RED) to show the areas these effect.")
		o->box(FL_BORDER_FRAME)
		o->color(FL_FOREGROUND_COLOR)
		o->selection_color(FL_FOREGROUND_COLOR)
		o->labelsize(11)
		o->align(FL_ALIGN_WRAP)
	end scope

	o->end_()
end scope
w->show(__FB_ARGC__, __FB_ARGV__)
Fl.run_()

for information, this code does not compile with the following error messages:

with gas64

fbc "_valuators.bas" -gen gas64 -w all -s gui
ld: _valuators.o: in function `Fl_Spinner::format(char const*)':
(.text+0x2391): undefined reference to `Fl_Spinner::update()'
ld: _valuators.o: in function `Fl_Spinner::step_(double)':
(.text+0x24bc): undefined reference to `Fl_Spinner::update()'
ld: _valuators.o: in function `Fl_Spinner::value(double)':
(.text+0x2546): undefined reference to `Fl_Spinner::update()'
Compilation failed.

and gcc

fbc "_valuators.bas" -gen gcc -Wc -Os -s gui
ld: _valuators.o: in function `main':
_valuators.c:(.text.startup+0x9f1): undefined reference to `Fl_Spinner::update()'
ld: _valuators.c:(.text.startup+0xa07): undefined reference to `Fl_Spinner::update()'
ld: _valuators.c:(.text.startup+0xa5a): undefined reference to `Fl_Spinner::update()'
ld: _valuators.c:(.text.startup+0xa97): undefined reference to `Fl_Spinner::update()'
ld: _valuators.c:(.text.startup+0xaad): undefined reference to `Fl_Spinner::update()'
Compilation failed.

the other codes compile without problem

freebasic version : 1.10
angros47
Posts: 2385
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

Ok, that's weird: the function is implemented in the include file, but in my version of the library it seems implemented in the library as well.
BTW, try replacing the file Fl_Spinner.bi with this:

Code: Select all

#include once "Enumerations.bi"
#include once "Fl_Group.bi"
#include once "Fl_Input.bi"
#include once "Fl_Repeat_Button.bi"

#include once "crt/stdio.bi"

extern "c++"
type Fl_Spinner extends Fl_Group
	value_ as double
	minimum_ as double
	maximum_ as double
	step__ as double
	format_ as const zstring ptr

	input_ as Fl_Input = any
	up_button_ as Fl_Repeat_Button = any
	down_button_ as Fl_Repeat_Button = any

	declare static sub sb_cb(w as Fl_Widget ptr, sb as Fl_Spinner ptr)
	declare sub update()
protected:
	declare constructor (byref b as const Fl_Spinner)
	declare operator let (byref b as const Fl_Spinner)

public:
	declare constructor(X as long, Y as long, W as long, H as long, L as const zstring ptr = 0)

	declare function format() as const zstring ptr
	declare sub format(f as const zstring ptr)
	declare function handle(event as long) as long

	declare const function maximum() as double
	declare sub maximum(m as double)
	declare const function minimum() as double
	declare sub minimum(m as double)
	declare sub range(a as double, b as double)
	declare sub resize(X as long, Y as long, W as long, H as long)
	declare const function step_() as double
	declare sub step_(s as double)
	declare const function textcolor() as Fl_Color
	declare sub textcolor(c as Fl_Color)
	declare const function textfont() as Fl_Font
	declare sub textfont(f as Fl_Font)
	declare const function textsize() as Fl_Fontsize
	declare sub textsize(s as Fl_Fontsize)
	declare const function type_() as ubyte
	declare sub type_(v as ubyte)
	declare const function value() as double
	declare sub value(v as double)
	declare sub color(v as Fl_Color)
	declare const function color() as Fl_Color
	declare sub selection_color(val_ as Fl_Color)
	declare const function selection_color() as Fl_Color
end type
end extern

private sub Fl_Spinner.sb_cb(w as Fl_Widget ptr, sb as Fl_Spinner ptr)

	dim v as double

	if w = @sb->input_ then
		v = val(*sb->input_.value())

		if v < sb->minimum_ then
			sb->value_ = sb->minimum_
			sb->update()
		elseif v > sb->maximum_ then
			sb->value_ = sb->maximum_
			sb->update()
		else
			sb->value_ = v
		end if
	elseif w = @sb->up_button_ then
		v = sb->value_ + sb->step__

		if v > sb->maximum_ then
			sb->value_ = sb->minimum_
		else
			sb->value_ = v
		end if

		sb->update()
	elseif w = @sb->down_button_ then
		v = sb->value_ - sb->step__

		if v < sb->minimum_ then 
			sb->value_ = sb->maximum_
		else
			sb->value_ = v
		end if

		sb->update()
	end if

	sb->set_changed()
	sb->do_callback()

end sub

private sub Fl_Spinner.update()
	dim s as zstring * 255

	if left(*format_,3)="%.*" then
		dim c as integer = 0
		dim temp as zstring * 64
		dim sp as zstring ptr=@temp
		sprintf(temp, "%.12f", step_)
		do while *sp: sp+=1: loop
		sp-=1
		do while *sp>temp andalso *sp=asc("0"): sp-=1:loop
		do while *sp>temp andalso (*sp>=asc("0") andalso *sp<=asc("9") ):  sp-=1: c+=1: loop
		sprintf(s, format_, c, value_)
	else 
		sprintf(s, format_, value_)
	end if
	input_.value(s)
end sub



private function Fl_Spinner.format() as const zstring ptr
	return format_
end function

private sub Fl_Spinner.format(f as const zstring ptr)
	format_=f
	update()
end sub


private function Fl_Spinner.handle(event as long) as long
	select case (event) 
	case FL_KEYDOWN,  FL_SHORTCUT 
		if Fl.event_key() = _FL_Up then
			up_button_.do_callback()
			return 1
		elseif Fl.event_key() = _FL_Down then
			down_button_.do_callback()
			return 1
		else
			return 0
		end if

	case FL_FOCUS
		if input_.take_focus() then return 1 else return 0
	end select
	return base.handle(event)

end function


private function Fl_Spinner.maximum() as double
	return maximum_
end function

private sub Fl_Spinner.maximum(m as double)
	maximum_=m
end sub

private function Fl_Spinner.minimum() as double
	return minimum_
end function

private sub Fl_Spinner.minimum(m as double)
	minimum_=m
end sub

private sub Fl_Spinner.range(a as double, b as double)
	minimum_=a: maximum_=b
end sub

private sub Fl_Spinner.resize(X as long, Y as long, W as long, H as long)
	base.resize(X,Y,W,H)

	input_.resize(X, Y, W - H / 2 - 2, H)
	up_button_.resize(X + W - H / 2 - 2, Y, H / 2 + 2, H / 2)
	down_button_.resize(X + W - H / 2 - 2, Y + H - H / 2, H / 2 + 2, H / 2)
end sub

private function Fl_Spinner.step_() as double
	return step__
end function

private sub Fl_Spinner.step_(s as double)
	step__ = s
	if step__ <>cast(long, step__) then 
			input_.type_(FL_FLOAT_INPUT_)
	else
		 input_.type_(FL_INT_INPUT_)
	end if
	update()

end sub

private function Fl_Spinner.textcolor() as Fl_Color
	return input_.textcolor()
end function

private sub Fl_Spinner.textcolor(c as Fl_Color)
	input_.textcolor(c)
end sub

private function Fl_Spinner.textfont() as Fl_Font
	return input_.textfont()
end function

private sub Fl_Spinner.textfont(f as Fl_Font)
	input_.textfont(f)
end sub

private function Fl_Spinner.textsize() as Fl_Fontsize
	return input_.textsize()
end function

private sub Fl_Spinner.textsize(s as Fl_Fontsize)
	input_.textsize(s)
end sub

private function Fl_Spinner.type_() as ubyte
	return input_.type_()
end function

private sub Fl_Spinner.type_(v as ubyte)
	if v=FL_FLOAT_INPUT_ then
		format("%.*f")
	else
		format("%.0f")
	end if

	input_.type_(v)
end sub

private function Fl_Spinner.value() as double
	return value_
end function

private sub Fl_Spinner.value(v as double)
	value_ = v: update()
end sub

private sub Fl_Spinner.color(v as Fl_Color)
	input_.color(v)
end sub

private function Fl_Spinner.color() as Fl_Color
	return input_.color()
end function

private sub Fl_Spinner.selection_color(val_ as Fl_Color)
	input_.selection_color(val_)
end sub

private function Fl_Spinner.selection_color() as Fl_Color
	return input_.selection_color()
end function


Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

yes, that solves the problem, thank you for your answer.
the example is impressive, we immediately see the potential of FLTK.

note that compiling with gcc produces this message :

fbc "_valuators.bas" -gen gcc -Wc -Os -s gui
_valuators.c:395:7: warning: conflicting types for built-in function ‘sprintf’; expected ‘int(char *, const char *, ...)’ [-Wbuiltin-declaration-mismatch]
395 | int32 sprintf( uint8*, uint8*, ... );
| ^~~~~~~
_valuators.c:1:1: note: ‘sprintf’ is declared in header ‘<stdio.h>’
+++ |+#include <stdio.h>
1 | typedef signed char int8;

Compilation completed successfully.
angros47
Posts: 2385
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

The issue you reported seems related to a more generic issue:

viewtopic.php?t=32305
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

angros47 wrote: Jul 12, 2023 22:18 The issue you reported seems related to a more generic issue:

viewtopic.php?t=32305
Thank you for your reply. I confirm that the code compiles and executes correctly. the freebasic maintainers should fix this problem. the c c++ language is very strict. ignoring compiler warnings can only lead to more serious problems later.
coderJeff
Site Admin
Posts: 4382
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

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

Post by coderJeff »

Coolman wrote: Jul 13, 2023 10:34 Thank you for your reply. I confirm that the code compiles and executes correctly. the freebasic maintainers should fix this problem. the c c++ language is very strict. ignoring compiler warnings can only lead to more serious problems later.
What version / platform of gcc? We are using gcc as a high-level assembler and I suppose we've gotten away with close enough typing in older versions of gcc where perhaps these kinds of warnings were not enabled by default or did not exist.
Post Reply