swarm-support
[Top][All Lists]
Advanced

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

Re: Text on the Raster


From: Marcus G. Daniels
Subject: Re: Text on the Raster
Date: 16 Oct 2000 16:54:56 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "RK" == Kewley, R MAJ SE <address@hidden> writes:

RK> I saw some previous posts on how to put text on the raster. 

RK> I have solved this problem for x-windows using the TextRaster object
RK> in the attached archive. 

RK> However, I could use some help adapting the code so that it
RK> compiles in windows.  I browsed to tkobj internal.m object to try
RK> to figure out how to do graphics in windows and I have a rough cut
RK> in the TextRaster object.  The code compiles under win32 but does
RK> not link because it cannot find methods such as TextOut,
RK> DeleteObject from the gdi32.dll windows object. 

Yow!  All pain and no gain!

Here's a portable approach in Java. 

(It is tested with Kaffe 1.0.5, and JDK 1.3 on Linux, and `jdkswarm'
on Windows.)

import swarm.Globals;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.activity.Activity;
import swarm.objectbase.Swarm;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.defobj.Zone;
import swarm.Selector;

import java.awt.Frame;
import java.awt.Container;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.image.MemoryImageSource;
import java.awt.Window;

public class TextRasterDemo extends GUISwarmImpl {
  final int w = 256;
  final int h = 256;
  final int x = 100;
  final int y = 100;
  int textX, textY;
  MemoryImageSource source;
  Image image;
  TextRaster textRaster;

  Schedule schedule;
  
  TextRasterDemo (Zone aZone) {
    super (aZone);

    textRaster = new TextRaster ();

    Frame frame = new WrapperFrame ();
    frame.setBounds (100, 100, w, h);
    frame.add (textRaster);
    frame.show ();
  }

  public Object buildActions () {
    schedule = new ScheduleImpl (getZone (), 1);
    
    try {
      schedule.at$createActionTo$message
        (0, this, new Selector (getClass (), "move", false));
    } catch (Exception e) {
      e.printStackTrace ();
    }
    return this;
  }

  public Activity activateIn (Swarm swarmContext) {
    super.activateIn (swarmContext);
    
    schedule.activateIn (this);
    return getActivity ();
  }
  
  public void move () {
    textX = Globals.env.uniformIntRand.getIntegerWithMin$withMax (0, w);
    textY = Globals.env.uniformIntRand.getIntegerWithMin$withMax (0, h);
    textRaster.repaint ();
    getActionCache ().doTkEvents ();
  }

  class WrapperFrame extends Frame {
    public void update (Graphics g) {
      paint (g);
    }
  }
  
  class TextRaster extends Container {
    int pixels[] = new int[w * h];
    Container container;
    
    public TextRaster () {
      super ();

      for (int gi = 0; gi < h; gi++) {
        int goffset = gi * w;
        for (int bi = 0; bi < w; bi++) {
          int boffset = goffset + bi;
          pixels[boffset] = (255 << 24) | (128 << 16) | (gi << 8) | bi;
        }
      }
      source = new MemoryImageSource (w, h, pixels, 0, w);
      source.setAnimated (true);
      image = createImage (source);
    }

    public void update (Graphics g) {
      paint (g);
    }
    
    public void paint (Graphics g) {
      g.drawImage (image, 0, 0, this);
      g.drawString ("Hi", textX, textY);
    }
  }
  
  static public void main (String args[]) {
    Globals.env.initSwarm ("TextRasterDemo", "0.0", "address@hidden",
                           args);
    
    TextRasterDemo textRasterDemo =
      new TextRasterDemo (Globals.env.globalZone);

    textRasterDemo.buildObjects ();
    textRasterDemo.buildActions ();
    textRasterDemo.activateIn (null);
    textRasterDemo.go ();
    System.exit (0);
  }
}

                  ==================================
   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]