home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / modula3 / 877 < prev    next >
Encoding:
Text File  |  1992-08-20  |  6.7 KB  |  235 lines

  1. Newsgroups: comp.lang.modula3
  2. Path: sparky!uunet!decwrl!deccrl!news.crl.dec.com!pa.dec.com!src.dec.com!Norman Ramsey <nr@Princeton.EDU>
  3. From: Norman Ramsey <nr@Princeton.EDU>
  4. Subject: trestle applications on black-and-white screens
  5. To: m3
  6. Message-ID: <9208201635.AA17119@cs.Princeton.EDU>
  7. Cc: msm
  8. Date: Thu, 20 Aug 92 12:35:46 -0400
  9. Lines: 224
  10.  
  11. I've noticed that the trestle applications emerging from src aren't
  12. much fun on black-and-white screens.  Perhaps they all have color
  13. monitors, so they tend to forget how the other half lives :-).  In any
  14. case, their nicely colored backgrounds tend to come out white (or,
  15. occasionally, black).  I've written an interface, TwoTone, that makes
  16. it easy to construct backgrounds that are solid colors on a color
  17. screen, and textures on a black-and-white screen.  At some point I'll
  18. cobble up a selection of interesting textures (like those in the
  19. figures in Greg's book), but for now I'm making do with shades of gray
  20. from the Gray interface.  I'm posting the two interfaces and their
  21. implementations, and also the diffs for Solitaire and Card, so you can
  22. get a dark grey `felt' instead of the default white.  Of course, it's
  23. still that nice shade of green on a color monitor.
  24.  
  25.  
  26. Norman Ramsey
  27.  
  28.  
  29. nr@hart (33) % rcsdiff Solitaire.m3
  30. ===================================================================
  31. RCS file: Solitaire.m3,v
  32. retrieving revision 1.1
  33. diff -r1.1 Solitaire.m3
  34. 240c240
  35. <       EVAL TextureVBT.T.init(txt, Card.felt);
  36. ---
  37. >       EVAL TextureVBT.T.init(txt, Card.felt.op, Card.felt.txt);
  38. nr@hart (34) % cd ../../bicycle/src
  39. nr@hart (35) % rcsdiff Card.?3
  40. ===================================================================
  41. RCS file: Card.i3,v
  42. retrieving revision 1.1
  43. diff -r1.1 Card.i3
  44. 45c45
  45. < IMPORT PaintOp, VBT, ZSplit, Point;
  46. ---
  47. > IMPORT VBT, ZSplit, Point, TwoTone;
  48. 56c56
  49. <   felt: PaintOp.T; (* color of the background; you have to put the
  50. ---
  51. >   felt: TwoTone.T; (* color of the background; you have to put the
  52. ===================================================================
  53. RCS file: Card.m3,v
  54. retrieving revision 1.1
  55. diff -r1.1 Card.m3
  56. 14c14
  57. <          Time, CardRank, CardSuit, FaceCards, HighlightVBT,
  58. ---
  59. >          Time, CardRank, CardSuit, FaceCards, Gray, HighlightVBT,
  60. 16c16
  61. <          MouseSplit, Split, Thread;
  62. ---
  63. >          MouseSplit, Split, Thread, TwoTone;
  64. 586,588c586,588
  65. <       op1 := felt;
  66. <       op2 := felt;
  67. <       txt := Pixmap.Solid;
  68. ---
  69. >       op1 := felt.op;
  70. >       op2 := felt.op;
  71. >       txt := felt.txt;
  72. 617c617
  73. <     VBT.PolyTint(v, a, felt)
  74. ---
  75. >     VBT.PolyTexture(v, a, felt.op, felt.txt)
  76. 634,635c634,635
  77. <       txt := Pixmap.Solid;
  78. <       op := felt
  79. ---
  80. >       txt := felt.txt;
  81. >       op := felt.op;
  82. 730c730
  83. <   felt := PaintOp.Pair(PaintOp.Bg, realFelt);
  84. ---
  85. >   felt := TwoTone.New(PaintOp.Pair(PaintOp.Bg, realFelt), Gray.New4x4(10));
  86.  
  87. # To unbundle, "sed '1,/^# To unbundle/d' < thisfile | sh"
  88. # To unbundle, make sure both lines appear in the file
  89. # Thu Aug 20 12:28:07 EDT 1992
  90. echo TwoTone.i3 1>&2
  91. sed 's/^-//' >'TwoTone.i3' <<'End of TwoTone.i3'
  92. -INTERFACE TwoTone;
  93. -IMPORT PaintOp, Point, Pixmap, Rect, VBT;
  94. -
  95. -TYPE
  96. -  T = RECORD
  97. -        op: PaintOp.T;
  98. -        txt: Pixmap.T;
  99. -      END;
  100. -
  101. -PROCEDURE New(colorop: PaintOp.T; monotxt: Pixmap.T):T;
  102. -  (* Result
  103. -       op is PaintOp.BgFg on a mono display, colorop on a color display
  104. -       txt is monotxt on a monodisplay, Pixmap.Solid on a color display
  105. -   *)
  106. -
  107. -PROCEDURE Paint(v: VBT.Leaf; READONLY clip: Rect.T;
  108. -                tone:T; READONLY delta := Point.Origin); <* LL.sup < v *>
  109. -(* Paint the rectangle "clip" with the texture "tone.txt+delta" using
  110. -   the operation "tone.op". *) 
  111. -
  112. -END TwoTone.
  113. End of TwoTone.i3
  114. echo TwoTone.m3 1>&2
  115. sed 's/^-//' >'TwoTone.m3' <<'End of TwoTone.m3'
  116. -MODULE TwoTone;
  117. -IMPORT PaintOp, Pixmap, Point, Palette, Rect, 
  118. -       ScreenType, ScrnPaintOp, ScrnPixmap, VBT;
  119. -
  120. -TYPE
  121. -  PMClosure = Palette.PixmapClosure OBJECT
  122. -    pm: Pixmap.T
  123. -  METHODS OVERRIDES 
  124. -    apply := PMApply
  125. -  END;
  126. -
  127. -PROCEDURE PMApply(cl: PMClosure; st: ScreenType.T): ScrnPixmap.T =
  128. -  BEGIN
  129. -    IF st.color THEN
  130. -      RETURN Palette.ResolvePixmap(st, Pixmap.Solid)
  131. -    ELSE
  132. -      RETURN Palette.ResolvePixmap(st, cl.pm)
  133. -    END
  134. -  END PMApply;
  135. -
  136. -TYPE
  137. -  OpClosure = Palette.OpClosure OBJECT
  138. -    op: PaintOp.T;
  139. -  METHODS OVERRIDES
  140. -    apply := OpApply;
  141. -  END;
  142. -
  143. -PROCEDURE OpApply(cl: OpClosure; st: ScreenType.T): ScrnPaintOp.T =
  144. -  BEGIN
  145. -    IF st.color THEN
  146. -      RETURN Palette.ResolveOp(st, cl.op)
  147. -    ELSE
  148. -      RETURN Palette.ResolveOp(st, PaintOp.BgFg)
  149. -    END
  150. -  END OpApply;
  151. -
  152. -PROCEDURE New(colorop: PaintOp.T; monotxt: Pixmap.T):T =
  153. -  BEGIN
  154. -    RETURN T { Palette.FromOpClosure(NEW(OpClosure, op := colorop)),
  155. -               Palette.FromPixmapClosure(NEW(PMClosure, pm := monotxt)) }
  156. -  END New;
  157. -
  158. -PROCEDURE Paint(v: VBT.Leaf; READONLY clip: Rect.T;
  159. -                tone:T; READONLY delta := Point.Origin) = <* LL.sup < v *>
  160. -BEGIN
  161. -  VBT.PaintTexture(v, clip, tone.op, tone.txt, delta);
  162. -END Paint;
  163. -
  164. -BEGIN
  165. -END TwoTone.
  166. End of TwoTone.m3
  167. echo Gray.i3 1>&2
  168. sed 's/^-//' >'Gray.i3' <<'End of Gray.i3'
  169. -INTERFACE Gray;
  170. -IMPORT Pixmap;
  171. -
  172. -PROCEDURE New3x3(intensity:[0..9]):Pixmap.T;
  173. -  (* return a 3x3 1-bit Pixmap.T with intensity pixels lit *)
  174. -
  175. -PROCEDURE New4x4(intensity:[0..16]):Pixmap.T;
  176. -  (* return a 4x4 1-bit Pixmap.T with intensity pixels lit *)
  177. -
  178. -END Gray.
  179. End of Gray.i3
  180. echo Gray.m3 1>&2
  181. sed 's/^-//' >'Gray.m3' <<'End of Gray.m3'
  182. -MODULE Gray;
  183. -IMPORT Pixmap, Point, Rect, ScrnPixmap;
  184. -
  185. -TYPE
  186. -  A3 = ARRAY [0..2] OF [0..9];
  187. -CONST
  188. -  Intense3 = ARRAY [0..2] OF A3 {A3 {7, 9, 5}, 
  189. -                                 A3 {2, 1, 4}, 
  190. -                                 A3 {6, 3, 8}};
  191. -
  192. -PROCEDURE New3x3(intensity:[0..9]):Pixmap.T =
  193. -VAR bounds := Rect.FromSize(3, 3);
  194. -    raw := ScrnPixmap.NewRaw(1, bounds);
  195. -BEGIN
  196. -  FOR h := 0 TO 2 DO
  197. -    FOR v := 0 TO 2 DO
  198. -      IF intensity >= Intense3[h, v] THEN
  199. -        raw.set(Point.FromCoords(h,v), 1);
  200. -      ELSE
  201. -        raw.set(Point.FromCoords(h,v), 0);
  202. -      END;
  203. -    END;
  204. -  END;
  205. -  RETURN Pixmap.FromBitmap(raw);
  206. -END New3x3;
  207. -
  208. -TYPE
  209. -  A4 = ARRAY [0..3] OF [0..16];
  210. -CONST
  211. -  Intense4 = ARRAY [0..3] OF A4 {A4 { 1,  9,  3, 11}, 
  212. -                                 A4 {13,  5, 15,  7}, 
  213. -                                 A4 { 4, 12,  2, 10},
  214. -                                 A4 {16,  8, 14,  6}};
  215. -
  216. -PROCEDURE New4x4(intensity:[0..16]):Pixmap.T =
  217. -VAR bounds := Rect.FromSize(4, 4);
  218. -    raw := ScrnPixmap.NewRaw(1, bounds);
  219. -BEGIN
  220. -  FOR h := 0 TO 3 DO
  221. -    FOR v := 0 TO 3 DO
  222. -      IF intensity >= Intense4[h,v] THEN
  223. -        raw.set(Point.FromCoords(h,v), 1);
  224. -      ELSE
  225. -        raw.set(Point.FromCoords(h,v), 0);
  226. -      END;
  227. -    END;
  228. -  END;
  229. -  RETURN Pixmap.FromBitmap(raw);
  230. -END New4x4;
  231. -
  232. -BEGIN
  233. -END Gray.
  234. End of Gray.m3
  235.