FLTK 1.3.x C Wrapper (obsolete)

User contributed sources that have become inactive, deprecated, or generally unusable. But ... we don't really want to throw them away either.
Post Reply
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

Today I talk to my self :-)

there are no Fl_Toolbar why ?
because it's a simple Fl_Group of flat Fl_Buttons with Fl_Images,Fl_Labels and Fl_Tooltip's

there are no Fl_Statusbar why ?
because it's a simple Fl_Group with a number of Fl_Box'es and Fl_Labels also.

Ok I believe it and give it a try.

Joshy Thank you.

No problem at all.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by ike »

FB editor in 400 lines:
because it is not finished yet you have to create
project.fbp manually (make sure there is no empty lines)
first line is path for your FBC

Code: Select all

c:\fb100
test1.bas
test1.bas
test3.bas
1. create new folder and compile it there
2. create project.fbp in same folder and edit it (see sample)
3. copy test1.bas, test2.bas .... in same folder
4. run

Code: Select all

#include "file.bi"
#include once "fltk-c.bi"
#define MAX_FILES 50
DIM SHARED AS Fl_Double_Window PTR mainwin
DIM SHARED AS FL_WINDOW PTR win_CMD_CNTR

DIM SHARED AS FL_BUTTON PTR btnSEARCH 
DIM SHARED AS FL_BUTTON PTR btnCLEARSRCHRESULTS
DIM SHARED AS FL_INPUT PTR inpSEARCH_TERM
DIM SHARED AS FL_BROWSER PTR brw_SEARCH_RESULTS

DIM SHARED AS FL_BUTTON PTR btnCOMPILE 
DIM SHARED AS FL_BUTTON PTR btnRUN
DIM SHARED AS FL_INPUT PTR inpCOMPILE_COMMAND
DIM SHARED AS FL_INPUT PTR inpRUN_COMMAND
DIM SHARED AS FL_BROWSER PTR brw_COMPILE_RESULTS

DIM SHARED AS FL_BROWSER PTR brw_FREQ_SRCH_LIST

DIM SHARED AS Fl_Menu_Bar PTR Menu
DIM SHARED AS Fl_Tabs PTR tabs
DIM SHARED AS Fl_Group PTR grp(MAX_FILES)
DIM SHARED AS Fl_Text_Buffer PTR buf(MAX_FILES)
DIM SHARED AS Fl_Text_Editor PTR edt(MAX_FILES)
DIM SHARED AS FL_BROWSER PTR brw(MAX_FILES)

DIM SHARED AS STRING filenames(MAX_FILES), fbc_path
DIM SHARED AS INTEGER fcnt, whichtab

'''' calculate name for EXE file
FUNCTION CALC_EXE(txt AS STRING) AS STRING
	DIM ret AS STRING
	DIM AS INTEGER pos1, pos2
	pos1=INSTR(txt, " ")
	pos2=INSTR(txt, ".")
	ret = MID(txt, pos1+1, pos2-pos1-1) + ".exe"
	RETURN ret
END FUNCTION

'''' clean for search result list
FUNCTION kleanTXT(txt AS STRING) AS STRING
	DIM AS STRING ret
	ret = TRIM(txt)
	IF UCASE(MID(ret,1,3)) = "SUB" THEN ret = TRIM(MID(ret,4))
	IF UCASE(MID(ret,1,3)) = "VAR" THEN ret = TRIM(MID(ret,4))
	IF UCASE(MID(ret,1,6)) = "DIM AS" THEN ret = TRIM(MID(ret,7))
	RETURN ret
END FUNCTION

