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 


Custom Button With Icon

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

Joined: 10 Apr 2015
Posts: 1348

PostPosted: Wed Apr 01, 2020 12:31 am    Post subject: Custom Button With Icon Reply with quote

This is a very basic CE Lua. Just to contribute which maybe help someone who doesn't know yet how to improving to create a custom form component easier using CE Lua.

I. The script

Code:
-----------------------------
-- Custom Button With Icon --
-- By Corroder VCL Bro     --
-- 01-04-2020              --
-- CE 7.0                  --
-----------------------------

Note = [[
frm (object) = object handle eq: form, panel
x,y (integer) = position/location of the custom button on the object (left, top)
w,h (integer) = size of the custom button (width, height)
col (hex, integer) = color of the custom button (ref.: http://www.endprod.com/colors/)
ico (jpg, bmp, png) = picture source for the custom button. Could be from Http, local disk, or table file
txtcol (hex, integer) = the custom button text color
txtsz (integer) = size of text font
txt (string) = text for the custom button
bname (string) = name for the custom button
]]

----------------------------- The function
function createButtonIcon(frm, x, y, w, h, col, ico, txtcol, txtsz, txt, bname)

 local btnCn = createPanel(frm)
 btnCn.setSize(w,h)
 btnCn.setPosition(x,y)
 btnCn.Color = col
 btnCn.BorderStyle = 'bsNone'
 btnCn.BevelOuter = 'bvNove'
 btnCn.BevelInner = 'bvNove'

 local i = frm.getComponentCount()

 if bname == "" or bname == nil then
  btnCn.Name = 'btn'..i
 else
  btnCn.Name = bname
 end

 btnCn.Caption = ""

 local btnIco = createImage(btnCn)
 btnIco.Height = btnCn.Height-10
 btnIco.Width = btnIco.Height
 btnIco.setPosition(10, (btnCn.Height - btnIco.Height) / 2)
 btnIco.Anchors = '[akTop,akLeft,akRight,akBottom]'
 btnIco.Stretch = true
 btnIco.Picture.loadFromFile(ico)

 local btnTxt = createLabel(btnCn)
 btnTxt.Font.Color = txtcol
 btnTxt.Font.Size = txtsz
 btnTxt.Caption = txt
 btnTxt.setPosition(btnIco.Left + btnIco.Width + 5, (btnIco.Height - btnTxt.Height) / 2 + 3)
end

--------------------------------------- Example
f = createForm()
f.Caption = 'Test Custom Button With Icon'
createButtonIcon(f, 10,10, 200, 50, 1115250, 'E:/GLauncherResources/awaken_game.png', 0xffffff, 14, 'Cheat Engine', nil)
createButtonIcon(f, 40,65, 200, 50, 1231210, 'E:/GLauncherResources/folder_icon.png', 0xffffff, 12, 'Auto Assembler', nil)
createButtonIcon(f, 10,120, 200, 50, 0, 'E:/GLauncherResources/home_icon.png', 25250, 15, 'My Hack #1', nil)



II. Mark some options
- For the picture source, you should change for the picture source location. Example:

Code:
myPicture = loadFromStream(findTableFile('blabla.png).Stream)
createButtonIcon(f, 40,175, 200, 30, 9129488, myPicture, 16760576, 11, 'Exit', nil)

-- or

picpath = 'C:/PictureResources/'
createButtonIcon(f, 40,175, 200, 30, 9129488, picpath..'blabla.jpg', 16760576, 11, 'Exit', nil)



Feel free to edit or customize the function to make it better.
Enjoy!

EDIT:
I change this part:

Code:
local i = frm.getComponentCount()

 if bname == "" or bname == nil then
  btnCn.Name = 'cButton'..i
 else
  btnCn.Name = 'c_'..bname
 end

 btnCn.Caption = ""


And a test for run events handler, for example:

Code:
f = createForm()
f.Caption = 'Test Custom Button With Icon'

-- create a custom button and give the button name as : nil = "cButton1" and defined name as "cButton1" = "c_cButton1"
createButtonIcon(f, 40,65, 200, 50, 1231210, 'E:/GLauncherResources/folder_icon.png', 0xffffff, 12, 'Auto Assembler',nil)
createButtonIcon(f, 10,10, 200, 50, 1115250, 'E:/GLauncherResources/awaken_game.png', 0xffffff, 14, 'Cheat Engine','cButton1')

-- check components name on the form
for i = 0, f.ComponentCount - 1 do
  print(f.Component[i].Name)
end

-- make some test functions
function test1()
 showMessage("Hello Cheat Engine!")
 return
end

function test2()
 showMessage("Cheat Engine Lua Script")
 return
end

-- run the event handlers
btn1 = f.findComponentByName('cButton1')
btn2 = f.findComponentByName('c_cButton1')
btn1.OnClick = test1
btn2.OnClick = test2


Should be there are better ways to give the components name (eq.using '_G') so the components will identified as objects to handle some events.
I believe you can customizing it.



Capture.JPG
 Description:
Custom Button With Icon
 Filesize:  23.25 KB
 Viewed:  2493 Time(s)

Capture.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL


Last edited by Corroder on Wed Apr 01, 2020 6:37 am; edited 1 time in total
Back to top
View user's profile Send private message
Aylin
Grandmaster Cheater
Reputation: 9

Joined: 16 Feb 2017
Posts: 592

PostPosted: Wed Apr 01, 2020 4:38 am    Post subject: Reply with quote

Good job dude congratulations.
I like these kinds of images. It makes classic paintings fun.
I think I was given permission to edit.
Like every user, I set it up for myself.

Code:
----------------------------- The function
function createButtonIcon(frm, x, y, w, h, col, ico, txtcol, txtsz, txt, bname, func)

 local btnCn = createPanel(frm)
 btnCn.setSize(w,h)
 btnCn.setPosition(x,y)
 btnCn.Color = col
 btnCn.BorderStyle = 'bsNone'
 btnCn.BevelOuter = 'bvNove'
 btnCn.BevelInner = 'bvNove'
  btnCn.Font.Color = txtcol
 btnCn.Font.Size = txtsz
 btnCn.Caption = "       "..txt
 btnCn.OnMouseMove=function() btnCn.Color=col + 70 end
 btnCn.OnMouseLeave=function() btnCn.Color=col end
 btnCn.OnClick=function() func() end

 local i = frm.getComponentCount()

 if bname == "" or bname == nil then
  btnCn.Name = 'btn'..i
 else
  btnCn.Name = bname
 end


 local btnIco = createImage(btnCn)
 btnIco.Height = btnCn.Height-10
 btnIco.Width = btnIco.Height
 btnIco.setPosition(10, (btnCn.Height - btnIco.Height) / 2)
 btnIco.Anchors = '[akTop,akLeft,akRight,akBottom]'
 btnIco.Stretch = true
 btnIco.Picture.loadFromStream(findTableFile(ico).stream)

end
--------------------------------------- Example
myPicture1 = ("a11.png")
myPicture2 = ("a12.png")
myPicture3 = ("a13.png")
function func1()  end
function func2()  end
function func3()  end

f = createForm()
f.Caption = 'Test Custom Button With Icon'
createButtonIcon(f, 10,10, 200, 50, 1115250, myPicture1, 0xffffff, 14, 'Cheat Engine', nil, func1)
createButtonIcon(f, 40,65, 200, 50, 1231210, myPicture2, 0xffffff, 12, 'Auto Assembler', nil, func2)
createButtonIcon(f, 10,120, 200, 50, 0, myPicture3, 25250, 15, 'My Hack #1', nil, func3)


thanks again.

_________________
Hi Hitler Take control of your trainer
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 MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 33

Joined: 10 Apr 2015
Posts: 1348

PostPosted: Wed Apr 01, 2020 5:07 am    Post subject: Reply with quote

Thanks, Aylin, It's free to edit or customize the function. I just show a basic example of this.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
LongBeardedLion
Expert Cheater
Reputation: 0

Joined: 10 Apr 2020
Posts: 117

PostPosted: Thu Apr 23, 2020 5:42 am    Post subject: Reply with quote

So this works to inject this image inside a game?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions 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