FLTK-C-1.3.3 for FreeBASIC

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 21, 2019 21:36

bcohio2001 wrote:I understand that I can use Fl_WindowExSetHandleCB to trap window events.
If I trap for the FL_EVENT_SHOW, is this run before or after the call to Fl_Run.

I would like to run a little init code that might create another window, other than the main.

Do you have a example snippet for this?
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Postby bcohio2001 » Jul 22, 2019 1:35

THIS IS A HACKED TOGETHER CODE JUST TO GIVE EXAMPLE

Code: Select all

Sub DoSomething()
   var win = Fl_WindowExNew(640,480,"Do something....")
   'create other "controls"
   Fl_WindowShow win
End Sub

function HandleCB cdecl (byval self as any ptr,byval event as FL_EVENT) as Long
   select case as const event
      Case FL_EVENT_SHOW
         'do some checks
         If GottaDoSomething Then DoSomething()
         '
      Case FL_EVENT_CLOSE
         'do some end of program code ... close any files, etc....
         '
   End Select
   'let FLTK handle it
   return Fl_WindowExHandleBase(self,event)
End Function

var win = Fl_WindowExNew(640,480,"Main dlg")
'create other "controls"
Fl_WindowExSetHandleCB win,@HandleCB
Fl_WindowShow win '<- HandleCB now?
Fl_Run
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 22, 2019 7:42

Thanks!
D.J.Peters
Posts: 8240
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Postby D.J.Peters » Jul 22, 2019 11:31

If I start coding with fltk-c at first I open in a IDE (FBIDE or Geany) the file "flt-main.bi" as a kind of mini command reference.

For example if you not sure what Fl_Run() does or is it needed at all I would search in the fltk-main.bi TAB for Fl_Run()

Joshy

Code: Select all

' #####################
' # FLTK Message Loop #
' #####################
' Fl_Wait() waits until "something happens" and then returns.
' Call this repeatedly to "run" your program.
' You can also check what happened each time after this returns,
' which is quite useful for managing program state.
' What Fl_Wait() really does is call all idle callbacks,
' all elapsed timeouts, call Fl_Flush() to get the screen to update,
' and then wait some time (zero if there are idle callbacks, the shortest of all pending timeouts, or infinity),
' for any events from the user or any Fl_Add_fd() callbacks.
' It then handles the events and calls the callbacks and then returns.
declare function Fl_Wait() as long
' Waits a maximum of time seconds.
' It can return much sooner if something happens.
declare function Fl_Wait2(byval timeout as double) as double
' Same as Fl_Wait2(0).
declare function Fl_Check() as long
' Fl_Ready is similar to Fl_Check() except this does not call Fl_Flush() or any callbacks,
' which is useful if your program is in a state where such callbacks are illegal.
declare function Fl_Ready() as long
' As long as any windows are displayed Fl_Run() calls Fl_Wait() repeatedly.
declare function Fl_Run() as long
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 22, 2019 14:04

D.J.Peters wrote:If I start coding with fltk-c at first I open in a IDE (FBIDE or Geany) the file "flt-main.bi" as a kind of mini command reference.

For example if you not sure what Fl_Run() does or is it needed at all I would search in the fltk-main.bi TAB for Fl_Run()

Yes i am using this file too, to see which functions available. This helps sometimes a lot.

Meanwhlle i have worked again whole night long on fbc_options.bas. It is a tricky fiddling around, but now it is in a state that almost all works. You can select a few options and with "OK" button the complete cmd-line is shown in console.

Code: Select all

' fbc_options.bas
' by Knatterton

#ifdef __FB_WIN32__ ' goes for all windows
   var shared fbc_name = @"fbc*.exe"
   var shared fbc_path = @"\FreeBASIC\"
   var shared defaultpath = @"\FreeBASIC\"
   var shared file_name = @"FastLighter.bas"
   var shared file_path = @"\FreeBASIC\"
#else ' linux or mac
   var shared fbc_name = @"fbc"
   var shared fbc_path = @"/usr/local/bin/"
   var shared defaultpath = @"/usr/local/bin/"
   var shared file_name = @"FastLighter.bas"
   var shared file_path = @"/home/fujitsu/Projekte/"
#endif

#include once "fltk-c.bi"

type toptions
  as short activ = 0
  as string opt, para, desc, value
end type

'var options = Fl_WindowNew(860,640,"Fbc options")
dim shared as Fl_Window ptr options
options = Fl_WindowNew(860,640,"Fbc options")
dim shared as toptions fbc_opt(60)
dim shared i as short
dim shared as string cmd_line
'cmd_line = fbc_name

for i = 0 to 60
  with fbc_opt(i)
    read (.opt)
    read (.para)
    read (.desc)
  end with
next i

