Liberty BASIC Community Forum
« Card graphics question »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 5:57pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Card graphics question  (Read 151 times)
Turtleman
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 187
xx Card graphics question
« Thread started on: Nov 9th, 2017, 05:20am »

I've using the popular qcard dll and have looked over Alyce's excellent 13-lesson tutorial, but can't find anything that shows how to reposition a card 90 degrees (horizontal). In my blackjack program, it would be nice to be able to designate a double down card by positioning it horizontally, as I've seen in a couple other programs. That may not be possible in LB, but at least the program's finally at a point where I can consider adding "frills." smiley Thanks!
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: Card graphics question
« Reply #1 on: Nov 9th, 2017, 08:08am »

Not sure it can be done within the .dll But you are drawing to a graphics screen so it should be perfectly possible to use the blitter to draw 90o cards. You would need one bmp of all cards and then slice it out from a graphicsDC and blit it to the displayDC using transparentBlit()

Blitter demos are on the LBPE.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: Card graphics question
« Reply #2 on: Nov 10th, 2017, 12:01pm »

I am out of time right now and have a busy few days. This is some code that attempts to use Parallelogram Blit to grab the card and rotate it. You would need to draw it somewhere off centre, grab it, rotate and draw the grabbed bmp where you want it and then delete the original

I have not got the blit parameters right. There is a tutorial over on LBPE that should get you started experimenting.

Whether it all stays in view or not needs testing. Flush wont work with blitted graphics so you might need to grab the whole screen and redraw it then flush.

edit updated the code still a little ugly.

Code:
     nomainwin
    WindowWidth=700
    WindowHeight=480
    graphicbox #1.g, 0, 0, 700, 440
    open "Card Game" for window_nf as #1
    #1 "trapclose [quit]"
    'get graphicbox handle
    hBox=hwnd(#1.g)
    ' Get the handle to the graphicbox display:
    displayDC = GetDC(Hwnd(#1.g))




    'open the dlls
    open "qcard32.dll" for dll as #qc

    'initialize the deck
    Call InitializeDeck hBox
    'draw a nice background
    #1.g "down; fill 10 190 225"

    for i = 1 to 2
        scan
        'window handle, card index number, x, y
        Call DealCard hBox,i,i*100,10
        Call RotateCard hBox,i,i*100,10,displayDC


    next

wait
[quit]
    ' Release the handle from the graphicbox display:
    Call ReleaseDC Hwnd(#1.g), displayDC
    Close #qc
    Close #1
    end
''''''''''''''''''''
'subs and functions:

Sub InitializeDeck hndle
    calldll #qc, "InitializeDeck",_
    hndle as ulong,r as long
    End Sub
Sub DealCard hndle,nC,x,y
    'places card on window whose handle is hndle at x,y
    'nC is number of card - 1-52 in first deck and
    '53-104 in second deck, if used
    calldll #qc, "DealCard",hndle as ulong,nC as long,_
    x as long,y as long,r as void
    End Sub
Sub RotateCard hBox,i,x,y,displayDC

    centreX=x+35
    centreY=y+48

    'getbmp bmp
    #1.g "getbmp bmp ";x;" ";y;" 71 96"
    '#1.g "drawbmp bmp 200 200"
    hbmp = Hbmp("bmp")

    STRUCT lpPoint,_
    x1 as long,_  'ulx
    y1 as long,_  'uly
    x2 as long,_  'urx
    y2 as long,_  'ury
    x3 as long,_  'llx
    y3 as long    'lly

    angle=135
    'use some trig to map out our three points on a circle
    lpPoint.x1.struct=centreX-(72*cos(angle/57.29577951))
    lpPoint.y1.struct=centreY-(53*sin(angle/57.29577951))
    lpPoint.x2.struct=centreX-(72*cos((angle+90 mod 360)/57.29577951))
    lpPoint.y2.struct=centreY-(53*sin((angle+90 mod 360)/57.29577951))
    lpPoint.x3.struct=centreX-(72*cos((angle+270 mod 360)/57.29577951))
    lpPoint.y3.struct=centreY-(53*sin((angle+270 mod 360)/57.29577951))

    calldll #gdi32, "PlgBlt",_
        displayDC as ulong,_        'device context of graphicbox
        lpPoint as struct,_   'array of points
        displayDC as ulong,_      'device context of graphicbox
        x as long,_           'ulx source
        y as long,_           'uly source
        71 as long,_    'width source
        96 as long,_   'height source
        0 as ulong,_      'mask bmp handle, null = not used
        0 as long,_           'ulx mask
        0 as long,_           'uly mask
        re as long            'nonzero=success

    #1.g "getbmp bmp ";x-15;" ";y+12;" 101 73"
    call RemoveCard hBox, i
    #1.g "drawbmp bmp ";x-15;" ";y+12


    End Sub

Sub SetCardStatus nC,face
    'nC is number of card - 1-52 in first deck and
    '53-104 in second deck, if used
    'face:  0=facedown,1=faceup
    calldll #qc, "SetCardStatus",nC as long,_
    face as long,r as void
    End Sub

Sub RemoveCard hndle,nC
    'removes a card from screen that was
    'drawn with DealCard, replacing screen background
    calldll #qc, "RemoveCard",hndle as ulong,_
    nC as long,r as void
    End Sub




Function GetDC(hWnd)
    CallDLL #user32, "GetDC",_
        hWnd As ulong,_  'window or control handle
        GetDC As ulong   'returns device context
End Function

Sub ReleaseDC hWnd, hDC
    CallDLL#user32,"ReleaseDC",_
        hWnd As ulong,_  'window or control handle
        hDC As ulong,_   'handle of DC to delete
        result As Long
End Sub


Sub BitBlt hDCdest,x,y,w,h,hDCsrc,x2,y2
    CallDLL #gdi32, "BitBlt",hDCdest As uLong,x As Long,y As Long,w As Long,h As Long,_
        hDCsrc As uLong,x2 As Long,y2 As Long, _SRCCOPY As Ulong, Result As long
End Sub




 
« Last Edit: Nov 10th, 2017, 1:18pm by Rod » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls