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
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by VANYA »

D.J.Peters wrote:
VANYA wrote:Is it possible in FLTK to minimize the window and return it to its original state from the "minimize" ?
Min- or maximizing a window is the job of the window manager
triggered by the user if he/she click the min/max button.

If you will do it self by code you have to use the Windows API or XLIb.

With other words there isn't a Fl_WindowMinimize(win) nor Fl_WindowMaximize(win) method.
(So far I know)

Joshy
Clear, thanks for the answer.
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by jevans4949 »

Joshy (or anybody), sorry to be a pain.

I'm writing a program which needs a "pop-up" window on processing the first data record of each of 2 files.

1. Does FLTK-C provide access to the C++ destructors? I would like to get rid of this window once I've got the user input (and copied it into a global).

2. How do I exit a window from a button within the pop-up window and return to the process in the main window?

I also notice that in FLTK C++, Fl_File_ChooserShow is supposed to return a pointer to the chosen filename, or null if none is chosen, whereas in the .bi it is defined as a sub. I worked around this, but can we have the C++ functionality?
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 »

jevans4949 wrote:I also notice that in FLTK C++, Fl_File_ChooserShow is supposed to return a pointer to the chosen filename, or null if none is chosen
Thats wrong my friend :-)

Fl_File_ChooserShown() returns<>0 if the dialog are not closded by the user.

Fl_File_ChooserGetValue(fc) returns the selected stuff or NULL

Joshy

file: Fl_File_Chooser03.bas

Code: Select all

#include once "fltk-c.bi"

' test of:
' Fl_Register_Images    http://www.fltk.org/doc-1.3/Fl__Shared__Image_8H.html#a5c361cb2fdac6c22f6259f5e044657f4
' Fl_Wait               http://www.fltk.org/doc-1.3/classFl.html#a108a84216f0b3fa1cb0c46ab7449a312
' Fl_File_Chooser       http://www.fltk.org/doc-1.3/classFl__File__Chooser.html
' Fl_File_ChooserShown
' Fl_File_ChooserGetValue
' Fl_File_ChooserCount

Fl_Register_Images() ' for image previews

dim as Fl_File_Chooser ptr fc

fc = Fl_File_ChooserNew("media", "Image Files (*.{gif,jpg,jpeg,bmp,png,tif})", FL_FILECHOOSER_SINGLE, "Fl_File_Chooser03.bas")

Fl_File_ChooserShow fc
while Fl_File_ChooserShown(fc)
  Fl_Wait()
wend

if Fl_File_ChooserCount(fc) then
  print *Fl_File_ChooserGetValue(fc)
end if
print "press any key ..."
sleep


nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by nimdays »

I didn't know Fl_Text_Editor has built in drag and drop.
I can move selection to another editor and even move some links from my desktop.
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 »

All FLTK widgets supports DND (so far I know)
but you need to start a DND and look for the right event's.
http://www.fltk.org/articles.php?L770

Joshy

I tested only DND with files file: Fl_DND_Files.bas

Code: Select all

#include once "fltk-c.bi"

' test of DND :
' Fl_EventText()

function HandleCB cdecl (byval self as any ptr,byval event as FL_EVENT) as long
  static as integer ActiveDND=0
  select case as const event
  case FL_EVENT_DND_ENTER   : ActiveDND=1 : return 1
  case FL_EVENT_DND_LEAVE   : ActiveDND=0 : return 1
  case FL_EVENT_DND_DRAG , FL_EVENT_DND_RELEASE : return 1
  case FL_EVENT_PASTE
    if ActiveDND then
      beep
      print *Fl_EventText() : ActiveDND=0 : return 1
    end if
  end select
  return Fl_WindowExHandleBase(self,event)
end function
'
' main
'
var win = Fl_WindowExNew(640,480,"Drag file[s] over the window !")
Fl_WindowExSetHandleCB win,@HandleCB
Fl_WindowShow win
Fl_Run
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 »

Because of malware on alice-dsl.net domain I moved all content to my new shiny3d.de server.

Joshy
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by nimdays »

Last time i ignored the warning and downloaded it.

By the way, I have undefined reference to `Fl_GetFontSizes` here.
I don't know, Maybe i put the wrong code ?

Code: Select all

#include once "fltk-c.bi"