data "","<file>","Read more command line arguments from a file", _
" -a","<file>","Treat file as .o/.a input file", _
" -arch","arch","Set target architecture (default: 486)", _
" -asm","att|intel","Set asm format (-gen gcc|llvm, x86 or x86_64 only)", _
" -b","<file>","Treat file as .bas input file", _
" -c","","Compile only, do not link", _
" -C","","Preserve temporary .o files", _
" -d","<name>[=<val>]","Add a global #define", _
" -dll","","Same as -dylib", _
" -dylib","","Create a DLL (win32) or shared library (*nix/*BSD)", _
" -e","","Enable runtime error checking", _
" -ex","","-e plus RESUME support", _
" -exx","","-ex plus array bounds/null-pointer checking", _
" -export","","Export symbols for dynamic linkage", _
" -forcelang","force","Override #lang statements in source code", _
" -fpmode","fast|precise","Select floating-point math accuracy/speed", _
" -fpu","x87|sse","Set target FPU", _
" -g","","Add debug info", _
" -gen","gas|gcc|llvm","Select code generation backend", _
"[-]-help","","Show this help output", _
" -i","<path>","Add an include file search path", _
" -include","<file>","Pre-#include a file for each input .bas", _
" -l","link","Link in a library", _
" -lang","lang","Select FB dialect: fb, deprecated, fblite, qb", _
" -lib","","Create a static library", _
" -m","module","Specify main module (default if not -c: first input .bas)", _
" -map","<file>","Save linking map to file", _
" -maxerr","maxerr","Only show <n> errors", _
" -mt","","Use thread-safe FB runtime", _
" -nodeflibs","","Do not include the default libraries", _
" -noerrline","","Do not show source context in error messages", _
" -noobjinfo","","Do not read/write compile-time info from/to .o and .a files", _
" -o","<file>","Set .o (or -pp .bas) file name for prev/next input file", _
" -O","optimize","Optimization level (default: 0)", _
" -p","<path>","Add a library search path", _
" -pic","","Generate position-independent code (non-x86 Unix shared libs)", _
" -pp","","Write out preprocessed input file (.pp.bas) only", _
" -prefix","<path>","Set the compiler prefix path", _
" -print","host|target","Display host/target system name", _
" -print","fblibdir","Display the compiler's lib/ path", _
" -print","x","Display output binary/library file name (if known)", _
" -profile","","Enable function profiling", _
" -r","","Write out .asm/.c/.ll (-gen gas/gcc/llvm) only", _
" -rr","","Write out the final .asm only", _
" -R","","Preserve temporary .asm/.c/.ll/.def files", _
" -RR","","Preserve the final .asm file", _
" -s","console|gui","Select win32 subsystem", _
" -showincludes","","Display a tree of file names of #included files", _
" -static","","Prefer static libraries over dynamic ones when linking", _
" -t","stack","Set .exe stack size in kbytes, default: 1024 (win32/dos)", _
" -target","target","Set cross-compilation target", _
" -title","title","Set XBE display title (xbox)", _
" -v","","Be verbose", _
" -vec","vector","Automatic vectorization level (default: 0)", _
"[-]-version","","Show compiler version   ", _
" -w","all|pedantic|<n>","Set min warning level: all, pedantic or a value", _
" -Wa","wa","Pass options to 'as'", _
" -Wc","wc","Pass options to 'gcc' (-gen gcc) or 'llc' (-gen llvm)", _
" -Wl","wl","Pass options to 'ld'", _
" -x","<file>","Set output executable/library file name", _
" -z","setjmp","Use setjmp/longjmp to implement GOSUB"

sub CheckCB cdecl (byval self as FL_WIDGET ptr,byval CheckButton as any ptr)
  var opt = *Fl_WidgetGetLabel(CheckButton)
  for i as short = 0 to 60
   if fbc_opt(i).opt = opt then
     if fbc_opt(i).activ = 0 then
       fbc_opt(i).activ = 1
     else
       fbc_opt(i).activ = 0
     end if
     print *Fl_WidgetGetLabel(CheckButton)
      print str(fbc_opt(i).activ)
     exit for
   end if
  next i
end sub

' choice callbacks
sub ArchChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(2).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(2).value
end sub

sub AsmChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(3).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(3).value
end sub

sub FastChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(15).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(15).value
end sub

sub FpuChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(16).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(16).value
end sub

sub GenChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(18).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(18).value
end sub

sub LangChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(23).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(23).value
end sub

sub PrintChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(38).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(38).value
end sub

sub GuiChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(46).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(46).value
end sub

sub WarnChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(55).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(55).value
end sub

sub SetChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(60).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(60).value
end sub

sub TargetChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(50).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(50).value
end sub

' string input callbacks
sub ForceInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(14).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(14).value
end sub

sub LinkInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(22).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(22).value
end sub

sub ModuleInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(25).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(25).value
end sub

sub TitleInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(51).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(51).value
end sub

sub WaInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(56).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(56).value
end sub

sub WcInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(57).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(57).value
end sub

sub WlInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(58).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(58).value
end sub


' integer input callbacks
sub MaxInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(27).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(27).value
end sub

sub OptInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(33).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(33).value
end sub

sub StackInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(49).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(49).value
end sub

sub VecInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(53).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(53).value
end sub

' button callbacks
sub CancelButtonCB cdecl (byval button as FL_WIDGET ptr)
  Fl_WindowHide(options)
end sub

sub OKButtonCB cdecl (byval button as FL_WIDGET ptr)
  dim as string opt_line
  for i = 0 to 60
  with fbc_opt(i)
    if .activ = 1 then
      opt_line = " " & .opt & " " & .value     
      cmd_line = cmd_line & opt_line
    end if
  end with
  next i
  ? cmd_line & " " & *file_name
    Fl_WindowHide(options)
end sub

var cancelbtn = Fl_ButtonNew(Fl_WidgetGetW(options)-180,Fl_WidgetGetH(options)-40,70,24,"Cancel")
var okbtn = Fl_ButtonNew(Fl_WidgetGetW(options)-90,Fl_WidgetGetH(options)-40,70,24,"OK")
Fl_WidgetSetCallback0 cancelbtn,@CancelButtonCB
Fl_WidgetSetCallback0 okbtn,@OKButtonCB

var scr = Fl_ScrollNew(20,20,Fl_WidgetGetW(options)-40,Fl_WidgetGetH(options)-80)

' get the V Scrollbar
var v = Fl_ScrollScrollbar(scr)
 Fl_WidgetSetAlign v,Fl_ALIGN_BOTTOM_RIGHT ' <-- default
                       
dim as Fl_Check_Button ptr cb(60)
dim as Fl_Button ptr btn(60)

