Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4571464
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:30:28+00:00 2026-05-21T19:30:28+00:00

With a little help from the last question regarding drawings in Cocoa i’ve implemented

  • 0

With a little help from the last question regarding drawings in Cocoa i’ve implemented some basic shapes, as well as dragging / resizing.

So, right now i’m trying to figure out, how to create a effect like in Keynote when a shape is resized and it automatically fits the size of another shape next to it and then “locks” the mouse for a bit of time.

The first attempt is to use a delay function, like

NSDate *future = [NSDate dateWithTimeIntervalSinceNow: 0.5 ];
[NSThread sleepUntilDate:future];

reacting on the desired event (e. g. shape width == height). But this results not in the desired effect, since the whole App freezes for the specified amount of time. In addition to that i think, that the user won’t recognize it as something saying “you’ve reached a special size”. Showing guidelines only at the event is not a solution, since the guidelines are shown as soon as the shape is selected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:30:29+00:00Added an answer on May 21, 2026 at 7:30 pm

    For snap to guides, I don’t think you actually want the cursor to stop. Just that the resizing should stop reacting to the cursor movements, within a small range of your target.

    The solution in that other question is more or less what you want, I think. Essentially, when you get close enough to the guide, you just change the point’s coordinates to those of the guide. So, building on the sample code I posted in your earlier question, this becomes your view’s mouseDragged:, and mouseUp:. You can leave the new checks out of mouseDragged: if you want the point to snap only on mouse up, a different but just as valid behavior.

    If you’re matching the edges of rectangles, you’ll probably find the Foundation Rect Functions, like NSMaxX and NSMaxY, useful.

    - (void)mouseDragged:(NSEvent *)event {
        if( !currMovingDot ) return;
        NSPoint spot = [self convertPoint:[event locationInWindow] 
                                 fromView:nil];
        spot.x = MAX(0, MIN(spot.x, self.bounds.size.width));
        spot.y = MAX(0, MIN(spot.y, self.bounds.size.height));
    
        // Look for Dots whose centerlines are close to
        // the current mouse position
        for( Dot * dot in dots ){
            if (dot == currMovingDot) {
                // Don't snap to myself! Leaving this out causes
                // "snap to grid" effect.
                continue;
            }
            // Where SNAP_DIST is #define'd somewhere
            // something under 10 seems to be a good value
            if( abs(spot.x - dot.position.x) <= SNAP_DIST ){
                spot.x = dot.position.x;
            }
            if( abs(spot.y - dot.position.y) <= SNAP_DIST ){
                spot.y = dot.position.y;
            }
        } 
    
    
        currMovingDot.position = spot;
        [self setNeedsDisplay:YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A little help from those who’ve used Timthumb before. http://themes.amplus.gambit.ph/wp-content/themes/amplus/functions/timthumb.php?src=http://themes.amplus.gambit.ph/wp-content/uploads/2011/02/12979795614923485443_a1967ff888_b.jpg&w=860&h=300&f=5,255,0,0,0 This image should be
I need a little help getting a tar file to download from a website.
I need a little help here: I get a file from an HTML upload
I would need little help here. I'm trying to get the git respository from
I've gotten help from others on this, but their replies were a little bit
need a little help with some sql. I am trying to get distinct frompersonid,
Hopefully my last question for a little while, although I can't be sure... I'm
Little help if you don't mind. Basically, I have 3 radio boxes and a
A little help here to figure out what error to run this piece of
I need a little help with an if statement in php. I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.