UnderwareDESIGN

PlayBASIC => Show Case => Topic started by: kevin on January 22, 2005, 08:38:03 AM

Title: Flexi Windows
Post by: kevin on January 22, 2005, 08:38:03 AM
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..)
Title: Flexi Windows
Post by: kevin on January 22, 2005, 11:53:53 AM
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)
[pbcode]


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)
     If x#=>w Then x#=x#-w
    Stars#(CurrentBuffer)=x#
 Next
    PositionCameraX 1,0
    DrawCamera 1
   DrawGFXImmediate

return


[/pbcode]


Title: Flexi Windows
Post by: kevin on January 23, 2005, 12:23:39 AM
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  :)
Title: Flexi Windows
Post by: kevin on January 23, 2005, 07:55:13 AM
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


[pbcode]

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

 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)
     If x#=>w Then x#=x#-w
    Stars#(CurrentBuffer)=x#
 Next
    PositionCameraX 1,0
    DrawCamera 1
   DrawGFXImmediate

return
[/pbcode]

Title: Flexi Windows
Post by: kevin on January 23, 2005, 08:13:21 AM
Well fixed the World Buffer delete problem and it now works like a charm...
Title: Flexi Windows
Post by: kevin on January 23, 2005, 02:40:12 PM
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 :)  

  [plink] Download Flexi Gui Demo V0.04 (740k) (http://www.underwaredesign.com/files/demos/FlexiDemoV004.zip)[/plink]
Title: Flexi Windows
Post by: Jeku on January 24, 2005, 01:49:21 AM
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.
Title: Flexi Windows
Post by: kevin on January 24, 2005, 07:46:56 AM
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..
Title: Flexi Windows
Post by: kevin on January 24, 2005, 04:49:51 PM
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..  :)
Title: Flexi Windows
Post by: kevin on January 25, 2005, 12:53:48 AM
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..
Title: Flexi Windows
Post by: kevin on January 25, 2005, 12:55:33 AM
Notice the resizable clock window.  This window is running from an GUI generated event.  So it basically set and forget !
Title: Flexi Windows
Post by: Jeku on January 25, 2005, 03:26:58 AM
What will this be in the end?  PlayGUI on steroids?  :)
Title: Flexi Windows
Post by: kevin on January 25, 2005, 01:06:19 PM
Without the Gadgets :)


 So you think, clicking on the title should POP the wiondow to front always ? (like window )
Title: Flexi Windows
Post by: Jeku on January 25, 2005, 01:33:22 PM
QuoteWithout the Gadgets :)


  So you think, clicking on the title should POP the wiondow to front always ? (like window )
[snapback]5393[/snapback]

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 :)
Title: Flexi Windows
Post by: kevin on January 25, 2005, 03:38:31 PM
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..
Title: Flexi Windows
Post by: kevin on January 27, 2005, 09:47:31 AM
Update V0.09:

 This is taking forever :( , got the  bright idea yesterday to make the task bar a window also.  As I was just going to hack it together, for the sake of the demo (ohh, what ever could it be? :) )   It didn't seem like a issue at the time, but this meant setting up priorities with windows.  Which ended up breaking most the events.  Anyway now you can have windows of various priorities.   They can clicked to the front of each priority group.   Since the task bar needs to be always at the front . It has a higher priority. Clicking the other windows won't cover it  

 Set set up some auto event generation stuff for window, so now the 'update events' routine can generate not only timed redraws but can force a windows update rate.  So regardless of the PB refresh rate the window is redrawn at it's own FPS.  You'll get some stutters here and there, but hey that happens :)  

 The cool thing about it, is that you don't have to manage the timing of the redraws yourself,  you set it and it just seems to occur.. as if by magic..

 The only thing not working is that while you can minimize a widow to the task bar,  you can't restore as i've not written that part yet :)
Title: Flexi Windows
Post by: kevin on January 27, 2005, 09:58:29 AM
V0.09  piccy
Title: Flexi Windows
Post by: kevin on January 28, 2005, 04:07:52 PM
Update V0.11

 I knew there was good reason why was going to hack together task bar window previously.. What was it?,  Well it was to avoid the need for parent/child infrastructure with windows.  

 The nice thing about task bar being a window, is that minimized windows merely need to be linked to the task bar window.  Which would have a bit of custom code to render the minimized icons.  This also means that i can trap clicks etc through the existing code basically.   But it's been a bit messing setting it up, and flip-flopping on a few ideas but it's slowly getting there.. I really don't want to have to return update it later.

 Another nice thing about linked windows.   The children are limited to the parents bounds though and you can't drag a window off the parents view port.   But there's a few issues with that still..   (due to changing ideas :) )

