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 


ListView with pictures?

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

Joined: 17 Jan 2018
Posts: 205

PostPosted: Fri Oct 27, 2023 5:52 am    Post subject: ListView with pictures? Reply with quote

Good day. How to add a picture to the listview? A listview has already been created on the form with two columns, Listview ViewStyle:vsReport. Pictures are in gif format. Pictures are added via the table -> add file. I want to do it like in the screenshot below:

What is the difference between the OnCustomDrawItem and OnDrawItem events?



12.JPG
 Description:
 Filesize:  13.48 KB
 Viewed:  4269 Time(s)

12.JPG


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

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

PostPosted: Fri Oct 27, 2023 10:19 am    Post subject: Reply with quote

to start, convert the images to icons or png, or bmp. I don't think gif is supported

load the images from the tablefiles. Imageobject.loadFromStream(tablefile.stream)

then if they aren't bmp create in memory bitmaps (createBitmap) and copy the images from the original image to the bitmap (using canvas copyRect or draw)

(resize them to 32x32)

create an imagelist with createImageList and add the bitmaps to it (imagelistobject.add(bitmap) )

in the listview set the property SmallImages to the imagelist

Now for each listitem in the list, you can set the ImageIndex property to the index the image is in the imagelist

and there you have it, the images should show up as lonf as the listitem has a proper imageindex set

--
Or, if using an imagelist isn't something you wish to use, then you can use OnCustomDrawItem (OnDrawItem isn't supported)

You still need to load the images from the tablefiles but you can store them internally as something else than a bitmap (though still recommended for performance)
and then in the OnCustomDrawItem draw using sender.Canvas and the listitem's displayRect rectangle info to draw an image and the text of the listitem

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

Joined: 17 Jan 2018
Posts: 205

PostPosted: Sat Oct 28, 2023 8:07 am    Post subject: Reply with quote

Here is the code, it displays the gif images, but it does not display the text. How to display text with OnCustomDrawItem?
Code:

local materiacolortbl = { 'magic.gif', 'support.gif',
'command.gif', 'independent.gif', 'summon.gif', 'allmateria.gif' }

local inventoryrefr = {UDF1.CEListView1, UDF1.CEButton1}


local materialisttbl = {
[0x00] = 'MP Plus'
,[0x01] = 'HP Plus'
,[0x02] = 'Speed Plus'
,[0x03] = 'Magic Plus'
,[0x04] = 'Luck Plus'
,[0x05] = 'EXP Plus'
-- ... 91 names
,[0x5A] = 'Master Summon'
,[0xFF] = 'NONE'
}

  local items = inventoryrefr[1].Items
  items.Clear()

  for x = 0, 199 do
  local offset = basaddr + 0x005E8D4C+x*4 --basaddr=0x400000
  local valuemat = readBytes(offset)
  local item = items.Add()
  item.Caption = materialisttbl[valuemat]
  item.SubItems.text = readInteger(offset+1) & 0xFFFFFF
  end

  inventoryrefr[1].ItemIndex = 0
 
 
local function button1onclick()
  local addr = basaddr + 0x005E8D4C
  for x = 0, 199 do
  local offset = addr+x*4
  local valuemat = readBytes(offset)
  local matname = materialisttbl[valuemat]

  local item = inventoryrefr[1].Items[x]
  item.Caption = matname
  local matap = readInteger(offset+1) & 0xFFFFFF
  local subit = item.SubItems
  subit.text = matap
  end
end

inventoryrefr[2].OnClick = button1onclick --UDF1.CEButton1.OnClick-update data



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

--local ilist={}

for i=1, 6 do
 local pic = materiacolortbl[i]
 local picSrc = createPicture()
 picSrc.loadFromStream(findTableFile(pic).Stream)
 local bmpPic = picSrc.getBitmap()
 bmpPic.PixelFormat = 'pf8bit'

 imgList.add(bmpPic)

 --ilist[i]=bmpPic --picSrc
 bmpPic.Destroy()
 picSrc.Destroy()
end

--inventoryrefr[1].StateImages = imgList --StateIndex
--inventoryrefr[1].SmallImages = imgList --set the property in the listview
--inventoryrefr[1].Items[1].ImageIndex = 1 --displays image in ListView
--inventoryrefr[1].Items[2].ImageIndex = 0 --displays image in ListView

inventoryrefr[1].OnCustomDrawItem = function(sender, ListItem, state)
 local rect1=ListItem.displayRect(0)
 --sender.Canvas.fillRect(rect1.Left,rect1.Top,rect1.Right,rect1.Bottom)
 sender.Canvas.textOut(21, 1, sender.Items[ListItem.Index]) --displays text in place of the image
 imgList.draw(sender.Canvas, rect1.Left + 1, rect1.Top + 1, 3)
return true
end


Dark Byte wrote:
Or, if using an imagelist isn't something you wish to use, then you can use OnCustomDrawItem (OnDrawItem isn't supported)

You still need to load the images from the tablefiles but you can store them internally as something else than a bitmap (though still recommended for performance)
and then in the OnCustomDrawItem draw using sender.Canvas and the listitem's displayRect rectangle info to draw an image and the text of the listitem

How to display pictures without creating Imagelist?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sat Oct 28, 2023 5:26 pm    Post subject: Reply with quote

if you use imagelist you don't use OnCustomDrawItem

Quote:

How to display pictures without creating Imagelist?

use OnCustomDrawItem and draw the picture in that event handler (and the text as well)

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

Joined: 17 Jan 2018
Posts: 205

