#ifndef INTUITION_IMAGECLASS_H
#include <intuition/imageclass.h>
#endif

#define MYLIB_BOOPSI
#define MYLIB_GRAPHICS

#include "MyLib.h"

#include "StaticSavedsAsmA0A1A2.h"

/************************************************************************/

struct IClass *IconifyImageClass;

/****** MyLib.lib/CreateIconifyImageClass ********************************
*
*    NOTE
*	Most of this class was not actually developed by me;
*	however, I don't know where I got it from. If anyone knows
*	the real author of this, I'd be glad to hear about it.
*
*************************************************************************/

METHOD(IM_DRAW,struct impDraw *)

{
  struct RastPort *RastPort;
  UWORD ShineColor, ShadowColor, BackColor;
  UWORD RealShineColor, RealShadowColor;
  WORD Left, Top;
  WORD Width, Height;
  WORD InnerTop, InnerBottom;
  struct
    {
      unsigned int Active:1;
      unsigned int Selected:1;
    } Flags;

  RealShineColor=Message->imp_DrInfo->dri_Pens[SHINEPEN];
  RealShadowColor=Message->imp_DrInfo->dri_Pens[SHADOWPEN];

  switch(Message->imp_State)
    {
    case IDS_SELECTED:
      ShineColor=RealShadowColor;
      ShadowColor=RealShineColor;
      BackColor=Message->imp_DrInfo->dri_Pens[FILLPEN];
      Flags.Selected=TRUE;
      Flags.Active=TRUE;
      break;

    case IDS_INACTIVENORMAL:
      ShineColor=RealShineColor;
      ShadowColor=RealShadowColor;
      BackColor=Message->imp_DrInfo->dri_Pens[BACKGROUNDPEN];
      Flags.Selected=FALSE;
      Flags.Active=FALSE;
      break;

    case IDS_INACTIVESELECTED:
      ShineColor=RealShadowColor;
      ShadowColor=RealShineColor;
      BackColor=Message->imp_DrInfo->dri_Pens[BACKGROUNDPEN];
      Flags.Selected=TRUE;
      Flags.Active=FALSE;
      break;

    default:
      ShineColor=RealShineColor;
      ShadowColor=RealShadowColor;
      BackColor=Message->imp_DrInfo->dri_Pens[FILLPEN];
      Flags.Selected=FALSE;
      Flags.Active=TRUE;
      break;
    }

  RastPort=Message->imp_RPort;

  Left=((struct Image *)TheObject)->LeftEdge+Message->imp_Offset.X;
  Top=((struct Image *)TheObject)->TopEdge+Message->imp_Offset.Y;
  Width=((struct Image *)TheObject)->Width;
  Height=((struct Image *)TheObject)->Height;

  SetDrMd(RastPort,JAM1);

  /* draw border */
  SetAPen(RastPort, RealShadowColor);
  Move(RastPort, Left, Top+1);
  Draw(RastPort, Left, Top+Height-2);
  Move(RastPort, Left, Top+Height-1);
  Draw(RastPort, Left+Width, Top+Height-1);

  SetAPen(RastPort, ShadowColor);
  Move(RastPort, Left+Width-2, Top+1);
  Draw(RastPort, Left+Width-2, Top+Height-2);
  Move(RastPort, Left+1, Top+Height-1);
  Draw(RastPort, Left+Width-2, Top+Height-1);

  SetAPen(RastPort, RealShineColor);
  Move(RastPort, Left+Width-1, Top+1);
  Draw(RastPort, Left+Width-1, Top+Height-2);
  Move(RastPort, Left, Top);
  Draw(RastPort, Left+Width, Top);

  SetAPen(RastPort, ShineColor);
  Move(RastPort, Left+1, Top+1);
  Draw(RastPort, Left+1, Top+Height-2);
  Move(RastPort, Left+1, Top);
  Draw(RastPort, Left+Width-2, Top);

  /* draw background */
  SetAPen(RastPort, BackColor);
  RectFill(RastPort, Left+2, Top+1, Left+Width-3, Top+Height-2);

  InnerTop=Top+(Height/5);
  InnerBottom=Top+(Height*4)/5;

  /* draw inner rectangle */
  SetAPen(RastPort, RealShadowColor);
  Move(RastPort, Left+8, InnerBottom-2);
  Draw(RastPort, Left+8, InnerBottom-4);
  Draw(RastPort, Left+11, InnerBottom-4);
  Draw(RastPort, Left+11, InnerBottom-2);
  Draw(RastPort, Left+8, InnerBottom-2);

  /* draw outer rectangle */
  if (Flags.Selected)
    {
      Move(RastPort, Left+6, InnerBottom);
      Draw(RastPort, Left+6, InnerBottom-6);
      Draw(RastPort, Left+13, InnerBottom-6);
      Draw(RastPort, Left+13, InnerBottom);
      Draw(RastPort, Left+6, InnerBottom);
    }
  else
    {
      Move(RastPort, Left+6, InnerTop);
      Draw(RastPort, Left+6, InnerBottom);
      Draw(RastPort, Left+Width-7, InnerBottom);
      Draw(RastPort, Left+Width-7, InnerTop);
      Draw(RastPort, Left+6, InnerTop);
    }

  /* fill inner rectangle */
  if (Flags.Active)
    {
      SetAPen(RastPort, RealShineColor);
      Move(RastPort, Left+9, InnerBottom-3);
      Draw(RastPort, Left+10, InnerBottom-3);
    }

  return TRUE;
}

/************************************************************************/

STATIC_SAVEDS_ASM_A0A1A2(ULONG,Dispatcher,struct IClass *,TheClass,Msg,Message,Object *,TheObject)

{
  switch(Message->MethodID)
    {
      METHOD_DISP(IM_DRAW,struct impDraw *);
    }
  return SUPER_METHOD;
}

/************************************************************************/

struct IClass *CreateIconifyImageClass(void)

{
  if ((IconifyImageClass=MakeClass(NULL,BOOPSI_imageclass,NULL,0,0))!=NULL)
    {
      IconifyImageClass->cl_Dispatcher.h_Entry=Dispatcher;
    }
  return IconifyImageClass;
}
