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
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by jevans4949 »

My (infrequent) programming efforts these days mostly revolve around extracting data from one CSV file to another. I figured it would be useful to have a skeleton program to select input and output files with a mickey-mouse routine to copy from one to the other, and do this with FLTK.

I have uploaded my files to Google Drive for your amusement; the following link will find them:
https://drive.google.com/open?id=0ByOah ... nRETHdmcTg

I’ve tested it on Windows XP and in 32-bit mode on Windows 7 64-bit.

To make it easier to develop programs outside the FLTK folder created by the download, I copied all the .BI files to folder Freebasic\inc\FLTK, and encode the include statements as:
#Include Once "fltk\fltk-c.bi"
The DLL file needs to be copied to the Freebasic\lib\win32 folder for the linkage-editor, and to the Windows\System32 folder for run-time use. (If running the 32-bit compiler on Windows 7 64bit, that should be Windows\SysWOW64)

I used the Native_File_Chooser feature, as it will be more familiar to the user, and provides more information than the FLTK version. The fact that GetOpen/SaveFilename ignores the initial directory setting is a Windows mis-feature for which I haven’t found the solution.

The copy routine uses the crt/stdio binary functions, to go with the Fl_fopen function, which should cope with UTF8 filenames (although I haven't tested for actual UTF8 filenames).

A few things I noticed that didn’t get a mention in Lothar Schirm’s tutorial; you may have discovered them already:

- for Buttons and Boxes, widget text is by default aligned at the centre of the widget. Use Fl_WidgetSetAlign to change this; if you want the text aligned left inside the box, set to ( Fl_ALIGN_LEFT+Fl_ALIGN_INSIDE). If you don’t specify inside, the caption will go outside the box.

- the callback functions are only invoked according to the Fl_Widget::when switches. The default is to call only when the mouse button is released. This is OK for most purposes, but you may need to tweak it.

- for callback routines in FreeBasic, you will need to encode them as Sub or Function, and this will throw up a type difference warning for the FL_WidgetSetCallback parameter. You can avoid this by using a Cast function on the sub’s address, e.g.:
Fl_WidgetSetCallback0(exebutton,Cast(Fl_callback0,@Copier))

Thanks to Joshy and all those who contibuted to the FLTK-C project.
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by jdebord »

With the Spreadsheet.bas example program provided with FLTK, it's possible to enter capital letters when editing the headers of the rows or columns.

But this is not possible when editing a table cell, since pressing the SHIFT key closes the input box.

How can we modify the program so that we can type capital letters (e.g. SHIFT+A) in a table cell ?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

@jevans4949 don't cast callback pointers !!! NEVER !!!

If you get a warning that means something are wrong

here this can crash
sub Copier (widget As Fl_Widget Ptr)

and must be:
sub Copier cdecl (widget As Fl_Widget Ptr)

The reason are C will restore the stack this means the caller removes (pop's) the param widget ptr from stack.

Without cdecl it's BASIC and in BASIC the method/function self will restore the stack and removes the param from stack

If you cast your BASIC sub as C method the param will be removed twice from stack and this can end in an corrupt stack.

bla bla bla :-)

You use the boxtypes in a wrong manner
oufname=Fl_BoxNew2(CULng(FL_BORDER_BOX),5,100,scrnw-60,20,"")

it must be:
oufname=Fl_BoxNew2(BoxType(FL_BORDER_BOX),5,100,scrnw-60,20,"")

change all CULng(() to BoxType() take a lock at: Fl_Boxtype01.bas

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

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

@jdebord post a really short example with the problem please.

Than I will look what I can do for you.

Joshy
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by jevans4949 »

@D.J.Peters: Thanks for your corrections. The significance of the Cdecl had passed me by, and the BoxType function.

I have corrected these, and re-loaded to Google Drive.
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by jdebord »

D.J.Peters wrote:@jdebord post a really short example with the problem please.

Than I will look what I can do for you.

Joshy
I use a slightly modified version of the demo program Spreadsheet.bas provided with FLTK. It is not really short :)

Code: Select all

#include once "fltk-main.bi"

' Demonstrate simple spreadsheet editor that includes editing row/col headers as well as table cells erco 5/23/14
' from: http://seriss.com/people/erco/fltk/#Fl_Table_Spreadsheet_Cell_Row_Col_Edit

const as integer MAX_COLS = 3
const as integer MAX_ROWS = 100

type Spreadsheet
  declare constructor (byval x as long, byval y as long, byval w as long, byval h as long, byval label as const zstring ptr = 0)
  declare operator cast as Fl_TableEx ptr
  declare operator cast as Fl_Table   ptr
  declare operator cast as Fl_Group   ptr
  declare operator cast as Fl_Widget  ptr
  declare sub EventCB2  ' table's event callback (instance)
  declare sub SetValueHide
  declare sub StartEditing(byval context as Fl_TableContext,byval r as long,byval c as long)
  declare sub DoneEditing
  declare static function HandleCB   cdecl (byval me as any ptr,byval event as Fl_Event) as long
  declare static function DrawCellCB cdecl (byval self as any ptr,byval context as Fl_TableContext, _
                                            byval r as long, byval c as long, _
                                            byval x as long, byval y as long, byval w as long, byval h as long) as long
  declare static sub EventCB cdecl (byval wgt as Fl_Widget ptr,byval v as any ptr) ' table's event callback
  declare static sub InputCB cdecl (byval wgt as Fl_Widget ptr,byval v as any ptr) ' input widget's callback

  as Fl_Input ptr m_input                  ' single instance of Fl_Int_Input widget
  as long row_edit, col_edit               ' row/col being modified
  as Fl_TableContext context_edit          ' context being edited (row head/col head/cell)
  ' Buffer for spreadsheet content
  as string row_values(MAX_ROWS)           ' one dimensional array of strings
  as string col_values(MAX_COLS)           ' one dimensional array of strings
  as string cell_values(MAX_ROWS,MAX_COLS) ' two dimensional array of strings
  as Fl_TableEx ptr m_tbl
end type

operator Spreadsheet.cast as Fl_TableEx ptr : operator = m_tbl : end operator
operator Spreadsheet.cast as Fl_Table   ptr : operator = m_tbl : end operator
operator Spreadsheet.cast as Fl_Group   ptr : operator = m_tbl : end operator
operator Spreadsheet.cast as Fl_Widget  ptr : operator = m_tbl : end operator

constructor Spreadsheet(byval x as long,byval y as long,byval w as long,byval h as long,byval label as const zstring ptr)
  m_tbl = Fl_TableExNew(x, y, w, h, label)
  Fl_TableBegin(m_tbl)

  Fl_TableSetTableBox      m_tbl, BoxType(FL_THIN_UP_FRAME)
  Fl_TableExSetDrawCellCB  m_tbl, @DrawCellCB
  'Fl_TableExSetHandleCB    m_tbl,@HandleCB
  Fl_WidgetSetCallbackArg  m_tbl, @EventCB, @this
  Fl_WidgetSetUserdata     m_tbl, @this
  Fl_WidgetSetWhen         m_tbl, FL_WHEN_NOT_CHANGED or Fl_WidgetGetWhen(m_tbl)


  ' Create input widget that we'll use whenever user clicks on a cell
  m_input = Fl_InputNew(w \ 2, w \ 2, 0, 0)
  Fl_WidgetHide           m_input
  Fl_WidgetSetCallbackArg m_input, @InputCB, @this
  Fl_WidgetSetWhen        m_input, FL_WHEN_ENTER_KEY_ALWAYS  ' callback triggered when user hits Enter
  ' Fl_Input_SetMaximumSize m_input,5
  Fl_WidgetSetColor       m_input, FL_YELLOW

  Fl_TableEnd m_tbl

  ' Table rows
  Fl_TableSetRowHeader       m_tbl, 1
  Fl_TableSetRowHeaderWidth  m_tbl, 75
  Fl_TableRowHeightAll       m_tbl, 25
  Fl_TableSetRowResize       m_tbl, 1
  Fl_TableSetRows            m_tbl, MAX_ROWS

  ' Table cols
  Fl_TableSetColHeader       m_tbl, 1
  Fl_TableSetColHeaderHeight m_tbl, 25
  Fl_TableColWidthAll        m_tbl, 75
  Fl_TableSetColResize       m_tbl, 1
  Fl_TableSetCols            m_tbl, MAX_COLS

  context_edit = FL_CONTEXT_NONE
  row_edit = 0
  col_edit = 0
  Fl_TableSetSelection m_tbl, 0, 0, 0, 0
  dim as long r,c
  for r=0 to MAX_ROWS
    for c=0 to MAX_COLS
      cell_values(r,c)= "" ' & r * MAX_ROWS + c
    next
  next
  for r = 0 to MAX_ROWS
    row_values(r) = str(r + 1)
  next
  for c = 0 to MAX_COLS
    col_values(c) = chr(asc("A") + c)
  next
  Fl_TableEnd(m_tbl)
end constructor

sub Spreadsheet.EventCB cdecl (byval wgt as Fl_Widget ptr, byval v as any ptr)
  dim as Spreadsheet ptr me = v
  me->EventCB2()
end sub

sub Spreadsheet.InputCB cdecl (byval wgt as Fl_Widget ptr, byval v as any ptr)
  dim as Spreadsheet ptr me = v
  me->SetValueHide()
end sub

' Apply value from input widget to values[row][col] array and hide (done editing)
sub Spreadsheet.SetValueHide
  select case as const context_edit
    case FL_CONTEXT_ROW_HEADER : row_values(row_edit) = *Fl_Input_GetValue(m_input)
    case FL_CONTEXT_COL_HEADER : col_values(col_edit) = *Fl_Input_GetValue(m_input)
    case FL_CONTEXT_CELL       : cell_values(row_edit, col_edit) = *Fl_Input_GetValue(m_input)
  end select
  Fl_WidgetHide(m_input)
  Fl_WindowCursor(Fl_WidgetWindow(m_tbl), FL_CURSOR_DEFAULT) ' if we don't do this, cursor can disappear!
end sub

' Start editing a new cell: move the Fl_Int_Input widget to specified row/column
' Preload the widget with the cell's current value and make the widget 'appear' at the cell's location.
' If R=-1, indicates column C is being edited
' If C=-1, indicates row R is being edited
sub Spreadsheet.StartEditing(byval context as Fl_TableContext, byval r as long, byval c as long)
  ' Keep track of cell being edited
  context_edit = context
  row_edit = r
  col_edit = c
  ' Clear any previous multicell selection
  if (r < 0 or c < 0) then
    Fl_TableSetSelection(m_tbl, 0, 0, 0, 0)
  else
    Fl_TableSetSelection(m_tbl, r, c, r, c)
  end if
  ' Find X/Y/W/H of cell
  dim as long X,Y,W,H
  Fl_TableExFindCell m_tbl, context, R, C, X, Y, W, H
  Fl_WidgetResize(m_input, X, Y, W, H)  ' Move Fl_Input widget there
  select case as const context
    case FL_CONTEXT_ROW_HEADER
      Fl_GroupAdd Fl_WidgetWindow(m_tbl), m_input ' XXX parent to nonscrollable group
      Fl_Input_SetValue m_input, row_values(R)
    case FL_CONTEXT_COL_HEADER
      Fl_GroupAdd Fl_WidgetWindow(m_tbl), m_input ' XXX parent to nonscrollable group
      Fl_Input_SetValue m_input, col_values(C)
    case FL_CONTEXT_CELL
      Fl_GroupAdd m_tbl, m_input                  ' XXX parent to scrollable table
      Fl_Input_SetValue m_input, cell_values(R, C)
    case else ' shouldn't happen
      Fl_Input_SetValue m_input, "?"
  end select
  ' Fl_WidgetPosition or Fl_Input_SetPosition2 ?
  Fl_Input_SetPosition2 m_input, 0, len(*Fl_Input_GetValue(m_input))  ' Select entire input field
  Fl_WidgetShow      m_input  ' Show the input widget, now that we've positioned it
  Fl_WidgetTakeFocus m_input
end sub

  ' Tell the input widget it's done editing, and to 'hide'
sub Spreadsheet.DoneEditing
  if (Fl_WidgetVisible(m_input)) then ' input widget visible, ie. edit in progress?
    SetValueHide() ' Transfer its current contents to cell and hide
  end if
end sub

' Handle drawing all cells in table
function Spreadsheet.DrawCellCB cdecl (byval me as any ptr, byval context as Fl_TableContext, _
                                       byval r as long, byval c as long, _
                                       byval x as long, byval y as long, byval w as long, byval h as long) as long
  dim as Spreadsheet ptr self = Fl_WidgetGetUserdata(me)
  select case as const context
    case FL_CONTEXT_STARTPAGE  ' table about to redraw
    case FL_CONTEXT_COL_HEADER ' table wants us to draw a column heading (C is column)
      ' don't draw this cell if it's being edited
      if (self->context_edit = context andalso C = self->col_edit andalso Fl_WidgetVisible(self->m_input)) then return 1
      DrawSetFont FL_HELVETICA_BOLD, 14  ' set font for heading to bold
      DrawPushClip X, Y, W, H            ' clip region for text
      DrawBox BoxType(FL_THIN_UP_BOX), x, y, w, h, Fl_TableGetColHeaderColor(self->m_tbl)
      DrawSetColor FL_BLACK
      DrawStrBox self->col_values(C), x, y, w, h, FL_ALIGN_CENTER
      DrawPopClip
      return 1

    case FL_CONTEXT_ROW_HEADER  ' table wants us to draw a row heading (R is row)
    ' don't draw this cell if it's being edited
      if (self->context_edit = context andalso R = self->row_edit andalso Fl_WidgetVisible(self->m_input)) then return 1
      DrawSetFont FL_HELVETICA_BOLD, 14     ' set font for heading to bold
      DrawPushClip X, Y, W, H               ' clip region for text
      DrawBox BoxType(FL_THIN_UP_BOX), x, y, w, h, Fl_TableGetRowHeaderColor(self->m_tbl)
      DrawSetColor FL_BLACK
      DrawStrBox self->row_values(R), x, y, w, h, FL_ALIGN_CENTER
      DrawPopClip
    return 1

  case FL_CONTEXT_CELL ' table wants us to draw a cell
    ' don't draw this cell if it's being edited
    if ( self->context_edit = context andalso _
         R = self->row_edit andalso _
         C = self->col_edit andalso _
         Fl_WidgetVisible(self->m_input)) then return 1
    ' Background
    dim as long highlight = Fl_TableIsSelected(self->m_tbl, R, C) and (context = self->context_edit)
    DrawBox BoxType(FL_THIN_UP_BOX), x, y, w, h, iif(highlight, FL_YELLOW, FL_WHITE)
    ' Text
    DrawSetFont(FL_HELVETICA, 14) ' ..in regular font
    DrawPushClip(X+3, Y+3, W-6, H-6)
      DrawSetColor(FL_BLACK)
      DrawStrBox self->cell_values(R,C), x+3, y+3, w-6, h-8, FL_ALIGN_RIGHT
    DrawPopClip
    return 1

  case FL_CONTEXT_RC_RESIZE ' table resizing rows or columns
    if Fl_WidgetVisible(self->m_input) then
      Fl_TableExFindCell(self->m_tbl,self->context_edit, self->row_edit, self->col_edit, X, Y, W, H)
      Fl_WidgetResize(self->m_input, X, Y, W, H)
      Fl_TableInitSizes(self->m_tbl)
    end if
    return 1
  end select

  return 0
end function

' Callback whenever someone clicks on different parts of the table
sub Spreadsheet.EventCB2
  var context = Fl_TableCallbackContext(m_tbl)
  var c = Fl_TableCallbackCol(m_tbl)
  var r = Fl_TableCallbackRow(m_tbl)

  select case as const context
    case FL_CONTEXT_ROW_HEADER, _
         FL_CONTEXT_COL_HEADER, _
         FL_CONTEXT_CELL ' A table event occurred on a cell
      select case as const Fl_EventNumber() ' see what FLTK event caused it
        case FL_EVENT_PUSH  ' mouse click?
          DoneEditing       ' finish editing previous
          StartEditing(context, R, C)
        case FL_EVENT_KEYBOARD  ' key press in table?
          DoneEditing() ' finish any previous editing
          if (C = Fl_TableGetCols(m_tbl)-1 or R = Fl_TableGetRows(m_tbl)-1) then
            return ' no editing of totals column
          end if
          dim as ubyte b = Fl_EventText()[0]
          select case b
            case asc("0") to asc("9"), asc("+"), asc("-")  ' any of these should start editing new cell
              StartEditing(context, R, C)
              Fl_InputHandle(m_input, Fl_EventNumber())    ' pass typed char to input
            case 10,13 ' let enter key edit the cell
              StartEditing(context, R, C)
          end select
      end select
    case FL_CONTEXT_TABLE '  A table event occurred on dead zone in table
      DoneEditing() ' done editing, hide
  end select
end sub

'
' main
'
var win = Fl_Double_WindowNew(600, 200, "Carnet d'adresses")
var tbl = new Spreadsheet(10, 25, 580, 165, "Saisie des données")

Fl_GroupSetResizable(win,win)
Fl_WindowShow win
Fl_Run
The problem is : when editing a cell table (not a header cell), pressing the SHIFT key closes the input box, so that I cannot type capital letters.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

@jdebord
I wrote all FL_XXX*.bas stuff to test my FLTK-C wrapper.

Spreadsheet.bas is from erco look at: http://seriss.com/people/erco/fltk/#Fl_ ... w_Col_Edit

Looks like you does only a copy and paste the stuff without to learn or read it carefully :-)