' create the lines
for i as short = 0 to 60
  with fbc_opt(i)
   cb(i) = Fl_Check_ButtonNew(20,i*20+20,20,10, .opt)
   Fl_WidgetSetCallbackArg cb(i),@CheckCB,cb(i)
   
   var fl_boxn = Fl_BoxNew(340,i*20+20,450,20, .desc)
   Fl_WidgetSetAlign *fl_boxn,Fl_ALIGN_LEFT or Fl_ALIGN_INSIDE
   
   select case .para
   
     case ""
       exit select
       
     case "<file>"
       btn(i) = Fl_ButtonNew(160,i*20+20,140,20,.para)
   
     case "<path>"
       btn(i) = Fl_ButtonNew(160,i*20+20,140,20,.para)
   
     ' choice widgets
     case "arch"
       var arch = Fl_ChoiceNew(160,i*20+20,140,20,"")
      Fl_Menu_Add3(arch,"native")
      Fl_Menu_Add3(arch,"32")
       Fl_Menu_Add3(arch,"64")
      Fl_Menu_Add3(arch,"386")
      Fl_Menu_Add3(arch,"486")
      Fl_Menu_Add3(arch,"586")
      Fl_Menu_Add3(arch,"686")
      Fl_Menu_Add3(arch,"athlon")
      Fl_Menu_Add3(arch,"athlon-xp")
      Fl_Menu_Add3(arch,"athlon-fx")
      Fl_Menu_Add3(arch,"k8-")
      Fl_Menu_Add3(arch,"pentium-mmx")
      Fl_Menu_Add3(arch,"pentium2")
      Fl_Menu_Add3(arch,"pentium3")
      Fl_Menu_Add3(arch,"pentium4")
      Fl_Menu_Add3(arch,"pentium4-sse3")
      Fl_Menu_Add3(arch,"x86_64")
      Fl_Menu_Add3(arch,"x86-64")
      Fl_Menu_Add3(arch,"amd64")
      Fl_Menu_Add3(arch,"armv6")
      Fl_Menu_Add3(arch,"armv7-a")
      Fl_Menu_Add3(arch,"aarch64")
      Fl_ChoiceSetValue(arch,0)
      .value = "native"
      Fl_WidgetSetCallbackArg arch,@ArchChoiceCB,arch
      
    case "lang"
       var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
       Fl_Menu_Add3(cho,"fb")
      Fl_Menu_Add3(cho,"deprecated")
      Fl_Menu_Add3(cho,"fblite")
      Fl_Menu_Add3(cho,"qb")
      Fl_ChoiceSetValue(cho,0)
      .value = "fb"
      Fl_WidgetSetCallbackArg cho,@LangChoiceCB,cho

     case "att|intel"
       var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
      Fl_Menu_Add3(cho,"intel")
       Fl_Menu_Add3(cho,"att")
      Fl_ChoiceSetValue(cho,0)
      .value = "intel"
      Fl_WidgetSetCallbackArg cho,@AsmChoiceCB,cho
      
    case "fast|precise"
      var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
      Fl_Menu_Add3(cho,"fast")
      Fl_Menu_Add3(cho,"precise")
      Fl_ChoiceSetValue(cho,0)
      .value = "fast"
      Fl_WidgetSetCallbackArg cho,@FastChoiceCB,cho
   
    case "x87|sse"
      var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
      Fl_Menu_Add3(cho,"sse")
       Fl_Menu_Add3(cho,"x87")
      Fl_ChoiceSetValue(cho,0)
      .value = "sse"
      Fl_WidgetSetCallbackArg cho,@FpuChoiceCB,cho

     case "gas|gcc|llvm"
       var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
       Fl_Menu_Add3(cho,"gas")
      Fl_Menu_Add3(cho,"gcc")
      Fl_Menu_Add3(cho,"llmv")
      Fl_ChoiceSetValue(cho,1)
      .value = "gcc"
      Fl_WidgetSetCallbackArg cho,@GenChoiceCB,cho
     
     case "host|target"
       var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
       Fl_Menu_Add3(cho,"host")
      Fl_Menu_Add3(cho,"target")
      Fl_ChoiceSetValue(cho,1)
      .value = "target"
      Fl_WidgetSetCallbackArg cho,@PrintChoiceCB,cho
     
     case "console|gui"
       var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
       Fl_Menu_Add3(cho,"console")
      Fl_Menu_Add3(cho,"gui")
      Fl_ChoiceSetValue(cho,1)
      .value = "gui"
      Fl_WidgetSetCallbackArg cho,@GuiChoiceCB,cho
     
    case "all|pedantic|<n>"
      var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
       Fl_Menu_Add3(cho,"all")
       Fl_Menu_Add3(cho,"none")
      Fl_Menu_Add3(cho,"pedantic")
      Fl_Menu_Add3(cho,"param")
      Fl_Menu_Add3(cho,"Escape")
      Fl_Menu_Add3(cho,"Next")
      Fl_Menu_Add3(cho,"funcptr")
      Fl_Menu_Add3(cho,"constness")
      ' Fl_Menu_Add3(cho,"W0")
      Fl_ChoiceSetValue(cho,1)
      .value = "none"
      Fl_WidgetSetCallbackArg cho,@WarnChoiceCB,cho
      
    case "setjmp"
      var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
      Fl_Menu_Add3(cho,"setjmp")
      Fl_Menu_Add3(cho,"gosub")
      Fl_ChoiceSetValue(cho,0)
      .value = "setjmp"
      Fl_WidgetSetCallbackArg cho,@SetChoiceCB,cho
      
    case "target"
      var cho = Fl_ChoiceNew(160,i*20+20,140,20,"")
      Fl_Menu_Add3(cho,"dos")
      Fl_Menu_Add3(cho,"win32")
      Fl_Menu_Add3(cho,"win64")
      Fl_Menu_Add3(cho,"xbox")
      '<os>-<arch>
      '<os> can be one of:     
      Fl_Menu_Add3(cho,"linux-x86")
      Fl_Menu_Add3(cho,"linux-x86_64")
      Fl_Menu_Add3(cho,"linux-arm")
      Fl_Menu_Add3(cho,"linux-aarch64")
      Fl_Menu_Add3(cho,"cygwin-x86")
      Fl_Menu_Add3(cho,"cygwin-x86_64")
      Fl_Menu_Add3(cho,"cygwin-arm")
      Fl_Menu_Add3(cho,"cygwin-aarch64")      
      Fl_Menu_Add3(cho,"darwin-x86")
      Fl_Menu_Add3(cho,"darwin-x86_64")
      Fl_Menu_Add3(cho,"darwin-arm")
      Fl_Menu_Add3(cho,"darwin-aarch64")
      Fl_Menu_Add3(cho,"freebsd-x86")
      Fl_Menu_Add3(cho,"freebsd-x86_64")
      Fl_Menu_Add3(cho,"freebsd-arm")
      Fl_Menu_Add3(cho,"freebsd-aarch64")
      Fl_Menu_Add3(cho,"netbsd-x86")
      Fl_Menu_Add3(cho,"netbsd-x86_64")
      Fl_Menu_Add3(cho,"netbsd-arm")
      Fl_Menu_Add3(cho,"netbsd-aarch64")
      Fl_Menu_Add3(cho,"openbsd-x86")
      Fl_Menu_Add3(cho,"openbsd-x86_64")
      Fl_Menu_Add3(cho,"openbsd-arm")
      Fl_Menu_Add3(cho,"openbsd-aarch64")
      Fl_ChoiceSetValue(cho,4)
       .value = "linux-x86_64"
       Fl_WidgetSetCallbackArg cho,@TargetChoiceCB,cho
      
    ' string input widgets
     case "force"
       var inp1 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp1, "")
       .value = ""
       Fl_WidgetSetCallbackArg inp1,@ForceInputCB,inp1
       
     case "link"
       var inp1 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp1, "")
        .value = ""
       Fl_WidgetSetCallbackArg inp1,@LinkInputCB,inp1
       
     case "module"
        var inp1 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp1, "")
        .value = ""
       Fl_WidgetSetCallbackArg inp1,@ModuleInputCB,inp1
         
     case "title"
       var inp1 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp1, "")
       .value = ""
       Fl_WidgetSetCallbackArg inp1,@TitleInputCB,inp1
       
     case "wa"
       var inp1 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp1, "")
       .value = ""
       Fl_WidgetSetCallbackArg inp1,@WaInputCB,inp1
       
     case "wc"
       var inp1 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp1, "")
       .value = ""
       Fl_WidgetSetCallbackArg inp1,@WcInputCB,inp1
       
     case "wl"
       var inp1 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp1, "")
       .value = ""
       Fl_WidgetSetCallbackArg inp1,@WlInputCB,inp1
       
      
       ' int input widgets
     case "maxerr"
       var inp2 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp2, "0")
       .value = "0"
       Fl_WidgetSetCallbackArg inp2,@MaxInputCB,inp2
       
     case "optimize"
       var inp2 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp2, "0")
       .value = "0"
       Fl_WidgetSetCallbackArg inp2,@OptInputCB,inp2
       
     case "stack"
       var inp2 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp2, "1024")
       .value = "1024"
       Fl_WidgetSetCallbackArg inp2,@StackInputCB,inp2 
       
     case "vector"
       var inp2 = Fl_InputNew(160,i*20+20,140,20,"")
       Fl_Input_SetValue(inp2, "0")
       .value = "0"
       Fl_WidgetSetCallbackArg inp2,@VecInputCB,inp2 
   
     case else
      ' btn(i) = Fl_ButtonNew(160,i*20+20,140,20,.para)
   end select
    ? i & " Val: " & .value
  end with
 
