FLTK-C-1.3.3 for FreeBASIC

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Coolman
Posts: 207
Joined: Nov 05, 2010 15:09

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby Coolman » Mar 11, 2019 20:29

test under linux 64 based on ubuntu. all examples work. great job.
oyster
Posts: 182
Joined: Oct 11, 2005 10:46

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby oyster » Mar 29, 2019 1:08

long time no see D. J. Peters. is he busy coding the oop interface?
FreeBasic+FLTK
Posts: 5
Joined: Mar 31, 2019 20:04

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby FreeBasic+FLTK » Mar 31, 2019 20:38

Hello,
I've a question regarding the redrawing of the FLTK menu bar. With invoking the sub below only the textsize of the submenus increases automatically, but not not of the main menu bar. In C++ there one needs to code "menu->redraw()" (*). What is the FreeBasic Code for that?
(* according to https://fltk.easysw.narkive.com/RBRol6S ... at-runtime) .

Many thanks!
AB
I'm quite new to FLTK (and GUI programming in general) and I'm not a native speaker of English.

sub IncreaseSizeCB cdecl (byval self as FL_Widget ptr, byval userdata as any ptr)
Fl_Menu_SetTextSize(mnb, Fl_Menu_GetTextSize(mnb)+1)
end sub
jdebord
Posts: 511
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby jdebord » Apr 01, 2019 7:01

You may try Fl_Redraw (Redraws all widgets) or Fl_WidgetRedraw(mnb) (Redraws a specific widget)
FreeBasic+FLTK
Posts: 5
Joined: Mar 31, 2019 20:04

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby FreeBasic+FLTK » Apr 05, 2019 21:26

Thank you, that works. Some other questions:
1) Is there a download for fltk-c-1.3.3-static.zip ?
2) Closing a window with the x-button isn't the same as quitting the program via menu (in some occasions it doesn't completely close the application).
What does the x-button trigger?

Thanks
A.B.
D.J.Peters
Posts: 7690
Joined: May 28, 2005 3:28

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby D.J.Peters » Apr 06, 2019 21:44

FreeBasic+FLTK wrote:Closing a window with the x-button isn't the same as quitting the program via menu (in some occasions it doesn't completely close the application). What does the x-button trigger?

If you not a robot take a look at:
file: "Fl_WindowCallback01.bas"

Code: Select all

#include once "fltk-c.bi"

sub WindowCB cdecl (byval self as FL_WIDGET ptr)
  Fl_WindowHide Fl_WidgetAsWindow(self)
  print "window closed !"
  beep:sleep 1000
end sub
'
' main
'
var Win = Fl_WindowNew(320,200)
Fl_WidgetSetCallback0 Win, @WindowCB
Fl_WindowShow Win
Fl_Run

and "Fl_WindowCallback02.bas"

Code: Select all

#include once "fltk-c.bi"

sub WindowCB cdecl (byval self as FL_WIDGET ptr)
  if ((Fl_EventNumber()=FL_EVENT_SHORTCUT) andalso (Fl_EventKey()=FL_Escape)) then
    return ' ignore Escape
  end if
  beep
  Fl_WindowHide Fl_WidgetAsWindow(self)
end sub
'
' main
'
var Win = Fl_WindowNew(320,200)
Fl_WidgetSetCallback0 Win, @WindowCB
Fl_WindowShow Win
Fl_Run
badidea
Posts: 1385
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby badidea » Apr 08, 2019 21:56

dkr wrote: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
...

I was playing a bit with FLTK today, and I found that you can also make a "Fl_Menu_FindItemByIndex" by "pointer hack":

Code: Select all

'A drop-down (or choice) menu 
dim as Fl_Choice ptr pChoice = Fl_ChoiceNew ( 10, 10, 200, 25 )
Fl_Menu_Add ( pChoice, "bla1" )
Fl_Menu_Add ( pChoice, "bla2" )
'...
Fl_Menu_ItemDeactivate ( Fl_Menu_GetMenu ( pChoice ) + index )

This may be unsafe, but I don't see another way to do this.