How ever:

in sub Spreadsheet.EventCB2 all keyboard input are handled

Code: Select all

select case b
      case asc("0") to asc("9"),asc("+"),asc("-")  ' any of these should start editing new cell
What does it mean ?
Yes looks like only numbers are allowed all other key input are ignored.

If you remove this restriction you can enter any text SHIFT & letters also.

Joshy

something like this:

Code: Select all

      select case b
      case 10,13 ' let enter key edit the cell
        StartEditing(context, R, C)
      case else ' !!! asc("0") to asc("9"),asc("+"),asc("-")  !!!
        StartEditing(context, R, C)
        Fl_InputHandle(m_input,Fl_EventNumber()) ' pass typed char to input
      end select
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by jdebord »

Yes it works. Thank you very much !

I had noticed this line but did not think it was responsible since the lower case letters were also allowed, as well as the digits.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

jdebord wrote:... lower case letters were also allowed ...
You are right :-)

Joshy
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by owen »

I need some assistance using fltk for the fbcad project.
I just got home (kissimmee, fl) from being out a few weeks on the road driving a truck. trying to write code with the monitor bouncing around is not easy.

basically i need help with the equivalent of this fbgfx to gtk image buffer but in fltk:

a quick excerpt of code from fbcadcam source code

Code: Select all


