Sign in to follow this  
Followers 0
cramaboule

Slide Transition Effect

14 posts in this topic

#1 ·  Posted (edited)

From this post

I thought that's must be nice to post something nice here. Testing many ways, for me, this is the best !

Cramaboule

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AU3Check_Parameters=-w 5 -w 3 -w 4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Array.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{Esc}", "_Exit")

Global $c=0, $i, $k, $l, $chk, $fn
Global $hGDI[3], $hGraphic[2], $hImage, $hBrush1, $hBrush2, $hFamily, $hFont, $hFormat, $tLayout, $aInfo, $sString
Global Const $fsize = 8, $fh = 15
Global Const $width = 800, $height = 600
Global Const $bg_color = "000000"
Global $imagedir =  FileSelectFolder("Select folder with images", "", 4, @ScriptDir)

If $imagedir = "" Then Exit MsgBox(16, "Error", "No folder selected!", 5)


Global $aFiles = _FileListToArray($imagedir, "*.*", 1)
If Not UBound($aFiles) Then Exit MsgBox(16, "Error", "No files found!", 5)


$l = 1
Do
    $chk = StringRegExp($aFiles[$l], "(.*\.jpg|.*\.png|.*\.bmp|.*\.gif|.*\.JPG|.*\.PNG|.*\.BMP|.*\.GIF)", 3)
    If @error Then
        _ArrayDelete($aFiles, $l)
        $l -= 1
    EndIf
    $l += 1
Until $l = UBound($aFiles)


If UBound($aFiles) = 1 Then Exit MsgBox(16, "Error", "No images found!", 5)


Fader_Init($width, $height)


For $k = 1 To UBound($aFiles) - 1
    _Transition($imagedir & "\" & $aFiles[$k])
Next

Sleep(3000)
_Exit()


Func _Transition($image, $delay = 0, $speed = 15, $sleep = 2000)
    Local $a, $d = $c, $iX, $iY
    $hImage = _GDIPlus_ImageLoadFromFile($image)
    $iX = _GDIPlus_ImageGetWidth($hImage)
    $iY = _GDIPlus_ImageGetHeight($hImage)

    $FDesktop=$height/$width
    $Fact =1
    If $iX > $width And $FDesktop > ($iY/$iX) Then
        $Fact=$width/$iX
    ElseIf $iY > $height Then
        $Fact=$height/$iY
    EndIf
    $H1 = Round(($Fact * $iY),0)
    $W1 = Round(($Fact * $iX),0)
    ;$H0 = Round(($height-$H1)/2,0)
    ;$W0 = Round(($width-$W1)/2,0)

    _GDIPlus_GraphicsDrawImageRect($hGraphic[$d], $hImage,($width - $W1)/2, ($height - $H1) / 2,$W1,$H1)
    $hBrushFont2 = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ; text color
    $hFormat = _GDIPlus_StringFormatCreate()
    $hLayout = _GDIPlus_RectFCreate(($width - $W1)/2, ($height - $H1) / 2,$W1,$H1)
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 25, 0, 3)

    _GDIPlus_GraphicsDrawStringEx($hGraphic[$d], $sString, $hFont, $hLayout, $hFormat, $hBrushFont2)

    WinSetTrans($hGDI[$d], "", 0)
    WinSetOnTop($hGDI[$d], "", 1)
    For $a = 0 To 254 Step $speed
        WinSetTrans($hGDI[$d], "", $a)
        Sleep($delay)
    Next
    WinSetTrans($hGDI[$d], "", 254)
    WinSetOnTop($hGDI[Not ($d)], "", 0)
    WinSetTrans($hGDI[Not ($d)], "", 0)
    _GDIPlus_GraphicsClear($hGraphic[Not ($d)])
    $c = 1 - $d

    _GDIPlus_ImageDispose ($hImage) ; very important to realease the pics
    Sleep($sleep)
EndFunc   ;==>_Transition


Func Fader_Init($width, $height)
    $hGDI[2] = GUICreate("", $width, $height, (@DesktopWidth - $width)/2, (@DesktopHeight - $height)/2 , $WS_POPUP)
    $hGDI[0] = GUICreate("", $width, $height, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $hGDI[2])
    $hGDI[1] = GUICreate("", $width, $height, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $hGDI[2])
    GUISetBkColor("0x" & $bg_color, $hGDI[2])
    GUISetState(@SW_SHOW, $hGDI[2])
    GUISetState(@SW_SHOW, $hGDI[0])
    GUISetState(@SW_SHOW, $hGDI[1])
    WinSetTrans($hGDI[0], "", 0)
    WinSetTrans($hGDI[1], "", 0)
    _GDIPlus_Startup()
    $hGraphic[0] = _GDIPlus_GraphicsCreateFromHWND($hGDI[0])
    $hGraphic[1] = _GDIPlus_GraphicsCreateFromHWND($hGDI[1])
    _GDIPlus_GraphicsClear($hGraphic[0], "0xFF" & $bg_color)
    _GDIPlus_GraphicsClear($hGraphic[1], "0xFF" & $bg_color)
    $hBrush1 = _GDIPlus_BrushCreateSolid(0xFFF0F080)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, $fsize)
    $tLayout = _GDIPlus_RectFCreate(0, $height - $fh, 0, 0)