Edit: Maybe it is safe (as long as you don't go 'out-of-bounds'), menu can be filled with an array as well, see: https://www.fltk.org/doc-1.1/Fl_Menu_Item.html

Edit2: And this (ugly) thing gives you the menu size (minus menu terminator):

Code: Select all

print Fl_Menu_ItemSize ( Fl_Menu_GetMenu ( pChoice ) ) - 1
badidea
Posts: 1385
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby badidea » Apr 10, 2019 22:28

Just for fun, a small Resistor / voltage / current / power calculator. Prefixes to be done still.

Code: Select all

#include once "fltk-c-1.3.3/fltk-c.bi"

enum : E_R, E_U, E_I, E_P : end enum
const as integer NUM_PREFIX = 6

dim shared as Fl_Window ptr pWinMain
dim shared as Fl_Float_input ptr pValue(E_R to E_P)
dim shared as Fl_Choice ptr pChoUnit(E_R to E_P)
dim shared as Fl_Button ptr pButton(E_R to E_I)

sub setInputColors(flColor as Fl_COLOR)
   for i as integer = E_R to E_P
      Fl_Input_SetTextColor(pValue(i), flColor)
   next
   Fl_WidgetRedraw(pWinMain)
end sub

sub inputCallBack cdecl (byval pWidget as Fl_Widget ptr, byval userData as long)
   dim as double value = val(*Fl_Input_GetValue(*pWidget))
   if value <= 0 then
      value = 0
      Fl_Input_SetValue(*pWidget, "0")
   end if
   setInputColors(FL_RED) 'something changed set values invalid / red
end sub

sub unitCallBack cdecl (byval pWidget as Fl_Widget ptr, byval userData as long)
   'todo
end sub

sub buttonCallBack cdecl (byval pWidget as Fl_Widget ptr, byval userData as long)
   dim as double R, U, I, P
   select case userData 'switch on changed input
      case E_R
         U = val(*Fl_Input_GetValue(pValue(E_U)))
         I = val(*Fl_Input_GetValue(pValue(E_I)))
         if I = 0 then R = 1e+99 else R = U / I
         Fl_Input_SetValue(pValue(E_R), str(R))
      case E_U
         R = val(*Fl_Input_GetValue(pValue(E_R)))
         I = val(*Fl_Input_GetValue(pValue(E_I)))
         U = I * R
         Fl_Input_SetValue(pValue(E_U), str(U))
      case E_I
         R = val(*Fl_Input_GetValue(pValue(E_R)))
         U = val(*Fl_Input_GetValue(pValue(E_U)))
         if R = 0 then I = 1e+99 else I = U / R
         Fl_Input_SetValue(pValue(E_I), str(I))
      case else
         print "buttonCallBack: Unknown case"
   end select
   P = U * I
   Fl_Input_SetValue(pValue(E_P), str(P))
   setInputColors(Fl_BLACK) 'set value valid / black again
end sub

dim as string label(E_R to E_P) = {"Resistance:", "Voltage:", "Current:", "Power:"}
dim as string unit(E_R to E_P) = {"Ω", "V", "A", "W"}
dim as string prefix(NUM_PREFIX-1) = {"n", "μ", "m", "", "k", "M"}

'Set up the GUI
pWinMain = Fl_WindowNew(520, 190, "Resistor Calculator / badidea / 2019-04-08")
for i as integer = E_R to E_P
   dim as integer y = 20 + 40 * i
   'set up value input and label
   pValue(i) = Fl_Float_InputNew(140, y, 160, 30, label(i))
   Fl_WidgetSetCallback1Arg(pValue(i), @inputCallBack, i)
   Fl_Input_SetTextSize(pValue(i), 20)
   Fl_WidgetSetLabelSize(pValue(i), 20)
   Fl_Input_SetMaximumSize(pValue(i), 10)
   Fl_Input_SetValue(pValue(i), "1")
   if i = E_P then Fl_Input_SetReadonly(pValue(i), FL_INPUT_READONLY)
   'set up unit selector
   pChoUnit(i) = Fl_ChoiceNew(310, y, 80, 30)
   for j as integer = 0 to NUM_PREFIX-1
      Fl_Menu_Add(pChoUnit(i), prefix(j) + unit(i))
      'A bit ugly but works, get menu by index
      if j <> 3 then Fl_Menu_ItemDeactivate(Fl_Menu_GetMenu(pChoUnit(i)) + j)
   next
   'print Fl_Menu_ItemSize ( Fl_Menu_GetMenu ( pChoUnit ( i ) ) ) - 1
   Fl_Menu_SetTextSize(pChoUnit(i), 20)
   Fl_ChoiceSetValue(pChoUnit(i), 3) 'set with no prefix
   Fl_WidgetSetCallback1Arg(pChoUnit(i), @unitCallBack, i)
   'set up buttons
   if i <= E_I then 'skip power button
      pButton(i) = Fl_ButtonNew(400, y, 110, 30, "Calculate")
      Fl_WidgetSetLabelSize(pButton(i),20)
      Fl_WidgetSetCallback1Arg(pButton(i), @buttonCallBack, i)
   end if
next
Fl_WindowShow(pWinMain) 'Show or raise window
Fl_Run() 'Run until all windows are closed

Image
darwin4ever
Posts: 11
Joined: Feb 03, 2017 22:40

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby darwin4ever » Apr 18, 2019 13:20

Hi,

I have 2 questions :

1) Actually I have the following FB directory-structure :

    bin
    doc
    docs
    examples
    ext-bin
    inc
    lib