sub BrowserCB cdecl(byval self as FL_WIDGET ptr,byval box as any ptr)
  var brw = cptr(Fl_Browser ptr,self)
  dim as long i = Fl_BrowserGetValue(brw)
  Fl_WidgetCopyLabel box,Fl_BrowserGetText(brw,i)
  Fl_WidgetSetLabelFont(box,i)
  Fl_WidgetRedrawLabel box
  
  dim as long ptr s
  'dim as long n = Fl_GetFontSizes(i,s)
end sub


var Win = Fl_WindowNew(400,170)
var box = Fl_BoxNew    (10,0,140,24)
var brw = Fl_BrowserNew(10,24,200,116)
Fl_WidgetSetType brw,FL_HOLDBROWSER
Fl_WidgetSetCallbackArg brw,@BrowserCB,box
var brw1 = Fl_BrowserNew(220,24,170,116)

dim n as zstring ptr = @"*"
dim as FL_FONT k = Fl_SetFonts(n)

for i as integer = 0 to k-1
    '?*Fl_GetFontName(i)
    Fl_BrowserAdd brw,*Fl_GetFontName(i)
next i

Fl_WindowShow Win
Fl_Run
Thanks.
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 »

You are right good find
"Fl_GeFontSizes" it's an missing "t" in my C++ code :-)

as a workaround you can change in file: fltk-main.bi line: 2583 to
declare function Fl_GetFontSizes alias "Fl_GeFontSizes" (byval f as FL_FONT, byref size as long ptr) as long

thank you

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 »

Here are a test of Fl_GetFontSizes() and how it works.

Note only few fonts have fixed sizes (bitmap fonts) for example the old courier, terminal or symbol ...
all other are true type (vector fonts) and can be drawn in a wide range of size.

joshy

Code: Select all

#include once "fltk-c.bi"

dim shared as Fl_Browser ptr brw1,brw2

sub BrowserCB cdecl(byval self as FL_WIDGET ptr,byval box as any ptr)
  dim as FL_FONTSIZE ptr s 
  var i = Fl_BrowserGetValue(brw1)
  Fl_WidgetSetLabelFont(box,i)
  Fl_WidgetCopyLabel(box,Fl_BrowserGetText(brw1,i))
  Fl_BrowserClear(brw2)
  var nSizes = Fl_GetFontSizes(i,s)
  if nSizes>0 andalso s[0]<>0 then
    for i=0 to nSizes-1
      Fl_BrowserAdd(brw2, str(s[i]))
    next
  end if
  'redraw the window
  Fl_WidgetRedraw(Fl_WidgetWindow(brw1))
end sub

'
' main
'
#define W Fl_WidgetGetW
#define H Fl_WidgetGetH
#define Y Fl_WidgetGetY
const gap = 10

var Win = Fl_WindowNew(400,300)

var box = Fl_BoxNew(gap,gap,W(win)-gap*2,24,"select a font ...")
brw1 = Fl_BrowserNew(gap          ,gap*2+H(box),W(win)-gap*8,H(win)-H(box)-3*gap)
brw2 = Fl_BrowserNew(gap*2+W(brw1),Y(brw1)     ,4*gap       ,H(brw1))
Fl_WidgetSetCallbackArg(brw1,@BrowserCB,box)
Fl_WidgetSetType(brw1,FL_HOLDBROWSER)
Fl_WidgetSetType(brw2,FL_HOLDBROWSER)

var n = Fl_SetFonts()
for i as integer = 0 to n-1
  var fontName = *Fl_GetFontName(i)
  if left(fontName,1)<>"@" then Fl_BrowserAdd(brw1, fontName)
next

Fl_WindowShow(Win)
Fl_Run
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by nimdays »

Thanks , Many of my fonts don't have size.
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 »

nimdays wrote:Thanks , Many of my fonts don't have size.
you mean: "Many of my fonts don't have fixed sizes" right ?
Fixed sizes fonts are bitmaps all other fonsts are scaleable vector fonsts.

Joshy

file: Fl_GetFontSizes.bas

Code: Select all

#include "fltk-c.bi"

dim as string fontName
dim as long fontAttributes,nSizes,fontSize,fontNumber,nFonts
dim as long ptr fontSizes

' load font list
nFonts = Fl_SetFonts()    
while fontNumber<nFonts
  fontName = *Fl_GetFontName(fontNumber,@fontAttributes)
  if len(fontName) andalso (left(fontName,1)<>"@")then
    print fontName & " "; 
    select case as const fontAttributes
      case FL_BOLD        : print "is bold ";
      case FL_ITALIC      : print "is italic ";
      case FL_BOLD_ITALIC : print "is bold and italic ";
    end select 
        
    nSizes = Fl_GetFontSizes(fontNumber,fontSizes)
    if (nSizes>1) andalso (fontSizes[0]<>0) then
      print "font has fixed sizes: ";
      for i as integer =0 to nSizes-1
        fontSize=fontsizes[i]
        print str(fontSize) & " ";
      next
      sleep 1000
    end if 
    print
  end if
  fontNumber+=1
wend
?:? "press any key ..."
sleep
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by nimdays »

D.J.Peters wrote: you mean: "Many of my fonts don't have fixed sizes" right ?
Fixed sizes fonts are bitmaps all other fonsts are scaleable vector fonsts.

Joshy
Thanks again for the code, and yes fixed sizes.
dkr
Posts: 40
Joined: Nov 20, 2015 15:17
Location: Alabama, USA

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by dkr »

Hello,
I am trying to make a input selection for a data acquisition system. I have played around a little with the fltk for freebasic library, but kind of stuck on using Radio Button. I have looked at all the examples that Joshy has provided - still stumped.
When I try to use the b1 = Fl_Radio_ButtonNew() the code compiles but doesn't run (currently commented out). The Fl_Radio_Round_NewButton functions do work.

Also, I need to make sixteen of these AC / DC | input level selections. Is there an easy way to do this besides lots of copy and pastes? I don't have the code yet, but I will save the results to a file. I will also have to have five to seven of these pages - one per card on the data acq system.

Thanks,
Darren

Code: Select all

   #INCLUDE "fltk-c.bi"

'Windows and widgets:
DIM SHARED AS Fl_Window PTR Window_Main
DIM SHARED AS Fl_Box PTR Box_text
DIM SHARED AS Fl_Button PTR Button_Click
DIM SHARED AS Fl_Group PTR Group_radio
DIM SHARED AS Fl_Button PTR Button_close
Dim SHARED AS Fl_Radio_Button PTR b1,b2
DIM SHARED AS Fl_Radio_Round_Button PTR br_ac1,br_ac2,br_ac3,br_ac4,br_ac5,br_ac6,br_ac7,br_ac8
DIM SHARED AS Fl_Radio_Round_Button PTR br_ac9,br_ac10,br_ac11,br_ac12,br_ac13,br_ac14,br_ac15,br_ac16
DIM SHARED AS Fl_Radio_Round_Button PTR br_dc1,br_dc2,br_dc3,br_dc4,br_dc5,br_dc6,br_dc7,br_dc8
DIM SHARED AS Fl_Radio_Round_Button PTR br_dc9,br_dc10,br_dc11,br_dc12,br_dc13,br_dc14,br_dc15,br_dc16
DIM SHARED AS FL_Choice PTR chc
Dim Shared ac(1 to 16) as Integer


SUB Create_Window_Main ()
'Window with button:

    Window_Main = Fl_WindowNew (400, 400, "Input Voltage Level & Coupling")
    Box_text = Fl_BoxNew(10, 80, 50, 20, "Ch.1")
    Fl_WidgetSetLabelFont Box_text,FL_HELVETICA_BOLD :Fl_WidgetSetLabelSize Box_text,18
    Group_radio = Fl_GroupNew (10, 70, 190, 190, "   AC     DC")
        Fl_GroupBegin (Group_radio)
            'b1 = Fl_Radio_ButtonNew(60, 80, 80, 40,"AC")   '<--- these don't work ????
            'Fl_WidgetSetSelectionColor(Fl_Radio_ButtonNew(130, 80, 80, 40,"DC"),FL_RED) '<- would really like to do this ??
            'b2 = Fl_Radio_ButtonNew(130, 80, 80, 40,"DC")  '<--- these don't work ????
            br_ac1 = Fl_Radio_Round_ButtonNew (60, 80, 50, 20, "ac1")
            br_dc1 = Fl_Radio_Round_ButtonNew (130, 80, 50, 20, "dc1")
        Fl_GroupEnd (Group_radio)
    chc = Fl_ChoiceNew(180,80,80,20)    
    Fl_Menu_Add3 chc,"Input Level/±10.0|Input Level/±3.16|Input Level/±1.00|Input Level/±0.316"
    Fl_ChoiceSetValue chc,3
    Button_close = Fl_ButtonNew (20, 350, 100, 20, "Close")

END SUB

SUB Buttons_Event CDECL (widget AS Fl_Widget PTR, arg AS ANY PTR)
'Callback function for all buttons
    dim inplvl(1 to 16) as single => {10.0,3.16,1.0,0.316}
    SELECT CASE arg
