AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YDAT | YWAIT | Byzgraf | FAQs
addCursor (String name, Object value) yoix.awt
 
Creates a new cursor from value, which must be an Image or String that is not NULL, adds the new cursor to the yoix.awt.Cursor dictionary as the entry associated with name, and returns 1 if the operation succeeded and 0 if it failed, which usually means name has already been defined.

value should usually be an Image, because the hotspot, paint, and size fields in an Image let you control how the custom cursor is built. A value that is a String should be the name of a cursor that is already defined in yoix.awt.Cursor or the name a local a file or URL that contains a GIF or JPEG image that will be used as the cursor. It sounds easy, but a String argument is not as convenient as you might expect, because you do not get any control over the cursor's size or hotspot.

Any value that addCursor accepts can also be assigned directly to the cursor field that is defined in all AWT or Swing components, however each assignment (after the first one) involves overhead that can be eliminated using addCursor. In other words, a custom cursor that is used more than a few times is a candidate that your application may want to add to yoix.awt.Cursor using addCursor.
 
 Example:   The program,
import yoix.*.*;

Image triangle = {
    int type = TYPE_RGBA;

    Dimension size = {
        double width = 36;
        double height = 36;
    };

    paint(Rectangle r) {
        Rectangle bbox;

        graphics {
            gsave();
            initclip();
            clippath();
            bbox = pathbbox();
            newpath();

            moveto(0, 0);
            rlineto(bbox.width, 0);
            rlineto(0, bbox.height);
            closepath();
            setrgbcolor(0, 1, 1);
            gsave();
            fill();
            grestore();
            setrgbcolor(1, 0, 0);
            setlinewidth(1);
            stroke();
            grestore();

            hotspot = new Point {
                double x = bbox.width/2;
                double y = bbox.height/2;
            };
        }
    }
};

addCursor("TRIANGLE", triangle);

Frame frame = {
    BoxLayout layoutmanager;

    Array layout = {
        0,
        new Button {
            Object cursor = Cursor.TRIANGLE;
            String text = "This is a test...";

            mousePressed(e) {
                cursor = NULL;
            }

            mouseReleased(e) {
                cursor = "TRIANGLE";
            }
        },
        0
    };
};

frame.visible = TRUE;
draws a triangle in an image, uses the image to create a custom cursor named TRIANGLE, and then uses TRIANGLE as the cursor that is displayed by a button when it is not pressed.
 
 Return:   int
 
 See Also:   addColor, Image

 

Yoix is a registered trademark of AT&T Intellectual Property.