Once I get this working OK, it's time for that damn Kyruss tech demo...
Title: Flexi Windows
Post by: kevin on January 29, 2005, 12:25:44 PM
Flex GUI V0.13

 Well here's prolly the last tech demo of Flexi.  This one has the main devices/controls integrated together.  So now the taskbar actually functions.   There's still a few known issues, but nothing that will get in the road of the what its to be used for at the moment.
 
Window Features:

  * Basic controls Resize, Drag, click to front,

  * Windows have prioritys,  Windows are grouped and drawn based on their priority

  * Optional palette(s)

  * Optional window gadgets (minimized, maximize and close)

  * Mouse over highlights

  * Event Driven
   ---> User can catch  MouseOver,MouseClick, resize, redraw, create, delete, etc
   ---> Windows can control their own refresh rate  (either delta time a FPS rate)
   ---> System events and be over written, So you can make your own control functions to over ride

  * Windows are linkable.  (hit the space bar in the demo to LINK the clock and the Stars windows to the Borderless window - note Minimized will NOT work in this context...)

  * TaskBar for minimized windows.   User can catch events on Task bar.  Currently their can only be one task bar active at once.  


 There's still a few issues In the demo,  link minimizing a child window..  and maximize should pop exclusively to the front.  I've left the task bar to drag also,  it'll auto reposition it's self when it generates an update event.  TO show it's still a window





 [plink] Download Flexi Gui Demo V0.13 (750k) (http://www.underwaredesign.com/files/demos/FlexiDemoV013.zip)[/plink]

Title: Flexi Windows
Post by: Jeku on January 29, 2005, 02:42:50 PM
That is awesome!  I like how the resizing works... good job!  Would love to see the source :)

Was it written entirely in PB or did you have to make low-level modifications?
Title: Flexi Windows
Post by: kevin on January 29, 2005, 02:58:54 PM
Nah, It's entirely PB1.062 (which has some bug fixes over release 1.06) but certainly nothing special about it.
Title: Flexi Windows
Post by: kevin on October 31, 2005, 07:07:29 PM
Flexi V0.16

 This in the continuation of PB's Flexi GUI library.  Previous the library didn't support any gadgets, so the purpose of this (quick) update is to introduce some basic gadgets ASAP.  

  So far i've only implemented a LABEL gadget.  Gadgets are linked to their parent window.  At this point their limited to being attached to windows, which is really though my own laziness.  While it would be  possible to link and sub link gadgets/windows, considering the style of gadgets that are going to be implemented, but it doesn't seem practical at this point.    

 Gadgets like windows generate events.  The user trap theses in the same approach, that being processing the event que.  There two type of basic events, user and system events. While you can manually trap and process System events if you like, obviously there best left to the library to maintain.   User events refer to everything from stuff like  MoveOver, Mouse Click, Window Open/CLose/resize/Drag etc etc

 In terms of Gadgets all I really need for my current project are  Labels,  Images and Sliders.   But i'll prolly add Text Boxes, Buttons also.  The performance of the library is veyr good, it's cache based, so the refresh load is spread more evenly.


The shot bellow shows a bunch of running windows mainly (from the old tech demo).  From double buffered windows, fixed refresh windows like the stars/clock through to image backdrops with some simple label attachments.
Title: Flexi Windows
Post by: kevin on November 01, 2005, 12:19:12 AM
It's Funny What You Find

  While testing the library earlier I'd noticed sometimes windows would vanish while pressing the space bar.  Well at least that's what I thought.  In fact, the main loop code was set up make those windows become children of the borderless window.    Which is what you can see in the picture.  It's rather bizarre and something i'd completely forgotten about.    You can try it yourself, load the existing Flexi example in projects/function_library folder

  Gadget wise the basic Command Buttons are in, need some cosmetics though
Title: Flexi Windows
Post by: kevin on November 01, 2005, 04:23:23 PM
Scroll Bars


 Here's the scroll bar prototypes  (only vscroll so far)
Title: Flexi Windows
Post by: kevin on November 01, 2005, 05:37:27 PM
Check box, Vscroll + HScroll   Gadgets
Title: Flexi Windows
Post by: kevin on November 04, 2005, 09:10:08 AM
Scroll Bars Implemented

   Been toying with implementing scrolling bars into the library.   They were causing a few headaches initially, but it's mostly worked out now.  At this point there fully functional apart from user dragging.  But the hover and clicking (small + large) steps are up and running.  

   Had some  logic drama's with working out a way to size to the handle, but it now seems capable of representing the gadgets range correctly without the handle virtually disappearing :).
