home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
tools
/
pufferfish
/
source
/
bsclass.c
next >
Wrap
C/C++ Source or Header
|
1994-02-12
|
5KB
|
197 lines
/*
* BoxedStringClass.c
*
* Thanks to Mike Stark for this code!
*
* NOTE: I've renamed MakeMyBoopsiClasses and FreeMyBoopsiClasses to
* MakeBoxedStringClass and FreeBoxedStringClass, respectively.
*
* Also, from the message I received from Mike:
* > It doesn't handle resetting the gadget shape after creation but
* > other than that it works fine.
* ...
* > Actually, I discovered a new problem. The box won't draw right if
* > the gadget was defined with GA_RelRight, GA_RelBottom, GA_RelWidth
* > or GA_RelHeight.
*
* Neither of these are used, so I haven't bothered with them. Users
* modifying this code should be aware of these issues, though.
*
*/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/cghooks.h>
#include <intuition/gadgetclass.h>
#include <clib/alib_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include "PufferFish.h"
/*
* Function prototypes for this module.
*/
ULONG __saveds DispatchBoxedString(Class *, Object *, Msg);
ULONG BSC_New(Class *cl, Object *o, struct opSet *ops);
ULONG BSC_Update(Class *cl, Object *o, struct opUpdate *opu);
ULONG BSC_Render(Class *cl, struct Gadget *Gad, struct gpRender *msg);
void MyDrawBox(struct RastPort *RPort, WORD LeftEdge, WORD TopEdge, WORD Width,
WORD Height, WORD shine, WORD shadow);
/*
* The class definitions contained inthis module.
*/
Class *BoxedStringClass = NULL;
ULONG __saveds DispatchBoxedString(Class *cl, Object *o, Msg msg)
/*************************\
* DispatchBoxedString *
* ------------------ *
* The dispatcher for the BoxedStringClass gadget,
\*************************/
{
ULONG Answer = FALSE;
switch(msg->MethodID)
{
case OM_NEW:
Answer = BSC_New(cl, o, (struct opSet *)msg);
break;
case OM_UPDATE:
Answer = BSC_Update(cl, o, (struct opUpdate *)msg);
break;
case GM_RENDER:
Answer = BSC_Render(cl, (struct Gadget *)o, (struct gpRender *)msg);
break;
default:
Answer = DoSuperMethodA(cl, o, msg);
break;
}
return Answer;
}
ULONG BSC_New(Class *cl, Object *o, struct opSet *ops)
{
struct Gadget *gad;
if (gad = (struct Gadget *)DoSuperMethodA(cl, o, (Msg)ops))
{
gad->LeftEdge += 4;
gad->TopEdge += 2;
gad->Width -= 8;
gad->Height -= 4;
}
return (ULONG)gad;
}
ULONG BSC_Render(Class *cl, struct Gadget *Gad, struct gpRender *msg)
{
struct RastPort *RPort;
UWORD *pens, shine, shadow;
ULONG Answer;
Answer = DoSuperMethodA(cl, (Object *)Gad, (Msg)msg);
if (msg->gpr_Redraw == GREDRAW_REDRAW)
{
if (msg->MethodID == GM_RENDER)
{
RPort = msg->gpr_RPort;
}
else
{
RPort = ObtainGIRPort(msg->gpr_GInfo);
}
if (msg)
{
if (msg->gpr_GInfo)
{
if (msg->gpr_GInfo->gi_DrInfo)
{
pens = (UWORD *)msg->gpr_GInfo->gi_DrInfo->dri_Pens;
}
}
}
if (RPort)
{
shine = pens[SHINEPEN];
shadow = pens[SHADOWPEN];
MyDrawBox(RPort, Gad->LeftEdge - 4, Gad->TopEdge - 2, Gad->Width + 8,
Gad->Height + 4, shine, shadow);
MyDrawBox(RPort, Gad->LeftEdge - 2, Gad->TopEdge - 1, Gad->Width + 4,
Gad->Height + 2, shadow, shine);
if (msg->MethodID != GM_RENDER)
{
ReleaseGIRPort(RPort);
}
}
}
return Answer;
}
ULONG BSC_Update(Class *cl, Object *o, struct opUpdate *opu)
{
struct RastPort *RPort;
ULONG Answer;
Answer = DoSuperMethodA(cl, o, (Msg)opu);
if (RPort = ObtainGIRPort(opu->opu_GInfo))
{
(void)DoMethod(o, GM_RENDER, opu->opu_GInfo, RPort,
GREDRAW_UPDATE, 0);
ReleaseGIRPort(RPort);
}
return Answer;
}
void MakeBoxedStringClass(void)
/*************************\
* MakeBoxedStringClass *
* ------------------- *
* Creates the boopsi classes defined in this file.
\*************************/
{
ULONG __saveds DispatchBoxedString();
ULONG HookEntry();
if (BoxedStringClass = MakeClass(NULL, (UBYTE *)"strgclass", NULL, 0, 0))
{
BoxedStringClass->cl_Dispatcher.h_Entry = HookEntry;
BoxedStringClass->cl_Dispatcher.h_SubEntry = DispatchBoxedString;
}
}
void FreeBoxedStringClass(void)
/*************************\
* FreeBoxedStringClass *
* ------------------- *
* Deletes the boopsi classes defined in this file.
\*************************/
{
if (BoxedStringClass)
{
FreeClass(BoxedStringClass);
}
}
void MyDrawBox(struct RastPort *RPort, WORD LeftEdge, WORD TopEdge, WORD Width,
WORD Height, WORD shine, WORD shadow)
{
SetAPen(RPort, shine);
Move(RPort, LeftEdge, TopEdge + Height - 1);
Draw(RPort, LeftEdge, TopEdge);
Draw(RPort, LeftEdge + Width - 2, TopEdge);
Move(RPort, LeftEdge + 1, TopEdge + 1);
Draw(RPort, LeftEdge + 1, TopEdge + Height - 2);
SetAPen(RPort, shadow);
Move(RPort, LeftEdge + 1, TopEdge + Height - 1);
Draw(RPort, LeftEdge + Width - 1, TopEdge + Height - 1);
Draw(RPort, LeftEdge + Width - 1, TopEdge);
Move(RPort, LeftEdge + Width - 2, TopEdge + Height - 2);
Draw(RPort, LeftEdge + Width - 2, TopEdge + 1);
}