The Windows implementation is done, except for image drawing. I'm going to attempt an implementation with X on Linux now.
One of the big problems with X, and the reason why Linux GUIs are so bad, is its asynchronous design. it was originally created in order to run a program on one computer and output a display on another networked computer! This causes huge problems because you can do things like set the size of a window, then query it immediately and get a different result than what you just set! With this approach, all the controls within the window will be "virtualized" so X has no control over anything except the main window.
The SubWindow class should probably only be used for creating an OpenGL rendering context. I think separate gadgets within the window should be implemented by the GUI, as if the window was just a blank canvas for drawing. The more stuff that's written in BMX code, the less opportunities there are for bad OS code to screw up your program.
The commands are quite repetitive and verbose. This isn't meant to be used directly by the application developer, but to be the basis of a GUI.
Function CoreWindowSetShape(win:TCoreWindow,x:Int,y:Int,width:Int,height:Int)
Function CoreWindowSetClipRegion(win:TCoreWindow,x:Int,y:Int,width:Int,height:Int,clip:Int)
Function CoreImageGetWidth:Int(img:TCoreImage)
Function CoreImageGetHeight:Int(img:TCoreImage)
Function CoreDeleteObject(o:Byte Ptr)
Function CoreImageCreate:TCoreImage(width:Int,height:Int,format:Int,pixels:Byte Ptr)
Function CoreWindowDrawImage(img:TCoreImage,x:Int,y:Int,width:Int,height:Int)
Function CoreWindowDrawRect(win:TCoreWindow,x:Int,y:Int,width:Int,height:Int)
Function CoreWindowDrawText(win:TCoreWindow,text$z,x:Int,y:Int,width:Int,height:Int,style:Int)
Function CoreWindowClear(win:TCoreWindow)
Function CoreWindowSetText(win:TCoreWindow,text$z)
Function CoreWindowSetCallback(win:TCoreWindow,Callback(win:TCoreWindow, event_id:Int, x:Int, y:Int ))
Function CoreWindowGetHandle:Byte Ptr(win:TCoreWindow)
Function CoreWindowSetColor(win:TCoreWindow,r%,g%,b%,bg%)
Function CoreCreateWindow:TCoreWindow(title$z,x:Int,y:Int,width:Int,height:Int,parent:TCoreWindow,style:Int)
Function CoreCreateSubWindow:TCoreWindow(title$z,x:Int,y:Int,width:Int,height:Int,parent:TCoreWindow,style:Int)
Function CoreWindowClientWidth:Int(win:TCoreWindow)
Function CoreWindowClientHeight:Int(win:TCoreWindow)
Function CoreWindowGetX:Int(win:TCoreWindow)
Function CoreWindowGetY:Int(win:TCoreWindow)
Function CoreWindowGetWidth:Int(win:TCoreWindow)
Function CoreWindowGetHeight:Int(win:TCoreWindow)
Example:
SuperStrict
Framework brl.systemdefault
Import brl.eventqueue
Import "Core.bmx"
Global win:TCoreWindow=CoreCreateWindow("Core Window Test",200,100,800,600,Null,CORE_WINDOW_DEFAULT)
CoreWindowSetColor win,34,34,35,True
CoreWindowSetCallback(win,MainWindowCallback)
Global subwin:TCoreWindow=CoreCreateSubWindow("Subwindow",40,40,CoreWindowClientWidth(win)-200,CoreWindowClientHeight(win)-60,win,0)
CoreWindowSetColor subwin,0,0,0,True
Global subwin2:TCoreWindow=CoreCreateSubWindow("Subwindow 2",50,50,CoreWindowClientWidth(subwin)-100,CoreWindowClientHeight(subwin)-100,subwin,0)
CoreWindowSetColor subwin2,35,35,35,True
CoreWindowSetCallback(subwin2,SubWindowCallback)
Repeat
WaitEvent()
Forever
End
Function MainWindowCallback(win:TCoreWindow, id:Int, x:Int, y:Int) "C"
Select id
Case CORE_EVENT_WINDOW_CLOSE
End
Case CORE_EVENT_WINDOW_PAINT
CoreWindowClear(win)
Case CORE_EVENT_WINDOW_SIZE
CoreWindowSetShape subwin,40,40,CoreWindowClientWidth(win)-200,CoreWindowClientHeight(win)-60
CoreWindowSetShape subwin2,50,50,CoreWindowClientWidth(subwin)-100,CoreWindowClientHeight(subwin)-100
EndSelect
EndFunction
Function SubWindowCallback(win:TCoreWindow, id:Int, x:Int, y:Int) "C"
Select id
Case CORE_EVENT_WINDOW_PAINT
Local s:String="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
s=s+"~n~n"+s+"~n~n"+s
CoreWindowSetClipRegion(win,50,50,200,200,False)
CoreWindowClear(win)
CoreWindowSetClipRegion(win,50,50,200,200,True)
CoreWindowSetColor(win,0,0,128,False)
CoreWindowDrawRect(win,0,0,CoreWindowClientWidth(win)/2,CoreWindowClientHeight(win))
CoreWindowSetColor(win,255,255,255,False)
CoreWindowDrawText(win,s,0,0,CoreWindowClientWidth(win),CoreWindowClientHeight(win),CORE_TEXT_CENTER|CORE_TEXT_wrap)
EndSelect
EndFunction
|