Blit.sel
#!./Selene
Selene.UseDirectFB("--dfb:quiet,no-vt")
DirectFB.init( DirectFB.CooperativeConst('FULLSCREEN') )
local img,err = SelImage.create("/usr/local/share/directfb-examples/gnu-keys.png")
if img then
local srf = SelSurface.create { caps=SelSurface.CapabilityConst('PRIMARY')
}
local isrf = img:toSurface() img:destroy()
print "Partial blit"
srf:Blit(
isrf, { 10,20,30,40 }, 50,50 )
print "Hit 'enter' key to exit"
io.stdin:read'*l'
print "Create a background"
srf:Clear(0,0,0,0)
w,h = srf:GetSize()
math.randomseed( os.time() )
for i = 1, 75 do
local c = math.random(10)
if c > 6 then
srf:SetColor( math.random(0,255), math.random(0,255), math.random(0,255), math.random(0,255))
elseif c == 3 then
srf:DrawLine( math.random(0,w), math.random(0,h), math.random(0,w), math.random(0,h) )
elseif c == 4 then
srf:DrawRectangle( math.random(0,w), math.random(0,h), math.random(0,w), math.random(0,h) )
elseif c == 5 then
srf:FillRectangle( math.random(0,w), math.random(0,h), math.random(0,w), math.random(0,h) )
elseif c == 6 then
srf:FillTriangle( math.random(0,w), math.random(0,h), math.random(0,w), math.random(0,h), math.random(0,w), math.random(0,h) )
end
end
local backup = srf:clone()
print "Hit 'enter' key to exit"
io.stdin:read'*l'
print "Blit with transparency"
_,err = srf:restore(backup)
if err then
print("*E* ".. err)
end
srf:SetBlittingFlags( SelSurface.BlittingFlagsConst('BLEND_ALPHACHANNEL') )
srf:Blit(
isrf, nil, 150,150 )
print "Hit 'enter' key to exit"
io.stdin:read'*l'
print "TileBlit with transparency"
srf:restore(backup) srf:SetBlittingFlags( SelSurface.BlittingFlagsConst('BLEND_ALPHACHANNEL') )
srf:TileBlit(
isrf, nil, 150,150 )
print "Hit 'enter' key to exit"
io.stdin:read'*l'
print "manual TileBlit with transparency and clip"
srf:restore(backup) srf:SetBlittingFlags( SelSurface.BlittingFlagsConst('BLEND_ALPHACHANNEL') )
srf:SetClipS( 0, h/2, w, isrf:GetHight() )
srf:TileBlit(
isrf, nil, 0,h/2 )
print "Hit 'enter' key to exit"
io.stdin:read'*l'
print "Builtin TileBlit with transparency and clip"
srf:restore(backup) srf:SetBlittingFlags( SelSurface.BlittingFlagsConst('BLEND_ALPHACHANNEL') )
_,err = srf:TileBlitClip(
isrf, nil, { 20, 20, w-40, isrf:GetHight() } )
if err then
print(err)
end
print "Hit 'enter' key to exit"
io.stdin:read'*l'
print "StretchBlit with transparency"
srf:restore(backup)
srf:SetBlittingFlags( SelSurface.BlittingFlagsConst('BLEND_ALPHACHANNEL') )
srf:StretchBlit( isrf, nil, {50,50, h-100,w-100} )
print "Hit 'enter' key to exit"
io.stdin:read'*l'
backup:destroy()
srf:destroy()
else
print(err)
end