FLTK-C-1.3.3 for FreeBASIC

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 7780
Joined: May 28, 2005 3:28

Re: FLTK-C-1.3.3 for FreeBASIC

Postby D.J.Peters » Aug 13, 2019 23:48

I found online C++ code that use the second form of Fl_WindowSdow()

Code: Select all

mainWindow->icon(my_icon);
mainWindow->show(argc,argv);
It's Fl_WindowShowArgs(win,argc,argv) in C or FreeBASIC may be you give it a try also.

Joshy
Knatterton
Posts: 117
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Aug 14, 2019 3:29

Could you provide a fb snippet?

Erco mentions two ways in Linux, but both dont't work in mint 19.2 64, tried today once more:

http://seriss.com/people/erco/fltk/howt ... -icon.html
Boris the Old
Posts: 134
Joined: Feb 04, 2011 20:34
Location: Ontario, Canada

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Boris the Old » Aug 16, 2019 17:51

@Joshy

It's been a few months since I was on the forums, and just wanted to let you know that FLTK is working out well in converting our business applications from PowerBasic to FB.

Knatterton wrote:What's my personal motivation to work on Fltk? I am programmer for fun, like we all here.


Some of us are here to find better ways of extracting large amounts of money from our customers. ;-)

Rod
Knatterton
Posts: 117
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Aug 16, 2019 19:21

Boris the Old wrote:Some of us are here to find better ways of extracting large amounts of money from our customers. ;-)

After reading the fltk-threads i would guess you are the only one. :-)
Knatterton
Posts: 117
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Aug 16, 2019 21:28

Found 8 new slider types. Have seen them somewhere. With Joshys tip for horizontal roller it was possible to add them.

Code: Select all

' Fltk_Sliders_02.bas
' with 24 types
' move window to the side to see console

#include once "fltk-c.bi"

'test of:
' Fl_SliderNew()      http://www.fltk.org/doc-1.3/classFl__Slider.html
' Fl_Fill_SliderNew()
' Fl_Nice_SliderNew()
' Fl_Value_SliderNew()
' Fl_WidgetSetType()

sub SliderCB cdecl (byval self as FL_WIDGET ptr,byval valuator as any ptr)
  print *Fl_WidgetGetLabel(self) & " value = " & Fl_ValuatorGetValue(valuator)
end sub

var win = Fl_WindowNew(810,720, "Fltk_Sliders_02.bas 24 types all together, integer and float")

var sld1 = Fl_SliderNew          ( 30, 10, 30,220,"V-Slider")
var sld2 = Fl_Fill_SliderNew     (110, 10, 30,220,"V-Fill")
var sld3 = Fl_Nice_SliderNew     (190, 10, 30,220,"V-Nice")
var sld4 = Fl_Value_SliderNew    (270, 10, 30,220,"V-Value")
var sld5 = Fl_Value_SliderNew    (350, 10, 30,220,"V-Val-Fill")
var sld6 = Fl_Value_SliderNew    (430, 10, 30,220,"V-Val-Nice")
Fl_WidgetSetType(sld5,FL_SLIDER_VERT_FILL)
Fl_WidgetSetType(sld6,FL_SLIDER_VERT_NICE)

var sld7 = Fl_SliderNew          ( 30, 300, 30,220,"V-Slider")
var sld8 = Fl_Fill_SliderNew     (110, 300, 30,220,"V-Fill")
var sld9= Fl_Nice_SliderNew      (190, 300, 30,220,"V-Nice")
var sld10 = Fl_Value_SliderNew   (270, 300, 30,220,"V-Value")
var sld11 = Fl_Value_SliderNew   (350, 300, 30,220,"V-Val-Fill")
var sld12 = Fl_Value_SliderNew   (430, 300, 30,220,"V-Val-Nice")
Fl_WidgetSetType(sld11,FL_SLIDER_VERT_FILL)
Fl_WidgetSetType(sld12,FL_SLIDER_VERT_NICE)

