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
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

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

Post by badidea »

I was testing a bit more. Made this code:

Code: Select all

const as integer USE_DOUBLE_WIN = 1
const as integer USE_CALL_BACK = 1
const as integer USE_MAKE_CURRENT = 1

#include once "fltk-c.bi"

dim shared as Fl_Window ptr pWin
dim shared as Fl_BoxEx ptr pBoxEx
dim shared as Fl_Button ptr pBtn

function drawCB cdecl(widget as any ptr) as long
	if(USE_MAKE_CURRENT = 1) then
		Fl_WindowMakeCurrent(pWin)
	end if
	DrawSetRGBColor(rnd*255, rnd*255, rnd*255)
	DrawSetLineStyle(FL_SOLID, 2)
	DrawArc(Fl_WidgetGetX(pBoxEx), Fl_WidgetGetY(pBoxEx), _
	        Fl_WidgetGetW(pBoxEx), Fl_WidgetGetH(pBoxEx), 0, 360)
	return 1
end function

sub buttonCB cdecl (byval widget as Fl_Widget ptr)
	if(USE_CALL_BACK = 1) then
		Fl_WidgetRedraw(pBoxEx)
	else
		if(USE_MAKE_CURRENT = 1) then
			Fl_WindowMakeCurrent(pWin)
		end if
		DrawSetRGBColor(rnd*255, rnd*255, rnd*255)
		DrawSetLineStyle(FL_SOLID, 2)
		DrawArc(Fl_WidgetGetX(pBoxEx), Fl_WidgetGetY(pBoxEx), _
				Fl_WidgetGetW(pBoxEx), Fl_WidgetGetH(pBoxEx), 0, 360)
	end if
end sub

print USE_DOUBLE_WIN; USE_CALL_BACK; USE_MAKE_CURRENT

if(USE_DOUBLE_WIN = 1) then
	pWin = Fl_Double_WindowNew(600, 400)
else
	pWin = Fl_WindowNew(600, 400)
end if
pBoxEx = Fl_BoxExNew(200, 100, 300, 200) 'Note: BoxEx is created before Button
pBtn = Fl_ButtonNew(20, 156, 108, 24, "Draw")
Fl_WidgetSetCallback0(pBtn, @buttonCB)
Fl_BoxExSetDrawCB(pBoxEx, @drawCB)
Fl_WindowShow(pWin)
Fl_Run()
Then played with the constants USE_DOUBLE_WIN, USE_CALL_BACK, USE_MAKE_CURRENT

On Windows7 in virtual box:

0,0,0 no update
0,0,1 ok
0,1,0 ok
0,1,1 ok
1,0,0 no update
1,0,1 ok
1,1,0 ok
1,1,1 ok

So if we don't use the drawing call back, Fl_WindowMakeCurrent is required. Makes sense I think.


On my Linux system (desktop):

0,0,0 no update
0,0,1 ok
0,1,0 ok
0,1,1 ok
1,0,0 no update
1,0,1 empty window, no button, until window is moved, circle never shown
1,1,0 ok
1,1,1 empty window, no button, until window is moved, circle never shown

My conclusion: Something goes wrong with the combination of Fl_Double_WindowNew() and Fl_WindowMakeCurrent(pWin). Or I use Fl_WindowMakeCurrent() wrong.
WQ1980
Posts: 48
Joined: Sep 25, 2015 12:04
Location: Russia

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

Post by WQ1980 »

@D.J.Peters
In Linux static libraries not show cyrillic alphabet, greek and etc.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

@WQ1980 you are right :-(
the libraries are all 100% the same I use to build the dynamic fltk-c-wrapper.

First I tried changing the linking order then I added fltk-c-wrapper-ut8.o manually to fbc but without success.

I don't know how to solve it ATM all other stuff works with the static lib's here.

Looks like you have to use the dynamic version of fltk-c-wrapper.

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

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

Post by D.J.Peters »

So far I know the C++ toolchain used the help of g++ to link the static libs FreeBASIC only ld directly.

I wonder me that only the UTF-8 stuff makes trouble all other things works with the static libs.

However I use fltk-c dynamic libs most time.

Joshy
WQ1980
Posts: 48
Joined: Sep 25, 2015 12:04
Location: Russia

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

Post by WQ1980 »

This is result my function "DrawStrEx"
Ubuntu and static libraries fltk-c-1.3.3

http://www.mediafire.com/view/81jsj7oet ... scrin1.png#

This is freetype + FLTK :)

