News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

BitBlt Motion

Started by masitecno, May 25, 2012, 09:04:44 AM

Previous topic - Next topic

masitecno

Hi everybody.

I'm trying to scroll an image like a cilinder, i had an idea using bitblt but i think something was wrong in the implementation:

Code:
Paint_Proc proc hWin:DWORD, hDC:DWORD, movit:DWORD
    LOCAL hOld :DWORD
    LOCAL hNew :DWORD
    LOCAL memDC:DWORD
    LOCAL memDCBack:DWORD
    invoke CreateCompatibleDC,hDC
    mov memDC, eax                   
    invoke SelectObject,memDC,hBmp
    mov hOld, eax                         
    invoke CreateCompatibleDC,hDC   
    mov memDCBack, eax
    invoke SelectObject,memDC,hBmp
    mov hNew, eax
    .if movit == 0
      invoke BitBlt,hDC,10,10,768,576,memDC,0,0,SRCCOPY
    .else
    mov var3, 0
    .while var3 < 2     ;<< set the number of times image is looped
      mov var1, 0
      .while var1 < 768 ;<<  Bitmap width
         invoke BitBlt,memDCBack,0,0,767,576,memDC,1,0,SRCCOPY     ;take from pixel 1 to width
         invoke BitBlt,memDCBack,767,0,1,576,memDC,767,0,SRCCOPY  ;take pixel 1 to  last column
         invoke BitBlt,hDC,10,10,768,576,memDCBack,var1,0,SRCCOPY    ;draw the image

        inc var1
      .endw

    inc var3
    .endw
    .endif
    invoke SelectObject,hDC,hOld
    invoke DeleteDC,memDC
    invoke SelectObject,hDC,hNew
    invoke DeleteDC,memDCBack
    return 0
Paint_Proc endp

(The original code was taken from a masm32 example)

I think bitblt can copy from the second column to the end of the bitmap, then copy the first column to the last column then paint that in the window but.
It just doesnt work.

I would appreciate some help. Thanks.

qWord

A Bitmap cannot be selected into two DC simultaneously.
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

did you see the code i posted in the old forum ???


masitecno


Yes I did Dave, it's just than i did not undestand.

Could you please explain me again?

Thankyou

dedndave

#4
well - i may have made it a little over-complicated by adding the 2 transparent images
also - i used double-buffering to prevent flicker
it makes the paint code look a little heavy - my fault
still - we do want to double-buffer

but - let's look at the code without the 2 transparencies...
    LOCAL   hbmpPrev1 :HBITMAP
    LOCAL   hbmpPrev2 :HBITMAP
    LOCAL   hbmpMem2  :HBITMAP
    LOCAL   ps        :PAINTSTRUCT

;------------------------------

    mov     eax,uMsg
    .if eax==WM_PAINT
        push    ebx
        push    esi
        push    edi
        INVOKE  BeginPaint,hWnd,addr ps
        INVOKE  CreateCompatibleDC,eax
        xchg    eax,ebx                                                       ;EBX = hdcMem1
        INVOKE  SelectObject,ebx,hbmpCanyon
        mov     hbmpPrev1,eax
        INVOKE  CreateCompatibleDC,ps.hdc
        xchg    eax,esi                                                       ;ESI = hdcMem2
        INVOKE  CreateCompatibleBitmap,ps.hdc,sizeCanyon.x,sizeCanyon.y
        mov     hbmpMem2,eax
        INVOKE  SelectObject,esi,eax
        xor     edi,edi                                                       ;EDI = 0
        mov     hbmpPrev2,eax
        mov     ecx,sizeCanyon.x
        mov     eax,uStepOffset
        sub     ecx,eax
        push    ecx
        push    eax
        INVOKE  BitBlt,esi,edi,edi,ecx,sizeCanyon.y,ebx,eax,edi,SRCCOPY
        pop     eax
        pop     ecx
        .if eax
            INVOKE  BitBlt,esi,ecx,edi,eax,sizeCanyon.y,ebx,edi,edi,SRCCOPY
        .endif
        INVOKE  BitBlt,ps.hdc,edi,edi,sizeCanyon.x,sizeCanyon.y,esi,edi,edi,SRCCOPY
        INVOKE  SelectObject,esi,hbmpPrev2
        INVOKE  DeleteObject,hbmpMem2
        INVOKE  DeleteDC,esi
        INVOKE  SelectObject,ebx,hbmpPrev1
        INVOKE  DeleteDC,ebx
        INVOKE  EndPaint,hWnd,addr ps
        pop     edi
        pop     esi
        pop     ebx
        xor     eax,eax                                 ;return 0


the uStepOffset variable is a value from 0 to (image width - 1)
it determines the X coordinate at which the image will be "folded"

let's say we have an image that is 100 pixels wide
if uStepOffset is 10, image pixel columns 10 through 99 will be painted on the left of the display area
then, image pixel columns 0 through 9 are painted on the right side of the display area

if it's value is 0, the image is displayed normally, so the first BitBlt call takes care of all of it
if the value is not 0, the second BitBlt call takes care of the remaining part

the third BitBlt call takes care of the double-buffering

hfheatherfox07

Quote from: dedndave on May 25, 2012, 10:15:13 AM
did you see the code i posted in the old forum ???

Hey all .....
my first post here ..... :icon_cool:
@ dedndave I looked for that were is it ?   :P
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

LOL never mind it was a link not an attachment

http://dedndave.x10hosting.com/MillerTime.zip


NICE!!!
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.