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 


Drawing using mouse

 
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: Mon Sep 21, 2020 7:59 pm    Post subject: Drawing using mouse Reply with quote

How to draw (i.e:rectangle) using mouse, to make selection area?.

I try (followed FP method):

Code:
if f then f.destroy() end
f = createForm()
f.Position = 'poScreenCenter'
f.setSize(600, 600)

--img = createImage(f)
--img.setPosition(10,10)
--img.setSize(500,500)
--img.Picture.loadFromStream(findTableFile('myimage.jpg').stream)
--img.AutoSize = true


local md = false

local p1 = {}
p1.x = 0
p1.y = 0

local p2 = {}
p2.x = 0
p2.y = 0

local r = {}
r.Left = 0
r.Top = 0
r.Right = 0
r.Bottom = 0

local selrect = {}
selrect.Left = 0
selrect.Top = 0
selrect.Right = 0
selrect.Bottom = 0

f.OnMouseDown = function(sender, button,  x, y)
 if selrect.Left ~= 0 then
    sender.Canvas.Brush.Color = 0xff
    sender.Canvas.Pen.Color = 0xff
    --sender.Canvas.Pen.Mode = 'pmMask'
    --sender.Canvas.DrawFocusRect(selrect)
    sender.Canvas.Rect(selrect)
    selrect.Left = 0
    selrect.Top = 0
    selrect.Right = 0
    selrect.Bottom = 0
 end
  p1.x = x
  p1.y = y
  md = true
end

f.OnMouseMove = function(sender, button, x, y)
 if not md then return end

 r.Top = p1.y
 r.Left = p1.x
 r.Right = p2.x
 r.Bottom = p2.y
 --img.Canvas.pen.Mode = 'pmMask'
 sender.Canvas.Brush.Color = 0xff
 sender.Canvas.Pen.Color = 0xff

 if (p1.x ~= 0) and (p2.x ~= 0) then
    if (p2.x > p1.x) then
        --sender.Canvas.DrawFocusRect(r)
        sender.Canvas.Rect(r)
    else
        --sender.Canvas.DrawFocusRect(Rect(p2.x, p2.y, p1.x, p1.y))
        sender.Canvas.Rect(p2.x, p2.y, p1.x, p1.y)
        p2.x = x
        p2.y = y
        r.Top = p1.y
        r.Left = p1.x
        r.Right = p2.x
        r.Bottom = p2.y
        --sender.Canvas.Pen.Mode = 'pmCopy'

        if (p1.x ~=0) and (p2.x ~=0) then
           if (p2.x > p1.x) then
             --sender.Canvas.DrawFocusRect(r)
             sender.Canvas.Rect(r)
          else
             --sender.Canvas.DrawFocusRect(Rect(p2.x, p2.y, p1.x, p1.y))
             sender.Canvas.Rect(p2.x, p2.y, p1.x, p1.y)
          end
       end
   end
 end
end


f.OnMouseUp = function(sender, button, x, y)
 r.Top = p1.y
 r.Left = p1.x
 r.Right = p2.x
 r.Bottom = p2.y

 --img.Canvas.Pen.Mode = 'pmMask'
 sender.Canvas.Brush.Color = 0xff
 sender.Canvas.Pen.Color = 0xff

 if (p1.x ~= 0) and (p2.x ~= 0)then
    if (p2.x > p1.x) then
       --sender.Canvas.DrawFocusRect(r)
       sender.Canvas.Rect(r)
  else
       --sender.Canvas.DrawFocusRect(Rect(p2.x, p2.y, p1.x, p1.y))
       sender.Canvas.Rect(p2.x, p2.y, p1.x, p1.y)
 end

  if p1.x < p2.x then
     selrect.Left = p1.x
     selrect.Top = p1.y
     selrect.Right = p2.x
     selrect.Bottom = p2.y
  else
     selrect.Left = p2.x
     selrect.Top = p2.y
     selrect.Right = p1.x
     selrect.Bottom = p1.y
  end

  md = false
  p1.x = 0
  p1.y = 0
  p2.x = 0
  p2.y = 0
 end
end

f.show()



Doesn't get effect anything.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 202

PostPosted: Tue Sep 22, 2020 5:30 am    Post subject: This post has 1 review(s) Reply with quote

