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
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Knatterton »

bcohio2001 wrote:Of the ones I looked at, none addressed the issue that I am having.
Not sure what you mean. Maybe this one helps:

Code: Select all

#include once "fltk-c.bi"

var Win = Fl_WindowNew(320,200)
Dim As String MLText = "Line 1" + Chr(13,10) + "Line 2" + Chr(13, 10) + "Line 3"
Var StatusArea = Fl_BoxNew(10,10,300,180,MLText)
'Fl_WidgetSetAlign(StatusArea, Fl_ALIGN_TOP_LEFT)
Fl_WidgetSetAlign *StatusArea,Fl_ALIGN_LEFT or Fl_ALIGN_INSIDE
Fl_WindowShow Win
Fl_Run
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by bcohio2001 »

Thank you.
Fl_ALIGN_INSIDE is what I needed. Weird that you have to specify it to "stay inside" the widget.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Knatterton »

Another way to display text seems not to exist. Except the DrawStr().
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Knatterton »

But with Box we can do an exact positionimg everyhwere on the window, with font, size, color and frame. When everything fits, we can comment out the frame and the static text is ready.

Code: Select all

' Fltk_Box_Text.bas

#include once "fltk-c.bi"

var Win = Fl_WindowNew(200,200, "Fltk_Box_Text")
Dim As String text1 = "Text 1"

Var box1 = Fl_BoxNew(10,10,120, 50, text1)
Fl_WidgetSetAlign box1, Fl_ALIGN_TOP_LEFT or Fl_ALIGN_INSIDE 
Fl_WidgetSetBox(box1, FL_ENGRAVED_BOX)
Fl_WidgetSetColor box1, FL_CYAN
Fl_WidgetSetLabelColor(box1,FL_DARK_YELLOW)
Fl_WidgetSetLabelFont(box1, FL_COURIER)
Fl_WidgetSetLabelSize(box1,24)
Fl_WidgetSetLabel(box1, "Text 2")


Fl_WindowShow Win
Fl_Run
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by jdebord »

An example using graphic functions (Draw...) and the "extended" window widget:

Code: Select all

#include "fltk-main.bi"

function draw_text cdecl (self as any ptr) as long

  DrawSetColor FL_WHITE
  DrawRectFill 0, 0, 300, 300

  DrawSetColor FL_BLUE

  DrawRectFill  10,  10, 130,  80
  DrawRectFill  10, 110, 130,  80
  DrawRectFill  10, 210, 130,  80
  DrawRectFill 160,  10, 130, 280

  DrawSetColor FL_WHITE

  DrawSetFont FL_TIMES_BOLD, 15

  DrawStrBox "Centered", 10,  10, 130, 80
  DrawStrBox "Right justified", 10, 110, 130, 80, FL_ALIGN_RIGHT
  DrawStrBox "Left justified", 10, 210, 130, 80, FL_ALIGN_LEFT

  DrawSetFont FL_TIMES_BOLD_ITALIC, 30

  DrawStrBox "Text wrapped on several lines", 160, 10, 130, 280, FL_ALIGN_WRAP

  return 1
end function

var win = Fl_Double_WindowExNew2(100, 100, 300, 300)

Fl_Double_WindowExSetDrawCB win, @draw_text

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

Re: FLTK-C-1.3.3 for FreeBASIC

Post by D.J.Peters »

Windows vs Linux don't use chr(13,10) use !"\n" instead.

Joshy

Code: Select all

#include once "fltk-c.bi"
var Win = Fl_WindowNew(320,200)
Dim As String MLText = !"Line 1\n" & !"Line 2\n" &  "Line 3"
Var StatusArea = Fl_BoxNew(10,10,300,180,MLText)
Fl_WidgetSetAlign(StatusArea, Fl_ALIGN_TOP_LEFT or Fl_ALIGN_INSIDE)
Fl_WindowShow(Win)
Fl_Run()
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Knatterton »

For relaxing another pixmap button:

Code: Select all

' Fltk_Pixmap_Button_03.bas

#include once "fltk-c.bi"