Title: Flexi Windows
Post by: BlinkOk on November 04, 2005, 02:29:00 PM
looks cool. are you going to do combo boxes and list boxes?
Title: Flexi Windows
Post by: kevin on November 04, 2005, 02:32:34 PM
Not if i can help it.  ATM, I just need to get it a useful point for Play Mapper.  Can always come back later.
Title: Flexi Windows
Post by: BlinkOk on November 04, 2005, 02:39:04 PM
are you going to release this for general use or is it just going to be part of play mapper?
Title: Flexi Windows
Post by: kevin on November 04, 2005, 02:48:12 PM
Yeap,  for example an older version can be found in your PB/projects/function_libraries folder now.  

Prolly should make it into a Slib though, which would make using it bit simpler.
Title: Flexi Windows
Post by: BlinkOk on November 04, 2005, 02:51:32 PM
cool.
combo and list boxes would be the shizzle though. lol:)
Title: Flexi Windows
Post by: kevin on November 04, 2005, 03:06:49 PM
:) .. but ya could always use WinGUI for more complex (window styled) user interfaces.
Title: Flexi Windows
Post by: BlinkOk on November 04, 2005, 03:20:42 PM
too true!
Title: Flexi Windows
Post by: kevin on November 04, 2005, 04:45:53 PM
Scroll Bars Done
 
 This piccy has both the H/V scroll bars in and running.
Title: Flexi Windows
Post by: kevin on November 04, 2005, 06:48:09 PM
Check Boxes
Title: Flexi Windows
Post by: kevin on November 07, 2005, 12:40:37 AM
Picture Boxes

 Well, I've implemented a simple picture box.  While it's pictured with scroll bars attached to it, those are manually implemented in code.  Since at this point controls can't have their dependant controls.  If they could, I could build more complex controls out of a group of existing base controls.  But time is getting away from me.  The purpose of this gui update was simply to implement enough functionality to enable it to be used in PlayMapper.  That's it.
Title: Flexi Windows
Post by: kevin on November 08, 2005, 08:31:42 PM
Text Boxes (single line)

 And here we  have single line text boxes up and running.  While there's some cosmetic work to be done, that pretty much completes the base gadget set that I thought i'd need.  

  The input works pretty well, it's smart enough to manage the refresh so that only changes the input state effect the redrawing the gadget and subsequently it's parent window. This smoothes out the performance a great deal, and virtually makes missed key strokes a thing of the past.  It's certainly not infallible though.
Title: Flexi Windows
Post by: kevin on November 10, 2005, 09:49:48 AM
Flex GUI V0.29

 Well, here's the current build of the Flexi GUI library.  It's a bit of mish mash of approaches internally, but it works :)



Window Features:

* Basic controls Resize, Drag, click to front,

* Windows have prioritys, Windows are grouped and drawn based on their priority

* Optional palette(s)

* Optional window gadgets (minimized, maximize and close)

* Mouse over highlights

* Event Driven
---> User can catch MouseOver,MouseClick, resize, redraw, create, delete, etc
---> Windows can control their own refresh rate (either delta time a FPS rate)
---> System events and be over written, So you can make your own control functions to over ride

* Windows are linkable.

* TaskBar for minimized windows. User can catch events on Task bar. Currently their can only be one task bar active at once.



Gadgets:

* Labels  
 * Text Box
 * Command Button
 * Check Boxes
 * Picture Box
 * V scrollers
 * H scrollers


