FLTK 1.3.x C Wrapper (obsolete)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby tinycla » Jun 05, 2015 14:10

I'm developing a software for my wife in FreeBasic & Fltk, and I've found a little problem.
First of all, I must say that the more I use Fltk, the more I like it. It's very fast, and easy (well, once you find your way in the documentation...) and makes very simple to develop a good UI.
The problem is about accented letters. I'm italian, so the program I'm writing uses the italian language, where there are plenty of accented letters (à, è, ù and so on). When I use such a letters in the window, all is OK, the letters display in the right way. But when I try to use an accentend letter in a Fl_ErrorMessage, for example, in Windows the letter is wrong. In Linux all is OK (I'm developing the program both in Linux, at home, and in Windows7, at work, in my free time).
The source files are saved as Unicode, and the program runs well on both OSes, except for such Fl_ErrorMessage.
Anybody can suggest where to search for solving the problem?
D.J.Peters
Posts: 8123
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jun 05, 2015 16:38

ike wrote:why drawarc2 does not work here. Thx
May be a bug in FLTK (not in the wrapper)
however you can use DrawCircle() or DarwArc()

Joshy
Last edited by D.J.Peters on Jun 05, 2015 17:00, edited 1 time in total.
D.J.Peters
Posts: 8123
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jun 05, 2015 16:57

tinycla wrote:... But when I try to use an accentend letter in a Fl_ErrorMessage, for example, in Windows the letter is wrong. In Linux all is OK...
I don't know looks OK here.

Joshy
Image
Last edited by D.J.Peters on Oct 03, 2017 4:13, edited 1 time in total.
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby tinycla » Jun 05, 2015 20:03

I've solved the problem using FlAlert instead of Fl_ErrorMessage. I've seen that under Linux Fl_ErrorMessage doesn't display a messagebox but write the error in console. FlAlert does what I need.
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Using Fl_Table

Postby tinycla » Jun 05, 2015 20:06

Another question: I'm using an Fl_Table, which contains an Fl_Input. I'm searching for a way to get the value of this Fl_Input for all the rows when user push a button (not in the Fl_Input event). How could I do this?
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby ike » Jun 05, 2015 21:18

Joshi,

May be a bug in FLTK (not in the wrapper)
however you can use DrawCircle() or DarwArc()



It work if it is inside:

DrawBeginComplexPolygon

DrawEndComplexPolygon
(but it is not what I want to do)

Same apply for DrawCurve (Bezxier curve)

DrawCurve and DrawArc2 take DOUBLE as parameter

and DrawLine, DrawArc take INTEGER as parameter
badidea
Posts: 2120
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby badidea » Jun 06, 2015 14:48

Question, there must be an easier way then this to get the text of an Fl_Choice selection?

Code: Select all

sub ChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  print *Fl_Menu_GetMenu(cho)[Fl_ChoiceGetValue(cho)].text
end sub
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby ike » Jun 06, 2015 16:27

dim as integer indx = Fl_ChoiceGetValue (choice1)
? indx
D.J.Peters
Posts: 8123
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jun 06, 2015 16:33

Way you mean it must be an easier way ?

Joshy

Code: Select all

#include once "fltk-c.bi"

' test of:
' Fl_Choice    http://www.fltk.org/doc-1.3/classFl__Choice.html

sub ChoiceCB cdecl (byval self as Fl_Widget ptr,byval cho as any ptr)
  ' get parent of the widget
  var win = Fl_WidgetWindow(self)
  ' get index of selected item
  var ind = Fl_ChoiceGetValue(cho)
  ' copy label from item to window caption
  Fl_WindowCopyLabel win,Fl_Menu_GetMenu(cho)[ind].text
end sub
'
' main
'
var win = Fl_WindowNew(640,480,"Fl_Choice")
var cho = Fl_ChoiceNew(280,240,128,24)
' add some items
Fl_Menu_Add3 cho,"ASM/FASM|ASM/TASM|ASM/MASM|ASM/NASM|ASM/WASM|ASM/YASM"
Fl_Menu_Add3 cho,"BASIC/Interpreter/ScriptBasic|BASIC/Compiler/FreeBASIC"
Fl_Menu_Add3 cho,"BASIC/Interpreter/SdlBasic|BASIC/Interpreter/Yabasic"
Fl_Menu_Add3 cho,"BASIC/Compiler/PureBasic|BASIC/Compiler/PowerBASIC"
Fl_Menu_Add3 cho,"GUI/GTK+|GUI/FLTK|GUI/QT|GUI/WX"
' select first iterm
Fl_ChoiceSetValue cho,0
' add standard callback
Fl_WidgetSetCallbackArg cho,@ChoiceCB,cho
' put window on desktop
Fl_WindowShow win
Fl_Run
badidea
Posts: 2120
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby badidea » Jun 06, 2015 16:46

Yes, that was the example I used, was looking for something shorter like: * Fl_ChoiceGetText(cho)
But, I realized that I will probably have data I filled the menu / choice box with anyway in memory.
Then it will be something like TextArray(Fl_ChoiceGetValue(cho)) and if I use the text elsewhere in the GUI, I can use this Fl_WindowCopyLabel.
D.J.Peters
Posts: 8123
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jun 06, 2015 19:03

@ike you are right isn't a bug
you mixed fast integer drawing with complex pecision drawing.

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

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby ike » Jun 06, 2015 19:35

Strange:

DrawStr "FLTK", x1+140, y1+150 'CRASH

DrawStrRot(0, "FLTK", x1+200, y1+100) 'CRASH

DrawStrRot(1, "FLTK", x1+200, y1+100) 'WORKS


and once i use DrawStrRot(1, .....

this will work well:

DrawStr "FLTK", x1+140, y1+150

===========================================






Code: Select all

#include once "fltk-c.bi"

namespace T
DIM SHARED AS Fl_BoxEx PTR box1
DIM AS Fl_Window PTR win
end namespace
'#############################################################
FUNCTION DrawCB1 CDECL(box AS ANY PTR) AS INTEGER
dim as integer x1 = Fl_WidgetGetX(T.box1)
dim as integer y1 = Fl_WidgetGetY(T.box1)
dim as integer w = Fl_WidgetGetW(T.box1)
dim as integer h = Fl_WidgetGetH(T.box1)
dim as integer i

drawpushclip(x1,y1,w,h)
DrawRectFillColor x1, y1, w, h, Fl_BLACK
'''''''
DrawSetColor FL_RED : DrawSetLineStyle FL_SOLID, 2
DrawLine (x1+20, y1+20, x1+100, y1+100)

DrawSetLineStyle FL_SOLID OR FL_CAP_ROUND, 10
DrawLine (x1+40, y1+20, x1+120, y1+100)

DrawSetLineStyle FL_SOLID OR FL_CAP_FLAT, 10
DrawLine (x1+60, y1+20, x1+140, y1+100)

DrawSetColor FL_WHITE : DrawSetLineStyle FL_SOLID OR FL_CAP_FLAT, 10
DrawLine2 (x1+20, y1+120, x1+150, y1+150, x1+350, y1+444) 'Draws a line from (x,y) to (x1,y1) and another from (x1,y1) to (x2,y2)

DrawSetColor Fl_MAGENTA : DrawSetLineStyle FL_SOLID OR FL_CAP_ROUND, 10
DrawLine2 (x1+20, y1+220, x1+150, y1+250, x1+350, y1+544) 'Draws a line from (x,y) to (x1,y1) and another from (x1,y1) to (x2,y2)

DrawSetColor Fl_CYAN :DrawSetLineStyle FL_SOLID OR FL_CAP_ROUND, 2
DrawLoop (x1+20, y1+320, x1+150, y1+350, x1+350, y1+644)

DrawSetColor FL_BLUE : DrawSetLineStyle FL_SOLID OR FL_CAP_ROUND, 1 
DrawRect(x1+400, y1+100, 60, 60)
DrawRectColor(x1+400, y1+200, 60, 60, FL_YELLOW)
DrawSetColor Fl_DARK_GREEN
DrawRectFill(x1+400, y1+300, 60, 60)
DrawRectFillColor(x1+400, y1+400, 60, 60, Fl_DARK_MAGENTA)


DrawSetColor FL_BLUE: DrawSetLineStyle(FL_SOLID, 2)
DrawRect(x1+500, y1+100, 60, 60)
DrawSetColor FL_RED: DrawSetLineStyle(FL_SOLID, 2)
DrawArc(x1+500, y1+100, 60, 60, 0, 270)

DrawSetColor FL_GREEN: DrawSetLineStyle(FL_SOLID, 2)
DrawCircle (x1+700,y1+100, 20)
DrawCircle (x1+700,y1+100, 30)
DrawCircle (x1+700,y1+100, 40)


DrawSetColor FL_GREEN: DrawSetLineStyle(FL_SOLID, 1)
DrawPolygon (x1+800, y1+200, x1+650, y1+300, x1+700, y1+400) 'Fills a 3-sided polygon. The polygon must be convex.

DrawSetColor FL_RED
DrawPolygon2 (x1+800, y1+500, x1+650, y1+600, x1+700, y1+700, x1+600, y1+550) 'Fills a 4-sided polygon. The polygon must be convex.


DrawSetColor FL_RED
'DrawSetRGBColor 0, 255, 255
DrawStr "FLTK", x1+140, y1+150               'CRASH

'DrawStrRot(0, "FLTK", x1+200, y1+100)       'CRASH
DrawStrRot(1, "FLTK", x1+200, y1+100)        'WORKS


drawpopclip()
RETURN 1
END FUNCTION

'marker01
'#############################################################
SUB FormTCREATE()
IF T.win THEN RETURN
DIM AS INTEGER xx,yy,ww,hh
Fl_ScreenWorkAreaXYWH xx, yy, ww, hh
T.win = Fl_Double_windowExNew2((ww-1000)/2, (hh-800)/2, 1000, 800, "Form Caption")
Fl_WindowSetModal (T.win)
T.box1 = Fl_BoxExNew(70, 20, 880, 680, "T")
Fl_BoxExSetDrawCB T.box1, @DrawCB1

'marker00
Fl_GroupEnd T.win
END SUB


SUB FormTSHOW()
Fl_WindowShow T.win
END SUB


FormTCREATE
FormTSHOW
Fl_Run
D.J.Peters
Posts: 8123
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jun 06, 2015 19:58

@ike you must set a font before !!!

Code: Select all

#include once "fltk-c.bi"

'test of:
' DrawSetFont
' DrawStr
' DrawStrRot

function DrawCB cdecl (byval self as any ptr) as long
  dim as integer w =Fl_WidgetGetW(self)
  dim as integer h =Fl_WidgetGetH(self)
  dim as integer deg = 180
  for font as integer = 0 to 15
    dim as integer size=6+rnd*70
    DrawSetFont font,size
    for i as integer = 0 to 1
      DrawSetRGBColor rnd*255,rnd*255,rnd*255
      dim as integer x=rnd*w
      dim as integer y=rnd*h
      if i and 1 then
        DrawStr "DrawStr()",x,y
      else
        DrawStrRot deg,"DrawStrRot()",x,y
        deg+=5
      end if
    next
  next
  return 1
end function
'
' main
'
' for drawing it's a good idea to use a flicker free double buffered window
var win = Fl_Double_WindowNew(640,480,"Drawing02.bas resize me ...")
var box = Fl_BoxExNew(5,5,630,470)
Fl_BoxExSetDrawCB box,@DrawCB
Fl_GroupSetResizable win,box
Fl_WindowShow win
Fl_Run
badidea
Posts: 2120
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby badidea » Jun 06, 2015 20:12

I think I am getting too old to learn something new. Which which pretty bad at the age of 37 :-)

So I wanted a 'checkbox' GUI-element and checked by default. All GUI-toolkits have checkboxes, so shouldn't be too hard.

Well, I couldn't find a checkbox example in the folder, so I googled for 'FLTK checkbox'. Turns out it is called 'CheckButton'. Ok, lets use that.

I look in the example folder for something like fl_check_button.bas. No hit, luckily the tutorial on the German website shows an checkButton example.

Code: Select all

Dim Shared As Fl_Check_Button Ptr Button_check
Button_check = Fl_Check_ButtonNew (20, 170, 100, 20, "Checkbutton")

So, copy-paste, and I have a checkButton. Now make it checked... No example, so I go to the FLTK documentation website. The Fl_Check_Button Class does not have a member or property for that listed, so I look for the inherited stuff. Fl_Light_Button, also not much. For Fl_button I see clear(), set() and value(). Looks good.

So I try:
Button_check.set() ... error, wait it is a pointer, lets try
Button_check->set() ... error, lets try value() function
Button_check->value(1) ... error, maybe setValue?
Button_check->setValue(1) ... error, this is not going anywhere, think!

Ah, Fl_Choice uses Fl_ChoiceSetValue(cho, 0) to set the selection, maybe something similar exists for Fl_Check_Button. Lets look in the fltk-c.bi file for fl_CheckButtonSet... Nothing. Looking at the documentation website again, Looking for examples in the folder, doing various Google searches... not helping. Back to fltk-c.bi, go through the file slowly... Wait maybe Fl_ButtonSet? Yes! and even better Fl_ButtonSetValue().

Code: Select all

#include once "fltk-c.bi"

sub ChoiceCB cdecl (byval self as Fl_Widget ptr,byval pChoice as any ptr)
   print *Fl_Menu_GetMenu(pChoice)[Fl_ChoiceGetValue(pChoice)].text
end sub

sub CheckCB cdecl (byval self as Fl_Widget ptr, byval pButton as any ptr)
   print Fl_ButtonGetValue(pButton)
end sub

'Window
dim as Fl_Window ptr pWin
pWin = Fl_WindowNew(320, 200, "Window title!")

'Drop-down list
dim as Fl_Choice ptr pChoice
pChoice = Fl_ChoiceNew(10, 10, 200, 25)
Fl_Menu_Add(pChoice, "Random text here")
Fl_Menu_Add(pChoice, "Even more nonsense")
Fl_ChoiceSetValue(pChoice, 0)
Fl_WidgetSetCallbackArg(pChoice, @ChoiceCB, pChoice)

'Checkbox
dim As Fl_Check_Button ptr pButtonCheckR
pButtonCheckR = Fl_Check_ButtonNew(10, 40, 200, 25, "Check this")
Fl_ButtonSetValue(pButtonCheckR, 1)
Fl_WidgetSetCallbackArg(pButtonCheckR, @CheckCB, pButtonCheckR)

Fl_WindowShow(pWin)
Fl_Run

But my question is, am I approaching this inefficient? Am I missing something? Or is this slowly learning something new inevitable? In general, I want to do X in language Y without toolkit Z. How do I do that when documentation only seems to talk about A and B?

Anyway, I'll continue playing with FLTK. In reality, posting this took longer then the actual problem. FLTK seems a good match for FreeBASIC. 'Simple' and lightweight.
D.J.Peters
Posts: 8123
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jun 06, 2015 22:24

@badidea if you can't find an example first take a look inside of fltk-c.bi and try to get the parent from the widget you will use.

'# class Fl_Button extends Fl_Widget #
'# class Fl_Light_Button extends Fl_Button #
'# class Fl_Check_Button extends Fl_Light_Button #

That means you can use all commands from Fl_Widget and Fl_Button with your Fl_Check_Button also.

e.g. Fl_WidgetGetLabel(), Fl_ButtonGet/SetValue() ...

Joshy

Code: Select all

#include once "fltk-c.bi"

sub CheckCB cdecl (byval self as FL_WIDGET ptr,byval CheckButton as any ptr)
  print *Fl_WidgetGetLabel(self) & "[" & Fl_ButtonGetValue(CheckButton) & "]"
end sub

'
' main
'
var win = Fl_WindowNew(320,40,"Fl_CheckButton01.bas")

var cb1 = Fl_Check_ButtonNew( 10,10,90,30,"Button 1")
var cb2 = Fl_Check_ButtonNew(110,10,90,30,"Button 2")
var cb3 = Fl_Check_ButtonNew(210,10,90,30,"Button 3")

Fl_WidgetSetCallbackArg cb1,@CheckCB,cb1
Fl_WidgetSetCallbackArg cb2,@CheckCB,cb2
Fl_WidgetSetCallbackArg cb3,@CheckCB,cb3

Fl_WindowShow Win
Fl_Run

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 2 guests