FLTK-C-1.3.3 for FreeBASIC

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Knatterton »

Baptiste wrote:Excuse me, Knatterton, I did not see your message
No problem, we can handle more topics at once like we often do. :-)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

Code: Select all

#include once "fltk-c.bi"

' get current value from counter1 or counter2 
' and set var Value1 or Value2 (!!! exists outside the callback !!!)
sub CounterCB cdecl (byval self as FL_WIDGET ptr, byval userdata as any ptr)
  var Value = Fl_ValuatorGetValue(cptr(Fl_Valuator ptr,self))
  print "Value = " & Value
 *cptr(double ptr,userdata)=Value
end sub
'
' main
'
var win = Fl_WindowNew(212,112,"Fl_Counter04.bas")
var counter1 = Fl_CounterNew(10,10,192,24,"Fl_counter 1")
Fl_ValuatorBounds(counter1,2,18)
Fl_ValuatorSetValue(counter1,2)
Fl_ValuatorSetStep(counter1,1)

var counter2 = Fl_CounterNew(10,64,192,24,"Fl_counter 2")
Fl_ValuatorSetStep(counter2,1)
' !!! counter2.min = counter2.max !!!
Fl_ValuatorSetMinimum(counter2,Fl_ValuatorGetMaximum(counter1))
' !!! counter2.value must be >= counter2.min !!!
Fl_ValuatorSetValue(counter2,Fl_ValuatorGetMinimum(counter2))

' !!! Value 1 and 2 can be used outside of the callback !!!
dim as double Value1,Value2
Fl_WidgetSetCallbackArg(counter1,@CounterCB,@Value1)
Fl_WidgetSetCallbackArg(counter2,@CounterCB,@Value2)


Fl_WindowSetResizable(win,win)
Fl_WindowShow(win)
Fl_Run()
Last edited by D.J.Peters on Jul 01, 2019 22:18, edited 1 time in total.
Baptiste
Posts: 17
Joined: May 15, 2019 10:58

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Baptiste »

Thank you Joshy for your patience
My little example program works.
as we say at home "I understand quickly, but we must explain myself a long time"
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

I added a PDF download "FLTK 1.3.0 Programming Manual" good for offline reading see first post.

Joshy
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Knatterton »

Here i have a draft of an IDE for FB with Fltk-c. It even works in linux if fbc is on the path, just tested. For MS or Mac please test.

Code: Select all

' FastLighter.bas
' IDE for FreeBASIC 1.06 and Fltk-c 1.3.3 
' by Knatterton

#include once "datetime.bi"
#include once "fltk-c.bi"

dim shared as ubyte r8=128,g8=64,b8=0
dim shared as double rr=0.5,gg=0.26,bb=0.0
dim shared as zstring ptr file = @"FastLighter.bas"
dim shared as zstring ptr path = @"/usr/local/bin/fbc"
dim shared as string exename
dim shared as string cmdline
exename = "fbc"
cmdline = "/usr/local/bin/fbc"

dim as Fl_Window ptr win = Fl_WindowNew(1024,768, "FastLighter.bas")
var edt = Fl_Text_EditorNew(10,40,Fl_WidgetGetW(win)-20,Fl_WidgetGetH(win)-50)
dim shared as Fl_Text_Buffer ptr buf
buf = Fl_Text_BufferNew()
var hd  = Fl_Text_BufferNew()

' menubar
sub NewCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
  Fl_Text_BufferSetText(buf,"")
end sub

sub OpenCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
  flFileChooserOkLabel("Open")
  file = flFileChooser("select a file","*.bas", ExePath(), 1) ' 1 = relative 0 = absolute path
  Fl_Text_BufferLoadFile(buf,file) 
  print *file
end sub

sub SaveCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
  if Fl_Text_BufferSaveFile(buf,file) <> 0 then
    print "error"
  end if
end sub

sub SaveAsCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
  flFileChooserOkLabel("Save")
  file = flFileChooser("select a file","*.bas", ExePath(), 1) ' 1 = relative 0 = absolute path
  if Fl_Text_BufferSaveFile(buf,file) <> 0 then
    print "error"
  end if
