Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
User avatar
Danilo
Posts: 51
Joined: Wed Feb 26, 2014 7:11 am

Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by Danilo »

SetDesktopTitle(title.s) / GetDesktopTitle()

Code: Select all

Procedure SetDesktopTitle(title.s)
    !document.title = v_title;
EndProcedure

Macro SetDesktopTitle_Macro(_title_)
    !document.title = _title_;
EndMacro

Procedure.s GetDesktopTitle()
    !return document.title;
EndProcedure

If OpenWindow(0, 20, 20, 300, 200, "Window")
  Debug GetDesktopTitle()
  SetDesktopTitle_Macro("Window example")
  Debug GetDesktopTitle()
EndIf

I would like to change the "desktop background" at runtime:
- SetDesktopBackgroundColor( color )
- GetDesktopBackgroundColor()

Would be even better if we also could set a background pattern:
- SetDesktopBackgroundImage( ImageID )
cya,
...Danilo
Fred
Site Admin
Posts: 1510
Joined: Mon Feb 24, 2014 10:51 am

Re: Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by Fred »

To do that, just open a window with the #PB_Window_Background flag, then you can use Get/SetWindowTitle() to change the browser window title. Once Set/GetWindowColor() will be supported, you will be able to change the background window. Then only an image will be missing, a new command could be done for that.
User avatar
Danilo
Posts: 51
Joined: Wed Feb 26, 2014 7:11 am

Re: Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by Danilo »

Fred wrote:To do that, just open a window with the #PB_Window_Background flag,
Thanks Fred, this already works! Very nice!

Code: Select all

