Liberty BASIC Community Forum
« Graphics pan »

Welcome Guest. Please Login or Register.
Jan 23rd, 2018, 7:21pm


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


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


member is offline

Avatar




PM


Posts: 22
xx Graphics pan
« Thread started on: Dec 1st, 2017, 01:27am »

Hi guys,
I have to pan a graphic area containing a drawing.
Is there any example?
I would like to make the 'hand' appear as in Autocad, if possible,
Thanks,
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1732
xx Re: Graphics pan
« Reply #1 on: Dec 1st, 2017, 02:26am »

pan example (right button pans )
Zoom and pan

LBPE on changing cursor
Custom Cursors With LoadCursorFromFile

Combined program (uses existing "pointing hand cursor", try to investigate link#2 as for any other hand cursor exists)
Code:
'zoom and pan
'by tsh73, july 2013
'1. draw smth, denending of offset (offX, offY) and scale
'2. scale and pan, programmatically
'3.     rmb pans
'4.     lmb zooms (left to right zoom in; righ to left zoom out (try it))
'5. F5 resets zoom/pan to original one

nomainwin
open "test zoom & pan" for graphics_nsb_nf as #gr
#gr "trapclose [quit]"
#gr "down"
#gr "home; posxy cx cy"

#gr "when rightButtonDown [rmbDown]"
#gr "when rightButtonUp [rmbUp]"
#gr "when rightButtonMove [rmbMove]"

#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

'-------------------------------
[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]
    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]
wait

[lmbMove]
    #gr "place ";lmbX;" ";lmbY;"; box ";oldX;" ";oldY
    oldX=MouseX: oldY=MouseY
    #gr "place ";lmbX;" ";lmbY;"; box ";oldX;" ";oldY
wait

'--------------------------------------
[rmbDown]
    rmbX=MouseX: rmbY=MouseY
    oldX=MouseX: oldY=MouseY
    #gr "rule xor"
    'cursor CROSSHAIR
    call SetCursor CursorHandle
wait

[rmbUp]
    offX=offX+MouseX-rmbX
    offY=offY+MouseY-rmbY
    #gr "rule over"
    gosub [drawStuff]
    'cursor NORMAL
wait

[rmbMove]
    #gr "line ";rmbX;" ";rmbY;" ";oldX;" ";oldY
    oldX=MouseX: oldY=MouseY
    #gr "line ";rmbX;" ";rmbY;" ";oldX;" ";oldY
    call SetCursor CursorHandle
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

damned Dog in the Manger
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: Graphics pan
« Reply #2 on: Dec 1st, 2017, 03:29am »

Not sure I understand what you are looking for. Is it to move an object within a graphics window or to pan over a large image with a small graphics window?

Here is code to select drawn objects and move them. Anatoly has covered the cursor issue.

Code:
    nomainwin
    ' draw some objects
    dim obj(10,4) 'x,y,width/height, obj number = z order
    obj(1,1)=100
    obj(1,2)=100
    obj(1,3)=50

    obj(2,1)=120
    obj(2,2)=120
    obj(2,3)=25
    numObj=2


    open "Panning" for graphics as #1
    #1 "down ; trapclose [quit]"
    #1 "when rightButtonDown [select]"
    gosub [draw]

    wait


    [select]
    x=MouseX
    y=MouseY
    selected=0
    for n=numObj to 1 step -1
        if x>obj(n,1) and x<obj(n,1)+obj(n,3)then
            if y>obj(n,2) and y<obj(n,2)+obj(n,3) then
                selected=n
                exit for
            end if
        end if
    next
    if selected>0 then
        #1 "when rightButtonDown"
        #1 "when rightButtonMove [track]"
        #1 "when rightButtonUp [stop]"
        offsetX=x-obj(n,1)
        offsetY=y-obj(n,2)
    end if
    gosub [draw]
    wait


    [track]
    obj(selected,1)=MouseX-offsetX
    obj(selected,2)=MouseY-offsetY
    gosub [draw]
    wait

    [stop]
    #1 "when rightButtonDown [select]"
    #1 "when rightButtonMove"
    #1 "when rightButtonUp"
    selected=0
    gosub [draw]
    wait



    [draw]
    #1 "cls"
    for n= 1 to numObj
        if n= selected then #1 "color red" else #1 "color black"
        #1 "place ";obj(n,1);" ";obj(n,2)
        #1 "box ";obj(n,1)+obj(n,3);" ";obj(n,2)+obj(n,3)
    next
    return


    [quit]
    close #1
    end



 
