@Display command

Find quick help here to get you started with Hollywood
Post Reply
SpawnPPC
Posts: 20
Joined: Fri Mar 15, 2024 11:51 pm

@Display command

Post by SpawnPPC »

Hi to all. Hollywood give me error on @DISPLAY line but i don't found any error. Any one tell me where I wrong ?

----------------------------------------------------------

; Configurazione iniziale

Function InitApp()

; Definisce la dimensione della finestra
Local fnaWidth = 400
Local fnaHeight = 300

; Apre una finestra nera centrata sullo schermo
OpenBlackWindow(fnaWidth, fnaHeight)

; Mantiene la finestra aperta in attesa di eventi
Repeat
WaitEvent
Forever

EndFunction

Function OpenBlackWindow(fnaWidth, fnaHeight)
; Determina la dimensione dello schermo e la profondità dei colori
Local screenWidth = GetAttribute(#DISPLAY, #ATTRWIDTH)
Local screenHeight = GetAttribute(#DISPLAY, #ATTRHEIGHT)
; Calcola la posizione della finestra
Local fnaPosX = (screenWidth - fnaWidth) / 2
Local fnaPosY = (screenHeight - fnaHeight) / 2

; Apre la finestra
@DISPLAY {Width = fnaWidth, Height = fnaHeight, Color = #BLACK, Borderless = True, X = fnaPosX, Y= fnaPosY}

EndFunction

; Avvia l'applicazione

InitApp()
User avatar
emeck
Posts: 179
Joined: Fri Apr 03, 2015 3:17 pm

Re: @Display command

Post by emeck »

@SpawnPPC

You are using @DISPLAY inside a function. Preprocessor commands are processed before the rest of the script, so in this case, before your functions are read.

Use @DISPLAY at the start of your script or if you need to create displays while running the script, use the CreateDisplay() function.
PowerBook 5.8 MorphOS 3.18
Mac Mini MorphOS 3.18
plouf
Posts: 528
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: @Display command

Post by plouf »

hello,

emeck is correct just to add a few notes

1 preprocessor command dont accept variables (thats the error compiler tells you), because as said they are proccessed before script execution

2 i see that you need to center screen, there are X and Y special coordination constants for that -> #CENTER

3 Getattribute need a third argument -> GetAttribute(#DISPLAY,0, #ATTRWIDTH)

final ,not about your code, prefer to paste code inse "["code"]" tags, it is creates better readable code :)
Christos
SpawnPPC
Posts: 20
Joined: Fri Mar 15, 2024 11:51 pm

Re: @Display command

Post by SpawnPPC »

Thanx to all ! I will try. Maybe I will return here after ! XD Byeee !!!
SpawnPPC
Posts: 20
Joined: Fri Mar 15, 2024 11:51 pm

Re: @Display command

Post by SpawnPPC »

OK. This is my updated code but I'm not getting the desired result!

I just want to open a completely black window with no gadgets, no borders, with just a custom red X button inside the same window to close the window, and I want it in the top right corner.

But the result is that the window will appear with the white menu bar and with the normal X gadget in the rightmost place of the menu bar. Some idea ? My windows must not be draggable or movable.

Look please:

-----------------------------------------------------

; Variabili globali per la risoluzione dello schermo e profondità dei colori
Global screenWidth, screenHeight, colorDepth

; Funzione per il riconoscimento della risoluzione dello schermo e profondità dei colori
Function DetectScreen()
; Determina la dimensione dello schermo
screenWidth = GetAttribute(#DISPLAY, 1, #ATTRWIDTH)
screenHeight = GetAttribute(#DISPLAY, 1, #ATTRHEIGHT)
; Determina la profondità dei colori
colorDepth = GetAttribute(#DISPLAY, 1, #ATTRDEPTH)
EndFunction

; Funzione per l'apertura di una finestra nera senza bordi
Function OpenBlackWindow()
; Calcola e utilizza le dimensioni della finestra e la posizione per centrarla sullo schermo
If screenWidth = 320 And screenHeight = 200
CreateDisplay(2, {Width = 160, Height = 100, Color = #BLACK, Borderless = True, X = 80, Y = 50})
ElseIf screenWidth = 640 And screenHeight = 480
CreateDisplay(2, {Width = 320, Height = 240, Color = #BLACK, Borderless = True, X = 160, Y = 120})
ElseIf screenWidth = 800 And screenHeight = 600
CreateDisplay(2, {Width = 400, Height = 300, Color = #BLACK, Borderless = True, X = 200, Y = 150})
ElseIf screenWidth = 1024 And screenHeight = 768
CreateDisplay(2, {Width = 512, Height = 384, Color = #BLACK, Borderless = True, X = 256, Y = 192})
ElseIf screenWidth = 1280 And screenHeight = 720
CreateDisplay(2, {Width = 640, Height = 360, Color = #BLACK, Borderless = True, X = 320, Y = 180})
ElseIf screenWidth = 1280 And screenHeight = 800
CreateDisplay(2, {Width = 640, Height = 400, Color = #BLACK, Borderless = True, X = 320, Y = 200})
ElseIf screenWidth = 1280 And screenHeight = 1024
CreateDisplay(2, {Width = 640, Height = 512, Color = #BLACK, Borderless = True, X = 320, Y = 256})
ElseIf screenWidth = 1366 And screenHeight = 768
CreateDisplay(2, {Width = 683, Height = 384, Color = #BLACK, Borderless = True, X = 341, Y = 192})
ElseIf screenWidth = 1440 And screenHeight = 900
CreateDisplay(2, {Width = 720, Height = 450, Color = #BLACK, Borderless = True, X = 360, Y = 225})
ElseIf screenWidth = 1600 And screenHeight = 900
CreateDisplay(2, {Width = 800, Height = 450, Color = #BLACK, Borderless = True, X = 400, Y = 225})
ElseIf screenWidth = 1600 And screenHeight = 1200
CreateDisplay(2, {Width = 800, Height = 600, Color = #BLACK, Borderless = True, X = 400, Y = 300})
ElseIf screenWidth = 1920 And screenHeight = 1080
CreateDisplay(2, {Width = 960, Height = 540, Color = #BLACK, Borderless = True, X = 480, Y = 270})
ElseIf screenWidth = 1920 And screenHeight = 1200
CreateDisplay(2, {Width = 960, Height = 600, Color = #BLACK, Borderless = True, X = 480, Y = 300})
ElseIf screenWidth = 2560 And screenHeight = 1440
CreateDisplay(2, {Width = 1280, Height = 720, Color = #BLACK, Borderless = True, X = 640, Y = 360})
ElseIf screenWidth = 3840 And screenHeight = 2160
CreateDisplay(2, {Width = 1920, Height = 1080, Color = #BLACK, Borderless = True, X = 960, Y = 540})
EndIf

; Mostra il display
OpenDisplay(2)
EndFunction

; Funzione per creare il bottone rosso di uscita
Function CloseButton()
Local closeButtonSize = 30
; Crea un pennello per il pulsante di uscita
Local brushID = CreateBrush(Nil, closeButtonSize, closeButtonSize, #RED)
; Visualizza il pulsante di uscita in alto a destra della finestra
DisplayBrush(brushID, screenWidth - closeButtonSize, 0)
; Visualizza la "X" nera centrata all'interno del pulsante rosso
TextOut(screenWidth - closeButtonSize / 2, closeButtonSize / 2, "X", {Color = #BLACK, Align = #CENTER})
EndFunction

; Configurazione iniziale
Function InitApp()
; Chiama la funzione di riconoscimento della risoluzione dello schermo
DetectScreen()
; Chiama la funzione di apertura della finestra nera
OpenBlackWindow()
; Chiama la funzione per creare il bottone rosso di uscita
CloseButton()

; Mantiene la finestra aperta in attesa di eventi
Repeat
Local event = WaitEvent()
; Controlla se il pulsante di uscita viene cliccato
If event.action = "OnMouseDown"
If event.mousex >= screenWidth - 30 And event.mousex <= screenWidth And event.mousey <= 30
End
EndIf
EndIf
Forever
EndFunction

; Avvia l'applicazione
InitApp()

---------------------------------------------------------
Flinx
Posts: 226
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: @Display command

Post by Flinx »

Your DetectScreen() function reads the size of the standard program window.
Here you have something to work with:

Code: Select all

@DISPLAY {Width = 50, Height = 50, Hidden = True}
t = GetMonitors()
DebugPrint(t[0].Width, t[0].Height)
screenWidth=t[0].Width
screenHeight=t[0].Height
SetDisplayAttributes({X=#RIGHT, Y=#TOP, Width = screenWidth/3, Height = screenHeight/3, Borderless = True, Color = #BLACK, Active = True})
OpenDisplay(1)
ActivateDisplay(1)
Wait(100)
User avatar
jPV
Posts: 624
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: @Display command

Post by jPV »

SpawnPPC wrote: Sun Jul 28, 2024 5:00 pm OK. This is my updated code but I'm not getting the desired result!

I just want to open a completely black window with no gadgets, no borders, with just a custom red X button inside the same window to close the window, and I want it in the top right corner.

But the result is that the window will appear with the white menu bar and with the normal X gadget in the rightmost place of the menu bar. Some idea ? My windows must not be draggable or movable.
I took a quick look at it, and here's how I'd modify your script without changing it too much for now (notice the "Fix" comments):

Code: Select all

; Variabili globali per la risoluzione dello schermo e profondità dei colori
Global screenWidth, screenHeight, colorDepth, displayWidth, displayHeight ; Fix: separate screen and display dimensions
Global closeButtonSize = 30 ; Fix: close button size is needed in several functions. Would be better as Const, if it doesn't need to be dynamic later.

; Funzione per il riconoscimento della risoluzione dello schermo e profondità dei colori
Function DetectScreen()
	; Determina la dimensione dello schermo
	screenWidth = GetAttribute(#DISPLAY, 1, #ATTRHOSTWIDTH)  ; Fix: HOST width
	screenHeight = GetAttribute(#DISPLAY, 1, #ATTRHOSTHEIGHT) ; Fix: HOST height
	; Determina la profondità dei colori
	colorDepth = GetAttribute(#DISPLAY, 1, #ATTRDEPTH)
EndFunction

; Funzione per l'apertura di una finestra nera senza bordi
Function OpenBlackWindow()
	; Calcola e utilizza le dimensioni della finestra e la posizione per centrarla sullo schermo
	displayWidth = screenWidth / 2 ; Fix: calculate display width
	displayHeight = screenHeight / 2 ; Fix: calculate display height

	; Fix: Use calculated dimensions to avoid long pre-defined screen sizes lists (#CENTER could be screenWidth/4 too). "Fixed" makes it non-draggable.
	CreateDisplay(2, {Width = displayWidth, Height = displayHeight, Color = #BLACK, Borderless = True, X = #CENTER, Y = #CENTER, Fixed = True})

	; Mostra il display
	OpenDisplay(2) ; NOTE: the display 1 is left under this display. Maybe you would want to close/hide it, or modify its properties instead of creating a new display.
EndFunction

; Funzione per creare il bottone rosso di uscita
Function CloseButton()
	; Crea un pennello per il pulsante di uscita
	Local brushID = CreateBrush(Nil, closeButtonSize, closeButtonSize, #RED)
	; Visualizza il pulsante di uscita in alto a destra della finestra
	DisplayBrush(brushID, #RIGHT, #TOP) ; Fix: display the brush at top-right position of the display
	; Visualizza la "X" nera centrata all'interno del pulsante rosso
	Local xWidth, xHeight = TextWidth("X"), TextHeight("X")  ; Fix: finetune the X position
	TextOut(#RIGHT - closeButtonSize / 2 + xWidth / 2, closeButtonSize / 2 - xHeight / 2, "X", {Color = #BLACK}) ; Fix: positioning
	FreeBrush(brushID) ; Fix: Free the brush to not leak the memory with "orphan" brushes! You could also draw the X to the brush itself if you'd like to re-use it later and store brush id globally without freeing it. But if local id -> free it!
EndFunction

; Fix: use separate function to handle events installed by the InstallEventHandler
Function HandleInput(msg)
	Switch msg.Action
	Case "OnMouseUp":
		Local x, y = MouseX(), MouseY()
		If x > displayWidth - closeButtonSize And y < closeButtonSize
			End
		EndIf
	EndSwitch
EndFunction   

; Configurazione iniziale
Function InitApp()
	; Chiama la funzione di riconoscimento della risoluzione dello schermo
	DetectScreen()
	; Chiama la funzione di apertura della finestra nera
	OpenBlackWindow()
	; Chiama la funzione per creare il bottone rosso di uscita
	CloseButton()

	; Mantiene la finestra aperta in attesa di eventi
	InstallEventHandler({OnMouseUp = HandleInput}) ; Fix: let's use more standard way to handle events, and "up" is better than "down" in these cases
EndFunction

; Avvia l'applicazione
InitApp()

Repeat ; Fix: the main loop can be at the end for clarity
	WaitEvent
Forever 
If you want to make more buttons, or do the close button in prettier way, I'd use MakeButton(). And setting display attributes for the default screen instead of creating another display could be a good idea, like Flinx already suggested.
SpawnPPC
Posts: 20
Joined: Fri Mar 15, 2024 11:51 pm

Re: @Display command

Post by SpawnPPC »

Thanx, I will try !
Post Reply