Grid snap to

Anyone know how if you can create a grid on a panel so that if the user clicks somewhere on it, and a drawing will appear there, that you can make it snap to the nearest gridline? The only snapTo I can find anything about is for sliders. Thanks

All you need is a little math...
int x = evt.getX(); // mouse click x
int y = evt.getY();
int gridx = 10; // spacing of grid lines
int gridy = 10;
int a = x / gridx;
int b = y / gridy;
if (x % gridx > gridx / 2) a++;
if (y % gridy > gridy / 2) b++;
x = a * gridx;
y = b * gridy;

Similar Messages

  • Illustrator cc 2014 grid snap problem

    Since Updating to the whole cc2014 suite last week, grid snapping in Illustrator has been terrible. Literally Nothing really snaps to the grid.
    Does anyone share this problem? Anyone has a solution to this?
    And Yes, i've turned off 'align to pixel grid'.
    I'm working on a mac with OSX 10.9.3 running.
    Thanks in advance!

    I'm having the same exact issue. Before I upgraded to Illustrator CC 2014 I was using Illustrator CS6 and resizing a rectangle that's *off* the pixel grid would snap it to the pixel grid correctly. The snapping to pixel grid is the main reason I use Illustrator for web UI design. There were some bugs in CS6, like if the artboard was not snapped to the pixel grid then all the elements on the page would be off the pixel grid at the same distance that the artboard was off. That was an easy fix - just realign the artboard to the pixel grid and all the rectangle objects would snap to the grid when resized. But with Illustrator CC 2014 nothing snaps to the pixel grid.
    HOW TO REPRODUCE:
    Create a new document.
    Go to Pixel Preview.
    Zoom in to pixel level.
    Drag a rectangle on the screen.
    As you can see - IT IS snapped to the pixel grid (it happens only on creation).
    Grab the free transform anchor point and drag it up and to the right.
    As you can see - IT IS NOT snapped to the pixel grid.
    Try to drag the corner to free transform it to snap to the pixel grid. It doesn't work.
    Try to snap it to the pixel grid - it doesn't snap.
    Try to snap it to the pixel grid - it doesn't snap.
    Profit? No.
    SCREENCAST:
    http://quick.as/y0rwhymv
    GIF:
    As you can see it's very hard to snap to pixel. And even when it looks like it snaps, it actually is not on the pixel grid line.
    cc2014_bug.gif
    IMAGES:
    Dragging new rectangle:
    1create.png
    Resize it using free transform - gets off the pixel grid.
    2drag.png
    Continue to try to snap it back to the pixel grid using the transform tool, but still doesn't work:
    3drag.png
    Rinse and repeat. Still really bad. Snapping to pixel doesn't work anymore!
    4drag-but-nothing.png
    As you can see there is no way of snapping a rectangle back to the pixel grid!! Here are my settings:
    5settings.png
    Illustrator team - PLEASE FIX THIS BUG! I love using Illustrator for web design and UI mockups, but this bug makes it almost useless. There's no way to create pixel perfect designs with this bug. I hope all the information I provided above helps pinpoint the bug. Thanks!

  • Points not obeying grid-snapping, or any snapping-rules where merged.

    This is my situation.
    1. Draw a line... It snaps to grid perfectly.
    2. Draw another line... It snaps to grid perfectly.
    3. Merge line1 with line 2 at one end... (It seems snapped to grid, but shows a "+" protruding connection so I zoom, and it is fine close-up...
    4. Move the point to a new grid-snap point to see if it draws better zoomed-out 100% without showing overlapping on this single point... However, now it snaps everywhere except onto the grid. Like all around the point, just not on the point. Now it will no longer snap to any grid-point or other point, always being "off". (This does not resolve by adding a new point and breaking the line. The whole line now refuses to snap to any actual point. It is always offset by an unsteady ammount/percent. Sometimes it is real close, sometimes it is about 50% between all snap-points.)
    Resolution = None... Never move points once set, and naver intersect a third line to a point, and never intersect one line with another.
    Results... everything looks misaligned, slightly off-angle, can not make any true aligned items, unless I use line-thickness 3, to hide the off-angles from misaligned points.

    This is what is happening, at a programming level...
    Once a point is "merged/union", at the intersection. That point it is now located, becomes an offset to the actual "Grid". However, (for some reason only on intersected lines), the offset interferes with snapping. It will SNAP, at your grid-distance, at a slight offset, never on the actual intersection. It starts to "snap", as if the grid is offset, staying on the lines, but invisible lines that are not the grid.
    The only resolution to get the line to go back to the grid, is to use the arrow-keys to bump it the 5.0-0.1 pixels it is off. (In my case with a 10px grid.)
    However, moving the point again, causes it to start snapping to the phantom-invisible grid-lines, and it will have to be nudged with the arrow-keys to push it back to an actual grid location.
    Also, however... This does nothing to resolve the zoomed-out view which shows top-left intersections displaying as a "+" when they are truly intersected. Also noticing that the lower-right lines alwys seem "open", not connected. (Drawing a standard rectangle with a line-width of 1px shows the "open" bottom corner.)
    Somewhere in code, there is an issue with drawing. Zoomed-out it is drawing "top-left" of pixel-locations, but zoomed-in, it is drawing from the "center" of the pixels. Thus, this akward offset, which is always top-left offset, and causing what seems to be "holes" on the bottom-right of intersections.
    (Might be a direct-x thing, becuse MS draws/calculates from top-left. GL draws from center. Most software draws bottom-right. Due to copyrighted "formulas" for drawing.)
    I suspect antialias may also be interfering with the drawings, as it completely messes-up curved-rectangles, making them look bowed-out not curved on the corners. Again, someone is using a GL formula for a MS translation, or software-formula for MS translation, not using the off-set adjustment to match the middle-draw to the top-left draw code.

  • Grid Snapping Isn't Working

    So I have Illustrator CC at work and for the life of me, I cant get grid snapping to work, I turn off all other snapping and guides and leave on only "Show Grid" and "Snap to Grid."
    Pleas help, this is exhausting, I can't precisely measure anything.

    Please tell us step by step what exactly you're doing, what exactly you expect and what exactly Illustrator is doing.
    Screenshots help.

  • Enhancement request: Grid snap without grid dots showing

    It would be helpful to turn on the grid snap without actually showing the grid dots, allowing diagram objects to align properly without the constant distraction of the dots. Thanks.

    created an ER for that
    Philip

  • Grid Snap in UIR Edit Window (Newbie)

    Sorry for such a seemingly dumb question... Experienced in LabView,
    learning CVI.
    I can't figure out how to turn off the "grid snap" in the UIR editor. When
    I move controls with the arrow keys, they jump about a quarter inch at a
    time. I'd like them to move in single pixel increments for fine alignment
    (the "Alignment..." options are not suitable for what I need to do). I've
    looked in the user manual and in the online help and either I can't read or
    it's not there.
    How do I turn off the grid snap in the UIR editor?
    Thanks in advance!
    Justin Goeres

    Dear Justin,
    In the UIR editor objects move ten pixels at a time if you select and move
    them by arrow keys.
    You can move one pixel at a time by using Shift + arrow keys.
    Regards
    Roberto

  • Grid snapping in xy graph

    hi
     i want to snap the grid in xy graph
    i am plotting graph using mouse down event
    now i want to snap grid on mouse down(means if i click any where the point will be entered on nearest grid)
    regards
    mazhar
    Solved!
    Go to Solution.

    thanx smercurio
    may be i have not describe my problem clearly.
    let me explain first  the link of my post you reffered  the main problems of that post are two constant because when i change size of my graph i loose alignment of the cursor and entered position. after some time and debuging i fix that and make it generic(mean if some one change graph size the alignment will not take effect) see the property which replace that constant.
    Message Edited by mazhar.ali on 02-18-2009 03:54 AM
    Message Edited by mazhar.ali on 02-18-2009 03:56 AM
    Message Edited by mazhar.ali on 02-18-2009 03:59 AM
    Attachments:
    cursor alignment.JPG ‏40 KB

  • Guide and grid snapping going crazy - help!

    I'm having real problems when snapping bezier paths to guides and grids. As you can see in the video, it seems to snap to SOMETHING, but not the grid or guide, it's driving me crazy. Even more annoying, sometimes it works perfectly. Anyone know what the heck is going on? I have turned off the "new" snapping feature and just checked "snap to guides" in the VIEW menu.
    After Effects CC 2014 (latest)
    OSX 10.9.5
    Mac Pro 2013 (12 core)
    Please help, I'm on a huge project that is pure shape layers, and not being able to snap to guides is a nightmare.
    Thanks!
    Rory.

    Sorry, I cannot replicate your issue. I've tried having 8 shapes and masks and switching the pixel aspect ratio conversion on and off and switching the grid on and off and switching guides on and off and switching all of the snap functions in and out in various combinations.
    A very long time ago, when grids were new, I had changed the color of the grid to white. when I started working on a white layer later in the project I was freaked out that the grid had malfunctioned but it had simply been made invisible by the user. I spent hours on the After Effects AOL forum before I figured it out. This is not related to your problem, clearly, but these things are often less weird than they seem.

  • Snap to Grid problem in Illustrator CS4

    I found a weird problem with the "snap to grid" feature in Illustrator CS4 running on MAC OS X Snow Leopard.
    To reproduce it, on my system, it is enough to:
    1. Make sure to have the Snap To Grid enabled (View->Snap to grid)
    2. Draw a rectangle (see BEGIN.JPG)
    3. Select the Direct Selection Tool
    4. Try to increase the width of the rectangle, by dragging one side of the shape (not a single point, but the whole side in a move).
    5. On my system, I see that Illustrator behaves in a wrong way; it is like Illustrator is snapping to a not aligned grid, and the rectangle begins to be distorted (see END.JPG).
    If I try to move a on point at a time, instead of moving one complete side, everything seems to works fine.

    Win Vista 64-bit AI CS4.  Can't seem to reproduce your issue.  I drag on the right side of a rectangle with grid snap on and show grid and it snaps exactly to the grid, not anywhere in between even if I start with a rectangle that was created "not-on-grid".  When it snaps it snaps to distances equal to the grid spacing, though it won't snap to the grid itself.  It's as if it snaps to its own internal grid.  I guess that's a problem in and of itself since once you have grid snapping turned on no matter where the original rectangle was you would like it to snap to the grid lines.
    EDIT:  Now I see how you created the problem--with direct selection (white arrow) as opposed to full selection with bounding box (black arrow).  Black arrow selection snaps to its internal grid while white arrow snaps to rhombus-like snapping.  I guess it's designed to be used with individual points and not with edges.  (AI doesn't have edge-snapping).

  • Garageband, snap to grid and editing with precision

    I'm *this* close to buying an iPad mini. The main reason is that I run a podcast and like the idea of editing it during my daily commute. I usually create the podcast with Garageband on my Mac, so was thinking Garageband on iPad would be the obvious app.
    BUT when I tested it out today on a store iPad I could not figure out a way to turn of "snap to grid" when editing audio, which means that it's impossible to make precise edits to speech - you can't just cut and join wherever you like, only at 1/16-beat (or whatever) intervals.
    I'm hoping that someone here who uses their iPad for audio editing will either tell me that 1.) I'm wrong, and you can in fact turn of the grid-snapping and edit audio with precision, or 2.) there's a different app for iPad that can edit audio with precision, ideally a multitrack editor. Double bonus points if the finished multitrack can be fine-tuned on a Mac later.
    Anyone?

    I wasn't able to find clean up by right clicking, but on the finder menu in view, clean up is present and it works. Problem fixed.
    Thanks a lot galantesteve!

  • Another snapping problem

    The illustrator in our studio is having an issue with snapping...
    Snap is off everywhere:
    - snap to grid
    - snap to objects
    - snap to point
    - smart guides
    - in the 3d grid "snap to grid"
    - in the document template "align new objects to grid"
    - in the transformation panel "align to pixel grid"
    Yet sometimes at high zoom levels when moving nodes/curve handles there is some sort of snapping going on. At first we thought it was a problem with the wacom tablet, but the problem happens also with the mouse.
    Is there some other snap setting I'm forgetting?
    Is there a known bug?
    We're using version illustrator CS5 15.0.2
    TIA

    Where are things snapping to? Artboad edges or just random places in the center of the artboard?
    There is an everpresent snap to artboard edges that can not be turned off, ever. You simply must not work at artboard edges to avoid that snap.

  • Snap to Point problems

    Illustrator CS6:
    I feel a bit of a fraud even asking this, as it seems so basic – but I am having trouble "snapping" one object to another.
    I can get objects to snap to ruler guides fine, but not other objects.
    Can anyone help?

    There are three snapping options in the View menu: Smart Guides, Snap to Grid, and Snap to Point.
    When the Smart Guides are on with the default options in the preferences, you can snap align the bounding box of the object being dragged to the bounding boxes of other objects by dragging the object from any point on its fill or path.  Smart Guides will show the alignment lines and also intersection lines when two sides of the bounding boxes of the dragged and target objects coincide and also when the center points coincide.
    If you hold the Ctrl key down while dragging, the Smart Guides will also snap the point under the cursor which doesn't have to be an anchor point but any point on the object's fill or path to a path or anchor point of another object and will display a label indicating if it is the anchor point or path being snapped to. If you are not dragging a whole object but  segment/s you don't have to hold the Ctrl key - it will snap to paths and points.
    Wen Snap to Grid is on, the Smart Guides if on are automatically turned off. When dragging whole objects, Snap to Grid snaps first straight lines if any to the nearest line on the gird and if there are no straight lines it snaps the nearest point of the object to the nearest point on the grid. There is no visual feedback with labels or cursor changes for eventual snapping because it always snaps to the nearest intersection of the grid.
    Snap to Point can be on when one of the previous two options is on. It will snap the point under the cursor which like the Smart Guides could be also any point on the object's fill, to the anchor points of other objects and it will indicate this by changing the cursor to white.
    Snap to Point compliments the Smart Guides by making the cursor white when snapping to a point and you don't have to hold Ctrl when dragging whole objects to snap to a point.
    With Snap to Grid on, Snap to Point has a priority and the point under the cursor will snap to a point of another object instead to the grid.
    Also have in mind that another level of snapping is added by using Snap to Pixel Grid feature available when creating a new document and from the Transform panel. It deals with anti-aliasing, it is object based, and will have a priority over all of the other snapping options

  • Illustratro CS 5.1 snap issues

    Out of the blue now, Illustrator is driving me nuts.
    I am trying to create a rectangle in an existing Illustrator drawing and rotate it into place.
    I draw the rectangle and then click on the "election" arrow to rotate the rectangle to the angle I need. However, as soon as I click on the selection arrow, a bounding box that includes the rectangle and a significant area outside the rectangle is selected. This causes a problem because the rectangle is not the size I need and when I try to rotate and strectch it to fit the area I want, the handles encompass and area much larger and rather than being able to just drag the handles to the size I want, I must play around with them to try to get them to fit.
    I've searched a number of different forums and this appears to be an on-going problem. A number of people said to turn offf snap to grid, snap top point, smart guides, etc. All of these are turned off, but Illustrator continually insists on drawing the recatangle at the initial size I want, but then encompassing a much larger area outside the actual rectangle. Someon suggested going to the Transform menu and turning off an element there, but I wasn't able to find that specific element (perhaps a newer of older version of Illustrator). Someone else said to else suggested going to the align menu and making a change there. Again, my align menu doesn't provide the option that was suggested. I have tried everything I can think of and am getting incredibly irritated.
    Here is a screen shot of what I'm talking about -
    When I draw the rectangle it looks the way I expected it to. However, as soon as I pcik the selection arrow, I get the huge bounding box that has no  correlation to the rectanlge I drew.
    I even treid drawing the rectangle off the artboard and moving it into place, but the same thing happens, wherever I draw the rectangle.
    I had preivously been using Illustrator CS3 and NEVER had this issue. Only in Illustrator CS 5.1.
    I'm ready to dump CS 5.1 and go back to CS 3 - since it works as expected.
    Any help/suggestions would be greatly appreciated!

    This drawing is from an AutoCad file so there are a lot of layers. I did try to create a blank layer and draw the rectangle on it, but same result.
    That said, the vast majority of my files are from AutoCad and I've never had this issue previously, i.e. the past 10-12 years.

  • Creating a custom panel for Snapping....??

    I'm trying to create a custom panel in Flash CS3 that will
    allow me to turn snapping on and off (i.e. 'Snap Align', 'Snap to
    Grid', 'Snap to Guides', etc.) by just checking or unchecking some
    checkboxes, but I can't find any JSFL code that will change the
    snapping options. When I try changing the snapping in a document,
    it doesn't list it in the history panel. Is there any way to do
    this? PLEASE! Someone help me!

    Thanks for the link, but it is broken for me. I think I see where you are sending me. Only one
    problem....I am an artist...not a programmer. So I guess what I am asking for is a development tool that would be easy for this type of thing. Beyond the kid friendly interface it would be nice to be able to skin your art specific interface that you make. I mean really all it is is making fancy icons in photoshop and attaching PS actions or commands to the icons. Looks like the tools that are out there already will do this for me, they are just ugly right now. If we could skin these then it would be a little more appealing for the target audience that you are making the UI for.
    Thansk again for the help!
    NickZ.

  • Grid origin, slipping and other grid tips?

    I'd love to hear some tips about working with Grid Snapping. (Using CS6 here)
    The two major things I'm confused about:
    1) How do I set the origin point for the grid?
    (Doesn't seem related to the ruler zero origin tool or the artboard tool. Unless I'm being very dense, it's not obvious or intuitive.)
    2) Is it me or do items aligned with the grid somehow get unaligned when moving?
    (I turn View Grid on and my objects are aligned perfectly on the grid in Wireframe mode. But after moving things around several times, I can't get my objects to snap back to their original position. Pixel Grid turned off & zero sub-divisions, btw.)

    Hi Top Ten,
    You can't get them back once they go. You now need to edit the css code manually to do the same thing.
    For instance if you want divs to sit beside each other you put this in the css for that div:
    clear: none;
    This css means that div will allow other divs to sit beside it.
    Then put in a width in percentages. For example if you have three divs that need to sit beside each other put:
    width: 33%;
    in each of them. Or maybe:
    width: 31%;
    margin-right: 2%;
    Fortunately in DWCC it is now robust enough for you to do those code changes by hand. My original question in this thread was posed when DW CC fluid grid had just come out and crashed easily. A year later all is well, so you can do those changes in the css code without problems now.
    Regards,
    Mary

Maybe you are looking for

  • ACS 5.3 Backup fails

    ACS 5.3 on VM- backup fails all the time. I opened several tickets with Cisco, but still no luck. Here is one of the log message I got during the backup. Maybe someone can point out what the issue is. debugd[2933]: [31965]: config:kron: cs_api.c[1142

  • Query related to Max of Data

    I'm working with Database 10g.Scenario as foll. Table T1 - Id,Action,actiondt.data as follows ID,action,actiondt 1,A,11-jan-09 1,B,12-jan-09 1,C,13-jan-09 Query should give me result as foll. ID,Action,Max(action) 1, A, 13-jan-09 1, B, 13-jan-09 1, C

  • Import from a catalog

    When i try to import from another catalog (from my laptop), the finder window opens and then shuts down instantly.  How do I transfer photos saved as an LRcat file?

  • How to handle producer not registered/down using Interceptor in wsrp

    Hi , I have to handle a Scenario in wsrp where if producer is down or not responding then i have to show a error message on consumer .For that i want to use a Interceptor . can you provide me some step for proceeding. thanks in advance

  • Need help with sqlldr

    hi everybody, i tried to load data from a text file to an existing table, using sql loader and the following control file LOAD DATA INFILE 'ginos.txt' INTO TABLE DEMO.GINOS1 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (CODE, NAME) but it didn