home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
prog
/
c
/
precg105.lha
/
source
/
cyclegadget.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-04
|
9KB
|
366 lines
#include <stdio.h>
#include "CycleGadget.h"
#include "CycleGadgetClass.h"
#include "BoolGadgetClass.h"
#include "precognition.h"
#include "minmax.h"
#include "AmigaMem.h"
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
void CycleGadget_CleanUp( CycleGadget *self )
{
Afree( self->bg.BoxBorder->BottomRight.NextBorder );
self->bg.BoxBorder->BottomRight.NextBorder = NULL;
StringList_CleanUp( &self->sl );
}
Point CycleGadget_AskSize( CycleGadget *self,
PIXELS Width,
PIXELS Height )
{
Point size;
size.y = 14;
size.x = MAX( Width, 32 );
return size;
}
USHORT CycleGadget_ClaimEvent( CycleGadget *self,
IntuiMessage *event )
{
USHORT response = 0;
switch (event->Class)
{
case REFRESHWINDOW:
response = RESPONDED;
break;
case GADGETUP:
if (event->IAddress == (void*) &self->bg.g)
{
response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
}
break;
}
return response;
}
LONG CycleGadget_Value( CycleGadget *self )
{
return (LONG) self->bg.state;
}
LONG CycleGadget_SetValue( CycleGadget *self,
LONG selection )
{
USHORT s;
s = MIN( selection, self->sl.nEntries );
s = MAX( s, 0 );
self->bg.state = s;
Forbid();
self->Format.IText = self->sl.Entries[s];
Permit();
return (LONG) s;
}
#ifdef BUILDER
LONG CycleGadget_SV_NoRangeCheck( CycleGadget *self,
LONG selection )
{
USHORT s;
self->bg.state = s;
return (LONG) s;
}
#endif
void CycleGadget_Render( CycleGadget *self,
RastPort *RPort )
{
PIXELS xmin, xmax, ymin, ymax;
xmin = self->bg.Location.x + 2;
ymin = self->bg.Location.y + 2;
xmax = xmin + self->bg.Size.x - 4;
ymax = ymin + self->bg.Size.y - 4;
SetAPen( RPort, self->bg.Pens.BackPen );
SetDrMd( RPort, JAM1 );
RectFill( RPort, xmin, ymin, xmax, ymax );
SetAPen( RPort, self->bg.Pens.FrontPen );
PrintIText( RPort, &self->Format, self->bg.Location.x, self->bg.Location.y );
EmbossedGadget_Render( &self->bg, RPort );
}
void CycleGadget_Refresh( CycleGadget *self )
{
pcgWindow *window;
RastPort *rport;
Point loc;
if (window = InteractorWindow(self))
{
EmbossedGadget_Refresh(self);
rport = RPort( window );
loc = Location(self);
PrintIText( rport, &self->Format, loc.x, loc.y );
}
}
USHORT CycleGadget_Respond( CycleGadget *self,
IntuiMessage *event )
{
USHORT response = 0;
Window *window;
USHORT selection;
switch (event->Class)
{
case REFRESHWINDOW:
response = RESPONDED;
break;
case GADGETUP:
if (event->IAddress == (void*) &self->bg.g)
{
window = event->IDCMPWindow;
selection = self->bg.state + 1;
if (selection == self->sl.nEntries)
selection = 0;
SetValue( self, selection );
Render( self, window->RPort );
response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
}
break;
}
return response;
}
#ifdef BUILDER
#include "BuilderMethods.h"
#include "GraphicObject_Builder.h"
#include "CycleGadget_builder.h"
#include "CycleGadget_coder.h"
#include "CycleGadgetIO.h"
#include <string.h>
CycleGadget *CycleGadget_New( CycleGadget *self )
{
CycleGadget *cycle = NULL;
USHORT i;
char **choices;
if (cycle = (CycleGadget *) Amalloc(sizeof(CycleGadget)))
{
if (self)
{
StringList *sl;
sl = &(self->sl);
choices = (char**) Acalloc( sizeof(char*), sl->nEntries+1 );
for (i=0; i<sl->nEntries; i++)
{
choices[i] = sl->Entries[i];
}
choices[sl->nEntries] = NULL;
CycleGadget_Init( cycle,
self->bg.Location.x, self->bg.Location.y,
self->bg.Size.x, self->bg.Pens,
Title(self), choices );
Afree(choices);
}
else
{
CycleGadget_Init( cycle, 0, 0, 64, StandardPens(), NULL, NULL );
}
GiveItAName( cycle );
}
return cycle;
}
struct BuilderMethods CycleGadget_bm;
#endif
BOOL CycleGadget_elaborated = FALSE;
struct ValuatorClass CycleGadget_Class;
void CycleGadgetClass_Init( struct ValuatorClass *class )
{
BoolGadgetClass_Init( class );
class->isa = BoolGadgetClass();
class->ClassName = "CycleGadget";
/* -------- Commented-out methods are inherited ----------------*/
class->CleanUp = CycleGadget_CleanUp;
class->AskSize = CycleGadget_AskSize;
class->SizeFlags = GraphicObject_SizeFlagsX;
class->Render = CycleGadget_Render;
class->Refresh = CycleGadget_Refresh;
class->ClaimEvent = CycleGadget_ClaimEvent;
class->Respond = CycleGadget_Respond;
class->Value = CycleGadget_Value;
class->SetValue = CycleGadget_SetValue;
/* class->SetTitle = EmbossedGadget_SetTitle;*/
#ifdef BUILDER
go_InitBuilderMethods( &CycleGadget_bm );
class->BuilderMethods = &CycleGadget_bm;
CycleGadget_bm.New = CycleGadget_New;
CycleGadget_bm.PropEdit = CycleGadget_PropEdit;
CycleGadget_bm.WriteCode = CycleGadget_WriteCode;
CycleGadget_bm.WriteIFF = WriteCycleGadgetChunk;
CycleGadget_bm.ReadIFF = ReadCycleGadgetChunk;
#endif
}
struct ValuatorClass *CycleGadgetClass( void )
{
if (! CycleGadget_elaborated)
{
CycleGadgetClass_Init( &CycleGadget_Class );
CycleGadget_elaborated = TRUE;
}
return &CycleGadget_Class;
}
WORD Cycle_BrightLinePoints[] = { 15,1, 15,12 };
WORD Cycle_DarkLinePoints[] = { 14,1, 14,12 };
WORD Cycle_ArrowPoints[] =
{ 10,3, 10, 7, 12,5, 7,5, 9,7, 9,2, 5,2,
4,3, 4,10, 5,3, 5,11, 9,11, 9,10, 10,10 };
typedef struct CycleBorder
{
Border BrightLine;
Border DarkLine;
Border Arrow;
} CycleBorder;
CycleBorder *CycleBorder_New( pcg_3DPens Pens )
{
CycleBorder *border;
border = (CycleBorder *) Acalloc( 1, sizeof(CycleBorder) );
border->BrightLine.LeftEdge = 0;
border->BrightLine.TopEdge = 0;
border->BrightLine.FrontPen = Pens.BrightPen;
border->BrightLine.BackPen = Pens.BackPen;
border->BrightLine.DrawMode = JAM1;
border->BrightLine.Count = 2;
border->BrightLine.XY = Cycle_BrightLinePoints;
border->BrightLine.NextBorder = &border->DarkLine;
border->DarkLine.LeftEdge = 0;
border->DarkLine.TopEdge = 0;
border->DarkLine.FrontPen = Pens.DarkPen;
border->DarkLine.BackPen = Pens.BackPen;
border->DarkLine.DrawMode = JAM1;
border->DarkLine.Count = 2;
border->DarkLine.XY = Cycle_DarkLinePoints;
border->DarkLine.NextBorder = &border->Arrow;
border->Arrow.LeftEdge = 0;
border->Arrow.TopEdge = 0;
border->Arrow.FrontPen = Pens.FrontPen;
border->Arrow.BackPen = Pens.BackPen;
border->Arrow.DrawMode = JAM1;
border->Arrow.Count = 14;
border->Arrow.XY = Cycle_ArrowPoints;
border->Arrow.NextBorder = NULL;
return border;
}
void CycleGadget_Init( CycleGadget *self,
PIXELS LeftEdge,
PIXELS TopEdge,
PIXELS Width,
pcg_3DPens Pens,
char *label,
char **Choices )
{
Point size;
AlignInfo ainfo;
self->bg.isa = CycleGadgetClass();
size = AskSize( self, Width, 0 );
BoolGadget_Init( &self->bg, LeftEdge, TopEdge, size.x, size.y,
Pens, NULL );
ainfo = TextAlignment(self);
SetTextAlignment( self, tx_OUTSIDE | tx_LEFT | tx_YCENTER,
ainfo.Xpad, ainfo.Ypad );
self->bg.isa = CycleGadgetClass();
self->bg.g.Flags = GADGHCOMP;
self->bg.BoxBorder->BottomRight.NextBorder =
(Border *) CycleBorder_New(Pens);
StringList_Init( &self->sl, FALSE );
self->bg.state = 0;
self->bg.LabelText.NextText = &self->Format;
self->Format.FrontPen = Pens.FrontPen;
self->Format.BackPen = Pens.BackPen;
self->Format.DrawMode = JAM1;
self->Format.LeftEdge = 20;
self->Format.TopEdge = 3;
self->Format.ITextFont = &pcg_Topaz80;
self->Format.IText = (Choices ? Choices[0] : NULL);
self->Format.NextText = NULL;
if (Choices)
StringList_AddStrings( &self->sl, Choices, 0 );
SetTitle( self, label );
}