[plink]Download Flexi Gui Demo V0.29 (850k) (http://www.underwaredesign.com/files/demos/FlexiDemoV029.zip)[/plink]


Here's the demo code
[pbcode]
; create THE taskbar  (only one is supported)  
MyTaskBar=FlexiCreateTaskBar()

 
Dim MyWIndows(5)

 
LogoImage=GetFreeImage()
LoadImage "flex_gui.bmp",LogoImage


#IF PBCompileMode=0
   BackPath$="../../"
#ELSE
 BackPath$=""
#ENDIF


BAckGroundImage=GetFreeImage()
LoadImage BackPath$+"gfx/bg22.jpg",BackGroundImage

BAckGroundImage2=GetFreeImage()
LoadImage BackPath$+"gfx/back20.jpg",BackGroundImage2

 
MousePOinterIMage=GetFreeImage()
LoadImage "gfx\mouse.bmp",MousePOinterIMage
ImageMaskColour MousePOinterIMage,$ff00ff


MyClock=FlexiCreate("win",200,300)
FlexiSetTitle(MyClock,"Simple Clock")
FlexiPosition(MyClock,Rnd(GetScreenWidth()-200),Rnd(GetScreenHeight()-200))
; FlexiAllowResize(MyClock,false)
FlexiStyle(MyClock,%001)

FlexiOpen(MyClock)
FlexiAutoFresh(MyClock,Timer(),250)


; Make a window with NO border that has absolute priority
WinBoarderLess=FlexiCreate("win",320,200)
FlexiStyle(WinBoarderLess,%001)
FlexiPosition(WinBoarderLess,Rnd(100),Rnd(100))
FlexiBoarderLess(WinBoarderLess)
FlexiFpsFresh(WinBoarderLess,Timer()+15,30)
; FlexiPriority(WinBoarderLess,5)

FlexiOpen(WinBoarderLess)






MyWindow=FlexiCreate("win",GetImageWidth(logoimage)+100,GetImageHeight(LogoIMage)+100)
FlexiSetTitle(myWindow,"Blank Window")
FlexiPosition(MyWindow,Rnd(GetScreenWidth()-200),Rnd(GetScreenHeight()-200))
; FlexiAllowResize(MyWindow,false)
FlexiStyle(MyWindow,%101)
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,Rnd(GetScreenWidth()-200),Rnd(GetScreenHeight()-200))
FlexiSetTitle(myWindow2,"Camera Based Stars")

; FlexiAutoFresh(MyWindow2,Timer(),100)
FlexiFPSFresh(MyWindow2,Timer(),31)
; FlexiAutoFresh(MyWindow2,Timer(),33)

FlexiOpen(MyWindow2)


MyPalette=FlexiNewPalette()

; FlexiSetPalettePens(MyPalette,rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb(),rndrgb())
FlexiSetPaletteTitle(MyPalette,$ff00ff,$00fff0,$ffff80)

FlexiState.CurrentPalette=MyPalette


MyWindow3=FlexiCreate("win",250,200)
FlexiSetTitle(myWindow3,"Hello World")
FlexiPosition(MyWindow3,Rnd(GetScreenWidth()-200),Rnd(GetScreenHeight()-200))
FlexiOpen(MyWindow3)

 

 FlexiState.CurrentPalette=1
 For lp=0 To GetArrayElements(MyWIndows(),1)
 w=RndRange(50,250)
 h=RndRange(50,100)
  MyWindows(lp)=FlexiCreate("win",w,h)
  FlexiPosition(MyWindows(lp),Rnd(GetScreenWidth()-200),Rnd(GetScreenHeight()-200))
  FlexiSetTitle(MyWindows(lp),"My Window"+Str$(lp))

 ThisLabel=FlexiCreateLabel("Hello There:",100,100,MyWindows(lp))
 ThisLabel2=FlexiCreateLabel("Hello:",100,200,MyWindows(lp))

  ThisLabel3   =FlexiCreategadget("label",50,60,150,15,MyWindows(lp))
   FlexiSetCaption(ThisLabel3,"Thislabel3")

   FlexiSetAlignment(ThisLabel3,FlexGadJustify_Right)
 
 
 ThisCmdButton=FlexiCreateCmdButton("Command Me:",100,150,100,22,MyWindows(lp))

;l   FlexiWindows(index).BackGroundImage =ThisImage

 If Rnd(1)
    FlexiBackDrop(Mywindows(lp),BAckGroundImage)
 Else
    FlexiBackDrop(Mywindows(lp),BAckGroundImage2)
 EndIf
 
    For Checklp=0 To 10
   x=200+(checklp*20)
   y=100+(checklp*20)
   FlexiCreateCheckBox(x,y,10+checklp,Mywindows(lp))
    Next

  FlexiOpen(MyWindows(lp))
    LastWindow=MyWindows(lp)
 Next



   ThisVscroll   =FlexiCreategadget("vscroll",40,40,16,250,LastWindow)
   FlexiSetValueRange(ThisVscroll,0,10)
   FlexiSetValue(ThisVscroll,6)
   FlexiOpen(ThisVscroll)

   ThisVscroll2   =FlexiCreategadget("vscroll",80,40,16,250,LastWindow)
   FlexiSetValueRange(ThisVscroll2,0,100)
   FlexiSetValue(ThisVscroll2,50)
   FlexiOpen(ThisVscroll2)


   ThisHscroll2   =FlexiCreategadget("hscroll",100,40,160,20,LastWindow)
   FlexiSetValueRange(ThisHscroll2,0,100)
   FlexiSetValue(ThisHscroll2,50)
   FlexiOpen(ThisHscroll2)


   Thisimage=LogoImage