next

Fl_ScrollScrollTo scr, 0,0
Fl_GroupSetResizable options,scr
Fl_WindowShow options
Fl_Run
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 23, 2019 1:03

Questions now would be if all entries in "Target"-choice are possible or which can be deleted. Other mistakes or improvements?
D.J.Peters
Posts: 8240
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Postby D.J.Peters » Jul 23, 2019 1:29

Can't test it ATM I'm not at home,
but don't hard code any path or name of FreeBASIC !

Let the user select it's path and fbc file and safe it in a Fl_Preferences file.

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

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 23, 2019 2:07

The button callbacks for file and path are not implemented now. But there are a lot of small corrections necessary here and there. Any help will be welcome.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 23, 2019 3:06

D.J.Peters wrote:Let the user select it's path and fbc file and safe it in a Fl_Preferences file.

This is planned, but the loading and to set the widgets to these values seems not to be so easy.

Code: Select all

' fbc_options.bas
' by Knatterton

#ifdef __FB_WIN32__ ' goes for all windows
   var shared fbc_name = @"fbc*.exe"
   var shared fbc_path = @"\FreeBASIC\"
   var shared defaultpath = @"\FreeBASIC\"
   var shared file_name = @"FastLighter.bas"
   var shared file_path = @"\FreeBASIC\"
#else ' linux or mac
   var shared fbc_name = @"fbc"
   var shared fbc_path = @"/usr/local/bin/"
   var shared defaultpath = @"/usr/local/bin/"
   var shared file_name = @"FastLighter.bas"
   var shared file_path = @"/home/fujitsu/Projekte/"
#endif

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

type toptions
  as string activ = "0", opt, para, desc, value, ind = "0"
end type

'var options = Fl_WindowNew(860,640,"Fbc options")
dim shared as Fl_Window ptr options
options = Fl_WindowNew(860,640,"Fbc options")
dim shared as toptions fbc_opt(60)
dim shared i as short
dim shared as string cmd_line


for i = 0 to 60
  with fbc_opt(i)
    read (.opt)
    read (.para)
    read (.desc)
    read (.value)
  end with
next i

