Display/show gif -- /drawgif
Wims
17/04/26 09:57 PM
This code can be used to show a gif in a picture window, it auto loops and auto clean itself if you close the window:
To create/initiate the gif, use $drawgif(@win,x y,filename,cbalias,w h,customdelay)
It will return an ID value which can then be used to pause, resume, and delete the gif animation
pause: /drawgif -p <id>
resume: /drawgif -r <id>
delete: /drawgif -d <id>
'cbalias' is a callback alias called when the gif is finished, if not specified, the gif auto loops, if specified, the alias is called as an identifier, if you return something non-0 (non-$false and non-$null), it auto loops.
'w h' can be used to strech/squeeze into that bitmap size
'customdelay' will ignore the gif's delays and use that constant time (millisecond) between frames.
alias drawgif {
if ($prop) {
var %h drawgif $+ $1,%f $hget(%h,frame),%delay $hget(%h,cdelay)
if (%delay == $null) %delay = $pic($hget(%h,filename),%f).delay
if ($hget(%h,wh)) drawpic -os $hget(%h,wxy) $v1 %f $hget(%h,filename)
else drawpic -o $hget(%h,wxy) %f $hget(%h,filename)
.timerdrawgif $+ $1 -ho 1 %delay noop $!drawgif( $1 ).draw
if ($calc(%f + 1) >= $pic($hget(%h,filename)).frames) {
if ($hget(%h,cbalias)) {
if ($($+($,$v1,$chr(40),$1,$chr(41)),2)) hadd drawgif $+ $1 frame 0
else {
.timerdrawgif $+ $1 off
hfree drawgif $+ $1
}
}
else hadd drawgif $+ $1 frame 0
}
else hinc drawgif $+ $1 frame
return
:error
if (*invalid window* iswm $error) {
reseterror
.timerdrawgif $+ $1 off
hfree drawgif $+ $1
return
}
}
if ($$1 === -p) .timerdrawgif $+ $$2 -P
elseif ($$1 === -r) .timerdrawgif $+ $$2 -r
elseif ($$1 == -d) {
.timerdrawgif $+ $$2 off
hfree drawgif $+ $2
}
else {
var %t $ticksqpc
hadd -m drawgif $+ %t wxy $1-2
hadd drawgif $+ %t frame 0
hadd drawgif $+ %t filename $3
hadd drawgif $+ %t cbalias $4
hadd drawgif $+ %t wh $5
hadd drawgif $+ %t cdelay $6
.timer -ho 1 0 noop $!drawgif( %t ).draw
return %t
}
}
Example
alias mayo {
window -depo @test 0 0 800 900
echo -sg $drawgif(@test,0 0,C:\Users\Ouims\Downloads\gm1.gif,gifend)
}
alias gifend echo -sg gif ended | return 1