From: Norman Ramsey <nr@Princeton.EDU>
Subject: trestle applications on black-and-white screens
To: m3
Cc: msm
Date: Thu, 20 Aug 92 12:35:46 -0400

I've noticed that the trestle applications emerging from src aren't
much fun on black-and-white screens.  Perhaps they all have color
monitors, so they tend to forget how the other half lives :-).  In any
case, their nicely colored backgrounds tend to come out white (or,
occasionally, black).  I've written an interface, TwoTone, that makes
it easy to construct backgrounds that are solid colors on a color
screen, and textures on a black-and-white screen.  At some point I'll
cobble up a selection of interesting textures (like those in the
figures in Greg's book), but for now I'm making do with shades of gray
from the Gray interface.  I'm posting the two interfaces and their
implementations, and also the diffs for Solitaire and Card, so you can
get a dark grey `felt' instead of the default white.  Of course, it's
still that nice shade of green on a color monitor.


Norman Ramsey


nr@hart (33) % rcsdiff Solitaire.m3
===================================================================
RCS file: Solitaire.m3,v
retrieving revision 1.1
diff -r1.1 Solitaire.m3
240c240
<       EVAL TextureVBT.T.init(txt, Card.felt);
---
>       EVAL TextureVBT.T.init(txt, Card.felt.op, Card.felt.txt);
nr@hart (34) % cd ../../bicycle/src
nr@hart (35) % rcsdiff Card.?3
===================================================================
RCS file: Card.i3,v
retrieving revision 1.1
diff -r1.1 Card.i3
45c45
< IMPORT PaintOp, VBT, ZSplit, Point;
---
> IMPORT VBT, ZSplit, Point, TwoTone;
56c56
<   felt: PaintOp.T; (* color of the background; you have to put the
---
>   felt: TwoTone.T; (* color of the background; you have to put the
===================================================================
RCS file: Card.m3,v
retrieving revision 1.1
diff -r1.1 Card.m3
14c14
<          Time, CardRank, CardSuit, FaceCards, HighlightVBT,
---
>          Time, CardRank, CardSuit, FaceCards, Gray, HighlightVBT,
16c16
<          MouseSplit, Split, Thread;
---
>          MouseSplit, Split, Thread, TwoTone;
586,588c586,588
<       op1 := felt;
<       op2 := felt;
<       txt := Pixmap.Solid;
---
>       op1 := felt.op;
>       op2 := felt.op;
>       txt := felt.txt;
617c617
<     VBT.PolyTint(v, a, felt)
---
>     VBT.PolyTexture(v, a, felt.op, felt.txt)
634,635c634,635
<       txt := Pixmap.Solid;
<       op := felt
---
>       txt := felt.txt;
>       op := felt.op;
730c730
<   felt := PaintOp.Pair(PaintOp.Bg, realFelt);
---
>   felt := TwoTone.New(PaintOp.Pair(PaintOp.Bg, realFelt), Gray.New4x4(10));

# To unbundle, "sed '1,/^# To unbundle/d' < thisfile | sh"
# To unbundle, make sure both lines appear in the file
# Thu Aug 20 12:28:07 EDT 1992
echo TwoTone.i3 1>&2
sed 's/^-//' >'TwoTone.i3' <<'End of TwoTone.i3'
-INTERFACE TwoTone;
-IMPORT PaintOp, Point, Pixmap, Rect, VBT;
-
-TYPE
-  T = RECORD
-        op: PaintOp.T;
-        txt: Pixmap.T;
-      END;
-
-PROCEDURE New(colorop: PaintOp.T; monotxt: Pixmap.T):T;
-  (* Result
-       op is PaintOp.BgFg on a mono display, colorop on a color display
-       txt is monotxt on a monodisplay, Pixmap.Solid on a color display
-   *)
-
-PROCEDURE Paint(v: VBT.Leaf; READONLY clip: Rect.T;
-                tone:T; READONLY delta := Point.Origin); <* LL.sup < v *>
-(* Paint the rectangle "clip" with the texture "tone.txt+delta" using
-   the operation "tone.op". *) 
-
-END TwoTone.
End of TwoTone.i3
echo TwoTone.m3 1>&2
sed 's/^-//' >'TwoTone.m3' <<'End of TwoTone.m3'
-MODULE TwoTone;
-IMPORT PaintOp, Pixmap, Point, Palette, Rect, 
-       ScreenType, ScrnPaintOp, ScrnPixmap, VBT;
-
-TYPE
-  PMClosure = Palette.PixmapClosure OBJECT
-    pm: Pixmap.T
-  METHODS OVERRIDES 
-    apply := PMApply
-  END;
-
-PROCEDURE PMApply(cl: PMClosure; st: ScreenType.T): ScrnPixmap.T =
-  BEGIN
-    IF st.color THEN
-      RETURN Palette.ResolvePixmap(st, Pixmap.Solid)
-    ELSE
-      RETURN Palette.ResolvePixmap(st, cl.pm)
-    END
-  END PMApply;
-
-TYPE
-  OpClosure = Palette.OpClosure OBJECT
-    op: PaintOp.T;
-  METHODS OVERRIDES
-    apply := OpApply;
-  END;
-
-PROCEDURE OpApply(cl: OpClosure; st: ScreenType.T): ScrnPaintOp.T =
-  BEGIN
-    IF st.color THEN
-      RETURN Palette.ResolveOp(st, cl.op)
-    ELSE
-      RETURN Palette.ResolveOp(st, PaintOp.BgFg)
-    END
-  END OpApply;
-
-PROCEDURE New(colorop: PaintOp.T; monotxt: Pixmap.T):T =
-  BEGIN
-    RETURN T { Palette.FromOpClosure(NEW(OpClosure, op := colorop)),
-               Palette.FromPixmapClosure(NEW(PMClosure, pm := monotxt)) }
-  END New;
-
-PROCEDURE Paint(v: VBT.Leaf; READONLY clip: Rect.T;
-                tone:T; READONLY delta := Point.Origin) = <* LL.sup < v *>
-BEGIN
-  VBT.PaintTexture(v, clip, tone.op, tone.txt, delta);
-END Paint;
-
-BEGIN
-END TwoTone.
End of TwoTone.m3
echo Gray.i3 1>&2
sed 's/^-//' >'Gray.i3' <<'End of Gray.i3'
-INTERFACE Gray;
-IMPORT Pixmap;
-
-PROCEDURE New3x3(intensity:[0..9]):Pixmap.T;
-  (* return a 3x3 1-bit Pixmap.T with intensity pixels lit *)
-
-PROCEDURE New4x4(intensity:[0..16]):Pixmap.T;
-  (* return a 4x4 1-bit Pixmap.T with intensity pixels lit *)
-
-END Gray.
End of Gray.i3
echo Gray.m3 1>&2
sed 's/^-//' >'Gray.m3' <<'End of Gray.m3'
-MODULE Gray;
-IMPORT Pixmap, Point, Rect, ScrnPixmap;
-
-TYPE
-  A3 = ARRAY [0..2] OF [0..9];
-CONST
-  Intense3 = ARRAY [0..2] OF A3 {A3 {7, 9, 5}, 
-                                 A3 {2, 1, 4}, 
-                                 A3 {6, 3, 8}};
-
-PROCEDURE New3x3(intensity:[0..9]):Pixmap.T =
-VAR bounds := Rect.FromSize(3, 3);
-    raw := ScrnPixmap.NewRaw(1, bounds);
-BEGIN
-  FOR h := 0 TO 2 DO
-    FOR v := 0 TO 2 DO
-      IF intensity >= Intense3[h, v] THEN
-        raw.set(Point.FromCoords(h,v), 1);
-      ELSE
-        raw.set(Point.FromCoords(h,v), 0);
-      END;
-    END;
-  END;
-  RETURN Pixmap.FromBitmap(raw);
-END New3x3;
-
-TYPE
-  A4 = ARRAY [0..3] OF [0..16];
-CONST
-  Intense4 = ARRAY [0..3] OF A4 {A4 { 1,  9,  3, 11}, 
-                                 A4 {13,  5, 15,  7}, 
-                                 A4 { 4, 12,  2, 10},
-                                 A4 {16,  8, 14,  6}};
-
-PROCEDURE New4x4(intensity:[0..16]):Pixmap.T =
-VAR bounds := Rect.FromSize(4, 4);
-    raw := ScrnPixmap.NewRaw(1, bounds);
-BEGIN
-  FOR h := 0 TO 3 DO
-    FOR v := 0 TO 3 DO
-      IF intensity >= Intense4[h,v] THEN
-        raw.set(Point.FromCoords(h,v), 1);
-      ELSE
-        raw.set(Point.FromCoords(h,v), 0);
-      END;
-    END;
-  END;
-  RETURN Pixmap.FromBitmap(raw);
-END New4x4;
-
-BEGIN
-END Gray.
End of Gray.m3
Newsgroups: comp.lang.modula3