home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / oberon / system / kepler4.mod (.txt) < prev    next >
Oberon Text  |  1977-12-31  |  6KB  |  187 lines

  1. Syntax10.Scn.Fnt
  2. MODULE Kepler4;    (* J. Templ, 18.3.91 *)
  3.     IMPORT
  4.         Viewers, KeplerGraphs, KeplerFrames, Oberon, Texts, TextFrames,
  5.         KeplerPorts, Display, Files, Fonts, Kepler2;
  6.     CONST
  7.         ML = 2; MM = 1; MR = 0;
  8.     TYPE
  9.         Icon* = POINTER TO IconDesc;
  10.         IconDesc* = RECORD
  11.             (KeplerFrames.ButtonDesc)
  12.             fnt*: Fonts.Font;
  13.             V: Viewers.Viewer;
  14.         END ;
  15.         Galaxy* = POINTER TO GalaxyDesc;
  16.         GalaxyDesc* = RECORD
  17.             (KeplerGraphs.ConsDesc)
  18.             G*: KeplerGraphs.Graph
  19.         END ;
  20. (* ---------------------------------- Icon ---------------------------------- *)
  21.     PROCEDURE (I: Icon) Execute* (keys: SET);
  22.         VAR X, Y: INTEGER;
  23.             V, V1: Viewers.Viewer;
  24.             N: Oberon.ControlMsg; msg: Viewers.ViewerMsg;
  25.     BEGIN
  26.         IF keys = {MM} THEN
  27.             IF I.V = NIL THEN
  28.                 IF ~Oberon.Pointer.on THEN Oberon.AllocateUserViewer(Oberon.Mouse.X, X, Y);
  29.                     N.id := Oberon.mark; N.X := X; N.Y := Y; V := Viewers.This(X, Y-1); V.handle(V, N)
  30.                 ELSE V := Viewers.This(Oberon.Pointer.X, Oberon.Pointer.Y-1)
  31.                 END ;
  32.                 I.Execute^({MM});
  33.                 V1 := Viewers.This(Oberon.Pointer.X, Oberon.Pointer.Y-1);
  34.                 IF V1 # V THEN I.V := V1 END;    (* heuristic *)
  35.             ELSIF I.V.state = 0 THEN
  36.                 Viewers.Open(I.V, I.V.X, I.V.Y+I.V.H);
  37.                 msg.id := Viewers.restore; I.V.handle(I.V, msg)
  38.             END
  39.         ELSIF (keys = {ML, MM}) & (I.cmd #"") THEN
  40.             IF ~Oberon.Pointer.on THEN Oberon.AllocateUserViewer(Oberon.Mouse.X, X, Y);
  41.             N.id := Oberon.mark; N.X := X; N.Y := Y; V := Viewers.This(X, Y-1); V.handle(V, N)
  42.             ELSE V := Viewers.This(Oberon.Pointer.X, Oberon.Pointer.Y-1)
  43.             END ;
  44.             I.Execute^({MM});
  45.             V1 := Viewers.This(Oberon.Pointer.X, Oberon.Pointer.Y-1);
  46.             IF V1 # V THEN I.V := V1 END;    (* heuristic *)
  47.         ELSE I.Execute^(keys)
  48.         END
  49.     END Execute;
  50.     PROCEDURE (I: Icon) Draw* (F: KeplerPorts.Port);
  51.     BEGIN
  52.         F.DrawRect(I.p[0].x, I.p[0].y, I.p[1].x - I.p[0].x, I.p[1].y - I.p[0].y, Display.white, Display.replace);
  53.         F.DrawString(I.p[0].x + 12, I.p[0].y - I.fnt.minY * 4 + 4, I.par, I.fnt, Display.white, Display.replace)
  54.     END Draw;
  55.     PROCEDURE (I: Icon) Read* (VAR R: Files.Rider);
  56.         VAR fnt: ARRAY 32 OF CHAR;
  57.     BEGIN
  58.         I.Read^(R);
  59.         Files.ReadString(R, fnt);
  60.         I.fnt := Fonts.This(fnt);
  61.         I.V := NIL
  62.     END Read;
  63.     PROCEDURE (I: Icon) Write* (VAR R: Files.Rider);
  64.     BEGIN
  65.         I.Write^(R);
  66.         Files.WriteString(R, I.fnt.name)
  67.     END Write;
  68.     PROCEDURE NewIcon*;
  69.         VAR i: Icon; o: Kepler2.Offset;
  70.             c: KeplerGraphs.Constellation;
  71.             ch: CHAR;
  72.             k, dx, d0, d1, d2, d3: INTEGER;
  73.             d4, beg, end, time: LONGINT;
  74.             R: Texts.Reader;
  75.             S: Texts.Scanner;
  76.             T: Texts.Text;
  77.     BEGIN
  78.         IF KeplerFrames.nofpts >= 1 THEN
  79.             NEW(i); i.nofpts := 2;
  80.             KeplerFrames.ConsumePoint(i.p[0]);
  81.             NEW(o); i.p[1] := o; o.refcnt := 1; NEW(c); o.c := c; c.p[0] := i.p[0]; c.nofpts := 1; INC(c.p[0].refcnt);
  82.             i.V := Oberon.MarkedViewer();
  83.             Texts.OpenReader(R, i.V.dsc(TextFrames.Frame).text, 0);
  84.             Texts.Read(R, ch); i.fnt := R.fnt; k := 0; o.dx := 20;
  85.             WHILE ch = " " DO Texts.Read(R, ch) END ;
  86.             WHILE ch > " " DO
  87.                 i.par[k] := ch; INC(k);
  88.                 Display.GetChar(i.fnt.raster, ch, dx, d0, d1, d2, d3, d4); INC(o.dx, dx*4);
  89.                 Texts.Read(R, ch)
  90.             END ;
  91.             i.par[k] := 0X; o.dy := (i.fnt.height + 4)*4; o.Calc;
  92.             Oberon.GetSelection(T, beg, end, time);
  93.             IF time > 0 THEN
  94.                 Texts.OpenScanner(S, T, beg); Texts.Scan(S);
  95.                 IF S.class = Texts.Name THEN COPY(S.s, i.cmd) END
  96.             END ;
  97.             KeplerFrames.Focus.Append(o);
  98.             KeplerFrames.Focus.Append(i);
  99.         END
  100.     END NewIcon;
  101. (* ---------------------------------- Galaxy ---------------------------------- *)
  102.     PROCEDURE (self: Galaxy) Draw* (F: KeplerPorts.Port);
  103.     BEGIN
  104.         INC(F.x0, self.p[0].x); INC(F.y0, self.p[0].y);
  105.         self.G.Draw(F);
  106.         DEC(F.x0, self.p[0].x); DEC(F.y0, self.p[0].y)
  107.     END Draw;
  108.     PROCEDURE *Dummy(op: INTEGER; g: KeplerGraphs.Graph; c: KeplerGraphs.Object);
  109.     END Dummy;
  110.     PROCEDURE (self: Galaxy) Read* (VAR R: Files.Rider);
  111.         VAR o: KeplerGraphs.Object;
  112.     BEGIN
  113.         self.Read^(R);
  114.         KeplerGraphs.ReadObj(R, o); self.G := o(KeplerGraphs.Graph)
  115.     END Read;
  116.     PROCEDURE (self: Galaxy) Write* (VAR R: Files.Rider);
  117.     BEGIN
  118.         self.Write^(R);
  119.         KeplerGraphs.WriteObj(R, self.G)
  120.     END Write;
  121.     PROCEDURE NewGalaxy*;
  122.         VAR G: KeplerGraphs.Graph;
  123.             Gx: Galaxy;
  124.             M: KeplerFrames.SelMsg;
  125.             offset: Kepler2.Offset;
  126.             p0: KeplerGraphs.Star;
  127.             B: KeplerPorts.BalloonPort;
  128.     BEGIN
  129.         M.time := 0;
  130.         Viewers.Broadcast(M);
  131.         IF (M.time > 0) & (KeplerFrames.nofpts > 0) THEN
  132.             KeplerFrames.ConsumePoint(p0);
  133.             NEW(G); G.notify := KeplerFrames.NotifyDisplay;
  134.             G.CopySelection(M.G, 0, 0); G.All(0);
  135.             NEW(B); KeplerPorts.InitBalloon(B);
  136.             G.Draw(B);
  137.             G.All(1); G.MoveSelection(-B.X, -B.Y); G.All(0);
  138.             NEW(offset); NEW(offset.c);
  139.             offset.dx := B.W; offset.dy := B.H;
  140.             offset.c.p[0] := p0; INC(p0.refcnt); offset.refcnt := 1; offset.c.nofpts := 1; offset.Calc;
  141.             NEW(Gx); Gx.G := G; G := KeplerFrames.Focus;
  142.             Gx.p[0] := p0; Gx.p[1] := offset; Gx.nofpts := 2; 
  143.             G.Append(p0); G.Append(offset); G.Append(Gx)
  144.         END
  145.     END NewGalaxy;
  146. (* ---------------------------------- Button ---------------------------------- *)
  147.     PROCEDURE NewButton*;
  148.         VAR o: KeplerFrames.Button; beg, end, time, i: LONGINT; S: Texts.Scanner; T: Texts.Text;
  149.     BEGIN
  150.         IF KeplerFrames.nofpts >= 2 THEN
  151.             Oberon.GetSelection(T, beg, end, time);
  152.             IF time > 0 THEN
  153.                 Texts.OpenScanner(S, T, beg);
  154.                 Texts.Scan(S);
  155.                 IF S.class = Texts.Name THEN
  156.                     NEW(o); o.nofpts := 2;
  157.                     KeplerFrames.ConsumePoint(o.p[0]);
  158.                     KeplerFrames.ConsumePoint(o.p[1]);
  159.                     KeplerFrames.Focus.Append(o);
  160.                     COPY(S.s, o.cmd); i := 0;
  161.                     WHILE Texts.Pos(S) < end DO
  162.                         Texts.Read(S, o.par[i]); INC(i)
  163.                     END
  164.                 END
  165.             END
  166.         END
  167.     END NewButton;
  168.     PROCEDURE UpdateButton*;
  169.         VAR o: KeplerFrames.Button; beg, end, time, i: LONGINT; S: Texts.Scanner; T: Texts.Text;
  170.     BEGIN
  171.         o := KeplerFrames.MarkedButton();
  172.         IF o # NIL THEN
  173.             Oberon.GetSelection(T, beg, end, time);
  174.             IF time > 0 THEN
  175.                 Texts.OpenScanner(S, T, beg);
  176.                 Texts.Scan(S);
  177.                 IF S.class = Texts.Name THEN
  178.                     COPY(S.s, o.cmd); i := 0;
  179.                     WHILE Texts.Pos(S) < end DO
  180.                         Texts.Read(S, o.par[i]); INC(i)
  181.                     END
  182.                 END
  183.             END
  184.         END
  185.     END UpdateButton;
  186. END Kepler4.
  187.