User IP Logged

Angelo2449
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Graphics pan
« Reply #3 on: Dec 1st, 2017, 5:16pm »

Hi Gender,
I thank you for the precious information.
I made the 'zoom' and works perfectly (not here but it affects the 'pan') even if, after the last changes related to the 'pan', I have a flicker with the cursor.
The 'pan' does not work, I attach here the code (reduced) in the hope that I can review it and solve the problem.
Thank you.
Code:

    nomainwin

    on error goto [GestErr]

    dim Componente$(300), PuntoBuono$(300), Riga$(300), nome$(300), COx(300), COy(300)
    dim ZoomScala(64)   ' livelli di Zomm

    [Grafica]

    TipoErrore$ = "Grafica"

    UpperLeftX = 50
    UpperLeftY = 25

    WindowWidth  = 1240
    WindowHeight =  720

    BackgroundColor$ = "blue"
    ForegroundColor$ = "black"
    ListboxColor$ = "white"

    xab = 37 : Disco$ = "C:"

    textbox #graph.test, 939, 645, 268, 25
    graphicbox #graph.gra, 30, 10, 900, 660

    open "Grafica - Restituzione del Rilievo - Catasto by Montoli Angelo Ambrogio" for window as #graph
    #graph, "font courier_new 10 16 bold"
    #graph, "trapclose [quit.GraphUno]"
    #graph.gra, "enable"

    #graph.gra, "down"
    #graph.gra, "home; posxy cx cy"

    #graph.gra, "when rightButtonDown [rmbDown]"
    #graph.gra, "when rightButtonUp [rmbUp]"
    #graph.gra, "when rightButtonMove [rmbMove]"

    #graph.gra, "when leftButtonDown [lmbDown]"
    #graph.gra, "when leftButtonUp [lmbUp]"
    #graph.gra, "when leftButtonMove [lmbMove]"

    #graph.gra, "down"
    #graph.gra, "color red"

    offX = 0 : offY = 0
    scale = 1

    TipoCursore$ = "zoom" : Associato = 0
    Apertura = 0
    #graph.gra, "flush"

    Riga$(1) = "po1                 ,1500118.675841,5042522.142279,522.155 - 4420299.591,700199.755,4529425.839"
    Riga$(2) = "po2                 ,1500112.811504,5042505.703623,505.717 - 4420312.148,700195.804,4529414.368"
    Riga$(3) = "po3                 ,1500120.298150,5042503.102554,164.597 - 4420312.799,700203.490,4529412.533"
    Riga$(4) = "po4                 ,1500126.076201,5042519.277912,519.291 - 4420300.439,700207.385,4529423.818"
    Riga$(5) = "po5                 ,1500118.547251,5042521.957075,521.970 - 4420299.771,700199.653,4529425.739"

    h = hwnd(#graph.gra)

    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)

    gbh = hwnd(#graph.gra)

    timer 100, [check]

    goto [Grafica.Apri]
    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$ = "xy")
        if mh = gbh then cursor crosshair else cursor normal

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

    end select

    wait

   Function GetMouseFocus()
        'Returns the handle of the window or control whose
        'client area is under the mouse cursor.
        Struct GMFpoint, x As Long, y As Long
        Struct GMFrc, left As Long, top As Long, right As Long, bottom As Long
        Calldll #user32, "GetCursorPos", GMFpoint As Struct, ret As Void
        X = GMFpoint.x.struct
        Y = GMFpoint.y.struct
        Calldll #user32, "WindowFromPoint", X As Long, Y As Long, hWnd As Ulong
        Calldll #user32, "ScreenToClient", hWnd As Ulong, GMFpoint As Struct, ret As Void
        x = GMFpoint.x.struct
        y = GMFpoint.y.struct
        Calldll #user32, "GetClientRect", hWnd As Ulong, GMFrc As Struct, r As long
        Calldll #user32, "PtInRect", GMFrc As Struct, x As Long, _
        y As Long, PointOnClient As long
        If PointOnClient Then GetMouseFocus = hWnd
    End Function

    Function GetFocus()
        Calldll #user32, "GetFocus", GetFocus As Ulong
    End Function

    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

    [quit.Graph]

    close #graph

    wait

    [GestErr]

    #graph.test, Err$

    wait

    [quit.GraphUno]

    NonChiudere = 0
    GraficCtrl = 0
    cursor normal
    close #graph
    Entrata = 0
    SeAperto = 0

    wait

    [Grafica.Apri]

    gosub [Grafica.ApriUno]
    TipoZoom$ = "Esteso"
    goto [Graph.ZoomEsteso]

    wait

    [Graph.ZoomEsteso]

    TipoZoom$ = "Elastico"
    scale = scaleoriginal
    mapX = originalX
    mapY = originalY
    gosub [ZoomElastico_Uno]
    TipoCursore$ = "zoom" : Associato = 0
    #graph.gra, "flush"
    #graph.test, "OK"
    wait


    [GraphApriErr]

    #graph.test, "-- "; Err$

    wait


    [Grafica.ApriUno]

    mapX = 0 : mapY = 0 : k = 0

    for k = 1 to 5
        mapX = mapX + val(mid$(Riga$(k), 22, 14))
        mapY = mapY + val(mid$(Riga$(k), 37, 14))
    next k

    FineFile = k
    LZoom = 1

    mapX = mapX / 5
    mapY = mapY / 5
    print mapX
    print mapY

    originalX = mapX
    originalY = mapY
    scaleoriginal = 900000 / mapX
    scale(LZoom) = 900000 / mapX

    return

    ' #MGiu

    [lmbDown]

    lmbX = MouseX : lmbY = MouseY
    oldX = lmbX : oldY = lmbY
    #graph.gra, "rule xor"
    #graph.gra, "place "; lmbX; " "; lmbY

    [lmbMove]

    #graph.gra, "color black"
    #graph.gra, "place " ; lmbX; " "; lmbY;"; box "; oldX; " "; oldY
    oldX = MouseX : oldY = lmbY + (oldX - lmbX) / 900 * 660
    #graph.gra, "place "; lmbX; " "; lmbY; "; box ";oldX; " "; oldY
    Move = 1

    wait

    [rmbDown]

    rmbX=MouseX: rmbY=MouseY
    oldX=MouseX: oldY=MouseY
    #graph.gra, "rule xor"
    'cursor CROSSHAIR
    call SetCursor CursorHandle

    wait

    [rmbUp]

    offX = offX + MouseX - rmbX
    offY = offY + MouseY - rmbY
    #graph.gra, "rule over"
    goto [Graph.ZoomEsteso]

    wait

    [rmbMove]

    #graph.gra, "line ";rmbX;" ";rmbY;" ";oldX;" ";oldY
    oldX=MouseX: oldY=MouseY
    #graph.gra, "line ";rmbX;" ";rmbY;" ";oldX;" ";oldY
    call SetCursor CursorHandle

    wait

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

    ' #MSu

    [lmbUp]

    LZoom = LZoom + 1
    lmbXX = MouseX : lmbYY = MouseY

    if MouseX = 0 or MouseY = 0 then wait

    lmbCX = lmbX + (lmbXX - lmbX) / 2
    lmbCY = lmbY + (lmbYY - lmbY) / 2
    distX = lmbCX - cx
    distY = lmbCY - cy
    mapX = mapX + distX / scale
    mapY = mapY - distY / scale
    scale = 900 * scale / (lmbXX - lmbX)
    scale(LZoom) = scale
    #graph.gra, "rule over"

    Move = 0

    gosub [ZoomElastico]
    mapX(LZoom) = mapX
    mapY(LZoom) = mapY
    distX(LZoom) = distX
    distY(LZoom) = distY
    #graph.gra, "flush"

    wait

    [GestZoomErr]

    #graph.test, Err$; " - "; scale(LZoom)

    wait

    [ZoomElastico]

    TipoErrore$ = "ZoomElastico"
    TipoZoom$ = "Elastico"

    if Provenienza$ = "Mouse" then
        scale = scale(LZoom)
    else
        scale = ZoomScala(NumZoom)
    end if

    [ZoomElastico_Uno]

    #graph.gra, "cls"
    #graph.gra, "place 2 2"
    #graph.gra, "color red"
    #graph.gra, "box 897 657"
    #graph.gra, "line 0 330 900 330"    ' centro orizzontale
    #graph.gra, "line 450 0 450 660"    ' centro verticale

    Ltxt$ = "6" : Htxt$ = "12"
    #graph.gra, "font courier_new "; val(Ltxt$); " "; val(Htxt$); " bold"

    for i = 1 to 5

        COx = int(cx + (val(mid$(Riga$(i), 22, 14)) - mapX) * scale)
        COy = int(660 - (cy + (val(mid$(Riga$(i), 37, 14)) - mapY) * scale) + 30 * scale)
        nome$(i) = trim$(left$(Riga$(i), 20)) : NomePunto$ = nome$(i)

        COx(i) = COx : COy(i) = COy

        #graph.gra,  "color red"
        #graph.gra,  "place "; COx; " "; COy
        #graph.gra,  "circle 3"
        #graph.gra,  "color black"
        #graph.gra,  "place "; COx + 1; " "; COy - 5
        #graph.gra,  "down"
        #graph.gra,  "\"; trim$(left$(Riga$(i), 20))

    next i

    TuttiPunti = i

    return

 

