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
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by D.J.Peters »

I found this option 'FL_OPTION_DND_TEXT' :-)

disable text drag and drop operation Fl_SetOption(FL_OPTION_DND_TEXT, 0)
enable text drag and drop operation Fl_SetOption(FL_OPTION_DND_TEXT, 1)

Joshy

Code: Select all

sub ModifyCb cdecl (byval p           as long, _
                    byval nInserted   as long, _
                    byval nDeleted    as long, _
                    byval nRestyled   as long, _
                    byval deletedText as const zstring ptr, _
                    byval pUserdata   as any ptr)
Fl_SetOption(FL_OPTION_DND_TEXT,0)
  ' ...

Code: Select all

  ' ...
Fl_SetOption(FL_OPTION_DND_TEXT,1)   
end sub
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by D.J.Peters »

Do you know the situation where you test or debug stuff and comment out temporary code and forgot to remove the changes at end ?

I found the evil :-)

I'm sure this is from a test or debug session !

Joshy

Code: Select all

s = Fl_Text_BufferLineStart(TextBuffer,s)
  e = Fl_Text_BufferLength(TextBuffer)
  'e = Fl_Text_BufferLineEnd(TextBuffer,e)
and must be:

Code: Select all

  s = Fl_Text_BufferLineStart(TextBuffer,s)
  'e = Fl_Text_BufferLength(TextBuffer)
  e = Fl_Text_BufferLineEnd(TextBuffer,e)
VANYA
Posts: 1839
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by VANYA »

D.J.Peters wrote: Nov 05, 2022 5:59 Do you know the situation where you test or debug stuff and comment out temporary code and forgot to remove the changes at end ?
Of course
D.J.Peters wrote: Nov 05, 2022 5:59 Joshy

Code: Select all

s = Fl_Text_BufferLineStart(TextBuffer,s)
  e = Fl_Text_BufferLength(TextBuffer)
  'e = Fl_Text_BufferLineEnd(TextBuffer,e)
and must be:

Code: Select all

  s = Fl_Text_BufferLineStart(TextBuffer,s)
  'e = Fl_Text_BufferLength(TextBuffer)
  e = Fl_Text_BufferLineEnd(TextBuffer,e)
Yes, there is no more error in this option. Thank you!
will you update the archive?

But still, the question remains: is it possible to connect a callback to catch FL_DRAG , FL_RELEASE events, or is this not provided for with widgets? I just want to understand the capabilities of the library before taking it into action. You are an experienced person and have studied it, I think it will not be difficult for you to tell me?
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by D.J.Peters »

VANYA wrote: Nov 05, 2022 6:31But still, the question remains: is it possible to connect a callback to catch FL_DRAG , FL_RELEASE events, or is this not provided for with widgets?
First of all I'm not sure you have only execute all "Ex" widget test's or do you read the 'Ex' widget code also ?
And if you read about the Ex Widget do you know why the most widgets exist as "normal" like Fl_Button" and as a 'ex'tended version like: Fl_ButtonEx ?

Normaly all event stuff are handled by the fltk C++ classes but if you need to manipulate the events or doing your own widget drawing ... stuff you used the extended version of an widget.

In case of the Fl_Text_Editor widget you can use the extended version "Fl_Text_EditorEx"
var editor = Fl_Text_EditorEx(bla, bla, bla, bla)

then you set your own Event Handler Callback
Fl_Text_EditorExSetHandleCB(editor, @myEventHandler)

Inside your own myEventHandler() callback you can handle all kinds of events self.
All events you do not handle must be delegated back to the C++ parent class.
return Fl_Text_EditorExHandleBase(me, event)

or you rerturn "1" or "0" to signal the parent class to handle a event self.

Sounds complicated but it's for all extended widgets the same stuff.

So take a look to some of the 'Ex' tests and you will get it.

Joshy
Last edited by D.J.Peters on Nov 05, 2022 8:28, edited 1 time in total.
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by D.J.Peters »

The fun part are FreeBASIC can extends classes self so as an expert it's posiible to write classes like the good old from VB 6 (Visual Basics)

Don't worry it's an advanced OOP FreeBASIC example but hey we don't die stupid like Trump supporters :lol:

take a look at "function HandleCB cdecl(byval me as any ptr, byval event as Fl_Event) as long"

You will notice all events are optional for the FORM user and how to delegate unused events back to the parent C++ class.

But again you need only take a look at the simple WidgetEx examples shipped with fltk-c :-)

Joshy

By the way this code block would be the same for all other widget too and would be generated by a FORM designer.
But the FreeBASIC communtiy is to small to invest so much livetime in projects I have done all the last 17 years.