var sld13 = Fl_Hor_SliderNew      (550, 10,220, 30,"H-Slider")
var sld14 = Fl_Hor_Fill_SliderNew (550, 60,220, 30,"H-Fill")
var sld15 = Fl_Hor_Nice_SliderNew (550,110,220, 30,"H-Nice")
var sld16 = Fl_Hor_Value_SliderNew(550,160,220, 30,"H-Value")
var sld17 = Fl_Hor_Value_SliderNew(550,210,220, 30,"H-Val-Fill")
var sld18 = Fl_Hor_Value_SliderNew(550,260,220, 30,"H-Val:Nice")
Fl_WidgetSetType(sld17,FL_SLIDER_HOR_FILL)
Fl_WidgetSetType(sld18,FL_SLIDER_HOR_NICE)

var sld19 = Fl_Hor_SliderNew      (550, 410, 220, 30,"H-Slider")
var sld20 = Fl_Hor_Fill_SliderNew (550, 460, 220, 30,"H-Fill")
var sld21 = Fl_Hor_Nice_SliderNew (550, 510, 220, 30,"H-Nice")
var sld22 = Fl_Hor_Value_SliderNew(550, 560, 220, 30,"H-Value")
var sld23 = Fl_Hor_Value_SliderNew(550, 610, 220, 30,"H-Val-Fill")
var sld24 = Fl_Hor_Value_SliderNew(550, 660, 220, 30,"H-Val-Nice")
Fl_WidgetSetType(sld23,FL_SLIDER_HOR_FILL)
Fl_WidgetSetType(sld24,FL_SLIDER_HOR_NICE)


Fl_WidgetSetColor(sld1, Fl_RED)
Fl_WidgetSetColor(sld2, Fl_YELLOW)
Fl_WidgetSetColor(sld3, Fl_CYAN)
Fl_WidgetSetColor(sld4, Fl_GREEN)
Fl_WidgetSetColor(sld5, Fl_WHITE)
Fl_WidgetSetColor(sld6, Fl_MAGENTA)

Fl_WidgetSetColor(sld7, Fl_DARK_CYAN)
Fl_WidgetSetColor(sld8, Fl_DARK_GREEN)
Fl_WidgetSetColor(sld9,  Fl_RED)
Fl_WidgetSetColor(sld10, Fl_YELLOW)
Fl_WidgetSetColor(sld11, Fl_CYAN)
Fl_WidgetSetColor(sld12, Fl_GREEN)

Fl_WidgetSetColor(sld13, Fl_DARK_BLUE)
Fl_WidgetSetColor(sld14, Fl_DARK_YELLOW)
Fl_WidgetSetColor(sld15, Fl_DARK_CYAN)
Fl_WidgetSetColor(sld16, Fl_GREEN)
Fl_WidgetSetColor(sld17, Fl_DARK_CYAN)
Fl_WidgetSetColor(sld18, Fl_WHITE)

Fl_WidgetSetColor(sld19, Fl_RED)
Fl_WidgetSetColor(sld20, Fl_YELLOW)
Fl_WidgetSetColor(sld21, Fl_DARK_CYAN)
Fl_WidgetSetColor(sld22, Fl_GREEN)
Fl_WidgetSetColor(sld23, Fl_MAGENTA)
Fl_WidgetSetColor(sld24, Fl_DARK_YELLOW)




'where color can be one of these:
'Fl_BLACK
'Fl_DARK_GREEN
'Fl_GREEN
'Fl_DARK_RED
'Fl_DARK_YELLOW
'Fl_RED
'Fl_YELLOW
'Fl_DARK_BLUE
'Fl_DARK_MAGENTA
'Fl_DARK_CYAN
'Fl_BLUE
'Fl_MAGENTA
'Fl_CYAN 
'Fl_WHITE

