|
|
1.1 ! root 1: .TH MOVETO 3L "630 MTG" ! 2: .SH NAME ! 3: moveto, sPtCurrent \- change and return the value current screen point ! 4: .SH SYNOPSIS ! 5: .ft B ! 6: #include <dmd.h> ! 7: .sp ! 8: void moveto (p) ! 9: .br ! 10: Point p; ! 11: .sp ! 12: \f3Point sPtCurrent ( )\f1 ! 13: .sp ! 14: \f3extern int didmoveto;\f1 ! 15: .ft R ! 16: .SH DESCRIPTION ! 17: These functions can be used to change or return the value ! 18: of the current screen point. The current screen point is simply a place holder ! 19: that applications can use to manage current screen position. ! 20: For example, the \fIlputchar\fR function uses ! 21: .I sPtCurrent ! 22: to find the point at which to print the next character and uses ! 23: .I moveto ! 24: to update the current screen point after it prints the character. ! 25: ! 26: The current screen point is similar to but distinct ! 27: from \fIPtCurrent\fR (see \fIglobals\fR(3R)). The primary difference is that ! 28: the current screen point is stored in screen coordinates, and ! 29: the ! 30: \fIPtCurrent\fR is stored in window coordinates (see \fItransform\fR(3R)). ! 31: This makes the ! 32: current screen point easier to deal with for applications that want to ! 33: work completely in screen coordinates. ! 34: ! 35: The \fImoveto\fR function will move the current screen ! 36: point to the point \fIp\fR. The \fIsPtCurrent\fR ! 37: function returns the value of the current screen point. ! 38: ! 39: The current screen point is actually stored in the variable ! 40: P->scurpt. It is stored as an offset from Drect.origin ! 41: (i.e., sub[p, Drect.origin]). Note that this refers only to internal ! 42: representation. The functions \fImoveto\fR and \fIsPtCurrent\fR work in actual ! 43: screen coordinates and translate the offset on each call. ! 44: ! 45: Storing the current screen point as ! 46: an offset from Drect.origin has the advantage that successive calls to ! 47: \fIsPtCurrent\fR will return the proper position within a window even if the ! 48: window was moved between calls. ! 49: ! 50: .bp ! 51: Reshapes of a window between successive calls to \fIsPtCurrent\fR are handled ! 52: as follows. If the offset of the current screen point from Drect.origin is ! 53: still within the window ! 54: after the reshape, \fIsPtCurrent\fR will ! 55: return the current screen point within the new window at the same offset from ! 56: Drect.origin that existed in the old window. If the offset from Drect.origin ! 57: is no longer within the window (i.e., the window was reshaped smaller), ! 58: \fIsPtCurrent\fR will return Drect.origin as the current screen point. ! 59: If an application wants to handle reshape more ! 60: elegantly, it can use the following code fragment after each call to the ! 61: \fIwait\fR function. This ! 62: code fragment will cause the current screen point to move to the upper ! 63: left-hand corner of the window after a reshape. ! 64: .PP ! 65: .RS 3 ! 66: .ft CM ! 67: .nf ! 68: if(P->state&RESHAPED) { ! 69: if(!(P->state&MOVED)) ! 70: moveto(Drect.origin); ! 71: P->state &= ~(MOVED|RESHAPED); ! 72: } ! 73: .fi ! 74: .ft R ! 75: .RE ! 76: .PP ! 77: The current screen point must be initialized with the ! 78: \fImoveto\fR function before \fIsPtCurrent\fR is called the first time. ! 79: Library routines which use this facility can check if initialization is ! 80: necessary by looking at the global variable \fIdidmoveto\fR each time they ! 81: are called. This variable will be set to 0 if \fImoveto\fR has not ! 82: been called. An example below shows how the \fIdidmoveto\fR ! 83: variable is used to determine if initialization is necessary within a ! 84: simple putchar function. ! 85: .SH EXAMPLES ! 86: There are two types of users of the current screen point. The first ! 87: type of user is calling existent library routines such as \fIlprintf\fR ! 88: and \fIlputchar\fR, and is only interested in using the ! 89: \fImoveto\fR function to control the library routines. ! 90: The following code fragment illustrates how \fImoveto\fR can be used ! 91: with \fIlprintf\fR to display a prompt at the bottom of the window. ! 92: .PP ! 93: .RS 3 ! 94: .ft CM ! 95: .nf ! 96: .S -2 ! 97: #include <dmd.h> ! 98: #include <font.h> ! 99: ! 100: extern Point fPt(); ! 101: Point p; ! 102: ! 103: p = fPt( Drect.origin.x, ! 104: Drect.corner.y - FONTHEIGHT(largefont) ); ! 105: moveto(p); ! 106: lprintf("Choose an Option> "); ! 107: .fi ! 108: .ft R ! 109: .S +2 ! 110: .RE ! 111: .bp ! 112: .PP ! 113: The second type of user of the current screen point is writing ! 114: new library routines which use this facility. The following example ! 115: shows how to accomplish this by implementing a simple putchar routine. ! 116: In the example below, didmoveto is checked first ! 117: to see if initialization of the current point is required. Then the code ! 118: obtains ! 119: the value of the current screen point, prints a character, and updates ! 120: the current screen point for the next call to myputchar. ! 121: .PP ! 122: .RS 3 ! 123: .ft CM ! 124: .nf ! 125: myputchar(c) ! 126: char c; ! 127: { ! 128: extern int didmoveto; ! 129: extern Point sPtCurrent(); ! 130: extern Point string(); ! 131: char s[2]; ! 132: Point curpos; ! 133: ! 134: s[0] = c; ! 135: s[1] = '\e0'; ! 136: ! 137: if(!didmoveto) ! 138: moveto(Drect.origin); ! 139: ! 140: curpos = sPtCurrent(); ! 141: curpos = string(&largefont, s, &display, ! 142: curpos, F_STORE); ! 143: moveto(curpos); ! 144: ! 145: } ! 146: .fi ! 147: .ft R ! 148: .RE ! 149: .SH SEE ALSO ! 150: globals(3R), jmove(3R), lprintf(3L), lputchar(3L), ! 151: resources(3R), structures(3R), transform(3R/3L). ! 152: .SH BUGS ! 153: The \fBdidmoveto\fR initialization scheme will not work with ! 154: shared text applications because \fIdidmoveto\fR is a global variable shared ! 155: by all invocations of a shared text application. Shared text applications ! 156: must explicitly initialize the current screen point by calling ! 157: \fImoveto\fR.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.