FLTK 1.3.x C Wrapper (obsolete)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
jdebord
Posts: 525
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby jdebord » May 23, 2015 7:34

There seems to be a bug with the function Fl_Color_ChooserHue : it returns a constant value instead of the correct hue.

Here is a modification of the demo program Fl_Color_Chooser01.bas which shows the problem (sub ChooserCB1)

For a workaround, get the RGB values and convert to HSV with Fl_Color_ChooserRGB2HSV (sub ChooserCB2)

Code: Select all

#include once "fltk-c.bi"

sub ChooserCB cdecl (byval self as Fl_Widget ptr,byval cc as any ptr)
  dim as ubyte r = Fl_Color_ChooserR(cc)* 255
  dim as ubyte g = Fl_Color_ChooserG(cc)* 255
  dim as ubyte b = Fl_Color_ChooserB(cc)* 255
  print "ChooserCB (RGB): " & r & "," & g & "," & b
end sub

sub ChooserCB1 cdecl (byval self as Fl_Widget ptr,byval cc as any ptr)
  dim as double h = Fl_Color_ChooserHue(cc)
  dim as double s = Fl_Color_ChooserSaturation(cc)
  dim as double v = Fl_Color_ChooserValue(cc)
  print "ChooserCB1 (HSV): " & h & "," & s & "," & v
end sub

sub ChooserCB2 cdecl (byval self as Fl_Widget ptr,byval cc as any ptr)
  dim as double r = Fl_Color_ChooserR(cc)
  dim as double g = Fl_Color_ChooserG(cc)
  dim as double b = Fl_Color_ChooserB(cc)
  dim as double h, s, v
  Fl_Color_ChooserRGB2HSV cc, r, g, b, h, s, v
  print "ChooserCB2 (HSV): " & h & "," & s & "," & v
end sub

'
' main
'
var win = Fl_WindowNew(320,240, "Fl_Color_Chooser")
var cc  = Fl_Color_ChooserNew(10,10,Fl_WidgetGetW(win)-20,Fl_WidgetGetH(win)-20)

' Fl_WidgetSetCallbackArg cc,@ChooserCB, cc   ' R, G, B correct
Fl_WidgetSetCallbackArg cc,@ChooserCB1, cc  ' H wrong, S and V correct
' Fl_WidgetSetCallbackArg cc,@ChooserCB2, cc  ' H, S, V correct


' init via RGB (double) 0-1
Fl_Color_ChooserRGB cc,0.75,0.5,0.0
' set byte mode 0-255
Fl_Color_ChooserSetMode cc,FL_COLORCHOOSER_BYTE
Fl_WindowShow win
Fl_Run
D.J.Peters
Posts: 7941
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » May 23, 2015 9:44

@jdebord good find !
You are right Fl_Color_ChooserHue(cc) returns curently cc.h()
and cc.h() is the in C++ the hight of the ColorChooser widget :-)

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

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » May 23, 2015 12:04

@jdebord It's fixed now.

Joshy
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby tinycla » May 23, 2015 18:51

I have a question. I have searched for a way to make a multi-window program, but didn't find any examples showing how to do this. I mean a program where when the user push a button or select a menu item, a new window is shown with its widgets. Anybody can tell me how to do?
ike
Posts: 383
Joined: Jan 17, 2011 18:59

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby ike » May 23, 2015 20:20

Some stupid example where I was testing MODAL, NONMODAL windows, and full screen ON/OFF

Press first button to show a window, then press second button couple of times - to random move it

Then try 3. and 4. button on main screen


Code: Select all


#include once "fltk-c.bi"

dim shared as FL_WINDOW ptr win1, win2, win3, win4

sub BUTTON1Clicked cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
  if Fl_WindowShown(win2) = 1 then
   Fl_WindowHide Win2
  else
   Fl_WindowShow Win2
  endif
end sub

sub BUTTON2Clicked cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
   Fl_WindowResize(win2, rnd*350, rnd*350, 150,150)
   Fl_WindowSetLabel (win2, "Abcdefgh...")
   print *Fl_WindowGetLabel (win2)
   print Fl_WindowXRoot (win2)
   print Fl_WindowYRoot (win2)
   
end sub
sub BUTTON3Clicked cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
  Fl_WindowShow Win1
end sub
sub BUTTON4Clicked cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
  Fl_WindowShow Win3
end sub

sub BUTTON5Clicked cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
  Fl_WindowHide Win1
end sub

sub BUTTON6Clicked cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
  Fl_WindowHide Win3 'close
end sub

sub BUTTON7Clicked cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
  Fl_WindowFullscreenOff(win3)
end sub


sub BUTTON8Clicked cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
  Fl_WindowFullscreen(win3)
end sub
''''''''''''''''''''''''''''''''''''''''''''

dim as FL_WINDOW ptr Win    = Fl_WindowNew(400, 300, "Windows")

dim as FL_BUTTON ptr Button1 = Fl_ButtonNew(10,10,200,30,"Show-Hide NonModal")
Fl_WidgetSetCallback Button1, @BUTTON1Clicked

dim as FL_BUTTON ptr Button2 = Fl_ButtonNew(10,50,200,30,"RandomMove")
Fl_WidgetSetCallback Button2, @BUTTON2Clicked

dim as FL_BUTTON ptr Button3 = Fl_ButtonNew(10,90,200,30,"Show Modal")
Fl_WidgetSetCallback Button3, @BUTTON3Clicked

dim as FL_BUTTON ptr Button4 = Fl_ButtonNew(10,130,200,30,"FullScreen")
Fl_WidgetSetCallback Button4, @BUTTON4Clicked

Win1 = Fl_WindowNew(300, 200, "win1")
dim as FL_BUTTON ptr Button5 = Fl_ButtonNew(10,10,200,30,"Close")
Fl_WidgetSetCallback Button5, @BUTTON5Clicked

Win2 = Fl_WindowNew(300, 500, "win2"): Fl_GroupSetResizable(win2,win2)

Win3 = Fl_WindowNew(300, 200, "win3")

Fl_WindowBegin(win3)
dim as FL_BUTTON ptr Button6 = Fl_ButtonNew(10,10,200,30,"Close")
Fl_WidgetSetCallback Button6, @BUTTON6Clicked
dim as FL_BUTTON ptr Button7 = Fl_ButtonNew(10,50,200,30,"FullScreenOff")
Fl_WidgetSetCallback Button7, @BUTTON7Clicked
dim as FL_BUTTON ptr Button8 = Fl_ButtonNew(10,90,200,30,"FullScreenOn")
Fl_WidgetSetCallback Button8, @BUTTON8Clicked
Fl_WindowEnd(win3)

'Fl_WindowClearBorder (win1)

'Fl_WindowSetMenuWindow (win1)

Fl_WindowSetModal (win1)

Fl_WindowShow Win
Fl_Run

D.J.Peters
Posts: 7941
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » May 23, 2015 20:46

I love FLTK it's so simple
(after a short learning curve)

Code: Select all

#include once "fltk-c.bi"

sub ButtonCB cdecl (byval self as Fl_Widget ptr)
  var win = Fl_WindowNew2(rnd*(Fl_GetW()-320),rnd*(Fl_GetH()-240),320,240,"window")
  var btn = Fl_ButtonNew(19,10,80,24,"new window")
  Fl_WidgetSetCallback0 btn,@ButtonCB
  Fl_WindowShow win
end sub
'
' main
'
ButtonCB 0
Fl_Run
NOTE:
A FLTK button callback is a FreeBASIC cdecl method not more nor less.
So you can call a callback self.

I call ButtonCB manualy to create the first window with a button and bring it on the desktop.
After you press the button the ButtonCB is fired up and a one more window are created
and so on ...

Joshy
Lothar Schirm
Posts: 333
Joined: Sep 28, 2013 15:08
Location: Bavaria, Germany

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby Lothar Schirm » May 25, 2015 14:49

I want to write a little program - a picture viewer. The download package includes two examples (Fl_Image01.bas and Fl_image02.bas) sjowing how to load a picture from a file into a box. In these examples, the pictures in the files have the size (width and height) of the box. How can I fit the size of a picture into the size of the box if the picture is too large? Has FLTK the possibility to evaluate the dimensions of a picture loaded from a file and to change its dimensions?
D.J.Peters
Posts: 7941
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » May 25, 2015 20:01

@Lothar you can find the answer in "Fl_Shared_Image04.bas".

Online docu: Fl_Shared_ImageCopy2()

Joshy

Code: Select all

' The copy2() method creates a copy of the specified image and rescale it.
declare function Fl_Shared_ImageCopy2(byval si as Fl_Shared_Image ptr,byval w as long,byval h as long) as Fl_Image ptr
Lothar Schirm
Posts: 333
Joined: Sep 28, 2013 15:08
Location: Bavaria, Germany

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby Lothar Schirm » May 26, 2015 8:20

