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
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 »

Imortis wrote:... but the second has an underscore between Input_ and ... Menu_ ... I only ask because it seems like no matter which I guessed when working with a widget for the first time, I guessed wrong.
The answer is simple take a look in file: "fltk-main.bi"

you can read this:

Fl_Extends1(Menu_,Widget)
...
Fl_Extends1(Input_,Widget)

that means Fl_Menu_ (underscrore) and Fl_Input_ (underscrore) are classes of it's own.

For example the Fl_Input widget extends Fl_Input_ class
Fl_Extends2(Input,Input_,Widget)

If you get/set properties of the the Fl_Input_ (underscrore) class you have to use the names of the properties with an underscore
but if you use get/set properties of the the Fl_Input class no extras underscrore are needed.

No magic at all ;-)

For all readers sorry for the trouble and my bad english description about the callback stuff.

Here are the C++ code if you use callbacks of any extend version of any Fl_Widget like Fl_ButtonEx for example.

If you return 0 or do not have the draw callback implemented Fl_Button::draw() will be called inside the C++ wrapper.
If you return 0 or do not have the resize callback implemeneted Fl_Button::resize() will be called inside the C++ wrapper.
If you have implemented the handle callback your return value will be used otherwise the return value of Fl_Box::handle() inside the C++ wrapper will be used.

Code: Select all

#define ExtendEx(name) \
class name##Ex : public name { \
  void draw() {\
    int ret=0; \
    if(drawcb) ret=drawcb(this); \
    if(!ret) name::draw(); \
  } \
  \
  int handle(int event) { \
    if(handlecb) \
      return handlecb(this, event); \
    else \
      return name::handle(event); \
  } \
  void resize(int X, int Y, int W, int H){ \
    int ret=0; \
    if(resizecb) ret=resizecb(this,X,Y,W,H); \
    if(!ret) name::resize(X,Y,W,H); \
  } \
  ...
Here are the C++ code if you use callbacks of the Fl_WidgetEx.

Only if you implemented/overwrote the draw callback it will be called from the c++ wrapper.
If you implemented/overwrote the resize callback it will be called if you return 0 Fl_Widget::resize() will be called for you.
Only if you implemented/overwrote the handle callback it will be called from the c++ wrapper and your return value is delegated to FLTK.

Joshy

Code: Select all

class Fl_WidgetEx : public Fl_Widget {
  void draw() {
    if(drawcb) drawcb(this);
  }

  int handle(int event) {
    int ret=0;
    if (handlecb) ret=handlecb(this, event);
    return ret;
  }

