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: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

New version is aviable with all dependencies dynamic/static for win32 and linux x86.
(source code as 4 code::blocks builds are included also)

Joshy


Overview FLTK Unicode and UTF-8 support.

new UTF8 stuff

Code: Select all

...
...
'########
'# UTF8 #
'########
'Return the number of bytes needed to encode the given UCS4 character in UTF8.
declare function Fl_utf8bytes(ucs as uinteger) as integer
' OD: returns the byte length of the first UTF-8 char sequence (returns -1 if not valid)
declare function Fl_utf8len(c as byte) as integer
' OD: returns the byte length of the first UTF-8 char sequence (returns +1 if not valid)
declare function Fl_utf8len1(c as byte) as integer
' OD: returns the number of Unicode chars in the UTF-8 string
declare function Fl_utf_nb_char(buf as const ubyte ptr, len as integer) as integer
' F2: Convert the next UTF8 char-sequence into a Unicode value (and say how many bytes were used)
declare function Fl_utf8decode(p as const zstring ptr, end as const zstring ptr, len as integer ptr) as uinteger
' F2: Encode a Unicode value into a UTF8 sequence, return the number of bytes used
declare function Fl_utf8encode(ucs as uinteger, buf as zstring ptr) as integer
' F2: Move forward to the next valid UTF8 sequence start betwen start and end
declare function Fl_utf8fwd(p as const zstring ptr, start as const zstring ptr, end as const zstring ptr) as const zstring ptr
' F2: Move backward to the previous valid UTF8 sequence start
declare function Fl_utf8back(p as const zstring ptr, start as const zstring ptr, end as const zstring ptr) as const zstring ptr
' XX: Convert a single 32-bit Unicode value into UTF16
declare function Fl_ucs_to_Utf16(ucs as const uinteger, dst as ushort ptr, dstlen as const uinteger) as uinteger
' F2: Convert a UTF8 string into UTF16
declare function Fl_utf8toUtf16(src as const zstring ptr, srclen as uinteger, dst as ushort ptr, dstlen as uinteger) as uinteger
' F2: Convert a UTF8 string into a wide character string - makes UTF16 on win32, "UCS4" elsewhere
declare function Fl_utf8towc(src as const zstring ptr, srclen as uinteger, dst as wchar_t ptr, dstlen as uinteger) as uinteger
' F2: Convert a wide character string to UTF8 - takes in UTF16 on win32, "UCS4" elsewhere
declare function Fl_utf8fromwc(dst as zstring ptr, dstlen as uinteger, src as const wchar_t ptr, srclen as uinteger) as uinteger
' F2: Convert a UTF8 string into ASCII, eliding untranslatable glyphs
declare function Fl_utf8toa (src as const zstring ptr, srclen as uinteger, dst as zstring ptr, dstlen as uinteger) as uinteger
' F2: Convert 8859-1 string to UTF8
declare function Fl_utf8froma (dst as zstring ptr, dstlen as uinteger, src as const zstring ptr, srclen as uinteger) as uinteger
' F2: Returns true if the current O/S locale is UTF8
declare function Fl_utf8locale() as integer
/' F2: Examine the first len characters of src, to determine if the input text is UTF8 or not
 NOTE: The value returned is not simply boolean - it contains information about the probable type of the src text. '/
declare function Fl_utf8test(src as const zstring ptr, len as uinteger) as integer
/' XX: return width of "raw" ucs character in columns.
 * for internal use only '/
declare function Fl_wcwidth_(ucs as uinteger) as integer
/' XX: return width of utf-8 character string in columns.
 NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252 mapping, depending on original build options '/
declare function Fl_wcwidth(src as const zstring ptr) as integer
' OD: Return true if the character is non-spacing
declare function Fl_nonspacing(ucs as uinteger) as uinteger
' F2: Convert UTF8 to a local multi-byte encoding - mainly for win32?
declare function Fl_utf8to_mb(src as const zstring ptr, srclen as uinteger, dst as zstring ptr, dstlen as uinteger) as uinteger
' OD: Convert UTF8 to a local multi-byte encoding
declare function Fl_utf2mbcs(src as const zstring ptr) as zstring ptr
' F2: Convert a local multi-byte encoding to UTF8 - mainly for win32?
declare function Fl_utf8from_mb(dst as zstring ptr, dstlen as uinteger, src as const zstring ptr, srclen as uinteger) as uinteger
#ifdef __FB_WIN32__
' OD: Attempt to convert the UTF8 string to the current locale
declare function Fl_utf8_to_locale(s as const zstring ptr, len as integer, codepage as uinteger) as zstring ptr
' OD: Attempt to convert a string in the current locale to UTF8
declare function Fl_locale_to_utf8(s as const zstring ptr, len as integer, codepage as uinteger) as zstring ptr
#endif
' The following functions are intended to provide portable, UTF8 aware versions of standard functions
' OD: UTF8 aware strncasecmp - converts to lower case Unicode and tests
declare function Fl_utf_strncasecmp(s1 as const zstring ptr, s2 as const zstring ptr, n as integer) as integer
' OD: UTF8 aware strcasecmp - converts to Unicode and tests
declare function Fl_utf_strcasecmp(s1 as const zstring ptr, s2 as const zstring ptr) as integer
' OD: return the Unicode lower case value of ucs
declare function Fl_tolower(ucs as uinteger) as integer
' OD: return the Unicode upper case value of ucs
declare function Fl_toupper(ucs as uinteger) as integer
' OD: converts the UTF8 string to the lower case equivalent
declare function Fl_utf_tolower(str as const ubyte ptr,len as integer, buf as zstring ptr) as integer
' OD: converts the UTF8 string to the upper case equivalent
declare function Fl_utf_toupper(str as const ubyte ptr, len as integer, buf as zstring ptr) as integer
' OD: Portable UTF8 aware chmod wrapper
declare function Fl_chmod(f as const zstring ptr, mode as integer) as integer
' OD: Portable UTF8 aware access wrapper
declare function Fl_access(f as const zstring ptr, mode as integer) as integer
' OD: Portable UTF8 aware stat wrapper             !!! buffer as stat ptr
declare function Fl_stat(path as const zstring ptr, buffer as any ptr) as integer
' OD: Portable UTF8 aware getcwd wrapper
declare function Fl_getcwd( buf as zstring ptr, maxlen as integer) as zstring ptr
' OD: Portable UTF8 aware fopen wrapper
declare function Fl_fopen(f as const zstring ptr, mode as const zstring ptr) as FILE ptr
' OD: Portable UTF8 aware system wrapper
declare function Fl_system(f as const zstring ptr) as integer
' OD: Portable UTF8 aware execvp wrapper
declare function Fl_execvp(file as const zstring ptr, argv as const zstring ptr ptr) as integer
' OD: Portable UTF8 aware open wrapper
declare function Fl_open(f as const zstring ptr, o as integer) as integer
' OD: Portable UTF8 aware unlink wrapper
declare function Fl_unlink(f as const zstring ptr) as integer
' OD: Portable UTF8 aware rmdir wrapper
declare function Fl_rmdir(f as const zstring ptr) as integer
' OD: Portable UTF8 aware getenv wrapper
declare function Fl_getenv(name as const zstring ptr) as zstring ptr
' OD: Portable UTF8 aware execvp wrapper
declare function Fl_mkdir(f as const zstring ptr, mode as integer) as integer
' OD: Portable UTF8 aware rename wrapper
declare function Fl_rename(f as const zstring ptr, t as const zstring ptr) as integer
' OD: Given a full pathname, this will create the directory path needed to hold the file named
declare sub      Fl_make_path_for_file(path as const zstring ptr)
' OD: recursively create a path in the file system
declare function Fl_make_path(path as const zstring ptr) as byte
...
...
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

Hello VANYA
get you the right letters on your box from this short UTF-8 test ?

Joshy

Code: Select all