;BackGroundImage2
   PicX=100
   PicY=200
   PicW=150
   PicH=150

   PictureBox  =FlexiCreategadget("picture",picx,picy,picw,pich,LastWindow)
   FlexiSetGadgetImage(Picturebox,Thisimage)
   FlexiOpen(PictureBox)
  w=GetImageWidth(ThisIMage)
  h=GetImageHeight(ThisIMage)
   
   PictureBoxVscroll  =FlexiCreategadget("vscroll",picx+picw,picy,16,pich,LastWindow)
   w2=w-picw
   If w2<0 Then w2=0
   h2=h-pich
   If h2<0 Then h2=0

   FlexiSetValueRange(PictureBoxVscroll,0,h2)
;   FlexiSetValue(PictureBoxVscroll,0)

   PictureBoxHscroll  =FlexiCreategadget("hscroll",picx,picy+pich,picw,16,LastWindow)
   FlexiSetValueRange(PictureBoxHscroll,0,w2)
;   FlexiSetValue(PictureBoxHscroll,0)


   FlexiOpen(PictureBoxVscroll)
   FlexiOpen(PictureBoxHscroll)









  Dim TextBoxes(5)


   For lp=0 To 5
 y=100+(lp*30)
 TextBoxes(lp)    =FlexiCreategadget("textbox",350,y,160,20,LastWindow)
 FlexiOpen(TextBoxes(lp))
   Next

  For lp=0 To 4
 ThisObject=TextBoxes(lp)
 NextObject=TextBoxes(lp+1)
   FlexiSetGadgetNextFocus(ThisObject,NExtObject)
   Next
   

   CheckBox     =FlexiCreategadget("checkbox",200,200,10,10,LastWindow)

;  FlexiSetCaption(CheckBox,"HELLO")

   FlexiOpen(CheckBox)



 MyWindowDB=FlexiCreate("win",100,100)
 FlexiSetTitle(myWindowDB,"Double Buffered")
 FlexiPosition(MyWindowDB,Rnd(GetScreenWidth()-200),Rnd(GetScreenHeight()-200))
 FlexiBackBufferState(MyWindowDB,True)
 FlexiFPSFresh(MyWindowDB,Timer(),5)

 FlexiOpen(MyWindowDB)



   w2xd#=2
   w2yd#=3
   MYC=RGBFade($ADd4ac,70)
   
   
   Do
 RenderToScreen
 Cls Myc


 sw=GetScreenWidth()
 sh=GetScreenHeight()
 x=(sw/2)-(GetImageWidth(logoimage)/2)
 y=(sh/2)-(GetImageHeight(logoimage)/2)
 DrawImage LogoImage,x,y,0



; Call Update Events Function to get new/process existing events
 FlexiUpdateEvents()

; ==========================================
; Process the Events
; ==========================================
 For EventIndex=0 To flexiState.EventStackSize-1
    ThisObject=FlexiEvents(EventIndex).ThisObject


    Select FlexiEvents(EventIndex).EventType

   Case FlexEvent_UserHitEnter
  ; User press enter in a textbox

      #Print "user hit enter in text box"
;     For lp=0 To 5
;    If ThisObject=TextBoxes(lp)
;       If lp<5
;      FlexiSetFocus(TextBoxes(lp+1))               
;      ExitFor
;    EndIf   
;;    EndIf
;  Next
   

   Case FlexEvent_UserKeyStroke
      sc=FlexiEvents(eventindex).KeyScancode
      ik$=FlexiEvents(eventindex).KeyINkey$
       
;       If ik$<>""           
;      Caption$=FlexiGetCaption(ThisObject)+ik$
  ;   #Print Caption$
;      FlexiSetCaption(ThisObject,Caption$)
;      #Print "ThisObject:"+Str$(ThisObject)

;       EndIf    

   Case FlexEvent_UserMouseClick
      Select ThisObject
   ; Catch When the Mouse is over the draw area of a window
   
     Case ThisLabel
       FlexiRenderTo(ThisObject)
       FlexiSetCaption(ThisObject,"Mouse Clicked"+Str$(Rnd(100)))   

     Case ThisCmdButton
       #Print "clicked command button"


     Case ThisVscroll
       #Print FlexiGetValue(ThisObject)



   ; trap clicks on the picture box scrollers
     Case PictureBoxVscroll,PictureBoxHscroll
       Yoffset=FlexiGetValue(PictureBoxVscroll)
       Xoffset=FlexiGetValue(PictureBoxHscroll)
       FlexiSetImageOffset(PictureBox,Xoffset,Yoffset)        


     Case MyTaskBar     
       

     Default
        bx,by=FlexiGetViewportTop(thisObject)
        FlexiRenderTo(ThisObject)
        X=FlexiEvents(EventIndex).MouseXpos
        Y=FlexiEvents(EventIndex).MouseYpos
        MB=FlexiEvents(EventIndex).MouseButtons
   
        If MB=1  
       oldm=GetInkMode()
       InkMode 1+64
       CircleC x,y,10,1,$220304
       InkMode oldm
        EndIf
        If MB=2
       oldm=GetInkMode()
       InkMode 1+64
       size=Rnd(20)
       BoxC x-size,y-size,x+size,y+size,1,RGB(Rnd(15),Rnd(15),Rnd(15))
      ;$020304
       InkMode oldm
        EndIf

        FlexiSetRefresh(ThisObject,True)

      EndSelect
     
   Case FlexEvent_UserWindowFocus       
     FlexiRenderTo(ThisObject)
     bx,by=FlexiGetViewportTop(thisObject)
;      ink $ffffff
;      text bx,by,"I have focus"+str$(focuscount)
;      inc focuscount

   Case FlexEvent_UserMouseOver
  ; Catch When the Mouse is over the draw area of a window

      Select ThisObject
     
     Case ThisLabel
       FlexiRenderTo(ThisObject)
       FlexiSetCaption(ThisObject,"Mouse Over"+Str$(Rnd(100)))   
      EndSelect
     
     
     
   Case FlexEvent_UserRedraw

      Select ThisObject
     Case MyClock
        FlexiRenderTo(ThisObject)
        w,h=FlexiGetSIze(thisObject)
        bx,by,bx2,by2=FlexiGetViewport(thisObject)
        Cls $35550
        DRawClock(bx+(w/2),by+(h/2),w/2,h/2)
   
        
     Case MyWindow2
    ; HAndle window #2
        FlexiRenderTo(ThisObject)
    ; rener the stars to ths window
        bx,by=FlexiGetViewportTop(thisObject)
        Gosub Process_Stars
        If Timer()>StarsFPSstart
       StarsFPS=CurrentStarsFPS
       CurrentStarsFps=0        
       StarsFpsStart=Timer()+1000
        EndIf   
        Inc CurrentStarsFPS
        Text bx,by,"Stars FPS:"+Str$(StarsFPS)

     Case WinBoarderLess
        FlexiRenderTo(WinBoarderLess)
        bx,by=FlexiGetViewportTop(thisObject)
        bx,by,bx2,by2=FlexiGetViewport(thisObject)
 ;     BackDrop2(bx,by,bx2,by2)
;         ink $443366
        Cls $443366
        Text bx,by,"No Boarder + Resizeable"


     Case MyWindowDB
        FlexiRenderTo(ThisObject)
        bx,by,bx2,by2=FlexiGEtViewport(Thisobject)   

        If DBREset=0
       DoubleBXpos=bx
       DoubleBYpos=by
       DbREset=True
       Cls RndRGB()
        EndIf         
        Flag=0
        oldink=GetInkMode()  
        InkMode 1+64
        LockBuffer
        For Dots=0 To 1000
       DotC DoubleBXpos,DoubleBypos,RGB(33,22,0)
     ;rnd(16),rnd(16),rnd(16))
       Inc DoubleBXpos
       If  DoubleBXpos=>bx2
          DoubleBXpos=bx
          Inc DoubleBYpos
          If DoubleBYpos>By2 Then Flag = True: ExitFor dots   
       EndIf
        Next
        UnLockBuffer
        InkMode Oldink         
        If flag   Then   FlexiSync(ThisObject)   : Dbreset=0
     
      EndSelect


   Case FlexEvent_UserOpenWindow
  ; Catch When a window has been openned   

   Case FlexEvent_UserCloseWindow
  ; Catch When the USer CLICKS the close gadget


   Case FlexEvent_UserResize
  ; Catch when a window has been resized
      Select ThisObject
     Case MyWindow
        FlexiRenderTo(ThisObject)
        w,h=FlexiGetSIze(thisObject)
        bx,by,bx2,by2=FlexiGetViewport(thisObject)
        ShadeBox bx,by,bx2,by2,RndRGB(),RndRGB(),RndRGB(),RndRGB()
        DrawImage Logoimage,bx+((w/2)-GetImageWidth(LogoIMage)/2),by+((h/2)-GetImageHeight(LogoIMage)/2),0

     Case MyWindow2
        flexirenderto(mywindow2)
        Gosub init_world_buffers

     Case MyWindow3          
        FlexiRenderTo(ThisObject)
        w,h=FlexiGetSIze(thisObject)
        bx,by,bx2,by2=FlexiGetViewport(thisObject)
        ShadeBox bx,by,bx2,by2,RndRGB(),RndRGB(),RndRGB(),RndRGB()
        For lp=0 To 100
          Ink RndRGB()
          Text Rnd(w),Rnd(h),"Hello World"
        Next
        

      EndSelect





      
   Case FlexEvent_UserMaximized
  ; Catch  when the user click Maximized button
     FlexiRenderTo(ThisObject)
     bx,by=FlexiGetViewportTop(thisObject)
     Text bx,by,"You maximized me"    
         
   Case FlexEvent_UserMinimized
  ; Catch  when the user click Maximized button
     FlexiRenderTo(ThisObject)
     bx,by=FlexiGetViewportTop(thisObject)
     Text bx,by,"You Minimized me"    

   Default
      FlexiProcessEvent(EventIndex)
    EndSelect
 Next


