FLTK 1.3.x C Wrapper (obsolete)

User contributed sources that have become inactive, deprecated, or generally unusable. But ... we don't really want to throw them away either.
Post Reply
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by D.J.Peters »

Image
file: Fl_File_Chooser03.bas

Code: Select all

#include once "fltk-c.bi"
Fl_Register_Images()

dim as Fl_File_Chooser ptr fc = Fl_File_ChooserNew("media", "Image Files (*.{gif,jpg,jpeg,bmp,png,tif})", FL_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
Last edited by D.J.Peters on Dec 13, 2013 12:50, edited 1 time in total.
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by D.J.Peters »

Image

Code: Select all

#include once "fltk-c.bi"

' test of:
' Fl_Tile

function CreateMainWindow as FL_WINDOW ptr
  dim as integer w,h
  ' create flicker free double window
  dim as FL_Window ptr win = Fl_Double_WindowNew(100,100,512,512,"move the lines or the cross in the middle")
  Fl_WindowBegin win
    w=Fl_WidgetGetW(win)
    h=Fl_WidgetGetH(win)
    dim as FL_Group ptr grp = Fl_GroupNew(0,0,w,h)
    Fl_GroupBegin grp
      dim as FL_Group ptr tile = Fl_TileNew(0,0,w,h)
      Fl_GroupBegin tile
        w=w\2 : h=h\2
        Fl_WidgetSetBox Fl_Round_ClockNew(0,0,w,h),FL_DOWN_BOX
        Fl_WidgetSetBox Fl_Round_ClockNew(w,0,w,h),FL_DOWN_BOX
        Fl_WidgetSetBox Fl_Round_ClockNew(0,h,w,h),FL_DOWN_BOX
        Fl_WidgetSetBox Fl_Round_ClockNew(w,h,w,h),FL_DOWN_BOX
      Fl_GroupEnd tile
    Fl_GroupEnd grp
  Fl_WindowEnd win
  Fl_GroupSetResizable win,grp
  Fl_WindowSizeRange win,160,100
  return win
end function

'
' main
'
Fl_WindowShow CreateMainWindow()
Fl_Run
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by D.J.Peters »

Image

Code: Select all

#include once "fltk-c.bi"

' test of:
' Fl_GroupSetResizable  http://www.fltk.org/doc-1.3/classFl__Group.html#afd220e45e1ac817bde7d6a25fdf74e37

const BOX_STYLE = FL_DOWN_BOX

' get screensize and calculate window size
dim as integer sw = Fl_GetW(),ww=sw\2
dim as integer sh = Fl_GetH(),wh=sh\2

' create a centered flicker free (double buffered) window
dim as FL_WINDOW ptr win = Fl_Double_WindowNew(ww\2,wh\2,ww,wh, "resize me ...")

Fl_WindowBegin win ' open the child list
  dim as integer bw = ww\4, bh = wh\4

  ' add 4 boxes in first row
  Fl_WidgetSetColor Fl_BoxNew2(BOX_STYLE,bw*0,bh*0,bw*1,bh*1),fl_RGB_Color(rnd*255,rnd*255,rnd*255)
  Fl_WidgetSetColor Fl_BoxNew2(BOX_STYLE,bw*1,bh*0,bw*1,bh*1),fl_RGB_Color(rnd*255,rnd*255,rnd*255)
  Fl_WidgetSetColor Fl_BoxNew2(BOX_STYLE,bw*2,bh*0,bw*1,bh*1),fl_RGB_Color(rnd*255,rnd*255,rnd*255)
  Fl_WidgetSetColor Fl_BoxNew2(BOX_STYLE,bw*3,bh*0,bw*1,bh*1),fl_RGB_Color(rnd*255,rnd*255,rnd*255)

  ' add 3 boxes in second row
  Fl_WidgetSetColor Fl_BoxNew2(BOX_STYLE,bw*0,bh*1,bw*1,bh*2),fl_RGB_Color(rnd*255,rnd*255,rnd*255)
  Fl_WidgetSetColor Fl_BoxNew2(BOX_STYLE,bw*1,bh*1,bw*2,bh*2),FL_BLACK
  Fl_WidgetSetColor Fl_BoxNew2(BOX_STYLE,bw*3,bh*1,bw*1,bh*2),fl_RGB_Color(rnd*255,rnd*255,rnd*255)

  ' add 2 boxes in third row
  Fl_WidgetSetColor Fl_BoxNew2(BOX_STYLE,bw*0,bh*3,bw*2,bh*1),fl_RGB_Color(rnd*255,rnd*255,rnd*255)
  Fl_WidgetSetColor Fl_BoxNew2(BOX_STYLE,bw*2,bh*3,bw*2,bh*1),fl_RGB_Color(rnd*255,rnd*255,rnd*255)

Fl_WindowEnd win ' close the child list

Fl_GroupSetResizable win,win ' all child boxes are resized proportional

Fl_WindowShow win ' bring the window on the screen

Fl_Run ' enter the message loop
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by D.J.Peters »

New version is aviable. (see first post)

Joshy

fixed: Fl_Shared_ImageGet was wrong

Code: Select all

declare function Fl_Shared_ImageGet(img_name as const zstring ptr, w as integer=0, h as integer=0) as Fl_Shared_Image ptr
added: JPEG and PNG loading from memory

Code: Select all

' load from memory
' If a name is given, the image is added to the list of shared images (see: Fl_Shared_Image) and will be available by that name.
declare function Fl_PNG_ImageMem(name_png as const zstring ptr=0, buffer as const any ptr, datasize as integer) as FL_PNG_Image ptr
declare function Fl_JPEG_ImageMem(name_jpeg as const zstring ptr=0, buffer as const any ptr) as FL_JPEG_Image ptr
Fl_Widgets as Fl_TreeItems works now.
Image

Code: Select all

#include once "fltk-c.bi"

'test of:
' Fl_Tree_ItemSetWidget 

sub TreeCB cdecl (wgt as Fl_Widget ptr, pdata as any ptr)
  dim as Fl_Tree ptr tr = cptr(Fl_Tree ptr,wgt)
  dim as Fl_Tree_Item ptr item = Fl_TreeGetCallbackItem(tr)
  if (item=0) then exit sub
  
  dim as const zstring ptr label = Fl_Tree_ItemGetLabel(item)
  select case Fl_TreeGetCallbackReason(tr)
  case FL_TREE_REASON_SELECTED    : print "FL_TREE_REASON_SELECTED   " & *label
  case FL_TREE_REASON_DESELECTED  : print "FL_TREE_REASON_DESELECTED " & *label
  case FL_TREE_REASON_OPENED      : print "FL_TREE_REASON_OPENED     " & *label
  case FL_TREE_REASON_CLOSED      : print "FL_TREE_REASON_CLOSED     " & *label
  end select
end sub

sub ButtonCB cdecl (wgt as Fl_Widget ptr, pdata as any ptr)
  ? "ButtonCB"
end sub


'
' main
'
#define MAX_FIELDS   5
#define FIELD_WIDTH  70
#define FIELD_HEIGHT 30

dim as Fl_Tree_Item ptr item
dim as Fl_Group ptr grp

dim as Fl_Window ptr win = Fl_WindowNew(100,100, 320,200, "Fl_Tree03.bas")
Fl_WindowBegin(win)

  dim as Fl_Tree ptr tree = Fl_TreeNew(10,20,300,170,"Fl_Tree")
  Fl_TreeSetShowRoot(tree,0) ' don't show root of tree
  Fl_WidgetSetCallback(tree,@TreeCB) ' setup a callback for the treeview

  Fl_GroupBegin(tree)

    Fl_TreeAdd(tree,"Flintstones/Fred") ' add some items
    Fl_TreeAdd(tree,"Flintstones/Wilma")
    Fl_TreeAdd(tree,"Flintstones/Pebbles")
    Fl_TreeClose(tree,"Flintstones")
    
    Fl_TreeAdd(tree,"Simpsons/Homer")
    Fl_TreeAdd(tree,"Simpsons/Marge")
    Fl_TreeAdd(tree,"Simpsons/Bart")
    Fl_TreeAdd(tree,"Simpsons/Lisa")
    Fl_TreeClose(tree,"Simpsons")

    item = Fl_TreeAdd(tree,"Widgets/Fields")
    grp=Fl_GroupNew(0,0,FIELD_WIDTH*MAX_FIELDS, FIELD_HEIGHT)
      for i as  integer = 0 to MAX_FIELDS-1
        Fl_InputNew(i*FIELD_WIDTH,0,FIELD_WIDTH,FIELD_HEIGHT)
      next
    Fl_GroupEnd(grp)
    Fl_Tree_ItemSetWidget item,grp

    item = Fl_TreeAdd(tree,"Widgets/Button")
    grp=Fl_GroupNew(0,0,160,16)
      dim as Fl_ButtonEx ptr Btn = Fl_ButtonExNew(0,0,160,16,"ok")
      Fl_WidgetSetCallback Btn,@ButtonCB
    Fl_GroupEnd(grp)
    Fl_Tree_ItemSetWidget item,grp
    Fl_TreeClose(tree,"Widgets")

  Fl_GroupEnd(tree)

Fl_WindowEnd(win)

Fl_GroupSetResizable(win,win)

Fl_WindowShow win

Fl_Run
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by D.J.Peters »

All kinds of FLTK windows have two constructors now.
(FL_Window, FL_Menu_Window, FL_Double_Window, Fl_GL_Window, FL_WindowEx,FL_Menu_WindowEx, FL_Double_WindowEX, Fl_GL_WindowEX)

Code: Select all

Fl_XXXNew(w as integer, h as integer,label as const zstring ptr=0)
Fl_XXXNew2(x as integer, y as integer, w as integer, h as integer,label as const zstring ptr=0)
note: Fl_XXXNew(320,200,"my window") isn't the same as: Fl_XXXNew2(0,0,320,200,"my window")

In first case the window manger on Linux or the windows desktop will define the new window position.

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

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by D.J.Peters »

Class Fl_Printer added and tested on Linux and Windows successful.

Joshy

Code: Select all

#include once "fltk-c.bi"

sub ButtonCB cdecl (wgt as Fl_Widget ptr, pData as any ptr)
  dim as integer w,h
  dim as Fl_Printer ptr prt = Fl_PrinterNew()
  if prt then
    Fl_PrinterStartJob prt,1
      Fl_PrinterStartPage prt
        Fl_PrinterSetCurrent prt
        Fl_PrinterGetPrintableRect prt,w,h
        print "page size " & w/72      & " x " & h/72      & " zoll"
        print "page size " & w/72*2.54 & " x " & h/72*2.54 & " cm"
        w \=16:w *=16
        h \=16:h *=16
        DrawRect 0,0,w-1,h-1
        for x as integer=0 to w-1 step 16
          DrawLine x,0,x,h-1
        next
        for y as integer=0 to h-1 step 16
          DrawLine 0,y,w-1,y
        next
      Fl_PrinterEndPage prt
    Fl_PrinterEndJob prt
    Fl_PrinterDelete prt
  end if
end sub


dim as Fl_Window ptr win = Fl_WindowNew(70,40)
dim as Fl_Button ptr btn = Fl_ButtonNew(10,10,60,20,"print")
Fl_WidgetSetCallBackArg btn,@ButtonCB

Fl_WindowShow win
Fl_Run
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by tinycla »

I receive an error trying to download the wrapper. What happened? The link doesn't work anymore.
Drago
Posts: 116
Joined: Aug 10, 2005 13:15

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by Drago »

It's now
ok now in first Post
And to Joshy... Great work !
Last edited by Drago on Dec 17, 2013 7:32, edited 1 time in total.
Imortis
Moderator
Posts: 1966
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by Imortis »

The example code in Drawing3.bas needs to be updated. Fl_WindowNew needs to be changed to Fl_WindowNew2
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by D.J.Peters »

tinycla wrote:I receive an error trying to download the wrapper. What happened? The link doesn't work anymore.
It happens only if you try to download while an upload are currently in progress.
Drago wrote:It's now xxx
remove the link from your post please
It's better to have only one link in the first post.
(if i change the server or the filename it will end in some dead links)
Drago wrote:And to Joshy... Great work !
Thank you for the nice comment.
Imortis wrote:The example code in Drawing3.bas needs to be updated. Fl_WindowNew needs to be changed to Fl_WindowNew2
Drawing03.bas isn't in the official download it was only on my Linux folder and never used.

Joshy
VANYA
Posts: 1866
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by VANYA »

Joshy fellow, as always everything works fine!
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by D.J.Peters »

VANYA wrote:Joshy fellow, as always everything works fine!
Thank you for testing.

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

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by D.J.Peters »

Code: Select all

#include once "fltk-c.bi"

' you can set for each widget callback's and there are 3 kinds of callbacks

' Callback with an pointer as user argument sub cecl callback(widget as FL_WIDGET ptr, pUserData as any ptr)
' Fl_WidgetSetCallback widget,@Callback
' Fl_WidgetSetCallbackArg widget,@Callback,pArg

' Callback0 without an argument sub cecl callback(widget as FL_WIDGET ptr)
' Fl_WidgetSetCallback0 widget,@Callback

' Callback1 with an long as user argument sub cecl callback(widget as FL_WIDGET ptr, UserData as long)
' Fl_WidgetSetCallback1Arg widget,@Callback,value

sub Callback cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
  print "Callback with ptr arg " & *Fl_WidgetGetLabel(widget) & " , "  & pUserData
end sub

sub Callback1 cdecl (widget as FL_WIDGET ptr, UserData as long)
  print "Callback with long arg " & *Fl_WidgetGetLabel(widget) & " , "  & UserData
end sub

sub Callback0 cdecl (widget as FL_WIDGET ptr)
  print "Callback " & *Fl_WidgetGetLabel(widget)
end sub

dim as FL_WINDOW ptr win  = Fl_WindowNew(250,50,"Fl_Callbacks")
dim as FL_BUTTON ptr btn1 = Fl_ButtonNew( 10,10,70,30,"button 1")
dim as FL_BUTTON ptr btn2 = Fl_ButtonNew( 90,10,70,30,"button 2")
dim as FL_BUTTON ptr btn3 = Fl_ButtonNew(170,10,70,30,"button 3")

Fl_WidgetSetCallbackArg  btn1,@Callback,btn1
Fl_WidgetSetCallback0    btn2,@Callback0
Fl_WidgetSetCallback1Arg btn3,@Callback1,123

Fl_WindowShow win
Fl_Run
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by tinycla »

The link in page 1 for me doesn't work. I receive the error "Not found". The files does not exists.
Please try to fix the error. Thanks.
Drago
Posts: 116
Joined: Aug 10, 2005 13:15

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.2)

Post by Drago »

just change the link from /fltk/fltk-c.zip to /fltk-c/fltk-c.zip

I think Joshy will fix this as soon as possible..

Greetings
Drago
Post Reply