News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Flexi Windows

Started by kevin, January 22, 2005, 08:38:03 AM

Previous topic - Next topic

kevin

Here's a little WIP pic of Flexi Windows,  I going to just port the old DB version, we were working on to PB , but decided it'd be a lot easier / better to re-write it.    

Features.
  * Windows Can Custom Palettes
  * Windows have basic  Style pref's  (close,Min & max Gadgets)  

To Do,
  * Screen  (So you can define a parent Screen as the PB display)
  * Window management (clicking, dragging, odering..)

kevin

#1
Another picture. I've been working on the rendering to the window objects.

This picture shows a bounding window with 1500 (z buffered) stars in it. So basically you can create a window and attach a camera to it, and just sit back and watch.. But you guys new that :)


Here's the demo code (without the library)
PlayBASIC Code: [Select]
 MyWindow=FlexiCreate("win",320,200)
FlexiPosition(MyWindow,100,200)
FlexiOpen(MyWindow)

MyPalette=FlexiNewPalette()
FlexiSetPalettePens(MyPalette,rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb())

cl=rgb(20,50,250)
cr=rgb(255,100,200)
FlexiSetPaletteTitle(MyPalette,cL,cR,$ffff80)
FlexiState.CurrentPalette=MyPalette

MyWindow2=FlexiCreate("win",220,100)
FlexiPosition(MyWindow2,400,100)
FlexiSetTitle(myWindow2,"Camera Based Stars")

FlexiOpen(MyWindow2)


MyPalette=FlexiNewPalette()
FlexiSetPalettePens(MyPalette,rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb())
FlexiState.CurrentPalette=MyPalette


MyWindow3=FlexiCreate("win",250,200)
FlexiPosition(MyWindow3,rnd(GetScreenWidth()-200),Rnd(GetScreenHeight()-200))
FlexiOpen(MyWindow3)


FlexRenderTo(mYwindow3)
For lp=0 to 10
ink rndrgb()
text rnd(150),rnd(200),"Hello World"
next


flexrenderto(mywindow2)
Gosub init_world_buffers

w2xd#=2
w2yd#=3

Do
rendertoscreen