'        CASE br_ac1
'            PRINT "Channel 1 - AC Coupled"
            'Print "br_ac1 = ";Fl_ButtonGetValue (br_ac1)
            'print "br_dc1 = ";Fl_ButtonGetValue (br_dc1)
            'ac(1) = Fl_ButtonGetValue (br_ac1)
'        CASE br_dc1
'            PRINT "Channel 1 - DC Coupled"
'            'Print "br_ac1 = ";Fl_ButtonGetValue (br_ac1)
'            'print "br_dc1 = ";Fl_ButtonGetValue (br_dc1)
            
'        CASE br_ac2
'            PRINT "Channel 2 - AC Coupled"
        CASE Button_close
            ac(1) = Fl_ButtonGetValue (br_ac1)
            Print "br_ac1 = ";ac(1)
            print inplvl(Fl_ChoiceGetValue(chc))
            Print "Save all information here"
            END
    END SELECT

END SUB

'Main program:
Create_Window_Main ()
'Fl_WidgetSetCallbackArg(br_ac1, @Buttons_Event(),br_ac1)
Fl_WidgetSetCallbackArg(br_dc1, @Buttons_Event(),br_dc1)
Fl_WidgetSetCallbackArg (Button_close, @Buttons_event(), Button_close)
Fl_WindowShow(Window_Main)
Fl_Run

END   
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"

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

var Win = Fl_WindowNew(320,60)
Fl_WindowBegin(win) ' <- this are optional (done by Fl_WindowNew)

  var RadioGroup = Fl_RadioGroupNew(10,20,300,40,"I'm a radio group")
  Fl_RadioGroupBegin(RadioGroup)
    Fl_Radio_ButtonNew( 10,20,90,30,"radio A")
    Fl_Radio_ButtonNew(110,20,90,30,"radio B")
    Fl_Radio_ButtonNew(210,20,90,30,"radio C")
  Fl_RadioGroupEnd(RadioGroup)  

Fl_WindowEnd(win) ' <- this are optional (done by Fl_WindowShow)
Fl_WindowShow Win
Fl_Run
an array of radio groups

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 NRADIO_GROUPS = 10
dim as Fl_RadioGroup ptr RadioGroups(NRADIO_GROUPS-1)

var Win = Fl_WindowNew(320,20+NRADIO_GROUPS*40)
for i as integer = 0 to NRADIO_GROUPS-1
  RadioGroups(i) = Fl_RadioGroupNew(10,20+i*40,300,40)
  Fl_RadioGroupBegin(RadioGroups(i))
    Fl_Radio_Round_ButtonNew( 10,20+i*40,90,30,"radio A")
    Fl_Radio_Round_ButtonNew(110,20+i*40,90,30,"radio B")
    Fl_Radio_Round_ButtonNew(210,20+i*40,90,30,"radio C")
  Fl_RadioGroupEnd(RadioGroups(i))  
next  

Fl_WindowShow Win
Fl_Run
using DATA lines to define diffrent captions or values

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

' if you need different caption or what ever you can use DATA lines

data 10 ' number of groups
data  3 ' number of buttons per group
data "aaa","bbb","ccc" 
data "A","B","C"
data "one","two","three"
data "1","2","3"
data "aaa","bbb","ccc"
data "aaa","bbb","ccc"
data "aaa","bbb","ccc"
data "aaa","bbb","ccc"
data "aaa","bbb","ccc"
data "aaa","bbb","ccc"

dim as integer NGROUPS,BUTTONS_PER_GROUP
read NGROUPS
read BUTTONS_PER_GROUP

var Win = Fl_WindowNew(320,20+NGROUPS*30)
for i as integer = 0 to NGROUPS-1
  var RadioGroup = Fl_RadioGroupNew(10,20+i*30,300,40)
  Fl_RadioGroupBegin(RadioGroup)
    for j as integer = 0 to BUTTONS_PER_GROUP-1
      dim as string label : read label
      var button = Fl_Radio_Round_ButtonNew(10+j*100,20+i*30,90,30)
      Fl_WidgetCopyLabel(button,label)
    next
  Fl_RadioGroupEnd(RadioGroup)  
next  

Fl_WindowShow Win
Fl_Run
dkr
Posts: 40
Joined: Nov 20, 2015 15:17
Location: Alabama, USA

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by dkr »

Mr. Peters, thanks for the reply. I can use these examples in my code. I did figure out why it wasn't working. I had a call back to a ptr that wasn't called - I think. I appreciate all your hard work on this library.

Darren
Post Reply