  void resize(int X, int Y, int W, int H){
    int ret=0;
    if(resizecb) ret=resizecb(this,X,Y,W,H);
    if(!ret) Fl_Widget::resize(X,Y,W,H);
  }
Boris the Old
Posts: 139
Joined: Feb 04, 2011 20:34
Location: Ontario, Canada

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by Boris the Old »

JohnK wrote:That is interesting, as i have always wanted a rapidq like gui library, that would use fltk under the hood. I didn't start it because it would be a LOT of work. If you method is simple then great.
It's not a lot of work if you restrict yourself to replicating only those features that you use. Over the years, I've developed a very simple structure for my applications that keeps the number of widget types to a minimum. My applications consist of a single window that contains a menu panel down the left side, a status panel along the bottom, and a task panel that occupies the rest of the window.

The status panel contains a number of simple boxes for displaying messages.

The menu panel contains a Tree widget that activates items in the task panel.

The task panel contains a Wizard widget. Each page in the wizard widget represents a program which is linked to an entry in the menu tree. Each program page is also implemented as a Wizard widget, with its pages representing the program screens. These screens contain the actual buttons, boxes, etc.

As you can see, I use very few widget types -- and also a very small subset of Joshy's FLTK wrapper.

To isolate my application code from FLTK, and to avoid using ZStrings in my application code, I put all the FLTK calls that I use in a single namespace. Here's a sample:

Code: Select all

'
'-----------------------------------------------
'  Procedure 54 : set the window caption text
BeginExternalSubroutine (subWindowCaption) _
    BPtr (bvpWidgetRef) _                                                                          ' 16882 : fltk widget reference
  , BVal (bvsCaption,                       typString) _                                           ' 15328 : caption text
  ParmEnd
'
'
  Fl_WindowCopyLabel                        (bvpWidgetRef, StrPtr(bvsCaption))
'
EndExternalSubroutine
'
'-----------------------------------------------
'  Procedure 55 : create a window
BeginExternalFunction (funWindowCreate) _
    BVal (bviBaseLeft,                      typInt32) _                                            ' 16413 : nominal left position of the gui object (pixels)
  , BVal (bviBaseTop,                       typInt32) _                                            ' 16414 : nominal top position of the gui object (pixels)
  , BVal (bviBaseWidth,                     typInt32) _                                            ' 16415 : nominal width of the gui object (pixels)
  , BVal (bviBaseHeight,                    typInt32) _                                            ' 16416 : nominal height of the gui object (pixels)
  ParmReturn (typPointer)
'
  LocalPointer (pWidgetRef)                                                                        ' 16882 : fltk widget reference
'
  pWidgetRef                                = Fl_Double_WindowNew2 (bviBaseLeft, bviBaseTop, bviBaseWidth, bviBaseHeight)
  prpAppWidgetRef                           = pWidgetRef                                           ' save the reference to the main application window widget
  Return                                    pWidgetRef
'
EndExternalFunction
'
'-----------------------------------------------
'  Procedure 56 : begin the window design
BeginExternalSubroutine (subWindowDesignBegin) _
    BPtr (bvpWidgetRef) _                                                                          ' 16882 : fltk widget reference
  ParmEnd
'
'
  Fl_WindowBegin                            (bvpWidgetRef)
'
EndExternalSubroutine
'
'-----------------------------------------------
'  Procedure 57 : end the window design
BeginExternalSubroutine (subWindowDesignEnd) _
    BPtr (bvpWidgetRef) _                                                                          ' 16882 : fltk widget reference
  ParmEnd
'
'
  Fl_WindowEnd                              (bvpWidgetRef)
'
EndExternalSubroutine
'
'-----------------------------------------------
'  Procedure 58 : destroy a window
BeginExternalSubroutine (subWindowDestroy) _
    BPtr (bvpWidgetRef) _                                                                          ' 16882 : fltk widget reference
  ParmEnd
'
'
  Fl_Double_WindowDelete                    (bvpWidgetRef)
'
EndExternalSubroutine
'
'-----------------------------------------------
'  Procedure 59 : link the window to the window events router
BeginExternalSubroutine (subWindowEventsCommon) _
    BPtr (bvpWidgetRef) _                                                                          ' 16882 : fltk widget reference
  ParmEnd
'
'
  Fl_WidgetSetCallback0                     (bvpWidgetRef, ProcPtr(funWindowEventsRouter))
'
EndExternalSubroutine
'
'-----------------------------------------------
'  Procedure 60 : kill the application window
BeginExternalSubroutine (subWindowKill) _
  ParmEnd
'
'
  Fl_WindowHide                             (prpAppWidgetRef)
'
EndExternalSubroutine
'
'-----------------------------------------------
'  Procedure 61 : resize and reposition a window
BeginExternalSubroutine (subWindowResize) _
    BPtr (bvpWidgetRef) _                                                                          ' 16882 : fltk widget reference
  , BVal (bviActualLeft,                    typInt32) _                                            ' 16417 : actual left position of the gui object (pixels)
  , BVal (bviActualTop,                     typInt32) _                                            ' 16418 : actual top position of the gui object (pixels)
  , BVal (bviActualWidth,                   typInt32) _                                            ' 16419 : actual width of the gui object (pixels)
  , BVal (bviActualHeight,                  typInt32) _                                            ' 16420 : actual height of the gui object (pixels)
  ParmEnd
'
'
  Fl_WindowResize                           (bvpWidgetRef, bviActualLeft, bviActualTop, bviActualWidth, bviActualHeight)
'
EndExternalSubroutine
'
'-----------------------------------------------
'  Procedure 62 : get the window`s gadget reference
BeginExternalFunction (funWindowSelfGet) _
    BPtr (bvpWidgetRef) _                                                                          ' 16882 : fltk widget reference
  ParmReturn (typPointer)
'
  LocalPointer (pSelf)                                                                             ' 16898 : reference to the active gadget object
'
    pSelf                                   = Fl_WidgetGetUserData (bvpWidgetRef)
    Return                                  pSelf
'
EndExternalFunction
'
'-----------------------------------------------
'  Procedure 63 : link the window to its gadget object
BeginExternalSubroutine (subWindowSelfSet) _
    BPtr (bvpWidgetRef) _                                                                          ' 16882 : fltk widget reference
  , BPtr (bvpSelf) _                                                                               ' 16898 : reference to the active gadget object
  ParmEnd
'
'
  Fl_WidgetSetUserData                      (bvpWidgetRef, bvpSelf)
'
EndExternalSubroutine
'
'-----------------------------------------------
'  Procedure 64 : show a window
BeginExternalSubroutine (subWindowShow) _
    BPtr (bvpWidgetRef) _                                                                          ' 16882 : fltk widget reference
  ParmEnd
'
'
  Fl_WindowShow                             (bvpWidgetRef)
'
EndExternalSubroutine
'
'-----------------------------------------------
'  Procedure 65 : create a wizard
BeginExternalFunction (funWizardCreate) _
    BVal (bviBaseLeft,                      typInt32) _                                            ' 16413 : nominal left position of the gui object (pixels)
  , BVal (bviBaseTop,                       typInt32) _                                            ' 16414 : nominal top position of the gui object (pixels)
  , BVal (bviBaseWidth,                     typInt32) _                                            ' 16415 : nominal width of the gui object (pixels)
  , BVal (bviBaseHeight,                    typInt32) _                                            ' 16416 : nominal height of the gui object (pixels)
  ParmReturn (typPointer)
'
  LocalPointer (pWidgetRef)                                                                        ' 16882 : fltk widget reference
'
  pWidgetRef                               = Fl_WizardNew (bviBaseLeft, bviBaseTop, bviBaseWidth, bviBaseHeight)
  Return                                   pWidgetRef
'
EndExternalFunction
'
'-----------------------------------------------
'  Procedure 66 : create a wizard page
BeginExternalFunction (funWizardPageCreate) _
    BVal (bviBaseLeft,                      typInt32) _                                            ' 16413 : nominal left position of the gui object (pixels)
  , BVal (bviBaseTop,                       typInt32) _                                            ' 16414 : nominal top position of the gui object (pixels)
  , BVal (bviBaseWidth,                     typInt32) _                                            ' 16415 : nominal width of the gui object (pixels)
  , BVal (bviBaseHeight,                    typInt32) _                                            ' 16416 : nominal height of the gui object (pixels)
  ParmReturn (typPointer)
'
  LocalPointer (pWidgetRef)                                                                        ' 16882 : fltk widget reference
'
  pWidgetRef                                = Fl_WizardPageNew (bviBaseLeft, bviBaseTop, bviBaseWidth, bviBaseHeight)
  Return                                    pWidgetRef
'
EndExternalFunction
Once the basic GUI elements are in place it's an easy process to customize the glitz and glam.

Rod
spartacus13012
Posts: 18
Joined: Nov 30, 2014 12:37
Location: FRANCE

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by spartacus13012 »

Hello from france,

I have somme question. Is it possible to interface "SCINTILLA EDITOR" by the "FLTK" library.

For creates a scintilla editing zone is it OK with FL_WINDOW instead of createwindowex?

And after how we must treat the events (notifycations) of "SCINTILLA", with something else than WNDPROC

Someone he tests it
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 »

spartacus13012 wrote:Is it possible to interface "SCINTILLA EDITOR" by the "FLTK" library.
Sure but I don't support it.

You have to retrieve the handle from FLTK parent window with Fl_XID(win)
include windows.bi for CreateWindowEX(hParent, "Scintilla", WS_CHILD ...)
than you have to hijack the original window proc for events from scintilla control.

FLTK-C is a ready to use crossplatform GUI and it comes with it's owen syntax highlighting editor widget.
(wich can be extended with any missing feature like all other FLTK widgets)

On Windows Scintilla is primary a 32-bit control for 64-bit you have to build it self.

On linux it's a GTK+ widget and C++ only. (by the way GTK+ comes with it's own syntax highlighting widget also)

