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

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

Post by angros47 »

Ok, I should have ported all the files. Some won't work on version 1.09 because they use the "alias char" command. Also, when nested types will be available I should modify some files, that contain a temporarily handmade mangle of some C++ functions.

But for now, it should already be usable on DOS, Linux, and on Windows 64 bit (not on Windows 32 bit)
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

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

Post by coderJeff »

nested types are basically available though there is still work do on some aspects. Depends on what is required by fltk if our feature is 'good enough'. Like it might work, or you may find that it doesn't and then it's a bug or some feature that needs to be improved. I kind of skip all over the place on bug fixes and development, but I think the nested types will eventually be something we return to. I am hoping fxm will set me straight.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

Ok, tested with FreeBASIC 1.10, and it seems to compile and work even for Win32

I update the code, to take advantage of the nested TYPEs (without them, some method's names weren't mangled correctly, and I had to call the mangled name manually; that's not needed anymore) and of the 'alias "char" ' feature
Roland Chastain
Posts: 992
Joined: Nov 24, 2011 19:49
Location: France
Contact:

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

Post by Roland Chastain »

Hello!

Tested the latest version of the library on Linux, with FBC 1.10 and the examples provided in this discussion. All compile and work fine.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

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

Post by coderJeff »

angros47 wrote: Jun 04, 2023 23:14 Ok, tested with FreeBASIC 1.10, and it seems to compile and work even for Win32
Roland Chastain wrote: Jun 05, 2023 5:29 Tested the latest version of the library on Linux, with FBC 1.10 and the examples provided in this discussion. All compile and work fine.
Golly, that's some good news!

One thing to watch out for is:
win32 + 32-bit + 'extern c++' + 'constructor or destructor' + arrays


Both fbc compiler and fb run time make some assumptions about the calling convention of constructors always being 'cdecl' - which is not necessarily true if given above situation. The array's data type is solved at compile time but not all information is passed to fb runtime and in particular the calling convention for the constructors/destructors. So, DIM, REDIM, ERASE might fail in weird ways, sorry. Maybe can be solved by adding extra flags to the ARRAY DESCRIPTOR to indicate for the ctors/dtors need to be called. I think NEW[]/DELETE[] probably work though.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

I wonder, should the FLTK headers be added to the FreeBasic include files? As far as I know, it's the only GUI that works in Windows, Linux, and even DOS
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

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

Post by coderJeff »

angros47 wrote: Jun 11, 2023 18:42 I wonder, should the FLTK headers be added to the FreeBasic include files? As far as I know, it's the only GUI that works in Windows, Linux, and even DOS
Sure, we can do that. Recently, I have thought about contributions in general for fbc 1.20 since it seems I have missed my chances in past few years. If the contribution is includes only, is of interest, has support, and is of reasonable quality, then it is fairly easy to get it added. Maybe only question is of user expectation and being located in './inc/<thing>' or something like './inc/contrib/<thing>'. Maybe a conversation for another thread -- what happens in 2 to 3 years when we have <thing> added but the original contributor is no longer interested, or rage-quits the community, and original contribution is out of date; is it ok to remove?

Anyway, if you (or someone you know can help) get it in to a pull request against current fbc/master that would be awesome.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

Pull request sent.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

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

Post by coderJeff »

angros47 wrote: Jun 13, 2023 23:20 Pull request sent.
Thank-you for the pull request. Do you think you will continue to support with pull requests in the future? Or is their hope that developers and users will take it over?
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

I hope developers and users could take over, in future, but I will try to provide support, if I can.
Roland Chastain
Posts: 992
Joined: Nov 24, 2011 19:49
Location: France
Contact:

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

Post by Roland Chastain »

angros47 wrote: Jun 21, 2023 23:52 I hope developers and users could take over, in future, but I will try to provide support, if I can.
Could you share also your examples somewhere?
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

I modified my test file to try the various feature, adding and removing them one by one, so it is a huge mess, actually, at the moment
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

Ok, here is an example, ported from the examples in C++:

radio.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_Return_Button.bi"
#include once "FLTK/Fl_Light_Button.bi"
#include once "FLTK/Fl_Check_Button.bi"
#include once "FLTK/Fl_Round_Button.bi"
#include once "FLTK/Fl_Group.bi"
#include once "FLTK/Fl_Output.bi"
extern cb_info alias "cb_info" as Fl_Output ptr
radio.bas

Code: Select all

#include once "radio.bi"

private sub button_cb cdecl( b as Fl_Button ptr, m as any ptr) 
	dim msg as zstring*255
	'sprintf(msg, "Label: '%s'\nValue: %d", b->label(),b->value())
	msg="Label: '" & *b->label() & !"'\n" & "Value: " & str(b->value())
	cb_info->value(msg)
	cb_info->redraw()
	print msg
end sub

dim shared cb_info as Fl_Output ptr

dim w as Fl_Double_Window ptr
scope
	dim o as Fl_Double_Window ptr = new Fl_Double_Window(369, 214)
	w = o
	scope
		dim o as Fl_Button ptr = new Fl_Button(20, 10, 160, 30, "&Fl_Button A1")
		o->tooltip("Normal button (callback called only when released)")
		o->labelsize(13)
		o->callback(cast(Fl_Callback, @button_cb))
	end scope
	scope
		dim o as Fl_Button ptr = new Fl_Button(20, 44, 160, 30, "Fl_Button &A2")
		o->tooltip("Normal button with callback called when changed (push and released)")
		o->labelsize(13)
		o->when(FL_WHEN_CHANGED)
		o->callback(cast(Fl_Callback, @button_cb))
	end scope
	scope
		dim o as Fl_Return_Button ptr = new Fl_Return_Button(20, 78, 160, 30, "Fl_Return_Button &B")
		o->tooltip("Button with Return key as default shortcut")
		o->labelsize(13)
		o->callback(cast(Fl_Callback, @button_cb))
	end scope
	scope
		dim o as Fl_Light_Button ptr = new Fl_Light_Button(20, 113, 160, 30, "Fl_Light_Button &C")
		o->tooltip("Button with toggle state and a visual indicator of the current state")
		o->labelsize(13)
		o->callback(cast(Fl_Callback, @button_cb))
	end scope
	scope
		dim o as Fl_Check_Button ptr = new Fl_Check_Button(20, 148, 160, 30, "Fl_Check_Button &D")
		o->tooltip("Check button with toggle state")
		o->down_box(FL_DOWN_BOX)
		o->labelsize(13)
		o->callback(cast(Fl_Callback, @button_cb))
	end scope
	scope
		dim o as Fl_Round_Button ptr = new Fl_Round_Button(20, 178, 160, 30, "Fl_Round_Button &E")
		o->tooltip("Round Button with toggle state")
		o->down_box(_FL_ROUND_DOWN_BOX)
		o->labelsize(13)
		o->callback(cast(Fl_Callback, @button_cb))
	end scope
	scope
		dim o as Fl_Group ptr = new Fl_Group(190, 10, 70, 120)
		o->box(FL_THIN_UP_FRAME)
		scope
			dim o as Fl_Round_Button ptr = new Fl_Round_Button(190, 10, 70, 30, "radio &1")
			o->tooltip("Radio button, only one button is set at a time, in the corresponding group.")
			o->type_(102)
			o->down_box(_FL_ROUND_DOWN_BOX)
			o->callback(cast(Fl_Callback, @button_cb))
		end scope
		scope
			dim o as Fl_Round_Button ptr = new Fl_Round_Button(190, 40, 70, 30, "radio &2")
			o->tooltip("Radio button, only one button is set at a time, in the corresponding group.")
			o->type_(102)
			o->down_box(_FL_ROUND_DOWN_BOX)
			o->callback(cast(Fl_Callback, @button_cb))
		end scope
		scope
			dim o as Fl_Round_Button ptr = new Fl_Round_Button(190, 70, 70, 30, "radio &3")
			o->tooltip("Radio button, only one button is set at a time, in the corresponding group.")
			o->type_(102)
			o->down_box(_FL_ROUND_DOWN_BOX)
			o->callback(cast(Fl_Callback, @button_cb))
		end scope
		scope
			dim o as Fl_Round_Button ptr = new Fl_Round_Button(190, 100, 70, 30, "radio &4")
			o->tooltip("Radio button, only one button is set at a time, in the corresponding group.")
			o->type_(102)
			o->down_box(_FL_ROUND_DOWN_BOX)
			o->callback(cast(Fl_Callback, @button_cb))
		end scope
		o->end_()
	end scope
	scope
		dim o as Fl_Group ptr = new Fl_Group(270, 10, 90, 120)
		o->box(FL_THIN_UP_BOX)
		scope
			dim o as Fl_Button ptr = new Fl_Button(280, 20, 20, 20, "radio")
			o->tooltip("Custom look button, only one button is set at a time, in the corresponding group.")
			o->type_(102)
			o->selection_color(1)
			o->align(FL_ALIGN_RIGHT)
		end scope
		scope
			dim o as Fl_Button ptr = new Fl_Button(280, 45, 20, 20, "radio")
			o->tooltip("Custom look button, only one button is set at a time, in the corresponding group.")
			o->type_(102)
			o->selection_color(1)
			o->align(FL_ALIGN_RIGHT)
		end scope
		scope
			dim o as Fl_Button ptr = new Fl_Button(280, 70, 20, 20, "radio")
			o->tooltip("Custom look button, only one button is set at a time, in the corresponding group.")
			o->type_(102)
			o->selection_color(1)
			o->align(FL_ALIGN_RIGHT)
		end scope
		scope
			dim o as Fl_Button ptr = new Fl_Button(280, 95, 20, 20, "radio")
			o->tooltip("Custom look button, only one button is set at a time, in the corresponding group.")
			o->type_(102)
			o->selection_color(1)
			o->align(FL_ALIGN_RIGHT)
		end scope
		o->end_()
	end scope
	scope
		cb_info = new Fl_Output(190, 148, 170, 62, "callback:")
		cb_info->type_(12)
		cb_info->textsize(12)
		cb_info->align(133)
	end scope
	o->end_()
end scope
w->show(__FB_ARGC__,__FB_ARGV__)
Fl.run_()
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

Another example:

twowin.bas:

Code: Select all

'
' "$Id$"
'
' Cross-window focus test program for the Fast Light Tool Kit (FLTK).
'
' Copyright 1998-2015 by Bill Spitzak and others.
'
' This library is free software. Distribution and use rights are outlined in
' the file "COPYING" which should have been included with this file.  If this
' file is missing or damaged, see the license at:
'
'     http://www.fltk.org/COPYING.php
'
' Please report all bugs and problems on the following page:
'
'     http://www.fltk.org/str.php
'

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

dim shared as Fl_Input ptr b1, b2

private sub cb1(a as Fl_Widget ptr, b as any ptr)
	b2->take_focus()
end sub

private sub cb2(a as Fl_Widget ptr, b as any ptr)
	b1->take_focus()
end sub

dim win1 as Fl_Double_Window ptr = new Fl_Double_Window(200, 200)
dim bb1 as Fl_Button ptr = new Fl_Button(10, 10, 100, 100, "b1")
bb1->callback(@cb1)
b1 = new Fl_Input(10, 150, 100, 25)
win1->label("win1")
win1->end_()

dim win2 as Fl_Double_Window ptr = new Fl_Double_Window(200, 200)
dim bb2 as Fl_Button ptr = new Fl_Button(10, 10, 100, 100, "b2")
bb2->callback(@cb2)
b2 = new Fl_Input(10, 150, 100, 25)
win2->label("win2")
win2->end_()

win1->position(200, 200)
win2->position(400, 200)

win1->show(__FB_ARGC__,__FB_ARGV__)
win2->show()
Fl.run_()
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

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

Post by coderJeff »

angros47 wrote: Jun 21, 2023 23:52 I hope developers and users could take over, in future, but I will try to provide support, if I can.
FLTK headers are now merged in to fbc 1.20 development (master branch). Thanks.

To be honest, I don't know how much time I will have for this, so my hope too will be that others take up the effort if you are are unable. (I think my hang up in the past when trying to decide about merging in user contributions is who will finish the work and maintain it? Because the project is already full of unfinished and unmaintained things. So this time I just hope for the best).
Post Reply