[comp.windows.x] Pointer over image?

smgf@cl.cam.ac.uk (Steve Freeman) (03/02/90)

I'm beginning work on a system which will need pointers (ie. arrows of
some sort) which can be moved around over an image and left in place.
These pointers are not the same as the cursor (ie. mouse) pointer - the
mouse cursor will be used to drag these pointers around. Anyway, any
suggestions for a neat way to do this before I have to find one myself?
I'll be using the HP widget set most likely.

Many thanks,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Steve Freeman, Computer Lab, University of Cambridge, UK
(smgf@cl.cam.ac.uk -or- smgf%cl.cam.uk.ac@nsf.ac.uk)
"For every problem there is a solution which is simple and elegant and wrong"
 - Mark Twain (?)

hvr@kimba.Sun.COM (Heather Rose) (03/08/90)

In article <1787@gannet.cl.cam.ac.uk> smgf@cl.cam.ac.uk (Steve Freeman) writes:
>I'm beginning work on a system which will need pointers (ie. arrows of
>some sort) which can be moved around over an image and left in place.
>These pointers are not the same as the cursor (ie. mouse) pointer - the
>mouse cursor will be used to drag these pointers around. Anyway, any
>suggestions for a neat way to do this before I have to find one myself?
>I'll be using the HP widget set most likely.

The XView toolkit supplies this functionality already.  Just create a
cursor object from an X11 bitmap and set the new cursor to the window.
Here's an example that creates a cursor from the Sun logo.  Just name
an X11 bitmap file "logo.bm" to compile.  You probably don't want the
Sun logo image file, so I won't waste the bandwidth.

CURSOR_XHOT and CURSOR_YHOT define the hot point for the cursor.  The
XView toolkit is included with the X11R4 distribution.

Regards,

Heather

------------------------

/*
 * simple_cursor.c -- create a cursor (the Sun logo) and
 * assign it to a canvas window.
 */
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/cursor.h>
#include <xview/svrimage.h>

#include "logo.bm"

main(argc, argv)
int argc;
char *argv[];
{
    Frame        frame;
    Canvas       canvas;
    Xv_Cursor    cursor;
    Server_image svr_image;

    xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);

    /*
     * create a server image to use as the cursor's image.
     */
    svr_image = (Server_image)xv_create(XV_NULL, SERVER_IMAGE,
        XV_WIDTH,               logo_width,
        XV_HEIGHT,              logo_height,
        SERVER_IMAGE_X_BITS,    logo_bits,
        NULL);
    /*
     * create a cursor based on the image just created
     */
    cursor = (Xv_Cursor)xv_create(XV_NULL, CURSOR,
        CURSOR_IMAGE,           svr_image,
	CURSOR_XHOT,		32,
	CURSOR_YHOT,		32,
        NULL);

    /*
     * Create a base frame and a canvas
     */
    frame = (Frame)xv_create(XV_NULL, FRAME,
	XV_LABEL,		"Cursor",
	XV_X,			10,
	XV_Y,			10,
        NULL);

    canvas = (Canvas)xv_create(frame, CANVAS,
        XV_WIDTH,               400,
        XV_HEIGHT,              400,
	CANVAS_PAINTWINDOW_ATTRS,
        	WIN_CURSOR,     cursor,
		NULL,
        NULL);

    window_fit(frame);
    window_main_loop(frame);
}