'''' in buffer returns TEXT for line_number
FUNCTION lineTEXT(bf AS Fl_Text_Buffer PTR, line_number AS INTEGER) AS STRING
	DIM AS STRING ret, sss
	DIM AS INTEGER CL, LL, p1, p2
	sss = *Fl_Text_BufferGetText(bf)

	LL = Fl_Text_BufferLength(bf)
	CL = Fl_Text_BufferCountLines(bf, 0, LL)

	IF line_number > CL THEN
		ret = ""    
	ELSE    
		p1 = Fl_Text_BufferSkipLines(bf, 0, line_number-1)
		p2 = Fl_Text_BufferSkipLines(bf, p1, 1)
		ret = MID (sss, p1+1, p2-p1-1)
	END IF
	RETURN ret
END FUNCTION

'''' read list of files included in project (*.bas, *.bi)
SUB readProjecttxt()
	DIM AS STRING txt
	OPEN EXEPATH() & "\project.fbp" FOR INPUT AS #1
	LINE INPUT #1, txt
	fbc_path = txt
	DO WHILE NOT EOF(1)
	LINE INPUT #1, txt
	filenames(fcnt) = txt
	fcnt+=1
	LOOP    
	CLOSE #1
	END SUB    
	SUB GEN_FILE()
	DIM AS STRING fn
	fn = fbc_path + "\fs.txt"
	IF FILEEXISTS(fn) THEN
	ELSE
		OPEN fn FOR OUTPUT AS #1
		PRINT #1, "function"
		PRINT #1, "sub"
		CLOSE #1
	END IF
	END SUB

	'''' add Free Basic path to PATH
	SUB ADD_FB_PATH()
	DIM AS STRING path = ENVIRON("PATH")
	IF (LEN(path) > 0) THEN
		path = ";" + path
	END IF
	SETENVIRON("PATH=" + fbc_path + "\" + path)
END SUB

'''''''''''''''''''''''''''''''''''''''''''
'''''''' FORM COMMAND CENTRE ''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''

'''' user clicked on frequent search list 
SUB brw_FREQ_SRCH_LIST_CLICKED CDECL (self AS FL_WIDGET PTR, brw AS ANY PTR)
	DIM AS INTEGER ii = Fl_BrowserGetValue (brw_FREQ_SRCH_LIST)
	DIM AS STRING ss = *Fl_BrowserGetText(brw_FREQ_SRCH_LIST,ii)
	Fl_Input_SetValue (inpSEARCH_TERM, ss)
END SUB

'''' user clicked on search list
SUB brw_SEARCH_RESULTS_CLICKED CDECL (self AS FL_WIDGET PTR, brw AS ANY PTR)
	DIM AS INTEGER p1,p2, poz = Fl_BrowserGetValue (brw_SEARCH_RESULTS)  
	DIM AS STRING txt = *Fl_BrowserGetText(brw_SEARCH_RESULTS,poz), s1, s2
	p1= INSTR(1,txt,"|")
	p2= INSTR(p1+1,txt,"|")
	s1=MID(txt,p1+1,p2-p1-1)
	s2=MID(txt,p2+1)
	DIM AS INTEGER ind, lin
	ind=VALINT(s1)
	lin=VALINT(s2)
	DIM AS INTEGER res = Fl_TabsSetValue(tabs, grp(ind))
	DIM AS INTEGER pp1, st, en
	IF lin = 0 THEN RETURN

	Fl_Text_DisplayScroll(edt(ind), lin, 2)
	pp1 = Fl_Text_BufferSkipLines(buf(ind), 0, lin-1)
	  
	st = Fl_Text_DisplayLineStart(edt(ind), pp1)
	en = Fl_Text_DisplayLineEnd(edt(ind), pp1, 0)
	  
	Fl_Text_BufferSelect(buf(ind), st, en)
END SUB

'''' Button SEARCH clicked
SUB btnSEARCHCB CDECL (widget AS FL_WIDGET PTR, pUserData AS ANY PTR)
	DIM AS STRING ss
	DIM AS INTEGER i, j
	DIM AS INTEGER LL, CL, poz
	DIM AS STRING txt

	ss = *Fl_Input_GetValue(inpSEARCH_TERM)
	IF ss = "" THEN RETURN
	FOR j = 0 TO fcnt-1
		Fl_BrowserAdd brw_SEARCH_RESULTS, "********** " + filenames(j) + " ***********"
		LL = Fl_Text_BufferLength(buf(j))
		CL = Fl_Text_BufferCountLines(buf(j), 0, LL)
			FOR i = 0 TO CL
				txt = lineTEXT(buf(j), i)
				IF INSTR(UCASE(txt), UCASE(ss)) > 0 THEN
					IF UCASE(txt) <> "END SUB" THEN
						Fl_BrowserAdd brw_SEARCH_RESULTS, kleanTXT(txt) + SPACE(130) + "|" +STR(j) + "|" + STR(i) 
					END IF
				END IF
			NEXT i
	NEXT j
END SUB

'''' Button Clear Search Results clicked
SUB btnCLEARSRCHRESULTSCB CDECL (widget AS FL_WIDGET PTR, pUserData AS ANY PTR)
    Fl_BrowserClear brw_SEARCH_RESULTS
END SUB

'''' Compile
SUB btnCOMPILECB CDECL (widget AS FL_WIDGET PTR, pUserData AS ANY PTR)
	DIM AS STRING kmd = *Fl_Input_GetValue(inpCOMPILE_COMMAND)
	Fl_BrowserClear brw_COMPILE_RESULTS
	Fl_BrowserAdd (brw_COMPILE_RESULTS, "Compiling: " + kmd)
	OPEN PIPE kmd FOR INPUT AS #1
	DIM AS STRING ln
	DIM AS zstring PTR lnz
	DO UNTIL EOF(1)
		LINE INPUT #1, ln
		lnz = STRPTR(ln)
		IF LEN(ln) > 0 THEN
			Fl_BrowserAdd (brw_COMPILE_RESULTS, lnz)
		END IF
	LOOP
	CLOSE #1
	Fl_BrowserAdd (brw_COMPILE_RESULTS, "Done")
