swarm-support
[Top][All Lists]
Advanced

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

Re: Help with Raster, please?


From: Marcus G. Daniels
Subject: Re: Help with Raster, please?
Date: 01 Dec 1999 12:41:52 -0800
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "D3" == Doug Donalson <address@hidden> writes:

D3> I want a simple 2D display that I can draw on.  It looked like
D3> Raster might work so I decided to play around with it.  (You never
D3> can tell when you might need to draw an elipse.) 

Here's an example:

#import <simtools.h>
#import <objectbase/SwarmObject.h>
#import <gui.h>
#import <random.h>

#define XSIZE 100
#define YSIZE 150

@interface MyClass: SwarmObject
{
  id <Colormap> colormap;
  id <ZoomRaster> scamDisplay;
  id <ButtonPanel> panel;
}
- drawEllipse;
@end

@implementation MyClass

- exit
{
  exit (0);
}

- (void)dropScamDisplay
{
  [scamDisplay drop];
}

- drawEllipse
{
  int yradius = [uniformIntRand getIntegerWithMin: 0 withMax: 50];
  int xradius = [uniformIntRand getIntegerWithMin: 0 withMax: 50];
  int x0 = 50 - xradius;
  int y0 = 50 - yradius;
  int x1 = 50 + xradius;
  int y1 = 50 + yradius;

  [scamDisplay erase];
  [scamDisplay ellipseX0: x0 Y0: y0 X1: x1 Y1: y1 Width: 1
               Color: [uniformUnsRand getUnsignedWithMin: 0 withMax: 15]];
  [scamDisplay drawSelf];

  return self;
}

- zoomIn
{
  [scamDisplay increaseZoom];
  [self drawEllipse];

  return self;
}

- zoomOut
{
  [scamDisplay decreaseZoom];
  [self drawEllipse];

  return self;
}

- createEnd
{ 
  id <Zone> aZone = [self getZone];
  int i;

  colormap = [Colormap create: aZone];
  
  for (i = 0; i < 16; i++)
    [colormap setColor: i ToRed: (double)i / 15.0 Green: 0 Blue: 0];
  
  [colormap setColor: 16 ToRed: 0 Green: 1 Blue: 0];
  [colormap setColor: 17 ToRed: 0 Green: 0 Blue: 1];
  [colormap setColor: 18 ToGrey: 10];

  scamDisplay = [ZoomRaster create: aZone];
  [scamDisplay setColormap: colormap];
  [scamDisplay setWidth: XSIZE Height: YSIZE];
  [scamDisplay setWindowTitle: "ScamDisplay"];
  [scamDisplay setZoomFactor: 1];
  [scamDisplay pack];
  
  panel = [ButtonPanel createBegin: aZone];
  [panel setButtonTarget: self];
  panel = [panel createEnd];
  [panel setWindowTitle: "ControlPanel"];
  [panel addButtonName: "ZoomIn" method: @selector (zoomIn)];
  [panel addButtonName: "ZoomOut" method: @selector (zoomOut)];
  [panel addButtonName: "Redraw" method: @selector (drawEllipse)];
  [panel addButtonName: "Drop" method: @selector (dropScamDisplay)];
  [panel addButtonName: "Exit" method: @selector (exit)];
  
  return self;
}
@end

int
main (int argc, const char **argv)
{ 
  id mainObj;

  initSwarm (argc, argv);

  mainObj = [MyClass create: globalZone];
  [mainObj drawEllipse];


  while (1) { while (GUI_EVENT_ASYNC ()) {} }
}

/*
Local Variables:
compile-command: "gcc -DDLL -o zr2 -g -Wno-import -I$SWARMHOME/include 
-L$SWARMHOME/lib zr2.m -lswarmdll -lobjcdll"
End:
*/

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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