Today all BASIC like languages comes with a GUI and unicode/UTF support but the dev team of FreeBASIC thinks different.
A free open source BASIC with a standard GUI running on x86,x86_64,arm32,arm64,mac,windows,linux etc. would be game changer
and then a WEB backend for all kinds of smartphones and tablets would be a dream ;-)

Code: Select all

#include once "fltk-c.bi"

' advanced example

type FB_FORM extends Fl_Double_WindowEx
  public:
  declare destructor
  declare constructor(byval w as long,byval h as long,byval caption as zstring ptr=0)
  declare constructor(byval x as long,byval y as long,byval w as long,byval h as long,byval caption as zstring ptr=0)

  declare sub Show()

  ' user events (all optional)
  as function (byval frm as FB_FORM ptr) as long ShowEvent
  as function (byval frm as FB_FORM ptr) as long HideEvent
  as function (byval frm as FB_FORM ptr) as long CloseEvent
  as function (byval frm as FB_FORM ptr) as long FocusEvent
  as function (byval frm as FB_FORM ptr) as long UnfocusEvent
  as function (byval frm as FB_FORM ptr) as long EnterEvent
  as function (byval frm as FB_FORM ptr) as long LeaveEvent
  as function (byval frm as FB_FORM ptr) as long DrawEvent
  as function (byval frm as FB_FORM ptr, byval key as long) as long KeyDownEvent
  as function (byval frm as FB_FORM ptr, byval key as long) as long KeyUpEvent
  as function (byval frm as FB_FORM ptr, byval btn as long, byval x as long, byval y as long) as long ButtonPushEvent
  as function (byval frm as FB_FORM ptr, byval btn as long, byval x as long, byval y as long) as long ButtonReleaseEvent
  as function (byval frm as FB_FORM ptr, byval x   as long, byval y as long, byval w as long, byval h as long) as long ResizeEvent
  as function (byval frm as FB_FORM ptr, byval x   as long, byval y as long, byval z as long) as long MouseWheelEvent
  as function (byval frm as FB_FORM ptr, byval x   as long, byval y as long) as long MouseMoveEvent
  as function (byval frm as FB_FORM ptr, byval x   as long, byval y as long) as long MouseDragEvent

  private: ' FLTK stuff
  declare static sub      DestructorCB cdecl(byval me as any ptr)
  declare static function DrawCB       cdecl(byval me as any ptr) as long
  declare static function HandleCB     cdecl(byval me as any ptr, byval event as Fl_Event) as long
  declare static function ResizeCB     cdecl(byval me as any ptr, byval x as long, byval y as long, byval w as long, byval h as long) as long
  declare sub SetCallbacks
  as Fl_Double_WindowEx ptr m_Double_WindowEx
end type
' private form stuff
destructor FB_FORM
  if m_Double_WindowEx then Fl_Double_WindowExDelete m_Double_WindowEx
end destructor
constructor FB_FORM(byval w as long, byval h as long, byval caption as zstring ptr)
  m_Double_WindowEx = Fl_Double_WindowExNew(w,h,caption) : SetCallbacks
end constructor
constructor FB_FORM(byval x as long, byval y as long, byval w as long, byval h as long, byval caption as zstring ptr)
  m_Double_WindowEx = Fl_Double_WindowExNew2(x,y,w,h,caption) : SetCallbacks
end constructor

' public form stuff
sub FB_FORM.Show()
  Fl_WindowShow(m_Double_WindowEx)
end sub  

sub FB_FORM.SetCallbacks
  Fl_Double_WindowExSetDestructorCB(m_Double_WindowEx,@DestructorCB)
  Fl_Double_WindowExSetDrawCB      (m_Double_WindowEx,@DrawCB)
  Fl_Double_WindowExSetHandleCB    (m_Double_WindowEx,@HandleCB)
  Fl_Double_WindowExSetResizeCB    (m_Double_WindowEx,@ResizeCB)
  Fl_WidgetSetUserData             (m_Double_WindowEx,@This)
end sub

sub FB_FORM.DestructorCB cdecl(byval win as any ptr)
  print "FB_FORM.DestructorCB"
end sub

function FB_FORM.DrawCB cdecl(byval win as any ptr) as long
  print "FB_FORM.DrawCB"
  dim as FB_FORM ptr me = Fl_WidgetGetUserData(win)
  if me->DrawEvent then return me->DrawEvent(me)
  return 0
end function