Joshy
spartacus13012
Posts: 18
Joined: Nov 30, 2014 12:37
Location: FRANCE

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by spartacus13012 »

D.J.Peters wrote:
spartacus13012 wrote:Is it possible to interface "SCINTILLA EDITOR" by the "FLTK" library.
Sure but I don't support it.

You have to retrieve the handle from FLTK parent window with Fl_XID(win)
include windows.bi for CreateWindowEX(hParent, "Scintilla", WS_CHILD ...)
than you have to hijack the original window proc for events from scintilla control.

FLTK-C is a ready to use crossplatform GUI and it comes with it's owen syntax highlighting editor widget.
(wich can be extended with any missing feature like all other FLTK widgets)

On Windows Scintilla is primary a 32-bit control for 64-bit you have to build it self.

On linux it's a GTK+ widget and C++ only. (by the way GTK+ comes with it's own syntax highlighting widget also)

Joshy
Thank you very much for the information
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 »

I found this overview 2D and image drawing in FLTK

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 for sharing that one Joshy

I am thankful that the professors in the universities are sharing like this.
I wonder if I might have worked with a relative of Sean Ho in Hong Kong. I sent him an email about that idea.

I hope to talk to Sean and other professors about the idea of including freebasic in their curriculum.
chung
Posts: 648
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by chung »

