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 


Can I draw arrows on the canvas

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

Joined: 13 Sep 2018
Posts: 202

PostPosted: Mon Feb 22, 2021 7:37 am    Post subject: Can I draw arrows on the canvas Reply with quote

I can draw a straight line. I want to draw it as an arrow. What should I do
Code:
if f then f.Destroy() end
f=createForm()
--f.BorderStyle='bsNone'
f.Color=0x00ffff
f.setSize(300,300)
f.Position='poDesktopCenter'
f.FormStyle='fsSystemStayOnTop'
f.tag=0
p=createLabel(f)
p.Align='alBottom'
p.font.size=15
p.caption=string.format('OnPaint:  X:%s     Y:%s',x,y)
f.setLayeredAttributes(0xB4,230,3,3)

local xx , yy = 0 , 0
function OnPaint(sender,xx,yy,x,y)
  sender.repaint()
  sender.Canvas.Pen.Color=0x00
  sender.Canvas.Pen.Width=2
  sender.Canvas.Brush.Color=0xff
  sender.Canvas.Brush.Style=1
  --sender.Canvas.ellipse(xx,yy,x,y)
  --sender.Canvas.roundRect(xx,yy,x,y,16,16)
  sender.Canvas.line(xx,yy,x,y)
  sender.Canvas.textOut(250,50,'↑↑')
  sender.Canvas.textOut(250,150,'Drag')
  sender.Canvas.textOut(250,250,'↓↓')
  p.caption=string.format('OnPaint:  X:%s     Y:%s',x,y)
end
OnPaint(f,20,180,200,60)
f.OnMouseDown=function(sender,button,x,y)  xx,yy=x,y
  f.tag=1
    p.caption=string.format('MouePos:  X:%s     Y:%s',x,y)
    if x>=f.Width-100 then f.dragNow() f.tag=0  end
end
f.OnMouseUp=function() f.tag=0  end
f.OnMouseMove=function(sender,x,y)  if f.tag==1 then OnPaint(sender,xx,yy,x,y)  end end




Illustration.png
 Description:
 Filesize:  16.7 KB
 Viewed:  1947 Time(s)

Illustration.png


Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Mon Feb 22, 2021 8:38 am    Post subject: Reply with quote

yes, use math. I suck at it, but this seems to work somehow

Code:

local dpiscale=192/getScreenDPI()

if f then f.Destroy() end
f=createForm()
--f.BorderStyle='bsNone'
f.Color=0x00ffff
f.setSize(800*dpiscale,600*dpiscale)
f.Position='poDesktopCenter'
f.FormStyle='fsSystemStayOnTop'
f.tag=0
p=createLabel(f)
p.Align='alBottom'
p.font.size=15
p.caption=string.format('OnPaint:  X:%s     Y:%s',x,y)
f.setLayeredAttributes(0xB4,230,3,3)

local xx , yy = 0 , 0
function OnPaint(sender,xx,yy,x,y)
  sender.repaint()
  sender.Canvas.Pen.Color=0x00
  sender.Canvas.Pen.Width=dpiscale*4
  sender.Canvas.Brush.Color=0xff
  sender.Canvas.Brush.Style=1
  --sender.Canvas.ellipse(xx,yy,x,y)
  --sender.Canvas.roundRect(xx,yy,x,y,16,16)
  sender.Canvas.line(xx,yy,x,y)

  local angle=math.atan2(yy-y,xx-x)+0.8
  local angle2=math.atan2(xx-x,yy-y)+0.8

sender.Canvas.line(x,y,x+(dpiscale*20)*math.cos(angle),y+(dpiscale*20)*math.sin(angle))
sender.Canvas.line(x,y,x+(dpiscale*20)*math.sin(angle2),y+(dpiscale*20)*math.cos(angle2))

  sender.Canvas.textOut(250,50,'↑↑')
  sender.Canvas.textOut(250,150,'Drag')
  sender.Canvas.textOut(250,250,'↓↓')
  p.caption=string.format('OnPaint:  X:%s     Y:%s  A: %s',x,y, angle)
end
OnPaint(f,20,180,200,60)
f.OnMouseDown=function(sender,button,x,y)  xx,yy=x,y
  f.tag=1
    p.caption=string.format('MouePos:  X:%s     Y:%s',x,y)
    if x>=f.Width-100 then f.dragNow() f.tag=0  end
end
f.OnMouseUp=function() f.tag=0  end
f.OnMouseMove=function(sender,x,y)  if f.tag==1 then OnPaint(sender,xx,yy,x,y)  end end

_________________
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
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 202

PostPosted: Mon Feb 22, 2021 9:02 am    Post subject: Reply with quote

Dark Byte wrote:
yes, use math. I suck at it, but this seems to work somehow
Before you reply, I am testing this code, ha ha.
But there is a problem, with the mouse moving drawing there will be flashing;
And how can I draw more arrows without clearing the previous ones



Illustration2.png
 Description:
 Filesize:  211.1 KB
 Viewed:  1932 Time(s)

