[comp.sys.next] Re

scott@NIC.GAC.EDU (09/27/90)

paul@manray.asd.sgi.com (Paul Haeberli) writes:
   What follows is a 53 line paint program that compiles
   and runs on an IRIS workstation.  Could someone put
   together a simple example program for the NeXT machine
   that does something similar?

   I think this might be an instructive example for people
   who want to write simple graphics applications for the 
   NeXT machine.

[ the SGI program is deleted . . . ]

Ok, here goes:

This version is a brain-dead one - click-dragging paints black on a gray
backgroun, holding shift puts you in "erase" mode.  Since it uses single
pixels, it's not too useful.  Just integrate this (it's a CustomView) in
with an app using InterfaceBuilder (ask me if you need help), and away
you go.  This version took all of, err, about 5 minutes.  Mostly spent
launching various apps :-).

DinkyView.h:
#import <appkit/View.h>

@interface DinkyView:View
{
}

- mouseDown:(NXEvent *)e;

@end
DinkyView.m:

#import "DinkyView.h"
#import <dpsclient/wraps.h>
#import <appkit/Application.h>
#import <appkit/Window.h>

@implementation DinkyView

- mouseDown:(NXEvent *)e
{
  NXRect r={{0, 0}, {1, 1}};
  int emask=[window addToEventMask:(NX_MOUSEUPMASK | NX_MOUSEDRAGGEDMASK)];
  [self lockFocus];
  do {
    r.origin=e->location;
    [self convertPoint:&(r.origin) fromView:nil];
    PSsetgray( (e->flags&NX_SHIFTMASK) ? NX_LTGRAY : NX_BLACK);
    NXRectFill( &r);
    [window flushWindow];
    NXPing();
    e=[NXApp getNextEvent:(NX_MOUSEUPMASK | NX_MOUSEDRAGGEDMASK)];
  } while( e->type!=NX_MOUSEUP);
  [self unlockFocus];
  [window setEventMask:emask];
  return self;
}

@end


OK, now that's the simple version.  Now, for a version which allows
color changes, and size-of-dot changes (this one will let you go more
insane with the InterfaceBuilder, w/sliders and all).  Add about 5 to
10 minutes more for this one.

DinkyView.h:
#import <appkit/View.h>

@interface DinkyView:View
{
  float radius, color;
}

- takeRadiusFrom:sender;
- takeColorFrom:sender;
- mouseDown:(NXEvent *)e;

@end

DinkyView.m:
#import "DinkyView.h"
#import <dpsclient/wraps.h>
#import <appkit/Application.h>
#import <appkit/Window.h>
#import <appkit/Slider.h>

@implementation DinkyView

+ newFrame:(NXRect *)r
{
  self=[super newFrame:r];
  color=NX_BLACK;
  radius=1.0;
  return self;
}

- takeRadiusFrom:sender
{
  radius=[sender floatValue];
  return self;
}
- takeColorFrom:sender
{
  color=[sender floatValue];
  return self;
}

- mouseDown:(NXEvent *)e
{
  NXPoint p;
  int emask=[window addToEventMask:(NX_MOUSEUPMASK | NX_MOUSEDRAGGEDMASK)];
  [self lockFocus];
  do {
    PSsetgray( (e->flags&NX_SHIFTMASK) ? NX_LTGRAY : color);
    p=e->location;
    [self convertPoint:&p fromView:nil];
    PSmoveto( p.x, p.y);
    PSarc( p.x, p.y, radius, 0, 361);
    PSfill();
    [window flushWindow];
    NXPing();
    e=[NXApp getNextEvent:(NX_MOUSEUPMASK | NX_MOUSEDRAGGEDMASK)];
  } while( e->type!=NX_MOUSEUP);
  [self unlockFocus];
  [window setEventMask:emask];
  return self;
}

@end


There you go.

scott hess
scott@gac.edu
Independant NeXT Developer	(Stuart)
NeXT Campus Consultant		(Not much, really)
GAC Undergrad			(Horrid.  Simply Horrid.  I mean the work!)