Not comfortable
But I need to show cyrillic, japanese characters and etc in static libraries.

I will add this function in my extended input widget. It's simple.

It would be rewritten Fl_Choice + "DrawStrEx" = extended Fl_Choice with cyrillic and etc characters... it's complicated :(
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

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

Post by badidea »

I tried to investigate my double window graphics issue a bit further. I converted the code from post: http://www.freebasic.net/forum/viewtopi ... 05#p213076 to c/c++. Took me some time. My c/c++ skills are a bit rusty, but I made it:

Code: Select all

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Image.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/Fl_JPEG_Image.H>
#include <FL/Fl_Box.H>

//g++ -Wall flDraw2c.cpp `fltk-config --ldflags --cxxflags --use-images` -s -o flDraw2c
//-ljpeg

void ButtonCB(Fl_Widget* button, void* box)
{
	Fl_Window* win = ((Fl_Widget*)box)->window();
	Fl_RGB_Image* img = (Fl_RGB_Image*)win->user_data();
	win->make_current();
	img->draw( 0,  0, 64, 64,  0,  0);
	img->draw(84,  0, 64, 64, 64,  0);
	img->draw( 0, 84, 64, 64,  0, 64);
	img->draw(84, 84, 64, 64, 64, 64);
	button->redraw();
}

int main() {
	fl_register_images();
	Fl_JPEG_Image img("media/renata.jpg");
	//Fl_Window win(148, 148 + 32);
	Fl_Double_Window win(148, 148 + 32);
	Fl_Box box(0, 0, 148, 148);
	box.image(img);
	win.user_data(&img);
	Fl_Button btn(20, 156, 108, 24, "Draw");
	btn.callback(ButtonCB, &box);
    win.show();
    return Fl::run();
}
Result on my system: The same. With a normal window, it works as expected. With double buffering, it doesn't.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

@badidea the problem isn't the fltk-c wrapper code it works here it has something to do with your window manager.

Do you tested it with a active clip region too ?

If not try this please:

1) make the window the current Fl_WindowMakeCurrent(win)
2) push the clipregion DrawPushClip(x,y,w,h)
3) draw the image
4) pop the clipregion DrawPopClip()

Can you post the log from X-server ?

it's in /var/log/ (on most systems)

Joshy
WQ1980
Posts: 48
Joined: Sep 25, 2015 12:04
Location: Russia

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

Post by WQ1980 »

Hi!
How to work with a FLTK and several threads?
Need a example functions
Fl_Unlock
Fl_Lock
Fl_ThreadMessage
CFreBasic
Posts: 14
Joined: Feb 01, 2015 21:17

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

Post by CFreBasic »

(sorry my english)
* About: Load a picture (image-pic), destroy it of memory and load ANOTHER picture.

* I was testing the code were load an image an Scale to a desired size.
(the Scale is important)

(this is only a part of the code)

Code: Select all

    Fl_Register_Images()
    Fl_Shared_ImageGet("media/renata.gif")
    Fl_Shared_ImageGet("media/renata.bmp")
    Fl_Shared_ImageGet("media/renata.jpg")
    Fl_Shared_ImageGet("media/renata.png")
    Fl_Shared_ImageGet("media/win.png")
    Fl_Shared_ImageGet("media/lin.png")
    var nImages = Fl_Shared_ImageNumImages()
    var win = Fl_Double_WindowNew(6*NEW_IMAGE_SIZE,NEW_IMAGE_SIZE,"Fl_Shared_ImageCopy")
    for i as integer=0 to nImages-1
Fl_WidgetSetImage Fl_BoxNew(i*NEW_IMAGE_SIZE,0,NEW_IMAGE_SIZE,NEW_IMAGE_SIZE),Fl_Shared_ImageCopy2(Fl_Shared_ImageImages()[i],NEW_IMAGE_SIZE,NEW_IMAGE_SIZE)
    next i
* The: "Fl_Shared_ImageCopy2" use "Fl_Shared_ImageImages()" to know what pic to use an scale.

* My question is: How to "eliminate" or "destroy" of the array of Fl_Shared_ImageGet, an image??
This is because (in mi code), every time, in a button, load a pic with Fl_Shared_ImageGet, it keeps rising the amount of memory (and the others pics in memory: i no longer use anymore).
Thanks
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

@CFreBasic (so far I know) you have to release a Fl_Shared_Image with Fl_Shared_ImageRelease.
If the reference counter (Fl_Shared_ImageRefcount) is 0 all resources will be deallocated.

You have to delete a Fl_Image (result of Fl_Shared_ImageCopy) with Fl_ImageDelete

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

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

Post by D.J.Peters »

Code: Select all

#include once "fltk-c.bi"

' test of:
'   Fl_Shared_ImageNumImages()
'   Fl_Shared_ImageCopy2()
'   Fl_Shared_ImageRelease()
'   Fl_ImageDelete()

Fl_Register_Images()

Fl_Shared_ImageGet("media/win.png")
Fl_Shared_ImageGet("media/win.png")
Fl_Shared_ImageGet("media/win.png")
Fl_Shared_ImageGet("media/lin.png")
Fl_Shared_ImageGet("media/lin.png")
Fl_Shared_ImageGet("media/lin.png")


var nImages = Fl_Shared_ImageNumImages()
print "Fl_Shared_ImageNumImages() = " & nImages
for i as long = 0 to nImages-1
  var img = Fl_Shared_ImageImages()[i]
  print "Fl_Shared_ImageRefcount(" & i & ") = " & Fl_Shared_ImageRefcount(img)
next

' make a resized copy of SharedImage(0) as Fl_Image
' NOTE: a copy doesn't increment the ref counter
var img = Fl_Shared_ImageCopy2(Fl_Shared_ImageImages()[0],16,16)


' release and delete the Fl_Shared_Image(s)
while Fl_Shared_ImageNumImages()>0
  var img = Fl_Shared_ImageImages()[Fl_Shared_ImageNumImages()-1]
  print "Fl_Shared_ImageRelease(" & Fl_Shared_ImageNumImages()-1 & ")"
  Fl_Shared_ImageRelease img
wend

nImages = Fl_Shared_ImageNumImages()
print "Fl_Shared_ImageNumImages() = " & nImages

' delete the copy (Fl_Image)
print "Fl_ImageDelete(img)"
Fl_ImageDelete img

sleep
CFreBasic
Posts: 14
Joined: Feb 01, 2015 21:17

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

Post by CFreBasic »

- The code work... at some time. Then, ... not.

It tookme about an hour to try, test,....
But... still rise the ram. Even, loading the same image or another.

- This is some of the code:

Code: Select all

Dim Shared As Fl_Window Ptr VentT
Dim Shared As Fl_Box Ptr BoxIma
Dim Shared As Fl_Image Ptr ImConScale
Dim Shared As Integer nImages

Sub EraseImageFromMemory
 ' release and delete the Fl_Shared_Image(s)
 while Fl_Shared_ImageNumImages()>0
   Fl_Shared_ImageRelease Fl_Shared_ImageImages()[Fl_Shared_ImageNumImages()-1]
 wend
End sub

'- This Sub executes only ONE time, when the program start
Sub MainFirstSub

 Fl_Register_Images()

 Fl_Shared_ImageGet("media/background1.jpg")
 ImConScale = Fl_Shared_ImageCopy2(Fl_Shared_ImageImages()[0],20,16)
 Fl_WidgetSetImage BoxIma,ImConScale
 Fl_WidgetRedraw(VentT)

 '- Test:
 nImages = Fl_Shared_ImageNumImages()
 print "Fl_Shared_ImageNumImages() = " & nImages
End Sub