NumbOFevents=FlexiState.EventStackSize


; Flush the Event stack
 FlexiFlushEvents()


/*
    If SpaceKey()
   If linkme=0
      FlexiAttachObject(WinBoarderLess,MyClock)
   EndIf

   If linkme=5
      FlexiAttachObject(WinBoarderLess,MyWindow2)
   EndIf
   Inc linkme
  EndIf
*/


 RenderToScreen
 FlexiRender()

 Ink $ffffff
 Print FPS()

;  If EnterKey() Then CustomInput(100,100,0)


 If FunctionKeys(10)=True
    FlexiShowActiveGadgets()
 
 EndIf

   If FunctionKeys(1)=True
   Resize_PictureBox(PIctureBox,PIctureBoxVscroll,PictureBoxHscroll,-5,-5)
   EndIf

   If FunctionKeys(2)=True
   Resize_PictureBox(PIctureBox,PIctureBoxVscroll,PictureBoxHscroll,5,5)
   EndIf

;  MyText$, Status=CustomInput(100,100,1)

    
; If were running in Full screen mode, draw a Bitmap mouse pointer     
 If GetScreenType()=2
    DrawImage MousePOinterIMage,MouseX(),MouseY(),1
 EndIf  
 Sync
   Loop





init_world_buffers:


  BUffers=6

   If GetCameraStatus(1)
    DeleteCamera 1
   EndIf   

   For CurrentBuffer=1 To Buffers
 If GetWorldStatus(CurrentBuffer)
   DeleteWorld CurrentBuffer
 EndIf
   Next

 If FlexiStatus(Mywindow2)=False Then Return


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

   CreateCamera 1
;   CameraCls 1,Off

   Dim Stars#(BUffers)
  Stars=250
   C=$ffffff
   FadeStep#=50.0/Buffers
   For CurrentBuffer=1 To Buffers
 CreateWorld 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:
 If FlexiStatus(Mywindow2)=False Then Return

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

 For CurrentBuffer=1 To Buffers
    x#=Stars#(CurrentBuffer)
     PositionCameraX 1,X#
   CameraGrabWorldAt 1,CurrentBuffer,00,0,0
     x#=x#+(CurrentBuffer*1.10)
     If x#=>w Then x#=x#-w
    Stars#(CurrentBuffer)=x#
 Next
    PositionCameraX 1,0
    DrawCamera 1
   DrawGFXImmediate
Return


