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 


CE6.7 - OnCustomDraw and OnPaint event?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Thu Jun 08, 2017 5:47 am    Post subject: CE6.7 - OnCustomDraw and OnPaint event? Reply with quote

How to use OnCustomDraw and OnPaint? Can anyone provide some examples? Thanks.
_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Thu Jun 08, 2017 6:39 am    Post subject: Reply with quote

OnPaint gets called whenever something gets painted. You can do that to do some of your own painting with the canvas. E.g draw some line, a picture, some text, just a few pixels, up to you

OnCustomDraw:
Code:

  OnCustomDraw: function(Sender, {Top, Left, Bottom, Right}, DefaultDraw Optional): NewDefaultDraw
  OnCustomDrawItem: function(Sender, ListItem, {cdsSelected=true/false(nil), cdsGrayed=true/false(nil), cdsDisabled, cdsChecked, cdsFocused, cdsDefault, cdsHot, cdsMarked, cdsIndeterminate}, DefaultDraw Optional): NewDefaultDraw
  OnCustomDrawSubItem: function(Sender, ListItem, SubItemIndex, {cdsSelected=true/false(nil), cdsGrayed=true/false(nil), cdsDisabled, cdsChecked, cdsFocused, cdsDefault, cdsHot, cdsMarked, cdsIndeterminate}, DefaultDraw Optional): NewDefaultDraw

These get called when the listview is about to draw a line.
the DrawItem is for the main item, DrawSubItem for the secondary items

You can then draw your own text in the listview, like adding images, or what not and then return false to tell it not to draw,
or what is likely more common, just change the canvas's font color to something else, and then return true to let the normal drawing happen, but then with a modified color

if I get time i'll make an example

_________________
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
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Thu Jun 08, 2017 7:38 am    Post subject: Reply with quote

Dark Byte wrote:
OnPaint gets called whenever something gets painted. You can do that to do some of your own painting with the canvas. E.g draw some line, a picture, some text, just a few pixels, up to you

OnCustomDraw:
Code:

  OnCustomDraw: function(Sender, {Top, Left, Bottom, Right}, DefaultDraw Optional): NewDefaultDraw
  OnCustomDrawItem: function(Sender, ListItem, {cdsSelected=true/false(nil), cdsGrayed=true/false(nil), cdsDisabled, cdsChecked, cdsFocused, cdsDefault, cdsHot, cdsMarked, cdsIndeterminate}, DefaultDraw Optional): NewDefaultDraw
  OnCustomDrawSubItem: function(Sender, ListItem, SubItemIndex, {cdsSelected=true/false(nil), cdsGrayed=true/false(nil), cdsDisabled, cdsChecked, cdsFocused, cdsDefault, cdsHot, cdsMarked, cdsIndeterminate}, DefaultDraw Optional): NewDefaultDraw

These get called when the listview is about to draw a line.
the DrawItem is for the main item, DrawSubItem for the secondary items

You can then draw your own text in the listview, like adding images, or what not and then return false to tell it not to draw,
or what is likely more common, just change the canvas's font color to something else, and then return true to let the normal drawing happen, but then with a modified color

if I get time i'll make an example


Thanks. I would love an example about colored texts in listview. Very Happy

_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Thu Jun 08, 2017 7:47 am    Post subject: Reply with quote

maybe you'll like this then
Code:

s=createForm()
lv=createListView(s)
lv.ViewStyle='vsReport'
lv.RowSelect=true
lv.HideSelection=false

c=lv.Columns.add()
c.Caption='C1';
c=lv.Columns.add()
c.Caption='C2';

c=lv.Columns.add()
c.Caption='C3';

for i=1,10 do
  l=lv.Items.add()
  l.Caption='bla'..i;
  l.SubItems.add('line '..i)
  l.SubItems.add('i*2='..i*2)
end

lv.OnCustomDrawItem=function(sender, ListItem, state, DefaultDraw)
  if ListItem.Index % 2 == 0 then
    sender.canvas.font.color=0x0000ff
  else
    sender.canvas.font.color=0x00ff00
  end

  return true
end

lv.OnCustomDrawSubItem=function(sender, ListItem, SubItemIndex, state, DefaultDraw)
  if ListItem.Index % 3 == 0 then
    if SubItemIndex % 2 == 0 then
      sender.canvas.font.color=0xff0000
    else
      sender.canvas.font.color=0x00ffff
    end
  else
    sender.canvas.font.color=0xffff00
  end

  return true
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
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Thu Jun 08, 2017 8:18 am    Post subject: Reply with quote

Dark Byte wrote:
maybe you'll like this then
Code:

s=createForm()
lv=createListView(s)
lv.ViewStyle='vsReport'
lv.RowSelect=true
lv.HideSelection=false

c=lv.Columns.add()
c.Caption='C1';
c=lv.Columns.add()
c.Caption='C2';

c=lv.Columns.add()
c.Caption='C3';

for i=1,10 do
  l=lv.Items.add()
  l.Caption='bla'..i;
  l.SubItems.add('line '..i)
  l.SubItems.add('i*2='..i*2)
end

lv.OnCustomDrawItem=function(sender, ListItem, state, DefaultDraw)
  if ListItem.Index % 2 == 0 then
    sender.canvas.font.color=0x0000ff
  else
    sender.canvas.font.color=0x00ff00
  end

  return true
end

lv.OnCustomDrawSubItem=function(sender, ListItem, SubItemIndex, state, DefaultDraw)
  if ListItem.Index % 3 == 0 then
    if SubItemIndex % 2 == 0 then
      sender.canvas.font.color=0xff0000
    else
      sender.canvas.font.color=0x00ffff
    end
  else
    sender.canvas.font.color=0xffff00
  end

  return true
end


Thanks, DB! It works like a charm.

Edit:
Is it possible to only paint the text of a single cell?

_________________
**************

A simple example is better then ten links. Very Happy
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