dim as zstring ptr porsche_xpm(...) => {@"64 64 4 1", _
@" 	c #background",@".	c #000000000000",@"X	c #ffd100",@"o	c #FFFF00000000", _
@"                                                                ", _
@"                   ..........................                   ", _
@"              .....................................             ", _
@"        ............XXXXXXXXXXXXXXXXXXXXXXXX............        ", _
@"        ......XXXXXXX...XX...XXXXXXXX...XXXXXXXXXX......        ", _
@"        ..XXXXXXXXXX..X..XX..XXXX.XXXX..XXXXXXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..X..XX..XXX..XXXX..X...XXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..XXXXX..XX.....XX..XX.XXXXXXXXXXX..        ", _
@"        ..XXXXXXXXX.....XXX..XXX..XXXX..X.XXXXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..XXXXX..XXX..XXXX....XXXXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..XXXXX..XXX..XXXX..X..XXXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..XXXXX..XXX..X.XX..XX..XXXXXXXXXX..        ", _
@"        ..XXXXXXXXX....XXX....XXX..XX....XX..XXXXXXXXX..        ", _
@"        ..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX..        ", _
@"        ..XXXXXXXXX..........................XXXXXXXXX..        ", _
@"        ..XXX.......XXXXXXXXXXX...................XXXX..        ", _
@"        ......XX.XXX.XXX..XXXXX.........................        ", _
@"        ..XXXXX.XXX.XXX.XXXX.XX.........................        ", _
@"        ..XXXX.XXX.XX.......XXX.........................        ", _
@"        ..XXXX.......XXXXXX..XX..ooooooooooooooooooooo..        ", _
@"        ..X.....XXXXXXXXXXXXXXX..ooooooooooooooooooooo..        ", _
@"        ..X...XXXXXXXXXXXXXXXXX..ooooooooooooooooooooo..        ", _
@"        ..X..XXXXXXX.XX.XXXXXXX..ooooooooooooooooooooo..        ", _
@"        ..XXXXX.XXX.XX.XXXXXXXX..ooooooooooooooooooooo..        ", _
@"        ..XXXX.XXX.XX.XX................................        ", _
@"        ..XXXX.X.........X....X.X.X.....................        ", _
@"        ..XXXX...XXXXXXX.X..X...X.X.X.X.................        ", _
@"        ..X....XXXXXXXXXX.X...X.X.X.....................        ", _
@"        ..X...XXXXXXXXXX.XXXXXXXXXXXXXX.................        ", _
@"        ..X..XXXXXX.XX.X.XXX...XXXXXXXX.................        ", _
@"        ..XXXXX.XX.XX.XX.XX.....XXXXXXX.oooooooooooooo..        ", _
@"        ..XXXX.XX.XX.XX..XX.X...XXXXX.X.oooooooooooooo..        ", _
@"        ..XXXX.X.......X.XXXX...XXXX..X.oooooooooooooo..        ", _
@"        ..X......XXXXXX..XXXX...XXXX..X.oooooooooooooo..        ", _
@"        ..X...XXXXXXXXXX.XXX.....XXX.XX.oooooooooooooo..        ", _
@"        ..X..XXXXXXXXXXX.X...........XX.oooooooooooooo..        ", _
@"        .................X.X.........XX.................        ", _
@"        .................X.X.XXXX....XX.XXXXXXXXXXXXXX..        ", _
@"        .................XXX.XXXXX.X.XX.XXX.XX.XXXXXXX..        ", _
@"         ................XXXX.XXX..X..X.XX.XX.XXX.XXX..         ", _
@"         ................XXXXXXXX.XX.XX.X.XX.XXX.XXXX..         ", _
@"         .................XXXXXX.XX.XX.X..........XXX..         ", _
@"          ..oooooooooooooo.XXXXXXXXXX....XXXXXXXX..X..          ", _
@"          ..ooooooooooooooo.XXXXXXXX....XXXXXXXXXXXX..          ", _
@"           ..ooooooooooooooo........XXXXXXX.XX.XXXX..           ", _
@"           ..oooooooooooooooooo..XXXXX.XXX.XX.XX.XX..           ", _
@"            ..ooooooooooooooooo..XXXX.XXX.XX.XX.XX..            ", _
@"            ..ooooooooooooooooo..XXX.XX........XXX..            ", _
@"             ....................XXX....XXXXXX..X..             ", _
@"              ...................XX...XXXXXXXXXXX.              ", _
@"              ...................X...XXXXXXXXXXX..              ", _
@"               ..................X..XXXX.XXXXXX..               ", _
@"                .................XXX.XX.XX.XXX..                ", _
@"                 ................XX.XX.XX.XXX..                 ", _
@"                  ..ooooooooooo..XX.......XX..                  ", _
@"                   ..oooooooooo..X...XXXX.X..                   ", _
@"                    ..ooooooooo..X..XXXXXX..                    ", _
@"                     ...ooooooo..X..XXXX...                     ", _
@"                      ....ooooo..XXXXX....                      ", _
@"                        ....ooo..XXX....                        ", _
@"                          ....o..X....                          ", _
@"                            ........                            ", _
@"                              ....                              ", _
@"                                                                "}