end sub

sub PrintCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
end sub

sub QuitCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
  if flChoice("Do you really want to exit ?","no","yes") then
    Fl_WindowHide Fl_WidgetWindow(self)
  end if
end sub

sub UndoCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
end sub

sub CutCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
end sub

sub CopyCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
end sub

sub PasteCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
end sub

sub DeleteCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
end sub

sub FindCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
end sub

sub ReplaceCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
  var hv  = Fl_Help_ViewNew(10,10,620,460)
  Fl_Help_ViewLoad hv,"media/test01.html"
end sub

sub CompileCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
   'A Windows based example but the same idea applies to Linux
	Dim result As Integer
	result = Exec( exename, *file) 'cmdline )
	If result = -1 Then
	    Print "Error running "; exename
	Else
	    Print "Exit code:"; result
	End If
end sub

sub InputCB cdecl (byval self as Fl_Widget ptr)
  print *file
end sub

sub InputButtonCB cdecl (byval button as FL_WIDGET ptr)
  flFileChooserOkLabel("Take it")
  path = flFileChooser("Find FBC","*", path, 0) ' 1 = relative 0 = absolute path
  print *path
end sub

sub EndButtonCB cdecl (byval button as FL_WIDGET ptr)
  'end
 ' Fl_WindowHide pref
end sub

Dim Shared As Fl_Input Ptr Input_text

sub PrefCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
	var pref = Fl_WindowNew(440, 100, "Preferences")
	
	Input_text = Fl_InputNew(120, 12,200, 20, "Path to FBC:")
	Fl_WidgetSetCallback0(Input_text, @InputCB)
	Fl_Input_SetValue(Input_text, path)
	
	var Btn1 = Fl_ButtonNew(330,12,60,22,"Choose")
	Fl_WidgetSetCallback0 Btn1,@InputButtonCB
	
	var Btn2 = Fl_ButtonNew(330,60,60,22,"OK")
	Fl_WidgetSetCallback0 Btn2,@EndButtonCB
	Fl_WindowShow pref
end sub

sub ColorCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
  flColorChooser "flColorChooser()",r8,g8,b8, FL_COLORCHOOSER_RGB
end sub

sub DokuCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
  var WinWidth = 800
  var WinHeight = 600
  var win = Fl_Double_WindowNew2(Fl_GetW()/2-WinWidth /2, Fl_GetH()/2-WinHeight/2, _
      WinWidth,WinHeight,"Documentation")                    
  var hv  = Fl_Help_ViewNew(0,0,800,600)
  Fl_Help_ViewLoad hv,"Html/any.html"
  Fl_GroupSetResizable win,hv
  Fl_WindowShow win
end sub

sub AboutCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
  flMessage("FastLighter by Knatterton")
end sub

Fl_Register_Images()
Fl_WindowBegin(win)

Fl_Text_DisplaySetLinenumberWidth edt,40 ' 0 = line numbers off
Fl_Text_DisplaySetBuffer edt,buf

if Fl_Text_BufferLoadFile(buf,"FastLighter.bas") <> 0 then
  Fl_Text_BufferSetText(buf,!"print \"type your stuff\"")
end if

Fl_GroupSetResizable win,edt

var mnb = Fl_Menu_BarNew(0,0,1024,30)

' Overwrite default colors
Fl_Background(143,183,175)
Fl_Foreground(230,250,254)
Fl_Menu_SetTextFont(mnb,Fl_TIMES)

Fl_Menu_Add(mnb,"File/New"        , FL_CTRL+asc("n"),     @NewCB)
Fl_Menu_Add(mnb,"File/Open..."    , FL_CTRL+asc("o"),     @OpenCB)
Fl_Menu_Add(mnb,"File/Save"       , FL_CTRL+asc("s"),     @SaveCB)
Fl_Menu_Add(mnb,"File/Save &As...", FL_CTRL+asc("a"),     @SaveAsCB)
Fl_Menu_Add(mnb,"File/Print"      , FL_CTRL+asc("p"),     @PrintCB)
Fl_Menu_Add(mnb,"File/Quit"       , FL_CTRL+asc("q"),     @QuitCB)

