home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / Triton / Source / classes / palette.c < prev    next >
C/C++ Source or Header  |  1998-05-23  |  6KB  |  183 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_Palette ******
  23. *
  24. *   NAME    
  25. *    class_Palette -- A GadTools palette gadget
  26. *
  27. *   SUPERCLASS
  28. *    class_DisplayObject
  29. *
  30. *   SYNOPSIS
  31. *    TROB_Palette
  32. *
  33. *   ATTRIBUTES
  34. *    <Default>        : <unused>
  35. *    TRAT_Value       : BOOL checked
  36. *                       [create, set, get]
  37. *
  38. *   APPLICATION MESSAGES
  39. *    TRMS_NEWVALUE is sent when a new color has been selected. trm_Data
  40. *    contains the pen number of the selected color.
  41. *
  42. ******/
  43.  
  44.  
  45. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  46. //////////////////////////////////////////////////////////////////////////////////////// Include our stuff //
  47. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  48.  
  49. #define TR_THIS_IS_TRITON
  50.  
  51. #include <libraries/triton.h>
  52. #include <clib/triton_protos.h>
  53. #include "/internal.h"
  54. #include "palette.def"
  55.  
  56.  
  57. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  58. ////////////////////////////////////////////////////////////////////////////////////////////// Object data //
  59. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  60.  
  61. #define OBJECT (&(object->DO.O))
  62. #define DISPLAYOBJECT (&(object->DO))
  63. #define PALETTE object
  64.  
  65.  
  66. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  67. ////////////////////////////////////////////////////////////////////////////////////////////////// Methods //
  68. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  69.  
  70. TR_METHOD(Palette,NEW,NewData)
  71. {
  72.   if(!TRDP_DisplayObject_NEW(object,messageid,data,metaclass->trc_SuperClass)) return NULL;
  73.   data->project->trp_IDCMPFlags|=PALETTEIDCMP;
  74.  
  75.   DISPLAYOBJECT->MinHeight=max(CHECKBOX_HEIGHT,data->project->trp_TotalPropFontHeight);
  76.   DISPLAYOBJECT->MinWidth=(
  77.                    (max(CHECKBOX_WIDTH,data->project->trp_PropFont->tf_YSize)-3)
  78.                    * (1<<min(3,data->project->trp_Screen->RastPort.BitMap->Depth))
  79.                    ) +4;
  80.   DISPLAYOBJECT->XResize=TRUE;
  81.   DISPLAYOBJECT->YResize=TRUE;
  82.  
  83.   return (ULONG)object;
  84. }
  85.  
  86.  
  87. TR_METHOD(Palette,INSTALL,InstallData)
  88. {
  89.   TRDP_DisplayObject_INSTALL(object,messageid,data,metaclass->trc_SuperClass);
  90.   if(DISPLAYOBJECT->PrivData=(ULONG)
  91.      TR_CreateGadgetTags(OBJECT->Project,
  92.              OBJECT,
  93.              PALETTE_KIND,
  94.              DISPLAYOBJECT->Left,
  95.              DISPLAYOBJECT->Top,
  96.              DISPLAYOBJECT->Width,
  97.              DISPLAYOBJECT->Height,
  98.              GTPA_Color,          PALETTE->Selected,
  99.              GTPA_IndicatorWidth, DISPLAYOBJECT->MinWidth/2,
  100.              GTPA_Depth,          OBJECT->Project->trp_Screen->RastPort.BitMap->Depth,
  101.              GTPA_ColorOffset,    0,
  102.              GA_Disabled,         TR_DO_DISABLED,
  103.              TAG_END))
  104.     return 1L;
  105.   else
  106.     return NULL;
  107. }
  108.  
  109.  
  110. TR_METHOD(Palette,SETATTRIBUTE,SetAttributeData)
  111. {
  112.   switch(data->attribute)
  113.     {
  114.     case TRAT_Value:
  115.       if(PALETTE->Selected!=data->value)
  116.     {
  117.       PALETTE->Selected=data->value;
  118.       if(DISPLAYOBJECT->Installed)
  119.         GT_SetGadgetAttrs((struct Gadget *)DISPLAYOBJECT->PrivData,OBJECT->Project->trp_Window,
  120.                   NULL,GTPA_Color,PALETTE->Selected,
  121.                   GA_Disabled,TR_DO_DISABLED,TAG_END);
  122.     }
  123.       return 1L;
  124.  
  125.     default:
  126.       return TRDP_DisplayObject_SETATTRIBUTE(object,messageid,data,metaclass->trc_SuperClass);
  127.     }
  128. }
  129.  
  130.  
  131. TR_SIMPLEMETHOD(Palette,GETATTRIBUTE)
  132. {
  133.   if((ULONG)data==TRAT_Value) return PALETTE->Selected;
  134.   return TRDP_DisplayObject_GETATTRIBUTE(object,messageid,data,metaclass->trc_SuperClass);
  135. }
  136.  
  137.  
  138. TR_SIMPLEMETHOD(Palette,DISABLED_ENABLED)
  139. {
  140.   GT_SetGadgetAttrs((struct Gadget *)DISPLAYOBJECT->PrivData,OBJECT->Project->trp_Window,NULL,
  141.             GTPA_Color,PALETTE->Selected,GA_Disabled,TR_DO_DISABLED,TAG_END);
  142.   return 1L;
  143. }
  144.  
  145.  
  146. TR_METHOD(Palette,KEYDOWN_REPEATEDKEYDOWN,EventData)
  147. {
  148.   struct TR_Message *m;
  149.  
  150.   if(data->imsg->Code) PALETTE->Selected--; else PALETTE->Selected++;
  151.   PALETTE->Selected%=(1<<(OBJECT->Project->trp_Screen->RastPort.BitMap->Depth));
  152.  
  153.   if(m=TR_CreateMsg(Self.DO.O.Project->trp_App))
  154.     {
  155.       m->trm_ID=DISPLAYOBJECT->ID;
  156.       m->trm_Class=TRMS_NEWVALUE;
  157.       m->trm_Data=PALETTE->Selected;
  158.     }
  159.   TR_SetAttribute(OBJECT->Project,DISPLAYOBJECT->ID,TRAT_Value,PALETTE->Selected);
  160.  
  161.   return TR_DIRECTMETHODCALL(Palette,DISABLED_ENABLED);
  162. }
  163.  
  164.  
  165. TR_METHOD(Palette,EVENT,EventData)
  166. {
  167.   struct TR_Message *m;
  168.  
  169.   if((data->imsg->Class==IDCMP_GADGETUP)&&(data->imsg->IAddress==(APTR)(DISPLAYOBJECT->PrivData)))
  170.     {
  171.       PALETTE->Selected=data->imsg->Code;
  172.       if(m=TR_CreateMsg(Self.DO.O.Project->trp_App))
  173.     {
  174.       m->trm_ID=DISPLAYOBJECT->ID;
  175.       m->trm_Class=TRMS_NEWVALUE;
  176.       m->trm_Data=PALETTE->Selected;
  177.     }
  178.       TR_SetAttribute(OBJECT->Project,DISPLAYOBJECT->ID,TRAT_Value,PALETTE->Selected);
  179.       return 1L;
  180.     }
  181.   else return NULL;
  182. }
  183.