Thank you, works well. This is the result:

Code: Select all

'===============================================================================
' PictureViewer.bas
' Erstellt am 26.05.2015
'===============================================================================

#Include Once "fltk-c.bi"

Dim Shared As Fl_Box Ptr Box_Image


Sub Oeffnen Cdecl (widget As Fl_Widget Ptr, userdata As Any Ptr)
   'Neue Bild-Datei öffnen
   
   Dim As ZString Ptr file
   Dim As Long w, h
   Dim As Single Faktor1, Faktor2
   
   Fl_Register_Images()
   file = flFileChooser("Datei öffnen", _
                                    "*.bmp" + Chr(9) + "*.gif" + Chr(9) + "*.png" + Chr(9) + "*.jpg", _
                                    "C:\Users", 0)
   If file <> 0 Then
      Var img = Fl_Shared_ImageGet(*file)
      w = Fl_ImageGetWidth(img)
      h = Fl_ImageGetHeight(img)
      Faktor1 = 640 / w
    Faktor2 = 480 / h
    If Faktor2 <= Faktor1 Then
         Fl_WidgetSetImage(Box_Image, Fl_Shared_ImageCopy2(img, w * Faktor2, h * Faktor2))
    Else
         Fl_WidgetSetImage(Box_Image, Fl_Shared_ImageCopy2(img, w * Faktor1, h * Faktor1))
    End If
      Fl_WidgetRedraw(Box_Image)
   End If
   
End Sub


Sub Beenden Cdecl (widget As Fl_Widget Ptr, userdata As Any Ptr)
   'Programm beenden
   
   End
   
End Sub


'Hauptprogramm:

Var Window_Main = Fl_WindowNew   (640, 500, "PictureViewer")
Var   Menu = Fl_Menu_BarNew            (0, 0, 640, 20)
Fl_Menu_Add(Menu, "Datei/Öffnen",,@Oeffnen())
Fl_Menu_Add(Menu, "Datei/Beenden",,@Beenden())
Box_Image = Fl_BoxNew                  (0, 20, 640, 480)
         
Fl_WindowShow(Window_Main)
Fl_Run

End


(Last edited at 16:00)
D.J.Peters
Posts: 7941
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » May 27, 2015 8:54

Lothar Schirm wrote:Thank you, works well. This is the result
good to know :-)

some hints:

Don't use END exit the fltk message loop instead.
You can use for the exit menu item and window exit callback the same sub.
There is no need for any shared var in fltk you can use the "user param" of a callback instead.
Take a look how you can define some image formats for the flFileChooser dialog.
If you use a scaled copy of the loaded image you have to release the shared original image.
(the release method decrements the reference counter of the loaded image and if no widget used this image referencecounter=0 then FLTK deted the image)

Joshy

Code: Select all

' PictureViewer.bas
#Include Once "fltk-c.bi"

sub OpenCB cdecl (byval wgt as Fl_Widget ptr,byval box as any ptr)
  'dim as Fl_Box ptr box = userdata
  var file = flFileChooser("Load image ...","Image Files (*.{gif,jpg,jpeg,bmp,png,tif})","./media", 0)
  If file = 0 Then return

  var img = Fl_Shared_ImageGet(*file)
  if img = 0 then return

  ' box area
  var BoxW = Fl_WidgetGetW(box)
  var BoxH = Fl_WidgetGetH(box)

  ' image area
  var ImgW = Fl_ImageGetWidth(img)
  var ImgH = Fl_ImageGetHeight(img)

  if ImgW>BoxW then
    ImgH*=BoxW/ImgW
    ImgW=BoxW
  elseif ImgW<BoxW then
    ImgH*=BoxW/ImgW
    ImgW=BoxW
  end if

  if ImgH>BoxH then
    ImgW*=BoxH/ImgH
    ImgH=BoxH
  elseif ImgH<BoxH then
    ImgW*=BoxH/ImgH
    ImgH=BoxH
  end if

  Fl_WidgetSetImage Box, Fl_Shared_ImageCopy2(img, ImgW, ImgH)
  ' we use a new copy so realese the original image
  Fl_Shared_ImageRelease img
  ' redraw the window
  Fl_WidgetRedraw Fl_WidgetWindow(Box)
end sub

sub ExitCB Cdecl (byval wgt as Fl_Widget Ptr,byval win as any ptr)
  ' exit the message loop
  Fl_WindowHide win
end sub

'
' main
'
Fl_Register_Images()

