FLTK

Developers discussion and contributions to FbCadCam source code

Moderator: shela

Post Reply
owen
Site Admin
Posts: 16
Joined: Thu Apr 13, 2017 12:14 pm

FLTK

Post by owen » Wed May 10, 2017 6:25 pm

FLTK (Fast Light Tool Kit) like GTK (GIMP Toolkit) is a Graphical User Interface tool kit (programmer's library) which can be used in Freebasic to build applications with a look and feel of what most end users would expect in a commercial applications. Both FLTK and GTK are open source libraries and are each uniquely complex in their implementation.

Originally fbcadcam (aka fbcad) did not use a popular GUI library. Rather, it used a custom GUI that had the look and feel of an application designed in the 1980's. After experimenting with a few other (less then popular) GUI libraries, GTK was the best choice at the time and finally fbcadcam had a presentable appearance.

FLTK also provides a reasonable cross platform compatible appearance and is currently being considered for use in fbcadcam. There is a bit of experimenting and I thought I would share a bit of code with you that at a very basic level recreates the functionality of the GTK Expander widget for FLTK. In an effort to use FLTK for fbcadcam, I wanted to maintain a similar appearance of GTK's implimentation.

On the left hand side of fbcadcam (using GTK / as it is currently while writing this post) I have a scroll area filled with buttons for drawing lines, snapping to endpoints, etc... All of these buttons (icons) are contained in GTK expander widgets which when clicked expand and collapse each respective section of icons.

FLTK does not have an Expander widget. So here an example (in code) that is the beginning concept of an EXPANDER function for FLTK:

Code: Select all

#include once "fltk-c.bi"

Declare function ButtonHandleCB cdecl (self as any ptr,event as Fl_Event) as Integer

Dim Shared As BOOLEAN showhide(4)
showhide(1)=FALSE
showhide(2)=FALSE
showhide(3)=FALSE
showhide(4)=FALSE
Dim as string label

Dim As Fl_Window Ptr win
Dim As Fl_ButtonEx Ptr btn0,btn1,btn2,btn3,btn4
Dim As Fl_Button Ptr btns1(4,44),btns2(4,44),btns3(4,44),btns4(4,44)
Dim Shared As Fl_Scroll Ptr scr0,scr1,scr2,scr3,scr4
Dim Shared As FL_Pack Ptr pack0,pack1,pack2,pack3,pack4

win = Fl_WindowNew (800, 600, "layout test")
   scr0 = Fl_ScrollNew(0,0,300,600)
   Fl_WidgetSetType scr0, FL_SCROLL_VERTICAL

pack0 = Fl_PackNew(0,0,270,600)

   pack1 = Fl_PackNew(0,0,270,200)
      btn1= Fl_ButtonExNew(0,0,50,30,"expander1")
      Fl_ButtonExSetHandleCB btn1,@ButtonHandleCB
      scr1 = Fl_ScrollNew(0,0,50,200)
      Fl_WidgetSetType scr1, FL_SCROLL_VERTICAL
      For x as integer = 0 to 4
         For y as integer = 0 to 44
            label = "1"
            btns1(x,y) = Fl_ButtonNew(x*50,y*50,45,45)
            Fl_WidgetCopyLabel btns1(x,y), label
            Fl_WidgetSetColorSel(btns1(x,y),Fl_RGB_Color(rnd*255,rnd*255,rnd*255), _
               Fl_RGB_Color(rnd*255,rnd*255,rnd*255))
         next
      Next
   Fl_PackEnd pack1

   pack2 = Fl_PackNew(0,0,270,200)
      btn2= Fl_ButtonExNew(0,0,50,30,"expander2")
      Fl_ButtonExSetHandleCB btn2,@ButtonHandleCB
      scr2 = Fl_ScrollNew(0,0,50,200)
      Fl_WidgetSetType scr2, FL_SCROLL_VERTICAL
      For x as integer = 0 to 4
         For y as integer = 0 to 44
            label = "2"
            btns2(x,y) = Fl_ButtonNew(x*50,y*50,45,45)
            Fl_WidgetCopyLabel btns2(x,y), label
            Fl_WidgetSetColorSel(btns2(x,y),Fl_RGB_Color(rnd*255,rnd*255,rnd*255), _
               Fl_RGB_Color(rnd*255,rnd*255,rnd*255))
         next
      Next
   Fl_PackEnd pack2

   pack3 = Fl_PackNew(0,0,270,200)
      btn3= Fl_ButtonExNew(0,0,50,30,"expander3")
      Fl_ButtonExSetHandleCB btn3,@ButtonHandleCB
      scr3 = Fl_ScrollNew(0,0,50,200)
      Fl_WidgetSetType scr3, FL_SCROLL_VERTICAL
      For x as integer = 0 to 4
         For y as integer = 0 to 44
            label = "3"
            btns3(x,y) = Fl_ButtonNew(x*50,y*50,45,45)
            Fl_WidgetCopyLabel btns3(x,y), label
            Fl_WidgetSetColorSel(btns3(x,y),Fl_RGB_Color(rnd*255,rnd*255,rnd*255), _
               Fl_RGB_Color(rnd*255,rnd*255,rnd*255))
         next
      Next
   Fl_PackEnd pack3
   
   pack4 = Fl_PackNew(0,0,270,200)
      btn4= Fl_ButtonExNew(0,0,50,30,"expander4")
      Fl_ButtonExSetHandleCB btn4,@ButtonHandleCB
      scr4 = Fl_ScrollNew(0,0,50,200)
      Fl_WidgetSetType scr4, FL_SCROLL_VERTICAL
      For x as integer = 0 to 4
         For y as integer = 0 to 44
            label = "4"
            btns4(x,y) = Fl_ButtonNew(x*50,y*50,45,45)
            Fl_WidgetCopyLabel btns4(x,y), label
            Fl_WidgetSetColorSel(btns4(x,y),Fl_RGB_Color(rnd*255,rnd*255,rnd*255), _
               Fl_RGB_Color(rnd*255,rnd*255,rnd*255))
         next
      Next
   Fl_PackEnd pack4

Fl_PackEnd pack0

Fl_WindowShow(win)
Fl_Run

End


function ButtonHandleCB cdecl (self as any ptr,event as Fl_Event) as Integer
   dim as string msg = *Fl_WidgetGetLabel(self)
   Select case event
      Case 1
         Fl_WidgetHide(pack0)
         Select Case msg
            Case "expander1"
               If showhide(1)=FALSE Then
                  showhide(1)=TRUE
                  Fl_WidgetHide(scr1)
               Else
                  showhide(1)=FALSE
                  Fl_WidgetShow(scr1)
               EndIf
            Case "expander2"
               If showhide(2)=FALSE Then
                  showhide(2)=TRUE
                  Fl_WidgetHide(scr2)
               Else
                  showhide(2)=FALSE
                  Fl_WidgetShow(scr2)
               EndIf
            Case "expander3"
               If showhide(3)=FALSE Then
                  showhide(3)=TRUE
                  Fl_WidgetHide(scr3)
               Else
                  showhide(3)=FALSE
                  Fl_WidgetShow(scr3)
               EndIf
            Case "expander4"
               If showhide(4)=FALSE Then
                  showhide(4)=TRUE
                  Fl_WidgetHide(scr4)
               Else
                  showhide(4)=FALSE
                  Fl_WidgetShow(scr4)
               EndIf
         End Select
         Fl_WidgetShow(pack0)
   End Select
   Return 1
end function

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest