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()
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.