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 


How can I make a image fade in and then fade out

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

Joined: 15 Dec 2016
Posts: 31

PostPosted: Sat Oct 20, 2018 7:58 pm    Post subject: How can I make a image fade in and then fade out Reply with quote

I've spent the last two hours trying to figure this out. I don't want to fade the whole form in. Just a specific image that I imported. About the only thing I can do with the imported image is to choose if I want it to be visible or not. I'm hoping this is something that is possible through lua. Thanks for any help given.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4702

PostPosted: Sat Oct 20, 2018 9:08 pm    Post subject: Reply with quote

I don't know of any easy solution off the top of my head. Perhaps some library could.

You can manually paint the underlying canvas, but that could be difficult for a beginner.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Oct 20, 2018 9:57 pm    Post subject: Reply with quote

The picture control probably has an opacity property you can set in a timer to fade it in and out.

Edit: Apparently, Delphi doesn't inherit controls from something that would allow this like other languages. Go figure. :/

Well instead, you could load the image into a memory stream and later the data manually to edit the alpha of the image then set the picture box via the loadFromStream call.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Oct 20, 2018 10:41 pm    Post subject: Reply with quote

Here's the 'starting' bits of what I was referring to. You'd have to use an image format you are familiar with to edit the raw pixel data etc.

Code:

local function getFileSize(file)
    local s = 0;
    local f = io.open(file, 'rb');
    if (f ~= nil) then
        s = f:seek('end');
        f:close();
        return s;
    end
    return s;
end

local function getFileData(file, size)
    local f = io.open(file, 'rb');
    if (f ~= nil) then
        local data = f:read('*all');
        local buff = { };
        f:close();

        for x = 1, size do
            buff[x] = string.byte(data, x);
        end

        return buff;
    end
    return nil;
end

-- Load the image from disk..
local size = getFileSize('PATH_TO_IMAGE_HERE');
local data = getFileData('PATH_TO_IMAGE_HERE', size);

-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-- Edit the image data here..
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

-- Load the image into the stream..
local stream = createMemoryStream();
stream.write(data);
stream.Position = 0;

-- Load the image..
UDF1.CEImage1.Picture.loadFromStream(stream);
UDF1.CEImage1.Visible = true;
stream.destroy();


That'll allow you to edit the image data, load it into a stream, then load that stream into an image on the form.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
AmyGrrl
Cheater
Reputation: 0

Joined: 15 Dec 2016
Posts: 31

PostPosted: Sat Oct 20, 2018 11:36 pm    Post subject: Reply with quote

Kind of sucks there is no easy way to do this. Surprised nothing has been added to allow for this by now. A little disappointed.

What I did on my end to create a fade in. Was to use Gimp and edit the alpha level 7 different times. Using the values 30, 60, 90,120, 150, 180, 210. So I ended up with 8 different images that are around 80kb each. I then imported all the images and set them to invisible. Then created a threaded function to display them in order. With a slight delay between setting them invisible and visible. Works pretty well actually. But does increase the size a bit if you want to fade more than one image. But I only need on one image to fade in.

Tomorrow I will play around with your script and see if I can get it working. Being able to fade an image in through lua would be better because I would be able to create a more smooth transition.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Oct 21, 2018 7:15 am    Post subject: Reply with quote

Have you looked into using wincontrol's setLayeredAttributes ?

put the image on a panel (which is a wincontrol descendant) and make that transparent (only works on win8 and later)

_________________
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: 1668

PostPosted: Tue Oct 23, 2018 6:13 am    Post subject: Reply with quote

This is another way to fade in part of form using form2 inside form1. When alpha value for form2 reach maximum it change to a panel with position same as form2.

Idea has come from MDI form like use in C++

Code:
function fadeinShow(form)
  form.DoubleBuffered = true
  form.AlphaBlend = true
  form.AlphaBlendValue = 0
  form.Visible = true
  local timer = createTimer(form,false)
  timer.Interval = 1
  timer.OnTimer = function(t)
    form.AlphaBlendValue = form.AlphaBlendValue + 2

    if form.AlphaBlendValue>=250 then form.AlphaBlendValue = 255
                                      form.AlphaBlend = false
                                      t.Enabled = false


     f.hide()  -- or f.Destroy()
     pnl = createPanel(form1)
     pnl.top = form1.top + 10
     pnl.left = form1.left + 10
     pnl.width = form1.width - 20
     pnl.height = 100

     bg_image = createImage(pnl)
     bg_image.picture.loadFromStream(findTableFile('teaser_1.jpg').Stream)  -- add your own image to CE Table
     bg_image.left = 0
     bg_image.width = f.width
     bg_image.height = f.height
     bg_image.stretch = true
    end
  end
  timer.Enabled = true
end

function closeAll()
 f.destroy()
 closeCE()
 return caFree
end

form1 = createForm()

f = createForm()
f.top = form1.top + 40
f.left = form1.left + 10
f.width = form1.width - 20
f.height = 100
f.BorderStyle = 'bsNone'

bg_image = createImage(f)
bg_image.picture.loadFromStream(findTableFile('teaser_1.jpg').Stream) -- add your own image to CE Table
bg_image.left = 0
bg_image.width = f.width
bg_image.height = f.height
bg_image.stretch = true

fadeinShow(f)
--form1.show()
form1.onClose = closeAll

_________________
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