Is it possible for ReadPixel to work outside the Hollywood window?

Find quick help here to get you started with Hollywood
Post Reply
Severin
Posts: 7
Joined: Wed Oct 25, 2017 8:17 pm

Is it possible for ReadPixel to work outside the Hollywood window?

Post by Severin » Sat Apr 13, 2019 2:12 am

I'm trying to write a program to display the mouse position and the colour of the pixel it's over and display the info in the windows titlebar but if the mouse is outside the window I get a "Specified pixel is out of range!" requester.

This is on Amiga OS4 and I'm assuming that under the hood it's using the graphics.library ReadPixel() and the windows RastPort instead of the screens. It's a pity it doesn't use ReadPixelColor() which doesn't use Rastports as you just pass the x an y coordinates.

Here's my source, can anyone suggest a way round the problem?

@DISPLAY{Title = "Colour:$000000 X=0000 Y=0000", X = 0, Y = 0, Width = 400, Height = 1, NoModeSwitch = TRUE}
CtrlCQuit(TRUE)
EscapeQuit(TRUE)
Function p_Update(msg)
SetTitle("Colour:$" + HexStr(ReadPixel(msg.x, msg.y)) + " X=" + msg.x + " Y=" + msg.y +" ")
EndFunction
InstallEventHandler({OnMouseMove = p_Update})
Repeat
WaitEvent
Forever

Another little niggle is I can't set the window height to 0 so I'd only get the titlebar and none of the bottom borders.

Severin
Posts: 7
Joined: Wed Oct 25, 2017 8:17 pm

Re: Is it possible for ReadPixel to work outside the Hollywood window?

Post by Severin » Sat Apr 13, 2019 4:27 am

Slight update to the source so you don't have to point out my obvious mistakes.

@DISPLAY{Title="Colour:$000000 X=0000 Y=0000", X=0, Y=0, Width=400, Height=400, NoModeSwitch=True}

CtrlCQuit(TRUE)
EscapeQuit(TRUE)

Function p_Update(msg)
SetTitle("Colour:$"..HexStr(ReadPixel(msg.x,msg.y)).." X="..StrStr(msg.x).." Y="..StrStr(msg.y).." ")
EndFunction

InstallEventHandler({OnMouseMove = p_Update})

Repeat
WaitEvent
Forever

changed the height to 400 so I could get further and fixed the .. instead of + and strstr instead of str (which seems very weird to me).

User avatar
airsoftsoftwair
Posts: 2968
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Is it possible for ReadPixel to work outside the Hollywood window?

Post by airsoftsoftwair » Sat Apr 13, 2019 10:27 am

Sorry, that's not going to work. On AmigaOS it might be possible to read from the screen's bitmap without much overhead but on other systems this is going to be painfully slow. To do what you want, just grab a snapshot to a brush and then use ReadPixel() on that.

Severin
Posts: 7
Joined: Wed Oct 25, 2017 8:17 pm

Re: Is it possible for ReadPixel to work outside the Hollywood window?

Post by Severin » Sat Apr 13, 2019 4:57 pm

Thanks for confirming it won't work. I was trying to avoid the screengrab alternative. amiblitz has incompatability problems, maybe i do it with python or as a very, very, very last resort use the dreaded C.

Post Reply