Fl_Menu_Add(mnb,"Edit/Undo"       , FL_CTRL+asc("u"),     @UndoCB)
Fl_Menu_Add(mnb,"Edit/Cut"        , FL_CTRL+asc("x"),     @CutCB)
Fl_Menu_Add(mnb,"Edit/Copy"       , FL_CTRL+asc("v"),     @CopyCB)
Fl_Menu_Add(mnb,"Edit/Paste"      , FL_CTRL+asc("x"),     @PasteCB)
Fl_Menu_Add(mnb,"Edit/Delete"     , FL_CTRL+asc("x"),     @DeleteCB)
Fl_Menu_Add(mnb,"Edit/Search"     , FL_CTRL+asc("v"),     @AboutCB)
Fl_Menu_Add(mnb,"Edit/Colors"     , FL_CTRL+asc("z"),     @ColorCB)

Fl_Menu_Add(mnb,"Search/Find..."   ,FL_CTRL+asc("x"),     @FindCB)
Fl_Menu_Add(mnb,"Search/Replace...",FL_CTRL+asc("x"),     @ReplaceCB)
Fl_Menu_Add(mnb,"Search/Extended",  FL_CTRL+asc("x"),     @AboutCB)

Fl_Menu_Add(mnb,"Compile/Compile",     FL_CTRL+asc("c"),  @CompileCB)
Fl_Menu_Add(mnb,"Compile/Preferences", FL_CTRL+asc("p"),  @PrefCB)

Fl_Menu_Add(mnb,"Help/Documentation"  ,FL_CTRL+asc("d"),  @DokuCB)
Fl_Menu_Add(mnb,"Help/About",,                            @AboutCB)

Fl_Menu_Add3(mnb,"Help/Help/Item 1")
Fl_Menu_Add3(mnb,"Help/Help/Item 2")
Fl_Menu_Add3(mnb,"Help/Help/Item 3")

Fl_Register_Images()

Fl_WindowShow win
Fl_Run

' end FastLighter.bas
One thing i still haven't found out, how to do the positioning of the file-chooser. It appears mostly in the upper left corner. Few callbacks are not implemented now. Just a draft.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

I tested it on win32 and win64 :-)

Code: Select all

dim shared as zstring ptr file = @"FastLighter.bas"
dim shared as zstring ptr path = @"d:/FreeBASIC/"
dim shared as string exename
dim shared as string cmdline
exename = "fbc64.exe" ' I tested fbc32.exe
cmdline = path & exename
By the way for a syntax highlighting framework you can take a look at file: Fl_Text_Editor03.bas

Joshy
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Knatterton »

D.J.Peters wrote: By the way for a syntax highlighting framework you can take a look at file: Fl_Text_Editor03.bas
Yes, but then it becomes very long (to long to post here). It is extensible in many ways.
Last edited by Knatterton on Jul 04, 2019 11:30, edited 1 time in total.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Knatterton »

Maybe you never tried to make a more complex program and many windows with fltk-c. Then you see the problems beginners are faced. How to close a window from within a callback when it is defined with "var"? At such little problems one may become stuck and that's maybe why there are not much using fltk-c for bigger programs, i think.

At this point you begin to google and there you can find many docs and examples, but in many versions and styles which are mostly not directly useable for your project. Best would be to have examples for complex programs. :-)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

Knatterton wrote:Maybe you never tried to make a more complex program and many windows with fltk-c.
(Sorry about my bad written english)
You don't know not match about FLTK right ?

Some Linux X-Desktop managers are complete written in FLTK !

EDE Equinox Desktop Environment
Image

FLWM Fast Light Window Manager
Image
I self use FLTK and FLTK-C for many of my customers projects and this big programs (with many windows and dialogs) paid my bills in the past !
Knatterton wrote:How to close a window from within a callback when it is defined with "var"?
Every modern GUI program is event driven GTK, QT, IUP, FLTK etc.
Often beginners try to solve such simple problems by using global vars to have access from any callback.
The simplest solution in FLTK, GTK, QT, IUP are you can use the optional parameters for all kinds of callbacks.
Knatterton wrote:Best would be to have examples for complex programs. :-)
I wrote 2,600 C functions/methods for the FreeBASIC community so we can use the complete FLTK GUI with FreeBASIC.