Function BackDrop()
   Static baseangle#
   c1=RGBFade($ff0000,SinNewValue(50,baseangle#,50))
   c2=RGBFade($ffff00,CosNewValue(50,baseangle#,50))

   c3=RGBFade($ff00f0,SinNewValue(50,baseangle#*2,50))
   c4=RGBFade($1234,CosNewValue(50,baseangle#*2,50))
   y2=GetScreenHeight()
;-pFlexi_GetTAskBarHeight()
   ShadeBox 0,0,GetScreenWidth(),y2,c1,c2,c3,c4
   baseangle#=Mod(baseangle#+1,360)
EndFunction



Function BackDrop2(x1,y1,x2,y2)
   Static baseangle#
   c1=RGBFade($ff0000,SinNewValue(50,baseangle#,50))
   c2=RGBFade($ffff00,CosNewValue(50,baseangle#,50))
   c3=RGBFade($ff00f0,SinNewValue(50,baseangle#*2,50))
   c4=RGBFade($1234,CosNewValue(50,baseangle#*2,50))
   ShadeBox x1,y1,x2,y2+1,c1,c2,c3,c4
   baseangle#=Mod(baseangle#+1,360)
EndFunction




Function DrawClock(cx,cy,Width,height)

   Static ShapesCReated,ClockSHape,OldWidth,OldHeight

   If OldWidth<>Width  Or OldHeight<>height
 If SHapesCreated=1
    DeleteShape ClockShape
   SHapesCreated=0
 EndIf
   EndIf
   
   If SHapesCreated=0
 OldWidth=Width
 OldHeight=Height

 edgestep=10
 edges=360/edgestep

 ClockShape=GetFreeShape()  
 CreateShape ClockShape,edges+1,edges+1
 TempShape=GetFreeShape()  
 CreateShape TempShape,edges+1,edges+1
 VertIndex=1
 For Angle=0 To 359 Step edgestep
    X#=Cos(angle)*Width   
    Y#=Sin(angle)*Height   
    SetShapeVertex ClockShape,VertIndex,x#,y#  

    X#=Cos(angle)*(Width*0.90)   
    Y#=Sin(angle)*(Height*0.90)   
    SetShapeVertex TempShape,VertIndex,x#,y#  

; Link edges
    SetShapeEdge ClockShape,VertIndex,VertIndex,VertIndex+1
    SetShapeEdge TempShape,VertIndex,VertIndex,VertIndex+1

    Inc VertIndex
 Next

 Dec vertindex
 SetShapeEdge ClockShape,VertIndex,VertIndex,1
 SetShapeEdge TempShape,VertIndex,VertIndex,1

 MergeShape TempShape,ClockShape
 DeleteShape TempShape

 ShapesCreated=1
   EndIf

   #IF PBDebug=False
  LockBuffer
   #ENDIF
   

   Ink $446677
   DrawShape ClockShape,cx,cy,2
   Ink $ff6677
   DrawShape ClockShape,cx,cy,1
   
   S=CurrentSecond()
   M=CurrentMinute()
   H=CurrentHour()

; Minute Hand
   angle#=(360/12.0)*h
   angle#=WrapAngle(angle#,-90)
   LineC cx,cy,CosNewValue(cx,angle#,Width*0.5),SinNewValue(cy,angle#,Height*0.5),$ff0000
   
; Minute Hand
   angle#=(360/60.0)*m
   angle#=WrapAngle(angle#,-90)
   LineC cx,cy,CosNewValue(cx,angle#,Width*0.75),SinNewValue(cy,angle#,Height*0.75),$ffffff

; Second Hand
   angle#=(360/60.0)*s
   angle#=WrapAngle(angle#,-90)
   LineC cx,cy,CosNewValue(cx,angle#,Width*0.80),SinNewValue(cy,angle#,Height*0.80),$888888

   #IF PBDebug=False
 UnLockBuffer
   #ENDIF

EndFunction





Psub SHow()
   ArraySize=GetArrayElements(FlexiDrawOrder().tFlexDrawOrder,1)
Start=0
Cliph=GetScreenHeight()-100
th=GetTextHeight(" ")
h=Arraysize*th

 If h=>h
 Start=h-cliph
 Start=Start/th  
 EndIf  
 
   start=ClipRange(start,0,1000)  
   For lp=Start To ArraySize
 If FlexiDrawOrder(lp).status=True
    T$="Object:"+Digits$(FlexiDrawOrder(lp).ThisObject,6)+"  "+Right$(Hex$(FlexiDrawOrder(lp).ThisObject),6)
    T$=t$+"   Priority:"+Digits$(FlexiDrawOrder(lp).ThisPriority,4)
    Print t$
 EndIf
   Next
EndPsub




Function  Resize_PictureBox(PIctureBox,PIctureBoxVscroll,PictureBoxHscroll,Xchange,YChange)
   picx,picy=FlexigetPosition(pictureBox)
 picw,pich=FlexiGetSize(PictureBox)

 ThisIMage=FlexiGetGadgetImage(Picturebox)
   w=GetImageWidth(ThisIMage)
   h=GetImageHeight(ThisIMage)

 Picw=picw+XChange
 Pich=pich+YChange

     FlexiResize(picturebox,Picw,pich)
   
 FlexiResize(PictureBoxVscroll,16,pich)
 FlexiResize(PictureBoxHscroll,picw,16)
   
 FlexiPosition(pictureboxVscroll,Picx+picw,picy)
 FlexiPosition(pictureboxHscroll,Picx,picy+pich)

 w2=w-picw
 If w2<0 Then w2=0
 h2=h-pich
 If h2<0 Then h2=0
 FlexiSetValueRange(PictureBoxVscroll,0,h2)
 FlexiSetValueRange(PictureBoxHscroll,0,w2)

EndFunction
   

[/pbcode]