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 


Image Control Repeating Picture?

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

Joined: 30 Aug 2021
Posts: 45

PostPosted: Mon Sep 30, 2024 11:34 pm    Post subject: Image Control Repeating Picture? Reply with quote

Image controls on forms: they have a Stretch [picture] property but not a Repeat [picture] property? Or am I having trouble finding it? Is there a straightforward way to repeat a small image to the height and width of the image control (canvas) -- or any other control? As one does with, say, HTML backgrounds?

My end goal is to find the most efficient way to create a grid with 9x9px cells separated by 1x1px black lines. Users can click anywhere on the grid and I can determine which cell was clicked based on MouseDown x,y.

Going into this project I assumed that having a picture repeat by itself as a background would be more efficient than drawing hundreds of lines. My largest grid is 256x256, so that would require 514 lines including external borders -- or, even worse, 65536 squares.

Thanks!

_________________
It's not cheating. It's playing by my rules.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 34

Joined: 16 Feb 2017
Posts: 1404

PostPosted: Tue Oct 01, 2024 4:42 am    Post subject: Reply with quote

I will present you 2 different projects.
It is better to ask questions or find solutions with code examples.

This is my project:
Code:
if fdf1 then fdf1.Destroy() fdf1=nil end
DP1=getScreenDPI()/96
fdf1=createForm()
fdf1.height=286*DP1 fdf1.width=286*DP1
fdf1.PopupMode=0 fdf1.caption="fdf1"
fdf1.Position="poDesktopCenter" fdf1.ShowInTaskBar="stAlways"
fdf1.BorderStyle="bsSingle"
-------------------------
local imgTbl2 = {}
----------------------- imgTbl2.backImg1 ----- 
imgTbl2.backImg1=createImage(fdf1)
imgTbl2.backImg1.AutoSize=false
imgTbl2.backImg1.height=256*DP1 imgTbl2.backImg1.width=256*DP1 imgTbl2.backImg1.left=15*DP1 imgTbl2.backImg1.top=15*DP1
imgTbl2.backImg1.Font.Style="fsBold" imgTbl2.backImg1.Font.Size=0*DP1
imgTbl2.backImg1.Stretch=true
-----------------------

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

pct2 = createPictureFromURL("https://i.hizliresim.com/8m6rsj6.jpg")
imgTbl2.backImg1.Picture = pct2

--imgTbl2.backImg1.Picture.loadFromStream(findTableFile('exmimg1.jpg').Stream)

function img_px(frm,owr,px,py,nt)
local nxt1 = 0
local lf1 = owr.Left
local tp1 = owr.Top
local hg1 = owr.Height / tonumber(px)
local wd1 = owr.Width / tonumber(py)

  for i=1, tonumber(nt) do
    imgTbl2["imgs"..i] = createImage(frm)
    imgTbl2["imgs"..i].Name = "imgs"..i
    imgTbl2["imgs"..i].Height = hg1 + 0.0
    imgTbl2["imgs"..i].Width = wd1
    imgTbl2["imgs"..i].Top = tp1
    imgTbl2["imgs"..i].Left = lf1
    imgTbl2["imgs"..i].Cursor = -21
    --clicked replace panels

    imgTbl2["pnls"..i] = createPanel(frm)
    imgTbl2["pnls"..i].Name = "pnls"..i
    imgTbl2["pnls"..i].Height = hg1 + 0.0
    imgTbl2["pnls"..i].Width = wd1
    imgTbl2["pnls"..i].Top = tp1
    imgTbl2["pnls"..i].Left = lf1
    imgTbl2["pnls"..i].Cursor = -21
    imgTbl2["pnls"..i].Caption = i
    imgTbl2["pnls"..i].Color = 0xffff00
    imgTbl2["pnls"..i].Visible = false

    lf1 = tonumber(lf1) + tonumber(wd1)
     nxt1 = tonumber(nxt1) + 1
     if nxt1==tonumber(px) then
      nxt1=0 lf1=owr.Left
      tp1 = tonumber(tp1) + tonumber(hg1)
     end
     imgTbl2["imgs"..i].OnClick=function(sender)
       local i1 = i
       local sender1 = imgTbl2["pnls"..i]
       print("Clicked object; "..sender.Name.." - Number of frames; "..i1)
       sender.Visible=false sender1.Visible=true
     end
     imgTbl2["pnls"..i].OnClick=function(sender)
       local i1 = i
       local sender1 = imgTbl2["imgs"..i]
       print("Clicked object; "..sender.Name.." - Number of frames; "..i1)
       sender.Visible=false sender1.Visible=true
     end
  end
end

frm = fdf1
owr = imgTbl2.backImg1
px = 10
py = 10
nt = tonumber(px) * tonumber(py)

img_px(frm,owr,px,py,nt)


---------------------------------------------------------------------
---------------------------------------------------------------------
If we assume that each movement of the coordinate pixels represents "+1",
we can divide it into 9 grids and calculate the results as follows:
Code:
if fdf1 then fdf1.Destroy() fdf1=nil end
DP1=getScreenDPI()/96
fdf1=createForm()
fdf1.height=286*DP1 fdf1.width=286*DP1
fdf1.PopupMode=0 fdf1.caption="fdf1"
fdf1.Position="poDesktopCenter" fdf1.ShowInTaskBar="stAlways"
fdf1.BorderStyle="bsSingle"
-------------------------
local imgTbl2 = {}
----------------------- imgTbl2.backImg1 ----- 
imgTbl2.backImg1=createImage(fdf1)
imgTbl2.backImg1.AutoSize=false
imgTbl2.backImg1.height=256*DP1 imgTbl2.backImg1.width=256*DP1 imgTbl2.backImg1.left=15*DP1 imgTbl2.backImg1.top=15*DP1
imgTbl2.backImg1.Font.Style="fsBold" imgTbl2.backImg1.Font.Size=0*DP1
imgTbl2.backImg1.Stretch=true
-----------------------

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

pct2 = createPictureFromURL("https://i.hizliresim.com/8m6rsj6.jpg")
imgTbl2.backImg1.Picture = pct2

--imgTbl2.backImg1.Picture.loadFromStream(findTableFile('exmimg1.jpg').Stream)


imgTbl2.backImg1.OnMouseDown=function(sender, button, x, y)

p1 = math.floor(x * y)
x1 = math.floor(x / 9)
y1 = math.floor(y / 9)
frame_9 = tonumber(x1) * tonumber(y1)

print("Clicked pixel: "..p1)
print("Clicked grid left to right:: "..x1)
print("Clicked grid from top to bottom:: "..y1)
print("Clicked grid:: "..frame_9)

end


I hope it gave you ideas for your problem and solution.
Or if you wanted something different, we can continue with examples.

_________________
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
gibberishh
Cheater
Reputation: 1

Joined: 30 Aug 2021
Posts: 45

PostPosted: Wed Oct 02, 2024 8:12 pm    Post subject: Reply with quote

Thanks! I can use both your examples. This is very good. I came to the same conclusion as you did: that I will have to use a single large image for the full grid instead of having the image of one square repeat automatically.

Thanks again.

_________________
It's not cheating. It's playing by my rules.
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 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