Liberty BASIC Community Forum
« Graphics pan »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 6:10pm


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


« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Graphics pan  (Read 374 times)
Angelo2449
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Graphics pan
« Reply #15 on: Dec 22nd, 2017, 09:44am »

Not exactly, it works like this:
- I open a file, the graph is drawn.
- the cursor in the graphics area, is a cross, ready to perform another zoom.

and then it should work like this :
- I click the 'Pan' icon the cursor becomes a 'Hand' and the system is ready to run the 'Pan'.

So the system changes the cursor and attitude with each click of the corresponding icon.

The icons are many, the only one that does not work yet is that of the 'Pan' icon.

Thank you.


User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: Graphics pan
« Reply #16 on: Dec 22nd, 2017, 11:07am »

Ok you set the drawing status to either zoom or pan by button input then use leftMouseButton events to pan or zoom.

This does that but for some reason the hand cursor has stopped showing, I substituted the text cursor as I am out of time right now but this shows how to change status and cursor as events unfold.


Code:
zoom and pan

'5. F5 resets zoom/pan to original one

status=0
zoom=1
pan=2
nomainwin
button #gr.b1 "zoom",[zoom],UL, 10,10,50,20
button #gr.b2 "pan",[pan],UL,10,30,50,20
open "test zoom & pan" for graphics_nsb_nf as #gr
#gr "trapclose [quit]"
#gr "down"
#gr "home; posxy cx cy"


#gr "when leftButtonDown [lmbDown]"
#gr "when leftButtonUp [lmbUp]"
#gr "when leftButtonMove [lmbMove]"

