Page 1 of 2

Screen gadget Lib - Next beta

Posted: Mon Oct 23, 2006 10:59 am
by Hurga
Hi

I worked on the lib and added some new "features".

; - added: Combobox-Gadgets
; - added: support for #PB_Any
; - added: #PB_Button_Toggle support for ButtonImageGadgets
; - added: two functions to work with toggled ButtonImageGadgets: SG_SetToggleState() and SG_GetToggleState()
; - changed: improved the performance of most of the commands a bit
; - changed: the name of the command SG_DrawAllGadgets() to SG_DrawGadgets(), because the functionality changed, too
; - changed: the SG_DrawGadgets() can now optionally draw only some of the gadgets


and before I release the new version, I hope s.o. will have a look at it and maxbe play a bit around with it.
I hope there are no more bugs (but surely there are...) :-)

My next interest is:
Does somebody use the lib?
Suggestions for next version?

Thx

Here is a screenshot
Image

and here is the source for that Screenshot

Code: Select all

; Test mit PB_Any
;{ Example 

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse()= 0
  MessageRequester("Error", "init") 
  End 
EndIf

If OpenWindow(1, 0, 0, 1024, 768, "", #PB_Window_BorderLess)
  If OpenWindowedScreen(WindowID(1), 0,0, 1024, 768, 0, 0, 0)
    ; create a mouse
    If CreateSprite(0, 8, 8) 
      If StartDrawing(SpriteOutput(0)) 
        Circle(4, 4, 4, RGB(255, 255, 255)) 
        StopDrawing()
      EndIf 
    EndIf
    Dim GadgNr.l(4)
    ;{ build Screengadgets
    ;{ set the appearance for the Imagebutton-gadget
    CreateImage(11, 100, 60)
    StartDrawing(ImageOutput(11))
    Box(0, 0, 100, 60, $00FFFF)
    DrawingMode(4)
    For x = 0 To 200
      Circle(Random(90) + 5, Random(50) + 5, Random(4) + 1, RGB(Random(255), Random(255), Random(255)))
    Next
    StopDrawing()
    
    SG_SetBackground(0)
    SG_SetColor($00FFFF)
    
    ;}
    
    
    GadgNr(0) = SG_ListIconGadget(#PB_Any, 430, 80, 250, 315, "Column0", 100, #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_GridLines) ; 
    SG_AddGadgetColumn(GadgNr(0), 1, "Column1", 100)
    For x = 1 To 8
      SG_AddGadgetItem(GadgNr(0), -1, "test " + Str(x) + Chr(10) + "Part 2 / " + Str(x))
    Next
    SG_SetGadgetItemColor(GadgNr(0), 0, $FF0000, -1)
    SG_SetGadgetItemColor(GadgNr(0), 1, $00FF00, -1)
    
    CreateImage(201, 16, 16)
    StartDrawing(ImageOutput(201))
    Box(0, 0, 16, 16, $FF00FF)
    StopDrawing()
    SG_AddGadgetItem(GadgNr(0), 5, "test 5 new", ImageID(201))
    CreateImage(200, 16, 16)
    StartDrawing(ImageOutput(200))
    Box(0, 0, 16, 16, $0000FF)
    StopDrawing()
    SG_AddGadgetItem(GadgNr(0), 8, "test 8 new", ImageID(200))
    SG_SetGadgetBackground(GadgNr(0), 0)
    SG_SetGadgetColor(GadgNr(0), $00FFFF)
    
    
    GadgNr(1) = SG_ListIconGadget(#PB_Any, 900, 80, 100, 100, "Column0", 100, #PB_ListIcon_GridLines)
    
    
    GadgNr(2) = SG_ButtonGadget(#PB_Any, 650, 660, 120, 40, "OK")
    SG_SetGadgetColor(GadgNr(2), $FFFFFF)
    SG_SetGadgetBackground(GadgNr(2), 0)
    
    GadgNr(3) = SG_ButtonGadget(#PB_Any, 790, 660, 120, 40, "Toggle", #PB_Button_Toggle)
    
    GadgNr(4) =  SG_ButtonImageGadget(#PB_Any, 450, 550, 100, 60, ImageID(11), 0)
    
    ;} 
    
    ;{ Eventloop
    Repeat ; Start of the event loop
      ClearScreen(0)
      ; DisplaySprite(2, 0, 0) ; play with this to see a background
      
      StartDrawing(ScreenOutput())
      
      StopDrawing()
      
      SG_DrawGadgets(-1, 0)
      ExamineMouse () 
      DisplayTransparentSprite(0, MouseX(), MouseY())
      
      FlipBuffers(0)
      
      
      ;{ standard loop
      Event = SG_ScreenGadgetEvent() ; This line checks if an event happened
      
      GadgetID = SG_EventScreenGadgetID() ; Is it a gadget event?
      
      EventType = SG_EventType() ; The event type
      
      ;You can place code here, and use the result as parameters for the procedures
      
      If Event = #PB_Event_Gadget
        
        If GadgetID = GadgNr(2)
          If EventType = #SG_EventType_LeftRelease
            SG_FreeAllGadgets()
            Event = #PB_Event_CloseWindow
          EndIf
          
        ElseIf GadgetID = GadgNr(4)
          If EventType = #SG_EventType_LeftRelease
            SG_FreeGadget(GadgNr(3))
            
          EndIf
          
          
        EndIf
        
      EndIf
      ;}
      Delay(30)
      
      ExamineMouse()
      
    Until Event = #PB_Event_CloseWindow Or MouseButton(2) ; End of the event loop
    ;}
  EndIf
EndIf
;}


End
And here are an other example
http://purebasic.stdojedmahr.de/projekte/Example.zip

and the screenshot
Image


and (at last) the beta of the lib
http://purebasic.stdojedmahr.de/projekte/SGbeta.ZIP

Posted: Mon Oct 23, 2006 7:09 pm
by Shannara
I was going to use it, until I realized you need the initmouse or initkeyboard for the bugger to work, instead of using regular mouse or regular keyboard. That puts of people like me who uses graphic subsystems.

Hopefully, once the above is taken care of, I can use it again.

Posted: Tue Oct 24, 2006 7:21 am
by Hurga
Hm...
Can you give me an idea how to use Mouse and Keyboard in a screen enviroment without initmouse() and initkeyboard()?

Posted: Tue Oct 24, 2006 2:17 pm
by Intrigued
This sounds interesting, but no go in PB 4. Bummer (kicks dirt)

Posted: Tue Oct 24, 2006 4:15 pm
by Hurga
@Intrigued:
Strange - I coded it in PB4 and test it udner PB4. It works ok for me... (but thats the point - maybe ONLY for the coders? :D )

Can you tell me, what it does?

Posted: Tue Oct 24, 2006 4:52 pm
by Intrigued
Hurga wrote:@Intrigued:
Strange - I coded it in PB4 and test it udner PB4. It works ok for me... (but thats the point - maybe ONLY for the coders? :D )

Can you tell me, what it does?
I got this error:
Line 30: SG_SetBackground() is not a function, array, macro or linked list

Posted: Tue Oct 24, 2006 9:09 pm
by Shannara
WindowMouseX() and WindowMouseY() for the mouse. As for the keyboard, I dont think there are any PB commands yet, to capture keyboard presses for window applications.

Posted: Wed Oct 25, 2006 7:36 am
by Hurga
@Shannara: Sorry for my slowness, but I cant follow you...
I dont understand why to use WindowMouseX() and WindowMouseY() for the mouse, cos this is for windows. I wrote the lib for screens - So the only point for me is, if I use Windowedscreen... (but it seems for me that I dont understand your point - can you explain it to me agaon, please?)


@Intrigued
I think you tried the first example. In line 30 there is the first command of the lib. For me it seems that you forgot to drop the lib in the PureLibraries/UserLibraries folder and the res file in the Residents folder.

You can dl the files here:
http://purebasic.stdojedmahr.de/projekte/SGbeta.ZIP

I think it should work now... hopefully

Posted: Wed Oct 25, 2006 7:00 pm
by Intrigued
Okay, that did it, but brought up another question.

Isn't this really a Windowed application, just not having a boarder, titlebar? Sorry to be ruff or come off that way. But, I would believe a Screen gadget Lib would be just that, where you would code directly onto the Screen and not inside of a Window. Am I missing something?

Still, thanks for the help and sharing.

*thumbs up*

Posted: Wed Oct 25, 2006 7:24 pm
by Fluid Byte
Shannara wrote:I was going to use it, until I realized you need the initmouse or initkeyboard for the bugger to work, instead of using regular mouse or regular keyboard. That puts of people like me who uses graphic subsystems.
I think I know what he means. When you use InitMouse() the mouse will be captured to the screen. So it's invisible and locked to screen coordinates. Now, maybe you want to make a game running in a window rather then fullscreen (OpenWindowedScreen()). If you do you can hardly control the window because of the symptoms I mentioned above. Therefore it would be better to use WindowMouseX / Y instead of InitMouse().

As for the keyboard issue. I think you can use GetAsyncKeyState_() to catch a specific keypress. Haven't tested it yet but it should work.

Posted: Wed Oct 25, 2006 7:35 pm
by ricardo
The screenshot is showing your desktop? Im asking because i saw your Foxmail ticketbar in front and im confused... Maybe because i never used screens with PB... sorry if my question is too stupid :P

Posted: Wed Oct 25, 2006 10:49 pm
by Shannara
Thats what I mean. I'm working on a windowed game. But do not want to use any window control. For the most part, this will allow users to run in either full screen or windowed mode (depending on their wishes). Windowed mode provides excellent way to debugging ... but debugging in full screen is horrible ..

Plus the sample of the 3.94 version is windowed and not full screen ..

Posted: Thu Oct 26, 2006 7:41 am
by Hurga
Isn't this really a Windowed application, just not having a boarder, titlebar? Sorry to be ruff or come off that way. But, I would believe a Screen gadget Lib would be just that, where you would code directly onto the Screen and not inside of a Window. Am I missing something?
The windowed screen is only for better debugging (as Shannara said its horrible to debug in full screen. But you can change the example to fullscreen, no probs). All gadgets are drawn directly to the screen (and made out of Boxes, lines and so on)

You can have a look at the source (the old version) - you can found it in the PBOSL. I tried not to use any API, so it should be useable under Linux (and MAc, if 4.0 comes out)

//EDIT:
I´m using the screengadgetlib with my current project. If you are interested to see it working, look here (screenshots and a demo):
http://www.purebasic.fr/german/viewtopi ... 60&start=0
The game itself is in english, the thread in german

@ricardo
No, I used windowed screen, and so foxmail bar was on top of it. Its a screen shot of the screen, I opened, would be precise :-)

@Shannara
I agree, thats why I use Windowed Screen for testing too.
Let me see if I understand now: So you want to make it as Windowed game, but dont want to use any window-controls. And you prefer WindowMousex/Y. Is this right.
Hm, this would mean, that you can move your mose freely around. But you have problems(is it right) if you use Windomousex/y in fullscreen?[/url]

Posted: Thu Oct 26, 2006 5:12 pm
by Shannara
Right, it would require a compilerif statements for mouse checking depending if it's fullscreen or windowed mode. WindowMouseX/Y doesnt work on full screen.

Posted: Fri Oct 27, 2006 6:57 am
by Hurga
Ok, I think I´d understand what you mean. Lets see what I can do. (CAn take a while)
Thx for the suggestion