Dim Shared As GtkWidget Ptr myimage
Dim Shared mypixbuf as GdkPixbuf Ptr
Dim Shared mygetpixels As UByte Ptr

mywidth=580
myheight=580

ScreenRes mywidth,myheight,,4,fb.GFX_NULL


Type myclr
    r As UByte
    g As UByte
    b As UByte
End Type
Dim Shared myrgb As myclr


Sub myfbgfxtogtkimg()'580x580=336400
	If updatefbgfxgtkimage=TRUE Then
		ScreenLock()
		gtk_widget_hide(myimage)
		Dim As Integer i
		Dim As UByte pixcolor,r,g,b
		Dim as ubyte ptr myfbgfx = ScreenPtr
		For i = 0 To mywidth*myheight-1
			pixcolor=*(myfbgfx+i)
			myrgbcol(pixcolor)
			*(mygetpixels+i*3)=myrgb.r
			*(mygetpixels+i*3+1)=myrgb.g
			*(mygetpixels+i*3+2)=myrgb.b
		Next
		ScreenUnlock()
		gtk_widget_show(myimage)
		updatefbgfxgtkimage=FALSE
		'mousemoved=FALSE
	EndIf
End Sub

Sub myrgbcol(pc As UByte)
	Dim As UByte r,g,b
	Select Case pc
		Case 0 'black
			r=0
			g=0
			b=0
		Case 1 'blue
			r=0
			g=0
			b=170
		Case 2 'green
			r=0
			g=170
			b=0
		Case 3 'cyan
			r=0
			g=170
			b=170
		Case 4 'red
			r=170
			g=0
			b=0
		Case 5 'pink
			r=170
			g=0
			b=170
		Case 6 'yellow
			r=170
			g=85
			b=0
		Case 7 'grey
			r=170
			g=170
			b=170
		Case 8 'dark grey
			r=85
			g=85
			b=85
		Case 9 'bright blue
			r=85
			g=85
			b=255
		Case 10 'bright green
			r=85
			g=255
			b=85
		Case 11 'bright cyan
			r=85
			g=255
			b=255
		Case 12 'bright red
			r=255
			g=85
			b=85
		Case 13 'bright pink
			r=255
			g=85
			b=255
		Case 14 'bright yellow
			r=255
			g=255
			b=85
		Case 15 'white
			r=255
			g=255
			b=255
		Case 35
			r=128
			g=0
			b=128
		Case Else
			r=255
			g=255
			b=255
	End Select
	
	myrgb.r=r
	myrgb.g=g
	myrgb.b=b

