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
ike
Posts: 387
Joined: Jan 17, 2011 18:59

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

Post by ike »

Your english is better than mine, and I live and work in Canada 19 years!

And you almost (I said almost) answer my next question:
1. How to make small program with 2 buttons - when you press first draw a circle over second


and also:
2. Tree buttons, and when you press first change font on second and third.
I want to see how you pass parameters so I dont use ugly Dim shared

Thx

P.S. FLTK Wrapper is very good, better IMO then any other GUI for FB
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 »

ike wrote:How to make small program with 2 buttons - when you press first draw a circle over second
You a need a Window with two Buttons one from them must be a ButtonEX for the Draw callback.

Joshy

Code: Select all

#include once "fltk-c.bi"

' test of:
' Fl_XXXExSetDrawCB

sub Button1CB cdecl (self as Fl_Widget ptr,Button2 as any ptr)
  dim as any ptr DrawFlag = cast(any ptr,1)
  Fl_WidgetSetUserData Button2,DrawFlag
  Fl_WidgetRedraw Button2
end sub

function Button2DrawCB cdecl (self as any ptr) as integer
  var DrawFlag = Fl_WidgetGetUserData(self)
  if DrawFlag then
    var x = Fl_WidgetGetX(self) + Fl_WidgetGetW(self)/2
    var y = Fl_WidgetGetY(self) + Fl_WidgetGetH(self)/2
    var r = Fl_WidgetGetH(self)/2
    DrawSetColor FL_RED
    DrawCircle x,y,r
    DrawFlag=0 : Fl_WidgetSetUserData self,DrawFlag
    return 1 ' <-- tell FLTK "ignore the callback we are draw the button"
  end if
  return 0 ' <-- tell FLTK "don't ignore the callback and drawn the button for us"
end function
'
' main
'
var Window1 = Fl_WindowNew(158,52,"WidgetDrawing")
var Button1 = Fl_ButtonNew(10,10,64,32,"draw...")
var Button2 = Fl_ButtonExNew(84,10,64,32,"clear...")
Fl_WidgetSetCallbackArg Button1,@Button1CB,Button2
Fl_ButtonExSetDrawCB    Button2,@Button2DrawCB
Fl_WindowShow           Window1
Fl_Run
Last edited by D.J.Peters on Jan 13, 2014 8:27, 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 »

ike wrote:2. Tree buttons, and when you press first change font on second and third.
Inside a TreeView callback you can navigate to next/prev/first/last treeitem and set or get any treeitem property.
(of course you can retrieve a treeitem by its name too)

Here are the Tree_Item properties:

Code: Select all

type Fl_Tree_Item
  as const zstring ptr  _label            ' label (memory managed)
  as Fl_Font            _labelfont        ' label's font face
  as Fl_Fontsize        _labelsize        ' label's font size
  as Fl_Color           _labelfgcolor     ' label's fg color
  as Fl_Color           _labelbgcolor     ' label's bg color (0xffffffff is 'transparent')
  as ushort             _flags            ' misc flags
  as integer            _xywh(3)          ' xywh of this widget (if visible)
  as integer            _collapse_xywh(3) ' xywh of collapse icon (if visible)
  as integer            _label_xywh(3)    ' xywh of label
  as Fl_Widget ptr      _widget           ' item's label widget (optional)
  as Fl_Image ptr       _usericon         ' item's user-specific icon (optional)
  as Fl_Tree_Item_Array _children         ' array of child items
  as Fl_Tree_Item ptr   _parent           ' parent item (=0 if root)
  as any ptr            _userdata         ' user data that can be associated with an item
  as Fl_Tree_Item ptr   _prev_sibling     ' previous sibling (same level)
  as Fl_Tree_Item ptr   _next_sibling     ' next sibling (same level)
end type
ike wrote:I want to see how you pass parameters so I dont use ugly Dim shared
Remember you can set to any FLTK widget and of course for Tree Items also a user defined value.
So there is no need for any shared vars in a FLTK application.

In this simple test i change the font,fontsize, fontcolor and background color of all Tree Items after the selected Tree Item.

Joshy

Code: Select all

#include once "fltk-c.bi"

