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.
Is it possible for ReadPixel to work outside the Hollywood window?
Re: Is it possible for ReadPixel to work outside the Hollywood window?
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).
@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).
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Is it possible for ReadPixel to work outside the Hollywood window?
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.
Re: Is it possible for ReadPixel to work outside the Hollywood window?
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.