how can i set max buffer data size in fl_jpeg_image (name, data) load jpeg from memory? (to protect from corrupted input data, in case it indicates length greater than the real buffer size) , can specific corrupted data cause crash ?


update : i tried with missing hex"ffd9" end of jpeg image tag and after some times it crashed.
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 »

@chung a GUI with images in memory does not handle corrupt data.

Code: Select all

' If a name is given, the image is added to the list of shared images (see: Fl_Shared_Image) and will be available by that name.
declare function Fl_JPEG_ImageMem(byval a_name as const zstring ptr=0, byval buffer as const any ptr) as FL_JPEG_Image ptr
#define Fl_JPG_ImageMem Fl_JPEG_ImageMem
What you search are in FBimage.

Joshy

Code: Select all

declare function LoadRGBAMemory(buffer as const any ptr, buffersize as long) as any ptr
chung
Posts: 648
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by chung »

i tried the link , your website is marked as spyware by my antivirus !

never mind , in the freebasic package i found freeimage.bi => freeimage_openmemory , freeimage_loadfrommemory will do the thing .
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by VANYA »

Hi all!

At start of any example in the terminal the warning is displayed:
X_ChangeProperty: BadValue (integer parameter out of range for operation) 0x0
The example works. Who will tell me what this warning is? How to fix?

System: Linux Mint 32-bit.
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 »

I'm self and the FLTK community (so far I know) never fixed this stupid warning but you can ignore it (trust me)

Joshy
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by VANYA »

D.J.Peters wrote:I'm self and the FLTK community (so far I know) never fixed this stupid warning but you can ignore it (trust me)

Joshy
Well, I understand. Thanks for the answer Joshy!
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FLTK C for FreeBASIC Jan 09, 2017

Post by VANYA »

Is it possible in FLTK to minimize the window and return it to its original state from the "minimize" ?
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 »

VANYA wrote:Is it possible in FLTK to minimize the window and return it to its original state from the "minimize" ?
Min- or maximizing a window is the job of the window manager
triggered by the user if he/she click the min/max button.

If you will do it self by code you have to use the Windows API or XLIb.

With other words there isn't a Fl_WindowMinimize(win) nor Fl_WindowMaximize(win) method.
(So far I know)

Joshy
Post Reply