Would be cool if you or other FLTK-C users write tutorials, help files or share complex FLTK-C GUI programs.

Of course I can answer many questions about FLTK-C to solve such problems of beginners.

Joshy
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Knatterton »

D.J.Peters wrote:You don't know not match about FLTK right ?
I know your examples for fltk-c and the similar systems oft wx-c (abandoned) and gtk. So it could be better and you can consider me as test-beginner for fltk-c in fb.
D.J.Peters wrote:Often beginners try to solve such simple problems by using global vars to have access from any callback.
Yes, that was the solution i came to. For programs with more windows, buffers and such i define all windows in the begnning like here:

Code: Select all

dim shared as Fl_Window ptr win = Fl_WindowNew(1024,768, "FastLighter.bas")
dim shared as Fl_Text_Buffer ptr buf
Then i can access them from within a callback.
D.J.Peters wrote:You are free to learn FLTK-C and publish tutorials or your own big program.
I will do my best but i dont know if this is good enough to serve as example for others.
D.J.Peters wrote:I wrote 2,600 C functions/methods for the FreeBASIC community so wee can use the complete FLTK GUI with FreeBASIC.

Would be cool if you or other FLTK-C users write tutorials, help files or share complex FLTK-C GUI programs.

Of course I can answer many question about FLTK-C to solve such problems of beginners.
We are already on your way. Lets see how it all developes.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Knatterton »

D.J.Peters wrote:Of course I can answer many questions about FLTK-C to solve such problems of beginners.
The most important question would be how to set the position of the file-chooser (see "FastLighter.bas"), because it appears mostly in upper left corner of the screen, while most windows are centered. :-)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

The class Fl_File_Chooser isn't a widget class where you can set the the x,y position or move it around.
It's a dialog class and the window/desktop manager put the dialog on screen.

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

What is with the native file chooser on your system ?

Joshy
Image

Code: Select all

#include once "fltk-c.bi"
' test of class Fl_Native_File_Chooser

#ifdef __FB_WIN32__
var pattern="fbc*.exe"
var defaultpath="\FreeBASIC\"
#else
var pattern="fbc"
var defaultpath="/usr/local/bin/"
#endif


' single file selection
var nfc = Fl_Native_File_ChooserNew(NFC_BROWSE_FILE)
Fl_Native_File_ChooserSetTitle      nfc,"Choose the location of FreeBASIC"
Fl_Native_File_ChooserSetFilter     nfc,pattern
Fl_Native_File_ChooserSetDirectory  nfc,defaultpath
Fl_Native_File_ChooserSetPresetFile nfc,""


if Fl_Native_File_ChooserShow(nfc)=0 then
  print "selected: " & *Fl_Native_File_ChooserFilename(nfc)
else
  print "no file selected !"
end if

Fl_Native_File_ChooserDelete nfc
print "..."
sleep
Last edited by D.J.Peters on Jul 07, 2019 0:36, edited 1 time in total.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Knatterton »

D.J.Peters wrote:The class Fl_File_Chooser isn't a widget class where you can set the the x,y position or move it around.
It's a dialog class and the window/desktop manager put the dialog on screen.
Thanks a lot, Joshy. I am glad that's not i am just to stupid to find out to set it. The point is: with file-chooser in upper left corner it is not possible to create cool programs in FB, because it looks really strange. :-)
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Knatterton »

D.J.Peters wrote:What is with the native file chooser on your system ?
That don't work in mint 19.2 64 with FB 1.0.6.

The above program shows dozens warnings and then dozens:

simple_native_2:5792): GdkPixbuf-CRITICAL **: 02:38:33.389: gdk_pixbuf_get_width: assertion 'GDK_IS_PIXBUF (pixbuf)' failed
Last edited by Knatterton on Jul 07, 2019 0:41, edited 1 time in total.
Post Reply