• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Group rotation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Group rotation


  • Subject: Re: Group rotation
  • From: Graham Cox <email@hidden>
  • Date: Tue, 29 Apr 2008 16:34:21 +1000

Implementing grouping that really works is quite hard.

What about when groups are nested? This can go on indefinitely, so you need a mechanism that can take account of any number of nested groups. Since transforms from any level can be appended or prepended, this is the way to go I believe - each object has a transform that defines its position and rotation and size, and so does each group. When a shape is drawn it needs to apply all of the transforms for the whole group hierarchy that contains it. Also, when an object is grouped, it needs to have its coordinates translated so that they are relative to the group, (the series of transforms then compensates for this when the group draws its contents).

When you ungroup, what about if you have now rotated and resized and some of the contained groups are also rotated and resized? The effect is that paths can get skewed, which is valid, but you need to preserve all of that when you ungroup. There's a lot more to it than meets the eye. Getting it right is hard. ;-)

I don't think your code snippet gives enough information - the effect you're seeing is because of several transforms that don't match in some way, at least as far as I can tell.

One other thing - don't use NSUnionRect, it has really poor behaviour for grouping. Consider what it will do if you try and group two orthogonal lines separated by some distance, where their bounds have no height or width...


If you're interested, my DrawKit project implements grouping as outlined above, and as far as I can tell works as I would expect with any degree of nesting. You might get some useful things to go on from it (or just use it and save reinventing that particular wheel yet again):


http://apptree.net/drawkitmain.htm


hth,

G.



On 29 Apr 2008, at 3:25 pm, Ghufran Ahamad wrote:
Hi All,



I want to do group rotation for various objects. Objects are getting rotate
correctly on their center but when I group them the rotated object has got
shift. Note: In case of group only rotated object has got shift. Below is
the code snippet. Let me know I doing correct or not.




-(NSRect)drawingBoundForGroup:(int)in_Group

{

  NSRect rect = NSZeroRect;

  NSArray *objTlGraphic = [[self document] graphics];

  unsigned i,c = [objTlGraphic count];

  if(in_Group != 0)

{

    for(i = 0; i < c;i++)

   {

     if([[objTlGraphic objectAtIndex:i] GroupNO]==in_Group)

     {

       rect=NSUnionRect(rect,[[objTlGraphic objectAtIndex:i] bounds]);

       NSLog(@"Object Center Log Index= %d %d",rect,i);

      }

   }

  }

   return rect;

}



int Id_Group=[curGraphic GroupNO];

NSRect stRect=[curGraphic  drawingBoundForGroup:Id_Group];



NSAffineTransform* xform = [NSAffineTransform transform];

[currentContext saveGraphicsState];

[NSBezierPath clipRect:drawingBounds];

NSPoint center = NSMakePoint(NSMidX(stRect), NSMidY(stRect));

[xform translateXBy:center.x yBy:center.y];

[xform rotateByDegrees:[curGraphic GetAngle]];

[xform translateXBy:-center.x yBy:-center.y];

[xform concat];

[curGraphic drawInView:self isSelected:isSelected];

[currentContext restoreGraphicsState];

[self setNeedsDisplay:YES];





Thanks in advance,

Ghufran Ahmad

+91 - 9953130470

Skype ID: ghufran_khan81

AOL ID: gahmad81



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Group rotation (From: "Ghufran Ahamad" <email@hidden>)

  • Prev by Date: Re: How to adopt a superclass's protocol?
  • Next by Date: Re: Deleting preference file from within the application
  • Previous by thread: Group rotation
  • Next by thread: How can i connect to database?
  • Index(es):
    • Date
    • Thread