function FB_FORM.HandleCB cdecl(byval win as any ptr,byval event as Fl_Event) as long
  print "FB_FORM.HandleCB"
  dim as FB_FORM ptr me = Fl_WidgetGetUserData(win)
  select case as const event
  case FL_EVENT_SHOW       : if me->ShowEvent          then return me->ShowEvent(me)
  case FL_EVENT_HIDE       : if me->HideEvent          then return me->HideEvent(me)
  case FL_EVENT_CLOSE      : if me->CloseEvent         then return me->CloseEvent(me)
  case FL_EVENT_FOCUS      : if me->FocusEvent         then return me->FocusEvent(me)
  case FL_EVENT_UNFOCUS    : if me->FocusEvent         then return me->UnfocusEvent(me)
  case FL_EVENT_ENTER      : if me->EnterEvent         then return me->EnterEvent(me)
  case FL_EVENT_LEAVE      : if me->LeaveEvent         then return me->LeaveEvent(me)
  case FL_EVENT_PUSH       : if me->ButtonPushEvent    then return me->ButtonPushEvent   (me,Fl_EventButton(),Fl_EventX(),Fl_EventY())
  case FL_EVENT_RELEASE    : if me->ButtonReleaseEvent then return me->ButtonReleaseEvent(me,Fl_EventButton(),Fl_EventX(),Fl_EventY())
  case FL_EVENT_MOVE       : if me->MouseMoveEvent     then return me->MouseMoveEvent(me,Fl_EventX(),Fl_EventY())
  case FL_EVENT_DRAG       : if me->MouseDragEvent     then return me->MouseDragEvent(me,Fl_EventX(),Fl_EventY())
  case FL_EVENT_MOUSEWHEEL : if me->MouseWheelEvent    then return me->MouseWheelEvent(me,Fl_EventX(),Fl_EventY(),Fl_EventDY())
  case FL_EVENT_KEYDOWN    : if me->KeyDownEvent       then return me->KeyDownEvent(me,Fl_EventKey())
  case FL_EVENT_KEYUP      : if me->KeyUpEvent         then return me->KeyUpEvent(me,Fl_EventKey())
  end select
  ' delegate all unhandled events to the base class
  dim as Fl_WindowEx ptr ex=win
  return Fl_WindowExHandleBase(ex,event)
end function

function FB_FORM.ResizeCB cdecl(byval win as any ptr,byval x as long,byval y as long,byval w as long,byval h as long) as long
  print "FB_FORM.ResizeCB"
  dim as FB_FORM ptr me = Fl_WidgetGetUserData(win)
  if me->ResizeEvent then return me->ResizeEvent(me,x,y,w,h)
  return 0
end function

' optinal user defined callbacks
function ShowEventCB(byval frm as FB_FORM ptr) as long
  print "ShowEventCB"
  return 0
end function

function HideEventCB(byval frm as FB_FORM ptr) as long
  print "HideEventCB"
  return 0
end function

function FocusEventCB(byval frm as FB_FORM ptr) as long
  print "FocusEventCB"
  return 0
end function

function UnfocusEventCB(byval frm as FB_FORM ptr) as long
  print "UnfocusEventCB"
  return 0
end function

function EnterEventCB(byval frm as FB_FORM ptr) as long
  print "EnterEventCB"
  return 0
end function

function LeaveEventCB(byval frm as FB_FORM ptr) as long
  print "LeaveEventCB"
  return 0
end function

function ButtonPushEventCB(byval frm as FB_FORM ptr,byval button as long,byval x as long,byval y as long) as long
  print "ButtonPushEventCB Button(" & button & " at " & x & "," & y & ")"
  return 0
end function

function ButtonReleaseEventCB(byval frm as FB_FORM ptr,byval button as long,byval x as long,byval y as long) as long
  print "ButtonReleaseEventCB  Button(" & button & " at " & x & "," & y & ")"
  return 0
end function

function MouseMoveEventCB(byval frm as FB_FORM ptr,byval x as long,byval y as long) as long
  print "MouseMoveEventCB (" & x & "," & y & ")"
  return 0
end function

function MouseDragEventCB(byval frm as FB_FORM ptr,byval x as long,byval y as long) as long
  print "MouseMoveEventCB (" & x & "," & y & ")"
  return 0
end function

function MouseWheelEventCB(byval frm as FB_FORM ptr,byval x as long,byval y as long,byval z as long) as long
  print "MouseWheelEventCB (" & x & "," & y & "," & z & ")"
  return 0
end function

function KeyDownEventCB(byval frm as FB_FORM ptr,byval key as long) as long
  print "KeyDownEventCB Key(" & key & ")"
  return 0
end function

function KeyUpEventCB(byval frm as FB_FORM ptr,byval key as long) as long
  print "KeyUpEventCB  Key(" & key & ")"
  return 0
end function

