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 


Basic Idea Create Custom Tooltips (CEEdit)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Wed Jan 22, 2020 7:20 am    Post subject: Basic Idea Create Custom Tooltips (CEEdit) Reply with quote

From this topic: https://forum.cheatengine.org/viewtopic.php?t=613222

I try to make a basic idea for custom tooltip.

Code:
f = createForm()

edit1 = createEdit(f)
edit1.setPosition(20,20)
edit1.setSize(200,30)
edit1.Name = 'edit1'
edit1.Text = ''

edit2 = createEdit(f)
edit2.setPosition(20,edit1.Top + edit1.Height + 20)
edit2.setSize(200,30)
edit2.Name = 'edit2'
edit2.Text = ''

local v_url = 'https://i.stack.imgur.com/fM8wq.png'

function createPictureFromURL(url)
 local http = getInternet()
 local file = http.getURL(url)
 http.destroy()
 local picture = createPicture()
 local stream = createStringStream(file)
 picture.loadFromStream(stream)
 return picture
end

function createTooltip(sender, ttext)
 local tt_panel, tt_label, tt_img, c, timer

 if tt_panel then tt_panel.Destroy() end
 if tt_label then tt_label.Destroy() end
 if tt_img then tt_img.Destroy() end
 if timer then timer.Destroy() end

 tt_panel = createPanel(f)  -- Adjust form name here
 tt_panel.setSize(150,100)
 tt_panel.BorderStyle = 'bsNone'
 tt_panel.Left = sender.Left + 20
 tt_panel.Top = sender.Top +  5
 tt_panel.bringToFront()

 tt_img = createImage(tt_panel)
 tt_img.Align = 'alClient'
 tt_img.Stretch = true
 --tt_img.Picture.loadFromStream(findTableFile('tt1.png').Stream)
 image = createPictureFromURL(v_url)
 tt_img.setPicture(image)

 tt_label = createLabel(tt_panel)
 tt_label.Caption = ttext
 tt_label.Alignment = 'taCenter'
 --tt_label.AutoSize = false
 tt_label.WordWarp = true
 tt_label.Transparent = true
 tt_label.Font.Color = 55295
 tt_label.Font.Size = 12
 --tt_label.setSize(tt_panel.Width - 10, tt_panel.Height - 10)
 --tt_label.setPosition(10,10)  -- need adjust for component align
 tt_label.anchorSideLeft.control = tt_panel
 tt_label.anchorSideLeft.side = asrCenter
 tt_label.anchorSideTop.control = tt_panel
 tt_label.anchorSideTop.side = asrCenter
 tt_panel.Visible = false

 c = 0

 timer=createTimer(f, false)
 timer.Interval = 100
 timer.OnTimer=function(timer)
  tt_panel.Visible = true
  tt_panel.bringToFront()
  c = c + 10
  if c == 200 then
   tt_panel.Visible = false
   timer.Enabled = false
  end
 end
 timer.Enabled = true
end

function showTooltip(sender)
 local x = sender.getName()
 if x == 'edit1' then
  createTooltip(edit1, 'Enter Name')
 elseif x == 'edit2' then
  createTooltip(edit2, 'Enter Pass')
 else
  return nil
 end
end

function hideTooltip()
 if tt_panel then
  if timer then
   timer.Enabled = false
   timer.Destroy()
   tt_panel.Visible = false
  end
 end
end

f.Show()

edit1.onMouseEnter = showTooltip
edit1.onMouseLeave = hideTooltip

edit2.onMouseEnter = showTooltip
edit2.onMouseLeave = hideTooltip


But seem the timer does not work properly or 'OnMouseLeave The Component' event seems does not work properly.
Can someone check and fix it?.

This is just a basic idea. Of course, need to develop the idea at least:
- Adjust the tooltip window/bubble position according to the form size, which means set the tooltip position automatically if over from form size.
- More variation of tooltips bubble is needed.
Anyhow, the point you are no need to 're-write the code again and again' for each form components. especially for CEEdit Box.



Capture.JPG
 Description:
Basic idea for custom tooltip
 Filesize:  85.79 KB
 Viewed:  1573 Time(s)

Capture.JPG



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

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Wed Jan 22, 2020 10:17 am    Post subject: Reply with quote

Good job buddy congratulations.
And an alternative. Smile

Code:
if f then f.Destroy() end
local f = createForm(true)
f.Position = poDesktopCenter
f.Width = 220
f.Height = 160

local e1 = createEdit(f)
e1.Height = 24
e1.Left = 5
e1.Top = 5
e1.Width = 160