User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: Graphics pan
« Reply #4 on: Dec 2nd, 2017, 04:00am »

No solutions just yet. Just one or two questions.

The task is to plot coordinated points on a map, the scale of this map changes. If the user selects a boxed area of the map this should become full screen. Yes?No?

So we are not PANNING, we are ZOOMING in (or out) on a specific area of the map. PANNING would move the whole map without altering scale. Are we doing that to? Yes?No?

We have some super complex code to manage the mouse clicks. I fear that this is because we answered your previous questions without understanding the task.

I don't think we need a TIMER statement as this adds complexity. Neither do we need to know what window or control the mouse is over, we only need to react to mouse action in the graphics window. Liberty does this natively and simply.

For me I think it would help if you had a go at rewriting the code using Tsh73's model. That would put all of us in a better position to help.
User IP Logged

Angelo2449
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Graphics pan
« Reply #5 on: Dec 2nd, 2017, 07:28am »

Hy Gender,
The function must be 'panning', my code rewrite the list as an extended zoom but it is not correct.
It must work like the Autocad 'Pan', the 'Hand' symbol moves the points on the screen.
I repeat that, in the full version of the program (which I can not fully attach to its length), the zoom worked perfectly before inserting the subroutines for the 'Pan'.
Thank you.
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1732
xx Re: Graphics pan
« Reply #6 on: Dec 2nd, 2017, 08:39am »