#gr "when characterInput [keyCheck]"
#gr "setfocus"

    h=hwnd(#gr)
    call setClass h
    'This routine changes which cursor is loaded
    item$ = "649 pointing hand"      ' CHANGE TO CHOICE
    cursorNum=val(str$(32)+word$(item$,1))
    CursorHandle=LoadCursor(cursorNum)

offX=0:offY=0
scale = 1

gosub [drawStuff]
wait

[zoom]
    if status<>zoom then
        status=zoom
        cursor CROSSHAIR
    else
        status=0
        cursor NORMAL
    end if
    wait

[pan]
    if status<>pan then
        status=pan
        cursor TEXT 'HOURGLASS
        'call SetCursor CursorHandle
    else
        status=0
        cursor NORMAL
    end if
    wait

'-------------------------------
[keyCheck]
'print len(Inkey$), asc(Inkey$)
    if Inkey$=chr$(0)+chr$(_VK_F5) then
        offX=0:offY=0
        scale = 1
        gosub [drawStuff]
    end if
wait




'-------------------------------
[lmbDown]
    lmbX=MouseX: lmbY=MouseY
    oldX=MouseX: oldY=MouseY
    #gr "rule xor"
    wait



[lmbUp]
    if status=zoom then
        lmbX2=MouseX: lmbY2=MouseY
        dx2 = int((lmbX2-lmbX)/2)
        if dx2=0 then wait  'not possible to zoom
        midX=(lmbX2+lmbX)/2
        midY=(lmbY2+lmbY)/2
        midX.math = (midX-offX)/scale    'old scale
        midY.math = (midY-offY)/scale

        if dx2>0 then   'left to right zoom in
            scale = scale * cx/dx2
        else    'right  to left zoom out
            scale = scale * (-1)*dx2/cx
        end if
        'the math is, after new scale, selection rectangle midpoint should go to window midpoint
        offX=cx-scale*midX.math
        offY=cy-scale*midY.math
        'x.screen = offX+scale*x
        '=> x.math = (x.screen-offX)/scale
        'print     scale, (lmbX2+lmbX)/2, (lmbY2+lmbY)/2, offX, offY
        #gr "rule over"
        gosub [drawStuff]
    end if
    if status=pan then
        #gr "rule over"
        gosub [drawStuff]
    end if
   ' cursor NORMAL
   ' status=0
    wait

[lmbMove]
    if status=zoom then
        #gr "place ";lmbX;" ";lmbY;"; box ";oldX;" ";oldY
        oldX=MouseX: oldY=MouseY
        #gr "place ";lmbX;" ";lmbY;"; box ";oldX;" ";oldY
    end if
    if status=pan then
        offX=offX+MouseX-oldX
        offY=offY+MouseY-oldY
        oldX=MouseX: oldY=MouseY
        gosub [drawStuff]
    end if
    wait

'--------------------------------------



'---------------------------------
[drawStuff]
'x.screen = offX+scale*x
'=> x.math = (e.screen-offX)/scale
'#gr "line ";;" ";;" ";;" ";
    #gr "cls"
    'OX
    y=cy
    x0=(0-offX)/scale
    x1=(2*cx-offX)/scale
    #gr "line ";0;" ";y;" ";2*cx;" ";y
    #gr "place ";0;" ";y+25
    #gr "\";int(x0)
    #gr "place ";2*cx-50;" ";y+25
    #gr "\";int(x1)
    for x=10*int(x0/10) to 10*int(x1/10) step 10
        xe=offX+scale*x
        #gr "line ";xe;" ";y-4;" ";xe;" ";y+4
        if x mod 50 =0 then
            #gr "line ";xe;" ";y-7;" ";xe;" ";y+7
        end if
        if x mod 100 =0 then
            #gr "place ";xe;" ";y-20
            #gr "\";x;" "
        end if
    next
'OY
    x=cx
    y0=(0-offY)/scale
    y1=(2*cy-offY)/scale
    #gr "line ";x;" ";0;" ";x;" ";2*cy
    #gr "place ";x-40;" ";20
    #gr "\";int(y0)
    #gr "place ";x-40;" ";2*cy-5
    #gr "\";int(y1)
    for y=10*int(y0/10) to 10*int(y1/10) step 10
        ye=offY+scale*y
        #gr "line ";x-4;" ";ye;" ";x+4;" ";ye
        if y mod 50 =0 then
            #gr "line ";x-7;" ";ye;" ";x+7;" ";ye
        end if
        if y mod 100 =0 then
            #gr "place ";x+10;" ";ye
            #gr "\";y;" "
        end if
    next

'draw smth, denending of offset (offX, offY) and scale
'it really should be as simple as this. Or as complex as you want.
    randomize .5
    #gr "place ";scale*cx+offX;" "; scale*cy+offY

    #gr "north"
    for i = 1 to 20
        a=int(rnd(0)*360)-180
        r=int(rnd(0)*50)
        #gr "turn ";a;"; go ";r*scale
    next

#gr "flush"
return

[quit]
    close #gr
    end

'================================
sub SetCursor hCursor
    calldll #user32, "SetCursor",_
    hCursor as long,_
    result as long
    end sub

'This loads the cursor and returns the cursor's handle

function LoadCursor(CursorName)
    flags = hexdec("8000") or _LR_DEFAULTSIZE
    calldll #user32, "LoadImageA",_
        0             As long,_
        CursorName    As long,_
        _IMAGE_CURSOR as long,_
        0             as long,_
        0             as long,_
        flags         as long,_
        hCursor       As long

    call SetCursor hCursor
    LoadCursor=hCursor
    end function

sub setClass hWnd
   index=_GCL_HCURSOR or 0 'which part to set
   value=0 'set it to null

    calldll #user32, "SetClassLongA",_
        hWnd as long,_
        index as long,_
        value as long,_
        result as long

    end sub








 
User IP Logged

Angelo2449
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Graphics pan
« Reply #17 on: Dec 22nd, 2017, 1:11pm »

Ok,
so I would like it but now the 'little hand' does not appear.
Thank you.
User IP Logged

Angelo2449
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Graphics pan
« Reply #18 on: Dec 22nd, 2017, 4:49pm »

Ok,
The first step is this:
- I click the 'Pan' button
- the cursor becomes a 'Hand' when it is in the graphics area and becomes an 'Arrow' when it is elsewhere
the effect of pressing the left mouse button depends on this relationship:
Code:
   [check]

    mh = GetMouseFocus()

    select case

        case (CursorType$ = "zoom") and (Associato = 0)
        if mh = gbh then cursor crosshair else cursor normal

        case (CursorType$ = "zoom") and (Associato = 1)
        if mh = gbh then cursor arrow else cursor normal

        case (CursorType$ = "window")
        if mh = gbh then cursor crosshair else cursor normal

        case (CursorType$ = "Intersec") and (Intersec = 1)
        if mh = gbh then cursor arrow else cursor normal

        case (CursorType$ = "Hand")
        if mh = gbh then ????????????? else cursor normal

    end select

    wait

 


????????? for "Pan" effect.
Thank you
User IP Logged

Angelo2449
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Graphics pan
« Reply #19 on: Dec 23rd, 2017, 01:35am »

Now everything is in order, the 'Pan' function works perfectly|
I integrated the code like this:
Code:

.........................
[icoMano]

TipoCursore$ = "Mano"

wait
.........................

    [check]

    mh = GetMouseFocus()

    select case

        case (TipoCursore$ = "zoom") and (Associato = 0)
        if mh = gbh then cursor crosshair else cursor normal

        case (TipoCursore$ = "zoom") and (Associato = 1)
        if mh = gbh then cursor arrow else cursor normal

        case (TipoCursore$ = "finestra")
        if mh = gbh then cursor crosshair else cursor normal

        case (TipoCursore$ = "Intersezione") and (Intersezione = 1)
        if mh = gbh then cursor arrow else cursor normal

       if mh = gbh then call SetCursor CursorHandle else cursor 
       normal

    end select
 


the thing that is missing is if I click the 'Hand' button and set 'TipoCursore$' to 'Mano' I would like the hand cursor to appear right away..

Thank you.



« Last Edit: Dec 23rd, 2017, 01:41am by Angelo2449 » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: Graphics pan
« Reply #20 on: Dec 23rd, 2017, 04:26am »

The hand button is "outside" the graphicbox. You are setting the cursor to hand with the restriction of the mouse being "inside" the graphicbox. You can't have both.

I assume here that you have a timer running, constantly checking what control the mouse is over.
« Last Edit: Dec 23rd, 2017, 04:28am by Rod » User IP Logged

Pages: 1 2  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