data " @","<file>","Read more command line arguments from a file", "", _
" -a","<file>","Treat file as .o/.a input file", "", _
" -arch","arch","Set target architecture (default: 486)", "native", _
" -asm","att|intel","Set asm format (-gen gcc|llvm, x86 or x86_64 only)", "intel", _
" -b","<file>","Treat file as .bas input file", "", _
" -c","","Compile only, do not link", "", _
" -C","","Preserve temporary .o files", "", _
" -d","<name>[=<val>]","Add a global #define", "", _
" -dll","","Same as -dylib", "", _
" -dylib","","Create a DLL (win32) or shared library (*nix/*BSD)", "", _
" -e","","Enable runtime error checking", "", _
" -ex","","-e plus RESUME support", "", _
" -exx","","-ex plus array bounds/null-pointer checking", "", _
" -export","","Export symbols for dynamic linkage", "", _
" -forcelang","force","Override #lang statements in source code", "", _
" -fpmode","fast|precise","Select floating-point math accuracy/speed", "fast", _
" -fpu","x87|sse","Set target FPU", "sse", _
" -g","","Add debug info", "", _
" -gen","gas|gcc|llvm","Select code generation backend", "gcc", _
" -help","","Show this help output", "", _
" -i","<path>","Add an include file search path", "", _
" -include","<file>","Pre-#include a file for each input .bas", "", _
" -l","link","Link in a library", "", _
" -lang","lang","Select FB dialect: fb, deprecated, fblite, qb", "fb", _
" -lib","","Create a static library", "", _
" -m","module","Specify main module (default if not -c: first input .bas)", "", _
" -map","<file>","Save linking map to file", "", _
" -maxerr","maxerr","Only show <n> errors", "0", _
" -mt","","Use thread-safe FB runtime", "", _
" -nodeflibs","","Do not include the default libraries", "", _
" -noerrline","","Do not show source context in error messages", "", _
" -noobjinfo","","Do not read/write compile-time info from/to .o and .a files", "", _
" -o","<file>","Set .o (or -pp .bas) file name for prev/next input file", "", _
" -O","optimize","Optimization level (default: 0)", "0", _
" -p","<path>","Add a library search path", "", _
" -pic","","Generate position-independent code (non-x86 Unix shared libs)", "", _
" -pp","","Write out preprocessed input file (.pp.bas) only", "", _
" -prefix","<path>","Set the compiler prefix path", "", _
" -print","host|target","Display host/target system name", "target", _
" -print","fblibdir","Display the compiler's lib/ path", "", _
" -print","x","Display output binary/library file name (if known)", "", _
" -profile","","Enable function profiling", "", _
" -r","","Write out .asm/.c/.ll (-gen gas/gcc/llvm) only", "", _
" -rr","","Write out the final .asm only", "", _
" -R","","Preserve temporary .asm/.c/.ll/.def files", "", _
" -RR","","Preserve the final .asm file", "", _
" -s","console|gui","Select win32 subsystem", "gui", _
" -showincludes","","Display a tree of file names of #included files", "", _
" -static","","Prefer static libraries over dynamic ones when linking", "", _
" -t","stack","Set .exe stack size in kbytes, default: 1024 (win32/dos)", "1024", _
" -target","target","Set cross-compilation target", "dos", _
" -title","title","Set XBE display title (xbox)", "", _
" -v","","Be verbose", "", _
" -vec","vector","Automatic vectorization level (default: 0)", "0", _
" -version","","Show compiler version   ", "", _
" -w","all|pedantic|<n>","Set min warning level: all, pedantic or a value", "all", _
" -Wa","wa","Pass options to 'as'", "", _
" -Wc","wc","Pass options to 'gcc' (-gen gcc) or 'llc' (-gen llvm)", "", _
" -Wl","wl","Pass options to 'ld'", "", _
" -x","<file>","Set output executable/library file name", "", _
" -z","setjmp","Use setjmp/longjmp to implement GOSUB", "gosub"

sub load_opts  ' open and read the file
   dim as integer filehandle
   filehandle = freefile
   open "fbc.opt" for input as #filehandle
   for i as short = 0 to 60
       line input #filehandle, fbc_opt(i).activ
       line input #filehandle, fbc_opt(i).value
       line input #filehandle, fbc_opt(i).ind
   next i   
   close #filehandle
end sub

If fileexists("fbc.opt") then load_opts

sub save_opts ' open and write the file
   dim as integer filehandle
   filehandle = freefile
   open "fbc.opt" for output as #filehandle
   for i as short = 0 to 60
      print #filehandle, fbc_opt(i).activ
      print #filehandle, fbc_opt(i).value
      print #filehandle, fbc_opt(i).ind
   next i
   close #filehandle
end sub

sub CheckCB cdecl (byval self as FL_WIDGET ptr,byval CheckButton as any ptr)
  var opt = *Fl_WidgetGetLabel(CheckButton)
  for i as short = 0 to 60
   if fbc_opt(i).opt = opt then
     if fbc_opt(i).activ = "0" then
       fbc_opt(i).activ = "1"
     else
       fbc_opt(i).activ = "0"
     end if
     print *Fl_WidgetGetLabel(CheckButton)
      print fbc_opt(i).activ
     exit for
   end if
  next i
end sub

' choice callbacks
sub ArchChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(2).ind = str(ind)
  fbc_opt(2).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(2).value
end sub

sub AsmChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(3).ind = str(ind)
  fbc_opt(3).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(3).value
end sub

sub FastChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(15).ind = str(ind)
  fbc_opt(15).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(15).value
end sub

sub FpuChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(16).ind = str(ind)
  fbc_opt(16).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(16).value
end sub

sub GenChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(18).ind = str(ind)
  fbc_opt(18).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(18).value
end sub

sub LangChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(23).ind = str(ind)
  fbc_opt(23).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(23).value
end sub

sub PrintChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(38).ind = str(ind)
  fbc_opt(38).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(38).value
end sub

sub GuiChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(46).ind = str(ind)
  fbc_opt(46).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(46).value
end sub

sub WarnChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(55).ind = str(ind)
  fbc_opt(55).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(55).value
end sub

sub SetChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(60).ind = str(ind)
  fbc_opt(60).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(60).value
end sub

sub TargetChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  var ind = Fl_ChoiceGetValue(cho)
  fbc_opt(50).ind = str(ind)
  fbc_opt(50).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? fbc_opt(50).value
end sub

' string input callbacks
sub ForceInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(14).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(14).value
end sub

sub LinkInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(22).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(22).value
end sub

sub ModuleInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(25).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(25).value
end sub

sub TitleInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(51).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(51).value
end sub

sub WaInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(56).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(56).value
end sub

sub WcInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(57).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(57).value
end sub

sub WlInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(58).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(58).value
end sub


' integer input callbacks
sub MaxInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(27).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(27).value
end sub

sub OptInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(33).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(33).value
end sub

sub StackInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(49).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(49).value
end sub

sub VecInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
 fbc_opt(53).value = *Fl_Input_GetValue(input_)
 ? fbc_opt(53).value
end sub

' button callbacks
sub CancelButtonCB cdecl (byval button as FL_WIDGET ptr)
  Fl_WindowHide(options)
end sub

sub OKButtonCB cdecl (byval button as FL_WIDGET ptr)
  cmd_line = ""
  for i as short = 0 to 60
  with fbc_opt(i)
    if .activ = "1" then   
      cmd_line += .opt
      if .value <> "" then
        cmd_line += " " & .value
      end if 
    end if
  end with
  next i
  ? cmd_line & " " & *file_name
    Fl_WindowHide(options)
  save_opts