END SUB

'''' Run produced EXE
SUB btnRUNCB CDECL (widget AS FL_WIDGET PTR, pUserData AS ANY PTR)
	DIM AS STRING komd 
	komd = *fl_input_getvalue(inpRUN_COMMAND)
	DIM AS INTEGER res = SHELL(komd)
END SUB
''''

SUB FRM_CMD_CNTR_CREATE()
	DIM AS STRING gg = fbc_path + "\fs.txt"
	DIM fn AS zstring PTR = STRPTR(gg)
	IF win_CMD_CNTR THEN RETURN

	win_CMD_CNTR=Fl_WindowNew(1000,700,"Command Center")
	DIM AS Fl_Tabs PTR tab1 = Fl_TabsNew(10,10,1000-20,700-20)

		DIM AS Fl_Group PTR aaa = Fl_GroupNew(10,35,1000-20,700-45,"Search")
			inpSEARCH_TERM = fl_InputNew(100,40,200,20,"Search For:")
			btnSEARCH = Fl_ButtonNew(110,67,80,25,"Search")
			Fl_WidgetSetCallback btnSEARCH, @btnSEARCHCB
			btnCLEARSRCHRESULTS = Fl_ButtonNew(210,67,80,25,"Clear")
			Fl_WidgetSetCallback btnCLEARSRCHRESULTS, @btnCLEARSRCHRESULTSCB
			brw_SEARCH_RESULTS = Fl_BrowserNew(20,100,760,580)
			Fl_WidgetSetType brw_SEARCH_RESULTS, FL_HOLDBROWSER
			Fl_WidgetSetCallbackArg brw_SEARCH_RESULTS, @brw_SEARCH_RESULTS_CLICKED, brw_SEARCH_RESULTS
			Fl_Browser_SetTextFont brw_SEARCH_RESULTS, FL_COURIER
			brw_FREQ_SRCH_LIST = Fl_BrowserNew(790,100,190,580)
			Fl_WidgetSetType brw_FREQ_SRCH_LIST, FL_HOLDBROWSER
			Fl_Browser_SetTextFont brw_FREQ_SRCH_LIST, FL_COURIER
			Fl_BrowserLoad(brw_FREQ_SRCH_LIST, fn)
			Fl_WidgetSetCallbackArg brw_FREQ_SRCH_LIST,@brw_FREQ_SRCH_LIST_CLICKED,brw_FREQ_SRCH_LIST
		Fl_GroupEnd aaa
		
		DIM AS Fl_Group PTR bbb = Fl_GroupNew(10,35,1000-10,700-35,"Compile")
			inpCOMPILE_COMMAND = fl_InputNew(100,40,300,20,"Compile")
			Fl_Input_SetTextFont inpCOMPILE_COMMAND, FL_COURIER
			DIM AS STRING kmd = TRIM(fbc_path) + "\fbc " + filenames(0)
			DIM res AS INTEGER = Fl_Input_SetValue(inpCOMPILE_COMMAND, kmd)
			
			inpRUN_COMMAND = fl_InputNew(500,40,300,20,"Run")
			
			res = Fl_Input_SetValue(inpRUN_COMMAND, CALC_EXE(kmd))

			Fl_Input_SetTextFont inpRUN_COMMAND, FL_COURIER
			btnCOMPILE = Fl_ButtonNew(110,67,80,25,"Compile")
			Fl_WidgetSetCallback btnCOMPILE, @btnCOMPILECB
			btnRUN = Fl_ButtonNew(510,67,80,25,"Run")
			Fl_WidgetSetCallback btnRUN, @btnRUNCB
			brw_COMPILE_RESULTS = Fl_BrowserNew(20,100,960,580)
			Fl_WidgetSetType brw_COMPILE_RESULTS, FL_HOLDBROWSER
			Fl_Browser_SetTextFont brw_COMPILE_RESULTS, FL_COURIER
		Fl_GroupEnd bbb

		DIM AS Fl_Group PTR ccc = Fl_GroupNew(10,35,1000-10,700-35,"Code Snippets")
		  
		Fl_GroupEnd ccc
		DIM AS Fl_Group PTR ddd = Fl_GroupNew(10,35,1000-10,700-35,"Code Help")
		  
		Fl_GroupEnd ddd
		DIM AS Fl_Group PTR eee = Fl_GroupNew(10,35,1000-10,700-35,"Form Designer")
		  
		Fl_GroupEnd eee
	Fl_GroupEnd tab1
	Fl_GroupEnd win_CMD_CNTR
