home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Library / slider.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-19  |  5.7 KB  |  236 lines

  1. #include <stdio.h>
  2. #include "minmax.h"
  3. #include "Slider.h"
  4. #include "SliderClass.h"
  5. #include "EmbossedGadgetClass.h"
  6. #ifndef __GNUC__
  7. #include <clib/exec_protos.h>
  8. #include <clib/intuition_protos.h>
  9. #include <clib/graphics_protos.h>
  10. #endif
  11. #ifdef __GNUC__
  12. #include <proto/exec.h>
  13. #include <proto/intuition.h>
  14. #include <proto/graphics.h>
  15. #endif
  16. #ifdef __SASC
  17. #include <proto/exec.h>
  18. #include <proto/intuition.h>
  19. #include <proto/graphics.h>
  20. #endif
  21. #include "amigamem.h"
  22.  
  23.  
  24. /* Slider 'state' setings. */
  25. #define WAITING    0
  26. #define DRAGGING   1
  27.  
  28.  
  29.  
  30.  
  31. void Slider_CleanUp( Slider *self )
  32. {
  33.    self->eg.g.SpecialInfo = NULL;
  34.  
  35.    Afree( self->eg.BoxBorder );
  36.    self->eg.BoxBorder = NULL;
  37. }
  38.  
  39.  
  40.  
  41. void Slider_Render( Slider *self, RastPort *RPort )
  42. {
  43.    DrawBorder( RPort, &self->eg.BoxBorder->TopLeft,
  44.       self->eg.Location.x, self->eg.Location.y );
  45. }
  46.  
  47.  
  48. void Slider_Refresh( Slider *self )
  49. {
  50.    struct pcgWindow *window;
  51.  
  52.    window = InteractorWindow( (Interactor *)self );
  53.  
  54.    Render( (GraphicObject *)self, window->Window->RPort );
  55.    EmbossedGadget_Refresh( (EmbossedGadget *)self );
  56. }
  57.  
  58.  
  59.  
  60. #define X_BORDER_WIDTH 2
  61. #define Y_BORDER_WIDTH 1
  62.  
  63. tPoint Slider_SetLocation(  Slider *self,
  64.                             PIXELS  LeftEdge,
  65.                             PIXELS  TopEdge )
  66. {
  67.    Forbid(); /* Don't want Intuition looking at these while we modify em. */
  68.    self->eg.g.LeftEdge  = LeftEdge + X_BORDER_WIDTH * 2;
  69.    self->eg.g.TopEdge   = TopEdge  + Y_BORDER_WIDTH * 2;
  70.  
  71.    self->eg.Location.x  = LeftEdge;
  72.    self->eg.Location.y  = TopEdge;
  73.  
  74.    Permit();
  75.  
  76.    return self->eg.Location;
  77. }
  78.  
  79.  
  80.  
  81. tPoint Slider_AskSize( Slider *self,
  82.                        PIXELS  Width,
  83.                        PIXELS  Height )
  84. {
  85.    tPoint size;
  86.  
  87.    size.x = MAX( Width,  10 );
  88.    size.y = MAX( Height, 10 );
  89.  
  90.    return size;
  91. }
  92.  
  93. tPoint Slider_SetSize( Slider *self,
  94.                        PIXELS  Width,
  95.                        PIXELS  Height )
  96. {
  97.    tPoint size;
  98.  
  99.    size = AskSize( (GraphicObject *)self, Width, Height );
  100.  
  101.  
  102.    Forbid(); /* Don't want Intuition looking at these while we modify em. */
  103.    self->eg.Size     = size;
  104.    self->eg.g.Width  = size.x - X_BORDER_WIDTH * 4;
  105.    self->eg.g.Height = size.y - Y_BORDER_WIDTH * 4;
  106.  
  107.    pcg_Init3DBox(  self->eg.BoxBorder, 0, 0, size.x, size.y,
  108.                    self->eg.Pens.BrightPen,  self->eg.Pens.DarkPen,
  109.                    self->eg.BoxBorder->BottomRight.NextBorder );
  110.  
  111.    AlignText( &self->eg.LabelText, Size( (GraphicObject *)self ) );
  112.  
  113.    Permit();
  114.    return size;
  115. }
  116.  
  117.  
  118.  
  119.  
  120. BOOL Slider_elaborated = FALSE;
  121.  
  122. struct PositionerClass Slider_Class;
  123.  
  124. void SliderClass_Init( struct PositionerClass *class )
  125. {
  126.    PositionerClass_Init( class );
  127.    EmbossedGadgetClass_Init( (struct InteractorClass *)class );
  128.    class->isa         = PositionerClass();
  129.    class->ClassName   = "Slider";
  130.    class->CleanUp     = (void(*)(PObject *))Slider_CleanUp;
  131.    class->SetLocation = (Point(*)(GraphicObject *, PIXELS, PIXELS))Slider_SetLocation;
  132.    class->SetSize     = (Point(*)(GraphicObject *, PIXELS, PIXELS))Slider_SetSize;
  133.    class->AskSize     = (Point(*)(GraphicObject *, PIXELS, PIXELS))Slider_AskSize;
  134.    class->Render      = (void(*)(GraphicObject *, RastPort *))Slider_Render;
  135.    class->Refresh     = (void(*)(Interactor *))Slider_Refresh;
  136.    class->Activate    = NULL;
  137.    class->isActive    = NULL;
  138. }
  139.  
  140.  
  141. struct PositionerClass *SliderClass( void )
  142. {
  143.    if( ! Slider_elaborated )
  144.    {
  145.       SliderClass_Init( &Slider_Class );
  146.       Slider_elaborated = TRUE;
  147.    }
  148.  
  149.    return &Slider_Class;
  150. }
  151.  
  152.  
  153. #define V36_PROPNEWLOOK 0x0010
  154.    /*
  155.    ** This flag turns on the 3D look of the autoknob under Workbench 2.0
  156.    ** It's ignored under 1.3
  157.    **
  158.    ** I've redefined it here so that I can compile under 1.3 too.
  159.    */
  160.  
  161. void Slider_Init( Slider    *self,
  162.                   PIXELS     LeftEdge,
  163.                   PIXELS     TopEdge,
  164.                   PIXELS     Width,
  165.                   PIXELS     Height,
  166.                   pcg_3DPens Pens )
  167. {
  168.    Point size;
  169.  
  170.     /* Remove GADGHCOMP -- EDB */
  171.    EmbossedGadget_Init( (EmbossedGadget *)self, LeftEdge, TopEdge, Width, Height,
  172.      GADGHCOMP /* GFLG_GADGHNONE */, GADGIMMEDIATE | RELVERIFY | FOLLOWMOUSE, PROPGADGET, Pens, NULL );
  173.  
  174.    size = Slider_AskSize( self, Width, Height );
  175.  
  176.    self->eg.isa = SliderClass();
  177.    self->eg.Size = size;
  178.  
  179.    self->eg.g.LeftEdge         = LeftEdge + X_BORDER_WIDTH*2;
  180.    self->eg.g.TopEdge          = TopEdge  + Y_BORDER_WIDTH*2;
  181.    self->eg.g.Width            = Width    - X_BORDER_WIDTH*4;
  182.    self->eg.g.Height           = Height   - Y_BORDER_WIDTH*4;
  183.    self->eg.g.GadgetRender     = (APTR) &(self->AutoKnob);
  184.    self->eg.g.SelectRender     = NULL;
  185.    self->eg.g.SpecialInfo      = (APTR) &(self->Prop);
  186.  
  187.    self->Prop.Flags       = AUTOKNOB | PROPBORDERLESS | V36_PROPNEWLOOK;
  188.    self->Prop.HorizPot    = 0x8000;
  189.    self->Prop.VertPot     = 0x8000;
  190.    self->Prop.HorizBody   = 0xFFFF;
  191.    self->Prop.VertBody    = 0xFFFF;
  192.    self->Prop.CWidth      = 0;
  193.    self->Prop.CHeight     = 0;
  194.    self->Prop.HPotRes     = 0;
  195.    self->Prop.VPotRes     = 0;
  196.    self->Prop.LeftBorder  = 0;
  197.    self->Prop.TopBorder   = 0;
  198.  
  199.    SetLocation( (GraphicObject *)self, LeftEdge, TopEdge );
  200.    SetSize    ( (GraphicObject *)self, Width, Height );
  201. }
  202.  
  203.  
  204. void SlideLower( Slider *self )
  205. {
  206.    long    position;
  207.    USHORT   delta, value;
  208.  
  209.    delta = KnobSize( (Positioner *)self ) /2;
  210.    delta = MAX( delta, 1 );
  211.  
  212.    value = Value( (Valuator *)self );
  213.    position = value - delta;
  214.    position = MAX( position, 0 );
  215.  
  216.    SetValue( (Valuator *)self, position );
  217. }
  218.  
  219.  
  220. void SlideHigher( Slider *self )
  221. {
  222.    ULONG  position;
  223.    USHORT delta;
  224.    USHORT value;
  225.  
  226.    delta = KnobSize( (Positioner *)self ) /2;
  227.    delta = MAX( delta, 1 );
  228.    value = Value( (Valuator *)self );
  229.  
  230.    position = value + delta;
  231.    position = MIN( position, 0xFFFF );
  232.  
  233.    SetValue( (Valuator *)self, position );
  234. }
  235.  
  236.