• Welcome to Theos PowerBasic Museum 2017.

Animated composited Splash Screen

Started by Patrice Terrier, September 26, 2008, 09:50:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

Ray,
and others as well  ;)

Here is one example of a composited layered Splash Screen animation.

It uses 4 alphablended layers.


SUB SetImage(BYVAL hWnd AS LONG)
    LOCAL graphics, DesktopDC, hMemDC, hBmp, OldBmp, Img, imgW, imgH, ImgAttr, x, y, One AS LONG
    LOCAL rw AS RECT, bmp AS BITMAP, bi AS BITMAPINFO
    LOCAL dwp AS DWORD PTR
    LOCAL bf AS BLENDFUNCTION
    LOCAL lp, ptSrc AS POINTAPI
    LOCAL lpSize AS SIZEL
   
    STATIC LocalAlpha, LocalStepAlpha, xMove, FlipMove AS LONG   
   
    CALL GetWindowRect(hWnd, rw)
    lpSize.Cx = rw.nRight - rw.nLeft: lpSize.Cy = rw.nBottom - rw.nTop
    lp.X = rw.nLeft: lp.Y = rw.nTop

    DesktopDC = GetDC(0)
   
    '// Draw active frame to new memory DC
    hMemDC = CreateCompatibleDC(DesktopDC)
    hBmp = CreateCompatibleBitmap(DesktopDC, lpSize.Cx, lpSize.CY)
    OldBmp = SelectObject(hMemDC, hBmp)
    IF GdipCreateFromHDC(hMemDC, graphics) = 0 THEN
       CALL GdipSetInterpolationMode(graphics, 2)

       '// Draw layer 1 with respect of the z-order
       IF ImageArray(1) = 0 THEN ImageArray(1) = zLoadImageFromFile("LensCrown.png", imgW, imgH, 0)
       Img = ImageArray(1)
       IF Img THEN
          CALL GetImageSize(Img, imgW, imgH)
          CALL GdipDrawImageRectRectI(graphics, Img, x, y, imgW, imgH, 0, 0, imgW, imgH, 2, ImgAttr)
          '//CALL GdipDisposeImage(Img)
       END IF

       '// Draw layer 2 with respect of the z-order
       IF ImageArray(2) = 0 THEN ImageArray(2) = zLoadImageFromFile("LensOptical.png", imgW, imgH, 0)
       Img = ImageArray(2)
       IF Img THEN
          CALL GetImageSize(Img, imgW, imgH)
          IF LocalAlpha = 0 THEN LocalAlpha = 256
          IF LocalAlpha < 20 THEN
             LocalStepAlpha = 5
          ELSEIF LocalAlpha > 255 THEN
             LocalStepAlpha = -5
          END IF
          LocalAlpha = LocalAlpha + LocalStepAlpha

          ImgAttr = ZI_SetImageAlpha(LocalAlpha)
          CALL GdipDrawImageRectRectI(graphics, Img, 0, 0, imgW, imgH, 0, 0, imgW, imgH, 2, ImgAttr)
          '//CALL GdipDisposeImage(Img)
          imgAttr = 0
       END IF

       '// Draw layer 3 with respect of the z-order
       IF ImageArray(3) = 0 THEN ImageArray(3) = zLoadImageFromFile("LensFlare.png", imgW, imgH, 0)
       Img = ImageArray(3)
       IF Img THEN
          CALL GetImageSize(Img, imgW, imgH)
          IF FlipMove = 0 THEN
             xMove = xMove + 2
             IF xMove > 260 THEN FlipMove = -1
          ELSE
             xMove = xMove - 2
             IF xMove < 0 THEN FlipMove = 0
          END IF
          CALL GdipDrawImageRectRectI(graphics, Img, 103 + xMove, 100 + (xMove \ 2), imgW - (xMove\4), imgH - (xMove\4), 0, 0, imgW, imgH, 2, ImgAttr)
          '//CALL GdipDisposeImage(Img)
       END IF

       '// Draw layer 4 with respect of the z-order
       IF ImageArray(4) = 0 THEN ImageArray(4) = zLoadImageFromFile("LensLogo.png", imgW, imgH, 0)
       Img = ImageArray(4)
       IF Img THEN
          CALL GetImageSize(Img, imgW, imgH)
          CALL GdipDrawImageRectRectI(graphics, Img, 0, 0, imgW, imgH, 0, 0, imgW, imgH, 2, ImgAttr)
          '//CALL GdipDisposeImage(Img)
       END IF

       CALL GdipDeleteGraphics(graphics)
    END IF
   
    CALL GetObject(hBmp, sizeof(bmp), bmp)
   
    bf.BlendOp             = %AC_SRC_OVER
    bf.BlendFlags          = 0
    bf.AlphaFormat         = %AC_SRC_ALPHA '// Use source alpha
    bf.SourceConstantAlpha = 255 '//alpha
   
    CALL UpdateLayeredWindow (hWnd, DesktopDC, lp, lpSize, hMemDC, ptSrc, 0, bf, %ULW_ALPHA)
   
    CALL SelectObject(hMemDC, OldBmp)
    CALL DeleteObject(hBmp)
    CALL DeleteDC(hMemDC)
    CALL ReleaseDC(0, DesktopDC)
END SUB


Zip file updated on 08-09-2011

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Raymond Penn

Patrice,

Beautiful.  Just what I need.  Now I have to rework what I have but I think this will do the trick.

BTW, gdimage zinstance could cause problems for some people.  I created a dll and when you call getmodule  handle (zinstance) you get the EXE handle, not the dll which is what I needed as the resources were part of the dll, not the ede.  I don't remember if it caused me any other problems but I did work around them if it did.

Make sure you include this in the gdimage pacakge/demos.

Again, thanks. 

Ray

Patrice Terrier

#2
Ray

Quotegdimage zinstance could cause problems for some people

No, it can't ;)
because as written in the GDImage.CHM help file,
zInstance "Retrieve the instance of the current module."


FUNCTION zInstance ALIAS "zInstance" () EXPORT AS LONG
    FUNCTION = GetModuleHandle("")
END FUNCTION


Its purpose is to return the handle of the current EXE, because the parameter is "" null.

See also:
GetModuleHandleEx
and LoadLibraryEx with the %LOAD_LIBRARY_AS_IMAGE_RESOURCE (&H00000020) constant

Added:
The GDImage API to load an image resource is: ZI_LoadFromResource (see $GDIPLUSEXT for the list of supported graphic format) but here again it is intended to work with the current module.
See the RESOURCE.BAS demo.


...

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

I have updated the zip file to reduce CPU usage, loading/unloading the resource only once, using a global ImageArray() to store the image handles.

The zip file is attached to the first post of this thread.

Here is a screen shot hover BassBox (on VISTA)

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

The first post of this thread has been updated, to fix the ZIP file corruption caused by the "Server Collapse".

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com