END SUB

'''' Refresha ALL sub Function Lists
SUB REFRESH_SUBFUNC_LIST()
	DIM AS STRING ss
	DIM AS INTEGER i, j
	DIM AS INTEGER LL, CL, poz
	DIM AS STRING txt

	ss = "SUB"

	FOR j = 0 TO fcnt-1
		Fl_BrowserClear brw(j)
		Fl_BrowserAdd brw(j), "******* SUBS ********"
		LL = Fl_Text_BufferLength(buf(j))
		CL = Fl_Text_BufferCountLines(buf(j), 0, LL)
			FOR i = 0 TO CL
				txt = lineTEXT(buf(j), i)
				IF INSTR(UCASE(txt), UCASE(ss)) > 0 THEN
					IF UCASE(txt) <> "END SUB" THEN
						Fl_BrowserAdd brw(j), kleanTXT(txt) + SPACE(120) + "|" + STR(j) + "|" + STR(i) 
					END IF
				END IF
			NEXT i
	NEXT j


	ss = "FUNCTION"
	FOR j = 0 TO fcnt-1
		Fl_BrowserAdd brw(j), "******* FUNC ********"
		LL = Fl_Text_BufferLength(buf(j))
		CL = Fl_Text_BufferCountLines(buf(j), 0, LL)
			FOR i = 0 TO CL
				txt = lineTEXT(buf(j), i)
				IF INSTR(UCASE(txt), UCASE(ss)) > 0 THEN
					IF UCASE(txt) <> "END FUNCTION" THEN
						Fl_BrowserAdd brw(j), kleanTXT(txt) + SPACE(20) + "|" + STR(j) + "|" + STR(i)
					END IF
				END IF
			NEXT i
	NEXT j

	ss = "NEW("
	FOR j = 0 TO fcnt-1
		Fl_BrowserAdd brw(j), "******* WIDG ********"
		LL = Fl_Text_BufferLength(buf(j))
		CL = Fl_Text_BufferCountLines(buf(j), 0, LL)
			FOR i = 0 TO CL
				txt = lineTEXT(buf(j), i)
				IF INSTR(UCASE(txt), UCASE(ss)) > 0 THEN
					IF UCASE(txt) <> "ZZZZaasas" THEN
						Fl_BrowserAdd brw(j), kleanTXT(txt) + SPACE(20) + "|" + STR(j) + "|" + STR(i)
					END IF
				END IF
			NEXT i
	NEXT j
END SUB

'''''''''''''''''''''''''
''''' MENU ACTIONS ''''''
'''''''''''''''''''''''''
SUB CommandCentreFormShow CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
	Fl_WindowShow win_CMD_CNTR
END SUB

SUB Refresh1 CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
	REFRESH_SUBFUNC_LIST
END SUB

SUB Run1 CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
? "run"
END SUB

SUB NewFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    ? "Not Implemented"
    PRINT "New File"
END SUB

SUB OpenFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    ? "Not Implemented"
    RETURN

    DIM AS ZSTRING PTR file
    file = flFileChooser ("Open file", "*.bas, *.txt", EXEPATH(), 1)
    IF file <> 0 THEN PRINT "Selected file:" + *file
END SUB

SUB SaveFile CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    Fl_Text_BufferSaveFile (buf(whichtab), filenames(whichtab))
END SUB

SUB SaveAllFiles CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    DIM AS INTEGER i
    FOR i = 0 TO fcnt-1
    Fl_Text_BufferSaveFile (buf(i), filenames(i))
    NEXT i
END SUB

SUB EndProgram CDECL (widget AS Fl_Widget PTR, userData AS ANY PTR)
    END
END SUB

'''''''''''''''''''''''
'''''' MAIN FORM ''''''
'''''''''''''''''''''''
SUB MAIN_TAB_CLICKED CDECL (self AS FL_WIDGET PTR, tabs AS ANY PTR)
	VAR grp=Fl_TabsGetValue(tabs)
	DIM argmnt AS INTEGER = Fl_WidgetGetArgument(grp)
	whichtab = argmnt
	DIM AS STRING lbl = *Fl_WidgetGetLabel(grp) 
END SUB