#include once "fltk-c.bi"
dim as Fl_Window ptr Win = Fl_WindowNew(100,100,320,200,"UTF-8 example.")
Fl_ButtonNew(10,10,320-20,200-20,"Привет Большой Мир")
Fl_WindowShow Win
Fl_Run
Windows XP 32 bit (german).
Image
Last edited by D.J.Peters on Dec 13, 2013 12:45, edited 1 time in total.
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

D.J.Peters wrote:file: buildall.bat

Code: Select all

for %%i in (*.bas) do fbc %%i fltk.rc
pause
file: buildall_static.bat

Code: Select all

for %%i in (*.bas) do fbc -d FLTKSTATIC %%i fltk.rc
pause
thank you. I did not know this option freebasic. I would also add the option (-s gui):

for %%i in (*.bas) do fbc -s gui -d FLTKSTATIC %%i fltk.rc

to avoid the appearance of the dos window...
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

D.J.Peters wrote:Hello VANYA
get you the right letters on your box from this short UTF-8 test ?

Joshy

Code: Select all

#include once "fltk-c.bi"
dim as Fl_Window ptr Win = Fl_WindowNew(100,100,320,200,"UTF-8 example.")
Fl_ButtonNew(10,10,320-20,200-20,"Привет Большой Мир")
Fl_WindowShow Win
Fl_Run
Windows XP 32 bit (german).
Image
Display correctly in:

win 2000 pro (vm)
win xp (vm)
win 8 (64 bits)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

Coolman wrote:I would also add the option (-s gui) to avoid the appearance of the dos window...
Yes but some examples print messages in the console window.

Joshy
Last edited by D.J.Peters on Sep 26, 2013 16:27, edited 1 time in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

Image

Code: Select all

#include once "fltk-c.bi"

'test of:
' Fl_Chart           http://www.fltk.org/doc-1.3/classFl__Chart.html 
' Fl_WidgetSetType
' Fl_ChartAdd

dim as integer ww = 800
dim as integer hh = 600
dim as integer w = (ww-40) \ 3
dim as integer h = (hh-60) \ 2

dim as Fl_Window ptr Win = Fl_WindowNew(100,100, ww,hh, "Fl_Chart")

dim as Fl_chart ptr chart1 = Fl_ChartNew(10+w*0,10+h*0,w,h,"FL_CHART_BAR")
Fl_WidgetSetType chart1,FL_CHART_BAR
Fl_ChartAdd chart1,0.1,"value 0.1",FL_RED
Fl_ChartAdd chart1,1.0,"value 1.0",FL_GREEN
Fl_ChartAdd chart1,2.0,"value 2.0",Fl_RGB_Color(128,64,0)

dim as Fl_chart ptr chart2 = Fl_ChartNew(20+w*1,10+h*0,w,h,"FL_CHART_LINE")
Fl_WidgetSetType chart2,FL_CHART_LINE
Fl_ChartAdd chart2,0.1,"value 0.1",FL_RED
Fl_ChartAdd chart2,1.0,"value 1.0",FL_GREEN
Fl_ChartAdd chart2,2.0,"value 2.0",Fl_RGB_Color(128,64,0)

dim as Fl_chart ptr chart3 = Fl_ChartNew(30+w*2,10+h*0,w,h,"FL_CHART_FILL")
Fl_WidgetSetType chart3,FL_CHART_FILL
Fl_ChartAdd chart3,0.1,"value 0.1",FL_RED
Fl_ChartAdd chart3,1.0,"value 1.0",FL_GREEN
Fl_ChartAdd chart3,2.0,"value 2.0",Fl_RGB_Color(128,64,0)

dim as Fl_chart ptr chart4 = Fl_ChartNew(10+w*0,30+h*1,w,h,"FL_CHART_SPIKE")
Fl_WidgetSetType chart4,FL_CHART_SPIKE
Fl_ChartAdd chart4,0.1,"value 0.1",FL_RED
Fl_ChartAdd chart4,1.0,"value 1.0",FL_GREEN
Fl_ChartAdd chart4,2.0,"value 2.0",Fl_RGB_Color(128,64,0)

