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 


Avoid flicker when pan an image

 
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: 1668

PostPosted: Thu Sep 29, 2022 10:54 pm    Post subject: Avoid flicker when pan an image Reply with quote

I make an image viewer and pan by mouse events. But when mouse move the image (bitmap) going flicker. How to fix this?.

Try this code :

Code:
function createScrollBox(Parent)
local box = createComponentClass('TScrollBox', Parent)
 box.Parent = Parent
 return box
end

if f then f.Destroy() end

f = createForm()
f.setSize(600,600)
f.Position = 'poDesktopCenter'
f.Caption = 'CRDR - Image Viewer'
f.BorderStyle = 'bsFixed'
f.DoubleBuffered = true

scr = createScrollBox(f)
scr.Left = 8
scr.Top = 8
scr.Width = 584
scr.Height = 584
scr.AutoScroll = true

img = createImage(scr)
img.setSize(192,152)
img.Cursor = -22

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

function fLoad()
 url = "https://st.motortrend.com/uploads/sites/5/2018/11/2019-Mazda3-hatch-profile.jpg"
 mypic = createPictureFromURL(url)
 img.setPicture(mypic)
 img.AutoSize = true
end

local m_PanStartPoint = {}
m_PanStartPoint.X = 0
m_PanStartPoint.Y = 0
DeltaX = 0
DeltaY = 0
MouseIsDown = false


function img_MouseDown(sender, X, Y)
 X,Y = img.ScreenToClient(getMousePos())
 if isKeyPressed(VK_LBUTTON) then
  MouseIsDown = true
  m_PanStartPoint.X = X
  m_PanStartPoint.Y = Y
  img_MouseMove()
 end
end

function img_MouseMove(sender, X, Y)
 X,Y = img.ScreenToClient(getMousePos())
 -- if isKeyPressed(VK_LBUTTON) then
 if MouseIsDown == true then
  DeltaX  = (m_PanStartPoint.X - X)
  DeltaY  = (m_PanStartPoint.Y - Y)
  scr.HorzScrollBar.Position = DeltaX - scr.HorzScrollBar.Position
  scr.VertScrollBar.Position = DeltaY - scr.VertScrollBar.Position
 end
end

function img_MouseUp(sender, X, Y)
 X,Y = img.ScreenToClient(getMousePos())
 MouseIsDown= false
 m_PanStartPoint.X = X
 m_PanStartPoint.Y = Y
end

function FormClose(sender)
 closeCE()
 return caFree
end


f.Show()
fLoad()
img.OnMouseDown = img_MouseDown
img.OnMouseMove = img_MouseMove
img.OnMouseUp = img_MouseUp
--f.OnClose = FormClose()

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
DhaosCollider
How do I cheat?
Reputation: 0

Joined: 12 Mar 2022
Posts: 7

PostPosted: Fri Sep 30, 2022 2:52 am    Post subject: Reply with quote

Code:
function img_MouseMove(sender)
 -- if isKeyPressed(VK_LBUTTON) then
 if MouseIsDown == true then
  local X,Y = img.ScreenToClient(getMousePos())
  scr.HorzScrollBar.Position = X - scr.HorzScrollBar.Position
  scr.VertScrollBar.Position = Y - scr.VertScrollBar.Position
 end
end

You want reverse?
Code:
function img_MouseMove(sender)
 -- if isKeyPressed(VK_LBUTTON) then
 if MouseIsDown == true then
  local X,Y = img.ScreenToClient(getMousePos())
  local reverse = bNot(X - scr.HorzScrollBar.Position)
  scr.HorzScrollBar.Position = reverse + scr.Width * 1.2
  scr.VertScrollBar.Position = Y - scr.VertScrollBar.Position
 end
end
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Sep 30, 2022 4:21 am    Post subject: Reply with quote

Ok. Great, It work. Thank you
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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