PostPosted: Sun Oct 29, 2023 6:39 am    Post subject: Reply with quote

Dark Byte wrote:
use OnCustomDrawItem and draw the picture in that event handler (and the text as well)

Now the pictures are displayed, but the text is not displayed, screenshot below: without return true. There is something wrong with this line:
Code:
sender.Canvas.textOut(21, 1, sender.Items[ListItem.Index])

full code:
Code:
local materiacolortbl = { 'magic.gif', 'support.gif',
'command.gif', 'independent.gif', 'summon.gif', 'allmateria.gif' }

local inventoryrefr = {UDF1.CEListView1, UDF1.CEButton1}

local ilist={}

for i=1, 6 do
 local pic = materiacolortbl[i]
 local picSrc = createPicture()
 picSrc.loadFromStream(findTableFile(pic).Stream)
 local bmpPic = picSrc.getBitmap()
 bmpPic.PixelFormat = 'pf8bit'

 ilist[i]=bmpPic --picSrc
 --bmpPic.Destroy()
 --picSrc.Destroy()
end

inventoryrefr[1].OnCustomDrawItem = function(sender, ListItem, state, DefaultDraw)
 local rect1=ListItem.displayRect(0)
 sender.Canvas.textOut(21, 1, sender.Items[ListItem.Index])
 sender.Canvas.draw(rect1.Left + 1, rect1.Top + 1, ilist[1])
--return true --if return true then the text is displayed, but pictures are not displayed correctly
end

if "return true" in OnCustomDrawItem, then the text is displayed, but pictures are not displayed correctly, screenshot below: with return true.
Need an example of how to properly display text in OnCustomDrawItem in Listview.



without return true.png
 Description:
without return true
 Filesize:  2.71 KB
 Viewed:  4051 Time(s)

without return true.png




Last edited by Razi on Thu Nov 16, 2023 10:41 am; edited 3 times in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Oct 29, 2023 11:32 am    Post subject: Reply with quote

get displayRect from the listitem and then use that for textOut (or textRect)
top is y, left is x
and increase x by the size of the picture

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

Joined: 17 Jan 2018
Posts: 205

PostPosted: Mon Oct 30, 2023 2:30 am    Post subject: Reply with quote

Dark Byte wrote:
get displayRect from the listitem and then use that for textOut (or textRect)

It's already working. The problem was in the: sender.Items[ListItem.Index], there is no text in it.
Made it to work like this: (on the 32 bit Cheat Engine)
Code:

inventoryrefr[1].OnCustomDrawItem = function(sender, ListItem, state, DefaultDraw)
 local rect1=ListItem.displayRect(0)
 sender.Canvas.textOut(rect1.Left + 21, rect1.Top + 1, ListItem.Caption)
 sender.Canvas.textOut(rect1.Left + 121, rect1.Top + 1, ListItem.SubItems.text)
 sender.Canvas.draw(rect1.Left + 1, rect1.Top + 1, ilist[1])
end

Everything looks great. But now the row is not highlighted in blue when selected, as it should. How to highlight the selected row in blue again?
Is there a way to increase Item Height for Listview items? Because in the win XP, Listview ItemHeight = 13 by default, but size of my pictures are 14x14.



listview.jpg
 Description:
Here's what the listview looks like now
 Filesize:  30.8 KB
 Viewed:  3966 Time(s)

listview.jpg




Last edited by Razi on Tue Oct 31, 2023 10:19 am; edited 3 times in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Mon Oct 30, 2023 8:30 am    Post subject: Reply with quote

state is a string that contains the text highlighted (and some other things) when highlighted

in those cases draw a highlight background inside the rectangle before drawing the picture and text

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

Joined: 17 Jan 2018
Posts: 205

PostPosted: Tue Oct 31, 2023 10:16 am    Post subject: Reply with quote

Dark Byte wrote:
state is a string that contains the text highlighted (and some other things) when highlighted

Do not know how to use state in code

Dark Byte wrote:
in those cases draw a highlight background inside the rectangle before drawing the picture and text

I managed to do it like this:
Code:
Listview1.OnCustomDrawItem = function(sender, ListItem, state, DefaultDraw)
 local rect1=ListItem.displayRect(0)
 sender.Canvas.textOut(rect1.Left + 21, rect1.Top + 1, ListItem.Caption)
 sender.Canvas.textOut(rect1.Left + 121, rect1.Top + 1, ListItem.SubItems.text)
 sender.Canvas.draw(rect1.Left + 1, rect1.Top + 1, ilist[1])

local rect2=sender.Selected.displayRect(0)
sender.Canvas.Brush.Color=clHighlight --0xff9933
sender.Canvas.fillRect(rect2.Left,rect2.Top,rect2.Right,rect2.Bottom)
sender.Canvas.Font.Color=clHighlightText
sender.Canvas.textOut(rect2.Left + 21, rect2.Top + 1, sender.Items[sender.ItemIndex].Caption)
sender.Canvas.textOut(rect2.Left + 121, rect2.Top + 1, sender.Items[sender.ItemIndex].SubItems.text)
sender.Canvas.draw(rect2.Left + 1, rect2.Top + 1, ilist[1])
end

Is there a way to improve the code? Or does anyone have any tips?

Another question: how to increase the row/line height in the Listview (Listview.ItemHeight)? The only idea is to increase Listview.Font.Height/Size. In win XP it looks like this: screenshot below



winXP-tr-.JPG
 Description:
with ImageList
 Filesize:  106.05 KB
 Viewed:  3523 Time(s)

winXP-tr-.JPG


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