Sub Button_One_Event Cdecl (widget As FL_Widget Ptr)
 EraseImageFromMemory

 Fl_Shared_ImageGet("media/background2.jpg")
 ImConScale = Fl_Shared_ImageCopy2(Fl_Shared_ImageImages()[0],30,26)
 Fl_WidgetSetImage BoxIma,ImConScale
 Fl_WidgetRedraw(VentT)

 '- Test:
 nImages = Fl_Shared_ImageNumImages()
 print "Fl_Shared_ImageNumImages() = " & nImages
End Sub

Sub Button_Two_Event Cdecl (widget As FL_Widget Ptr)
 EraseImageFromMemory

 Fl_Shared_ImageGet("media/background3.jpg")
 ImConScale = Fl_Shared_ImageCopy2(Fl_Shared_ImageImages()[0],40,46)
 Fl_WidgetSetImage BoxIma,ImConScale
 Fl_WidgetRedraw(VentT)

 '- Test:
 nImages = Fl_Shared_ImageNumImages()
 print "Fl_Shared_ImageNumImages() = " & nImages
End Sub
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

@CFreBasic post a short complete working code that shows me the problem you have with the fltk-c wrapper please.
(note I don't have your images use some of the media folder)

Joshy
CFreBasic
Posts: 14
Joined: Feb 01, 2015 21:17

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

Post by CFreBasic »

* Here, the full code...
To see the problem, replace the images with others more bigger in pixels...

Code: Select all

#Include "fltk-c.bi"

Dim Shared As Fl_Window Ptr VentT
Dim Shared As Fl_Button Ptr Button_one
Dim Shared As Fl_Button Ptr Button_two
Dim Shared As Fl_Box Ptr Boxim
Dim Shared As Fl_Image Ptr Imgscale
Dim Shared As Integer nImages

Sub EraseImageFromMemory
 while Fl_Shared_ImageNumImages()>0
  Fl_Shared_ImageRelease Fl_Shared_ImageImages()[Fl_Shared_ImageNumImages()-1]
 wend
End sub

Sub FirstTime
 Fl_Shared_ImageGet("media/renata.png")
 Imgscale = Fl_Shared_ImageCopy2(Fl_Shared_ImageImages()[0],70,70)
 Fl_WidgetSetImage Boxim,Imgscale
 Fl_WidgetRedraw(VentT)
 nImages = Fl_Shared_ImageNumImages()
 print "Fl_Shared_ImageNumImages() = " & nImages
End sub

Sub Button_one_Event Cdecl (widget As FL_Widget Ptr)
 EraseImageFromMemory

 Fl_Shared_ImageGet("media/renata.jpg")
 Imgscale = Fl_Shared_ImageCopy2(Fl_Shared_ImageImages()[0],80,60)
 Fl_WidgetSetImage Boxim,Imgscale
 Fl_WidgetRedraw(VentT)
 nImages = Fl_Shared_ImageNumImages()
 print "Fl_Shared_ImageNumImages() = " & nImages
End Sub

Sub Button_two_Event Cdecl (widget As FL_Widget Ptr)
 EraseImageFromMemory

 Fl_Shared_ImageGet("media/renata.bmp")
 Imgscale = Fl_Shared_ImageCopy2(Fl_Shared_ImageImages()[0],90,90)
 Fl_WidgetSetImage Boxim,Imgscale
 Fl_WidgetRedraw(VentT)
 nImages = Fl_Shared_ImageNumImages()
 print "Fl_Shared_ImageNumImages() = " & nImages
End Sub

VentT = Fl_WindowNew (300, 200, "TEST")
Boxim = Fl_BoxNew(110, 10, 100, 100, "")
Button_one = Fl_ButtonNew (10, 10, 100, 20, "Pic Jpg")
Button_two = Fl_ButtonNew (10, 40, 100, 20, "Pic Bmp")

'* start the Register_Images:
Fl_Register_Images()

Fl_WidgetSetCallback0(Button_one, @Button_one_Event())
Fl_WidgetSetCallback0(Button_two, @Button_two_Event())
Fl_WindowShow(VentT)

'* Call the first picture (so Fl_Shared_ImageNumImages, has at last one loaded)
FirstTime

Fl_Run
Post Reply