End Sub
the idea is to scan the screenptr of the fbgfx screen and blit it to fltks bitmap image while preserving the screen color 1 - 15
I do it this way because of the zooming and panning and use of work pages.

perhaps instead of having to dig thru my source code. if the community could provide an fltk example of:
1. using fbgfx native drawing command (line and circle) : draw to the the fbgfx null screen (not to the fltk image initially)
2. when drawing to fbgfx null buffer, the screen's work page is set such that it draws over previously drawn lines and circles
3. blit the screenptr (work page) to fltk image buffer
4 redraw or update fltk image
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

There is no need to use FBGFX and swap it to a FLTK widget.

With FLTK you caan use the 2D vector drawing for your CAD system !
(including scaling, rotating, flipping, TTF-fonts ...)

How erver if you need FBGFX to FLTK take a look at:
FB_Image_2_FL_Image01.bas
FB_Image_2_FL_Image02.bas

Joshy
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by owen »

Thanks Joshy
FBGFX to FLTK
FB_Image_2_FL_Image01.bas
FB_Image_2_FL_Image02.bas
and
DrawingFastPixels.bas
is what I'm looking at. Thanks for the examples.
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by jdebord »

How do you make a horizontal scrollbar ?

I found this in one of erco's examples (http://seriss.com/people/erco/fltk/#Fl_Scrollbar) :

