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 


Combo box with pictures?
Goto page Previous  1, 2
 
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: Wed May 17, 2023 9:35 pm    Post subject: This post has 1 review(s) Reply with quote

Razi wrote:
AylinCE wrote:
( Try my last code above. It is the ultimate blending. )

It works with image load: ( Table -> Add file )
It does not work with links, most likely because my default browser (Chrome v.49) does not see these images.
I will try to optimize the code to reduce the number of lines and make the code more understandable for beginners.



As @Razi ask me to show an example using imagelist for add image to combobox.

First, note if imagelist only accept image with type bitmap (BMP), so we need
to extract the bitmap source from other image type such as PNG, JPG, etc.
Use getBitmap().

The example below need to improvement to get it work as well.

Code:
if f then f.destroy() end

f = createForm()
f.Width = 200
f.Height = 200
f.Position = 'poScreenCenter'
f.Caption = 'Icon'

cb = createComboBox(f)
cb.Left =10
cb.Top = 10
cb.Width = 180
cb.Style = 'csOwnerDrawFixed'
--cb.Items.Add('Select an item')
cb.Items.Add('Red Ball')
cb.Items.Add('Green Ball')
cb.Items.Add('Blue Ball')
cb.Items.Add('Random Ball')
cb.ItemIndex = 0

if imgList then imgList.Destroy() end
imgList = createImageList()
imgList.ImageIndex = 0

-----------------------------------------------------------------
-- Add images to imagelist (bmp type)
-- Assume images already added to table file
-----------------------------------------------------------------
for i=1, 4 do --- 4 is total images added to table file
 local pic = 'img'..i..'.png' --- the name of image file should be unique
 local picSrc = createPicture()
 picSrc.loadFromStream(findTableFile(pic).Stream) -- add images file to table first
 local bmpPic = picSrc.getBitmap()
 bmpPic.PixelFormat = 'pf8bit'
 bmpPic.TransparentColor = 0xFF00FF
 bmpPic.Transparent = true
 imgList.add(bmpPic)
 bmpPic.Destroy()
 picSrc.Destroy()
end

cb.OnDrawItem = function(sender, index, rect, state)
 sender.Canvas.fillRect(rect)
 sender.Canvas.textRect(rect, 25, rect.Top, sender.Items[index])
 imgList.draw(sender.Canvas, rect.Left + 1, rect.Top + 1, index)
end


Goodluck!

PS: @Razi, if you success to improve the code, specially for adjust the font color when combobox item selected as your script before, then if you doesn't mind, post your last success code here.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Thu May 18, 2023 12:42 am    Post subject: Reply with quote

Text color added.
And after the selection, a hidden focus was added to make the text look comfortable.

Code:
function loadUrl(link)
  local int=getInternet()
  s=int.getURL(link)
  int.destroy()
  return s
end

function crtPict25(link1)
  logostr22=loadUrl(link1)
  local ss22=createStringStream(logostr22)
  p=createPNG()
  p.loadFromStream(ss22)
  ss22.destroy()
  return p
end