If OpenWindow(0,0,0,0,0,"",#PB_Window_Background)
    SetWindowTitle(0,"Window example")
    CreateImage(0,DesktopWidth(0),DesktopHeight(0),24,0)
    If StartDrawing(ImageOutput(0))
        For y = 0 To OutputHeight() Step 20
            Box(0,y   ,OutputWidth(),10,RGB($40,$40,$40))
            Box(0,y+10,OutputWidth(),10,RGB($50,$50,$50))
        Next
        StopDrawing()
    EndIf
    ImageGadget(0,0,0,DesktopWidth(0),DesktopHeight(0),ImageID(0))
    For i = 0 To 5
        ButtonGadget(#PB_Any,20,20+i*25,100,20,"Button "+Str(i+1))
    Next i
    progress = ProgressBarGadget(#PB_Any,130,20,200,20,0,100)
    SetGadgetState(progress,40)
    
    OpenWindow(1,200,80,400,200,"Window",#PB_Window_Tool|#PB_Window_SizeGadget,WindowID(0))
EndIf
Problem: When the browser window size changes, the background window is not resized with it, yet.
Could this be added, and also an event for browser window size change? In this case I could also
re-generate the background image for the ImageGadget().

BTW: Shouldn't SpiderBasic constants be named #SB_XXXX? Using #PB_ is a bit weird for SB.
Maybe better to use #SB_ mainly and for compatibility to PB define the #PB_ constants additionally.
cya,
...Danilo
Fred
Site Admin
Posts: 1510
Joined: Mon Feb 24, 2014 10:51 am

Re: Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by Fred »

I think than if we rename the constants, we can forget about any crossplatform code between SB and PB. I agree it's a bit wierd, but IHMO it worths it.

About the size window event, it should work:

Code: Select all

Procedure BackgroundResize()
  Debug "Resize: "+WindowWidth(0) + "x" + WindowHeight(0)
EndProcedure


If OpenWindow(0,0,0,0,0,"",#PB_Window_Background)
  BindEvent(#PB_Event_SizeWindow, @BackgroundResize(), 0)
    SetWindowTitle(0,"Window example")
    CreateImage(0,DesktopWidth(0),DesktopHeight(0),24,0)
    If StartDrawing(ImageOutput(0))
        For y = 0 To OutputHeight() Step 20
            Box(0,y   ,OutputWidth(),10,RGB($40,$40,$40))
            Box(0,y+10,OutputWidth(),10,RGB($50,$50,$50))
        Next
        StopDrawing()
    EndIf
    ImageGadget(0,0,0,DesktopWidth(0),DesktopHeight(0),ImageID(0))
    For i = 0 To 5
        ButtonGadget(#PB_Any,20,20+i*25,100,20,"Button "+Str(i+1))
    Next i
    progress = ProgressBarGadget(#PB_Any,130,20,200,20,0,100)
    SetGadgetState(progress,40)
   
    OpenWindow(1,200,80,400,200,"Window",#PB_Window_Tool|#PB_Window_SizeGadget,WindowID(0))
    
EndIf
User avatar
Danilo
Posts: 51
Joined: Wed Feb 26, 2014 7:11 am

Re: Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by Danilo »

Fred wrote:About the size window event, it should work:
Thanks, it works. SetGadgetState() for ImageGadget() doesn't seem to work,
so I can't update the background picture.

Code: Select all

Procedure CreateBackground()
    CreateImage(0,WindowWidth(0),WindowHeight(0),24,0)
    If StartDrawing(ImageOutput(0))
        For y = 0 To OutputHeight() Step 20
            Box(0,y   ,OutputWidth(),10,RGB($40,$40,$40))
            Box(0,y+10,OutputWidth(),10,RGB($50,$50,$50))
        Next
        StopDrawing()
    EndIf
EndProcedure

Procedure BackgroundResize()
    ;Debug "Resize: "+WindowWidth(0) + "x" + WindowHeight(0)
    CreateBackground()
    ResizeGadget(0,0,0,WindowWidth(0),WindowHeight(0))
    SetGadgetState(0,ImageID(0))
    Debug GadgetWidth(0) ; correct size, but image not updated/refreshed
    ;UseGadgetList(WindowID(0))
    ;ImageGadget(0,0,0,DesktopWidth(0),DesktopHeight(0),ImageID(0))
EndProcedure


If OpenWindow(0,0,0,0,0,"",#PB_Window_Background)
    BindEvent(#PB_Event_SizeWindow, @BackgroundResize(), 0)
    SetWindowTitle(0,"Window example")
    CreateBackground()
    ImageGadget(0,0,0,DesktopWidth(0),DesktopHeight(0),ImageID(0))
    For i = 0 To 5
        ButtonGadget(#PB_Any,20,20+i*25,100,20,"Button "+Str(i+1))
    Next i
    progress = ProgressBarGadget(#PB_Any,130,20,200,20,0,100)
    SetGadgetState(progress,40)
   
    OpenWindow(1,200,80,400,200,"Window",#PB_Window_Tool|#PB_Window_SizeGadget,WindowID(0))
    
EndIf
cya,
...Danilo
PB.
Posts: 3
Joined: Tue Feb 25, 2014 3:07 am

Re: Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by PB. »

> Shouldn't SpiderBasic constants be named #SB_XXXX? Using #PB_ is a bit weird for SB

Isn't it for compatibility with PureBasic? So we can code an app for desktops
that will also run in the browser, without needing CompilerIf every few lines?
User avatar
Danilo
Posts: 51
Joined: Wed Feb 26, 2014 7:11 am

Re: Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by Danilo »

PB. wrote:> Shouldn't SpiderBasic constants be named #SB_XXXX? Using #PB_ is a bit weird for SB

Isn't it for compatibility with PureBasic? So we can code an app for desktops
that will also run in the browser, without needing CompilerIf every few lines?
Did you miss the next line?
Danilo wrote:Maybe better to use #SB_ mainly and for compatibility to PB define the #PB_ constants additionally.
cya,
...Danilo
Falko
Posts: 2
Joined: Tue Feb 25, 2014 1:35 pm

Re: Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by Falko »

Thank you @Danilo.

I've test it to WindowColor and change in your Code:

Code: Select all

If OpenWindow(0,0,0,0,0,"",#PB_Window_Background)
    SetWindowTitle(0,"Window example")
    CreateImage(0,DesktopWidth(0),DesktopHeight(0),24,0)
    If StartDrawing(ImageOutput(0))
        For y = 0 To OutputHeight() Step 20
            Box(0,y   ,OutputWidth(),10,RGB($40,$40,$40))
            Box(0,y+10,OutputWidth(),10,RGB($50,$50,$50))
        Next
        StopDrawing()
    EndIf
    ImageGadget(0,0,0,DesktopWidth(0),DesktopHeight(0),ImageID(0))
    For i = 0 To 5
        ButtonGadget(#PB_Any,20,20+i*25,100,20,"Button "+Str(i+1))
    Next i
    progress = ProgressBarGadget(#PB_Any,130,20,200,20,0,100)
    SetGadgetState(progress,40)
   
    OpenWindow(1,200,80,400,200,"Window",#PB_Window_Tool|#PB_Window_SizeGadget,WindowID(0))
     CreateImage(1,WindowWidth(1),WindowHeight(1),24,RGB(255,0,0))
    If StartDrawing(ImageOutput(1))
        Box(1,0,0,OutputWidth())
       StopDrawing()
    EndIf
    ImageGadget(1,0,0,WindowWidth(1),WindowHeight(1),ImageID(1))
   
EndIf
User avatar
skywalk
Posts: 47
Joined: Tue Feb 25, 2014 2:13 am
Location: Boston, MA

Re: Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by skywalk »

SetWindowTitle(0, "Window0 w/PB fn") ;<-- Why does this change the browser page title?

Code: Select all

Macro SetDesktopTitle(title_txt)
  ; 'title' fails since it is a JS keyword.
  !document.title = title_txt;
EndMacro
Procedure.s GetDesktopTitle()
  !return document.title;
EndProcedure

;Debug GetDesktopTitle()
SetDesktopTitle("BrowserPage w/JS")
;Debug GetDesktopTitle()
If OpenWindow(0,0,0,0,0,"blah",#PB_Window_Background)
  CreateImage(0,DesktopWidth(0),DesktopHeight(0),24,0)
  If StartDrawing(ImageOutput(0))
      For y = 0 To OutputHeight() Step 20
        Box(0,y   ,OutputWidth(),10,RGB($40,$40,$40))
        Box(0,y+10,OutputWidth(),10,RGB($50,$50,$50))
      Next
    StopDrawing()
  EndIf
  ImageGadget(0,0,0,DesktopWidth(0),DesktopHeight(0),ImageID(0))
  For i = 0 To 5
    ButtonGadget(#PB_Any,20,20+i*25,100,20,"Button "+Str(i+1))
  Next i
  progress = ProgressBarGadget(#PB_Any,130,20,200,20,0,100)
  SetGadgetState(progress,40)
  
  OpenWindow(1,200,80,400,200,"Window1",#PB_Window_Tool|#PB_Window_SizeGadget,WindowID(0))
  CreateImage(1,WindowWidth(1),WindowHeight(1),24,RGB(255,0,0))
  If StartDrawing(ImageOutput(1))
      Box(1,0,0,OutputWidth())
    StopDrawing()
  EndIf
  ImageGadget(1,0,0,WindowWidth(1),WindowHeight(1),ImageID(1))
EndIf
SetWindowTitle(0, "Window0 w/PB fn")  ;<-- Why does this change the browser page title?
SetWindowTitle(1, "Window1 w/PB fn")
When working toward the solution of a problem, it always helps if you know the answer. ~ ?
An expert is one who knows more and more about less and less until he knows absolutely everything about nothing. ~ Weber
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Set/GetDesktopTitle() and Set/GetDesktopBackgroundColor

Post by Peter »

skywalk wrote:SetWindowTitle(0, "Window0 w/PB fn") ;<-- Why does this change the browser page title?
[color=#AA0000]Fred[/color] wrote:just open a window with the #PB_Window_Background flag, then you can use Get/SetWindowTitle() to change the browser window title.
Greetings ... Peter
Post Reply