View previous topic :: View next topic |
Author |
Message |
Gou Cheater Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Thu Feb 08, 2018 3:36 pm Post subject: Changing image when the mouse hovers above it |
|
|
Hello guys! So i need some help once again.
I have an image in my form, and i've set it to not visible. I want it to become visible whenever a mouse hovers above it.
This is my code, but it doesnt seem to work
Code: | function PictureMouseEnter(sender)
UDF1.Picture.Visible=true
end
|
The code looks perfectly fine to me. I've set it for "on mouse enter" event.
Any ideas?
Thanks!
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Thu Feb 08, 2018 5:39 pm Post subject: |
|
|
at a guess MouseEnter probably isn't run when the object isn't visible, you may need to add the image to a panel and set the mouse events on that so that the panel is still visible and trigger the image appearing and disappearing.
yeah that's it. but the simple panel option isn't working because causing the image to appear and moving the mouse will cause the mouse to leave the panel, which causes the image to disappear at which point it's back in the panel, and... sigh. So it looks like you'd need the OnEnter set for the panel and the OnLeave to be set for the image itself.... except that in testing OnLeave does not appear to trigger when the mouse exits via the bottom and right sides, only the top and left. sigh.
Well then I suppose the next step is to try using the mouse moved event on the entire form and just manually checking if the mouse is inside, it's fairly trivial code.
Code: | function isMouseInside(control)
local x,y = getMousePos()
x,y = control.screenToClient(x,y)
return x > 0 and x < control.width and
y > 0 and y < control.height
end
-- testing code, on form
function onMove(sender)
UDF1.CEImage1.Visible = isMouseInside(UDF1.CEImage1)
UDF1.CEImage2.Visible = isMouseInside(UDF1.CEPanel1)
-- edit ^ could/should be CEImage2 not CEPanel1 depending on desired effect
-- added print v after image in panel failed to work
print(isMouseInside(UDF1.CEPanel1) and 1 or 0, os.clock())
end
|
which now works for the plain image because when you mouse over it when it's invisible the form is what's visible and so gets the event and when you mouse out it's on the form again, but does not work for the image inside of a panel because it's the panel that gets the event not the main form so the event would have to always be set on parent of the image. Simple enough but I was hoping for something that would work for both with the same setup....
edit: hm, seems the mouse move event can pass x,y values as well but I got less consistent results testing with that than the above code so...
|
|
Back to top |
|
|
Gou Cheater Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Thu Feb 08, 2018 6:10 pm Post subject: |
|
|
So from what i understand it's too complicated right?
It's not anything too important anyway. I am using mgr.inz.Player's code to make the form transparent (from the thread /viewtopic.php?t=586609 ), and i want an "exit" X button that turns red when the mouse hovers above it.
It's fine. It's just that this would be a neat extra.
Thanks for your help once again FreeER
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Thu Feb 08, 2018 6:27 pm Post subject: |
|
|
instead of making it visible, just load it with a different image
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Gou Cheater Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Thu Feb 08, 2018 6:34 pm Post subject: |
|
|
Thanks for the reply Dark Byte!
What would the code for that be?
I am guessing something like
Code: | UDF1.TPicture = (findTableFile("Image.png")) |
?
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Thu Feb 08, 2018 6:52 pm Post subject: |
|
|
Easiest to just have the image with the bitmap on the form, and then do something like
Code: |
if over then
UDF1.CEImage3.Picture.Assign(UDF1.CEImage1.Picture)
else
UDF1.CEImage3.Picture.Assign(UDF1.CEImage2.Picture)
end
|
and CEImage1 and 2 would then be invisible
But you can of course use tablefiles as well
Code: |
UDF1.CEImage3.Picture.loadFromStream(findTableFile('highlighted.png').stream)
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
|
Back to top |
|
|
Gou Cheater Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Fri Feb 09, 2018 10:39 am Post subject: |
|
|
I ended up doing this
Code: | function ExitMouseEnter(sender)
UDF1.CEImage1.Picture.loadFromStream(findTableFile('x1.png').stream)
end
function ExitMouseLeave(sender)
UDF1.CEImage1.Picture.loadFromStream(findTableFile('x2.png').stream)
end |
and it seems to work.
Thanks for the replies guys!
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Feb 11, 2018 3:49 am Post subject: |
|
|
Code: | pic1 = createPicture()
pic1.loadFromStream(findTableFile('x1.png').stream)
pic2 = createPicture()
pic2.loadFromStream(findTableFile('x2.png').stream)
function CEImage1MouseEnter(sender)
sender.Picture.Bitmap = pic1.Bitmap
end
function CEImage1MouseLeave(sender)
sender.Picture.Bitmap = pic2.Bitmap
end |
or
Code: | pic1 = createPicture()
pic1.loadFromStream(findTableFile('x1.png').stream)
pic2 = createPicture()
pic2.loadFromStream(findTableFile('x2.png').stream)
function CEImage1MouseEnter(sender)
sender.Picture.Assign(pic1)
end
function CEImage1MouseLeave(sender)
sender.Picture.Assign(pic2)
end |
_________________
|
|
Back to top |
|
|
|