sub ButtonCB cdecl (byval button as FL_WIDGET ptr)
  ? "Button pushed"
end sub

  const ICONSIZE = 48' flexible
  var win = Fl_Double_WindowNew(140,140,"Fltk_Pixmap")

  var porsche = Fl_PixmapNew(@porsche_xpm(0))
  var btn1 = Fl_ButtonNew( 30,30,80,80)
  Fl_WidgetSetImage btn1,porsche
  
  ' connect callbacks
  Fl_WidgetSetCallback0 btn1, @ButtonCB
  
Fl_WindowShow win
Fl_Run
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by bcohio2001 »

D.J.Peters wrote:Windows vs Linux don't use chr(13,10) use !"\n" instead.
I am aware of this. It was a "quick and dirty" example of my problem.
I am on windows so I naturally used Chr(13,10).
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Knatterton »

Joshy, a question about application icon, maybe you know this. Is that possible to create an application icon for any OS only with

Code: Select all

 Fl_WindowIcon(byval win as Fl_Window ptr, byval icon as const Fl_RGB_Image ptr)
And if yes how to convert a pixmap or jpg to FL_RGB_Image?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by D.J.Peters »

Knatterton wrote:...how to convert a pixmap or jpg to FL_RGB_Image ?
An FL_JPG_Image extends FL_RGB_Image you don't need to convert it !

I tested only Fl_WindowSetDefaultIcon() file: "Fl_WindowSetDefaultIcon.bas" is in the new flt-c version.

Icons are RGB images (true color 24/32-bit) like JPG,JPEG, PNG ... a pixmap image is a palette image only 256 colors max !

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

Re: FLTK-C-1.3.3 for FreeBASIC

Post by D.J.Peters »

I published a new fltk-c.1.3.3.zip file !

I fixed a bug in the C++ wrapper (Windows 32 and 64 bit)
I fixed an error in the "fltk-main.bi" file (Linux 32 and 64-bit)
I added many more comments in "flt-main.bi"
(complete HTML reference of the Fl_HelpView, Fl_Window and more ...)
I removed all the Fl_Extends1 ... Fl_Extends5 macros (Is much simpler now)
I added test Fl_HelpView05.bas Fl_WindowSetDefaultIcon01.bas may be more I can't remember :-)

This version can "optional" be integrated in a FreeBASIC setup !

fltk-c-1.3.3/fltk-c/fltk-gl.bi
fltk-c-1.3.3/fltk-c/fltk-glut.bi
fltk-c-1.3.3/fltk-c/fltk-main.bi
fltk-c-1.3.3/fltk-c/fltk-tools.bi
fltk-c-1.3.3/fltk-c.bi

copy file: fltk-c.bi and the complete folder "fltk-c" in the FreeBASIC include folder
on windows copy fltk-c-1.3.3/lib/win32 to FreeBASIC/lib/
on windows copy fltk-c-1.3.3/lib/win64 to FreeBASIC/lib/

on windows the result should look like this:
FreeBASIC/inc/fltk-c.bi
FreeBASIC/inc/fltk-c/fltk-gl.bi
FreeBASIC/inc/fltk-c/fltk-glut.bi
FreeBASIC/inc/fltk-c/fltk-main.bi
FreeBASIC/inc/fltk-c/fltk-tools.bi
FreeBASIC/lib/win32/libfltk-c1.3.3-32.dll.a
FreeBASIC/lib/win64/libfltk-c1.3.3-64.dll.a

on Linux it's depended where you installed FreeBASIC !
this is only an example how it can look:
/usr/local/include/freebasic/fltk-c.bi
/usr/local/include/freebasic/fltk-c/fltk-gl.bi
/usr/local/include/freebasic/fltk-c/fltk-glut.bi
/usr/local/include/freebasic/fltk-c/fltk-main.bi
/usr/local/include/freebasic/fltk-c/fltk-tools.bi