function ResizeEventCB(byval frm as FB_FORM ptr,byval x as long,byval y as long,byval w as long,byval h as long) as long
  print "ResizeEventCB(" & x & "," & y & "," & w & "," & h & ")"
  return 0
end function

function DrawEventCB(byval frm as FB_FORM ptr) as long
  print "DrawEventCB"
  return 0
end function

'
' main
'
var frm1 = FB_FORM(320,200, "Form 1")
frm1.ShowEvent          = @ShowEventCB
frm1.HideEvent          = @HideEventCB
frm1.FocusEvent         = @FocusEventCB
frm1.UnfocusEvent       = @UnfocusEventCB
frm1.EnterEvent         = @EnterEventCB
frm1.LeaveEvent         = @LeaveEventCB
frm1.ButtonPushEvent    = @ButtonPushEventCB
frm1.ButtonReleaseEvent = @ButtonReleaseEventCB
frm1.MouseMoveEvent     = @MouseMoveEventCB
frm1.MouseDragEvent     = @MouseDragEventCB
frm1.MouseWheelEvent    = @MouseWheelEventCB
frm1.KeyDownEvent       = @KeyDownEventCB
frm1.KeyUpEvent         = @KeyUpEventCB
frm1.ResizeEvent        = @ResizeEventCB
frm1.DrawEvent          = @DrawEventCB
frm1.Show()
Fl_Run()
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by D.J.Peters »

D.J.Peters wrote: Nov 05, 2022 5:48 I found this option 'FL_OPTION_DND_TEXT' :-)

disable text drag and drop operation Fl_SetOption(FL_OPTION_DND_TEXT, 0)
enable text drag and drop operation Fl_SetOption(FL_OPTION_DND_TEXT, 1)
There are more !

Joshy

Code: Select all

' Initiate a Drag And Drop operation.
declare function Fl_Dnd() as long
' Gets or sets whether drag and drop text operations are supported.
declare sub Fl_SetDndTextOps(byval v as long)
declare function  Fl_GetDndTextOps() as long
Last edited by D.J.Peters on Oct 31, 2023 1:15, edited 1 time in total.
VANYA
Posts: 1839
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by VANYA »

But the FreeBASIC communtiy is to small to invest so much livetime in projects I have done all the last 17 years.
I don't know about others, but I really appreciate what you do.
Today all BASIC like languages comes with a GUI and unicode/UTF support but the dev team of FreeBASIC thinks different.
Too many things to do, but very few developers of the FB project. Well, besides, English-speaking programmers do not really need Unicode :)

-----------

Thanks for the clarification and examples!

P.S. if you are interested to adapt from C++ language to FB: https://github.com/magiblot/tvision?ysc ... h784754842
This is the coolest open source console GUI I've come across. Systems: Windows, Linux, Dos.
And this is not easy to adapt to FB. However , all your projects are very laborious.
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: FLTK-C-1.3.3 for FreeBASIC

Post by jevans4949 »

Is there any list of error codes for FLTK?
I'm trying to produce a printout, and I'm getting "Endpage - error 1" in a messagebox for each page. I produced a skeleton page built on the FL_Printer01 example, but it all went pear-shaped when I added my data file, and I get no output.
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: FLTK-C-1.3.3 for FreeBASIC

Post by jevans4949 »

I solved my above problem eventually. I had set up a separate newpage function to invoke the FL-Startpage function and format the grid and column headers. while having all the other FLTK function calls in my main file processing loop. What I forgot to do was to invoke the newpage function after the Fl-Endpage function between pages. My program now works as intended.
ring0
Posts: 14
Joined: Dec 26, 2012 6:33
Location: Oz

Re: FLTK-C-1.3.3 for FreeBASIC

Post by ring0 »

My situation (simplified):
I have 2 FreeBASIC programs. Program #1 collects data and does some processing and puts the results into named shared memory. Then sends a message (WM_USER) to program #2. Program#2 gets the message, reads the data, does some more processing and presents the results. I am interested to use FLTK for program #2 - mainly to use Fl_Chart.
My Question: How can I obtain the WM_USER message in FLTK ? Is it possible and if so some explanation or pseudo code would be much appreciated.
Cheers
ring0
Helium5793
Posts: 42
Joined: Jun 21, 2016 13:06

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Helium5793 »

I am running fedora 38 and cannot get fltk 1.3.3 to communicate with freebasic 1.10. I have followed the old (2009?) set of directions but they don't seem to correctly install fltk. I could use help here, to get it installed. Even better would be a freebasic version that came with fltk installed if that is possible.



