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 


Speech Bubble

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

PostPosted: Thu Mar 05, 2020 6:55 am    Post subject: Speech Bubble Reply with quote

I try to make a speech bubble function using image canvas, example:

Code:
desc=[[
id = parent
w = image width
h = image height
x = image left
y = image top
text = text to display
]]

function CreateBubble(id,w,h,x,y,text)
 bmp = createImage(id)
 bmp.left = x
 bmp.top = y
 bmp.width = w
 bmp.height = h
 bmp.Transparent =  true
 bmp.TransparentColor=0

 width = bmp.Canvas.getTextWidth(text)
 height = bmp.Canvas.getTextHeight(text)

 bmp.Canvas.Font.Name = 'Verdana'
 bmp.Canvas.Font.CharSet= 255
 bmp.Canvas.Font.Color = 0xffff00
 bmp.Canvas.Font.Size = 14
 bmp.Canvas.Brush.Color = 0xFF0000

 --bmp.Canvas.fillRect(width - 2, height - 2, width + 4, height + 4)
 bmp.Canvas.Pen.Color=0xFF0000
 bmp.Canvas.Pen.Width = 3
 bmp.Canvas.line(x-2, y - 2, width + 4, height + 4)
 bmp.Canvas.line(x-2, y, x-2, y + height + 10)


 bmp.Canvas.Pen.Color=0xffffff
 bmp.Canvas.textOut(width + 4, height + 4, text)
 --bmp.Canvas.Draw(text, x, y)
end

function RemoveBubble(id)
 if bmp then bmp.destroy() else return nil end
end

f = createForm()
CreateBubble(f, 300, 50, 10,10,  "Hello Cheat Engine")


I have problems:
1. TransparentColor couldn't work (black part of the image)
2. Calculating textOut() position within image boundaries.
3. Is it possible to justify textOut() text into several lines?

Any helps?.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Thu Mar 05, 2020 9:02 am    Post subject: Reply with quote

1:
add
Code:

 bmp.Picture.Bitmap.Transparent =  true
 bmp.Picture.Bitmap.TransparentColor=0

to the end of CreateBubble (or at least after calling gettextwidth)

2:
no idea, textRect lets you keep the text within a certain space, but it's best just to calculate it with getTextWidth and getTextHeight untill it doesn't fit

3: use getTextWidth to find the cut off point and then do a new textOut a line lower at the position you like. getTextWidth on the previous line gets you the width. Just use basic math

_________________
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
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Mar 05, 2020 9:46 am    Post subject: Reply with quote

Thanks, DB

Done:

Code:
desc=[[
id = parent
w = image width
h = image height
x = image left
y = image top
text = text to display
]]

function CreateBubble(id,w,h,x,y,text)
 img = createImage(id)
 img.left = x
 img.top = y
 img.width = w
 img.height = h
 img.Transparent = true

 width = img.Canvas.getTextWidth(text)
 height = img.Canvas.getTextHeight(text)

 bmp = img.picture.Bitmap
 Canvas = bmp.Canvas
 Canvas.Font.Name = 'Verdana'
 Canvas.Font.CharSet= 255
 Canvas.Font.Color = 0xffff00
 Canvas.Font.Size = 12
 Canvas.Brush.Color = 0xFF0000

 --bmp.Canvas.fillRect(width - 2, height - 2, width + 4, height + 4)
 Canvas.Pen.Color=0xFF0000
 Canvas.Pen.Width = 2
 Canvas.line(x-2, y - 2, width + 4, height + 4)
 --bmp.Canvas.line(x-2, y, x-2, y + height + 2)


 Canvas.Pen.Color=0xffffff
 Canvas.textOut(width + 4, height + 4, text)
 Canvas.Draw(text, x, y)
 bmp.TransparentColor=0
end


function RemoveBubble(id)
 if bmp then bmp.destroy() else return nil end
end

f = createForm()
txt = "hello\n cheat engine"
CreateBubble(f, 300, 50, 10,10,  txt)


Next question: What is different between textOut() and textRect() ?.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Thu Mar 05, 2020 1:48 pm    Post subject: Reply with quote

textOut limits the block of text within a certain region
e.g:
Code:

Canvas.textRect({Left=0,Top=0,Right=width+40, Bottom=1000},width + 5, height + 4, text)

(Also doesn't use the default brush color)

it does support some special characters as well, like \r:
text="this\ris\ra\rmultiline\rstring"

and code styles like
Code:

[b] [/b] for bold
[u]/[/u] for underline
[i]/[/i] for italic


Also supports some escape characters like color:
Code:

text="this "..string.char(0x1b)..'[31mwas'..string.char(0x1b)..'[0m red'



and also some char pointer modification:
Code:

text="this "..string.char(0x1b).."[4DOverlaps"


look up ansi code sequences for more things you can try

_________________
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
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Mar 05, 2020 7:17 pm    Post subject: Reply with quote

Alright, I got it. Thanks, DB.

Code:
f = createForm(true)
f.Width = 300
f.Height = 200
f.Position = 'poScreenCenter'
f.Color = '0xfffffff'

pb=createPaintBox(f)
pb.Left,pb.Top,pb.Width,pb.Heigth = 0,30,200,170

txt = "this has set to color red brown red"
text="this\r"..string.char(0x1b)..'[31mhas set to color\r'..string.char(0x1b)..'[0mred brown red'
--text2="this "..string.char(0x1b).."[4DOverlaps"

f.OnPaint = function()
 c = f.Canvas
 c.font.Color = 0xff00ff
 c.font.Size = 12
 c.Brush.Style = 1
 c.textOut(10,10, txt)
end

pb.OnPaint = function()
  local rect={}
  rect.Left=0
  rect.Top=0
  rect.Right=pb.Width
  rect.Bottom=pb.Height
  pb.Canvas.Font.Size = 12
  pb.Canvas.Font.Color = 0xf0
  pb.Canvas.textRect(rect,10,30,text)
end


But, the textOut() or textRect() work if set under OnPaint() function or repaint().



Capture.JPG
 Description:
Test textOut() and textRect() CE 7.0
 Filesize:  18.03 KB
 Viewed:  1476 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