local e2 = createEdit(f)
e2.Height = 24
e2.Left = 5
e2.Top = 50
e2.Width = 160

local e3 = createEdit(f)
e3.Height = 24
e3.Left = 5
e3.Top = 100
e3.Width = 160

function PopUp1(f, item, left, top, text)
local item1 = createLabel(f)
item1.caption = text
item1.Left = item.left + 10
item1.Top = item.top + item.Height
item1.visible=false
local t1=createTimer(f)
t1.Interval=10
t1.OnTimer=function()
item.OnMouseMove = function()
item1.visible=true
end
item.OnMouseLeave = function()
item1.visible=false
end
end
end

PopUp1(f, e1, 10, 30, "Please write a valid e-mail")
PopUp1(f, e2, 10, 30, "Please write your password")
PopUp1(f, e3, 10, 30, "Please retype your password")

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Wed Jan 22, 2020 6:50 pm    Post subject: Reply with quote

Ok, here is the modified script.

Code:
f = createForm()

edit1 = createEdit(f)
edit1.setPosition(20,20)
edit1.setSize(200,30)
edit1.Name = 'edit1'
edit1.Text = ''

edit2 = createEdit(f)
edit2.setPosition(20,edit1.Top + edit1.Height + 20)
edit2.setSize(200,30)
edit2.Name = 'edit2'
edit2.Text = ''

local v_url = 'https://i.stack.imgur.com/fM8wq.png'

function createPictureFromURL(url)
 local http = getInternet()
 local file = http.getURL(url)
 http.destroy()
 local picture = createPicture()
 local stream = createStringStream(file)
 picture.loadFromStream(stream)
 return picture
end

function createTooltip(frm, handle, x, y, ttext)
 local tt_panel, tt_label, tt_img, timer, c

 if tt_panel then tt_panel.Destroy() end
 if tt_label then tt_label.Destroy() end
 if tt_img then tt_img.Destroy() end
 if timer then timer.Destroy() end

 tt_panel = createPanel(frm)  -- Adjust form name here
 tt_panel.setSize(150,100)
 tt_panel.BorderStyle = 'bsNone'
 tt_panel.Left = x
 tt_panel.Top = y
 tt_panel.bringToFront()

 tt_img = createImage(tt_panel)
 tt_img.Align = 'alClient'
 tt_img.Stretch = true
 --tt_img.Picture.loadFromStream(findTableFile('tt1.png').Stream) -- use for offline
 image = createPictureFromURL(v_url)
 tt_img.setPicture(image)

 tt_label = createLabel(tt_panel)
 tt_label.Caption = ttext
 tt_label.Align = 'alClient'
 tt_label.Alignment = 'taCenter'
 --tt_label.Anchors = '[akTop,akLeft,akRight,akBottom]'
 tt_label.Font.Color = 55295
 tt_label.Font.Size = 12
 tt_label.anchorSideLeft.control = tt_img
 tt_label.anchorSideLeft.side = asrCenter
 tt_label.anchorSideTop.control = tt_ing
 tt_label.anchorSideTop.side = asrCenter
 tt_label.WordWarp = true
 tt_label.Transparent = true
 tt_panel.Visible = false

 c = 0

 timer=createTimer(frm, false)
 timer.Interval = 100
 timer.OnTimer = function(timer)

  handle.OnMouseEnter = function()
   tt_panel.Visible = true
   tt_panel.bringToFront()
   c = c + 10
    if c == 200 then
     tt_panel.Visible = false
     timer.Enabled = false
    end
   handle.OnMouseLeave = function()
   tt_panel.Visible = false
  end
 end
 end
 timer.Enabled = true
end


f.Show()

createTooltip(f, edit1, edit1.Left + 20, edit1.Top + 5, "Please enter user name")
createTooltip(f, edit2, edit2.Left + 20, edit2.Top + 5, "Please enter password")


NEED TO FIX :
1. Text label word wrap
2. Timer, tooltip autohide for x seconds
3, Auto tooltip position (x,y)

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

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Thu Jan 23, 2020 5:00 am    Post subject: Reply with quote

I am a beginner and the code below appeals to me.
Leaving a clue about how to use the code is a thoughtful detail.
Thank you.

Code:
createTooltip(f, edit1, edit1.Left + 10, edit1.Top + 25, "Please enter user name")
createTooltip(f, edit2, edit2.Left + 10, edit2.Top + 25, "Please enter password")
Code:


Edit:
As a result of the text being long, the Panel does not stretch and the Text does not fit on the panel.
I can see the Text with the deviation below.
Otherwise, the label head and end appear cropped.