SUB Browser_SUB_FUNC_CLICKED CDECL (self AS FL_WIDGET PTR, brw_SEARCH_RESULTS AS ANY PTR)
	DIM argmnt AS INTEGER = Fl_WidgetGetArgument(self)
	DIM AS INTEGER p1,p2, poz = Fl_BrowserGetValue (brw(argmnt))  
	DIM AS STRING txt = *Fl_BrowserGetText(brw(argmnt),poz), s1, s2
	p1= INSTR(1,txt,"|")
	p2= INSTR(p1+1,txt,"|")
	s1=MID(txt,p1+1,p2-p1-1)
	s2=MID(txt,p2+1)
	DIM AS INTEGER ind, lin
	ind=VALINT(s1)
	lin=VALINT(s2)

	DIM AS INTEGER res = Fl_TabsSetValue(tabs, grp(ind)) 'nema potrebe
	DIM AS INTEGER pp1, st, en

	IF lin = 0 THEN RETURN

	Fl_Text_DisplayScroll(edt(argmnt), lin, 2)
	pp1 = Fl_Text_BufferSkipLines(buf(argmnt), 0, lin-1)
	  
	st = Fl_Text_DisplayLineStart(edt(argmnt), pp1)
	en = Fl_Text_DisplayLineEnd(edt(argmnt), pp1, 0)
	  
	Fl_Text_BufferSelect(buf(argmnt), st, en)
END SUB

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''MAIN''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
CHDIR(EXEPATH())
readProjecttxt
ADD_FB_PATH
GEN_FILE
DIM AS INTEGER xx, yy, ww, hh, i
Fl_ScreenWorkAreaXYWH xx, yy, ww, hh

mainwin = Fl_Double_WindowNew2((ww-1000)/2, (hh-800)/2, 1000, 800, "Spartan Free Basic Editor")
Menu = Fl_Menu_BarNew (0, 0, 1000, 25)
Fl_Menu_Add (Menu, "File/New",, @NewFile())
Fl_Menu_Add (Menu, "File/Open",, @OpenFile())
Fl_Menu_Add (Menu, "File/Save",FL_CTRL+ASC("c"), @SaveFile())
Fl_Menu_Add (Menu, "File/Save All",FL_CTRL+ASC("a"), @SaveAllFiles())
Fl_Menu_Add (Menu, "File/End",, @EndProgram())
Fl_Menu_Add (Menu, "Refresh/Refresh Sub-Function List ",, @Refresh1())
Fl_Menu_Add (Menu, "Refresh/NotUsed",, @Run1())
Fl_Menu_Add (Menu, "Command/Command Centre",, @CommandCentreFormShow())

tabs = Fl_TabsNew(10,30,980,760)
Fl_WidgetSetCallbackArg tabs,@MAIN_TAB_CLICKED,tabs

FOR i = 0 TO fcnt-1
    grp(i) = Fl_GroupNew(10,30+25,980,760-45, filenames(i))
        buf(i) = Fl_Text_BufferNew()
        edt(i) = Fl_Text_EditorNew(315,30+35,670,760-45)
        brw(i) = Fl_BrowserNew(15,30+35,290,760-45)
        Fl_Text_DisplaySetBuffer edt(i), buf(i)
        Fl_Text_DisplaySetCursorColor edt(i), FL_RED
        Fl_Text_DisplaySetLinenumberFGColor edt(i), FL_BLUE
        Fl_Text_DisplayCursorStyle(edt(i), 4)

        Fl_Text_BufferLoadFile buf(i), filenames(i)
        Fl_Text_DisplaySetTextFont(edt(i), Fl_COURIER)
        Fl_Text_DisplaySetTextSize(edt(i), 15)
        Fl_Browser_SetTextFont(brw(i), Fl_COURIER)
        Fl_Browser_SetTextsize(brw(i), 15)
        Fl_WidgetSetType brw(i), FL_HOLDBROWSER
        Fl_WidgetSetCallbackArg brw(i), @Browser_SUB_FUNC_CLICKED, brw(i)
        Fl_Text_DisplaySetLinenumberWidth edt(i), 40
        Fl_WidgetSetArgument(edt(i), i)
        Fl_WidgetSetArgument(grp(i), i)
        Fl_WidgetSetArgument(brw(i), i)
    Fl_GroupEnd grp(i)
NEXT i
    
Fl_GroupEnd tabs
Fl_WidgetSetSelectionColor(tabs, FL_GREEN)
Fl_WindowEnd mainwin

Fl_GroupSetResizable (mainwin, tabs) 

FRM_CMD_CNTR_CREATE
REFRESH_SUBFUNC_LIST

Fl_WindowShow mainwin
Fl_Run
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

Hello Ike if you create an FreeBASIC editor and you will share your work with us use the project section on this forum please.
The fltk-c library section isn't the right place for that kind of unfinished code.
But examples of new commands or code snippet with problems are welcome.
I hope for your understanding.

New version bublished:

new:

Code: Select all

' During an FL_PASTE event of non-textual data, returns a pointer to the pasted data.
declare function Fl_EventClipboardData() as any ptr
' Returns the type of the pasted data during an FL_PASTE event.
' Fl_clipboard_plain_text ("text/plain") or Fl_clipboard_image ("image")
declare function Fl_EventClipboardType() as const zstring ptr

' Returns whether the current scheme is the given name. 
declare function Fl_IsScheme(byval scheme as const zstring ptr) as integer

type MessageFunc as sub(byval msg as const zstring ptr,...)
' overwrite Fl::warning()
declare sub      Fl_SetWarningMessageFunc(byval func as MessageFunc)
' overwrite Fl::error()
declare sub      Fl_SetErrorMessageFunc(byval func as MessageFunc)
' overwrite Fl::fatal()
declare sub      Fl_SetFatalMessageFunc(byval func as MessageFunc)
' FLTK calls Fl::warning() to output a warning message. 
declare sub      Fl_WarningMessage(byval msg as const zstring ptr)
' FLTK calls Fl::error() to output a normal error message. 
declare sub      Fl_ErrorMessage(byval msg as const zstring ptr)
' FLTK calls Fl::fatal() to output a fatal error message.
declare sub      Fl_FatalMessage(byval msg as const zstring ptr)
added:
Fl_MessageFunc01.bas
Fl_File_Icon02.bas
Fl_File_Icon03.bas

I reorder the large Fl class section by theme can be read as short docu now.

Joshy
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by ike »

OK DJ

I did not feel it is real project, because look at that mess with SHARED variables.

I am strugling with a very basic question. How can I pass 4 widgets to callback function.
To be more precise here is example. Press button2
How I can do this without having SHARED in1, in2, in3, bb1??

Code: Select all

#include once "fltk-c.bi"

dim shared as fl_input ptr in1, in2, in3
dim shared as fl_button ptr bb1
sub Callback cdecl (widget as FL_WIDGET ptr, pUserData as any ptr)
  print "Callback with ptr arg " & *Fl_WidgetGetLabel(widget) & " , "  & pUserData
end sub

sub Callback1 cdecl (widget as FL_WIDGET ptr, UserData as long)
  print "Callback with long arg " & *Fl_WidgetGetLabel(widget) & " , "  & UserData
end sub

sub Callback0 cdecl (widget as FL_WIDGET ptr)
  print "Callback " & *Fl_WidgetGetLabel(widget)
  dim as integer res
  res = Fl_Input_SetValue (in1, "1111")
  res = Fl_Input_SetValue (in2, "2222")
  res = Fl_Input_SetValue (in3, "3333")
  Fl_WidgetCopyLabel (bb1, "4444")
end sub

var win  = Fl_WindowNew(250,280,"Parameters")
var btn1 = Fl_ButtonNew( 10,10,70,30,"button 1")
var btn2 = Fl_ButtonNew( 90,10,70,30,"button 2")
var btn3 = Fl_ButtonNew(170,10,70,30,"button 3")

in1 = fl_inputnew(40, 140, 100, 20)
in2 = fl_inputnew(40, 170, 100, 20)
in3 = fl_inputnew(40, 200, 100, 20)
bb1 = fl_buttonnew(40, 230, 100, 20, "AAA")

Fl_WidgetSetCallbackArg  btn1,@Callback,btn1
Fl_WidgetSetCallback0    btn2,@Callback0
Fl_WidgetSetCallback1Arg btn3,@Callback1,123


Fl_WindowShow win
Fl_Run
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

Code: Select all

#include once "fltk-c.bi"

sub ButtonCB cdecl (byval self as FL_WIDGET ptr,byval arg as any ptr)
  dim as Fl_Input ptr ptr in = arg
  Fl_Input_SetValue  in[0], "1111"
  Fl_Input_SetValue  in[1], "2222"
  Fl_Input_SetValue  in[2], "3333"
end sub
'
' main
'
dim as Fl_Input ptr in(2)
var win  = Fl_WindowNew(250,280,"Parameters")
in(0) = Fl_InputNew(40, 140, 100, 20)
in(1) = Fl_InputNew(40, 170, 100, 20)
in(2) = Fl_InputNew(40, 200, 100, 20)
var btn2 = Fl_ButtonNew( 90,10,70,30,"button 2")
Fl_WidgetSetCallbackArg btn2,@ButtonCB,@in(0)
Fl_WindowShow win
Fl_Run
Boris the Old
Posts: 139
Joined: Feb 04, 2011 20:34
Location: Ontario, Canada

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by Boris the Old »

@Joshy

Is there an FLTK function that can test a widget ptr to see if the widget exists and is still valid?

Code: Select all

  If Fl_WidgetIsValid(WidgetPtr) Then
    "process the widget"
  Else
    "the widget no longer exists"
  End If
Thanks, Rod
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by ike »

@Boris

Look at
Fl_Group line 3375 in fltk-c.bi

