discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simplest way to try NSBezierPath??


From: Fred Kiefer
Subject: Re: Simplest way to try NSBezierPath??
Date: Thu, 22 May 2003 23:38:36 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020903

HI Jonathon,

sorry for replying that late. I did just fish your mail out of my SPAM
folder, where it was classified as:
X-GMX-Antispam: 5 (Score=2.401; FORGED_YAHOO_RCVD)

jonathon wrote:
> I'm trying to programmatically create a window with a 'canvas' where I
> can experiment with NSBezierPath and other graphics functions.
>
> I don't want to use Gorm since I would rather learn the details behind
> the code.  With a simple app that just opens a window, what is the
> easiest way to get the NSView I need to use NSBezierPath?

Yes some example code for NSBezierPath would be great. Perhaps you could
come up with one? Just to give you a starting point I will attach the
code I used last year to test the performance of NSBezierPath relative
to DPS and PS operations.

Fred

/* 
   Tester for BezierPath
   Copyright (C) 2002 Free Software Foundation, Inc.

   Written by: Fred Kiefer <FredKiefer@gmx.de>
   Created: November 2002

   This file is part of the GNUstep Base Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSString.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSBezierPath.h>
#include <AppKit/NSColor.h>
#include <AppKit/NSMenu.h>
#include <AppKit/NSView.h>
#include <AppKit/NSWindow.h>

#include <AppKit/PSOperators.h>

@interface AppController: NSObject
{
}
@end


@implementation AppController

-(void) draw
{
  NSBezierPath *path;
  int i, k;
  int max = 5;

#if 0
  [[NSColor blackColor] set];
  NSLog(@"Start PS-Op test");
  for (i = 0; i < 100000; i++)
    {
        PSnewpath();
        PSmoveto(0, 0);
        for (k = 1; k < max; k++)
          {
              PSlineto(k*10, k*10);
          }
        PSstroke();
    }
  NSLog(@"End PS-Op test");
#endif

#if 1
  [[NSColor blueColor] set];
  NSLog(@"Start NSBezierPath test");
  path = [NSBezierPath new];
  for (i = 0; i < 100000; i++)
    {
        [path removeAllPoints];
        [path moveToPoint: NSMakePoint(0, 0)];
        for (k = 1; k < max; k++)
          {
            [path lineToPoint: NSMakePoint(k*10, k*10)];
          }
        [path stroke];
    }
  RELEASE(path);
  NSLog(@"End NSBezierPath test");
#endif

#if 0
  [[NSColor redColor] set];
  NSLog(@"Start DPS-Op test");
  for (i = 0; i < 100000; i++)
    {
        NSGraphicsContext *ctxt = GSCurrentContext();
  
        DPSnewpath(ctxt);
        DPSmoveto(ctxt, 0, 0);
        for (k = 1; k < max; k++)
          {
            DPSlineto(ctxt, k*10, k*10);
          }
        DPSstroke(ctxt);
    }
  NSLog(@"End DPS-Op test");
#endif
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
  NSWindow *aWin;
  NSMenu *menu = [NSMenu new];

  [menu addItemWithTitle: @"Quit"
        action: @selector(terminate:)
        keyEquivalent: @"q"];
  [NSApp setMainMenu: menu];
  RELEASE(menu);

  aWin = [[NSWindow alloc] initWithContentRect: NSMakeRect(200,200,130,50)
                           styleMask: NSTitledWindowMask
                           backing: NSBackingStoreBuffered
                           defer: NO];
  [aWin makeKeyAndOrderFront: nil];
  [[aWin contentView] lockFocus];
  [self draw];
  [[aWin contentView] unlockFocus];
  [aWin flushWindow];
}

@end

int main (int argc, const char *argv[])
{
  CREATE_AUTORELEASE_POOL(pool);
  id app;

  app = [NSApplication sharedApplication];
  [app setDelegate: [AppController new]];
  [app run];
  RELEASE(pool);
  return 0;
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]