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

  1. Syntax20b.Scn.Fnt
  2. ParcElems
  3. Alloc
  4. Syntax24b.Scn.Fnt
  5. Syntax10.Scn.Fnt
  6. Syntax10b.Scn.Fnt
  7. Syntax20i.Scn.Fnt
  8. FoldElems
  9. (* AMIGA *)
  10. MODULE IFF; (* Ralf Degner 4.08.1995 *)
  11. IMPORT
  12.     i:=AmigaIFFParse, a:=AmigaIFF, AmigaDos, Display, Viewers, Oberon, Texts,
  13.     PictureFrames, Pictures, MenuViewers, TextFrames, Log;
  14.     FileHan: AmigaDos.FileHandlePtr;
  15.     Handler: i.IFFHandlePtr;
  16.     FileOpen: BOOLEAN;
  17. (* NEVER leave an open IFF-File *)
  18. (* If a PROCEDURE opens an IFF-File, it MUST close the File before it ends *)
  19. (* Close IFF-File, uses AmigaDos direct *)
  20. PROCEDURE CloseFile();
  21.     VAR Dummy: BOOLEAN;
  22. BEGIN
  23.     IF FileOpen THEN i.CloseIFF(Handler); Handler:=NIL; END;
  24.     IF FileHan#0 THEN Dummy:=AmigaDos.Close(FileHan); FileHan:=0; END;
  25.     IF Handler#NIL THEN i.FreeIFF(Handler); Handler:=NIL END;
  26.     FileOpen:=FALSE;
  27. END CloseFile;
  28. (* Open IFF-File, uses AmigaDos direct *)
  29. PROCEDURE OpenFile(filemode: LONGINT; mode: SET; Name: ARRAY OF CHAR);
  30. BEGIN
  31.     FileHan:=AmigaDos.Open(Name, filemode);
  32.     IF FileHan#0 THEN
  33.         Handler:=i.AllocIFF();
  34.         IF Handler#NIL THEN
  35.             Handler.stream:=FileHan;
  36.             i.InitIFFasDOS(Handler);
  37.             IF i.OpenIFF(Handler, mode)=0 THEN FileOpen:=TRUE END
  38.         END
  39.     END;
  40.     IF ~FileOpen THEN CloseFile() END
  41. END OpenFile;
  42. (* Get selected Frame *)
  43. PROCEDURE GetFrame(VAR f: Display.Frame): BOOLEAN;
  44.     VAR v: Viewers.Viewer;
  45. BEGIN
  46.     IF Oberon.Par.frame=Oberon.Par.vwr.dsc THEN
  47.         IF (Oberon.Par.frame # NIL) THEN
  48.             f:=Oberon.Par.frame.next;
  49.             RETURN TRUE
  50.         END
  51.     ELSE
  52.         v:=Oberon.MarkedViewer();
  53.         IF (v.dsc # NIL) & (v.dsc.next # NIL) THEN
  54.             f:=v.dsc.next;
  55.             RETURN TRUE
  56.         END
  57.     END;
  58.     RETURN FALSE;
  59. END GetFrame;
  60. (* Get File-Name *)
  61. PROCEDURE GetName(VAR Name: ARRAY OF CHAR): BOOLEAN;
  62.         S: Texts.Scanner;
  63.         text: Texts.Text;
  64.         beg, end, time: LONGINT;
  65. BEGIN
  66.     Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos);
  67.     Texts.Scan(S);
  68.     IF S.class=Texts.Char THEN
  69.         IF S.c="^" THEN
  70.             Oberon.GetSelection(text, beg, end, time);
  71.             IF time=-1 THEN RETURN FALSE; END;
  72.             Texts.OpenScanner(S, text, beg);
  73.             Texts.Scan(S)
  74.         ELSE
  75.             RETURN FALSE
  76.         END
  77.     END;
  78.     IF ((S.class=Texts.Name) OR (S.class=Texts.String)) & (S.len<128) THEN
  79.         COPY(S.s, Name);
  80.         RETURN TRUE
  81.     ELSE
  82.         RETURN FALSE
  83. END GetName;
  84. (* Print Info of a Picture *)
  85. PROCEDURE PrintInfo(P: Pictures.Picture);
  86. BEGIN
  87.     Log.Str("Width="); Log.Int(P.width);
  88.     Log.Str("  Height="); Log.Int(P.height);
  89.     Log.Str("  Depth="); Log.Int(P.depth);
  90.     Log.Ln;
  91. END PrintInfo;
  92. (* Load Display-Colors *)
  93. PROCEDURE LoadColors*;
  94.     VAR Name: ARRAY 128 OF CHAR;
  95. BEGIN
  96.     IF GetName(Name) THEN
  97.         OpenFile(AmigaDos.oldFile, i.read, Name);
  98.         IF FileOpen THEN
  99.             a.LoadDisplayColors(Handler);
  100.             CloseFile()
  101.         END
  102. END LoadColors;
  103. (* Store Display-Colors *)
  104. PROCEDURE StoreColors*;
  105.         Name: ARRAY 128 OF CHAR;
  106.         error: LONGINT;
  107. BEGIN
  108.     IF GetName(Name) THEN
  109.         OpenFile(AmigaDos.newFile, i.write, Name);
  110.         IF FileOpen THEN
  111.             IF i.PushChunk(Handler, a.ILBM, a.FORM, i.sizeUnknown)=0 THEN
  112.                 a.StoreBMHD(Handler, 0, 0, 0, a.cmpNone);
  113.                 a.StoreDisplayColors(Handler);
  114.                 error:=i.PopChunk(Handler);
  115.             END;
  116.             CloseFile()
  117.         END
  118. END StoreColors;
  119. (* Make Screen-SnapShot *)
  120. PROCEDURE StoreDisplay*;
  121.     VAR Name: ARRAY 128 OF CHAR;
  122. BEGIN
  123.     IF GetName(Name) THEN
  124.         OpenFile(AmigaDos.newFile, i.write, Name);
  125.         IF FileOpen THEN
  126.             a.StoreDisplayAsILBM(Handler);
  127.             CloseFile()
  128.         END
  129. END StoreDisplay;
  130. (* Store Picture as ILBM *)
  131. PROCEDURE PaintStore*;
  132.         Name: ARRAY 128 OF CHAR;
  133.         f, g: Display.Frame;
  134. BEGIN
  135.     IF GetFrame(g) THEN
  136.         f:=g;
  137.         WITH f: PictureFrames.Frame DO
  138.             IF GetName(Name) THEN
  139.                 OpenFile(AmigaDos.newFile, i.write, Name);
  140.                 IF FileOpen THEN
  141.                     a.StorePictAsILBM(Handler, f.pict);
  142.                     CloseFile()
  143.                 END
  144.             END
  145.         ELSE
  146.         END
  147. END PaintStore;
  148. (* Open IFF with Paint *)
  149. PROCEDURE PaintOpen*;
  150.         Name: ARRAY 128 OF CHAR;
  151.         F: PictureFrames.Frame;
  152.         P: Pictures.Picture;
  153.         V: Viewers.Viewer;
  154.         X, Y :  INTEGER;
  155. BEGIN
  156.     IF GetName(Name) THEN
  157.         OpenFile(AmigaDos.oldFile, i.read, Name);
  158.         IF FileOpen THEN
  159.             P:=a.LoadILBMToPict(Handler);
  160.             CloseFile();
  161.             IF P#NIL THEN
  162.                 F:=PictureFrames.NewPicture(P);
  163.                 Oberon.AllocateUserViewer(Oberon.Par.vwr.X,X,Y);
  164.                 V := MenuViewers.New(TextFrames.NewMenu(Name, "^Paint.Menu.Text"),F, TextFrames.menuH, X, Y);
  165.                 PrintInfo(P)
  166.             END
  167.         END
  168. END PaintOpen;
  169. (* Fir Colors of Pictur to Display Colors *)
  170. PROCEDURE PaintFitColors*;
  171.         f, g: Display.Frame;
  172. BEGIN
  173.     IF GetFrame(g) THEN
  174.         f:=g;
  175.         WITH f: PictureFrames.Frame DO
  176.             a.FitColors(f.pict);
  177.         ELSE
  178.         END
  179. END PaintFitColors;
  180. END IFF.
  181. System.Free IFF ~
  182.