It seems the zip-file doesn't follow that structure.
Which files should I put where ?

2) I seems there is a newer 1.3.5 version at https://www.fltk.org/index.php

Can that version been used ?

Thanks
badidea
Posts: 1385
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby badidea » Apr 18, 2019 21:08

I have a "projects" folder for all my freebasic projects, inside it are a.o.:
* "fltk-c-1.3.3" with all the examples, media and stuff. For quick FLTK tests, I use this folder.
* Projects that use FLTK. Here I just put a stripped version of FLTK (only essentials, ~10 files) in a sub-folder, again called "fltk-c-1.3.3"
So:
/projects/fltk-c-1.3.3 (for testing FLTK)
/projects/FLTKproject1/fltk-c-1.3.3
/projects/FLTKproject2/fltk-c-1.3.3
Whenever I copy a project to another system, it always works (assuming FBC is installed).
darwin4ever
Posts: 11
Joined: Feb 03, 2017 22:40

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby darwin4ever » Apr 18, 2019 21:20

So you don't "merge" the (essential) files into the FreeBasic directory structure ?
Could you give a list of those "essentials" ?
badidea
Posts: 1385
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK C for FreeBASIC Jan 09, 2017

Postby badidea » Apr 18, 2019 21:29

darwin4ever wrote:So you don't "merge" the (essential) files into the FreeBasic directory structure ?
I don't.
darwin4ever wrote:Could you give a list of those "essentials" ?
For Windows & Linux:

fltk-c.bi
libfltk-c-1.3.3-32.dll.a
libfltk-c-1.3.3-64.dll.a
libXft.so.2.3.1
fltk-glut.bi
libfltk-c-1.3.3-32.so
libfltk-c-1.3.3-64.so
fltk-tools.bi
libfltk-c-1.3.3-32-syslib.so
libfltk-c-1.3.3-64-syslib.so


Maybe I should have added the license file and or documentation. Need to check this...
FreeBasic+FLTK
Posts: 5
Joined: Mar 31, 2019 20:04

Linker error Codeblocks/MinGW+FLTK-C

Postby FreeBasic+FLTK » Apr 27, 2019 20:30

