The fun part are FreeBASIC can extends classes self so as an expert it's posiible to write classes like the good old from VB 6 (Visual Basics)
Don't worry it's an advanced OOP FreeBASIC example but hey we don't die stupid like Trump supporters
take a look at "function HandleCB cdecl(byval me as any ptr, byval event as Fl_Event) as long"
You will notice all events are optional for the FORM user and how to delegate unused events back to the parent C++ class.
But again you need only take a look at the simple WidgetEx examples shipped with fltk-c
Joshy
By the way this code block would be the same for all other widget too and would be generated by a FORM designer.
But the FreeBASIC communtiy is to small to invest so much livetime in projects I have done all the last 17 years.
Today all BASIC like languages comes with a GUI and unicode/UTF support but the dev team of FreeBASIC thinks different.
A free open source BASIC with a standard GUI running on x86,x86_64,arm32,arm64,mac,windows,linux etc. would be game changer
and then a WEB backend for all kinds of smartphones and tablets would be a dream
Code: Select all
#include once "fltk-c.bi"
' advanced example
type FB_FORM extends Fl_Double_WindowEx
public:
declare destructor
declare constructor(byval w as long,byval h as long,byval caption as zstring ptr=0)
declare constructor(byval x as long,byval y as long,byval w as long,byval h as long,byval caption as zstring ptr=0)
declare sub Show()
' user events (all optional)
as function (byval frm as FB_FORM ptr) as long ShowEvent
as function (byval frm as FB_FORM ptr) as long HideEvent
as function (byval frm as FB_FORM ptr) as long CloseEvent
as function (byval frm as FB_FORM ptr) as long FocusEvent
as function (byval frm as FB_FORM ptr) as long UnfocusEvent
as function (byval frm as FB_FORM ptr) as long EnterEvent
as function (byval frm as FB_FORM ptr) as long LeaveEvent
as function (byval frm as FB_FORM ptr) as long DrawEvent
as function (byval frm as FB_FORM ptr, byval key as long) as long KeyDownEvent
as function (byval frm as FB_FORM ptr, byval key as long) as long KeyUpEvent
as function (byval frm as FB_FORM ptr, byval btn as long, byval x as long, byval y as long) as long ButtonPushEvent
as function (byval frm as FB_FORM ptr, byval btn as long, byval x as long, byval y as long) as long ButtonReleaseEvent
as function (byval frm as FB_FORM ptr, byval x as long, byval y as long, byval w as long, byval h as long) as long ResizeEvent
as function (byval frm as FB_FORM ptr, byval x as long, byval y as long, byval z as long) as long MouseWheelEvent
as function (byval frm as FB_FORM ptr, byval x as long, byval y as long) as long MouseMoveEvent
as function (byval frm as FB_FORM ptr, byval x as long, byval y as long) as long MouseDragEvent
private: ' FLTK stuff
declare static sub DestructorCB cdecl(byval me as any ptr)
declare static function DrawCB cdecl(byval me as any ptr) as long
declare static function HandleCB cdecl(byval me as any ptr, byval event as Fl_Event) as long
declare static function ResizeCB cdecl(byval me as any ptr, byval x as long, byval y as long, byval w as long, byval h as long) as long
declare sub SetCallbacks
as Fl_Double_WindowEx ptr m_Double_WindowEx
end type
' private form stuff
destructor FB_FORM
if m_Double_WindowEx then Fl_Double_WindowExDelete m_Double_WindowEx
end destructor
constructor FB_FORM(byval w as long, byval h as long, byval caption as zstring ptr)
m_Double_WindowEx = Fl_Double_WindowExNew(w,h,caption) : SetCallbacks
end constructor
constructor FB_FORM(byval x as long, byval y as long, byval w as long, byval h as long, byval caption as zstring ptr)
m_Double_WindowEx = Fl_Double_WindowExNew2(x,y,w,h,caption) : SetCallbacks
end constructor
' public form stuff
sub FB_FORM.Show()
Fl_WindowShow(m_Double_WindowEx)
end sub
sub FB_FORM.SetCallbacks
Fl_Double_WindowExSetDestructorCB(m_Double_WindowEx,@DestructorCB)
Fl_Double_WindowExSetDrawCB (m_Double_WindowEx,@DrawCB)
Fl_Double_WindowExSetHandleCB (m_Double_WindowEx,@HandleCB)
Fl_Double_WindowExSetResizeCB (m_Double_WindowEx,@ResizeCB)
Fl_WidgetSetUserData (m_Double_WindowEx,@This)
end sub
sub FB_FORM.DestructorCB cdecl(byval win as any ptr)
print "FB_FORM.DestructorCB"
end sub
function FB_FORM.DrawCB cdecl(byval win as any ptr) as long
print "FB_FORM.DrawCB"
dim as FB_FORM ptr me = Fl_WidgetGetUserData(win)
if me->DrawEvent then return me->DrawEvent(me)
return 0
end function
function FB_FORM.HandleCB cdecl(byval win as any ptr,byval event as Fl_Event) as long
print "FB_FORM.HandleCB"
dim as FB_FORM ptr me = Fl_WidgetGetUserData(win)
select case as const event
case FL_EVENT_SHOW : if me->ShowEvent then return me->ShowEvent(me)
case FL_EVENT_HIDE : if me->HideEvent then return me->HideEvent(me)
case FL_EVENT_CLOSE : if me->CloseEvent then return me->CloseEvent(me)
case FL_EVENT_FOCUS : if me->FocusEvent then return me->FocusEvent(me)
case FL_EVENT_UNFOCUS : if me->FocusEvent then return me->UnfocusEvent(me)
case FL_EVENT_ENTER : if me->EnterEvent then return me->EnterEvent(me)
case FL_EVENT_LEAVE : if me->LeaveEvent then return me->LeaveEvent(me)
case FL_EVENT_PUSH : if me->ButtonPushEvent then return me->ButtonPushEvent (me,Fl_EventButton(),Fl_EventX(),Fl_EventY())
case FL_EVENT_RELEASE : if me->ButtonReleaseEvent then return me->ButtonReleaseEvent(me,Fl_EventButton(),Fl_EventX(),Fl_EventY())
case FL_EVENT_MOVE : if me->MouseMoveEvent then return me->MouseMoveEvent(me,Fl_EventX(),Fl_EventY())
case FL_EVENT_DRAG : if me->MouseDragEvent then return me->MouseDragEvent(me,Fl_EventX(),Fl_EventY())
case FL_EVENT_MOUSEWHEEL : if me->MouseWheelEvent then return me->MouseWheelEvent(me,Fl_EventX(),Fl_EventY(),Fl_EventDY())
case FL_EVENT_KEYDOWN : if me->KeyDownEvent then return me->KeyDownEvent(me,Fl_EventKey())
case FL_EVENT_KEYUP : if me->KeyUpEvent then return me->KeyUpEvent(me,Fl_EventKey())
end select
' delegate all unhandled events to the base class
dim as Fl_WindowEx ptr ex=win
return Fl_WindowExHandleBase(ex,event)
end function
function FB_FORM.ResizeCB cdecl(byval win as any ptr,byval x as long,byval y as long,byval w as long,byval h as long) as long
print "FB_FORM.ResizeCB"
dim as FB_FORM ptr me = Fl_WidgetGetUserData(win)
if me->ResizeEvent then return me->ResizeEvent(me,x,y,w,h)
return 0
end function
' optinal user defined callbacks
function ShowEventCB(byval frm as FB_FORM ptr) as long
print "ShowEventCB"
return 0
end function
function HideEventCB(byval frm as FB_FORM ptr) as long
print "HideEventCB"
return 0
end function
function FocusEventCB(byval frm as FB_FORM ptr) as long
print "FocusEventCB"
return 0
end function
function UnfocusEventCB(byval frm as FB_FORM ptr) as long
print "UnfocusEventCB"
return 0
end function
function EnterEventCB(byval frm as FB_FORM ptr) as long
print "EnterEventCB"
return 0
end function
function LeaveEventCB(byval frm as FB_FORM ptr) as long
print "LeaveEventCB"
return 0
end function
function ButtonPushEventCB(byval frm as FB_FORM ptr,byval button as long,byval x as long,byval y as long) as long
print "ButtonPushEventCB Button(" & button & " at " & x & "," & y & ")"
return 0
end function
function ButtonReleaseEventCB(byval frm as FB_FORM ptr,byval button as long,byval x as long,byval y as long) as long
print "ButtonReleaseEventCB Button(" & button & " at " & x & "," & y & ")"
return 0
end function
function MouseMoveEventCB(byval frm as FB_FORM ptr,byval x as long,byval y as long) as long
print "MouseMoveEventCB (" & x & "," & y & ")"
return 0
end function
function MouseDragEventCB(byval frm as FB_FORM ptr,byval x as long,byval y as long) as long
print "MouseMoveEventCB (" & x & "," & y & ")"
return 0
end function
function MouseWheelEventCB(byval frm as FB_FORM ptr,byval x as long,byval y as long,byval z as long) as long
print "MouseWheelEventCB (" & x & "," & y & "," & z & ")"
return 0
end function
function KeyDownEventCB(byval frm as FB_FORM ptr,byval key as long) as long
print "KeyDownEventCB Key(" & key & ")"
return 0
end function
function KeyUpEventCB(byval frm as FB_FORM ptr,byval key as long) as long
print "KeyUpEventCB Key(" & key & ")"
return 0
end function
function ResizeEventCB(byval frm as FB_FORM ptr,byval x as long,byval y as long,byval w as long,byval h as long) as long
print "ResizeEventCB(" & x & "," & y & "," & w & "," & h & ")"
return 0
end function
function DrawEventCB(byval frm as FB_FORM ptr) as long
print "DrawEventCB"
return 0
end function
'
' main
'
var frm1 = FB_FORM(320,200, "Form 1")
frm1.ShowEvent = @ShowEventCB
frm1.HideEvent = @HideEventCB
frm1.FocusEvent = @FocusEventCB
frm1.UnfocusEvent = @UnfocusEventCB
frm1.EnterEvent = @EnterEventCB
frm1.LeaveEvent = @LeaveEventCB
frm1.ButtonPushEvent = @ButtonPushEventCB
frm1.ButtonReleaseEvent = @ButtonReleaseEventCB
frm1.MouseMoveEvent = @MouseMoveEventCB
frm1.MouseDragEvent = @MouseDragEventCB
frm1.MouseWheelEvent = @MouseWheelEventCB
frm1.KeyDownEvent = @KeyDownEventCB
frm1.KeyUpEvent = @KeyUpEventCB
frm1.ResizeEvent = @ResizeEventCB
frm1.DrawEvent = @DrawEventCB
frm1.Show()
Fl_Run()