• 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: invertrect, any cocoa versions suggested?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: invertrect, any cocoa versions suggested?


  • Subject: Re: invertrect, any cocoa versions suggested?
  • From: Robert Dell <email@hidden>
  • Date: Mon, 23 Jan 2006 23:01:26 -0500

yes, i actually need to invert the color pixels within the rectangle.
if i had access to the actual pixels, i could invert them myself (although that wouldn't be the fastest way) one pixel at a time.

i also need to read and set individual pixels the same way getcpixel and setcpixel did.

Nothing i've searched on the web, apple's site, or the frameworks gives me any indication of what i'm trying to do.  the closest thing i can come up with is coreimage but i'm unsure on how it works and it can't invert the color data.

implementing an apple2 hi-res graphics screen is the main thrust for this program segment.  more specifically, the apple pascal's turtlegraphics routines in their entirety (other than textmode and grafmode procedures) for script programmers.

i've already implemented the following:

-(void)initGraphicWindow;
{
  graphicwindow = [[NSWindow alloc] initWithContentRect: NSMakeRect(graphicwindowlocation.x,  graphicwindowlocation.y, 280, 192) styleMask: (NSTitledWindowMask)  backing: NSBackingStoreBuffered defer: NO];
  [graphicwindow setTitle: @"Turtlegraphics"];
  [graphicwindow setViewsNeedDisplay: YES];
  [graphicwindow makeKeyAndOrderFront: self];
  [graphicwindow display];
  mycontext = [[NSGraphicsContext graphicsContextWithWindow: graphicwindow] retain];
  context = (CGContextRef)[mycontext graphicsPort];
  turtleAngle = 0;
  [self ViewPort: NSMakeRect(0, 0, 279, 191)];
  [self PenColor: YASSEWhite];
  [self PenUp];
  [self MoveTo: NSMakePoint(0, 0)];
  [self TurnTo: 0];
  [self Erase];
};


-(void)ViewPort: (NSRect)thePort; { NSRect myrect; myrect = thePort; if (myrect.origin.x < 0) { myrect.origin.x = 0; }; if (myrect.origin.y < 0) { myrect.origin.y = 0; }; if ((myrect.size.width + myrect.origin.x) > 279) { myrect.size.width = 280 - myrect.origin.x; }; if ((myrect.size.height + myrect.origin.y) > 191) { myrect.size.height = 192 - myrect.origin.y; }; turtleViewPort = myrect; myCGRect = NSRectToCGRect(myrect); };

-(void)FillScreen: (NSColor *)theColor;
{
  if (graphicwindowvisible)
    {
    //[self getContextForWindow];
    CGContextSetRGBFillColor(context, [theColor redComponent], [theColor greenComponent], [theColor blueComponent], 1);
    CGContextBeginPath(context);
    CGContextFillRect(context, myCGRect);
    //CGContextClosePath(context);
    CGContextFlush(context);
    }
};

-(void)TurnTo: (int)angle;
{
  int temp = angle;
  if (temp < 0)
    {
    while (temp < 0)
      {
      temp += 360;
      };
    };
  if (temp > 359)
    {
    while (temp > 359)
      {
      temp -= 360;
      };
    };
  turtleAngle = temp;
};

-(void)Turn: (int)angle;
{
  int temp = turtleAngle + angle;
  if (temp < 0)
    {
    while (temp < 0)
      {
      temp += 360;
      };
    };
  if (temp > 359)
    {
    while (temp > 359)
      {
      temp -= 360;
      };
    };
  turtleAngle = temp;
};

-(void)MoveTo: (NSPoint)Position;
{
  /*
  if (Position.x > 279)
    {
    Position.x = 279;
    };
  if (Position.y > 191)
    {
    Position.y = 191;
    };
  if (Position.x < 0)
    {
    Position.x = 0;
    };
  if (Position.y < 0)
    {
    Position.y = 0;
    };
   */
  if (turtlePenMode)
    {
    // code a line here
    if (graphicwindowvisible)
      {
      //[self getContextForWindow];
      CGContextSetRGBStrokeColor(context, [penColor redComponent], [penColor greenComponent], [penColor blueComponent], 1);
      CGContextSetLineWidth(context, 1);
      CGContextBeginPath(context);
      CGContextMoveToPoint(context, turtlePosition.x + .5, turtlePosition.y + .5);
      CGContextAddLineToPoint(context, Position.x + .5, Position.y + .5);
      CGContextStrokePath(context);
      //CGContextClosePath(context);
      CGContextFlush(context);
      }
    };
  turtlePosition = Position;
};

-(void)Move: (int)distance;
{
  NSPoint dest;
  dest.y = turtlePosition.y + round(cos((turtleAngle / 360.0) * 2 * 3.14159265365) * distance); // 6.2831853017 is 2 * pi
  dest.x = turtlePosition.x + round(sin((turtleAngle / 360.0) * 2 * 3.14159265365) * distance); // 6.2831853017 is 2 * pi
  [self MoveTo: dest];
};

-(void)PenUp;
{
  turtlePenMode = NO;
};

-(void)PenDown;
{
  turtlePenMode = YES;
};

-(void)Erase;
{
  NSRect tmp = turtleViewPort;
  [self ViewPort: NSMakeRect(0, 0, 280, 192)];
  [self FillScreen: YASSEBlack];
  [self ViewPort: NSMakeRect(tmp.origin.x, tmp.origin.y, tmp.size.width, tmp.size.height)];
};

-(void)PenColor: (NSColor *) theColor;
{
  penColor = [[NSColor colorWithCalibratedRed: [theColor redComponent] green: [theColor greenComponent] blue: [theColor blueComponent] alpha: 1.0] retain];
};


and a few more.



Jim Correia wrote:
On Jan 23, 2006, at 8:05 PM, Robert Dell wrote:

Since invertrect is going to be depreciated, what are my choices for doing what it does?


Do you need exactly the the look that invert rect provides, or something equivalent? You didn't say exactly what you were doing. If you don't really need to invert the pixels, but just provide some sort of indicator (of selection?) there are several nicer alternatives.

Jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: invertrect, any cocoa versions suggested?
      • From: Ricky Sharp <email@hidden>
    • Re: invertrect, any cocoa versions suggested?
      • From: Scott Anguish <email@hidden>
    • Re: invertrect, any cocoa versions suggested?
      • From: John Stiles <email@hidden>
References: 
 >invertrect, any cocoa versions suggested? (From: Robert Dell <email@hidden>)
 >Re: invertrect, any cocoa versions suggested? (From: Jim Correia <email@hidden>)

  • Prev by Date: setUserInfo - how to use?
  • Next by Date: chapter tool xml
  • Previous by thread: Re: invertrect, any cocoa versions suggested?
  • Next by thread: Re: invertrect, any cocoa versions suggested?
  • Index(es):
    • Date
    • Thread