Board Logo
« Draw with object snap »

Welcome Guest. Please Login or Register.
Jan 18th, 2018, 3:55pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Draw with object snap  (Read 121 times)
Angelo2449
Member in Training
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 58
xx Draw with object snap
« Thread started on: Nov 6th, 2017, 11:21pm »

Hi Guys,
in autocad wi can draw with the help of object snaps ie the ability to hook an object (line, circle ...) through its features (end, center, ...).
Is there a possibility to do this in the> graphicbox <?
Has anyone already addressed this topic?
Thank you
User IP Logged

Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Draw with object snap
« Reply #1 on: Nov 7th, 2017, 02:08am »

If you go to the LBPE you will find Tom Nallys wireframe tutorials. There are some snap to grid examples I have seen. Look at the free form code as well, that has snap to grid.
User IP Logged

tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3636
xx Re: Draw with object snap
« Reply #2 on: Nov 7th, 2017, 04:54am »

I remember coding such stuff (making ends of line sticky / line editable)
Probably helping with someone else's program here on forums.

But I could not find a thing sad

Here' one snap-to grid example I found instead.
Snap to Grid Feature
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3636
xx Re: Draw with object snap
« Reply #3 on: Nov 7th, 2017, 07:38am »

I found that thread
it is LB::Drawing a line then editing length & position

I removed (commented out) all parts JB balked to - may be broke something in process
As for now, you draw bunch of lines
then selecting end point allows to move it.
Code:
nomainwin
    WindowWidth=500
    WindowHeight=500
    dim linestart(2,10),linemid(2,10),lineend(2,10)
    linecount=0
    graphicbox #1.graph,5,5,480,460
    open "Liberty Draw" for graphics_nsb_nf as #1
    #1,"trapclose [quit]"
    #1,"fill lightgray;flush"
    #1.graph,"down;color black;backcolor black"
    #1.graph,"when leftButtonDown [startLine]"
    #1.graph,"when leftButtonMove [trackLine]"
    #1.graph,"when leftButtonUp [finishLine]"
    'h=hwnd(#1.graph)
   'struct point,x as ulong,y as ulong
    wait

[startLine]
    startX=MouseX:startY=MouseY
    for a=1 to 10
        if (startX>linestart(1,a)-4) and (startX<linestart(1,a)+4) and (startY>linestart(2,a)-4) and (startY<linestart(2,a)+4) then
            startX=lineend(1,a):startY=lineend(2,a)
            oMouseX=linestart(1,a):oMouseY=linestart(2,a)
            'point.x.struct=oMouseX:point.y.struct=oMouseY
            gosub[mousesub]
            exit for
        end if
        if (startX>lineend(1,a)-4) and (startX<lineend(1,a)+4) and (startY>lineend(2,a)-4) and (startY<lineend(2,a)+4) then
            startX=linestart(1,a):startY=linestart(2,a)
            oMouseX=lineend(1,a):oMouseY=lineend(2,a)
            'point.x.struct=oMouseX:point.y.struct=oMouseY
            gosub[mousesub]
            exit for
        end if
        if (startX>linemid(1,a)-4) and (startX<linemid(1,a)+4) and (startY>linemid(2,a)-4) and (startY<linemid(2,a)+4) then
            startX=linestart(1,a):startY=linestart(2,a)
            oMouseX=lineend(1,a):oMouseY=lineend(2,a)
            'point.x.struct=int((startX+oMouseX)/2):point.y.struct=int((startY+oMouseY)/2)
            gosub[mousesub]
            exit for
        end if
    next a
    if existingline=1 then
        existingline=0
        goto[trackLine]
    end if
    linecount=linecount+1
    currentline=linecount
    if linecount>10 then notice "No More Lines!":wait
    oMouseX=startX:oMouseY=startY
    linestart(1,currentline)=startX:linestart(2,durrentline)=startY
    #1.graph,"rule over;place ";startX-3;" ";startY-3;";boxfilled ";startX+3;" ";startY+3
    #1.graph,"place ";int((startX+oMouseX)/2)-3;" ";int((startY+oMouseY)/2)-3;";boxfilled ";int((startX+oMouseX)/2)+3;" ";int((startY+oMouseY)/2)+3
    gosub[delseg]
    wait

[mousesub]
    'calldll #user32,"ClientToScreen",h as ulong,point as struct,r as ulong
    'clientX=point.x.struct:clientY=point.y.struct
    'calldll #user32,"SetCursorPos",clientX as ulong,clientY as long,r as boolean
    currentline=a
    existingline=1
    return

[trackLine]
    #1.graph,"rule over"
    #1.graph,"place ";startX-3;" ";startY-3;";boxfilled ";startX+3;" ";startY+3
    #1.graph,"rule xor"
    #1.graph,"place ";int((startX+oMouseX)/2)-3;" ";int((startY+oMouseY)/2)-3;";boxfilled ";int((startX+oMouseX)/2)+3;" ";int((startY+oMouseY)/2)+3
    #1.graph,"line ";startX;" ";startY;" ";oMouseX;" ";oMouseY
    #1.graph,"place ";oMouseX-3;" ";oMouseY-3;";boxfilled ";oMouseX+3;" ";oMouseY+3
    #1.graph,"place ";int((startX+MouseX)/2)-3;" ";int((startY+MouseY)/2)-3;";boxfilled ";int((startX+MouseX)/2)+3;" ";int((startY+MouseY)/2)+3
    #1.graph,"line ";startX;" ";startY;" ";MouseX;" ";MouseY
    #1.graph,"place ";MouseX-3;" ";MouseY-3;";boxfilled ";MouseX+3;" ";MouseY+3
    oMouseY=MouseY:oMouseX=MouseX
    gosub[delseg]
    wait

[finishLine]
    #1.graph,"rule over"
    #1.graph,"place ";MouseX-3;" ";MouseY-3;";boxfilled ";MouseX+3;" ";MouseY+3
    #1.graph,"place ";int((startX+oMouseX)/2)-3;" ";int((startY+oMouseY)/2)-3;";boxfilled ";int((startX+oMouseX)/2)+3;" ";int((startY+oMouseY)/2)+3
    linestart(1,currentline)=startX:linestart(2,currentline)=startY
    lineend(1,currentline)=oMouseX:lineend(2,currentline)=oMouseY
    linemid(1,currentline)=int((startX+oMouseX)/2):linemid(2,currentline)=int((startY+oMouseY)/2)
    gosub[delseg]
    #1.graph,"flush"
    wait

[delseg]
    #1.graph,"delsegment ";segnum-1
    #1.graph,"segment segnum"
    return

[quit]
    close #1
    end

 
« Last Edit: Nov 7th, 2017, 07:45am by tsh73 » User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

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