Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Changing image when the mouse hovers above it

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Gou
Cheater
Reputation: 0

Joined: 02 Oct 2017
Posts: 39

PostPosted: Thu Feb 08, 2018 3:36 pm    Post subject: Changing image when the mouse hovers above it Reply with quote

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
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Thu Feb 08, 2018 5:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gou
Cheater
Reputation: 0

Joined: 02 Oct 2017
Posts: 39

PostPosted: Thu Feb 08, 2018 6:10 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Feb 08, 2018 6:27 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Gou
Cheater
Reputation: 0

Joined: 02 Oct 2017
Posts: 39

PostPosted: Thu Feb 08, 2018 6:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Feb 08, 2018 6:52 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Feb 08, 2018 7:34 pm    Post subject: Reply with quote

Try this code :

Code:
myForm = createForm()
myPanel = createPanel(myForm)
myPanel.Height = 120
myPanel.Width = 120
 --- make Panel as flat panel with form face
myPanel.BevelInner = bsNone
myPanel.BevelOuter = bsNone
 --- center panel on form
myPanel.Left = (myForm.left + myForm.width - myPanel.width) / 2
myPanel.Top = (myForm.top + myForm.height - myPanel.height) /2
myPanel.Cursor = -21    -- cursor change to hand point when enter to panel area

function shwImage()
 myImage = createImage(myPanel)
 myImage.Height = 100
 myImage.Width = 100
 myImage.Stretch = true
 myImage.Visible = true
 myImage.Picture.loadFromStream(findTableFile('car.jpg').Stream)
   -- change picture file name with your own and add to CE>Table>Add File
end

function hideImage()
-- myImage.Destroy()
 myImage.Visible = false
end

myForm.show()

myPanel.onMouseEnter = shwImage
myPanel.onMouseLeave = hideImage


Note (Important) :
---------------------
Make sure panel size larger than image size to give space for mouse enter to the panel.
So, when mouse enter to the panel (not image) then image will show properly and disappear when mouse left the panel.

Idea Idea Idea

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Gou
Cheater
Reputation: 0

Joined: 02 Oct 2017
Posts: 39

PostPosted: Fri Feb 09, 2018 10:39 am    Post subject: Reply with quote

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
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Feb 11, 2018 3:49 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites