source: cprs/branches/tmg-cprs/m_files/TMGXGS.m@ 1582

Last change on this file since 1582 was 796, checked in by Kevin Toppenberg, 14 years ago

Initial upload

File size: 6.6 KB
Line 
1TMGXGS ;SFISC/VYD - SCREEN PRIMITIVES ;03/16/95 11:00
2 ;;8.0;KERNEL;;5/7/07 by //kt
3SAY(R,C,S,A) ;use this for coordinate output instead of WRITE
4 ;output to screen and update virtual screen (XGSCRN)
5 ;params: Row (0-IOSL),Col (0-IOM),string,
6 ;scrn attrib ie. I1R0B1 (optional)
7 N XGSAVATR,XGESC,XGOUTPUT ;save attribute,escape str,output stream
8 N %
9 ;set output stream to either XGSCRN (virtual screen) or some window
10 S XGOUTPUT=$S($G(XGFLAG("PAINT"),21)=21:"XGSCRN",1:$NA(^TMP("XGS",$J,XGW1)))
11 S XGSAVATR=XGCURATR ;preserve current attribute to restore later
12 S $X=C+$L(S)
13 S XGESC=$S($L($G(A)):$$CHG^XGSA(A),1:"")
14 S $E(@XGOUTPUT@(R,0),(C+1),$X)=S
15 S $E(@XGOUTPUT@(R,1),(C+1),$X)=$TR($J("",$L(S))," ",XGCURATR)
16 ;S $P(%,XGCURATR,$L(S)+1)="",$E(@XGOUTPUT@(R,1),(C+1),$X)=%
17 I XGOUTPUT="XGSCRN" D I 1 ;if screen painting is to occur
18 . ;output string in a proper place in proper attribute and restore attr
19 . ;;W $$IOXY(R,C)_XGESC_S_$S($L($G(A)):$$SET^XGSA(XGSAVATR),1:"")
20 . ;W $$IOXY(R,C)_XGESC_S_$S(XGSAVATR'=XGCURATR:$$SET^XGSA(XGSAVATR),1:"")
21 . DO CLIOXY(R,C,XGESC_S_$S(XGSAVATR'=XGCURATR:$$SET^XGSA(XGSAVATR),1:""))
22 . S $Y=R,$X=C+$L(S)-1
23 E S XGCURATR=XGSAVATR
24 Q
25 ;
26 ;
27VSAY(R,C,S,A) ;"//kt added 5/10/07
28 ;use this for coordinate output instead of WRITE ("Vertical write")
29 ;output to screen and update virtual screen (XGSCRN)
30 ;params: Row (0-IOSL),Col (0-IOM),string,
31 ;scrn attrib ie. I1R0B1 (optional)
32 ;"Note: write is from top to bottom
33 N XGSAVATR,XGESC,XGOUTPUT ;save attribute,escape str,output stream
34 N %
35 ;set output stream to either XGSCRN (virtual screen) or some window
36 S XGOUTPUT=$S($G(XGFLAG("PAINT"),21)=21:"XGSCRN",1:$NA(^TMP("XGS",$J,XGW1)))
37 S XGSAVATR=XGCURATR ;preserve current attribute to restore later
38 new TMGi
39 for TMGi=1:1:$L(S) do ;"write each character sequentially
40 . new SS set SS=$E(S,TMGi)
41 . S XGESC=$S($L($G(A)):$$CHG^XGSA(A),1:"")
42 . S $X=C+1
43 . S $E(@XGOUTPUT@(R,0),(C+1),$X)=SS
44 . S $E(@XGOUTPUT@(R,1),(C+1),$X)=$TR(" "," ",XGCURATR) ;"<-- '??'
45 . I XGOUTPUT="XGSCRN" D I 1 ;if screen painting is to occur
46 . . ;output string in a proper place in proper attribute and restore attr
47 . . DO CLIOXY(R,C,XGESC_SS_$S(XGSAVATR'=XGCURATR:$$SET^XGSA(XGSAVATR),1:""))
48 . . if TMGi'=$L(S) S R=R+1
49 . . set $X=C,$Y=R
50 . E S XGCURATR=XGSAVATR
51 Q
52 ;
53 ;
54SAYU(R,C,S,A) ;use this for coordinate output instead of WRITE
55 ;output to screen and update virtual screen (XGSCRN)
56 ;params: Row (0-IOSL),Col (0-IOM),string,
57 ;scrn attrib ie. I1R0B1 (optional)
58 N XGSAVATR,XGESC,XGOUTPUT ;save attribute,escape str,output stream
59 N %,%S,P,P1,P2,X ;P1:piece before &, P2:piece from & to the end
60 N XGATR
61 ;set output stream to either XGSCRN (virtual screen) or some window
62 S XGOUTPUT=$S($G(XGFLAG("PAINT"),21)=21:"XGSCRN",1:$NA(^TMP("XGS",$J,XGW1)))
63 S P=$L(S,"&&")
64 F %=1:1:P S $P(X,$C(1),%)=$P(S,"&&",%) ;replace all && with $C(1)
65 I X["&",$G(A)'["U1",'$$STAT^XGSA("U")!($G(A)["U0") D I 1
66 . S XGSAVATR=XGCURATR ;preserve current attribute to restore later
67 . S XGESC=$S($L($G(A)):$$CHG^XGSA(A),1:"")
68 . S XGATR=XGCURATR ;get pre-underline attributes
69 . S $X=C+$L(X)-1 ;adjust for a single &, which is not printable
70 . ;S $E(XGSCRN(R,0),(C+1),$X)=$TR($TR(X,"&",""),$C(1),"&")
71 . S $E(@XGOUTPUT@(R,0),(C+1),$X)=$TR($P(X,"&")_$P(X,"&",2,999),$C(1),"&")
72 . S $E(@XGOUTPUT@(R,1),(C+1),$X)=$TR($J("",$X-C)," ",XGCURATR)
73 . S P1=$TR($P(X,"&"),$C(1),"&"),P2=$TR($P(X,"&",2,999),$C(1),"&")
74 . S %S=P1_$$CHG^XGSA("U1")_$E(P2) ;preunderline_underlinechar
75 . S $E(@XGOUTPUT@(R,1),(C+1+$L(P1)))=XGCURATR ;record underlinechar
76 . ;S %S=%S_$$CHG^XGSA("U0")_$E(P2,2,999) ;%S_postunderline
77 . S %S=%S_$$SET^XGSA(XGATR)_$E(P2,2,999) ;%S_postunderline
78 . I XGOUTPUT="XGSCRN" D I 1
79 . . ;output string in a proper place in proper attribute and restore attr
80 . . ;;W $$IOXY(R,C)_XGESC_%S_$S($L($G(A)):$$SET^XGSA(XGSAVATR),1:"")
81 . . ;W $$IOXY(R,C)_XGESC_%S_$S(XGCURATR'=XGSAVATR:$$SET^XGSA(XGSAVATR),1:"")
82 . . DO CLIOXY(R,C,XGESC_%S_$S(XGCURATR'=XGSAVATR:$$SET^XGSA(XGSAVATR),1:""))
83 . . S $Y=R,$X=C+$L(X)-2
84 . E S XGCURATR=XGSAVATR
85 E D SAY(R,C,$TR(S,"&"),A):$D(A),SAY(R,C,$TR(S,"&")):'$D(A)
86 Q
87 ;
88 ;
89IOXY(R,C) ;cursor positioning WRITE argument instead of execute
90 ;Row,Col
91 Q $C(27,91)_((R+1))_$C(59)_((C+1))_$C(72)
92 ;
93 ;
94CLIOXY(R,C,S) ;"5/5/07 //kt added
95 ;Purpose: a unified function for writing to screen, that also handles clipping
96 ;Input: R,C -- row and column
97 ; S -- TEXT to put to screen.
98 I (R<TMGCLT)!(R>TMGCLB) GOTO CLDONE
99 I (C>TMGCLR) GOTO CLDONE
100 I (C<TMGCLL) DO ;clip leftward
101 . new ESC set ESC=""
102 . if $EXTRACT(S,1)=$CHAR(27) do
103CL1 . . do CLIPESC(.S,.ESC) ;"remove leading escape sequences prior to clipping.
104 . NEW TMGCLIP SET TMGCLIP=TMGCLL-C
105 . SET S=ESC_$EXTRACT(S,1+TMGCLIP,9999)
106 . SET C=TMGCLL
107
108 WRITE $$IOXY(R,C) ;position to R,C
109 NEW TMGSPL S TMGSPL=TMGCLR-C+1 ;find space left to clipping margin
110 WRITE $EXTRACT(S,1,TMGSPL)
111CLDONE
112 quit
113
114CLIPESC(S,ESC) ;"5/26/07 //kt added
115 ;Purpose: to separate an escape sequence from the beginning of a string
116 ;Input: S -- the string to work on
117 ; ESC -- PASS BY REFERENCE, an OUT PARAMETER
118 ; Note: prior entries in ESC will NOT be killed. Results will be appended
119 ;Output: if S has one more leading escape sequences, these will be removed
120 ;results: none
121 ;Note: The rule that will be used to determine the end of the escape sequence
122 ; will be when an uppercase letter is encountered, or another ESC(#27) is found
123
124 if $extract(S,1)'=$char(27) goto CEDone
125 set ESC=$get(ESC)_$char(27)
126 new p set p=2
127 new done set done=0
128 for do quit:(done=1)
129 . new ch,chNum set ch=$extract(S,p),chNum=$ascii(ch)
130 . if chNum=27 set done=1 quit
131 . if (chNum'<$ascii("A"))&(chNum'>$ascii("Z")) set done=1 quit
132 . set ESC=ESC_ch
133 . set p=p+1
134 set S=$extract(S,p,9999)
135 do CLIPESC(.S,.ESC) ;"check for further escape sequences
136CEDone
137 quit
Note: See TracBrowser for help on using the repository browser.