dim as Fl_chart ptr chart5 = Fl_ChartNew(30+w*2,30+h*1,w,h,"FL_CHART_PIE")
Fl_WidgetSetType chart5,FL_CHART_PIE
Fl_ChartAdd chart5,0.1,"value 0.1",FL_RED
Fl_ChartAdd chart5,1.0,"value 1.0",FL_GREEN
Fl_ChartAdd chart5,2.0,"value 2.0",Fl_RGB_Color(128,64,0)

Fl_WindowShow Win
Fl_Run
ike
Posts: 387
Joined: Jan 17, 2011 18:59

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

Post by ike »

Compiled all on winXP. Seems to work well except
Fl_browser.exe
When I click on other items in listbox blue pointer does not move?
Scrolling does work but moving pointer does not?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

Hello ike and welcome to FLTK :-)

Fl_Browser is only a powerful base class of other kinds Browser styles.

here are a "simple" Fl_Browser with colums enabled
Image
with permission from Greg Ercolano from Erco's FLTK Cheat Page

I'm sure you mean an Fl_Hold_Browser !

class Fl_Browser extends Fl_Browser_ and is an "normal" Browser for viewing items (you have to select/deselect items via FreeBASIC code)
class Fl_Select_Browser extends Fl_Browser and select/deselect items self (or multiply selected items)
class Fl_Hold_Browser extends Fl_Browser same as Fl_Select_Browser but highlight an selected item (or multiply selected items)

You can set for all this FL_Browser classes the Widget type
Fl_WidgetSetType widget, type

Joshy