sub TreeCB cdecl (wgt as Fl_Widget ptr, userdata as any ptr)
  var tree = cptr(Fl_Tree ptr,wgt)
  var item = Fl_TreeGetCallbackItem(tree)
  if (item=0) then exit sub
  item = Fl_TreeNext(tree,item)
  while item
    item->_labelfont   =   rnd*14
    item->_labelsize   =12+rnd*20
    item->_labelfgcolor=Fl_RGB_Color(rnd*255,rnd*255,rnd*255)
    item = Fl_TreeNext(tree,item)
  wend
end sub

'
' main
'
var win  = Fl_WindowNew(320,200, "for ike")
var tree = Fl_TreeNew(10,20,300,170)
Fl_TreeSetShowRoot(tree,0)         ' don't show root of tree
Fl_TreeAdd(tree,"Item 1")
Fl_TreeAdd(tree,"Item 2")
Fl_TreeAdd(tree,"Item 3")
Fl_WidgetSetCallback(tree,@TreeCB)
Fl_WindowShow win
Fl_Run
more random values

Code: Select all

#include once "fltk-c.bi"
sub TreeCB cdecl (widget as Fl_Widget ptr, tree as any ptr)
  Fl_TreeSetConnectorColor tree,Fl_RGB_Color(rnd*255,rnd*255,rnd*255)
  Fl_TreeSetConnectorStyle tree,cast(Fl_Tree_Connector,int(rnd*3))
  Fl_TreeSetSelectBox      tree,cast(FL_Boxtype,1+int(rnd*35))

  var item = Fl_TreeGetCallbackItem(tree)
  if item=0 then return

  item = Fl_TreeNext(tree,item)
  while item
    item->_labelfont   =   rnd*14
    item->_labelsize   =12+rnd*20
    dim as ubyte r=rnd*255, g=rnd*255, b=rnd*255
    item->_labelfgcolor=Fl_RGB_Color(r,g,b)
    item->_labelbgcolor=Fl_RGB_Color(255-r,255-g,255-b)
    item = Fl_TreeNext(tree,item)
  wend
end sub
'
' main
'
Fl_Background 128,128,128


var win  = Fl_Double_WindowNew(200,600, "for ike")
var tree = Fl_TreeNew(10,10,180,580)
Fl_TreeSetShowRoot tree,0 ' don't show root of tree
dim as integer root,parent,child
for i as integer=1 to 20
  if rnd<0.5 then
    root+=1:child=1
  elseif rnd<0.5 then
    parent+=1:child=1
  else
    child+=1
  end if
  Fl_TreeAdd tree,"root" & root & "/parent" & parent & "/ Item" & child
next
Fl_WidgetSetCallbackArg tree,@TreeCB,tree
Fl_GroupSetResizable win,tree
Fl_WindowShow win
Fl_Run
ike
Posts: 387
Joined: Jan 17, 2011 18:59

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

Post by ike »

Thx Joshi

userdata's confusing me, but now it is clear, I guess

Regards
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 »

A new version is available I added an optional DestructorCB to all extended widget classes.

Joshy

Code: Select all

#include once "fltk-c.bi"

' test of:
' WidgetExSetDestructorCB
' Fl_DeleteWidget
' Fl_WidgetWindow
' Fl_WidgetRedraw

sub DestructorCB cdecl (self as any ptr)
  print "DestructorCB"
  Fl_WidgetRedraw Fl_WidgetWindow(self) ' redraw the parent
end sub

sub ButtonCB cdecl (self as FL_WIDGET ptr)
  print "ButtonCB"
  Fl_DeleteWidget self
end sub
'
' main
'
var win = Fl_WindowNew(320,200)
var btn = Fl_ButtonExNew(10,10,128,24,"Delete me ...")
Fl_ButtonExSetDestructorCB btn,@DestructorCB
Fl_WidgetSetCallback0      btn,@ButtonCB
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 »

D.J.Peters wrote:Hello badidea and other Linux users,
I build a second fltk package fltk-c.tar.gz (for the download see first post)
These package will link to your current linux system libs libpng and libjpeg instead of fltk_png and fltk_jpeg.

Would be nice if you could give me feedback.

Joshy
bump
w_samsa
Posts: 19
Joined: Oct 12, 2011 9:44

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

Post by w_samsa »