But this is optional I self never put any files in the FreeBASIC folder !

How ever I added ~200 free png icons in fltl-c-1.3.3/media
can be useful for toolbars menus image buttons ...

Before you unzip the new version rename your current fltk-c-1.3.3 folder so you have an backup of all your work !

!!! Note: do not extract the *.zip file over your current ftk-c-1.3.3 folder !!!

Joshy
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Knatterton »

Nice work, have just installed, works so far on mint 64! :-)
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Knatterton »

D.J.Peters wrote:I tested only Fl_WindowSetDefaultIcon() file: "Fl_WindowSetDefaultIcon.bas" is in the new flt-c version.
Tested in windows 10 now: shows icon in upper left corner and in task bar. In Mint 64 only in taskbar, not in upper left corner.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK-C-1.3.3 for FreeBASIC

Post by D.J.Peters »

May be you can try the other set icon stuff also.

Code: Select all

declare sub      Fl_WindowIcon         (byval win as Fl_Window ptr, byval icon as const Fl_RGB_Image ptr)
declare sub      Fl_WindowIcons        (byval win as Fl_Window ptr, byval icons as const Fl_RGB_Image ptr ptr, byval count as long)
declare sub      Fl_WindowDefaultIcons (byval win as Fl_Window ptr, byval icons as const Fl_RGB_Image ptr ptr, byval count as long)
But the functionality on Linux depends of the desktop manager you are using.
For example the KDE desktop (in scope of icons) has more or other features like the a GNOME desktop or a XFCE or a LDX etc.

Do you got your Fl_Pixmap image as FL_RGB_Image ?

Code: Select all

' class Fl_Pixmap extends Fl_Image
Fl_Extends(Fl_Pixmap,Fl_Image)
 Fl_Extends(Fl_XPM_Image,Fl_Pixmap)
 Fl_Extends(Fl_GIF_Image,Fl_Pixmap)

' class Fl_RGB_Image extends Fl_Image
Fl_Extends(Fl_RGB_Image,Fl_Image)
 Fl_Extends(Fl_BMP_Image,Fl_RGB_Image)
 Fl_Extends(Fl_PNG_Image,Fl_RGB_Image)
 Fl_Extends(Fl_JPEG_Image,Fl_RGB_Image)
 Fl_Extends(Fl_PNM_Image,Fl_RGB_Image) 
You can create an Fl_RGB_Image from a buffer with RGB[A] pixels.

Code: Select all

declare function Fl_RGB_ImageNew(byval bits as const any ptr, byval w as long, byval h as long, byval BytesPerPixel as long=3, byval pitch as long=0) as Fl_RGB_Image ptr
I'm sure there are more than one way to get an RGB image from Pixmap image.

Not tested only some ideas:
Set a Fl_Pixmap or any other palette image as a widget image like a Fl_Box and grab it as RGB image.
Or draw a Fl_Pixmap on an Fl_Window or Fl_Widget and grab it as RGB image.
Or draw a Fl_Pixmap directly over an Fl_RGB_Image.
Or let convert (and optional resize) a Fl_Pixmap from the Fl_Shared_Image class.
...

I will give it a try but not before the weekend.

By the way Icons should have transparent pixels where no colored pixel are set.
This is why the red book image looks not so nice as window icon.
I put "png_with_pink_to_png_alpha.bas" in the media folder.
You can load any BMP, TGA, PNG, JPG, DDS, Tiff or PCX image with pink pixels
and create an png image where pink pixels becomes full transparent.

For example if you have a round shape draw all pixels outside the circle as pink and convert it as png with alpha channel.
Or use an good image editor like GIMP to create transparent regions in the image.

bla bla bla :-)

Joshy
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: FLTK-C-1.3.3 for FreeBASIC

Post by Knatterton »

I simply tested with your program as is (without changes). Meanwhlie i tested in Mint 32, there icon don't appear in both places.

Another thing i have noticed, 32x32 png becomes stretched on 48x48 button, but pixmap stays the same size, so that there is a little distance to the edge of button.

Anyway, all these are minor problems, fltk works for the biggest part and good even for complex programs, so thank you again for all your continued work!
Post Reply