home *** CD-ROM | disk | FTP | other *** search
- /* ==========================================================================
- **
- ** EmbossedGadget.c
- **
- ** ©1991 WILLISoft
- **
- ** ==========================================================================
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <exec/types.h>
- #ifndef __GNUC__
- #include <clib/intuition_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/diskfont_protos.h>
- #endif
- #ifdef __GNUC__
- #include <proto/intuition.h>
- #include <proto/exec.h>
- #include <proto/graphics.h>
- #include <proto/diskfont.h>
- #endif
- #ifdef __SASC
- #include <proto/intuition.h>
- #include <proto/exec.h>
- #include <proto/graphics.h>
- #include <proto/diskfont.h>
- #endif
- #include "AmigaMem.h"
-
- #include "EmbossedGadget.h"
- #include "EmbossedGadgetClass.h"
- #include "minmax.h"
- #include "Precognition_Utils.h"
-
- #define WAITING 0
- #define PRESSED 1
-
- void EmbossedGadget_CleanUp( EmbossedGadget *self )
- {
- Afree( self->BoxBorder );
- self->BoxBorder = NULL;
- }
-
-
- tPoint EmbossedGadget_SetLocation( EmbossedGadget *self,
- PIXELS LeftEdge,
- PIXELS TopEdge )
- {
- Forbid(); /* Don't want Intuition looking at these while we modify em. */
- self->Location.x = self->g.LeftEdge = LeftEdge;
- self->Location.y = self->g.TopEdge = TopEdge;
- Permit();
-
- return self->Location;
- }
-
-
-
-
- tPoint EmbossedGadget_AskSize( EmbossedGadget *self,
- PIXELS Width,
- PIXELS Height )
- {
- tPoint size;
-
- size.x = MAX( Width, 6 );
- size.y = MAX( Height, 6 );
-
- return size;
- }
-
-
- tPoint EmbossedGadget_SetSize( EmbossedGadget *self,
- PIXELS Width,
- PIXELS Height )
- {
- tPoint size;
-
- size = AskSize( (GraphicObject *)self, Width, Height );
-
- Forbid(); /* Don't want Intuition looking at these while we modify em. */
- self->Size = size;
- self->g.Width = size.x;
- self->g.Height = size.y;
-
- pcg_Init3DBox( self->BoxBorder, 0, 0, size.x, size.y,
- self->Pens.BrightPen, self->Pens.DarkPen,
- self->BoxBorder->BottomRight.NextBorder );
- Permit();
-
- AlignText( &self->LabelText, Size( (GraphicObject *)self ) );
-
- return size;
- }
-
-
- Gadget *EmbossedGadget_FirstGadget( EmbossedGadget *self )
- {
- return &self->g;
- }
-
-
- USHORT EmbossedGadget_nGadgets( EmbossedGadget *self )
- {
- return 1;
- }
-
-
- ULONG EmbossedGadget_IDCMPFlags( EmbossedGadget *self )
- {
- ULONG flags;
- UWORD activation;
-
- activation = self->g.Activation;
- flags = ((activation & GADGIMMEDIATE) ? GADGETDOWN :0)
- | ((activation & RELVERIFY) ? GADGETUP :0)
- | ((activation & FOLLOWMOUSE) ? MOUSEMOVE :0);
- return flags;
- }
-
-
- USHORT EmbossedGadget_ClaimEvent( EmbossedGadget *self,
- IntuiMessage *event )
- {
- USHORT response = 0;
-
- switch( event->Class )
- {
- case REFRESHWINDOW:
- response = RESPONDED;
- break;
-
- case GADGETDOWN:
- case GADGETUP:
- if( event->IAddress == (void *)&self->g )
- {
- response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
- }
- break;
-
- case MOUSEBUTTONS: /* Duration events. */
- case INTUITICKS:
- if( self->state )
- {
- response = RESPONDED | CHANGED_STATE;
- }
- break;
- }
-
- return response;
- }
-
-
- USHORT EmbossedGadget_Respond( EmbossedGadget *self,
- IntuiMessage *Event )
- {
- USHORT response = 0;
- Window *window;
-
- switch( Event->Class )
- {
- case REFRESHWINDOW:
- Refresh( (Interactor *)self );
- response = RESPONDED;
- break;
-
- case GADGETDOWN:
- if( Event->IAddress == (void *)FirstGadget( (Interactor *)self ) )
- {
- /* EmbossedGadget_SelectRender( self, rport ); */
- if( self->g.Activation & GADGDURATION )
- {
- window = Event->IDCMPWindow;
- self->state = PRESSED;
- /* Save the original IDCMP settings. */
- self->IDCMPbuf = window->IDCMPFlags;
-
- if( ! ( self->g.Activation & FOLLOWMOUSE ) )
- {
- /*
- ** For Duration gadgets, on GADGETDOWN, INTUITICKS
- ** are turned on so the EmbossedGadget can get
- ** continuous messages.
- */
- ModifyIDCMP( window,
- window->IDCMPFlags | INTUITICKS | MOUSEBUTTONS );
- }
- }
- response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
- }
- break;
-
- case GADGETUP:
- if( Event->IAddress == (void *)FirstGadget( (Interactor *)self ) )
- {
- /* EmbossedGadget_SelectRenderRestore( self, rport ); */
- window = Event->IDCMPWindow;
- if( self->state ) /* Duration turned on */
- {
- self->state = WAITING;
- ModifyIDCMP( window, self->IDCMPbuf );
- }
-
- response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
- }
- break;
-
- case INTUITICKS:
- if( self->state )
- { /* User is still pressing gadget */
- response = RESPONDED | CHANGED_STATE;
- }
- break;
-
- case MOUSEBUTTONS:
- /* MouseButtons happen when the User moves the mouse off
- * off the gadget before releasing.
- */
- if( self->state )
- {
- window = Event->IDCMPWindow;
- self->state = WAITING;
- ModifyIDCMP( window, self->IDCMPbuf );
-
- response = RESPONDED | CHANGED_STATE;
- }
- break;
-
- case MOUSEMOVE:
- if( self->state )
- {
- response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
- }
- break;
-
- }
- return response;
- }
-
-
- void EmbossedGadget_Refresh( EmbossedGadget *self )
- {
- pcgWindow *window;
- RastPort *rport;
- Point loc;
-
- if( window = InteractorWindow( (Interactor *)self ) )
- {
- RefreshGList( FirstGadget( (Interactor *)self ), iWindow( window ), NULL,
- nGadgets( (Interactor *)self ) );
- if( self->LabelText.IText )
- {
- rport = RPort( window );
- loc = Location( (GraphicObject *)self );
- PrintIText( rport, (struct IntuiText *)&self->LabelText, loc.x, loc.y );
- }
- }
- }
-
- void EmbossedGadget_Render( EmbossedGadget *self, RastPort *rport )
- {
- PIXELS x, y;
- Point loc;
-
- x = self->g.LeftEdge;
- y = self->g.TopEdge;
-
- if( self->g.GadgetRender )
- {
- if( self->g.Flags & GADGIMAGE )
- {
- DrawImage( rport, (struct Image *)self->g.GadgetRender, x, y );
- }
- else
- {
- DrawBorder( rport, (struct Border *)self->g.GadgetRender, x, y );
- }
- }
-
- if( self->g.GadgetText )
- {
- PrintIText( rport, self->g.GadgetText, x, y );
- }
-
- if( self->LabelText.IText )
- {
- loc = Location( (GraphicObject *)self );
- PrintIText( rport, (struct IntuiText *)&self->LabelText, loc.x, loc.y );
- }
- }
-
- #if 0 /* not ready for prime time */
- void EmbossedGadget_SelectRender( EmbossedGadget *self, RastPort *rport )
- {
- PIXELS x, y;
- Point loc;
-
- x = self->g.LeftEdge;
- y = self->g.TopEdge;
-
- /* SetAPen( ??? ) */
- /* SetBPen( ??? ) */
- /* SetDrawMd( ??? ) */
- /* RectFill from (x,y) to (x+size.x, y+size.y) with select color (blue (3) ) */
- /* then draw in reverse colors */
-
- if( self->g.GadgetRender )
- {
- if( self->g.Flags & GADGIMAGE )
- {
- DrawImage( rport, (struct Image *)self->g.GadgetRender, x, y );
- }
- else
- {
- DrawBorder( rport, (struct Border *)self->g.GadgetRender, x, y );
- }
- }
-
- if( self->g.GadgetText )
- {
- PrintIText( rport, self->g.GadgetText, x, y );
- }
-
- if( self->LabelText.IText )
- {
- loc = Location( (GraphicObject *)self );
- PrintIText( rport, (struct IntuiText *)&self->LabelText, loc.x, loc.y );
- }
-
- /* Restore things to normalcy */
- /* SetAPen( ??? ) */
- /* SetBPen( ??? ) */
- /* SetDrawMd( ??? ) */
-
- }
- #endif /* not ready for prime time */
-
- #if 0 /* not ready for primetime */
- void EmbossedGadget_SelectRenderRestore( EmbossedGadget *self, RastPort *rport )
- {
-
- /* Restore things to normalcy */
- /* SetAPen( ??? ) */
- /* SetBPen( ??? ) */
- /* SetDrawMd( ??? ) */
- /* rectfill back to normal background */
- /* redraw in the normal state */
- EmbossedGadget_Render( self, rport );
-
- }
- #endif /* not ready for prime time */
-
- BOOL EmbossedGadget_EnableIactor( EmbossedGadget *self,
- BOOL enable )
- {
- struct pcgWindow *window;
- struct Window *iwindow;
- RastPort *rport;
- Gadget *g;
- PIXELS xmin, xmax, ymin, ymax;
- short i, ngadgets;
-
- window = InteractorWindow( (Interactor *)self );
- g = FirstGadget( (Interactor *)self );
- ngadgets = nGadgets( (Interactor *)self );
-
- if( enable )
- {
- if( window && ( rport = RPort( window ) ) ) /* Window is open */
- {
- for( i = 0; i < ngadgets; i++, g = g->NextGadget )
- {
- xmin = g->LeftEdge;
- ymin = g->TopEdge;
- xmax = xmin + g->Width - 1;
- ymax = ymin + g->Height - 1;
-
- OnGadget( g, window->Window, NULL );
-
- SetDrMd( rport, JAM1 );
- SetAPen( rport, self->Pens.BackPen );
- RectFill( rport, xmin, ymin, xmax, ymax );
- Refresh( (Interactor *)self );
- }
- }
- else
- {
- for( i = 0; i < ngadgets; i++, g = g->NextGadget )
- {
- g->Flags &= ( ~ GADGDISABLED );
- }
- }
- }
- else
- {
- if( window && ( iwindow = iWindow( window ) ) ) /* window is open. */
- {
- for( i = 0; i < ngadgets; i++, g = g->NextGadget )
- {
- OffGadget( g, iwindow, NULL );
- }
- }
- else
- {
- for( i = 0; i < ngadgets; i++, g = g->NextGadget )
- {
- g->Flags |= GADGDISABLED;
- }
- }
- }
-
- return enable;
- }
-
-
- BOOL EmbossedGadget_isEnabled( Interactor *self ) /*, FIXED? -- EDB */
- /* BOOL enable ) */ /* BROKEN? -- EDB */
- {
- Gadget *g;
-
- if( g = FirstGadget( self ) )
- return (BOOL)( ! ( g->Flags & GADGDISABLED ) );
- else
- return FALSE;
- }
-
-
- char *EmbossedGadget_Title( EmbossedGadget *self )
- {
- return (char *)self->LabelText.IText;
- }
-
- BOOL EmbossedGadget_SetTitle( EmbossedGadget *self,
- char *title )
- {
- Afree( self->LabelText.IText );
- self->LabelText.IText = Astrdup( title );
- AlignText( &self->LabelText, Size( (GraphicObject *)self ) );
-
- return TRUE;
- }
-
- /* EDB -- Added Default Font Support Methods */
- extern TextAttr go_DefaultFont;
-
- TextAttr *EmbossedGadget_DefaultFont( EmbossedGadget *self )
- {
- if( self->LabelText.ITextFont != NULL )
- return self->LabelText.ITextFont;
- else return &go_DefaultFont; /* Topaz80 */
- }
-
- BOOL EmbossedGadget_SetDefaultFont( EmbossedGadget *self, TextAttr *default_font )
- {
- struct TextFont *myfont;
-
- if( default_font != NULL )
- { /* check to see if font is really available */
- if( myfont = OpenDiskFont( default_font ) )
- {
- self->LabelText.ITextFont = default_font;
-
- CloseFont( myfont );
- /* Get ourselves back into alignment */
- AlignText( &self->LabelText, Size( (GraphicObject *)self ) );
- return TRUE;
- }
- else return FALSE; /* font is not available */
- }
- else return FALSE; /* pointer was invalid */
- }
-
- /* changed from AlignInfo to (struct AlignInfo *) -- EDB */
- struct AlignInfo *EmbossedGadget_TextAlignment( GraphicObject *self )
- {
- EmbossedGadget *us = NULL;
- us = (EmbossedGadget *)self;
- return( &(us->LabelText.alignment) );
- }
-
- /* changed from AlignInfo to (struct AlignInfo *) -- EDB */
- BOOL EmbossedGadget_SetTextAlignment( GraphicObject *self,
- UBYTE Flags,
- BYTE Xpad,
- BYTE Ypad )
- {
- EmbossedGadget *us = NULL;
- us = (EmbossedGadget *)self;
- us->LabelText.alignment.Flags = Flags;
- us->LabelText.alignment.Xpad = Xpad;
- us->LabelText.alignment.Ypad = Ypad;
- AlignText( &us->LabelText, Size( (GraphicObject *)self ) );
-
- return TRUE;
- }
-
-
- BOOL EmbossedGadget_elaborated = FALSE;
-
- struct InteractorClass EmbossedGadget_Class;
-
- void EmbossedGadgetClass_Init( struct InteractorClass *class )
- {
- InteractorClass_Init( class );
- class->isa = InteractorClass();
- class->ClassName = "EmbossedGadget";
- class->CleanUp = (void(*)(PObject *))EmbossedGadget_CleanUp;
- class->SetLocation = (Point(*)(GraphicObject *, PIXELS, PIXELS))EmbossedGadget_SetLocation;
- class->SetSize = (Point(*)(GraphicObject *, PIXELS, PIXELS))EmbossedGadget_SetSize;
- class->AskSize = (Point(*)(GraphicObject *, PIXELS, PIXELS))EmbossedGadget_AskSize;
- class->Render = (void(*)(GraphicObject *, RastPort *))EmbossedGadget_Render;
- class->FirstGadget = (Gadget*(*)(Interactor *))EmbossedGadget_FirstGadget;
- class->nGadgets = (USHORT(*)(Interactor *))EmbossedGadget_nGadgets;
- class->IDCMPFlags = (ULONG(*)(Interactor *))EmbossedGadget_IDCMPFlags;
- class->ClaimEvent = (USHORT(*)(Interactor *, IntuiMessage *))EmbossedGadget_ClaimEvent;
- class->Respond = (USHORT(*)(Interactor *, IntuiMessage *))EmbossedGadget_Respond;
- class->Refresh = (void(*)(Interactor *))EmbossedGadget_Refresh;
- class->EnableIactor= (BOOL(*)(Interactor *, BOOL))EmbossedGadget_EnableIactor;
- class->isEnabled = (BOOL(*)(Interactor *))EmbossedGadget_isEnabled;
- class->Activate = NULL;
- class->isActive = NULL;
- class->Title = (char*(*)(GraphicObject *))EmbossedGadget_Title;
- class->SetTitle = (BOOL(*)(GraphicObject *, char *))EmbossedGadget_SetTitle;
- class->DefaultFont = (TextAttr*(*)(GraphicObject *))EmbossedGadget_DefaultFont;
- class->SetDefaultFont = (BOOL(*)(GraphicObject *, TextAttr *))EmbossedGadget_SetDefaultFont;
- class->TextAlignment = (AlignInfo*(*)(GraphicObject *))EmbossedGadget_TextAlignment;
- class->SetTextAlignment = (BOOL(*)(GraphicObject *, UBYTE, BYTE, BYTE))EmbossedGadget_SetTextAlignment;
- }
-
-
- struct InteractorClass *EmbossedGadgetClass( void )
- {
- if( ! EmbossedGadget_elaborated )
- {
- EmbossedGadgetClass_Init( &EmbossedGadget_Class );
- EmbossedGadget_elaborated = TRUE;
- }
-
- return &EmbossedGadget_Class;
- }
-
-
-
- void EmbossedGadget_Init( EmbossedGadget *self,
- SHORT LeftEdge,
- SHORT TopEdge,
- SHORT Width,
- SHORT Height,
- USHORT Flags,
- USHORT Activation,
- USHORT GadgetType,
- pcg_3DPens Pens,
- char *Label )
- {
- Interactor_Init( (Interactor *)self );
-
- self->isa = EmbossedGadgetClass();
- self->Pens = Pens;
- self->BoxBorder = (pcg_3DBox *) Acalloc( 1, sizeof( pcg_3DBox ) );
- self->state = WAITING;
-
- self->LabelText.FrontPen = Pens.FrontPen;
- self->LabelText.BackPen = Pens.BackPen;
- self->LabelText.DrawMode = JAM1;
- self->LabelText.ITextFont = &go_DefaultFont; /* &pcg_Topaz80; */
- self->LabelText.IText = NULL;
- self->LabelText.NextText = NULL;
- self->LabelText.alignment.Flags = tx_INSIDE | tx_LEFT | tx_YCENTER;
- self->LabelText.alignment.Xpad = STD_XPAD;
- self->LabelText.alignment.Ypad = STD_YPAD;
-
- self->g.NextGadget = NULL;
- self->g.Flags = Flags;
- self->g.Activation = Activation;
- self->g.GadgetType = GadgetType;
- self->g.GadgetRender = (APTR) &self->BoxBorder->TopLeft;
- self->g.SelectRender = NULL;
- self->g.MutualExclude = 0L;
- self->g.SpecialInfo = NULL;
- self->g.GadgetID = 0;
- self->g.UserData = NULL;
- self->g.GadgetText = NULL;
-
- SetLocation( (GraphicObject *)self, LeftEdge, TopEdge );
- SetSize( (GraphicObject *)self, Width, Height );
- SetTitle( (GraphicObject *)self, Label );
-
- }
-
-