' connect callbacks
Fl_WidgetSetCallbackArg sld1,@SliderCB,sld1
Fl_WidgetSetCallbackArg sld2,@SliderCB,sld2
Fl_WidgetSetCallbackArg sld3,@SliderCB,sld3
Fl_WidgetSetCallbackArg sld4,@SliderCB,sld4
Fl_WidgetSetCallbackArg sld5,@SliderCB,sld5
Fl_WidgetSetCallbackArg sld6,@SliderCB,sld6
Fl_WidgetSetCallbackArg sld7,@SliderCB,sld7
Fl_WidgetSetCallbackArg sld8,@SliderCB,sld8
Fl_WidgetSetCallbackArg sld9,@SliderCB,sld9
Fl_WidgetSetCallbackArg sld10,@SliderCB,sld10
Fl_WidgetSetCallbackArg sld11,@SliderCB,sld11
Fl_WidgetSetCallbackArg sld12,@SliderCB,sld12
Fl_WidgetSetCallbackArg sld13,@SliderCB,sld13
Fl_WidgetSetCallbackArg sld14,@SliderCB,sld14
Fl_WidgetSetCallbackArg sld15,@SliderCB,sld15
Fl_WidgetSetCallbackArg sld16,@SliderCB,sld16
Fl_WidgetSetCallbackArg sld17,@SliderCB,sld17
Fl_WidgetSetCallbackArg sld18,@SliderCB,sld18
Fl_WidgetSetCallbackArg sld19,@SliderCB,sld19
Fl_WidgetSetCallbackArg sld20,@SliderCB,sld20
Fl_WidgetSetCallbackArg sld21,@SliderCB,sld21
Fl_WidgetSetCallbackArg sld22,@SliderCB,sld22
Fl_WidgetSetCallbackArg sld23,@SliderCB,sld23
Fl_WidgetSetCallbackArg sld24,@SliderCB,sld24

' set to integer first 6
Fl_ValuatorSetStep(sld1, 1)
Fl_ValuatorSetStep(sld2, 1)
Fl_ValuatorSetStep(sld3, 1)
Fl_ValuatorSetStep(sld4, 1)
Fl_ValuatorSetStep(sld5, 1)
Fl_ValuatorSetStep(sld6, 1)

' set to integer first horiz 6
Fl_ValuatorSetStep(sld13, 1)
Fl_ValuatorSetStep(sld14, 1)
Fl_ValuatorSetStep(sld15, 1)
Fl_ValuatorSetStep(sld16, 1)
Fl_ValuatorSetStep(sld17, 1)
Fl_ValuatorSetStep(sld18, 1)

' set bounds
Fl_ValuatorBounds(sld1 , -6, 6)
Fl_ValuatorBounds(sld2 , -2, 7)
Fl_ValuatorBounds(sld3 , -8, 8)
Fl_ValuatorBounds(sld4 , 0, 6.3)
Fl_ValuatorBounds(sld5 , -5, 75)
Fl_ValuatorBounds(sld6 , -14, 14)
Fl_ValuatorBounds(sld7 , -75, 75)
Fl_ValuatorBounds(sld8 , -4, 14)
Fl_ValuatorBounds(sld9 , -6.5, 6.5)
Fl_ValuatorBounds(sld10 , -7.1, 7.1)
Fl_ValuatorBounds(sld11 , -8.7, 8.7)
Fl_ValuatorBounds(sld12 , 0, 6.3)
Fl_ValuatorBounds(sld13 , -7.5, 7.5)
Fl_ValuatorBounds(sld14 , -1.4, 4)
Fl_ValuatorBounds(sld15 , -7.5, 7.5)
Fl_ValuatorBounds(sld16 , -1.4, 4.1)
Fl_ValuatorBounds(sld17 , -75, 75)
Fl_ValuatorBounds(sld18 , -14, 14)
Fl_ValuatorBounds(sld19 , -6.5, 6.5)
Fl_ValuatorBounds(sld20 , -7.1, 7.1)
Fl_ValuatorBounds(sld21 , -8.7, 8.7)
Fl_ValuatorBounds(sld22 , 0, 6.3)
Fl_ValuatorBounds(sld23 , -7.5, 7.5)
Fl_ValuatorBounds(sld24 , -1.4, 4)

