FLTK-C-1.3.3 for FreeBASIC

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 7773
Joined: May 28, 2005 3:28

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby D.J.Peters » Jan 06, 2019 17:48

@oyster FLTK and fltk-c is all GPL but you don't have to remove the copyrights :-)

The Nim language can interface to C++ so why do you will use a FreeBASIC C binding and not FLTK C++ directly ?

How ever the simplest game ever the snake game compiled with Nim to JavaScript are 353,280 bytes (345 KB)

run the game:
https://picheta.me/snake/

view or save the created *.js file:
https://picheta.me/snake/snake.js

Joshy
oyster
Posts: 183
Joined: Oct 11, 2005 10:46

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby oyster » Jan 07, 2019 5:20

you scared me. So I checked https://www.fltk.org/COPYING.php and find FLTK uses LGPL, I understand that it is ok to use FLTK dynamic file(i.e. DLL on windows) even in commercial, close-source app. In fact, FLTK uses a modified LGPL, so if I use only official FLTK without modification, I can do static linking even in commercial, close-source app.

As for your fltk*.bi, if you choose GPL, it could be a disaster for me because any app uses GPLed library must open the source to the client.
oyster
Posts: 183
Joined: Oct 11, 2005 10:46

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby oyster » Jan 07, 2019 5:30

3 more things
1. how to do static link with FLTK in fb app?

2. does the spreadsheet/table in fltk*.bi support sorting by clicking the column header?

3. As for fltk for nim, https://github.com/Skrylar/nfltk is updated in July 2018, and there is only one test but you supplied so many!
oyster
Posts: 183
Joined: Oct 11, 2005 10:46

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby oyster » Jan 11, 2019 1:43

@D.J.Peters
I am still waiting for your declaration on the license of your fltk*.bi

If I use a lib who has GPL license, then GPL requires me to open all of my code

If I use a lib who has LGPL license, then I can closesource my code when I use the lib as DLL; but if I try to do static link, I have to open all my source. However since your fltk*.bi are all code, I think LGPL can't apply to it

English is not my native language, so correct me if there is something wrong
D.J.Peters
Posts: 7773
Joined: May 28, 2005 3:28

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby D.J.Peters » Jan 11, 2019 11:32

You can wait if you like but it is what it is :-)

http://www.fltk.org/COPYING.php

COPYING wrote:4. You do not have to provide a copy of the FLTK license with programs that are linked to the FLTK library, nor do you have to identify the FLTK license in your program or documentation as required by section 6 of the LGPL.

However, programs must still identify their use of FLTK. The following example statement can be included in user documentation to satisfy this requirement:

[program/widget] is based in part on the work of the FLTK project (http://www.fltk.org).


Joshy

Code: Select all

'  FreeBASIC header file for the Fast Light Tool Kit C wrapper.
'  FLTK C wrapper copyright 2013-2019 by D.J.Peters

'  C++ library Fast Light Tool Kit (FLTK)
'  Copyright 1998-2010 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
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby lizard » Jan 11, 2019 20:08

This seems the best GUI for FB at the moment. All works out of the box here on Linux Mint 18.3 64bit.
oyster
Posts: 183
Joined: Oct 11, 2005 10:46

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby oyster » Jan 14, 2019 13:00

should

Code: Select all

declare function Fl_ScreenY      alias "Fl_GetX" as long

be

Code: Select all

declare function Fl_ScreenY      alias "Fl_GetY" as long

in fltk-main.bi ?
oyster
Posts: 183
Joined: Oct 11, 2005 10:46

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby oyster » Jan 16, 2019 1:12

Regards from nimlang

Code: Select all

import fltk_main

proc ButtonClick (button: ptr FL_WIDGET, arg: pointer):cint {.cdecl.} =
  Fl_WidgetCopyLabel(button, "do it again")

var Win = Fl_WindowNew(320, 200, "What a shiny Window :-)")
var Btn = Fl_ButtonNew(10, 10, 120, 32, "click me")
Fl_WidgetSetCallback(Btn, ButtonClick)
Fl_WindowShow(Win)
Fl_Run()
oyster
Posts: 183
Joined: Oct 11, 2005 10:46

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby oyster » Jan 25, 2019 6:08

in Fl_Overlay_WindowEx.bas

Code: Select all

Fl_WidgetSetCallbackArg Fl_ButtonNew( 50, 50,100,100,"wider")   ,@Button1CB,win
Fl_WidgetSetCallbackArg Fl_ButtonNew(250, 50,100,100,"narrower"),@Button2CB,win
Fl_WidgetSetCallbackArg Fl_ButtonNew( 50,250,100,100,"taller")  ,@Button3CB,win
Fl_WidgetSetCallbackArg Fl_ButtonNew(250,250,100,100,"shorter") ,@Button4CB,win


should be

Code: Select all

Fl_WidgetSetCallbackArg Fl_ButtonNew( 50, 50,100,100,"wider")   ,@Button3CB,win
Fl_WidgetSetCallbackArg Fl_ButtonNew(250, 50,100,100,"narrower"),@Button4CB,win
Fl_WidgetSetCallbackArg Fl_ButtonNew( 50,250,100,100,"taller")  ,@Button1CB,win
Fl_WidgetSetCallbackArg Fl_ButtonNew(250,250,100,100,"shorter") ,@Button2CB,win
dkr
Posts: 34
Joined: Nov 20, 2015 15:17
Location: Alabama, USA

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby dkr » Mar 07, 2019 22:03

Hello,
Another question on using the FLTK library. I am trying to use the Fl_Menu_NewBar widget.
It will look something like the image in the link below.

https://imgur.com/9NA8YKh

Clicking on the menu items brings up another widget window from the callback
subroutines.

However if I go back to the above menu window, and click on the
same menu item it generates another instance of the same widget
window. How can I prevent another instance of the widget window
from starting? Do I use Fl_WidgetDeactivate in the subroutine that
starts the new widget window? Is there a way to deactivate just
that particular menu item?

There is this: declare sub Fl_Menu_ItemDeactivate(byval it as Fl_Menu_Item ptr);
but I don't know how to get that particular pointer or how to use it at all.

I have started with Joshy's example code below. Is it possible or reasonable to deactivate
any or all the main menu bar items from within the callback subroutines ("NewFile(),...) or
is there a better, more logical approach?

Thanks,
Darren

Code: Select all

SUB CreateWindow_Main ()
'Window with menu

    Window_Main = Fl_WindowNew (300, 200, "Test menu")
    Menu = Fl_Menu_BarNew (0, 0, 300, 20)
    Fl_Menu_Add (Menu, "File/New" ,,  @NewFile())
    Fl_Menu_Add (Menu, "File/Open" ,, @OpenFile())
    Fl_Menu_Add (Menu, "File/Save" ,, @SaveFile())
    Fl_Menu_Add (Menu, "File/End" ,,  @EndProgram())
    Fl_Menu_Add (Menu, "Help/Info" ,, @Info())

END SUB
badidea
Posts: 1416
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby badidea » Mar 07, 2019 23:09

It has been a while since I did any real code with FLTK, but I would try the following:
* Create the window (e.g. openFileWindow), before Fl_Run
* Call Fl_WindowShow(openFileWindow) on menu selection

Else, can you post some minimal code that compiles, then I can try some things.
dkr
Posts: 34
Joined: Nov 20, 2015 15:17
Location: Alabama, USA

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby dkr » Mar 08, 2019 14:43

Hello,
Here is most of the code. It is just a beginning. I need to determine if the Test_Menu window can be deactivated, otherwise I might have to re-think how to get the inputs into the program. The basic idea of the program is an easy gui to enter the general information and individual channel configurations. Then the code will eventually dump all this information into a csv file. That csv file is used with another program to actually make the hardware calls to start the data acquisition system and save the data to file.

Thanks,
Darren

Code: Select all

#INCLUDE once "fltk-c.bi"

#define Fl_RadioGroup      Fl_Group
#define Fl_RadioGroupNew   Fl_GroupNew
#define Fl_RadioGroupBegin Fl_GroupBegin
#define Fl_RadioGroupEnd   Fl_GroupEnd

const Nchn = 16
dim SHARED as Fl_RadioGroup ptr RadioGroups(Nchn-1),RadioAll
DIM SHARED AS Fl_Radio_Round_Button PTR dc(1 to 5,0 to Nchn-1),_
   ac(1 to 5,0 to Nchn-1),ac_all,dc_all

DIM SHARED AS Fl_Box PTR Box_text, All_text
DIM SHARED AS Fl_Button PTR BC1,BC2,BC3,BC4,BC5
DIM SHARED AS Fl_Choice PTR chc(1 to 5,0 to 15),lvl_all(1 to 5)
DIM SHARED as String dc_lab,ac_lab,chn,c_tab,t_c1,t_c2,t_c3,t_c4,t_c5,all
DIM SHARED AS Integer tab_num,i,card

t_c1 = "Input Coupling"
t_c2 = "Input Levels"
t_c3 = "AC"
t_c4 = "DC"
t_c5 = "( ± volts )"
all  = "all"
'Declaration of the callback functions - see below:
DECLARE SUB NewFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB OpenFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB SaveFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB EndProgram CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB Info CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB Button_Click_Event CDECL (widget AS FL_Widget PTR, arg AS ANY PTR)
DECLARE sub TabCB cdecl (byval tabs as FL_WIDGET ptr,byval parent as any ptr)
DECLARE sub SetAllAC CDECL (BYVAL self as FL_WIDGET PTR, byval btn as any ptr)
DECLARE sub SetAllDC CDECL (BYVAL self as FL_WIDGET PTR, byval btn as any ptr)
DECLARE sub SetAllLvl CDECL (BYVAL self as FL_WIDGET PTR, BYVAL btn as any PTR)



DIM SHARED AS Fl_Window PTR Window_Main
DIM SHARED AS Fl_Menu_Bar PTR Menu


SUB CreateWindow_Main ()
'Window with menu

    Window_Main = Fl_WindowNew (300, 200, "Test menu")
    Menu = Fl_Menu_BarNew (0, 0, 300, 20)
    Fl_Menu_Add (Menu, "File/New" ,,  @NewFile())
    Fl_Menu_Add (Menu, "File/Open" ,, @OpenFile())
    Fl_Menu_Add (Menu, "File/Save" ,, @SaveFile())
    Fl_Menu_Add (Menu, "File/End" ,,  @EndProgram())
    Fl_Menu_Add (Menu, "Help/Info" ,, @Info())

END SUB


'Callback functions:

SUB NewFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
 'Fl_Menu_ItemDeactivate(MENU)
 var win = Fl_WindowNew(500,660,"multi_card_input_v1.bas")
  var tabs = Fl_TabsNew(10,10,500-20,660-20)
  Fl_WidgetSetCallbackArg tabs,@TabCB,tabs
  '
  '  Card 1 - Tab 1
  '
  var tab1 = Fl_TabNew(10,35,500-20,660-45,"CARD 1 ")
  card = 1
  BC1 = Fl_ButtonNew (100, 50, 100, 20, "Submit")
' Putting titles in the tabs
  #macro tab_titles
  All_text = Fl_BoxNew(80,75,100,20,"")
  Fl_WidgetCopyLabel(All_text,"Input Coupling")    'Input Coupling
  All_text = Fl_BoxNew(250,75,100,20,"")
  Fl_WidgetCopyLabel(All_text,"Input Levels")      'Input Levels
  All_text = Fl_BoxNew(80,95,30,20,"")
  Fl_WidgetCopyLabel(All_text,"AC")                'AC
  All_text = Fl_BoxNew(170,95,30,20,"")
  Fl_WidgetCopyLabel(All_text,"DC")                'DC
  All_text = Fl_BoxNew(250,95,100,20,"")
  Fl_WidgetCopyLabel(All_text,"( ± volts )")       ' ( ± volts )
  #endmacro
  tab_titles
' make buttons & labels for setting "all" channels to AC or DC   
  RadioAll = Fl_RadioGroupNew(80,115,300,30)
     Fl_RadioGroupBegin(RadioAll)
       ac_all = Fl_Radio_Round_ButtonNew(80,115,50,20,all)
       Fl_WidgetCopyLabel(ac_all,all)
       Fl_WidgetSetCallbackArg ac_all,@SetAllAC,tab1
       dc_all = Fl_Radio_Round_ButtonNew(170,115,50,20,all)
       Fl_WidgetCopyLabel(dc_all,all)
       Fl_WidgetSetCallbackArg dc_all,@SetAllDC,tab1
     Fl_RadioGroupEnd(RadioAll)
' make choice box for "all" input levels
   lvl_all(card) = Fl_ChoiceNew(250,115,128,20,all)
   Fl_Menu_Add3 lvl_all(card),"Input Level/10.0|Input Level/3.16|Input Level/1.00|Input Level/0.316"
   Fl_ChoiceSetValue lvl_all(card),3
   Fl_WidgetSetCallbackArg lvl_all(card),@SetAllLvl,tab1
' make buttons and labels for all card channels
#macro button_lvls
   for i = 0 to Nchn-1
      dc_lab = "dc"+str(i+1)
      ac_lab = "ac"+STR(i+1)
      chn = "Ch."+STR(i+1)
      Box_text = Fl_BoxNew(10,140+i*30,50,20,"")
      Fl_WidgetCopyLabel(Box_text,chn)
      RadioGroups(i) = Fl_RadioGroupNew(80,140+i*30,300,30)
      Fl_RadioGroupBegin(RadioGroups(i))
         ac(card,i) = Fl_Radio_Round_ButtonNew(80,140+i*30,50,20,ac_lab)
         Fl_WidgetCopyLabel(ac(card,i),ac_lab)
         dc(card,i) = Fl_Radio_Round_ButtonNew(170,140+i*30,50,20,dc_lab)
         Fl_WidgetCopyLabel(dc(card,i),dc_lab)
      Fl_RadioGroupEnd(RadioGroups(i))
' make choice box for each channel input level range     
      chc(card,i) = Fl_ChoiceNew(250,140+i*30,128,20)   
      Fl_Menu_Add3 chc(card,i),"Input Level/10.0|Input Level/3.16|Input Level/1.00|Input Level/0.316"
      Fl_ChoiceSetValue chc(card,i),3
      Fl_ButtonSetOnly(ac(card,i))
   next
#endmacro
   button_lvls  'run macro
  Fl_TabEnd tab1
'
' Card 2 - Tab 2
'
  var tab2 = Fl_TabNew(10,35,500-20,660-45,"CARD 2 ")
  card = 2
  BC2 = Fl_ButtonNew (100, 50, 100, 20, "Submit")
' Putting titles in the tabs   
  tab_titles
' make buttons & labels for setting all channels to AC or DC   
  RadioAll = Fl_RadioGroupNew(80,115,300,30)
     Fl_RadioGroupBegin(RadioAll)
       ac_all = Fl_Radio_Round_ButtonNew(80,115,50,20,all)
       Fl_WidgetCopyLabel(ac_all,all)
       Fl_WidgetSetCallbackArg ac_all,@SetAllAC,tab2
       dc_all = Fl_Radio_Round_ButtonNew(170,115,50,20,all)
       Fl_WidgetCopyLabel(dc_all,all)
       Fl_WidgetSetCallbackArg dc_all,@SetAllDC,tab2
     Fl_RadioGroupEnd(RadioAll)
' make choice box for input levels
   lvl_all(card) = Fl_ChoiceNew(250,115,128,20,all)
   Fl_Menu_Add3 lvl_all(card),"Input Level/10.0|Input Level/3.16|Input Level/1.00|Input Level/0.316"
   Fl_ChoiceSetValue lvl_all(card),3
   Fl_WidgetSetCallbackArg lvl_all(card),@SetAllLvl,tab2
' make buttons and labels for all card channels
   button_lvls  'run macro
  Fl_TabEnd tab2
  '
' Card 3 - tab 3
'
  var tab3 = Fl_TabNew(10,35,500-20,660-45,"CARD 3 ")
  card = 3
  BC3 = Fl_ButtonNew (100, 50, 100, 20, "Submit")
' Putting titles in the tabs   
  tab_titles 'using macro
' make buttons & labels for setting all channels to AC or DC   
  RadioAll = Fl_RadioGroupNew(80,115,300,30)
     Fl_RadioGroupBegin(RadioAll)
       ac_all = Fl_Radio_Round_ButtonNew(80,115,50,20,all)
       Fl_WidgetCopyLabel(ac_all,all)
       Fl_WidgetSetCallbackArg ac_all,@SetAllAC,tab3
       dc_all = Fl_Radio_Round_ButtonNew(170,115,50,20,all)
       Fl_WidgetCopyLabel(dc_all,all)
       Fl_WidgetSetCallbackArg dc_all,@SetAllDC,tab3
     Fl_RadioGroupEnd(RadioAll)
' make choice box for input levels
   lvl_all(card) = Fl_ChoiceNew(250,115,128,20,all)
   Fl_Menu_Add3 lvl_all(card),"Input Level/10.0|Input Level/3.16|Input Level/1.00|Input Level/0.316"
   Fl_ChoiceSetValue lvl_all(card),3
   Fl_WidgetSetCallbackArg lvl_all(card),@SetAllLvl,tab3
' make buttons and labels for all card channels
   button_lvls  'run macro       
   Fl_TabEnd tab3
 
  '
' Card 4 - tab 4
'
  var tab4 = Fl_TabNew(10,35,500-20,660-45,"CARD 4 ")
  card = 4
  BC4 = Fl_ButtonNew (100, 50, 100, 20, "Submit")
' Putting titles in the tabs   
  tab_titles  'using macro
' make buttons & labels for setting all channels to AC or DC   
  RadioAll = Fl_RadioGroupNew(80,115,300,30)
     Fl_RadioGroupBegin(RadioAll)
       ac_all = Fl_Radio_Round_ButtonNew(80,115,50,20,all)
       Fl_WidgetCopyLabel(ac_all,all)
       Fl_WidgetSetCallbackArg ac_all,@SetAllAC,tab4
       dc_all = Fl_Radio_Round_ButtonNew(170,115,50,20,all)
       Fl_WidgetCopyLabel(dc_all,all)
       Fl_WidgetSetCallbackArg dc_all,@SetAllDC,tab4
     Fl_RadioGroupEnd(RadioAll)
' make choice box for input levels
   lvl_all(card) = Fl_ChoiceNew(250,115,128,20,all)
   Fl_Menu_Add3 lvl_all(card),"Input Level/10.0|Input Level/3.16|Input Level/1.00|Input Level/0.316"
   Fl_ChoiceSetValue lvl_all(card),3
   Fl_WidgetSetCallbackArg lvl_all(card),@SetAllLvl,tab4
' make buttons and labels for all card channels
   button_lvls  'run macro     
  Fl_TabEnd tab4
  '
' Card 5 - tab 5
'
  var tab5 = Fl_TabNew(10,35,500-20,660-45,"CARD 5 ")
  card = 5
  BC5 = Fl_ButtonNew (100, 50, 100, 20, "Submit")
' Putting titles in the tabs   
  tab_titles  'using macro
' make buttons & labels for setting all channels to AC or DC   
  RadioAll = Fl_RadioGroupNew(80,115,300,30)
     Fl_RadioGroupBegin(RadioAll)
       ac_all = Fl_Radio_Round_ButtonNew(80,115,50,20,all)
       Fl_WidgetCopyLabel(ac_all,all)
       Fl_WidgetSetCallbackArg ac_all,@SetAllAC,tab5
       dc_all = Fl_Radio_Round_ButtonNew(170,115,50,20,all)
       Fl_WidgetCopyLabel(dc_all,all)
       Fl_WidgetSetCallbackArg dc_all,@SetAllDC,tab5
     Fl_RadioGroupEnd(RadioAll)
' make choice box for input levels
   lvl_all(card) = Fl_ChoiceNew(250,115,128,20,all)
   Fl_Menu_Add3 lvl_all(card),"Input Level/10.0|Input Level/3.16|Input Level/1.00|Input Level/0.316"
   Fl_ChoiceSetValue lvl_all(card),3
   Fl_WidgetSetCallbackArg lvl_all(card),@SetAllLvl,tab5
' make buttons and labels for all channels
   button_lvls  'run macro       
  Fl_TabEnd tab5
  Fl_TabsEnd tabs
Fl_WindowEnd win

Fl_WindowShow win
Fl_WidgetSetCallback (BC1,@Button_Click_Event())
Fl_WidgetSetCallback (BC2,@Button_Click_Event())
Fl_WidgetSetCallback (BC3,@Button_Click_Event())
Fl_WidgetSetCallback (BC4,@Button_Click_Event())
Fl_WidgetSetCallback (BC5,@Button_Click_Event())
END SUB

SUB OpenFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    'Select a file to open:
    DIM AS ZSTRING PTR file
    file = flFileChooser ("Open file", "*.bas" + CHR(9) + "*.txt", EXEPATH(), 1)
    IF file <> 0 THEN PRINT "Selected file:" + *file
END SUB

SUB SaveFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    PRINT "Save File"
END SUB

SUB EndProgram CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    END
END SUB

SUB Info CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    'Show Info:
    flMessageBox ("Program Information", "Menu test program")
END SUB

SUB Button_Click_Event CDECL (widget AS FL_Widget PTR, arg AS ANY PTR)
   dim as long sa,sd,slvl,j,k
   dim as string s1
   PRINT "Button was clicked!"
   For j = 1 to 5
      PRINT
      Print "CARD ";j
      Print " Ch.    AC DC Lvl"
      for k = 0 to 15
         s1 = "Ch " & STR(k)
         sa = Fl_ButtonGetValue(ac(j,k))
         sd = Fl_ButtonGetValue(dc(j,k))
         slvl = Fl_ChoiceGetValue(chc(j,k))
         'print s1
         print Using "\     \ ## ## ##";s1;sa;sd;slvl
      NEXT
   NEXT
   'Fl_Menu_ItemActivate(MENU)
END SUB
'
' This callback routine just shows that the tab was changed
' Not sure what else this could do
'
sub TabCB cdecl (byval tabs as FL_WIDGET ptr,byval parent as any ptr)
  print "TabCB: " & *Fl_WidgetGetLabel(Fl_TabsGetValue(parent))
  c_tab = *Fl_WidgetGetLabel(Fl_TabsGetValue(parent))
  tab_num = CInt(ltrim(c_tab,"CARD "))
  print "Current tab = ";tab_num
end sub

'
' Sets all current tab (card) to DC coupling
'
sub SetAllDC CDECL (BYVAL self as FL_WIDGET PTR, byval btn as any ptr)
   PRINT "SetAllDC: " & *Fl_WidgetGetLabel(btn)
   print *Fl_WidgetGetLabel(self)
   c_tab = *Fl_WidgetGetLabel(btn)
   card = CInt(ltrim(c_tab,"CARD "))
   For i = 0 to 15
      Fl_ButtonSetOnly(dc(card,i))
     
   NEXT
 
END SUB
'
' Sets all current tab (card) to AC coupling
'
sub SetAllAC CDECL (BYVAL self as FL_WIDGET PTR, byval btn as any ptr)
   PRINT "SetAllAC: " & *Fl_WidgetGetLabel(btn)
   print *Fl_WidgetGetLabel(self)
   c_tab = *Fl_WidgetGetLabel(btn)
   card = CInt(ltrim(c_tab,"CARD "))
   'print "Card = ";tab_num
   For i = 0 to 15
      Fl_ButtonSetOnly(ac(card,i))
     
   NEXT
   
END SUB

sub SetAllLvl CDECL (BYVAL self as FL_WIDGET PTR, BYVAL btn as any PTR)
   'print Fl_ChoiceGetValue(lvl_all)
   c_tab = *Fl_WidgetGetLabel(btn)
   card = CInt(ltrim(c_tab,"CARD "))
   'print "Card = ";tab_num
   for i = 0 to 15
      Fl_ChoiceSetValue chc(card,i),Fl_ChoiceGetValue(lvl_all(card))
      'print "Ch ";str(i);" ";Fl_ButtonGetValue(ac(tab_num,i));" "; _
      '   Fl_ButtonGetValue(dc(tab_num,i)),Fl_ChoiceGetValue(chc(tab_num,i))
   NEXT
END SUB


'Main:

CreateWindow_Main ()
Fl_WindowShow (Window_Main)

Fl_Run

END
dkr
Posts: 34
Joined: Nov 20, 2015 15:17
Location: Alabama, USA

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby dkr » Mar 08, 2019 19:54

Found out how to deactivate an item in a menu. To show it, I used Joshy's menu_bar example.

in the NewFile callback:

Code: Select all

t1 = Fl_Menu_FindItemByName(m1,"File/New")    'this gets the menu item pointer
Fl_Menu_ItemDeactivate(t1)         'this will deactivate the "File/New" item


in the save callback:

Code: Select all

t1 = Fl_Menu_FindItemByName(m1,"File/New")    'have to reacquire the pointer
Fl_Menu_ItemActivate(t1) ' this reactivates the first menu item
will reactivate the "File/New" item


Code: Select all

#INCLUDE "fltk-c.bi"

'Declaration of the callback functions - see below:
DECLARE SUB NewFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB OpenFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB SaveFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB EndProgram CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB Info CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)

DIM SHARED AS Fl_Window PTR Window_Main
DIM SHARED AS Fl_Menu_Bar PTR m1
DIM SHARED AS FL_Menu_Item ptr t1

SUB CreateWindow_Main ()
'Window with menu

    Window_Main = Fl_WindowNew (300, 200, "Test menu")
    m1 = Fl_Menu_BarNew (0, 0, 300, 20)
    Fl_Menu_Add (m1, "File/New" ,,  @NewFile())
    Fl_Menu_Add (m1, "File/Open" ,, @OpenFile())
    Fl_Menu_Add (m1, "File/Save" ,, @SaveFile())
    Fl_Menu_Add (m1, "File/End" ,,  @EndProgram())
    Fl_Menu_Add (m1, "Help/Info" ,, @Info())

END SUB

'Callback functions:

SUB NewFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    PRINT "New File"
    t1 = Fl_Menu_FindItemByName(m1,"File/New")
    PRINT t1
   Fl_Menu_ItemDeactivate(t1)
   
END SUB

SUB OpenFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    'Select a file to open:
    DIM AS ZSTRING PTR file
    file = flFileChooser ("Open file", "*.bas" + CHR(9) + "*.txt", EXEPATH(), 1)
    IF file <> 0 THEN PRINT "Selected file:" + *file
END SUB

SUB SaveFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    PRINT "Save File"
    t1 = Fl_Menu_FindItemByName(m1,"File/New")
    Fl_Menu_ItemActivate(t1)
END SUB

SUB EndProgram CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    END
END SUB

SUB Info CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    'Show Info:
    flMessageBox ("Program Information", "Menu test program")
END SUB


'Main:

CreateWindow_Main ()
Fl_WindowShow (Window_Main)
Fl_Run

END
badidea
Posts: 1416
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby badidea » Mar 09, 2019 20:49

Alternative suggestion: Set 'new file window' modal (https://en.wikipedia.org/wiki/Modal_window)

Code: Select all

SUB NewFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
 'Fl_Menu_ItemDeactivate(MENU)
 var win = Fl_WindowNew(500,660,"multi_card_input_v1.bas")
 Fl_WindowSetModal(win)
 ...
James Klutho
Posts: 13
Joined: Nov 11, 2009 23:44

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby James Klutho » Mar 11, 2019 0:40

I downloaded the FLTK library and have been testing it out on my linux mint laptop. I am impressed with the work done here. A small issue with the install though. The instructions to copy the shared objects to my lib folder balked as written:

ubuntu: sudo cp libflt-c*.so /usr/lib

I simply changed it to the following and all is well:
ubuntu: sudo cp libfltk-c*.so /usr/lib

My hat is off to DJ Peters for his translation to c and freebasic.

Jim

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 2 guests