Hello, I've tried to build the fltk-c dll library with code::blocks (up-to-date mingw 32bit, Windows 10). The fltc-1.3.3 library was bulit without error (but many warnings), but the fltk-c library creation was aborted after
||=== Build: win32 in fltk-c-wrapper-1.3.3-dynamic (compiler: GNU GCC Compiler) ===|
...
d:\mingw\bin\..\lib\gcc\mingw32\8.2.0\..\..\..\..\mingw32\bin\ld.exe: ..\fltk-1.3.3\lib\win32\libfltk.a(Fl.o):Fl.cxx|| undefined reference to `__WSAFDIsSet@8'|
d:\mingw\bin\..\lib\gcc\mingw32\8.2.0\..\..\..\..\mingw32\bin\ld.exe: ..\fltk-1.3.3\lib\win32\libfltk.a(Fl.o):Fl.cxx|| undefined reference to `__WSAFDIsSet@8'|
d:\mingw\bin\..\lib\gcc\mingw32\8.2.0\..\..\..\..\mingw32\bin\ld.exe: ..\fltk-1.3.3\lib\win32\libfltk.a(Fl.o):Fl.cxx|| undefined reference to `__WSAFDIsSet@8'|
||error: ld returned 1 exit status|
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 35 second(s)) ===|

__WSAFDIsSet@8 seems to be a Windows issue
FreeBasic+FLTK
Posts: 5
Joined: Mar 31, 2019 20:04

FLTK

Postby FreeBasic+FLTK » May 05, 2019 13:03

The solution for this problem is:
In the main menu go "Settings->Compiler" and then in the new window in the folder "Linker Settings" add the libraries (<MinGW-path>\lib\libws2_32.a and <MinGW-path>\lib\libwinmm.a

Another problem was that when I created the dll-library fltk-c-1.3.3-32.dll that there was no link library (*.dll.a) created and fbc couldn't link it.
The soltion for that was that one has to use alias name for the functions and subs of the C-library in the Freebasic function and sub declarations.
So in "fltk-main.bi" one has to write
declare function Fl_WindowNew alias "Fl_WindowNew" (byval w as long, byval h as long, byval title as const zstring ptr=0) as Fl_Window ptr
instead of:
declare function Fl_WindowNew (byval w as long, byval h as long, byval title as const zstring ptr=0) as Fl_Window ptr
With this one doesn't need the ftlk*.dll.a library anymore.

Another problem was when I wanted to use fltk-1.3.5. Then there was a problem with the FL_ABI_VERSION. My work-around was to insert two new lines in Enumertions.H
#ifdef FLTK_ABI_VERSION
#undef FLTK_ABI_VERSION
#endif
#undef FL_ABI_VERSION // new
#define FL_ABI_VERSION 10305 //-new
#define FLTK_ABI_VERSION FL_ABI_VERSION

And there was a problem with glut. In the .h file there was (char*) in some function header, it had to be changed to const char*
FreeBasic+FLTK
Posts: 5
Joined: Mar 31, 2019 20:04

Re: FLTK C for FreeBASIC

Postby FreeBasic+FLTK » May 05, 2019 13:18

I've added some new functions and sub (new in fltk-1.3.4/5)

Code: Select all

function Fl_WidgetIsLabelCopied alias "Fl_WidgetIsLabelCopied" (byval wgt as Fl_Widget ptr) as long
function Fl_AbiVersion alias "Fl_AbiVersion" () as long
sub Fl_Shared_ImageScale alias "Fl_Shared_ImageScale" (byval si as Fl_Shared_Image ptr, byval w as long, byval h as long, byval prop as long=1, byval can_expand as long=0)
sub Fl_Copy_SurfaceDrawDecoratedWindow alias "Fl_Copy_SurfaceDrawDecoratedWindow" (byval cs as Fl_Copy_Surface ptr, byval win as Fl_Window ptr, byval delta_x as long=0, byval delta_y as long=0)
function Fl_Copy_SurfaceGetW alias "Fl_Copy_SurfaceGetW" (byval cs as Fl_Copy_Surface ptr) as long
Fl_Copy_SurfaceGetH alias "Fl_Copy_SurfaceGetH" (byval cs as Fl_Copy_Surface ptr) as long
Fl_ImageFail alias "Fl_ImageFail" (byval img as Fl_Image ptr) as long

(Used long since in win32 "integer" is the same, for win64 one should perhaps use integer)

Does anybody know of broken code in fltk-1.3.5?

At those who have written FLTK-C for FreeBasic: How about publishing it in GitHub? (The main project (FLTK) is there, too.)

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 3 guests