Searches the child array for the widget and returns the index
declare function Fl_GroupFind(byval grp as Fl_Group ptr,byval wgt as const Fl_Widget ptr) as integer
jdebord
Posts: 554
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by jdebord »

I have updated the french tutorial to take into account the change of version. The only modified file is:
http://sourceforge.net/projects/fbmath/ ... _intro.htm
Boris the Old
Posts: 139
Joined: Feb 04, 2011 20:34
Location: Ontario, Canada

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by Boris the Old »

@ike

Thanks, that should give me what I need.

We're in the middle of converting all our PowerBasic/EZGUI code and PureBasic code to FB. Luckily we're heavily into OOP, so the conversion is going well and we've been able to convert our GUI class to FLTK without too much trouble.

Rod
SARG
Posts: 1877
Joined: May 27, 2005 7:15
Location: FRANCE

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by SARG »

Hi D.J.P.

Playing with the highlighting function in Fl_Text_Editor03.bas I found some issues

In sub Highlight the last character of the string is not taken in account
I suggest to remove lenght-=1 in the line below.

Code: Select all

dim as ubyte   c = Text[e]':length-=1


Also in sub Highlight, 2 side by side quotes are not handled correctly
I suggest to replace the handling of strings by these lines.

Code: Select all

   ' string ?
    if c=34 Then
    	Dim As Long cpt
      FILLSTYLE(STYLE_STRING)
      cpt=1
      while cpt andalso c<>&H0A andalso length>0
      	If c=34 Then
      		FILLSTYLE(STYLE_STRING)
      		cpt=1-cpt
      		If c=34 Then cpt=1-cpt:FILLSTYLE(STYLE_STRING)
      	Else
      		FILLSTYLE(STYLE_STRING)
      	EndIf
      Wend
    end if
Boris the Old
Posts: 139
Joined: Feb 04, 2011 20:34
Location: Ontario, Canada

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by Boris the Old »

Is it possible to generate events, from within code, that can be directed to specific widgets?

PureBasic and various GUI packages allow standard and custom events to be injected into the message queue under program control. I need something like:

Code: Select all

  PostEvent(pWidgetPtr, iEVENT_NUMBER)
Rod
SARG
Posts: 1877
Joined: May 27, 2005 7:15
Location: FRANCE

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by SARG »

Hi,

In the fl_menu class a lot of functions return index but as the function to get the address of the array is missing this data is not very usefull.

Could you add it. Below an example of using extracts from the fltk doc.
const Fl Menu Item Fl Menu ::menu ( ) const [inline]
Returns a pointer to the array of Fl Menu Items.
This will either be the value passed to menu(value) or the private copy.
See Also
size() – returns the size of the Fl Menu Item array.
Example: How to walk the array:
for ( int t=0; t<menubar->size(); t++ )
{
// walk array of items
const Fl Menu Item &item = menubar->menu()[t]; // get each item
fprintf(stderr, "item #%d -- label=%s, value=%s type=%snn",t,
item.label() ? item.label() : "(Null)", // menu terminators have NULL labels
(item.flags & FL MENU VALUE) ? "set" : "clear", // value of toggle or radio items
(item.flags & FL SUBMENU) ? "Submenu" : "Item"); // see if item is a submenu or actual item
}
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by D.J.Peters »

jdebord wrote:I have updated the french tutorial to take into account the change of version. The only modified file is:
http://sourceforge.net/projects/fbmath/ ... _intro.htm
Thank you.

Joshy
SARG wrote:Playing with the highlighting function in Fl_Text_Editor03.bas I found some issues
It was only a test of new commands not a full version of an working editor.

Joshy
Boris the Old wrote:Is it possible to generate events, from within code, that can be directed to specific widgets?
Sure Fl_WidgetHandle(widget,event)

Joshy

Code: Select all

fltk-c.bi:2356: declare function Fl_Handle(byval event as Fl_Event,byval win as Fl_Window ptr) as integer
fltk-c.bi:2688: declare function Fl_WidgetHandle(byval wgt as Fl_Widget ptr,byval event as Fl_Event) as integer
fltk-c.bi:2795: declare function Fl_BoxHandle(byval box as Fl_Box ptr,byval e as Fl_Event) as integer
fltk-c.bi:2813: declare function Fl_ButtonHandle(byval btn as Fl_Button ptr,byval event as Fl_Event) as integer
fltk-c.bi:2837: declare function Fl_Repeat_ButtonHandle(byval btn as Fl_Repeat_Button ptr,byval ev as Fl_Event) as integer
fltk-c.bi:2846: declare function Fl_Return_ButtonHandle(byval btn as Fl_Return_Button ptr,byval ev as Fl_Event) as integer
fltk-c.bi:2860: declare function Fl_Light_ButtonHandle(byval btn as Fl_Light_Button ptr,byval ev as Fl_Event) as integer
fltk-c.bi:3055: declare function Fl_InputHandle(byval ip as Fl_Input ptr,byval event as Fl_Event) as integer
fltk-c.bi:3065: declare function Fl_File_InputHandle(byval fip as Fl_File_Input ptr,byval event as Fl_Event) as integer
fltk-c.bi:3103: declare function Fl_Secret_InputHandle(byval sip as Fl_Secret_Input ptr,byval event as Fl_Event) as integer
fltk-c.bi:3298: declare function Fl_Menu_ButtonHandle(byval mb as Fl_Menu_Button ptr,byval event as Fl_Event) as integer
fltk-c.bi:3307: declare function Fl_Menu_BarHandle(byval mb as Fl_Menu_Bar ptr,byval event as Fl_Event) as integer
fltk-c.bi:3317: declare function Fl_ChoiceHandle(byval c as Fl_Choice ptr,byval event as Fl_Event) as integer
fltk-c.bi:3409: declare function Fl_DialHandle(byval dial as Fl_Dial ptr,byval event as Fl_Event) as integer
fltk-c.bi:3444: declare function Fl_SliderHandle(byval sl as Fl_Slider ptr,byval event as Fl_Event) as integer
fltk-c.bi:3492: declare function Fl_ScrollbarHandle(byval sb as Fl_Scrollbar ptr,byval event as Fl_Event) as integer
fltk-c.bi:3508: declare function Fl_Value_SliderHandle(byval sl as Fl_Value_Slider ptr,byval event as Fl_Event) as integer
fltk-c.bi:3531: declare function Fl_Value_InputHandle(byval vi as Fl_Value_Input ptr,byval event as Fl_Event) as integer
fltk-c.bi:3559: declare function Fl_Value_OutputHandle(byval vo as Fl_Value_Output ptr,byval event as Fl_Event) as integer
fltk-c.bi:3585: declare function Fl_GroupHandle(byval grp as Fl_Group ptr,byval ev as Fl_Event) as integer
fltk-c.bi:3649: declare function Fl_TileHandle(byval til as Fl_Tile ptr,byval event as Fl_Event) as integer
fltk-c.bi:3661: declare function Fl_ScrollHandle(byval sc as Fl_Scroll ptr,byval event as Fl_Event) as integer
fltk-c.bi:3686: declare function Fl_Browser_Handle(byval br as Fl_Browser_ ptr,byval event as Fl_Event) as integer
fltk-c.bi:4041: declare function Fl_SpinnerHandle(byval spi as Fl_Spinner ptr,byval e as Fl_Event) as integer
fltk-c.bi:4269: declare function Fl_TabsHandle(byval tbs as Fl_Tabs ptr,byval event as Fl_Event) as integer
fltk-c.bi:4492: declare function Fl_Text_DisplayHandle(byval td as Fl_Text_Display ptr,byval event as Fl_Event) as integer
fltk-c.bi:4635: declare function Fl_Text_EditorHandle(byval te as Fl_Text_Editor ptr,byval e as Fl_Event) as integer
fltk-c.bi:4716: declare function Fl_TreeHandle(byval tr as Fl_Tree ptr,byval e as Fl_Event) as integer
fltk-c.bi:4906: declare function Fl_WindowHandle(byval win as Fl_Window ptr,byval event as Fl_Event) as integer
fltk-c.bi:5057: declare function Fl_Gl_WindowHandle(byval glwin as Fl_Gl_Window ptr,byval ev as Fl_Event) as integer
Last edited by D.J.Peters on Jan 01, 2015 18:36, edited 1 time in total.
Boris the Old
Posts: 139
Joined: Feb 04, 2011 20:34
Location: Ontario, Canada

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by Boris the Old »

D.J.Peters wrote:
Boris the Old wrote:Is it possible to generate events, from within code, that can be directed to specific widgets?
Sure Fl_Handle(widget,event)]
Thanks very much Joshy. Our lack of C experience makes some of this an up hill battle. :)

We're actually making good progress using your wrapper. We're wrapping your wrapper in our own GUI class so that we don't have to scatter FLTK code throughout our applications. And since we don't normally use ZStrings in our code we can isolate its use in one place.

FLTK is working out better than I expected. It's flexible, fast, and easy to use. Thanks again for all the work you've done in putting the wrapper together.

Rod
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK C Wrapper (Fast Light Toolkit v 1.3.3)

Post by ike »

What I am doing wrong here:

Code: Select all

dim label1 as string
label1 = exepath()
dim as zstring ptr nn  = strptr(label1)
? *nn
mainwin = Fl_Double_WindowNew2((ww-1000)/2, (hh-800)/2, 1000, 800, nn)
I want to create main window with label = exepath
Post Reply