home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / Triton / Source / classes / progress.c < prev    next >
C/C++ Source or Header  |  1998-05-23  |  6KB  |  173 lines

  1. /*
  2.  *  OpenTriton -- A free release of the triton.library source code
  3.  *  Copyright (C) 1993-1998  Stefan Zeiger
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20.  
  21.  
  22. /****** triton.library/class_Progress ******
  23. *
  24. *   NAME    
  25. *    class_Progress -- A progress indicator
  26. *
  27. *   SUPERCLASS
  28. *    class_DisplayObject
  29. *
  30. *   SYNOPSIS
  31. *    TROB_Progress
  32. *
  33. *   ATTRIBUTES
  34. *    <Default>        : ULONG maximum
  35. *                       [create, set]
  36. *    TRAT_Flags       : ULONG orientation
  37. *                       - TROF_HORIZ (default)
  38. *                       - TROF_VERT
  39. *                       [create, set]
  40. *    TRAT_Value       : ULONG current
  41. *                       [create, set, get]
  42. *
  43. ******/
  44.  
  45.  
  46. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  47. //////////////////////////////////////////////////////////////////////////////////////// Include our stuff //
  48. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49.  
  50. #define TR_THIS_IS_TRITON
  51.  
  52. #include <libraries/triton.h>
  53. #include <clib/triton_protos.h>
  54. #include "/internal.h"
  55. #include "progress.def"
  56.  
  57.  
  58. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  59. ////////////////////////////////////////////////////////////////////////////////////////////// Object data //
  60. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  61.  
  62. #define OBJECT (&(object->DO.O))
  63. #define DISPLAYOBJECT (&(object->DO))
  64. #define PROGRESS object
  65.  
  66.  
  67. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  68. ////////////////////////////////////////////////////////////////////////////////////////////////// Methods //
  69. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  70.  
  71. TR_METHOD(Progress,NEW,NewData)
  72. {
  73.   if(!TRDP_DisplayObject_NEW(object,messageid,data,metaclass->trc_SuperClass)) return NULL;
  74.  
  75.   if(!(DISPLAYOBJECT->YResize)) DISPLAYOBJECT->XResize=TRUE;
  76.   DISPLAYOBJECT->MinHeight=max(CHECKBOX_HEIGHT,data->project->trp_TotalPropFontHeight);
  77.   DISPLAYOBJECT->MinWidth=(DISPLAYOBJECT->MinHeight*data->project->trp_AspectFixing)/16;
  78.  
  79.   return (ULONG)object;
  80. }
  81.  
  82.  
  83. TR_SIMPLEMETHOD(Progress,INSTALL_REFRESH)
  84. {
  85.   ULONG left,top,width,height,sep;
  86.   struct TR_Project *project;
  87.   ULONG borderwidth,borderheight;
  88.  
  89.   TR_SUPERMETHOD;
  90.   project=OBJECT->Project;
  91.   borderwidth=TR_FrameBorderWidth(project,TRFT_ABSTRACT_PROGRESS);
  92.   borderheight=TR_FrameBorderHeight(project,TRFT_ABSTRACT_PROGRESS);
  93.  
  94.   left=DISPLAYOBJECT->Left;
  95.   top=DISPLAYOBJECT->Top;
  96.   width=DISPLAYOBJECT->Width;
  97.   height=DISPLAYOBJECT->Height;
  98.  
  99.   if(PROGRESS->Value<0) PROGRESS->Value=0;
  100.   if(PROGRESS->Value>DISPLAYOBJECT->PrivData) PROGRESS->Value=DISPLAYOBJECT->PrivData;
  101.  
  102.   TR_DrawFrame(project,NULL,left,top,width,height,TRFT_ABSTRACT_PROGRESS,FALSE);
  103.   SetAfPt(project->trp_Window->RPort, NULL, -1);
  104.   SetDrMd(project->trp_Window->RPort, JAM1);
  105.  
  106.   if(DISPLAYOBJECT->XResize)
  107.     {
  108.       sep=left+(((width+1-(2*borderwidth))*PROGRESS->Value)/DISPLAYOBJECT->PrivData);
  109.       if(sep>left+1)
  110.         {
  111.           SetAPen(project->trp_Window->RPort, project->trp_DrawInfo->dri_Pens[FILLPEN]);
  112.           RectFill(project->trp_Window->RPort, left+borderwidth, top+borderheight,
  113.            sep+borderwidth-2, top+height-1-borderheight);
  114.         }
  115.       if(sep<left+width-1-borderwidth)
  116.         {
  117.           SetAPen(project->trp_Window->RPort, project->trp_DrawInfo->dri_Pens[BACKGROUNDPEN]);
  118.           RectFill(project->trp_Window->RPort, max(sep+borderwidth-1,left+borderwidth),
  119.            top+borderheight, left+width-1-borderwidth, top+height-1-borderheight);
  120.         }
  121.     }
  122.   else
  123.     {
  124.       sep=top-borderheight+(((height-1)*PROGRESS->Value)/DISPLAYOBJECT->PrivData);
  125.       if(sep>top)
  126.         {
  127.           SetAPen(project->trp_Window->RPort, project->trp_DrawInfo->dri_Pens[FILLPEN]);
  128.           RectFill(project->trp_Window->RPort, left+borderwidth, top+borderheight,
  129.            left+width-1-borderwidth, sep);
  130.         }
  131.       if(sep<top+height-2)
  132.         {
  133.           SetAPen(project->trp_Window->RPort, project->trp_DrawInfo->dri_Pens[BACKGROUNDPEN]);
  134.           RectFill(project->trp_Window->RPort, left+borderwidth, max(sep,top)+1,
  135.            left+width-1-borderwidth, top+height-borderheight);
  136.         }
  137.     }
  138.   return 1L;
  139. }
  140.  
  141.  
  142. TR_METHOD(Progress,SETATTRIBUTE,SetAttributeData)
  143. {
  144.   switch(data->attribute)
  145.     {
  146.     case TRAT_Value:
  147.       PROGRESS->Value=data->value;
  148.       break;
  149.     case TRAT_Flags:
  150.       if((data->value)&TROF_VERT) DISPLAYOBJECT->YResize=TRUE;
  151.       break;
  152.     case 0:
  153.       DISPLAYOBJECT->PrivData=data->value;
  154.       break;
  155.     default:
  156.       return TRDP_DisplayObject_SETATTRIBUTE(object,messageid,data,metaclass->trc_SuperClass);
  157.     }
  158.   if(DISPLAYOBJECT->Installed) return TR_DIRECTMETHODCALL(Progress,INSTALL_REFRESH);
  159.   else return 1;
  160. }
  161.  
  162.  
  163. TR_SIMPLEMETHOD(Progress,GETATTRIBUTE)
  164. {
  165.   switch((ULONG)data)
  166.     {
  167.     case TRAT_Value:
  168.       return PROGRESS->Value;
  169.     default:
  170.       return TRDP_DisplayObject_GETATTRIBUTE(object,messageid,data,metaclass->trc_SuperClass);
  171.     }
  172. }
  173.