Linux:
Download and extract fltk-c.1.3.3.zip with all folders in your home folder:
copy the extracted library to /usr/lib
ubuntu: sudo cp libfltk-c*.so /usr/lib
slackware: su -c "cp libfltk-c*.so /usr/lib"
or any other distro as root: cp libfltk-c*.so /usr/lib
optional run buildall.sh
chmod -x ./buildall.sh
sh ./buildall.sh

Should this be in /usr/lib64 perhaps?
Any help appreciated,
John
silverman
Posts: 2
Joined: Oct 28, 2015 15:13

Re: FLTK-C-1.3.3 for FreeBASIC

Post by silverman »

Hello
(Sorry for my bad english, I use google translate)
I think there is a bug with "Fl_GroupNew". Check the code, the children ("Fl_Radio_Round_ButtonNew") have the wrong position. Now if you put a comment on line 14, it works. The same problem happens with "FL_TabNew" too.

Code: Select all

#Include "fltk-c.bi"

' Widgets
Dim Shared As Fl_Window Ptr Window_Main
Dim Shared As Fl_Group Ptr Group_radio
Dim Shared As Fl_Radio_Round_Button Ptr Button_radio_red, Button_radio_green, Button_radio_blue

dim shared GNX as long
dim shared GNY as long

    Window_Main = Fl_WindowNew (640, 480, "Test")

' Remark this line
GNX=100 : GNY=80
    Group_radio = Fl_GroupNew (GNX,GNY, 170, 90, "Group_radio:")
    
    ' création des boutonsradio positionnés dans Group_radio
    Fl_GroupBegin (Group_radio)
        Button_radio_red = Fl_Radio_Round_ButtonNew (10,5, 150, 20, "Button_radio_red")
        Button_radio_green = Fl_Radio_Round_ButtonNew (10,35, 150, 20, "Button_radio_green")
        Button_radio_blue = Fl_Radio_Round_ButtonNew (10,65, 150, 20, "Button_radio_blue")
    Fl_GroupEnd (Group_radio)
    '
    Fl_WidgetSetBox Group_radio,FL_ENGRAVED_BOX
    Fl_WidgetSetColor Group_radio, FL_LIGHT2
    
    ' on repositionne le nouveau groupe 
    Fl_WidgetPosition(Group_radio,100,80)

Fl_WindowShow (Window_Main)
Fl_Run

End
jdebord
Posts: 550
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by jdebord »

Hello silverman ( I assume you are silverman from the Panoramic forum ? )

The position of the widget inside a group is defined relative to the main window, not the group.

So you have to modiffy your coordinates:

Code: Select all

Fl_GroupBegin (Group_radio)
        Button_radio_red = Fl_Radio_Round_ButtonNew (10 + GNX, 5 + GNY, 150, 20, "Button_radio_red")
        Button_radio_green = Fl_Radio_Round_ButtonNew (10 + GNX, 35 + GNY, 150, 20, "Button_radio_green")
        Button_radio_blue = Fl_Radio_Round_ButtonNew (10 + GNX, 65 + GNY, 150, 20, "Button_radio_blue")
Fl_GroupEnd (Group_radio)
silverman
Posts: 2
Joined: Oct 28, 2015 15:13

Re: FLTK-C-1.3.3 for FreeBASIC

Post by silverman »

Thank you very much!
Baptiste
Posts: 18
Joined: May 15, 2019 10:58

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Baptiste »

Good morning,
I'm trying to use FLTK to draw curves or graphs. I therefore used the doc mentioned at the top of the post to draw an example. I would like to know if it is possible to draw a second curve on the same graph (for example y(x)/2). I made several unsuccessful attempts

Code: Select all

#Include "fltk-c.bi"

Dim Shared As Fl_Window Ptr Window_Main
Dim Shared As Fl_Chart Ptr Chart_Sine
dim x as Single
dim y(12) as Single

Sub CreateWindow_Main ()
' Fenêtre avec diagramme
    Window_Main = Fl_WindowNew (400, 240, "Graphe")
    Chart_Sine = Fl_ChartNew (10, 10, 380, 200, "absices=12")
    Fl_WidgetSetType (Chart_Sine, FL_CHART_LINE)
End Sub


CreateWindow_Main ()
Fl_WindowShow (Window_Main)


y(1)=100
y(2)=80
y(3)=65
y(4)=50
y(5)=40
y(6)=30
y(7)=21
y(8)=15
y(9)=10
y(10)=6
y(11)=4
y(12)=3

' Tracer la fonction 
  for x=1 to 12
     Fl_ChartAdd (Chart_Sine, y(x), "", FL_RED)  
  next
  
Fl_Run

print "Ok"

end




Post Reply