Your
Code:
[rmbUp] 
code
sets variables
offX, offY
but it never ever uses them.
Might be pan does not work because of this?
User IP Logged

damned Dog in the Manger
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1732
xx Re: Graphics pan
« Reply #7 on: Dec 2nd, 2017, 3:06pm »

So most straightforward way to actually pan is to change two lines in
Code:
    [ZoomElastico_Uno]
 
:
Code:
        #graph.gra,  "place "; COx+offX; " "; COy+offY
'...
        #graph.gra,  "place "; COx+offX + 1; " "; COy+offY - 5
 
« Last Edit: Dec 2nd, 2017, 3:07pm by tsh73 » User IP Logged

damned Dog in the Manger
Angelo2449
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Graphics pan
« Reply #8 on: Dec 3rd, 2017, 2:04pm »

Hi Guys,
I had guessed the problem and I wrote a routine using coordinate offsets and it seems to work very well.
Now I have another problem, after loading the drawing and doing the 'flush', if I open a window above the graphic area (for example an alert message), the graphics disappear, as if I had not done the 'flush'.
Is there anything I can do?
Thank you.
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1732
xx Re: Graphics pan
« Reply #9 on: Dec 3rd, 2017, 2:38pm »

Quote:
if I open a window above the graphic area (for example an alert message), the graphics disappear, as if I had not done the 'flush'.

1) "disappearing graphics" problem solved with FLUSH
2) >> if I open a window above the graphic area (for example an alert message), the graphics disappear,
so make a FLUSH just before opening window above
3) FLUSH takes memory. If your program starts misbehave because of this, read these two articles
SegmentsAndFlushing
How to FLUSH Without Running Out of Resources
User IP Logged

damned Dog in the Manger
Angelo2449
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Graphics pan
« Reply #10 on: Dec 4th, 2017, 04:40am »

Thanks tsh73,
another small problem :
I wrote a program that emulates the PC keyboard but I can not write the space.
Code:
textbox #nuovo.nuovop, 200, 15, 280, 25
......
[Nuovo.Spazio]
#nuovo.nuovop, "!contents? Char$"
#nuovo.nuovop, trim$(Char$) + " "
wait 

space does not even appear with chr$(32)
Thank you
« Last Edit: Dec 4th, 2017, 04:42am 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 #11 on: Dec 4th, 2017, 04:58am »

You can read and write spaces to textboxes. Perhaps your keyboard reading routine is the source of the problem?

