home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / term43-source.lha / Extras / Source / gtlayout-Source.lha / LTP_LevelImage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-20  |  9.9 KB  |  383 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1994 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. #ifdef DO_LEVEL_KIND
  10. VOID __regargs
  11. LTP_DrawLevelImageLeft(struct RastPort *RPort,struct DrawInfo *DrawInfo,LevelImageInfo *Level,struct Image *Image,WORD Left,WORD Top,WORD Width,WORD Height,WORD OffsetX,WORD OffsetY)
  12. {
  13.     WORD    BorderTop    = Level -> KnobTop,
  14.         BorderLeft    = Level -> KnobWidth;
  15.  
  16.     Left    += OffsetX;
  17.     Top    += OffsetY;
  18.  
  19.     if(Width > 0)
  20.     {
  21.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHADOWPEN]);
  22.  
  23.         Move(RPort,Left,Top);
  24.         Draw(RPort,Left,Top + Height - 1);
  25.  
  26.         if(Width > 1)
  27.         {
  28.             Move(RPort,Left + 1,Top);
  29.             Draw(RPort,Left + 1,Top + Height - 2);
  30.  
  31.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHINEPEN]);
  32.  
  33.             WritePixel(RPort,Left + 1,Top + Height - 1);
  34.  
  35.             if(Width > 2)
  36.             {
  37.                 Move(RPort,Left + 2,Top + Height - 1);
  38.                 Draw(RPort,Left + Width - 1,Top + Height - 1);
  39.  
  40.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHADOWPEN]);
  41.  
  42.                 Move(RPort,Left + 2,Top);
  43.                 Draw(RPort,Left + Width - 1,Top);
  44.  
  45.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[FILLPEN]);
  46.  
  47.                 RectFill(RPort,Left + 2,Top + 1,Left + Width - 1,Top + Height - 2);
  48.             }
  49.         }
  50.  
  51.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  52.  
  53.         RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top - 1);
  54.         RectFill(RPort,Left,Top + Height,Left + Width - 1,Top + Height + BorderTop - 1);
  55.         RectFill(RPort,Left - BorderLeft,Top - BorderTop,Left - 1,Top + Height + BorderTop - 1);
  56.     }
  57.     else
  58.     {
  59.         if(Level -> Position < BorderLeft)
  60.         {
  61.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  62.  
  63.             Left    = Image -> LeftEdge + OffsetX;
  64.             Width    = Level -> Position;
  65.  
  66.             if(Width > 0)
  67.                 RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top + Height + BorderTop - 1);
  68.         }
  69.     }
  70. }
  71.  
  72. VOID __regargs
  73. LTP_DrawLevelImageRight(struct RastPort *RPort,struct DrawInfo *DrawInfo,LevelImageInfo *Level,struct Image *Image,WORD Left,WORD Top,WORD Width,WORD Height,WORD OffsetX,WORD OffsetY)
  74. {
  75.     WORD    BorderTop    = Level -> KnobTop,
  76.         BorderLeft    = Level -> KnobWidth;
  77.  
  78.     Left    += OffsetX;
  79.     Top    += OffsetY;
  80.  
  81.     if(Width > 0)
  82.     {
  83.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHINEPEN]);
  84.  
  85.         Move(RPort,Left + Width - 1,Top);
  86.         Draw(RPort,Left + Width - 1,Top + Height - 1);
  87.  
  88.         if(Width > 1)
  89.         {
  90.             Move(RPort,Left + Width - 2,Top + 1);
  91.             Draw(RPort,Left + Width - 2,Top + Height - 1);
  92.  
  93.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHADOWPEN]);
  94.  
  95.             WritePixel(RPort,Left + Width - 2,Top);
  96.  
  97.             if(Width > 2)
  98.             {
  99.                 Move(RPort,Left,Top);
  100.                 Draw(RPort,Left + Width - 3,Top);
  101.  
  102.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHINEPEN]);
  103.  
  104.                 Move(RPort,Left,Top + Height - 1);
  105.                 Draw(RPort,Left + Width - 3,Top + Height - 1);
  106.  
  107.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  108.  
  109.                 RectFill(RPort,Left,Top + 1,Left + Width - 3,Top + Height - 2);
  110.             }
  111.         }
  112.  
  113.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  114.  
  115.         RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top - 1);
  116.         RectFill(RPort,Left,Top + Height,Left + Width - 1,Top + Height + BorderTop - 1);
  117.         RectFill(RPort,Left + Width,Top - BorderTop,Left + Width + BorderLeft - 1,Top + Height + BorderTop - 1);
  118.     }
  119.     else
  120.     {
  121.         Width = Image -> Width - (Level -> Position + 2 * BorderLeft);
  122.  
  123.         if(Width > 0)
  124.         {
  125.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  126.  
  127.             Left = Image -> LeftEdge + OffsetX + 2 * BorderLeft + Level -> Position;
  128.  
  129.             if(Width > 0)
  130.                 RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top + Height + BorderTop - 1);
  131.         }
  132.     }
  133. }
  134.  
  135. VOID __regargs
  136. LTP_DrawLevelImageKnob(struct RastPort *RPort,struct DrawInfo *DrawInfo,WORD Left,WORD Top,WORD Width,WORD Height,LevelImageInfo *Level,BOOL Selected)
  137. {
  138.     UWORD    Shine    = DrawInfo -> dri_Pens[SHINEPEN],
  139.         Shadow    = DrawInfo -> dri_Pens[SHADOWPEN],
  140.         Fill    = Selected ? DrawInfo -> dri_Pens[FILLPEN] : DrawInfo -> dri_Pens[BACKGROUNDPEN],
  141.         Back    = DrawInfo -> dri_Pens[BACKGROUNDPEN];
  142.  
  143.     Width = Level -> KnobWidth * 2;
  144.  
  145.     Left += Level -> Position - Level -> KnobWidth;
  146.  
  147.     if((Fill == Shine || Fill == Shadow) && Fill != Back)
  148.         Shine = Shadow = Back;
  149.  
  150.     LTP_SetAPen(RPort,Fill);
  151.  
  152.     RectFill(RPort,Left + 2,Top + 1,Left + 2 + Width - 3,Top + Height - 1);
  153.  
  154.     LTP_SetAPen(RPort,Shine);
  155.  
  156.     Move(RPort,Left + 1,Top + 1);
  157.     Draw(RPort,Left + 1,Top + Height - 2);
  158.     Draw(RPort,Left,Top + Height - 1);
  159.     Draw(RPort,Left,Top);
  160.     Draw(RPort,Left + Width - 2,Top);
  161.  
  162.     Move(RPort,Left + Width / 2,Top + 2);
  163.     Draw(RPort,Left + Width / 2,Top + Height - 3);
  164.  
  165.     LTP_SetAPen(RPort,Shadow);
  166.  
  167.     Move(RPort,Left + Width - 2,Top + Height - 2);
  168.     Draw(RPort,Left + Width - 2,Top + 1);
  169.     Draw(RPort,Left + Width - 1,Top);
  170.     Draw(RPort,Left + Width - 1,Top + Height - 1);
  171.     Draw(RPort,Left + 1,Top + Height - 1);
  172.  
  173.     Move(RPort,Left + Width / 2 - 1,Top + 2);
  174.     Draw(RPort,Left + Width / 2 - 1,Top + Height - 3);
  175. }
  176.  
  177. VOID __regargs
  178. LTP_DrawLevelImageComplete(struct Image *Image,struct RastPort *RPort,struct DrawInfo *DrawInfo,LevelImageInfo *Level,WORD OffsetX,WORD OffsetY,BOOL Selected)
  179. {
  180.     WORD    BorderTop    = Level -> KnobTop,
  181.         BorderLeft    = Level -> KnobWidth,
  182.         Left,Top,
  183.         Width,Height;
  184.     LONG    Position;
  185.  
  186.     Left    = Image -> LeftEdge + BorderLeft;
  187.     Top    = Image -> TopEdge + BorderTop;
  188.     Width    = Image -> Width - 2 * BorderLeft;
  189.     Height    = Image -> Height - 2 * BorderTop;
  190.  
  191.     Position = Level -> Position + Left;
  192.  
  193.     SetAfPt(RPort,NULL,0);
  194.  
  195.     LTP_DrawLevelImageKnob(RPort,DrawInfo,Image -> LeftEdge + BorderLeft + OffsetX,Image -> TopEdge + OffsetY,Image -> Width - 2 * BorderLeft,Image -> Height,Level,Selected);
  196.     LTP_DrawLevelImageLeft(RPort,DrawInfo,Level,Image,Left,Top,Position - BorderLeft - Left,Height,OffsetX,OffsetY);
  197.     LTP_DrawLevelImageRight(RPort,DrawInfo,Level,Image,Position + BorderLeft,Top,Left + Width - (Position + BorderLeft),Height,OffsetX,OffsetY);
  198. }
  199.  
  200. ULONG __regargs
  201. LTP_LevelClassDraw(struct Image *Image,struct impDraw *DrawMsg,LevelImageInfo *Level)
  202. {
  203.     struct RastPort *RPort = DrawMsg -> imp_RPort;
  204.  
  205.     if(RPort -> Layer)
  206.         LockLayerRom(RPort -> Layer);
  207.  
  208.     LTP_DrawLevelImageComplete(Image,RPort,Level -> DrawInfo,Level,DrawMsg -> imp_Offset . X,DrawMsg -> imp_Offset . Y,DrawMsg -> imp_State == IDS_SELECTED);
  209.  
  210.     if(DrawMsg -> imp_State == IDS_DISABLED)
  211.     {
  212.         WORD    Left    = Image -> LeftEdge    + DrawMsg -> imp_Offset . X,
  213.             Top    = Image -> TopEdge    + DrawMsg -> imp_Offset . Y;
  214.  
  215.         LTP_SetPens(RPort,Level -> DrawInfo -> dri_Pens[BLOCKPEN],0,JAM1);
  216.  
  217.         SetAfPt(RPort,(UWORD *)&ghostingPat,1);
  218.         RectFill(RPort,Left,Top,Left + Image -> Width - 1,Top + Image -> Height - 1);
  219.         SetAfPt(RPort,NULL,0);
  220.     }
  221.  
  222.     if(RPort -> Layer)
  223.         UnlockLayerRom(RPort -> Layer);
  224.  
  225.     return(TRUE);
  226. }
  227.  
  228. ULONG __regargs
  229. LTP_LevelClassSet(Class *class,struct Image *Image,struct opSet *SetMsg)
  230. {
  231.     LevelImageInfo    *Level = (LevelImageInfo *)INST_DATA(class,Image);
  232.     struct TagItem    *Item;
  233.     LONG         Width = Image -> Width - 2 * Level -> KnobWidth;
  234.  
  235.     if(Item = FindTagItem(LVIA_Current,SetMsg -> ops_AttrList))
  236.         Level -> Current = Item -> ti_Data;
  237.  
  238.     if(Item = FindTagItem(LVIA_Max,SetMsg -> ops_AttrList))
  239.         Level -> Max = Item -> ti_Data;
  240.  
  241.     if(Item = FindTagItem(LVIA_Position,SetMsg -> ops_AttrList))
  242.     {
  243.         LONG Position = Item -> ti_Data;
  244.  
  245.         if(Position < 0 || !Level -> Max)
  246.             Position = 0;
  247.         else
  248.         {
  249.             if(Position > Width)
  250.                 Position = Width;
  251.         }
  252.  
  253.         Level -> Position = Position;
  254.     }
  255.     else
  256.     {
  257.         if(Level -> Max)
  258.             Level -> Position = (Width * Level -> Current) / Level -> Max;
  259.         else
  260.             Level -> Position = 0;
  261.     }
  262.  
  263.     return(DoSuperMethodA(class,(Object *)Image,SetMsg));
  264. }
  265.  
  266. ULONG __regargs
  267. LTP_LevelClassGet(Class *class,struct Image *Image,struct opGet *GetMsg)
  268. {
  269.     LevelImageInfo *Level = (LevelImageInfo *)INST_DATA(class,Image);
  270.  
  271.     switch(GetMsg -> opg_AttrID)
  272.     {
  273.         case LVIA_Current:
  274.  
  275.             *GetMsg -> opg_Storage = Level -> Current;
  276.  
  277.             return(TRUE);
  278.  
  279.         case LVIA_Max:
  280.  
  281.             *GetMsg -> opg_Storage = Level -> Max;
  282.  
  283.             return(TRUE);
  284.  
  285.         case LVIA_Position:
  286.  
  287.             *GetMsg -> opg_Storage = Level -> Position;
  288.  
  289.             return(TRUE);
  290.  
  291.         case LVIA_KnobWidth:
  292.  
  293.             *GetMsg -> opg_Storage = Level -> KnobWidth;
  294.  
  295.             return(TRUE);
  296.     }
  297.  
  298.     return(DoSuperMethodA(class,(Object *)Image,GetMsg));
  299. }
  300.  
  301. ULONG __regargs
  302. LTP_LevelClassNew(Class *class,Object *object,struct opSet *SetMsg)
  303. {
  304.     LONG         Width        = GetTagData(IA_Width,0,SetMsg -> ops_AttrList),
  305.              Height     = GetTagData(IA_Height,0,SetMsg -> ops_AttrList);
  306.     UWORD         FontWidth    = GetTagData(LVIA_FontWidth,0,SetMsg -> ops_AttrList);
  307.     struct DrawInfo *DrawInfo    = (struct DrawInfo *)GetTagData(LVIA_DrawInfo,NULL,SetMsg -> ops_AttrList);
  308.  
  309.     if(Width && Height >= 4 && DrawInfo)
  310.     {
  311.         struct Image *Image;
  312.  
  313.         if(Image = (struct Image *)DoSuperMethodA(class,object,(Msg)SetMsg))
  314.         {
  315.             LevelImageInfo    *Level = (LevelImageInfo *)INST_DATA(class,Image);
  316.             WORD         QuarterWidth,
  317.                      KnobWidth,
  318.                      LevelHeight;
  319.             LONG         Current    = GetTagData(LVIA_Current,0,SetMsg -> ops_AttrList),
  320.                      Max        = GetTagData(LVIA_Max,0,SetMsg -> ops_AttrList);
  321.  
  322.             QuarterWidth    = (FontWidth + 3) / 4,
  323.             KnobWidth    = 3 * QuarterWidth,
  324.             LevelHeight    = (KnobWidth * DrawInfo -> dri_Resolution . X) / DrawInfo -> dri_Resolution . Y;
  325.  
  326.             if(LevelHeight >= Height)
  327.                 LevelHeight = Height / 4;
  328.  
  329.             if(LevelHeight < 4)
  330.             {
  331.                 if(Height > 4)
  332.                     LevelHeight = 4;
  333.                 else
  334.                     LevelHeight = Height;
  335.             }
  336.  
  337.             Level -> KnobWidth    = KnobWidth;
  338.             Level -> KnobTop    = (Height - LevelHeight) / 2;
  339.             Level -> LevelHeight    = LevelHeight;
  340.             Level -> Max        = Max;
  341.             Level -> Current    = Current;
  342.             Level -> DrawInfo    = DrawInfo;
  343.  
  344.             if(Max)
  345.                 Level -> Position = ((Width - 2 * KnobWidth) * Current) / Max;
  346.             else
  347.                 Level -> Position = 0;
  348.  
  349.             return((ULONG)Image);
  350.         }
  351.     }
  352.  
  353.     return(NULL);
  354. }
  355.  
  356. ULONG __saveds __asm
  357. LTP_LevelClassDispatcher(register __a0 Class *class,register __a2 Object *object,register __a1 Msg msg)
  358. {
  359.     switch(msg -> MethodID)
  360.     {
  361.         case IM_DRAW:
  362.  
  363.             return(LTP_LevelClassDraw((struct Image *)object,(struct impDraw *)msg,(LevelImageInfo *)INST_DATA(class,object)));
  364.  
  365.         case OM_SET:
  366.  
  367.             return(LTP_LevelClassSet(class,(struct Image *)object,(struct opSet *)msg));
  368.  
  369.         case OM_GET:
  370.  
  371.             return(LTP_LevelClassGet(class,(struct Image *)object,(struct opGet *)msg));
  372.  
  373.         case OM_NEW:
  374.  
  375.             return(LTP_LevelClassNew(class,object,(struct opSet *)msg));
  376.  
  377.         default:
  378.  
  379.             return(DoSuperMethodA(class,object,msg));
  380.     }
  381. }
  382. #endif    /* DO_LEVEL_KIND */
  383.