end sub

var cancelbtn = Fl_ButtonNew(Fl_WidgetGetW(options)-180,Fl_WidgetGetH(options)-40,70,24,"Cancel")
var okbtn = Fl_ButtonNew(Fl_WidgetGetW(options)-90,Fl_WidgetGetH(options)-40,70,24,"OK")
Fl_WidgetSetCallback0 cancelbtn,@CancelButtonCB
Fl_WidgetSetCallback0 okbtn,@OKButtonCB

var scr = Fl_ScrollNew(20,20,Fl_WidgetGetW(options)-40,Fl_WidgetGetH(options)-80)

' get the V Scrollbar
var v = Fl_ScrollScrollbar(scr)
 Fl_WidgetSetAlign v,Fl_ALIGN_BOTTOM_RIGHT ' <-- default
                       
dim as Fl_Check_Button ptr cb(60)
dim as Fl_Button ptr btn(60)

' create the lines
for i as short = 0 to 60
  with fbc_opt(i)
   cb(i) = Fl_Check_ButtonNew(24,i*24+24,24,24, .opt)
   Fl_WidgetSetCallbackArg cb(i),@CheckCB,cb(i)
   Fl_ButtonSetValue(cb(i),valint(.activ))
   
   var fl_boxn = Fl_BoxNew(340,i*24+24,450,24, .desc)
   Fl_WidgetSetAlign *fl_boxn,Fl_ALIGN_LEFT or Fl_ALIGN_INSIDE
   
   select case .para
   
     case ""
       exit select
       
     case "<file>"
       btn(i) = Fl_ButtonNew(160,i*24+24,140,24,.para)
   
     case "<path>"
       btn(i) = Fl_ButtonNew(160,i*24+24,140,24,.para)
   
     ' choice widgets
     case "arch"
       var arch = Fl_ChoiceNew(160,i*24+24,140,24,"")
      Fl_Menu_Add3(arch,"native")
      Fl_Menu_Add3(arch,"32")
       Fl_Menu_Add3(arch,"64")
      Fl_Menu_Add3(arch,"386")
      Fl_Menu_Add3(arch,"486")
      Fl_Menu_Add3(arch,"586")
      Fl_Menu_Add3(arch,"686")
      Fl_Menu_Add3(arch,"athlon")
      Fl_Menu_Add3(arch,"athlon-xp")
      Fl_Menu_Add3(arch,"athlon-fx")
      Fl_Menu_Add3(arch,"k8-")
      Fl_Menu_Add3(arch,"pentium-mmx")
      Fl_Menu_Add3(arch,"pentium2")
      Fl_Menu_Add3(arch,"pentium3")
      Fl_Menu_Add3(arch,"pentium4")
      Fl_Menu_Add3(arch,"pentium4-sse3")
      Fl_Menu_Add3(arch,"x86_64")
      Fl_Menu_Add3(arch,"x86-64")
      Fl_Menu_Add3(arch,"amd64")
      Fl_Menu_Add3(arch,"armv6")
      Fl_Menu_Add3(arch,"armv7-a")
      Fl_Menu_Add3(arch,"aarch64")
      Fl_ChoiceSetValue(arch,valint(.ind))
      Fl_WidgetSetCallbackArg arch,@ArchChoiceCB,arch
      
    case "lang"
       var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
       Fl_Menu_Add3(cho,"fb")
      Fl_Menu_Add3(cho,"deprecated")
      Fl_Menu_Add3(cho,"fblite")
      Fl_Menu_Add3(cho,"qb")
      Fl_ChoiceSetValue(cho,valint(.ind))
      Fl_WidgetSetCallbackArg cho,@LangChoiceCB,cho

     case "att|intel"
       var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
      Fl_Menu_Add3(cho,"intel")
       Fl_Menu_Add3(cho,"att")
      Fl_ChoiceSetValue(cho,valint(.ind))
      Fl_WidgetSetCallbackArg cho,@AsmChoiceCB,cho
      
    case "fast|precise"
      var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
      Fl_Menu_Add3(cho,"fast")
      Fl_Menu_Add3(cho,"precise")
      Fl_ChoiceSetValue(cho,valint(.ind))
      Fl_WidgetSetCallbackArg cho,@FastChoiceCB,cho
   
    case "x87|sse"
      var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
      Fl_Menu_Add3(cho,"sse")
       Fl_Menu_Add3(cho,"x87")
      Fl_ChoiceSetValue(cho,valint(.ind))
      Fl_WidgetSetCallbackArg cho,@FpuChoiceCB,cho

     case "gas|gcc|llvm"
       var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
       Fl_Menu_Add3(cho,"gas")
      Fl_Menu_Add3(cho,"gcc")
      Fl_Menu_Add3(cho,"llmv")
      Fl_ChoiceSetValue(cho,valint(.ind))
      Fl_WidgetSetCallbackArg cho,@GenChoiceCB,cho
     
     case "host|target"
       var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
       Fl_Menu_Add3(cho,"host")
      Fl_Menu_Add3(cho,"target")
      Fl_ChoiceSetValue(cho,valint(.ind))
      Fl_WidgetSetCallbackArg cho,@PrintChoiceCB,cho
     
     case "console|gui"
       var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
       Fl_Menu_Add3(cho,"gui")
       Fl_Menu_Add3(cho,"console")
      Fl_ChoiceSetValue(cho,valint(.ind))
      Fl_WidgetSetCallbackArg cho,@GuiChoiceCB,cho
     
    case "all|pedantic|<n>"
      var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
       Fl_Menu_Add3(cho,"all")
       Fl_Menu_Add3(cho,"none")
      Fl_Menu_Add3(cho,"pedantic")
      Fl_Menu_Add3(cho,"param")
      Fl_Menu_Add3(cho,"Escape")
      Fl_Menu_Add3(cho,"Next")
      Fl_Menu_Add3(cho,"funcptr")
      Fl_Menu_Add3(cho,"constness")
      ' Fl_Menu_Add3(cho,"W0")
      Fl_ChoiceSetValue(cho,valint(.ind))
      Fl_WidgetSetCallbackArg cho,@WarnChoiceCB,cho
      
    case "setjmp"
      var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
      Fl_Menu_Add3(cho,"gosub")
            Fl_Menu_Add3(cho,"setjmp")
      Fl_ChoiceSetValue(cho,valint(.ind))
      Fl_WidgetSetCallbackArg cho,@SetChoiceCB,cho
      
    case "target"
      var cho = Fl_ChoiceNew(160,i*24+24,140,24,"")
      Fl_Menu_Add3(cho,"dos")
      Fl_Menu_Add3(cho,"win32")
      Fl_Menu_Add3(cho,"win64")
      Fl_Menu_Add3(cho,"xbox")
      '<os>-<arch>
      '<os> can be one of:     
      Fl_Menu_Add3(cho,"linux-x86")
      Fl_Menu_Add3(cho,"linux-x86_64")
      Fl_Menu_Add3(cho,"linux-arm")
      Fl_Menu_Add3(cho,"linux-aarch64")
      Fl_Menu_Add3(cho,"cygwin-x86")
      Fl_Menu_Add3(cho,"cygwin-x86_64")
      Fl_Menu_Add3(cho,"cygwin-arm")
      Fl_Menu_Add3(cho,"cygwin-aarch64")      
      Fl_Menu_Add3(cho,"darwin-x86")
      Fl_Menu_Add3(cho,"darwin-x86_64")
      Fl_Menu_Add3(cho,"darwin-arm")
      Fl_Menu_Add3(cho,"darwin-aarch64")
      Fl_Menu_Add3(cho,"freebsd-x86")
      Fl_Menu_Add3(cho,"freebsd-x86_64")
      Fl_Menu_Add3(cho,"freebsd-arm")
      Fl_Menu_Add3(cho,"freebsd-aarch64")
      Fl_Menu_Add3(cho,"netbsd-x86")
      Fl_Menu_Add3(cho,"netbsd-x86_64")
      Fl_Menu_Add3(cho,"netbsd-arm")
      Fl_Menu_Add3(cho,"netbsd-aarch64")
      Fl_Menu_Add3(cho,"openbsd-x86")
      Fl_Menu_Add3(cho,"openbsd-x86_64")
      Fl_Menu_Add3(cho,"openbsd-arm")
      Fl_Menu_Add3(cho,"openbsd-aarch64")
      Fl_ChoiceSetValue(cho,valint(.ind))
       Fl_WidgetSetCallbackArg cho,@TargetChoiceCB,cho
      
    ' string input widgets
     case "force"
       var inp1 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp1, .value)
       Fl_WidgetSetCallbackArg inp1,@ForceInputCB,inp1
       
     case "link"
       var inp1 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp1, .value)
       Fl_WidgetSetCallbackArg inp1,@LinkInputCB,inp1
       
     case "module"
        var inp1 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp1, .value)
       Fl_WidgetSetCallbackArg inp1,@ModuleInputCB,inp1
         
     case "title"
       var inp1 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp1, .value)
       Fl_WidgetSetCallbackArg inp1,@TitleInputCB,inp1
       
     case "wa"
       var inp1 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp1, .value)
       Fl_WidgetSetCallbackArg inp1,@WaInputCB,inp1
       
     case "wc"
       var inp1 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp1, .value)
       Fl_WidgetSetCallbackArg inp1,@WcInputCB,inp1
       
     case "wl"
       var inp1 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp1, .value)
       Fl_WidgetSetCallbackArg inp1,@WlInputCB,inp1
       
      
       ' int input widgets
     case "maxerr"
       var inp2 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp2, .value)
       Fl_WidgetSetCallbackArg inp2,@MaxInputCB,inp2
       
     case "optimize"
       var inp2 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp2, .value)
       Fl_WidgetSetCallbackArg inp2,@OptInputCB,inp2
       
     case "stack"
       var inp2 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp2, .value)
       Fl_WidgetSetCallbackArg inp2,@StackInputCB,inp2 
       
     case "vector"
       var inp2 = Fl_InputNew(160,i*24+24,140,24,"")
       Fl_Input_SetValue(inp2, .value)
       Fl_WidgetSetCallbackArg inp2,@VecInputCB,inp2 
   
     case else
      ' btn(i) = Fl_ButtonNew(160,i*24+24,140,24,.para)
   end select
    ? i & " Val: " & .value
  end with
 
next

Fl_ScrollScrollTo scr, 0,0
Fl_GroupSetResizable options,scr
Fl_WindowShow options
Fl_Run


Edit: Updated the code again, works now
Last edited by Knatterton on Jul 24, 2019 8:36, edited 3 times in total.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Postby bcohio2001 » Jul 23, 2019 19:42

So the answer to my question is … Events are handled as they come in.

Code: Select all

#Include "fltk-c.bi"

Sub D(s As String)
   Dim As Integer x = FreeFile
   Open "Test Handles.txt" For Append As #x
   Print #x, s
   Close #x
   Sleep 700 'just to give time to write and not mix up any other calls
End Sub

function HandleCB cdecl (byval self as any ptr,byval event as FL_EVENT) as Long
   select case as const event
      Case FL_EVENT_SHOW
         'do some checks
         D("FL_EVENT_SHOW")
         '
      Case FL_EVENT_CLOSE
         'do some end of program code ... close any files, etc....
         D("FL_EVENT_CLOSE")
         '
   End Select
   'D(*EventAsString(event))
   Dim As String E = *EventAsString(event)
   D(E)
   'let FLTK handle it
   return Fl_WindowExHandleBase(self,event)
End Function

var win = Fl_WindowExNew(320,200, "Fl_Window")
Fl_BoxNew 20,40,300,100,"Hello, World!"
D("Setting callback")
Fl_WindowExSetHandleCB win,@HandleCB
D("Fl_WindowShow")
Fl_WindowShow win '<- HandleCB now?
D("Fl_Run")
Fl_Run
D("Exiting prg....")

Setting callback
Fl_WindowShow
FL_EVENT_SHOW
FL_EVENT_SHOW (16)
FL_EVENT_FOCUS (6)
Fl_Run
FL_EVENT_MOVE (11)
FL_EVENT_LEAVE (4)
FL_EVENT_MOVE (11)
FL_EVENT_LEAVE (4)
FL_EVENT_HIDE (15)
Exiting prg....


