Unkomplizierte Ergänzung zum BlitzBasic-Befehl DrawImage. Zeichnet ein (rechteckiges) Bild mit einem weichem Schattenwurf ("blurred drop shadow").
Nur mit kleineren Bildern Echtzeit-tauglich, aber sehr gut zu gebrauchen, um z.B. Bildern und Buttons im Titelmenü eine schicke 3D-Optik zu verpassen. In diesem Fall einfach alle Elemente vorher in ein großes Bild vorzeichnen und dann einfach dieses benutzen.
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN]
Graphics 800,600,0,2
Img_Pattern% = CreateImage(32,32) SetBuffer ImageBuffer(Img_Pattern) Color 100,100,125 : Rect 0,0,32,32,1 Color 150,150,175 : Rect 0,0,16,16,1 Rect 16,16,16,16,1
Img_Test% = CreateImage(128,128) SetBuffer ImageBuffer (Img_Test) Color 100,0,100 : Rect 0,0,128,128,1 Color 200,0,200 : Rect 0,0,64,64,1 Rect 64,64,64,64,1 : Color 255,255,0 SetBuffer BackBuffer()
x% = (800-ImageWidth (Img_Test))/2 y% = (600-ImageHeight(Img_Test))/2 off% = 12 strength% = 85 dir% = 1
While Not KeyHit(1)
TileBlock Img_Pattern,0,0
DrawImage_Shadow Img_Test, x , y , off, strength DrawImage_Shadow Img_Test, x-50 , y+50 , off, strength DrawImage_Shadow Img_Test, x-100, y-100, off, strength If KeyDown(27) And off < 32 Then off = off + 1 If KeyDown(53) And off > 4 Then off = off - 1
Text 10,10,\"HIT + OR - TO CHANGE THE SHADOW OFFSET. CURRENT OFFSET : \" + off
Flip 1 Wend
End
Function DrawImage_Shadow(Img%, img_x%, img_y%, offset% = 32, strength% = 100)
Local x1%, y1%, x2%, y2%, x%, y%, i%, j% Local shadowPercent% = strength Local shadowStep# = 100/offset
DrawBlock Img,img_x,img_y : If offset < 4 Return
LockBuffer GraphicsBuffer() For i = 0 To offset x1 = img_x + offset y1 = img_y + ImageHeight(Img)+i x2 = img_x + (ImageWidth(Img)-1)+i y2 = img_y + offset
j = shadowPercent For x = x1 To x2 DarkenPixel x,y1,shadowPercent-j If j > 0 Then j = j - shadowStep Next j = shadowPercent For y = y2 To y1 DarkenPixel x,y ,shadowPercent-j If j > 0 Then j = j - shadowStep Next shadowPercent = shadowPercent - shadowStep Next UnlockBuffer GraphicsBuffer()
End Function
Function DarkenPixel(x%,y%,percent%)
Local a%,r%,g%,b%,argb%,rgb1%,rgb% If percent > 100 percent = 100 rgb1 = (100-percent) * 255.0/100.0 rgb = ReadPixelFast(x,y) a = (rgb And $FF000000)/$1000000 r = rgb1 * ((rgb And $FF0000)/$10000) / 256 g = rgb1 * ((rgb And $FF00)/$100) / 256 b = rgb1 * ( rgb And $FF) / 256 WritePixelFast x,y,(a*$1000000 + r*$10000 + g*$100 + b)
End Function
|