MOVETO(3L)

NAME
moveto, sPtCurrent - change and return the value current screen point

SYNOPSIS
#include <dmd.h>

void moveto (p)
Point p;

Point sPtCurrent ( )

extern int didmoveto;

DESCRIPTION
These functions can be used to change or return the value of the current screen point. The current screen point is simply a place holder that applications can use to manage current screen position. For example, the lputchar function uses sPtCurrent to find the point at which to print the next character and uses moveto to update the current screen point after it prints the character. The current screen point is similar to but distinct from PtCurrent (see globals(3R)). The primary difference is that the current screen point is stored in screen coordinates, and the PtCurrent is stored in window coordinates (see transform(3R)). This makes the current screen point easier to deal with for applications that want to work completely in screen coordinates. The moveto function will move the current screen point to the point p. The sPtCurrent function returns the value of the current screen point. The current screen point is actually stored in the variable P->scurpt. It is stored as an offset from Drect.origin (i.e., sub[p, Drect.origin]). Note that this refers only to internal representation. The functions moveto and sPtCurrent work in actual screen coordinates and translate the offset on each call. Storing the current screen point as an offset from Drect.origin has the advantage that successive calls to sPtCurrent will return the proper position within a window even if the window was moved between calls.
Reshapes of a window between successive calls to sPtCurrent are handled as follows. If the offset of the current screen point from Drect.origin is still within the window after the reshape, sPtCurrent will return the current screen point within the new window at the same offset from Drect.origin that existed in the old window. If the offset from Drect.origin is no longer within the window (i.e., the window was reshaped smaller), sPtCurrent will return Drect.origin as the current screen point. If an application wants to handle reshape more elegantly, it can use the following code fragment after each call to the wait function. This code fragment will cause the current screen point to move to the upper left-hand corner of the window after a reshape.

    if(P->state&RESHAPED) {
    	if(!(P->state&MOVED))
    		moveto(Drect.origin);
    	P->state &= ~(MOVED|RESHAPED);
    }

The current screen point must be initialized with the moveto function before sPtCurrent is called the first time. Library routines which use this facility can check if initialization is necessary by looking at the global variable didmoveto each time they are called. This variable will be set to 0 if moveto has not been called. An example below shows how the didmoveto variable is used to determine if initialization is necessary within a simple putchar function.

EXAMPLES
There are two types of users of the current screen point. The first type of user is calling existent library routines such as lprintf and lputchar, and is only interested in using the moveto function to control the library routines. The following code fragment illustrates how moveto can be used with lprintf to display a prompt at the bottom of the window.

    #include <dmd.h>
    #include <font.h>
    extern Point fPt();
    Point p;
    p = fPt( Drect.origin.x,
        Drect.corner.y - FONTHEIGHT(largefont) );
    moveto(p);
    lprintf("Choose an Option> ");

The second type of user of the current screen point is writing new library routines which use this facility. The following example shows how to accomplish this by implementing a simple putchar routine. In the example below, didmoveto is checked first to see if initialization of the current point is required. Then the code obtains the value of the current screen point, prints a character, and updates the current screen point for the next call to myputchar.

    myputchar(c)
    char c;
    {
    	extern int didmoveto;
    	extern Point sPtCurrent();
    	extern Point string();
    	char s[2];
    	Point curpos;
    	s[0] = c;
    	s[1] = '\0';
    	if(!didmoveto)
                    moveto(Drect.origin);
    	curpos = sPtCurrent();
    	curpos = string(&largefont, s, &display,
    			curpos, F_STORE);
    	moveto(curpos);
    }

SEE ALSO
globals(3R), jmove(3R), lprintf(3L), lputchar(3L), resources(3R), structures(3R), transform(3R/3L).

BUGS
The didmoveto initialization scheme will not work with shared text applications because didmoveto is a global variable shared by all invocations of a shared text application. Shared text applications must explicitly initialize the current screen point by calling moveto.