home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "minmax.h"
- #include "Slider.h"
- #include "SliderClass.h"
- #include "EmbossedGadgetClass.h"
- #ifndef __GNUC__
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
- #endif
- #ifdef __GNUC__
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #endif
- #ifdef __SASC
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #endif
- #include "amigamem.h"
-
-
- /* Slider 'state' setings. */
- #define WAITING 0
- #define DRAGGING 1
-
-
-
-
- void Slider_CleanUp( Slider *self )
- {
- self->eg.g.SpecialInfo = NULL;
-
- Afree( self->eg.BoxBorder );
- self->eg.BoxBorder = NULL;
- }
-
-
-
- void Slider_Render( Slider *self, RastPort *RPort )
- {
- DrawBorder( RPort, &self->eg.BoxBorder->TopLeft,
- self->eg.Location.x, self->eg.Location.y );
- }
-
-
- void Slider_Refresh( Slider *self )
- {
- struct pcgWindow *window;
-
- window = InteractorWindow( (Interactor *)self );
-
- Render( (GraphicObject *)self, window->Window->RPort );
- EmbossedGadget_Refresh( (EmbossedGadget *)self );
- }
-
-
-
- #define X_BORDER_WIDTH 2
- #define Y_BORDER_WIDTH 1
-
- tPoint Slider_SetLocation( Slider *self,
- PIXELS LeftEdge,
- PIXELS TopEdge )
- {
- Forbid(); /* Don't want Intuition looking at these while we modify em. */
- self->eg.g.LeftEdge = LeftEdge + X_BORDER_WIDTH * 2;
- self->eg.g.TopEdge = TopEdge + Y_BORDER_WIDTH * 2;
-
- self->eg.Location.x = LeftEdge;
- self->eg.Location.y = TopEdge;
-
- Permit();
-
- return self->eg.Location;
- }
-
-
-
- tPoint Slider_AskSize( Slider *self,
- PIXELS Width,
- PIXELS Height )
- {
- tPoint size;
-
- size.x = MAX( Width, 10 );
- size.y = MAX( Height, 10 );
-
- return size;
- }
-
- tPoint Slider_SetSize( Slider *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->eg.Size = size;
- self->eg.g.Width = size.x - X_BORDER_WIDTH * 4;
- self->eg.g.Height = size.y - Y_BORDER_WIDTH * 4;
-
- pcg_Init3DBox( self->eg.BoxBorder, 0, 0, size.x, size.y,
- self->eg.Pens.BrightPen, self->eg.Pens.DarkPen,
- self->eg.BoxBorder->BottomRight.NextBorder );
-
- AlignText( &self->eg.LabelText, Size( (GraphicObject *)self ) );
-
- Permit();
- return size;
- }
-
-
-
-
- BOOL Slider_elaborated = FALSE;
-
- struct PositionerClass Slider_Class;
-
- void SliderClass_Init( struct PositionerClass *class )
- {
- PositionerClass_Init( class );
- EmbossedGadgetClass_Init( (struct InteractorClass *)class );
- class->isa = PositionerClass();
- class->ClassName = "Slider";
- class->CleanUp = (void(*)(PObject *))Slider_CleanUp;
- class->SetLocation = (Point(*)(GraphicObject *, PIXELS, PIXELS))Slider_SetLocation;
- class->SetSize = (Point(*)(GraphicObject *, PIXELS, PIXELS))Slider_SetSize;
- class->AskSize = (Point(*)(GraphicObject *, PIXELS, PIXELS))Slider_AskSize;
- class->Render = (void(*)(GraphicObject *, RastPort *))Slider_Render;
- class->Refresh = (void(*)(Interactor *))Slider_Refresh;
- class->Activate = NULL;
- class->isActive = NULL;
- }
-
-
- struct PositionerClass *SliderClass( void )
- {
- if( ! Slider_elaborated )
- {
- SliderClass_Init( &Slider_Class );
- Slider_elaborated = TRUE;
- }
-
- return &Slider_Class;
- }
-
-
- #define V36_PROPNEWLOOK 0x0010
- /*
- ** This flag turns on the 3D look of the autoknob under Workbench 2.0
- ** It's ignored under 1.3
- **
- ** I've redefined it here so that I can compile under 1.3 too.
- */
-
- void Slider_Init( Slider *self,
- PIXELS LeftEdge,
- PIXELS TopEdge,
- PIXELS Width,
- PIXELS Height,
- pcg_3DPens Pens )
- {
- Point size;
-
- /* Remove GADGHCOMP -- EDB */
- EmbossedGadget_Init( (EmbossedGadget *)self, LeftEdge, TopEdge, Width, Height,
- GADGHCOMP /* GFLG_GADGHNONE */, GADGIMMEDIATE | RELVERIFY | FOLLOWMOUSE, PROPGADGET, Pens, NULL );
-
- size = Slider_AskSize( self, Width, Height );
-
- self->eg.isa = SliderClass();
- self->eg.Size = size;
-
- self->eg.g.LeftEdge = LeftEdge + X_BORDER_WIDTH*2;
- self->eg.g.TopEdge = TopEdge + Y_BORDER_WIDTH*2;
- self->eg.g.Width = Width - X_BORDER_WIDTH*4;
- self->eg.g.Height = Height - Y_BORDER_WIDTH*4;
- self->eg.g.GadgetRender = (APTR) &(self->AutoKnob);
- self->eg.g.SelectRender = NULL;
- self->eg.g.SpecialInfo = (APTR) &(self->Prop);
-
- self->Prop.Flags = AUTOKNOB | PROPBORDERLESS | V36_PROPNEWLOOK;
- self->Prop.HorizPot = 0x8000;
- self->Prop.VertPot = 0x8000;
- self->Prop.HorizBody = 0xFFFF;
- self->Prop.VertBody = 0xFFFF;
- self->Prop.CWidth = 0;
- self->Prop.CHeight = 0;
- self->Prop.HPotRes = 0;
- self->Prop.VPotRes = 0;
- self->Prop.LeftBorder = 0;
- self->Prop.TopBorder = 0;
-
- SetLocation( (GraphicObject *)self, LeftEdge, TopEdge );
- SetSize ( (GraphicObject *)self, Width, Height );
- }
-
-
- void SlideLower( Slider *self )
- {
- long position;
- USHORT delta, value;
-
- delta = KnobSize( (Positioner *)self ) /2;
- delta = MAX( delta, 1 );
-
- value = Value( (Valuator *)self );
- position = value - delta;
- position = MAX( position, 0 );
-
- SetValue( (Valuator *)self, position );
- }
-
-
- void SlideHigher( Slider *self )
- {
- ULONG position;
- USHORT delta;
- USHORT value;
-
- delta = KnobSize( (Positioner *)self ) /2;
- delta = MAX( delta, 1 );
- value = Value( (Valuator *)self );
-
- position = value + delta;
- position = MIN( position, 0xFFFF );
-
- SetValue( (Valuator *)self, position );
- }
-
-