[Oberon] FPGA - OberonV4 Dialogs

Tomas Kral thomas.kral at email.cz
Thu Dec 13 23:30:29 CET 2018


On Thu, 13 Dec 2018 23:11:56 +0100
Jörg Straube <joerg.straube at iaeth.ch> wrote:

> „m.draw := Draw“ should be after NEW(m) in the two main bodies and
> deleted from both New()s

Thank you, corrected. Added some fields so I may not use `Texts', no
need to modify PO2013 `Texts' and `TextFrames'. Unlike the original
Dialogs.

MODULE DLog; (* TK 13.12.2018 Dialogs - simple coding for RISC *)
  IMPORT In, Out, Modules;

  TYPE
    Object* = POINTER TO ObjDesc;
    Methods* = POINTER TO MethodDesc;
    Rect* = POINTER TO RectDesc;

    ObjDesc* = RECORD
      do*: Methods;
      r*: Rect; (*bounding rectangle*)
      next: Object;
      id*: INTEGER
    END;

    RectDesc = RECORD x, y, w, h: INTEGER;
    END;

    MethodDesc* = RECORD
      draw*: PROCEDURE (o: Object);
    END;

  VAR first: Object; cnt: INTEGER;
  
  PROCEDURE Load*;
    VAR name: Modules.ModuleName; module: Modules.Module; New: PROCEDURE;
  BEGIN In.Open; In.Name(name);
    WHILE In.Done DO
      Out.String(name); Out.String(" loading ");
      Modules.Load(name, module);
      New := Modules.ThisCommand(module, "New");
      IF Modules.res = 0 THEN New() END ;
      In.Name(name); Out.Ln
    END;
  END Load;

  PROCEDURE LinkObj*(o: Object);
  BEGIN o.next := first; first := o;
    INC(cnt); o.id := cnt
  END LinkObj;

  PROCEDURE Update*;
    VAR o: Object;
  BEGIN o := first;
    WHILE o # NIL DO o.do.draw(o); o := o.next END
  END Update;

BEGIN first := NIL; cnt := 0
END DLog.

DLog.Load DText DButton DButton DText DText ~ Objects from stream now, TODO from persistent file
DLog.Update


MODULE DText;
  IMPORT DLog, Out;

  TYPE
    Text = ARRAY 32 OF CHAR;

    Item = POINTER TO ItemDesc;
    ItemDesc = RECORD(DLog.ObjDesc)
      static: BOOLEAN;
      name: Text;
    END;

  VAR t: Item; m: DLog.Methods;

  PROCEDURE Draw(o: DLog.Object);
  BEGIN Out.String("Drawing text"); Out.Int(o.id, 2); Out.Ln
  END Draw;

  PROCEDURE New*;
  BEGIN NEW(t); DLog.LinkObj(t); t.do := m
  END New;

BEGIN NEW(m); m.draw := Draw
END DText.


MODULE DButton;
  IMPORT DLog, Out;

  CONST oval = 0; oblique = 1;
  
  TYPE
    Item = POINTER TO ItemDesc;
    ItemDesc = RECORD(DLog.ObjDesc)
      shape: INTEGER;
    END;

  VAR t: Item; m: DLog.Methods;

  PROCEDURE Draw(o: DLog.Object);
  BEGIN Out.String("Drawing button"); Out.Int(o.id, 2); Out.Ln
  END Draw;

  PROCEDURE New*;
  BEGIN NEW(t); DLog.LinkObj(t); t.do := m
  END New;

BEGIN NEW(m); m.draw := Draw
END DButton.


-- 
Tomas Kral <thomas.kral at email.cz>


More information about the Oberon mailing list