I bring up my "Include Digger" program (Windows only) to look at the whole FLTK library.
I am trying to adapt it with FLTK to make it multi-platform.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 24, 2019 1:38

Updated the above code again, works now. Settings are saved and loaded again at next start. Then the widgets are set after this.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 24, 2019 8:39

Does anybody know if all these kombinations are possible?

Fl_Menu_Add3(cho,"linux-x86")
Fl_Menu_Add3(cho,"linux-x86_64")
Fl_Menu_Add3(cho,"linux-arm")
Fl_Menu_Add3(cho,"linux-aarch64")
Fl_Menu_Add3(cho,"cygwin-x86")
Fl_Menu_Add3(cho,"cygwin-x86_64")
Fl_Menu_Add3(cho,"cygwin-arm")
Fl_Menu_Add3(cho,"cygwin-aarch64")
Fl_Menu_Add3(cho,"darwin-x86")
Fl_Menu_Add3(cho,"darwin-x86_64")
Fl_Menu_Add3(cho,"darwin-arm")
Fl_Menu_Add3(cho,"darwin-aarch64")
Fl_Menu_Add3(cho,"freebsd-x86")
Fl_Menu_Add3(cho,"freebsd-x86_64")
Fl_Menu_Add3(cho,"freebsd-arm")
Fl_Menu_Add3(cho,"freebsd-aarch64")
Fl_Menu_Add3(cho,"netbsd-x86")
Fl_Menu_Add3(cho,"netbsd-x86_64")
Fl_Menu_Add3(cho,"netbsd-arm")
Fl_Menu_Add3(cho,"netbsd-aarch64")
Fl_Menu_Add3(cho,"openbsd-x86")
Fl_Menu_Add3(cho,"openbsd-x86_64")
Fl_Menu_Add3(cho,"openbsd-arm")
Fl_Menu_Add3(cho,"openbsd-aarch64")
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 24, 2019 17:56

bcohio2001 wrote:I bring up my "Include Digger" program (Windows only) to look at the whole FLTK library.
I am trying to adapt it with FLTK to make it multi-platform.

I think that is a good idea and you have a good understanding of Fltk.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Jul 26, 2019 12:00

Joshy, would this be what you mentioned before, not to hardcode pathes and filenames?

Code: Select all

' FLtk_fb_file_chooser.bas
' fb version of file-chooser
' centered with separated filepath, filename and path

#include once "fltk-c.bi"

dim shared as Fl_Window ptr Win
Win = Fl_WindowNew2(400,400,512, 380, "Fltk_fb_file_chooser")
dim as Fl_ButtonEx ptr OkBtn, FileBtn, CancelBtn

sub Fl_File_ChooserShowCenter(byval fc as FL_File_Chooser ptr)
  var win = cptr(FL_Double_Window ptr,Fl_WidgetWindow(Fl_File_ChooserNewButton(fc)))
  var scrW=Fl_GetW()          ' get screen width,height
  var scrH=Fl_GetH()
  var winW=Fl_WidgetGetW(win) ' get current win width,height
  var winH=Fl_WidgetGetH(win)
  var newX = scrW/2-winW/2    ' calculate new center position
  var newY = scrH/2-winH/2
  Fl_WidgetPosition(win,newX,newY)
  Fl_Double_WindowShow(win)
  Fl_File_ChooserRescanKeepFilename(fc)
end sub

' button callbacks
sub CancelButtonCB cdecl (byval button as FL_WIDGET ptr)
  Fl_WindowHide(Win)
end sub

sub OkButtonCB cdecl (byval button as FL_WIDGET ptr)
  Fl_WindowHide(Win)
end sub

sub FileButtonCB cdecl (byval self as Fl_Widget ptr,byval but as any ptr)
  flFileChooserOkLabel("Open")
  dim as string result = CurDir
  var fc = Fl_File_ChooserNew(result, "*", FL_FILECHOOSER_SINGLE, "Select a file")
  Fl_File_ChooserSetPreview(fc,0)
  Fl_File_ChooserShowCenter(fc)
  while Fl_File_ChooserShown(fc) andalso Fl_Wait()=1
  wend
 
  ' get file name out of filepath
  dim as string filepath = *Fl_File_ChooserGetValue(fc)
  dim as string file
  dim as string npath = *Fl_File_ChooserGetDirectory(fc)
  dim as long last
  #ifdef __FB_WIN32__ ' goes for all windows
    last = InStrRev(filepath, "\")
  #else ' linux or other
    last = InStrRev(filepath, "/")
  #endif
  file = Mid(filepath, last + 1, len(filepath))
  ?
  ? "pathfile: " & filepath
  ? "file: " & file
  ? "path: " & npath
  Fl_WindowCopyLabel but,file
end sub

FileBtn = Fl_ButtonExNew(20, 345, 285, 25, "Choose")
OkBtn = Fl_ButtonExNew(313, 345, 85, 25, "OK")
CancelBtn = Fl_ButtonExNew(408, 345, 72, 25, "Cancel")
Fl_WidgetSetCallback0 Cancelbtn,@CancelButtonCB
Fl_WidgetSetCallback0 OkBtn,@OkButtonCB
Fl_WidgetSetCallbackArg FileBtn,@FileButtonCB, FileBtn

Fl_WindowShow Win
Fl_Run


It is meant for reusebility of code like MrSwiss has written. So that each user can use file chooser without need to know how it works internally.
D.J.Peters
Posts: 8240
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Postby D.J.Peters » Jul 26, 2019 13:10

Yes it's better the user can select it's own FreeBASIC compiler !
For example in my windows D:\FreeBASIC folder are fbc32.exe and fbc64.exe !

Another user can have fbc.exe but in two folders:
C:\FreeBASIC-32\fbc.exe
C:\FreeBASIC-64\fbc.exe

or

32-bit in C:\Program Files (x86)\FreeBASIC\fbc.exe
64-bit in C:\Program Files\FreeBASIC\fbc.exe

You see the number of different combinations of path's and filenames are grows up.

That is why I wrote the user should select the right path and name of fbc :-)

Joshy

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 3 guests