EndFunc   ;==>Fader_Init


Func _Exit()
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic[0])
    _GDIPlus_GraphicsDispose($hGraphic[1])
    GUIDelete($hGDI[0])
    GUIDelete($hGDI[1])
    GUIDelete($hGDI[2])
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

and thanks to UEZ for his initial script

EDIT: corrected the script and added the thanks

Edited by cramaboule

Share this post


Link to post
Share on other sites



Well it seems to work fine, I dont know nowt about gdi but just one question. What is the global variable $end (which is also an argument for _Exit() function) actually do?

Just curious.

He forgot to remove it because I left it in my code, too! :P

@cramaboule: some credits would be nice :x

My version is working properly on Vista+ os only!

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

He forgot to remove it because I left it in my code, too! :P

@cramaboule: some credits would be nice :x

My version is working properly on Vista+ os only!

Br,

UEZ

Yes that's right.... Thanks to UEZ for his initial script.

With your version I have a slight effect where we see a bit of black in the middle of the transition.(Both GUI at around 128 of WinSetTrans) With your version modified by me :shifty: this isn't happened ! as I put on top the GUI who has the WinSetTrans set to 0 then going up to 254. I tested only on XP !!!

Cram

Share this post


Link to post
Share on other sites

Hue, Of topic, but what happened to the first message. It looks like its got messed up. (Its showing all the html tags)


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Hue, Of topic, but what happened to the first message. It looks like its got messed up. (Its showing all the html tags)

woops sorry about that,... Strange because when I left the forum all was okay....

I was away half day,... so now I took time to corrected this.

Cramaboule

Share this post


Link to post
Share on other sites

It seems to be that your code is working properly only on WinXP because on Vista and Win7 there is no fading effect - just displaying the images sequentially.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

It seems to be that your code is working properly only on WinXP because on Vista and Win7 there is no fading effect - just displaying the images sequentially.

Br,

UEZ

Hum,...:x Strange because I tested on a (Virtual) Win7 and my code works properly... (your code as well!!!)

I do not have any Vista so ... I cannot tell about it !!!!

Cramaboule

Share this post


Link to post
Share on other sites

I have tested this on Vista and it works great ... just like on XP. The transition effect is smooth, even on my rather slow laptop.

But in trying to follow the script, I don't understand the following steps in Fader_Init:

_GDIPlus_GraphicsClear($hGraphic[0], "0xFF" & $bg_color)

_GDIPlus_GraphicsClear($hGraphic[1], "0xFF" & $bg_color)

With $bg_color = "000000", what purpose is the Full Red On in these statements?

Thanks for an excellent example script.

Share this post


Link to post
Share on other sites

I have tested this on Vista and it works great ... just like on XP. The transition effect is smooth, even on my rather slow laptop.

But in trying to follow the script, I don't understand the following steps in Fader_Init:

With $bg_color = "000000", what purpose is the Full Red On in these statements?

Thanks for an excellent example script.

Well in the script of UEZ I thought the same... but looking at the help file the first 'FF' is the alpha then, comes the Red, Green and Blue...

Happy that it works on your Vista. of course you can change those values

For $a = 0 To 254 Step $speed
        WinSetTrans($hGDI[$d], "", $a)
        Sleep($delay)
    Next

$speed and $delay to set up your speed transition...

Cramaboule

Share this post


Link to post
Share on other sites

... but looking at the help file ...

Yes, I see that now ... $iARGB = 0xFF000000

Thanks for the quick reply.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thanks for sharing the code.

How it can be coded to show pics randomly?

And which way it can be coded to make a loop and only exit when a button is pressed?

For $k = 1 To UBound($aFiles) - 1
    _Transition($imagedir & "\" & $aFiles[$k])
Next

Sleep(3000)
_Exit()

Maybe putting this inside a while??:

While:

$msg = GUIGetMsg()

    _Transition($imagedir & "\" & $aFiles[$k])

Wend

Once again thanks for sharing it.

Edited by adolfito121

Share this post


Link to post
Share on other sites

It seems to be that your code is working properly only on WinXP because on Vista and Win7 there is no fading effect - just displaying the images sequentially.

As I am now on Win7 I had the same problem,...

adjust the time of translation ($delay, $speed) just increase $delay should be fine !!!

C.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0