' set initial values
Fl_ValuatorSetValue(sld1 , 1)
Fl_ValuatorSetValue(sld2 , -2)
Fl_ValuatorSetValue(sld3 , 12)
Fl_ValuatorSetValue(sld4 , 6)
Fl_ValuatorSetValue(sld5 , 3)
Fl_ValuatorSetValue(sld6 , -5)
Fl_ValuatorSetValue(sld7 , 3)
Fl_ValuatorSetValue(sld8 , 1)
Fl_ValuatorSetValue(sld9  , 0.1)
Fl_ValuatorSetValue(sld10 , -5.1)
Fl_ValuatorSetValue(sld11 , -7.1)
Fl_ValuatorSetValue(sld12 , 4.1)
Fl_ValuatorSetValue(sld13 , 3.1)
Fl_ValuatorSetValue(sld14 , -0.2)
Fl_ValuatorSetValue(sld15 , 5.1)
Fl_ValuatorSetValue(sld16 , 4.1)
Fl_ValuatorSetValue(sld17 , 3)
Fl_ValuatorSetValue(sld18 , 1)
Fl_ValuatorSetValue(sld19  , 0.1)
Fl_ValuatorSetValue(sld20 , -5.1)
Fl_ValuatorSetValue(sld21 , 8.1)
Fl_ValuatorSetValue(sld22 , 4.1)
Fl_ValuatorSetValue(sld23 , 3.1)
Fl_ValuatorSetValue(sld24 , -0.2)

Fl_WindowShow win
Fl_Run
Knatterton
Posts: 117
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Aug 19, 2019 7:06

Another one from the Fltk_ -series. Helps myself to learn fltk.

Code: Select all

' Fltk_Button_Array_01.bas

#include once "fltk-c.bi"

sub ButtonCB cdecl (byval self as Fl_Widget ptr)
  print "Button: " & *Fl_WidgetGetLabel(self)
end sub

Dim As Fl_Window Ptr Win = Fl_WindowNew (538, 538, "Fltk_Button_Array")

Dim as Fl_Button Ptr btn(15,15)
dim as string label1

' create buttons
for x as short = 0 to 15
  For y as short = 0 to 15
    label1 = str(1 + y*16 + x)
    btn(x,y) = Fl_ButtonNew(x*33+5,y*33+5,32,32)
    Fl_WidgetCopyLabel btn(x,y), label1
    Fl_WidgetSetColor(btn(x,y),Fl_RGB_Color(255-(x*16),255-(y*16),(x*16)))
    Fl_WidgetSetLabelColor(btn(x,y),Fl_GRAY)
    Fl_WidgetSetCallback0 btn(x,y),@ButtonCB
  next
next

Fl_GroupSetResizable Win,Win
Fl_WindowShow(Win)
Fl_Run
Knatterton
Posts: 117
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Aug 21, 2019 11:17

This is meant as the new preferences window for FastLighter. What would be still missing?

Code: Select all

' pref_window.bas
' by Knatterton

#include once "vbcompat.bi"
#include once "fltk-c.bi"

dim shared as string fbc_name
dim shared as string fbc_path

if SEP = "\" then ' goes for all windows
  fbc_name = "fbc*.exe"
   fbc_path = "\FreeBASIC\"
else ' linux or others
  fbc_name = "fbc"
   fbc_path = "/usr/local/bin/"
end if

type tprefs
  as string activ = "0", nam, opt, value, ind = "0", r, g, b
  as any ptr btn, box, fon
  as ulong col
end type

dim as short i
dim as ubyte r, g, b
dim shared as tprefs fl_pref(14)
dim shared as ubyte r8=255,g8=255,b8=255

fl_pref(0).col =  Fl_BACKGROUND_COLOR
fl_pref(1).col =  Fl_BACKGROUND2_COLOR
fl_pref(2).col =  Fl_FOREGROUND_COLOR
fl_pref(3).col =  Fl_RGB_Color(255,255,0)
fl_pref(4).col =  Fl_RGB_Color(150,134,122)
fl_pref(5).col =  Fl_RGB_Color(200,234,22)
fl_pref(6).col =  FL_BLACK         ' PLAIN    style 'A'
fl_pref(7).col =  FL_BLUE          ' KEYWORD  style 'B'
fl_pref(8).col =  FL_DARK_YELLOW   ' STRING   style 'C'
fl_pref(9).col =  Fl_RED          ' COMMENT  style 'D'
fl_pref(10).col =  FL_DARK_YELLOW  ' NUMBER   style 'E'
fl_pref(11).col =  FL_DARK_GREEN   ' PREPROC  style 'F'
fl_pref(12).col =  FL_CYAN         ' DATATYPE style 'G'
fl_pref(13).col =  FL_MAGENTA      ' OTHER    style 'H'
fl_pref(14).col =  FL_DARK_GREEN   ' USERLIB  style 'I'

for i = 0 to 14
  with fl_pref(i)
    Fl_GetColor(.col, r, g, b)
    .r = str(r)
    .g = str(g)
    .b = str(b)
    read .nam
  end with
next i

 data "Background","Background2","Foreground","Color 1","Color 2","Color 3","Plain", _
      "Keyword","String","Comment","Number","Preproc","Datatype","Other","Userlib"

sub load_prefs  ' open and read the file
   dim as integer filehandle
   filehandle = freefile
   open "fl.pref" for input as #filehandle
   for i as short = 0 to 14
     with fl_pref(i)
       line input #filehandle, .activ
       line input #filehandle, .r
       line input #filehandle, .g
       line input #filehandle, .b
       line input #filehandle, .ind
       fl_pref(i).col = Fl_RGB_Color(valint(.r),valint(.g),valint(.b))
       if i = 0 then Fl_Background(valint(.r),valint(.g),valint(.b))
       if i = 1 then Fl_Background2(valint(.r),valint(.g),valint(.b))
       if i = 2 then Fl_Foreground(valint(.r),valint(.g),valint(.b))
     end with
   next i   
   close #filehandle
   Fl_ReDraw()
end sub

sub save_prefs ' open and write the file
   dim as integer filehandle
   filehandle = freefile
   open "fl.pref" for output as #filehandle
   for i as short = 0 to 14
      print #filehandle, fl_pref(i).activ
      print #filehandle, fl_pref(i).r
      print #filehandle, fl_pref(i).g
      print #filehandle, fl_pref(i).b
      print #filehandle, fl_pref(i).ind
   next i
   close #filehandle
end sub

sub Fl_File_ChooserShowCenter(byval fc as FL_File_Chooser ptr)
  var win = cptr(FL_Double_Window ptr,Fl_WidgetWindow(Fl_File_ChooserNewButton(fc)))
  var scrW=Fl_GetW()          ' get screen width,height
  var scrH=Fl_GetH()
  var winW=Fl_WidgetGetW(win) ' get current win width,height
  var winH=Fl_WidgetGetH(win)
  var newX = scrW/2-winW/2    ' calculate new center position
  var newY = scrH/2-winH/2
  Fl_WidgetPosition(win,newX,newY)
  Fl_Double_WindowShow(win)
  Fl_File_ChooserRescanKeepFilename(fc)
end sub

' file callbacks
sub FbcFileCB cdecl (byval self as Fl_Widget ptr,byval txt as any ptr)
  flFileChooserOkLabel("Open")
  dim as string result = CurDir, label
  var fc = Fl_File_ChooserNew(result, "*" , FL_FILECHOOSER_SINGLE, "Select fbc")
  Fl_File_ChooserSetPreview(fc,0)
  Fl_File_ChooserShowCenter(fc)
  while Fl_File_ChooserShown(fc) andalso Fl_Wait()=1
  wend
  dim as string filepath = *Fl_File_ChooserGetValue(fc)
  'dim as string file ' next part later needed
  'dim as long last
  ' get file name out of filepath
  'last = InStrRev(filepath, SEP) ' SEP is defined in fltk-tools.bi
  'file = Mid(filepath, last + 1, len(filepath))
  'label = left(file,11) & ".."
  Fl_WindowCopyLabel txt, filepath ' display path and file
end sub

' button callbacks
sub ColorCB cdecl (byval self as Fl_Widget ptr,byval box as any ptr)
  dim as long y = Fl_WidgetGetY(self)
  dim as long i = (y-60)\40 ' get i through y pos
  flColorChooser fl_pref(i).nam,r8,g8,b8, FL_COLORCHOOSER_RGB
  fl_pref(i).r = str(r8)
  fl_pref(i).g = str(g8)
  fl_pref(i).b = str(b8)
  fl_pref(i).col = Fl_RGB_Color(r8,g8,b8)
  Fl_WidgetSetColor box,fl_pref(i).col
  if i = 0 then Fl_Background(r8,g8,b8)
  if i = 1 then Fl_Background2(r8,g8,b8)
  if i = 2 then Fl_Foreground(r8,g8,b8)
  Fl_ReDraw()
end sub

sub CancelButtonCB cdecl (byval button as FL_WIDGET ptr, options as any ptr)
  Fl_WindowHide(options)
end sub

sub OKButtonCB cdecl (byval button as FL_WIDGET ptr, prefs as any ptr)
  Fl_WindowHide(prefs)
  save_prefs
end sub

sub FontChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  dim as long ind = Fl_ChoiceGetValue(cho)
 ' dim as long y = Fl_WidgetGetY(self)
  dim as long i = (Fl_WidgetGetY(self)-60)\40 ' get i through y pos
  fl_pref(i).ind = str(ind)
  fl_pref(i).value = *Fl_Menu_GetMenu(cho)[ind].text
  ? "Font: " & *Fl_Menu_GetMenu(cho)[ind].text
end sub

sub GtkCB cdecl (byval self as Fl_Widget ptr)
  Fl_SetScheme("gtk+") ' : Fl_ReDraw()
end sub

sub PlasticCB cdecl (byval self as Fl_Widget ptr)
  Fl_SetScheme("plastic") ': Fl_ReDraw()
end sub

sub GleamCB cdecl (byval self as Fl_Widget ptr)
  Fl_SetScheme("gleam") ': Fl_ReDraw()
end sub

sub NoneCB cdecl (byval self as Fl_Widget ptr)
  Fl_SetScheme("none") ': Fl_ReDraw()
end sub

sub FbcInputCB cdecl (byval self as Fl_Widget ptr,byval input_ as any ptr)
  ? "fbc" & *Fl_Input_GetValue(input_)
end sub

' load last settings
If fileexists("fl.pref") then load_prefs
 
sub pref_window
   var pref = Fl_WindowNew(750, 680, "Preferences")
   Fl_WindowSetModal(pref)
   var Input_text = Fl_InputNew(120, 12,200, 20, "Path to FBC:")
   Fl_WidgetSetCallbackArg(Input_text, @FbcInputCB, Input_text)
   Fl_Input_SetValue(Input_text, fbc_path & fbc_name)
   
 
  for i as short = 0 to 14
    with fl_pref(i)
      ' buttons
      .btn = Fl_ButtonNew(20,60+40*i,100,24,.nam)
      Fl_WidgetSetColor .btn, Fl_BACKGROUND2_COLOR
     
      ' boxes
      .box = Fl_BoxExNew(140,60+40*i,100,24)
      Fl_WidgetSetBox .box, boxtype(FL_ENGRAVED_BOX)
      Fl_WidgetSetColor .box, .col
      Fl_WidgetSetCallbackArg .btn,@ColorCB, .box
     
      ' choices
      .fon = Fl_ChoiceNew(260,60 + 40 * i,220,24,"")
      Fl_Menu_Add3(.fon,"HELVETICA") '              =  0 ' Helvetica (or Arial) normal (0)
      Fl_Menu_Add3(.fon,"HELVETICA_BOLD") '         = Fl_HELVETICA or Fl_BOLD
      Fl_Menu_Add3(.fon,"HELVETICA_ITALIC") '       = Fl_HELVETICA or Fl_ITALIC
      Fl_Menu_Add3(.fon,"HELVETICA_BOLD_ITALIC") '  = Fl_HELVETICA or Fl_BOLD_ITALIC
      Fl_Menu_Add3(.fon,"COURIER") '                =  4 ' Courier normal
      Fl_Menu_Add3(.fon,"COURIER_BOLD") '           = Fl_COURIER   or Fl_BOLD
      Fl_Menu_Add3(.fon,"COURIER_ITALIC") '         = Fl_COURIER   or Fl_ITALIC
      Fl_Menu_Add3(.fon,"COURIER_BOLD_ITALIC") '    = Fl_COURIER   or Fl_BOLD_ITALIC
      Fl_Menu_Add3(.fon,"TIMES") '                  =  8 ' Times roman
      Fl_Menu_Add3(.fon,"TIMES_BOLD") '             = Fl_TIMES     or Fl_BOLD
      Fl_Menu_Add3(.fon,"TIMES_ITALIC") '           = Fl_TIMES     or Fl_ITALIC
      Fl_Menu_Add3(.fon,"TIMES_BOLD_ITALIC") '      = Fl_TIMES     or Fl_BOLD_ITALIC
      Fl_Menu_Add3(.fon,"SYMBOL") '                 = 12 ' Standard symbol font
      Fl_Menu_Add3(.fon,"SCREEN") '                 = 13 ' Default monospaced screen font
      Fl_Menu_Add3(.fon,"SCREEN_BOLD") '            = Fl_SCREEN    or Fl_BOLD ' Default monospaced bold screen font
      Fl_Menu_Add3(.fon,"ZAPF_DINGBATS") '          = 15 ' Zapf-dingbats font
      Fl_Menu_Add3(.fon,"FREE_FONT") '              = 16 ' first one to allocate
      Fl_ChoiceSetValue(.fon, valint(.ind))
      Fl_WidgetSetCallbackArg .fon,@FontChoiceCB,.fon
    end with
  next i
   
  ' schemes
   var grp2 = Fl_GroupNew(500,80,130,190,"Scheme") ' box must cover all buttons of group completely
      var rad4 = Fl_Radio_Round_ButtonNew(520,100,90,30,"None")
    Fl_WidgetSetBox(rad4,FL_ENGRAVED_BOX)
    Fl_WidgetSetColor rad4, Fl_BACKGROUND2_COLOR
      var rad5 = Fl_Radio_Round_ButtonNew(520,140,90,30,"Gtk+")
    Fl_WidgetSetBox(rad5,FL_ENGRAVED_BOX)
    Fl_WidgetSetColor rad5, Fl_BACKGROUND2_COLOR
      var rad6 = Fl_Radio_Round_ButtonNew(520,180,90,30,"Plastic")
    Fl_WidgetSetBox(rad6,FL_ENGRAVED_BOX)
    Fl_WidgetSetColor rad6, Fl_BACKGROUND2_COLOR
      var rad7 = Fl_Radio_Round_ButtonNew(520,220,90,30,"Gleam")
    Fl_WidgetSetBox(rad7,FL_ENGRAVED_BOX)
    Fl_WidgetSetColor rad7, Fl_BACKGROUND2_COLOR
   Fl_GroupEnd grp2
  Fl_WidgetSetBox(grp2,FL_ENGRAVED_BOX)
  Fl_WidgetSetColor grp2, FL_LIGHT2

   Fl_WidgetSetSelectionColor(rad4,FL_BLACK)
   Fl_WidgetSetSelectionColor(rad5,FL_BLACK)
   Fl_WidgetSetSelectionColor(rad6,FL_BLACK)
   Fl_WidgetSetSelectionColor(rad7,FL_BLACK)
   
   Fl_WidgetSetCallback0 rad4,@NoneCB
    Fl_WidgetSetCallback0 rad5,@GtkCB
    Fl_WidgetSetCallback0 rad6,@PlasticCB
    Fl_WidgetSetCallback0 rad7,@GleamCB
       
    ' set initial value for each group
    Fl_ButtonSetValue(rad4,1) ' checked
    'Fl_ButtonSetValue(rad5,0) ' unchecked
    'Fl_ButtonSetValue(rad6,0) ' unchecked
    'Fl_ButtonSetValue(rad7,0) ' unchecked
   
  ' main buttons
   var FbcBtn = Fl_ButtonNew(330,12,100,24,"Choose")
  Fl_WidgetSetColor FbcBtn, Fl_BACKGROUND2_COLOR
   Fl_WidgetSetCallbackArg FbcBtn,@FbcFileCB,Input_text
   
   var CanBtn = Fl_ButtonNew(500,620,100,24,"Cancel")
  Fl_WidgetSetColor CanBtn, Fl_BACKGROUND2_COLOR
   Fl_WidgetSetCallbackArg CanBtn,@CancelButtonCB, pref
   
   var OkBtn = Fl_ButtonNew(620,620,100,24,"OK")
  Fl_WidgetSetColor OkBtn, Fl_BACKGROUND2_COLOR
   Fl_WidgetSetCallbackArg OkBtn,@OKButtonCB, pref
   
  ' show window
   Fl_WindowShow pref
   Fl_GroupSetResizable pref,pref
  Fl_WindowSizeRange pref,240,120
   
end sub

pref_window

Fl_Run


If ok-button pressed all is saved, except path and scheme, so that colors and fonts are restored at next program start.

First 3 colors are the background, background2 and foreground, where all immediately change. So if background2 is changed buttons and choices change their color, depending on scheme. Is there a easy way to do the same for the rest of colors, so that already drawn things also change their color?
Knatterton
Posts: 117
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Postby Knatterton » Aug 23, 2019 23:07

Investigated further for the three color models of fltk RGB, 256 color indexed and color cube. They have an own color table for indexed mode. This shows it:

Code: Select all

' Fltk_Own_Color_Table.bas
' this shows fltk's own 256 color table in all its beautiness

#include once "fltk-c.bi"

sub ButtonCB cdecl (byval self as Fl_Widget ptr)
  print "Button: " & *Fl_WidgetGetLabel(self)
end sub

Dim As Fl_Window Ptr Win = Fl_WindowNew (538, 538, "Fltk_Own_Color_Table")

Dim as Fl_Button Ptr btn(15,15)
dim as string label1
dim as ulong col

Fl_OwnColormap() ' on linux seems to be same like system table
'Fl_GetSystemColors()

' numbering now from 0 on, x and y reversed to show exakt range if indexes

' create buttons
for y as short = 0 to 15
  For x as short = 0 to 15
    label1 = str(y*16 + x)
    btn(x,y) = Fl_ButtonNew(x*33+5,y*33+5,32,32)
    Fl_WidgetCopyLabel btn(x,y), label1
    Fl_WidgetSetColor(btn(x,y),col) ' col should be < 256 here
    Fl_WidgetSetLabelColor(btn(x,y),Fl_GRAY)
    Fl_WidgetSetCallback0 btn(x,y),@ButtonCB
    col += 1
  next
next

Fl_GroupSetResizable Win,Win
Fl_WindowShow(Win)
Fl_Run

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 12 guests