; shade the backdrop so it fades a little while the demo is running
FadeAngle#=wrapangle(fadeangle#,2)
c=$204020
c1=rgbfade($80c030,75+cos(fadeangle#)*25)
c2=rgbfade($80c030,75+sin(fadeangle#)*25)
c1=rgbfade($2040f0,75+cos(fadeangle#)*25)
shadebox 0,0,getscreenwidth(),getscreenheight(),c,c2,c1,c2
setcursor 0,0
text 0,0,fps()





x=MOd(FlexiGetX(MyWindow)+1,GetScreenWidth())
y=MOd(FlexiGetY(MyWindow)+2,GetScreenHeight())
FlexiPosition(MyWindow,x,y)


x=mousex()
y=mousey()
FlexiPosition(MyWindow3,x,y)


FlexRenderTo(mYwindow3)


; Buonce Window #2 around the screen

FlexRenderTo(MyWindow2)

Width=FlexiGetWidth(MyWindow2)
Height=FlexiGetHeight(MyWindow2)

x#=FlexiGetX(MyWindow2)+w2xd#
y#=FlexiGetY(MyWindow2)+w2yd#

if x#<=0 or (x#+width)=>getScreenWidth() then w2xd#=-w2xd#
if y#<=0 or (y#+height)=>getScreenheight() then w2yd#=-w2yd#

FlexiPosition(MyWindow2,x#,y#)

; rener the stars to ths window
gosub Process_Stars:


rendertoscreen



FlexiRender()

Sync
Loop





init_world_buffers:

W=FlexiGetWidth(MyWindow2)
H=FlexiGetHeight(MyWindow2)

CreateCamera 1
; CameraCls 1,Off

BUffers=6
Dim Stars#(BUffers)
Stars=250
C=$ffffff
FadeStep#=50.0/Buffers
For CurrentBuffer=1 To Buffers
CreateWorldBuffer CurrentBUffer

col=RGBFade(c,100-((buffers+1)-CurrentBuffer)*FadeStep#)
Stars#(BUffers)=Rnd(w)

; TEll PB To redirect all GFX output To the World buffer we Select
CaptureToWorld CurrentBuffer
CaptureDepth (buffers*10)-(currentbuffer*2)

For lp =0 To Stars
X=Rnd(w)
y=Rnd(h)
DotC x,y,Col
DotC x+w,y,Col
Next

Next CurrentBuffer
DrawGFXImmediate
return


Process_Stars:
CaptureToScene
ClsScene
For CurrentBuffer=1 To Buffers
x#=Stars#(CurrentBuffer)
PositionCameraX 1,X#
CameraGrabWorldAt 1,CurrentBuffer,00,0,0
x#=x#+(CurrentBuffer*1.10)
Login required to view complete source code




kevin

Update:

Working on the users control functions.  So far, you can click a window to front,  move it and drag a resize region.. It's all pretty painless, and much like every other gui library out there..


Events:

 The next issue it how events are handled.   Not really sure what direction i'll take for these.  

 I pretty much want the library to take care of it, but since the widows will require redrawing (from some events) by the user,  I need soem way of allow the user and library to work side by side..  Just not sure how to do it  :)

kevin

#3
Here's the demo code again..  I've added an event stack to some of the functions..  while most things will generate an event on the stack, there's two basic types those for the GUI and those for the user.    This means that user has to have a processing loop to manage events.. Which is nothing more than loop through the stack...

 When something is created, two events are spawned..  A Create and a USERredraw.. in that order.  You can see how to trap these in the code bellow..  But it's about the best i could come up with for the moment.  (we need function pointers)

 Anyway, this version has click to front,  resizing , dragging  the works..   Sadly there's a bug in the deleteWorld Buffer command making it crash if you resize the stars window.  But it does look pretty cool


PlayBASIC Code: [Select]
 MyWindow=FlexiCreate("win",320,200)
FlexiSetTitle(myWindow3,"Blank Window")

FlexiPosition(MyWindow,100,200)
FlexiOpen(MyWindow)

MyPalette=FlexiNewPalette()
FlexiSetPalettePens(MyPalette,rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb())

cl=rgb(20,50,250)
cr=rgb(255,100,200)
FlexiSetPaletteTitle(MyPalette,cL,cR,$ffff80)
FlexiState.CurrentPalette=MyPalette

MyWindow2=FlexiCreate("win",220,100)
FlexiPosition(MyWindow2,400,100)
FlexiSetTitle(myWindow2,"Camera Based Stars")

FlexiOpen(MyWindow2)


MyPalette=FlexiNewPalette()
FlexiSetPalettePens(MyPalette,rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb())
FlexiState.CurrentPalette=MyPalette


MyWindow3=FlexiCreate("win",250,200)
FlexiSetTitle(myWindow3,"Hello World")

FlexiPosition(MyWindow3,rnd(GetScreenWidth()-200),Rnd(GetScreenHeight()-200))
FlexiOpen(MyWindow3)





w2xd#=2
w2yd#=3

Do
rendertoscreen

cls 0
setcursor 0,0
print fps()



; Call Update Events to get
FlexiUpdateEvents()


; Process GUI and User Events

For EventIndex=0 to FlexiState.EventStackSize-1
EventType=FlexiEvents(EventIndex).EventType
Select EventType

case FlexEvent_UserRedraw

ThisObject=FlexiEvents(EventIndex).ThisObject
Select ThisObject

case MyWindow3
FlexRenderTo(ThisObject)
w,h=FlexiGetSIze(thisObject)
For lp=0 to 10
ink rndrgb()
text rnd(w),rnd(h),"Hello World"
next

Case MyWindow2

flexrenderto(mywindow2)
Gosub init_world_buffers

EndSelect




default
FlexiProcessEvent(EventIndex)
endselect
next

; Flush/clear the Event stack
FlexiFlushEvents()


; rener the stars to ths window
gosub Process_Stars:

rendertoscreen

ink $ffffff
print FlexiState.MouseOverWindow

FlexiRender()

dotc mousex(),mousey(),$ff00ff

Sync
Loop





init_world_buffers:

deleteAllcameras
; if GetCameraStatus(1)
; DeleteCamera 1
; endif

W=FlexiGetWidth(MyWindow2)
H=FlexiGetHeight(MyWindow2)

CreateCamera 1
; CameraCls 1,Off

BUffers=6
Dim Stars#(BUffers)
Stars=250
C=$ffffff
FadeStep#=50.0/Buffers
For CurrentBuffer=1 To Buffers
if GEtWorldBUfferstatus(CurrentBuffer)=true
DeleteWorldBUffer CurrentBuffer
endif

CreateWorldBuffer CurrentBUffer

col=RGBFade(c,100-((buffers+1)-CurrentBuffer)*FadeStep#)
Stars#(BUffers)=Rnd(w)

; TEll PB To redirect all GFX output To the World buffer we Select
CaptureToWorld CurrentBuffer
CaptureDepth (buffers*10)-(currentbuffer*2)

For lp =0 To Stars
X=Rnd(w)
y=Rnd(h)
DotC x,y,Col
DotC x+w,y,Col
Next

Login required to view complete source code



kevin

Well fixed the World Buffer delete problem and it now works like a charm...

kevin

#5
Flexi Demo V0.04


  Here a demo of Flex in it's current state,  the main thing missing is the minimize and maximize controls, but close works.   Most of stuff is rendering real time others are cache update redraw events.

  The logo is from the original DB version of Flex, which is by Kohai.  We were writing a GUI for a world editor we'd planned on writing after Visible Worlds.   But Play Basic got in the way :)  

  Download Flexi Gui Demo V0.04 (740k) (login required)

Jeku

#6
Kevin, that is awesome!  I'm very amazed :)

One thing I noticed is it only brings a window to the foreground if you click inside, not if you click on the titlebar.  That could be by design, though.
**
Automaton Games - Home of WordTrix 2.0, WordZap, and GameBasic
Jeku's Music - Easy listening electronic...
**

kevin

Funny you should mention that, it's one of those "should it, or shouldn't It?" questions i've been asking myself all day.

 Changing it is simple enough though

 Added a gadget hi-light thing and made the win maximize gadget active.  I've pretty run out of time, to get anything else in at the moment.  But it's   sorta useful ATM..

kevin

Update V0.06

 Been toying with adding a task bar which will hold minimized windows.   Much like how windows does.  

Anyway, i've given myself about 2 hours to complete whats left, so I can move onto the project this was written for..  :)

kevin

update v0.07

 * Added Task Bar (sorta)
 * User definable window gadgets
 * Windows can now be set to auto refresh.   So you can use your core 'select/case '  basically auto run the gui..

kevin

Notice the resizable clock window.  This window is running from an GUI generated event.  So it basically set and forget !

Jeku

What will this be in the end?  PlayGUI on steroids?  :)
**
Automaton Games - Home of WordTrix 2.0, WordZap, and GameBasic
Jeku's Music - Easy listening electronic...
**

kevin

Without the Gadgets :)


 So you think, clicking on the title should POP the wiondow to front always ? (like window )

Jeku

QuoteWithout the Gadgets :)


  So you think, clicking on the title should POP the wiondow to front always ? (like window )

Yes, I think the title bar should pop it to the front.  If you release the source to the full version then it shouldn't be hard to modify the code ourselves if you have no time :)
**
Automaton Games - Home of WordTrix 2.0, WordZap, and GameBasic
Jeku's Music - Easy listening electronic...
**

kevin

Yeah, it's open source of course. You know it's mess right ? :).. anyway   It'll come with the next update though so you'll just have to wait.  


 Ok then, now any click on the window pop's it to front.

 In terms of events,

  At the moment, All I have one main User REDRAW event.   When you resize a window, maximize, etc  this throws two events on the event stack.    A ReSize and a USERREdraw..   So you can trap that the window has change and needs updating..

 But i think there shuold be a UserReDraw and A UserReSize, USerCreate,UserDelete, UserMaximize, UserMinimize..   UserCLick etc  

 I think that'd give better control ..  as at the momemt the timed auto event stuff throws a user Redraw on the event stack.  same as when you resize...  But there really two different situations..  

 Might speend a bit more time cleaning it up, rather than just hacking my demo together..