You need to solve several problems:
First: we should record the coordinate point when the mouse clicks (as the origin coordinate), and draw the area horizontally and vertically with this coordinate point
Second: the brush color should follow the area being drawn, not the entire canvas
Code:
if f then f.Destroy() end
f=createForm()
f.Color=0x00ff00
f.setSize(300,300)
--f.OnMouseDown=function(p) f.dragNow() end
local down=1
f.OnMouseDown=function()
  down=0
end
f.OnMouseUp=function()
  down=1
end
f.OnMouseMove=function()
  local x,y=f.ScreenToClient(getMousePos())
  if down==0 then
    f.caption=x..' '..y
    f.Canvas.Clear()
    f.Canvas.Pen.Width=1
    f.Canvas.Brush.Color=0x00ffff
    f.Canvas.roundRect(f.width-x, f.height-y, x, y, 16, 16)
  end
end

f.setLayeredAttributes(0x0000ff,220,3,3)
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Tue Sep 22, 2020 5:58 am    Post subject: Reply with quote

Thanks, that it is. So, use ScreenToClient() more easier.
I made little edit on your script, so now the selection will start from where is first mouse down click.

Code:
if f then f.Destroy() end
f=createForm()
f.setSize(300,300)

local down=1
local startX, startY

f.OnMouseDown=function()
  x,y = f.ScreenToClient(getMousePos())
  startX = x
  startY = y
  down=0
end

f.OnMouseUp=function()
  down=1
end

f.OnMouseMove=function()
  local x,y=f.ScreenToClient(getMousePos())
  if down==0 then
    f.caption=x..' '..y
    f.Canvas.Clear()
    f.Canvas.Pen.Color = 0xff
    f.Canvas.Pen.Width = 1
    f.Canvas.Brush.Color = f.color
    f.Canvas.Brush.Style = 0
    f.Canvas.rect(startX, startY, x, y)
  end
end


PS: I need this to complete my cropping tool using CE Lua

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 202

PostPosted: Tue Sep 22, 2020 6:30 am    Post subject: Reply with quote

I think you should also feel that when you draw, there is a flicker.
I guess you want to do some screenshots.
Sometimes you coincide with me.
However, in terms of programming technology, I am certainly not as good as you.
Back to top
View user's profile Send private message
Oxijen
Expert Cheater
Reputation: 0

Joined: 07 May 2020
Posts: 163
Location: On The Moon

PostPosted: Tue Sep 22, 2020 7:28 am    Post subject: Reply with quote

I knew it is corrder just when I read the title Laughing
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Tue Sep 22, 2020 8:27 am    Post subject: Reply with quote

.lua wrote:
I think you should also feel that when you draw, there is a flicker.
I guess you want to do some screenshots.
Sometimes you coincide with me.
However, in terms of programming technology, I am certainly not as good as you.


I want to test and try to make a paint tool / image editor, using pure CE Lua script, which combining some logic from other apps. (mainly is Lazarus/Delphi).
Some abilities are : resize, crop by percent, crop by selection (both mouse event or typed coordinates), color handler (sephia, grayscale, monochrome, etc), flips, etc if possible. Just to completely my CE Lua script / tools / apps.

I am not good at all, with my limited programming skill, which I got just from read from google, ebooks or tutorial, I don't have learn basic programming at all.

Just read and at least try to understand, the practice.

When draw only one or two shape, the flicker matter is not appear, except we draw over than 10 or 20 shapes. And we already made a limited to draw just one shape at a time with clear the canvas.
That I know, if want draws much more shapes, then use memory buffers to store the shapes and call it by assign to the controls when needed. This is to avoid flickers matter.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 202

PostPosted: Tue Sep 22, 2020 9:11 pm    Post subject: Reply with quote

I just started to study on the way, and I only have spare time. Maybe the only thing I can do now is to be more serious
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Tue Sep 22, 2020 10:27 pm    Post subject: Reply with quote

Take your time and good luck.. Smile
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Wed Sep 23, 2020 9:10 am    Post subject: Reply with quote

What I am trying to do is something like this.


Capture.JPG
 Description:
 Filesize:  113.18 KB
 Viewed:  3234 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
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