var Win = Fl_WindowNew  (640, 500, "PictureViewer")
var Mnu = Fl_Menu_BarNew(0, 0,Fl_WidgetGetW(win), 24)
var Box = Fl_BoxNew     (0,24,Fl_WidgetGetW(win),Fl_WidgetGetH(win)-24)
Fl_Menu_Add Mnu,"File/Open ...",,@OpenCB, Box
Fl_Menu_Add Mnu,"File/Exit"    ,,@ExitCB, Win
Fl_WidgetSetCallbackArg win     ,@ExitCB, Win
Fl_WindowShow Win

Fl_Run
ike
Posts: 383
Joined: Jan 17, 2011 18:59

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby ike » May 29, 2015 4:14

https://www.youtube.com/watch?v=Sa2KSwFufiE

Very basic form designer for FLTK

viewtopic.php?f=8&t=23621

It helped me to create more than 150 forms, and also I use it if I have to edit them
badidea
Posts: 1779
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby badidea » May 31, 2015 16:35

I'm trying to get FLTK working on under Ubuntu 14.04 64-bit with a 32-bit Freebasic 1.00.0 installation.

Without #define syslib I get:

ld: warning: libXft.so.2, needed by ./libfltk-c-1.3.3-32.so, not found (try using -rpath or -rpath-link)
I located an libXft.so.2 in /usr/lib/x86_64-linux-gnu/

With #define syslib I get:

ld: cannot find -lpng
ld: cannot find -ljpeg
ld: cannot find -lzlib

Any ideas how I can get FLTK working here?

Edit: Fixed now, had to install the 32-bit library: libxft2:i386

Edit2: Note: Fl_ButtonEx03.bas has window title ButtonEx02
jdebord
Posts: 525
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby jdebord » Jun 03, 2015 9:16

A calculator made with FreeBASIC and FLTK:

Image

There are 3 files:

http://sourceforge.net/p/fbmath/code/HEAD/tree/FLTK/calc/fbeval.bas
http://sourceforge.net/p/fbmath/code/HEAD/tree/FLTK/calc/fbeval.bi
http://sourceforge.net/p/fbmath/code/HEAD/tree/FLTK/calc/calc.bas

1. Compile the shared library :

Code: Select all

fbc fbeval.bas -dll


2. Compile the main program:

Code: Select all

fbc calc.bas -s gui
D.J.Peters
Posts: 7941
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jun 03, 2015 17:46

Good job i like the calculator.

Joshy
ike
Posts: 383
Joined: Jan 17, 2011 18:59

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby ike » Jun 05, 2015 13:12

why drawarc2 does not work here. Thx

Code: Select all


#include once "fltk-c.bi"

namespace T
DIM SHARED AS Fl_BoxEx PTR box1
DIM AS Fl_Window PTR win
end namespace
'#############################################################
FUNCTION DrawCB1 CDECL(box AS ANY PTR) AS INTEGER
dim as integer x1 = Fl_WidgetGetX(T.box1)
dim as integer y1 = Fl_WidgetGetY(T.box1)
dim as integer w = Fl_WidgetGetW(T.box1)
dim as integer h = Fl_WidgetGetH(T.box1)
dim as integer i

drawpushclip(x1,y1,w,h)

DrawSetColor FL_WHITE
DrawRectFill x1,y1,w,h


DrawSetColor FL_BLUE
DrawLine (10, 10, 1150, 1150)

DrawSetColor FL_RED
DrawArc x1 + 100, y1 + 100, 100, 200, 0, 360

' why this is not drawn,
DrawSetColor FL_MAGENTA
DrawArc2 x1 + 100, y1 + 100, 120, 0, 360

DrawSetColor FL_GREEN
DrawCircle x1 + 100, y1 + 100, 110

drawpopclip()

RETURN 1
END FUNCTION

'marker01
'#############################################################
SUB FormTCREATE()
IF T.win THEN RETURN
DIM AS INTEGER xx,yy,ww,hh
Fl_ScreenWorkAreaXYWH xx, yy, ww, hh
T.win = Fl_Double_windowExNew2((ww-1000)/2, (hh-800)/2, 1000, 800, "Form Caption")
Fl_WindowSetModal (T.win)
T.box1 = Fl_BoxExNew(270, 20, 680, 580, "T")
Fl_BoxExSetDrawCB T.box1, @DrawCB1

'marker00
Fl_GroupEnd T.win
END SUB


SUB FormTSHOW()
Fl_WindowShow T.win
END SUB


FormTCREATE
FormTSHOW
Fl_Run


Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 2 guests