home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1986-11-21 | 4.4 KB | 151 lines |
- (* $V+, $R+ *)
- (*
-
- This module will save the current picture into an IFF
- file.
-
- Created: 8/31/87 by Richie Bielak
-
- Modified:
-
- Copyright © 1987 by Richie Bielak
-
- This program can be freely copied, but please leave
- my name in. Thanks....Richie
-
- *)
- IMPLEMENTATION MODULE ChaosSave;
-
- FROM SYSTEM IMPORT ADR, ADDRESS;
- FROM Intuition IMPORT ScreenPtr, WindowPtr, GadgetPtr, CloseWindow,
- WindowFlagsSet, WindowFlags, IDCMPFlags, IDCMPFlagsSet,
- IntuiMessagePtr, StringInfoPtr, Selected, IntuiText,
- GadgetActivation, GadgetActivationSet, ActivateGadget;
- FROM SimpleWindows IMPORT CreateWindow;
- FROM SimpleGadgets IMPORT BeginGadgetList, EndGadgetList, FreeGadgetList,
- LastGadget, AddGadgetTextButton, AddGadgetString;
- FROM Ports IMPORT WaitPort, ReplyMsg, GetMsg, MessagePtr;
- FROM ChaosUtil IMPORT InitTextItem;
- FROM AmigaDOS IMPORT FileHandle, Open, Close, ModeNewFile;
- FROM Memory IMPORT AllocMem, FreeMem, MemClear, MemReqSet;
- FROM PutPict IMPORT PutPicture, IffErr;
- FROM ShowError IMPORT Error;
-
- CONST
- BuffSize = 24;
-
- TYPE
- SaveGadgets = (OKGad, CancelGad, StrGad);
- buffer = ARRAY [0..BuffSize-1] OF CHAR;
-
- VAR
- buffp : POINTER TO buffer;
- ftext : IntuiText;
- LastFile : buffer;
-
- (* ++++++++++++++++++++++++++++++++++++++++ *)
- PROCEDURE SetUpGadgetList () : GadgetPtr;
- VAR sp : StringInfoPtr;
- BEGIN
- BeginGadgetList ();
- AddGadgetTextButton (147, 60, ADR(" OK "));
- AddGadgetTextButton (20, 60, ADR("Cancel"));
- AddGadgetString (20, 30, BuffSize-1, BuffSize, ADR(LastFile));
- (* Set the activation for the string gadget, so *)
- (* that we get a message when a return is hit. *)
- LastGadget^.Activation := GadgetActivationSet {RelVerify};
- (* Get the address of the buffer *)
- sp := LastGadget^.SpecialInfo;
- buffp := sp^.Buffer;
- (* Put some text next to the gadget *)
- InitTextItem (ftext, ADR("File Name"), 0, -10);
- LastGadget^.GadgetText := ADR(ftext);
- RETURN EndGadgetList ();
- END SetUpGadgetList;
-
- (* ++++++++++++++++++++++++++++++++++++++++ *)
- PROCEDURE WritePicture (sp : ScreenPtr; wp : WindowPtr);
- VAR
- f : FileHandle;
- wbufp : ADDRESS;
- err : BOOLEAN;
- BEGIN
- (* First open the file *)
- f := Open (buffp, ModeNewFile);
- IF f <> NIL THEN
- (* Allocate a work buffer *)
- wbufp := AllocMem (4096, MemReqSet {MemClear});
- IF wbufp = NIL THEN
- Error (sp,"Can't allocate work buffer!");
- RETURN
- END;
- (* Write out the picture *)
- WITH sp^ DO
- err := PutPicture (f, RastPort.BitMap^, Width, Height,
- ViewPort.ColorMap^.ColorTable,
- wbufp, 4096);
- END;
- IF err THEN
- Error (sp, "Can't write picture!");
- END;
- FreeMem (wbufp, 4096);
- (* Close the file *)
- Close (f);
- ELSE
- Error (sp, "Can't open file!");
- END; (* f <> NIL *)
- END WritePicture;
-
- (* ++++++++++++++++++++++++++++++++++++++++ *)
- PROCEDURE SavePicture (width, height : CARDINAL; sp : ScreenPtr);
- VAR
- wp : WindowPtr;
- GListPtr : GadgetPtr;
- gptr : GadgetPtr;
- msgptr : IntuiMessagePtr;
- quit : BOOLEAN;
- class : IDCMPFlagsSet;
- save : BOOLEAN;
- succ : BOOLEAN;
- BEGIN
- GListPtr := SetUpGadgetList ();
- wp := CreateWindow (20, 12, 220, 75,
- IDCMPFlagsSet {GadgetUp, GadgetDown},
- WindowFlagsSet {Activate}, GListPtr, sp,
- ADR ("Save Picture..."));
- (* Activate the string gadget. It's the last one in the list *)
- succ := ActivateGadget (LastGadget^, wp^, NIL);
- (* Process IDCMP messages *)
- REPEAT
- msgptr := WaitPort (wp^.UserPort^);
- LOOP
- msgptr := GetMsg (wp^.UserPort^);
- IF msgptr = NIL THEN EXIT END;
- class := msgptr^.Class; gptr := msgptr^.IAddress;
- ReplyMsg (MessagePtr (msgptr));
- IF class <= IDCMPFlagsSet {GadgetDown, GadgetUp} THEN
- quit := TRUE;
- CASE SaveGadgets(gptr^.GadgetID) OF
- StrGad, OKGad:
- save := buffp^[0] <> 0C;
- |
- CancelGad:
- save := FALSE;
- END;
- END;
- END; (* LOOP *)
- UNTIL quit;
- CloseWindow (wp^);
- (* Must call "WritePicture" first, as "FreeGadgetList" *)
- (* deallocates the string buffer. *)
- IF save THEN
- LastFile := buffp^;
- WritePicture (sp, wp);
- END;
- FreeGadgetList (GListPtr^);
- END SavePicture;
-
- BEGIN
- LastFile := "";
- END ChaosSave.
-