Illustration2.png


Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Mon Feb 22, 2021 9:14 am    Post subject: Reply with quote

draw to a bitmap with the same size and afterwards draw the bitmap to the window.

that will keep the arrow (and the rest) and solve the flickering

else keep a list of arrow positions and draw them each time. (I still recommend a bitmap to prevent flickering)

_________________
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
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 202

PostPosted: Mon Feb 22, 2021 9:36 am    Post subject: Reply with quote

Dark Byte wrote:
draw to a bitmap with the same size and afterwards draw the bitmap to the window.

that will keep the arrow (and the rest) and solve the flickering

else keep a list of arrow positions and draw them each time. (I still recommend a bitmap to prevent flickering)

I don't know how to use bitmap. Can you give me an example
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Mon Feb 22, 2021 10:26 am    Post subject: Reply with quote

Code:

local dpiscale=192/getScreenDPI()

if f then f.Destroy() end
if bm then bm.destroy() end



f=createForm()
bm=createBitmap()
lines={}

--f.BorderStyle='bsNone'
f.Color=0x00ffff
f.setSize(800*dpiscale,600*dpiscale)
bm.Width=f.ClientWidth
bm.Height=f.ClientHeight

f.Position='poDesktopCenter'
f.FormStyle='fsSystemStayOnTop'
f.tag=0
p=createLabel(f)
p.Align='alBottom'
p.font.size=15
p.caption=string.format('OnPaint:  X:%s     Y:%s',x,y)
f.setLayeredAttributes(0xB4,230,3,3)
f.OnPaint=function(sender)
  f.canvas.draw(0,0,bm)
end


local xx , yy = 0 , 0
function UpdateBitmapWithTempLine(sender,xx,yy,x,y)
  local i
  sender.canvas.brush.color=0xffff
  sender.canvas.clear()


  sender.Canvas.Pen.Color=0x00
  sender.Canvas.Pen.Width=dpiscale*4
  sender.Canvas.Brush.Color=0xff
  sender.Canvas.Brush.Style=1
  local angle
  local angle2

  --draw the previous lines
  for i=1,#lines do
    local xx=lines[i].startx
    local yy=lines[i].starty
    local x=lines[i].stopx
    local y=lines[i].stopy

    sender.Canvas.line(xx,yy,x,y)
    angle=math.atan2(yy-y,xx-x)+0.8
    angle2=math.atan2(xx-x,yy-y)+0.8
    sender.Canvas.line(x,y,x+(dpiscale*20)*math.cos(angle),y+(dpiscale*20)*math.sin(angle))
    sender.Canvas.line(x,y,x+(dpiscale*20)*math.sin(angle2),y+(dpiscale*20)*math.cos(angle2))
  end

  --draw the temporary line
  sender.Canvas.line(xx,yy,x,y)
  angle=math.atan2(yy-y,xx-x)+0.8
  angle2=math.atan2(xx-x,yy-y)+0.8
  sender.Canvas.line(x,y,x+(dpiscale*20)*math.cos(angle),y+(dpiscale*20)*math.sin(angle))
  sender.Canvas.line(x,y,x+(dpiscale*20)*math.sin(angle2),y+(dpiscale*20)*math.cos(angle2))

  --draw gui
  sender.Canvas.textOut(f.Width-100*dpiscale,100*dpiscale,'↑↑')
  sender.Canvas.textOut(f.Width-100*dpiscale,300*dpiscale,'Drag')
  sender.Canvas.textOut(f.Width-100*dpiscale,500*dpiscale,'↓↓')
  p.caption=string.format('OnPaint:  X:%s     Y:%s  A: %s',x,y, angle)

  f.repaint()
end
OnPaint(f,20,180,200,60)
f.OnMouseDown=function(sender,button,x,y)
  xx,yy=x,y
  f.tag=1
  p.caption=string.format('MouePos:  X:%s     Y:%s',x,y)
  if x>=f.Width-100 then f.dragNow() f.tag=0  end
end
f.OnMouseUp=function(sender, button, x,y)
  f.tag=0
  local a=(xx-x)*(xx-x)
  local b=(yy-y)*(yy-y)
  local c=math.sqrt(a+b)
  if c>4 then
    --only save long enough lines
    local line={}
    line.startx=xx
    line.starty=yy
    line.stopx=x
    line.stopy=y

    table.insert(lines, line)
  end
end
f.OnMouseMove=function(sender,x,y)  if f.tag==1 then UpdateBitmapWithTempLine(bm,xx,yy,x,y)  end end

UpdateBitmapWithTempLine(bm,0,0,0,0)

_________________
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
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 202

PostPosted: Mon Feb 22, 2021 10:56 am    Post subject: Reply with quote

Dark Byte wrote:
Wow, that's great. That's what I want. Thank you very much. Very Happy
Is it possible to clear one of the arrows? Or destroy it in the reverse order of the original drawing, because I see that a table is used in the code, and I wonder if it can be used to expand it
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