(this enum's are new in current download.)

Code: Select all

enum FL_BroserType
  FL_NORMALBROWSER = 0
  FL_SELECTBROWSER
  FL_HOLDBROWSER
  FL_MULTIBROWSER
end enum
Fl_Select_Browser01.bas
Image

Code: Select all

#include once "fltk-c.bi"

'test of:
' class Fl_Select_Browser extends Fl_Browser http://www.fltk.org/doc-1.3/classFl__Select__Browser.html

dim as Fl_Window ptr Win = Fl_WindowNew(100,100,320,100,"Fl_Select_Browser")
dim as Fl_Select_Browser ptr br = Fl_Select_BrowserNew(10,10,320-20,100-20)
Fl_Browser_SetHasScrollbar br, FL_SCROLL_VERTICAL_ALWAYS

Fl_BrowserAdd br,"item 1"
Fl_BrowserAdd br,"item 2"
Fl_BrowserAdd br,"item 3"
Fl_BrowserAdd br,"item 4"
Fl_BrowserAdd br,"item 5"
Fl_BrowserAdd br,"item 6"
Fl_BrowserAdd br,"item 7"
Fl_BrowserAdd br,"item 8"

Fl_BrowserInsert br,3,"item 2b"

dim as integer nitems = Fl_BrowserGetSize(br)
if nItems>0 then
  for item as integer = 1 to nItems
    ? *Fl_BrowserGetText(br,item)
  next
end if

Fl_WindowShow Win
Fl_Run
Fl_Hold_Browser01.bas
Image

Code: Select all

#include once "fltk-c.bi"

'test of:
' class Fl_Hold_Browser extends Fl_Browser http://www.fltk.org/doc-1.3/classFl__Hold__Browser.html

dim as Fl_Window ptr Win = Fl_WindowNew(100,100,320,100,"Fl_Hold_Browser")
dim as Fl_Hold_Browser ptr br = Fl_Hold_BrowserNew(10,10,320-20,100-20)
Fl_Browser_SetHasScrollbar br, FL_SCROLL_VERTICAL_ALWAYS

Fl_BrowserAdd br,"item 1"
Fl_BrowserAdd br,"item 2"
Fl_BrowserAdd br,"item 3"
Fl_BrowserAdd br,"item 4"
Fl_BrowserAdd br,"item 5"
Fl_BrowserAdd br,"item 6"
Fl_BrowserAdd br,"item 7"
Fl_BrowserAdd br,"item 8"

Fl_BrowserInsert br,3,"item 2b"

dim as integer nitems = Fl_BrowserGetSize(br)
if nItems>0 then
  for item as integer = 1 to nItems
    ? *Fl_BrowserGetText(br,item)
  next
end if

Fl_WindowShow Win
Fl_Run
Fl_Hold_Browser02.bas
Image

Code: Select all

#include once "fltk-c.bi"

'test of:
' class Fl_Hold_Browser extends Fl_Browser http://www.fltk.org/doc-1.3/classFl__Hold__Browser.html
' Fl_WidgetSetType class, FL_MULTIBROWSER

dim as Fl_Window ptr Win = Fl_WindowNew(100,100,320,100,"Fl_Hold_Browser (multi selection)")
dim as Fl_Hold_Browser ptr br = Fl_Hold_BrowserNew(10,10,320-20,100-20)
Fl_Browser_SetHasScrollbar br, FL_SCROLL_VERTICAL_ALWAYS

Fl_WidgetSetType br, FL_MULTIBROWSER

Fl_BrowserAdd br,"item 1"
Fl_BrowserAdd br,"item 2"
Fl_BrowserAdd br,"item 3"
Fl_BrowserAdd br,"item 4"
Fl_BrowserAdd br,"item 5"
Fl_BrowserAdd br,"item 6"
Fl_BrowserAdd br,"item 7"
Fl_BrowserAdd br,"item 8"

Fl_BrowserInsert br,3,"item 2b"

dim as integer nitems = Fl_BrowserGetSize(br)
if nItems>0 then
  for item as integer = 1 to nItems
    ? *Fl_BrowserGetText(br,item)
  next
end if

Fl_WindowShow Win
Fl_Run
Fl_Hold_Browser03.bas
Image

Code: Select all

#include once "fltk-c.bi"

'test of:
' class Fl_Hold_Browser extends Fl_Browser http://www.fltk.org/doc-1.3/classFl__Hold__Browser.html
' Fl_WidgetSetType class, FL_MULTIBROWSER
' Fl_WidgetSetSelectionColor
' Fl_BrowserAdd
' Fl_BrowserInsert
' Fl_BrowserGetSize
' Fl_BrowserGetText

dim as Fl_Window ptr Win = Fl_WindowNew(100,100,320,100,"Fl_Hold_Browser (SelectionColor)")
dim as Fl_Hold_Browser ptr br = Fl_Hold_BrowserNew(10,10,320-20,100-20)
Fl_Browser_SetHasScrollbar br, FL_SCROLL_VERTICAL_ALWAYS

Fl_WidgetSetType br, FL_MULTIBROWSER
Fl_WidgetSetSelectionColor br,Fl_BLUE

Fl_BrowserAdd br,"item 1"
Fl_BrowserAdd br,"item 2"
Fl_BrowserAdd br,"item 3"
Fl_BrowserAdd br,"item 4"
Fl_BrowserAdd br,"item 5"
Fl_BrowserAdd br,"item 6"
Fl_BrowserAdd br,"item 7"
Fl_BrowserAdd br,"item 8"

Fl_BrowserInsert br,3,"item 2b"

Fl_BrowserSelect br,1
Fl_BrowserSelect br,3
Fl_BrowserSelect br,5


dim as integer nitems = Fl_BrowserGetSize(br)
if nItems>0 then
  for item as integer = 1 to nItems
    ? *Fl_BrowserGetText(br,item)
  next
end if

Fl_WindowShow Win
Fl_Run
Last edited by D.J.Peters on Dec 13, 2013 12:47, edited 2 times in total.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

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

Post by ike »

Thank you DJ.

For answer and your work!

I am following what is happening with FB and GUI tools, because I feel I will start using FB on everyday base soon
but I am a litle bit confused about GUIs: IUP or FLTK or WX or VANYAs WINDOW9. It would be nice to discuss PRO and CON for all of them.

And I also want to thank to all members for answering my (and other ppl) questions.
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

Hello D.J.Peters

thank you for the job. that would be interesting. this is an example of intercepting events in a window in a do-loop structure:

- Detection closing window
- Detection events on buttons ...
...

This library is really very interesting. it could become the ideal visual interface freebasic. eg lazarus-FreePascal I'm currently testing can freely create programs with mistletoes executables under different platforms (Windows, Linux ...). it lacks in freebasic. libraries I tested are mostly incomplete or only work on one system ...
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

Hello Coolman,
you can repeatedly call Fl_Wait() as replacement for Fl_Run()
For any event callback take a look at Fl_classEx.bas tests.

Joshy

Fl_Wait.bas

Code: Select all

dim as Fl_Window ptr Win = Fl_WindowNew(100,100, 320,200, "Fl_Window")
Fl_BoxNew 20,40,300,100,"Hello, World!"
Fl_WindowShow Win

while Fl_Wait()
  print ".";
wend
Fl_ButtonEx01.bas

Code: Select all

function ButtonHandleCB cdecl (self as any ptr,event as Fl_Event) as integer
  dim as string msg
  select case event
  case Fl_Event.FL_PUSH
    msg = "Button pushed with mouse button "
    select case Fl_EventButtons()
    case FL_BUTTON1 : msg &= "1 "
    case FL_BUTTON2 : msg &= "2 "
    case FL_BUTTON3 : msg &= "3 "
    end select
    msg & = "at position " & Fl_EventX() & "," & Fl_EventY()
    ? msg
  end select
  return 0 ' don't eat the event
end function

dim as Fl_Window   ptr Win = Fl_WindowNew(100,100,320,200)
dim as Fl_ButtonEx ptr Btn = Fl_ButtonExNew(10,10,320-20,200-20,"push me !")
Fl_ButtonExSetHandleCB Btn,@ButtonHandleCB
Fl_WindowShow Win
Fl_Run
Last edited by D.J.Peters on Oct 02, 2013 17:49, edited 2 times in total.
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

D.J.Peters wrote:Hello Coolman,
you can repeatly call Fl_Wait as replacement for Fl_Run()
For any event callback take a look at Fl_classEx.bas tests.
eg. Fl_ButtonEx01.bas, Fl_ButtonEx02.bas, Fl_ButtonEx03.bas and Fl_ButtonEx04.bas

Joshy
thank you for your response.

I looked at the official documentation. it appears that it is not obvious to transpose the sample source codes in c freebasic. I tried to find more examples for other languages ​​as basic visual basic or other ...
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

Fl_SliderEx01.bas

Code: Select all

function HandleCB cdecl (self as any ptr,event as Fl_Event) as integer
  select case event
  case FL_EVENT.FL_RELEASE , FL_EVENT.FL_DRAG
    print "HandleCB SliderValue = " & Fl_ValuatorGetValue(self)
  end select
  return 0
end function

dim as Fl_Window ptr win = Fl_WindowNew(100,100, 390,210,"Fl_SliderEx01")
dim as Fl_SliderEx ptr sld = Fl_SliderExNew( 10, 10, 30,180,"0.0-1.0")
Fl_SliderExSetHandleCB sld, @HandleCB
Fl_WindowShow win
Fl_Run
Fl_SliderEx02.bas

Code: Select all

#include once "fltk-c.bi"

'test of:
' Fl_SliderExNew()      http://www.fltk.org/doc-1.3/classFl__Slider.html

function HandleCB cdecl (self as any ptr,event as Fl_Event) as integer
  select case event
  case FL_EVENT.FL_RELEASE , FL_EVENT.FL_DRAG
    print "HandleCB SliderValue = " & Fl_ValuatorGetValue(self)
  end select
  return 0
end function

dim as Fl_Window ptr win = Fl_WindowNew(100,100, 390,210,"Fl_SliderEx02")
Fl_SliderExSetHandleCB Fl_SliderExNew( 10, 10, 30,180,"0.0-1.0"),@HandleCB
Fl_WindowShow win
Fl_Run
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

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

Post by Coolman »

interesting. it is a different style of programming ...
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

Image
FB_Image_2_FL_Image.bas

Code: Select all

#include once "fltk-c.bi"

'test of:
' Fl_RGB_ImageNew
' Fl_WidgetSetImage http://www.fltk.org/doc-1.3/classFl__Widget.html#aff29d81e64b617158472f38d2cac186e

const IMG_SIZE=101
ScreenRes IMG_SIZE,IMG_SIZE,32,,-1
dim as ubyte ptr fb_img=ImageCreate(IMG_SIZE,IMG_SIZE)
dim as ubyte ptr fb_pixels
dim as integer   bpp,pitch
ImageInfo fb_img,,,bpp,pitch,fb_pixels
Line fb_img,(0,0)-(100,100),rgba(255,0,255,0),BF 'trans rectangle
Circle fb_img,(50,50),50,rgba(255,255,  0,255),,,,F
Circle fb_img,(25,30),12,rgba(255,255,255,255),,,,F
Circle fb_img,(75,30),12,rgba(255,255,255,255),,,,F
Circle fb_img,(25,30), 7,rgba(  0,  0,  0,255),,,,F
Circle fb_img,(75,30), 7,rgba(  0,  0,  0,255),,,,F
Circle fb_img,(50,50),28,rgba(  0,  0,  0,255),1.57*2,1.57*4

' BGR 2 RGB
dim as ubyte ptr p = fb_pixels
for y as integer=0 to IMG_SIZE-1
  for x as integer=0 to IMG_SIZE-1
    swap p[x*bpp],p[x*bpp+2]
  next
  p+=pitch
next

dim as Fl_Image  ptr fl_img = Fl_RGB_ImageNew(fb_pixels, IMG_SIZE,IMG_SIZE,bpp,pitch)
dim as Fl_Window ptr win = Fl_WindowNew(100,100,IMG_SIZE*3,IMG_SIZE*2,"FB_Image_to_FL_Image.bas")
dim as Fl_Box ptr box = Fl_BoxNew( 5,5,IMG_SIZE,IMG_SIZE)
Fl_WidgetSetImage box,fl_img

Fl_WindowShow win
Fl_Run
Image
Fl_Tiled_Image.bas

Code: Select all

#include once "fltk-c.bi"

'test of:
' Fl_Tiled_ImageNew
' Fl_WidgetSetImage http://www.fltk.org/doc-1.3/classFl__Widget.html#aff29d81e64b617158472f38d2cac186e

const IMG_SIZE=101
ScreenRes IMG_SIZE,IMG_SIZE,32,,-1
dim as ubyte ptr fb_img=ImageCreate(IMG_SIZE,IMG_SIZE)
dim as ubyte ptr fb_pixels
dim as integer bpp,pitch
ImageInfo fb_img,,,bpp,pitch,fb_pixels
Line fb_img,(0,0)-(100,100),rgba(255,0,255,0),BF 'trans rectangle
Circle fb_img,(50,50),50,rgba(255,255,  0,255),,,,F
Circle fb_img,(25,30),12,rgba(255,255,255,255),,,,F
Circle fb_img,(75,30),12,rgba(255,255,255,255),,,,F
Circle fb_img,(25,30), 7,rgba(  0,  0,  0,255),,,,F
Circle fb_img,(75,30), 7,rgba(  0,  0,  0,255),,,,F
Circle fb_img,(50,50),28,rgba(  0,  0,  0,255),1.57*2,1.57*4

' BGR 2 RGB
dim as ubyte ptr p = fb_pixels
for y as integer=0 to IMG_SIZE-1
  for x as integer=0 to IMG_SIZE-1
    swap p[x*bpp],p[x*bpp+2]
  next
  p+=pitch
next

dim as Fl_Tiled_Image ptr fl_timg = Fl_Tiled_ImageNew(Fl_RGB_ImageNew(fb_pixels, IMG_SIZE,IMG_SIZE,bpp,pitch))
dim as Fl_Window ptr win = Fl_WindowNew(100,100,IMG_SIZE*6,IMG_SIZE*4,"FL_Tiled_Image.bas")
dim as Fl_Box ptr box = Fl_BoxNew( 5,5,IMG_SIZE,IMG_SIZE)
Fl_WidgetSetImage box,fl_timg

Fl_WindowShow win
Fl_Run
Last edited by D.J.Peters on Dec 13, 2013 12:49, edited 1 time in total.
Post Reply