Code:
nomainwin
textbox #t.txt1, 20, 40, 260, 25
textbox #t.txt2, 20, 70, 260, 25
button #t.default, "OK", [respond], LR, 5, 0
WindowWidth = 350 : WindowHeight = 190
open "Simple text box use" for dialog as #t
#t "trapclose [quit]"

'clear the textbox and set the focus on it
#t.txt1 ""
#t.txt1 "!setfocus"
wait

[respond]
'get the contents once ok or enter has been clicked
#t.txt1 "!contents? response$"
#t.txt2 response$
wait

[quit]
close #t
end
 
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1732
xx Re: Graphics pan
« Reply #12 on: Dec 4th, 2017, 05:58am »

Works OK for me
Code:
    nomainwin

    WindowWidth = 352
    WindowHeight = 390

    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    textbox #main.textbox1, 14, 16, 100, 25
    button #main.button2, "add space", [button2Click], UL, 198, 16, 122, 25
    button #main.button3, "read", [button3Click], UL, 198, 51, 122, 25
    texteditor #main.texteditor5, 14, 56, 184, 275
    menu #main, "Edit"    '<--- Texteditor Menu can be moved but not removed.

    open "untitled" for window as #main
    print #main, "trapclose [quit.main]"

    print #main, "font ms_sans_serif 10"

    wait

[quit.main]
    Close #main
    END


[button2Click]    'Perform action for the button named 'button2'
    'Insert your own code here
    #main.textbox1 "!contents? txt$"
    txt$ = txt$+" "
    #main.textbox1 txt$
    wait


[button3Click]    'Perform action for the button named 'button3'
    'Insert your own code here
    #main.textbox1 "!contents? txt$"
    #main.texteditor5 ">";txt$;"<"
    wait
 
User IP Logged

damned Dog in the Manger
Angelo2449
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Graphics pan
« Reply #13 on: Dec 22nd, 2017, 01:27am »

Hi tsh73,
I would like to modify your 'Pan' program in this way :
the 'Hand' symbol should not be associated with the right mouse button press but at the press of a button.
my program intercepts the type of cursor like this :
Code:
    [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

    end select

    wait
 

I would like TypeCursor$ = 'hand' and make the 'Hand' symbol appear ready for the 'Pan'
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 #14 on: Dec 22nd, 2017, 04:06am »

If I am understanding what you want then you just need to line up the cursor changes with the button down and button up handlers.

I also changed the pan to pan the drawing as it goes, the zoom works as before.

So the hand appears whenever a left or right button is down and stays till the button is released. Is that what you wanted?

Code:
'zoom and pan
'by tsh73, july 2013
'1. draw smth, denending of offset (offX, offY) and scale
'2. scale and pan, programmatically
'3.     rmb pans
'4.     lmb zooms (left to right zoom in; righ to left zoom out (try it))
'5. F5 resets zoom/pan to original one

nomainwin
open "test zoom & pan" for graphics_nsb_nf as #gr
#gr "trapclose [quit]"
#gr "down"
#gr "home; posxy cx cy"

#gr "when rightButtonDown [rmbDown]"
#gr "when rightButtonUp [rmbUp]"
#gr "when rightButtonMove [rmbMove]"

#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

'-------------------------------
[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]
    call SetCursor CursorHandle
    lmbX=MouseX: lmbY=MouseY
    oldX=MouseX: oldY=MouseY
    #gr "rule xor"
    wait

[lmbUp]
    cursor NORMAL
    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]
    wait

[lmbMove]
    #gr "place ";lmbX;" ";lmbY;"; box ";oldX;" ";oldY
    oldX=MouseX: oldY=MouseY
    #gr "place ";lmbX;" ";lmbY;"; box ";oldX;" ";oldY
    wait

'--------------------------------------
[rmbDown]
    call SetCursor CursorHandle
    rmbX=MouseX: rmbY=MouseY
    oldX=MouseX: oldY=MouseY
    #gr "rule xor"
    wait

[rmbUp]
    #gr "rule over"
    gosub [drawStuff]
    cursor NORMAL
    wait

[rmbMove]
    offX=offX+MouseX-oldX
    offY=offY+MouseY-oldY
    '#gr "line ";rmbX;" ";rmbY;" ";oldX;" ";oldY
    oldX=MouseX: oldY=MouseY
    gosub [drawStuff]
    '#gr "line ";rmbX;" ";rmbY;" ";oldX;" ";oldY
    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



 
« Last Edit: Dec 22nd, 2017, 04:09am 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