[code] tt_panel.Visible = false
tt_panel.Height=tt_label.Height + 20
tt_panel.Width=tt_label.Width + 120[/code]

It may be necessary to rearrange for longer text.

It may be necessary to archive the final version to "Lua Extensions".
Good job buddy, congratulations.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Jan 23, 2020 6:57 am    Post subject: Reply with quote

Aylin wrote:

As a result of the text being long, the Panel does not stretch and the Text does not fit on the panel.
I can see the Text with the deviation below.
Otherwise, the label head and end appear cropped.

It may be necessary to rearrange for longer text.

It may be necessary to archive the final version to "Lua Extensions".


That is why I said on my latest post before :

NEED TO FIX :
1. Text label word wrap
2. Timer, tooltip autohide for x seconds
3, Auto tooltip position (x,y)

The main thing to fix is how to set text label length fit to the panel.

EDIT:
Fix for label centering and word wrapping.

Code:
f = createForm()

edit1 = createEdit(f)
edit1.setPosition(20,20)
edit1.setSize(200,30)
edit1.Name = 'edit1'
edit1.Text = ''

edit2 = createEdit(f)
edit2.setPosition(20,edit1.Top + edit1.Height + 20)
edit2.setSize(200,30)
edit2.Name = 'edit2'
edit2.Text = ''

local v_url = 'https://i.stack.imgur.com/fM8wq.png'

function createPictureFromURL(url)
 local http = getInternet()
 local file = http.getURL(url)
 http.destroy()
 local picture = createPicture()
 local stream = createStringStream(file)
 picture.loadFromStream(stream)
 return picture
end

function splittokens(s)
    local res = {}
    for w in s:gmatch("%S+") do
        res[#res+1] = w
    end
    return res
end

function textwrap(text, linewidth)
    if not linewidth then
        linewidth = 30 --75
    end

    local spaceleft = linewidth
    local res = {}
    local line = {}

    for _, word in ipairs(splittokens(text)) do
        if #word + 1 > spaceleft then
            table.insert(res, table.concat(line, ' '))
            line = {word}
            spaceleft = linewidth - #word
        else
            table.insert(line, word)
            spaceleft = spaceleft - (#word + 1)
        end
    end

    table.insert(res, table.concat(line, ' '))
    return table.concat(res, '\n')
end


function createTooltip(frm, handle, x, y, ttext)
 local tt_panel, tt_label, tt_img, timer, c

 if tt_panel then tt_panel.Destroy() end
 if tt_label then tt_label.Destroy() end
 if tt_img then tt_img.Destroy() end
 if timer then timer.Destroy() end

 tt_panel = createPanel(frm)  -- Adjust form name here
 tt_panel.setSize(150,100)
 tt_panel.BorderStyle = 'bsNone'
 tt_panel.Left = x
 tt_panel.Top = y
 tt_panel.bringToFront()

 tt_img = createImage(tt_panel)
 tt_img.Align = 'alClient'
 tt_img.Stretch = true
 --tt_img.Picture.loadFromStream(findTableFile('tt1.png').Stream) -- use for offline
 image = createPictureFromURL(v_url)
 tt_img.setPicture(image)

 tt_label = createLabel(tt_panel)
 tt_label.Caption = ttext
 tt_label.Align = 'alClient'
 tt_label.Alignment = 'taCenter'
 tt_label.Font.Color = 55295
 tt_label.Font.Size = 12
 tt_label.anchorSideLeft.control = tt_panel
 tt_label.anchorSideLeft.side = asrCenter
 tt_label.anchorSideTop.control = tt_panel
 tt_label.anchorSideTop.side = asrCenter
 tt_label.Layout = 'tlCenter'
 tt_panel.Visible = false

 c = 0

 timer=createTimer(frm, false)
 timer.Interval = 100
 timer.OnTimer = function(timer)

  handle.OnMouseEnter = function()
   tt_panel.Visible = true
   tt_panel.bringToFront()
   c = c + 10
    if c == 200 then
     tt_panel.Visible = false
     timer.Enabled = false
    end
   handle.OnMouseLeave = function()
   tt_panel.Visible = false
  end
 end
 end
 timer.Enabled = true
end


f.Show()

createTooltip(f, edit1, edit1.Left + 20, edit1.Top + 5, textwrap("Please enter user name",20))
createTooltip(f, edit2, edit2.Left + 20, edit2.Top + 5, textwrap("Please enter password",20))

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

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Thu Jan 23, 2020 8:37 am    Post subject: Reply with quote

Thanks for the fix. Now it works more stable.
_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website 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