home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
new
/
dev
/
obero
/
oberon-a
/
examples
/
libraries
/
intuition
/
rkmbuttonclass.mod
< prev
next >
Wrap
Text File
|
1995-07-02
|
17KB
|
529 lines
(*************************************************************************
$RCSfile: RKMButtonclass.mod $
Description: Example Boopsi gadget for RKRM:Libraries
Created by: fjc (Frank Copeland)
$Revision: 1.4 $
$Author: fjc $
$Date: 1995/07/02 16:59:58 $
Copyright © 1994-1995, Frank Copeland.
This example program is part of Oberon-A.
See Oberon-A.doc for conditions of use and distribution.
Log entries are at the end of the file.
*************************************************************************)
<* STANDARD- *> <*$ NilChk- StackChk- *>
MODULE RKMButtonclass;
IMPORT
SYS := SYSTEM,
Kernel,
e := Exec,
i := Intuition,
u := Utility,
gfx := Graphics,
cf := ClassFace,
IE := InputEvent,
Errors,
d := Dos;
CONST
VersionTag = "$VER: RKMButtonclass 1.4 (4.6.95)\r\n";
VersionStr = "RKMButtonclass 1.4 (4.6.95)\r\n";
CopyrightStr = "Copyright © 1994-1995 Frank Copeland";
(*
** Class specifics
*)
CONST
rkmButPulse = u.user + 1;
TYPE
ButINSTPtr = POINTER [2] TO ButINST;
ButINST = RECORD [2]
midX, midY : LONGINT; (* Co-ordinates of middle of gadget *)
END;
CONST
(* ButINST has one flag: *)
eraseOnly = 0; (* Tells rendering routine to *)
(* only erase the gadget, not *)
(* rerender a new one. This *)
(* lets the gadget erase it- *)
(* self before it rescales. *)
(**************************************************************************)
(* The Main procedure connects an RKMButClass object to a Boopsi integer *)
(* gadget, which displays the RKMButClass gadget's rkmButPulse value. *)
(* The code scales and moves the gadget while it is in place. *)
(**************************************************************************)
VAR
pulse2int : ARRAY 2 OF u.TagItem;
CONST
intWidth = 40;
intHeight = 20;
VAR
w : i.WindowPtr;
rkmbutcl : i.IClassPtr;
integer, but : i.GadgetPtr;
msg : i.IntuiMessagePtr;
(*------------------------------------*)
PROCEDURE^ freeRKMButGadClass ( cl : i.IClassPtr );
PROCEDURE* Cleanup (VAR rc : LONGINT);
BEGIN (* Cleanup *)
IF but # NIL THEN
SYS.PUTREG (0, i.RemoveGList (w, integer, -1));
i.DisposeObject (but); but := NIL
END;
IF integer # NIL THEN i.DisposeObject (integer); integer := NIL END;
IF rkmbutcl # NIL THEN freeRKMButGadClass (rkmbutcl); rkmbutcl := NIL END;
IF w # NIL THEN i.CloseWindow (w); w := NIL END
END Cleanup;
(*------------------------------------*)
PROCEDURE Init ();
BEGIN (* Init *)
ASSERT (u.base # NIL, 100);
pulse2int [0].tag := rkmButPulse; pulse2int [0].data := i.stringaLongVal;
pulse2int [1].tag := u.end;
but := NIL; integer := NIL; rkmbutcl := NIL; w := NIL;
Kernel.SetCleanup (Cleanup)
END Init;
(*------------------------------------*)
PROCEDURE MainLoop ( attr, value : LONGINT );
VAR done : BOOLEAN; ignore : LONGINT;
BEGIN (* MainLoop *)
done := FALSE;
ignore := i.SetGadgetAttrs (but^, w, NIL, attr, value, u.done);
WHILE ~done DO
e.WaitPort (w.userPort);
LOOP
msg := SYS.VAL (i.IntuiMessagePtr, e.GetMsg (w.userPort));
IF msg = NIL THEN EXIT END;
IF msg.class = {i.closeWindow} THEN done := TRUE END;
e.ReplyMsg (msg)
END;
END;
END MainLoop;
(*------------------------------------*)
PROCEDURE RenderRKMBut
( cl : i.IClassPtr; g : i.GadgetPtr; msg : i.RenderPtr )
: e.APTR;
VAR
inst : ButINSTPtr;
rp : gfx.RastPortPtr;
retval : e.APTR;
pens : i.DRIPenArrayPtr;
back, shine, shadow, wd, h, x, y : INTEGER;
BEGIN (* RenderRKMBut *)
inst := cf.InstData (cl, SYS.VAL (i.ObjectPtr, g));
retval := SYS.VAL (e.APTR, e.LTRUE);
pens := msg.gInfo.drInfo.pens;
IF msg.msg.methodID = i.gmRender THEN (* If msg is truly a gmRender message *)
(* (not a Input that looks like a *)
(* Render), use the rastport within *)
(* it... *)
rp := msg.rPort
ELSE (* ...Otherwise, get a rastport using *)
(* ObtainGIRPort(). *)
rp := i.ObtainGIRPort (msg.gInfo)
END;
IF rp # NIL THEN
IF i.selected IN g.flags THEN (* If the gadget is selected, *)
(* reverse the meanings of the *)
(* pens. *)
back := pens [i.fillPen];
shine := pens [i.shadowPen];
shadow := pens [i.shinePen]
ELSE
back := pens [i.backGroundPen];
shine := pens [i.shinePen];
shadow := pens [i.shadowPen]
END;
gfx.SetDrMd (rp, gfx.jam1);
gfx.SetAPen (rp, SHORT (back)); (* Erase the old gadget *)
gfx.RectFill
( rp, g.leftEdge,
g.topEdge,
g.leftEdge + g.width,
g.topEdge + g.height );
gfx.SetAPen (rp, SHORT (shadow)); (* Draw shadow edge *)
gfx.Move (rp, g.leftEdge + 1, g.topEdge + g.height);
gfx.Draw (rp, g.leftEdge + g.width, g.topEdge + g.height);
gfx.Draw (rp, g.leftEdge + g.width, g.topEdge + 1);
wd := g.width DIV 4; (* Draw arrows - Sorry, no frills imagery *)
h := g.height DIV 2;
x := g.leftEdge + (wd DIV 2);
y := g.topEdge + (h DIV 2);
gfx.Move (rp, x, SHORT (inst.midY));
gfx.Draw (rp, x + wd, y);
gfx.Draw (rp, x + wd, y + g.height - h);
gfx.Draw (rp, x, SHORT (inst.midY));
x := g.leftEdge + (wd DIV 2) + g.width DIV 2;
gfx.Move (rp, x + wd, SHORT (inst.midY));
gfx.Draw (rp, x, y);
gfx.Draw (rp, x, y + g.height - h);
gfx.Draw (rp, x + wd, SHORT (inst.midY));
gfx.SetAPen (rp, SHORT (shine)); (* Draw shine edge *)
gfx.Move (rp, g.leftEdge, g.topEdge + g.height - 1);
gfx.Draw (rp, g.leftEdge, g.topEdge);
gfx.Draw (rp, g.leftEdge + g.width - 1, g.topEdge);
IF msg.msg.methodID # i.gmRender THEN (* If we allocated a rastport, give *)
(* it back. *)
i.ReleaseGIRPort (rp)
END;
ELSE
retval := SYS.VAL (e.APTR, e.LFALSE);
END;
RETURN retval
END RenderRKMBut;
(*------------------------------------*)
PROCEDURE NotifyPulse
( cl : i.IClassPtr;
o : i.ObjectPtr;
flags : SET;
mid : LONGINT;
gpi : i.InputPtr );
VAR
tt : ARRAY 3 OF u.TagItem;
g : i.GadgetPtr;
ignore : e.APTR;
BEGIN (* NotifyPulse *)
g := SYS.VAL (i.GadgetPtr, o);
tt[0].tag := rkmButPulse;
tt[0].data := mid - gpi.mouse.x + g.leftEdge;
tt[1].tag := i.gaID;
tt[1].data := g.gadgetID;
tt[2].tag := u.done;
ignore := cf.DoSuperMethod
(cl, o, i.omNotify, SYS.ADR (tt), gpi.gInfo, flags)
END NotifyPulse;
(*------------------------------------*)
PROCEDURE* dispatchRKMButGad
( hook : u.HookPtr; obj : e.APTR; message : e.APTR )
: e.APTR;
VAR
cl : i.IClassPtr; o : i.ObjectPtr; msg : i.MsgPtr;
inst : ButINSTPtr;
retval, ignore : SYS.LONGWORD;
object : i.ObjectPtr;
g : i.GadgetPtr;
gpi : i.InputPtr;
ie : IE.InputEventPtr;
rp : gfx.RastPortPtr;
x, y, wd, h : INTEGER;
pens : i.DRIPenArrayPtr;
opSet : i.OpSetPtr;
BEGIN (* dispatchRKMButGad *)
cl := SYS.VAL (i.IClassPtr, hook);
o := obj;
msg := message;
retval := e.LTRUE;
CASE msg.methodID OF
i.omNew : (* First, pass up to superclass *)
object := cf.DoSuperMethodA (cl, o, msg^);
IF object # NIL THEN
g := SYS.VAL (i.GadgetPtr, object);
(* Initial local instance data *)
inst := cf.InstData (cl, object);
inst.midX := g.leftEdge + (g.width DIV 2);
inst.midY := g.topEdge + (g.height DIV 2);
retval := object
END;
|
i.gmHitTest :
(* Since this is a rectangular gadget this *)
(* method always returns i.gmrGadgetHit. *)
retval := i.gmrGadgetHit;
|
i.gmGoActive :
inst := cf.InstData (cl, o);
(* Only become active if the gmGoActive *)
(* was triggered by direct user input. *)
gpi :