source http://www.idlearts.com/OPB.zip
Linux, Windows and partial support on mac
supports
collections of classes (modules)
inheritance
Class data container to set & get additional properties or arbitrary data
memory managed and garbage collected
Runtime FFI (Foreign Function Interface) call supporting standard and cdecl VarArgs (x86 only)
external to the runtimes library is OPBWindow an event driven window manager, currently only linux and windows
a opb class function takes this form
Code: Select all
ProcedureDLL ClassVector2DScale(*this.ClassVector2D,sX.f,sY.f)
*this\x* sx
*this\y * sy
ProcedureReturn *this
EndProcedure
providing a pointer in the class structure and then create a new instance of it in your constructor
OPB is also compatible with Interfaces should you wish to present classes via them.
An example of how you define a class
Code: Select all
;Define the class structure
Structure ClassVector2D
x.f
y.f
length.f
normal.f
EndStructure
;Create Destructor
ProcedureDLL ClassVector2D_Free(*class.Vector2D)
OPBFreeClass(*class)
EndProcedure
;Create a Class Construtor for ClassVector2D
ProcedureDLL NewClassVector2D(Module,name.s,x.f,y.f)
Protected *this.ClassVector2D
;Create a new class instance
*this = OPBNewClass(Module,name,SizeOf(ClassVector2D),@ClassVector2D_Free())
If *vec2D
;Initilize vars
If x Or y
*vec2D\length = Sqr( x * x + y * y)
*vec2D\normal = 1 / *vec2D\length
*vec2D\x = x * *vec2D\normal
*vec2D\y = y * *vec2D\normal
EndIf
ProcedureReturn *vec2D
EndIf
EndProcedure
ProcedureDLL.f ClassVector2D_GetX(*this.ClassVector2D)
ProcedureReturn *this\x * *this\length
EndProcedure
ProcedureDLL.f ClassVector2D_GetY(*this.ClassVector2D)
ProcedureReturn *this\y * *this\length
EndProcedure
ProcedureDLL.f ClassVector2D_Magnitude(*this.ClassVector2D)
ProcedureReturn *this\length
EndProcedure
;...
OPBWindow is a demo of a cross platform event driven windows manager
providing a means to have multiple windows running including a window screen
Events are registered with a precedence
1 a specific gadget and event "OnClick" ...
2 a specific gadget or any gadget and all its events via "Onevent"
1 a specific window and event "OnWindowMaximize"
2 a specific window or any window and all its gadgets events via "OnEvent"
1 a windowScreen event
The keyboard functions replace pb functions(**don't use initkeyboard**)
and is mapped to US English keyboard including lower case keys
To test an arbitary key where you need to know multiple keys
OPB_Window_KeyboardPressed(window,#OPBKey_UP)
OPB_Window_KeyboardReleased(window,#OPBKey_DOWN)
To get a the current key
key = OPB_Window_GetKey(window)
keyString = OPB_Window_GetKeyString(key) ;convert it to string
Code: Select all
;start the opb window manager passing in a module and name of app
If OPB_Window_Manager(OPBStart(),"myapp")
InitSprite()
;create a new window
w1 = OPB_Window(#PB_Any,0,0,800,600,"Window1", #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget |#PB_Window_SizeGadget)
;open a screen on the window
OPB_Window_Screen(w1,0,25,800,575,0,0,0)
;register the screen drawing function
OPB_Window_AddEvent(w1,#Null,#ScreenCallBack,@window1_screen());register some specific window events
OPB_Window_AddEvent(w1,#Null,#OnWindowMaximize,@Window1_OnWindowMaximized())
OPB_Window_AddEvent(w1,#Null,#OnWindowMinimize,@Window1_OnWindowMinimized())
;Register a catch all for events
OPB_Window_AddEvent(w1,#Null,#OnEvent,@Window1_OnEvent())
;add a button and set default event and it's callback
b1 = OPB_Window_AddGadget(w1,ButtonGadget(#PB_Any,5,5,60,20,"OK"),#OnClick,@Window1_OK_OnClick())
;create a second window
w2 = OPB_Window(#PB_Any,0,0,300,200,"Window2",#PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget |#PB_Window_SizeGadget)
;get it's native pb number
;add a menu
If CreateMenu(0,WindowID(w2))
MenuTitle("Project")
MenuItem(1, "Open")
MenuBar()
MenuItem(4, "Close")
EndIf
;register the menu callcack
OPB_Window_AddEvent(w2,#Null,#OnMenu,@Window2_OnMenu())
;Add a button and register it's default event
b2 = OPB_Window_AddGadget(w2,ButtonGadget(#PB_Any,235,5,60,20,"OK"), #OnClick,@Window2_OK_OnClick())
;additionally add mouse enter and leave and scroll events for the button
OPB_Window_AddEvent(w2,b2,#OnMouseEnter,@Window2_OK_OnMouseEnter())
OPB_Window_AddEvent(w2,b2,#OnMouseLeave,@Window2_OK_OnMouseLeave())
OPB_Window_AddEvent(w2,b2,#OnMouseScroll,@Window2_OK_ONMouseScroll())
;Create a listview and add an OnEvent callback for the Gadget
lv2 = ListViewGadget(#PB_Any,5,30,290,130) ;
OPB_Window_AddGadget(w2,lv2,#OnEvent,@Window2_LV2_OnEvent())
;enter the main loop
OPB_Window_Main()
OPBStop()
;if used from the OPB dll call need to call opbclose()
;OPBClose()
EndIf
The FFI may be useful in situations where you want to add a runtime plugin mechanism
a scripting environment or test bed or just need to call functions with VarArgs foo(int a,int b,...)
Code: Select all
mlib = OPB_FFI_OpenLibrary(file,@enumfuncs())
;make a wrapper function to call the library function
Procedure.f Foof(a.f,b.f)
Static fn
If Not fn ;get the function and set the number of parameters
fn = OPB_FFI_GetFunction(mlib,"foof",2)
EndIf
If fn
OPB_FFI_PushF(fn,a) ;push parameters using the type functions
OPB_FFI_PushF(fn,b)
ProcedureReturn OPB_FFI_CallF(fn) ;call the function via the required return type
EndIf
EndProcedure