--alternate image load ..
--greenboll=crtPict25([[https://i.hizliresim.com/nbeibjw.png]])
--redboll=crtPict25([[https://i.hizliresim.com/5fovypg.png]])
--blueboll=crtPict25([[https://i.hizliresim.com/foy25pq.png]])
--silverboll=crtPict25([[https://i.hizliresim.com/a3ga54z.png]])
silverboll=crtPict25([[https://i.ibb.co/hByNYr5/boll1.png]])
redboll=crtPict25([[https://i.ibb.co/yS63zgb/boll2.png]])
greenboll=crtPict25([[https://i.ibb.co/p3chsT9/boll3.png]])
blueboll=crtPict25([[https://i.ibb.co/RBtxMZ0/boll4.png]])

-- or image load: ( Table >> Add file )
-- silverboll.loadFromStream(findTableFile("your_Image_name.png").stream)
-- blueboll.loadFromStream(findTableFile("your_Image_name.png").stream)
local ilist={}
ilist[1]=redboll
ilist[2]=greenboll
ilist[3]=blueboll
ilist[4]=silverboll

DP1=getScreenDPI()/96

f=createForm()
f.Width=DP1*200
f.Height=DP1*200
ed1=createEdit(f)
ed1.left=DP1*25 -- back cbox
cb=createComboBox(f)
cb.Width=DP1*160
cb.left=DP1*20
cb.Font.Size=DP1*12

local ComboBox1 = cb
ComboBox1.Style="csOwnerDrawVariable" -- or select 'csOwnerDrawFixed'
  ComboBox1.Clear()

ComboBox1.OnChange=function(sender)
--local ComboBox1 = UDF1.CEComboBox1
  if ComboBox1.ItemIndex == 0 then
    f.Color=clDefault
  elseif ComboBox1.ItemIndex == 1 then
    f.Color=clRed
  elseif ComboBox1.ItemIndex == 2 then
    f.Color=clGreen
  elseif ComboBox1.ItemIndex == 3 then
    f.Color=clBlue
  elseif ComboBox1.ItemIndex == 4 then
    f.Color=math.random(0xffffff)
  end
  ed1.setFocus() -- not focused combobox!
end

  function FillColorfulRect(aCanvas, Left, Top, Right, Bottom)
    for y=Top, Bottom - 1 do
      aCanvas.Pen.Color=math.random(0xffffff)
      aCanvas.line(Left, y, Right, y)
    end
  end

 ComboBox1.OnDrawItem=function(sender, index, rect, state)
  --ComboBox1.Canvas.Pen.Color=clBlack
  ComboBox1.Canvas.fillRect(rect.Left,rect.Top,rect.Right,rect.Bottom)
  --ComboBox1.Canvas.textRect(rect, 27, rect.Top, ComboBox1.Items[index])

sr={}
  sr.Left=4
  sr.Top=rect.Top
  sr.Right=rect.Bottom-rect.Top
  sr.Bottom=rect.Bottom

    if index == 4 then
      FillColorfulRect(ComboBox1.Canvas, rect.Left + 1, rect.Top + 1, rect.Left + 19, rect.Bottom - 1)
      sender.canvas.Font.Color=math.random(0xffffff)
      ComboBox1.Canvas.textRect(rect, 27, rect.Top, ComboBox1.Items[index])
    else
      if index == 0 then
      graphic=ilist[4]
      sender.canvas.stretchDraw(sr, graphic)
      sender.canvas.Font.Color=clDefault
      ComboBox1.Canvas.textRect(rect, 27, rect.Top, ComboBox1.Items[index])
      elseif index == 1 then
      graphic=ilist[1]
      sender.canvas.stretchDraw(sr, graphic)
      sender.canvas.Font.Color=clRed
      ComboBox1.Canvas.textRect(rect, 27, rect.Top, ComboBox1.Items[index])
      elseif index == 2 then
      graphic=ilist[2]
      sender.canvas.stretchDraw(sr, graphic)
      sender.canvas.Font.Color=clGreen
      ComboBox1.Canvas.textRect(rect, 27, rect.Top, ComboBox1.Items[index])
      elseif index == 3 then
      graphic=ilist[3]
      sender.canvas.stretchDraw(sr, graphic)
      sender.canvas.Font.Color=clBlue
      ComboBox1.Canvas.textRect(rect, 27, rect.Top, ComboBox1.Items[index])
      end
      --ComboBox1.Canvas.ellipse(rect.Left + 4,rect.Top + 1,rect.Left + 15,rect.Bottom - 1)
    end
  --ed1.setFocus()
end

  ComboBox1.Items.Add('Default')
  ComboBox1.Items.Add('Red')
  ComboBox1.Items.Add('Green')
  ComboBox1.Items.Add('Blue')
  ComboBox1.Items.Add('Random Color')
  ComboBox1.ItemIndex=0



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

Joined: 17 Jan 2018
Posts: 202

PostPosted: Thu May 18, 2023 5:50 am    Post subject: Reply with quote

Can't post code right now. Says: Your browser is out of date. It does not allow to use square brackets or other unusual symbols. This usually lasts 10-48 hours. During this time, can not write posts with code and write code even in PM. Recently it happens 1-2 days a week.

sender.Canvas.fillRect(rect) --isn't valid, change this line to:
sender.Canvas.fillRect(rect.Left,rect.Top,rect.Right,rect.Bottom) --fillRect(x1,y1,x2,y2) --this line makes text visible when combobox item selected
Corroder wrote:
PS: @Razi, if you success to improve the code, specially for adjust the font color when combobox item selected as your script before, then if you doesn't mind, post your last success code here.
Of course.
Dark Byte wrote:
you should check if state contains the text "odSelected" and if so draw the background as blue, or adjust the font color. As right now the default font color for selected text is white.

(ComboBox1.Canvas.fillRect(rect) isn't valid, ce lua has no support for this version yet. You have to provide it with x1,y1,x2,y2)


P.S. : Found a way. Sorry for late reply.
Code:
if f then f.destroy() end

f = createForm()
f.Width = 200
f.Height = 200
f.Position = 'poScreenCenter'
f.Caption = 'Icon'

cb = createComboBox(f)
cb.Left =10
cb.Top = 10
cb.Width = 180
cb.Style = 'csOwnerDrawFixed'
--cb.Items.Add('Select an item')
cb.Items.Add('Red Ball')
cb.Items.Add('Green Ball')
cb.Items.Add('Blue Ball')
cb.Items.Add('Random Ball')
cb.ItemIndex = 0

if imgList then imgList.Destroy() end
imgList = createImageList()
imgList.ImageIndex = 0

-----------------------------------------------------------------
-- Add images to imagelist (bmp type)
-- Assume images already added to table file
-----------------------------------------------------------------
for i=1, 4 do --- 4 is total images added to table file
 local pic = 'img'..i..'.png' --- the name of image file should be unique
 local picSrc = createPicture()
 picSrc.loadFromStream(findTableFile(pic).Stream) -- add images file to table first
 local bmpPic = picSrc.getBitmap()
 bmpPic.PixelFormat = 'pf8bit'
 bmpPic.TransparentColor = 0xFF00FF
 bmpPic.Transparent = true
 imgList.add(bmpPic)
 bmpPic.Destroy()
 picSrc.Destroy()
end

cb.OnDrawItem = function(sender, index, rect, state)
 sender.Canvas.fillRect(rect.Left,rect.Top,rect.Right,rect.Bottom)--this line makes text visible when combobox item selected
 --fillRect(x1,y1,x2,y2)
 sender.Canvas.textRect(rect, 25, rect.Top, sender.Items[index])
 imgList.draw(sender.Canvas, rect.Left + 1, rect.Top + 1, index)
end


Last edited by Razi on Fri May 19, 2023 8:23 pm; edited 2 times in total
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Thu May 18, 2023 8:47 am    Post subject: Reply with quote

You can write the code in a google document and share the link.
Do not add "https:\\" and "com" to the beginning of the link if necessary.

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

Joined: 17 Jan 2018
Posts: 202

PostPosted: Thu May 18, 2023 12:15 pm    Post subject: Reply with quote

I can wait.
P.S. : It looks like stretchDraw code shows a more pixelated image, but gives more control over the area of the image.
Have you tried, when image list is used, to reduce the height of the image so that there are 1-2 empty pixels vertically between the images in the combobox Items? Because now, they are right next to each other.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Fri May 19, 2023 8:30 pm    Post subject: Reply with quote

Razi wrote:
I can wait.
P.S. : It looks like stretchDraw code shows a more pixelated image, but gives more control over the area of the image.
Have you tried, when image list is used, to reduce the height of the image so that there are 1-2 empty pixels vertically between the images in the combobox Items? Because now, they are right next to each other.


you can adjust the bitmap size and combobox item height to get more spaces.

--Adjust #1
Code:
...
cb.ItemHeight = 22
cb.Style = 'csOwnerDrawFixed'
...


-- Adjust #2
Code:
...
local bmpPic = picSrc.getBitmap()
bmpPic.Canvas.Height = 18
bmpPic.Canvas.Width = 18
bmpPic.PixelFormat = 'pf32bit'
...


-- Adjust #3
Code:
...
sender.Canvas.textRect(rect, 25, rect.Top + 2, sender.Items[index])
 imgList.draw(sender.Canvas, rect.Left + 2, rect.Top + 2, index)
...


The pixelate should be according your installed graphic card and the image sources DPI size.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Sat May 20, 2023 5:16 am    Post subject: This post has 1 review(s) Reply with quote

Image layout size and text color are adjusted.
Also code change for transparent image:

Code:
 --bmpPic.TransparentColor = 0xFF00FF
 --bmpPic.Transparent = true
imgList.DrawingStyle='dsTransparent'


use ..
Code:
if f then f.destroy() end

f = createForm()
f.Width = 200
f.Height = 200
f.Position = 'poScreenCenter'
f.Caption = 'Icon'

cb = createComboBox(f)
cb.Left =10
cb.Top = 10
cb.Width = 180
cb.Style = 'csOwnerDrawFixed'
cb.Font.Size=11

ihg=cb.ItemHeight - 4

if imgList then imgList.Destroy() end
imgList = createImageList()
imgList.ImageIndex = 0

--celua line: 1051
imgList.Height=ihg
imgList.Width=ihg
--celua line: 1050
imgList.DrawingStyle='dsTransparent'

-----------------------------------------------------------------
for i=1, 4 do --- 4 is total images added to table file
 local pic = 'boll'..i..'.png' --- the name of image file should be unique
 local picSrc = createPicture()
 picSrc.loadFromStream(findTableFile(pic).Stream) -- add images file to table first
 local bmpPic = picSrc.getBitmap()
bmpPic.PixelFormat = 'pf8bit'
 imgList.add(bmpPic)
 bmpPic.Destroy()
end


cb.OnDrawItem = function(sender, index, rect, state)
--color table (for font color)
fclr1={clRed,clGreen,clBlue,math.random(0,16711680)}

 sender.Canvas.fillRect(rect.Left,rect.Top,rect.Right,rect.Bottom)--this line makes text visible when combobox item selected
-- text and font color
 for i=0, sender.Items.Count do
  if index then
   sender.Canvas.textRect(rect, 20, rect.Top, sender.Items[index])
   sender.canvas.Font.Color=tonumber(fclr[index+1])
  end
 end
 imgList.Draw(sender.canvas, rect.Left+1, rect.Top+3, index)
end

--load image
cb.Items.Add('Red Ball')
cb.Items.Add('Green Ball')
cb.Items.Add('Blue Ball')
cb.Items.Add('Random Ball')
cb.ItemIndex = 0

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

Joined: 17 Jan 2018
Posts: 202

PostPosted: Sun May 21, 2023 10:32 am    Post subject: Reply with quote

Corroder wrote:
you can adjust the bitmap size and combobox item height to get more spaces.

It's strange, but in the designer, changing the ItemHeight does not work, but in the script it works. In the designer, can only be changed Font height, and this will also change ItemHeight. Everything works well, thanks.

Corroder wrote:
The pixelate should be according your installed graphic card and the image sources DPI size.

Yes, this is because it stretches or shrinks the image from the original resolution.

AylinCE wrote:
Image layout size and text color are adjusted.
Also code change for transparent image:
Code:
fclr1={clRed,clGreen,clBlue,math.random(0,16711680)}
...
   sender.canvas.Font.Color=tonumber(fclr[index+1])

There's a little mistake, fclr needs to be changed to fclr1.

Many thanks to everyone who helped.
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
Goto page Previous  1, 2
Page 2 of 2

 
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