Code: Select all

        scrollbar = new Fl_Scrollbar(0,50,500,25,"Scrollbar");
        scrollbar->type(FL_HORIZONTAL);
But I cant'find the equivalent of "type" in the FB version.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by D.J.Peters »

@jdebord the problem are you and we all FLTK lovers have to learn the object tree.

Fl_Double_Window extends Fl_Window extends Fl_Group extends Fl_Widget
Image

Fl_Scrollbar extends Fl_Slider extends Fl_Valuator extends Fl_Widget
Image

Fl_Output extends Fl_Input extends Fl_Input_ extends Fl_Widget
Image
...

After a month or so you will know it while you sleep and dream from simple life with FLTK.

What a nightmare :lol:

A nother point are in C++ a property xxx.type() can be a setter xxx.type(FLTK_IM_HERE) or a getter var property = xxx.type().

The same property name can be set or get numbers or strings.
xxx.value(0.1) or xxx.value("I'm a nice text!")

The FLTK C++ wrapper I wrote for FreeBASIC is C so we must use:

xxx.SetType() or xxx.GetType()
xxx.SetValue() or xxx.GetValue()
and so one ...

Joshy

Code: Select all

' file: Fl_Scrollbar01.bas
#include "fltk-c.bi"

' show scrollbar's value when changed
sub Scrollbar_CB cdecl(self as Fl_Widget ptr, byval pout as any ptr) 
  var value = str(Fl_ValuatorGetValue(cptr(FL_Scrollbar ptr,self)))
  Fl_Input_SetValue(pout, value)