Hi Joshy,
I tested the library using WIN XP and Lubuntu 13.04 and it works fine, even the static libs. I've used the .zip package.
I would ask you if there is a function to center a window. I just started to use the library and there is a lot of stuff to learn :)

Thanks
Walter
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 »

Hello Walter, and welcome to FLTK :-)

Joshy

Code: Select all

#include once "fltk-c.bi"

' test of:
' Fl_GetH()
' Fl_GetW()
' Fl_WindowNew2()

const WinWidth = 640
const WinHeight = 480
dim as Fl_Window ptr Win = Fl_WindowNew2(Fl_GetW()/2-WinWidth /2, _
                                         Fl_GetH()/2-WinHeight/2, _
                                         WinWidth,WinHeight,"Fl_WindowCentered.bas")
Fl_BoxNew 10,10,WinWidth-20,WinHeight-20,"Hello, World!"
Fl_WindowShow Win
Fl_Run
from file "fltk-c.bi"

Code: Select all

' screen
declare function Fl_GetX() as integer
declare function Fl_GetY() as integer
declare function Fl_GetW() as integer
declare function Fl_GetH() as integer

declare function Fl_SceenX      alias "Fl_GetX" as integer
declare function Fl_SceenY      alias "Fl_GetX" as integer
declare function Fl_SceenWidth  alias "Fl_GetW" as integer
declare function Fl_SceenHeight alias "Fl_GetH" as integer
w_samsa
Posts: 19
Joined: Oct 12, 2011 9:44

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

Post by w_samsa »

Thank you very much. Now I'm learning how to retrive window position and size.

Walter
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 »

Fl_WidgetGetX(win), Fl_WidgetGetY(win), Fl_WidgetGetW(win), Fl_WidgetGetH(win),
Rens
Posts: 256
Joined: Jul 06, 2005 21:09

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

Post by Rens »

D.J.Peters wrote:
D.J.Peters wrote:Hello badidea and other Linux users,
I build a second fltk package fltk-c.tar.gz (for the download see first post)
These package will link to your current linux system libs libpng and libjpeg instead of fltk_png and fltk_jpeg.

Would be nice if you could give me feedback.

Joshy
bump
Some feedback:
On Linux copy or move the dynamic lib in usr/lib
cd fltk-c
su -c "cp *.so /usr/lib"
First of all there are no *.so files in the directory fltk-c after extracting fltk-c.tar.gz
Bad luck, so i tried to compile (without them) a basic file with geany on linux lite

I got this error:

./libfltk-c-1-3-2.so: undefined reference to `png_set_longjmp_fn'

Note: I got this error on trying to compile any fltk sample basic files?!

With other programs, for example image viewer, i can load and see png files.

I have tried many things, like installing any lib with a name png in it. Googled to find a solution to this error. Copied libpng*.so from fltk-c to /usr/lib and to /lib and *.a files to /usr/local/lib/freebasic. I got more and more errors. :(

Maybe the solution is to recompile it on my system but in the directory src there are only files about zlib and some headers. Where can i find all the needed files?
And how to compile? Should i install fltk from the repositry of Linux?

I will greatly appreciate your help for finding a solution to this one.
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 »

Rens wrote:First of all there are no *.so files in the directory fltk-c after extracting fltk-c.tar.gz
Sorry for the trouble but this can't be true.
If I download and extract the fltk-c.tar.gz archive i get the file "libfltk-c-1-3-2.so" from 01/14/2014 ?!?

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 »

The key for drawing inside a FL_Window is Fl_WindowMakeCurrent()

Joshy

Code: Select all

#include once "fltk-c.bi"

'test of:
' Fl_WindowMakeCurrent() (http://www.fltk.org/doc-1.3/classFl__Window.html#a65a2499309b3fdd1bed463cefa0cd1e2)

sub ButtonCallback cdecl (btn as FL_WIDGET ptr, pUserData as any ptr)
  static as integer gfxPrimitive=0
  ' get the parent window of the button widget
  dim as Fl_Window ptr win = Fl_WidgetWindow(btn)
  ' get dimension of the window
  dim as integer x,y,w =Fl_WidgetGetW(win)
  dim as integer r,h =Fl_WidgetGetH(win)
  ' select the window as curent drawing target
  Fl_WindowMakeCurrent win
  ' from here you can use any DrawXYZ commands
  ' there are more take a look at "fltk-c.bi"
  DrawRectFill 0,0,w,h
  for i as integer = 1 to 1000
    DrawSetRGBColor rnd*255,rnd*255,rnd*255
    select case gfxPrimitive
    case 0 : DrawPoint rnd*w,rnd*h
    case 1 : DrawLine  rnd*w,rnd*h, rnd*w,rnd*h
    case 2 : DrawRect  rnd*w,rnd*h, rnd*w,rnd*h
    case 3 : r=rnd*h/2:DrawArc   rnd*w,rnd*h, r,r, 0,360 ' circle
    case 4 : DrawRectFill rnd*w,rnd*h, rnd*w,rnd*h
    case 5 : DrawBox cast(FL_Boxtype,1+rnd*FL_FREE_BOXTYPE), rnd*w,rnd*h, rnd*w,rnd*h, Fl_RGB_Color(rnd*255,rnd*255,rnd*255)
    case 6 : DrawArc   rnd*w,rnd*h, rnd*w,rnd*h, 0,360 ' oval
    end select
  next
  gfxPrimitive=(gfxPrimitive+1) mod 7
end sub
'
' main
'
dim as Fl_Window ptr win = Fl_WindowNew(640,480,"drawing03")
dim as FL_BUTTON ptr Btn = Fl_ButtonNew(10,10,64,24,"draw")
Fl_WidgetSetCallback Btn,@ButtonCallback

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 »

If you need continuous drawing like for games/simulation/videoplayback/opengl or what ever
don't enter the event loop with Fl_Run() use Fl_Wait2() instead.

Joshy

Code: Select all

#include once "fltk-c.bi"

'test of:
' Fl_WindowShown()
' Fl_WindowMakeCurrent()
' Fl_Wait2()

sub DrawMe(win as Fl_Window ptr)
  static as integer gfxPrimitive=0
  ' get dimension of the window
  dim as integer x,y,w =Fl_WidgetGetW(win)
  dim as integer r,h =Fl_WidgetGetH(win)
  ' select the window as curent drawing target
  Fl_WindowMakeCurrent win
  ' from here you can use any DrawXYZ commands take a look at "fltk-c.bi"
  DrawRectFillColor 0,0,w,h,FL_WHITE
  for i as integer = 1 to 100
    DrawSetRGBColor rnd*255,rnd*255,rnd*255
    select case gfxPrimitive
    case 0 : DrawPoint rnd*w,rnd*h
    case 1 : DrawLine  rnd*w,rnd*h, rnd*w,rnd*h
    case 2 : DrawRect  rnd*w,rnd*h, rnd*w,rnd*h
    case 3 : r=rnd*h/2:DrawArc   rnd*w,rnd*h, r,r, 0,360 ' circle
    case 4 : DrawRectFill rnd*w,rnd*h, rnd*w,rnd*h
    case 5 : DrawBox cast(FL_Boxtype,1+rnd*FL_FREE_BOXTYPE), rnd*w,rnd*h, rnd*w,rnd*h, Fl_RGB_Color(rnd*255,rnd*255,rnd*255)
    case 6 : DrawArc   rnd*w,rnd*h, rnd*w,rnd*h, 0,360 ' oval
    end select
  next
  gfxPrimitive=(gfxPrimitive+1) mod 7
end sub
'
' main
'
dim as Fl_Window ptr win = Fl_WindowNew(640,480,"drawing04")
Fl_WindowShow win

while Fl_WindowShown(win)
  ' wait for any event with a timeout value
  dim as double t = Fl_Wait2(0.05)
  DrawMe win
wend
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

great job as usual.

this library is excellent but not obvious to use in freebasic. documentation is insufficient ...

in this example nothing is displayed. why :

Code: Select all

#include once "fltk-c.bi"

dim as Fl_Window ptr win = Fl_WindowNew(350,120,"Test")
Fl_BoxNew(10,10,340,20,"Compteur")
Fl_WindowShow win

Dim As Double i
Dim As String tmp

while Fl_WindowShown(win)
	' wait for any event with a timeout value
	dim as double t = Fl_Wait2(0.05)	
	Fl_WindowMakeCurrent win
	For i=1 To 1000
		tmp=Str(i)		
		Fl_BoxNew(10,40,340,40,tmp)
	Next i
wend
End
Post Reply