end sub

' Fl_Double_Window extends Fl_Window
var win = Fl_Double_WindowNew(500,300,"Fl_Scrollbar Demo")
  ' Fl_Scrollbar extends FL_Slider extends Fl_Valuator
  var scb = Fl_ScrollbarNew(0,50,500,25,"Scrollbar")
  ' Fl_Slider extends Fl_Valuator
  Fl_SliderSetSliderSize(scb,0.5) ' the fractional size of the scrollbar's tab, 1/2 scollbar's size
  Fl_ValuatorBounds(scb,100,200)  ' min/max value of the slider's positions
  Fl_ValuatorSetValue(scb,150.0)  ' the initial value (in fltk1.3+ you can use scrollbar->value(150); 
  Fl_ValuatorSetStep(scb,10)      ' force step rate to 10 (slider move changes value: 100, 110, 120..)
  ' Fl_Valuator extends Fl_Widget
  Fl_WidgetSetType(scb,FL_SCROLL_HORIZONTAL)
  ' Fl_Output extends Fl_Input
  var oup = Fl_OutputNew(200,150,100,40,"Scrollbar Value:")
  Fl_Input_SetTextSize(oup,24)
  ' Fl_Input extends Fl_Widget
  Fl_WidgetSetCallbackArg(scb,@Scrollbar_CB,oup)
  ' Fl_Window extends Fl_Group 
Fl_WindowEnd(win) ' close the group 
Fl_WindowShow(win)
Fl_SetScheme("gtk+")
FL_Run()
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by jdebord »

Thank you for these explanations !

I was aware of Fl_SetScheme, but I have still many things to learn :)
Post Reply