// -----------------------------------------------------------------------------
// demo.c
// demo program for myimagegclass
// ©1994 Excellent Studios
// 07 Jan 1994
//
// $Id: demo.c,v 1.1 94/01/11 03:03:47 rick Exp Locker: rick $
// -----------------------------------------------------------------------------

/* MUI */
#include <libraries/mui.h>

/* System */
#include <dos/dos.h>
#include <graphics/gfxmacros.h>

/* Prototypes */
#include <clib/alib_protos.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/muimaster.h>
#include <proto/asl.h>

/* ANSI C */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>

#include <intuition/icclass.h>
#include <intuition/gadgetclass.h>
#include "myimagegclass.h"

#include <exec/memory.h>

#include "myimagegclass.h"

#define TextSpace(str,weight)\
   TextObject,TextFrame,MUIA_Text_Contents,str,MUIA_Weight,weight,MUIA_Background,MUII_TextBack,End
#define KeyImageButton(image,control)\
   ImageObject,\
      ImageButtonFrame,\
      MUIA_InputMode, MUIV_InputMode_RelVerify,\
      MUIA_Image_Spec, image,\
      MUIA_Image_FontMatch, TRUE,\
      MUIA_Background, MUII_ButtonBack,\
      MUIA_ControlChar, control,\
      End
#define AppRetID(gad,attr,attrVal,id)\
   DoMethod(gad,MUIM_Notify,attr,attrVal,app,2,MUIM_Application_ReturnID,id)
// no '-' sign, no negatives allowed in this integer gadget!
#define KeyInteger(contents,maxlen,controlchar)\
	StringObject,\
		StringFrame,\
		MUIA_ControlChar    , controlchar,\
		MUIA_String_MaxLen  , maxlen,\
		MUIA_String_Integer, contents,\
		MUIA_String_Accept, "0123456789",\
		End

enum {
   ID_POPUP = 1,
   ID_BEEP,
   ID_SCALEX,
   ID_SCALEY,
   ID_RELX,
   ID_RELY,
   ID_RELWIDTH,
   ID_RELHEIGHT,
   ID_ASPECTRATIO,
   ID_IMAGEBEEP
};

// GLOBALS --------------------------------------------------------------

struct Library *MUIMasterBase;
Class *myimagegclass;

struct FileRequester *loadReq;

struct BitMap bitMap;
struct Image image;
APTR app, WI_Pic,WI_Options, i_myImage,i_miniImage,t_name,t_info,g_popup,
     g_scaleX,g_scaleY,g_relX,g_relY,g_aspect,g_relWidth,g_relHeight,g_beep;

ULONG sFlags, relWidth = 100, relHeight = 100, beep;

USHORT chip excellent0_data[] =
{
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc0,  0xfff,  0xe000,  0x0,  0x0,  0x3ff,  0xf000,
  0xf800,  0x0,  0x1f,  0xfff8,  0xffff,  0xf9ff,  0xffc0,  0x1fff,  0xe000,  0x0,  0x0,  0x3ff,  0xf000,
  0xf800,  0x0,  0x1f,  0xff80,  0x7fff,  0xf81f,  0xffc0,  0x3fff,  0xe000,  0x0,  0x0,  0x1ff,  0xf000,
  0xf800,  0x0,  0xf,  0xfc00,  0x3fff,  0xf001,  0xffc0,  0x3fff,  0xc002,  0x0,  0x0,  0x1ff,  0xf000,
  0xf800,  0x0,  0xf,  0xf000,  0xfff,  0xc000,  0x1fc0,  0x7fff,  0x800e,  0x0,  0x380,  0xff,  0xf000,
  0xf800,  0x0,  0x7,  0xf800,  0x7ff,  0x8000,  0x3fc0,  0xffff,  0x803c,  0x0,  0x3e0,  0xff,  0xf000,
  0xf800,  0x0,  0x7,  0xfc00,  0x1fe,  0x0,  0xffc0,  0xffff,  0x80fc,  0x0,  0x1ff,  0x7f,  0xf000,
  0xf800,  0xfff,  0xffff,  0xff00,  0xfc,  0x3,  0xffc1,  0xffff,  0x1fc,  0x0,  0xff,  0xc07f,  0xf000,
  0xf800,  0xfff,  0xffff,  0xff80,  0x78,  0x7,  0xffc3,  0xffff,  0x7f8,  0x30,  0x7f,  0xfe3f,  0xf000,
  0xf800,  0xfff,  0xffff,  0xffc0,  0x10,  0xf,  0xffc3,  0xfffe,  0x1ff8,  0x1c,  0x3f,  0xff9f,  0xf000,
  0xf800,  0xfff,  0xffff,  0xfff0,  0x0,  0x3f,  0xffc7,  0xfffe,  0x7ff0,  0xf,  0x803f,  0xffff,  0xf000,
  0xf800,  0xfff,  0xffff,  0xfff8,  0x0,  0x7f,  0xffcf,  0xfffc,  0xfff0,  0xf,  0xc01f,  0xffff,  0xf000,
  0xf800,  0x0,  0x7ff,  0xfffe,  0x0,  0x1ff,  0xffcf,  0xffff,  0xffe0,  0x7,  0xf00f,  0xffff,  0xf000,
  0xf800,  0x0,  0x7ff,  0xffff,  0x0,  0x7ff,  0xffdf,  0xffff,  0xffe0,  0x7,  0xfc0f,  0xffff,  0xf000,
  0xf800,  0x0,  0x7ff,  0xffff,  0x8000,  0xfff,  0xffdf,  0xffff,  0xffc0,  0x3,  0xff07,  0xffff,  0xf000,
  0xf800,  0x0,  0x7ff,  0xffff,  0xe000,  0xfff,  0xffff,  0xffff,  0xffc0,  0x1,  0xffc3,  0xffff,  0xf000,
  0xf800,  0x0,  0x7ff,  0xffff,  0xc000,  0x7ff,  0xffff,  0xffff,  0xff80,  0x1ef1,  0xfff1,  0xffff,  0xf000,
  0xf800,  0x0,  0x7ff,  0xffff,  0x0,  0x3ff,  0xffff,  0xbfff,  0xef80,  0x3f3f,  0xffff,  0xffff,  0xf000,
  0xf800,  0x0,  0x7ff,  0xfffe,  0x0,  0x1ff,  0xffff,  0x3fff,  0xcf00,  0x3f1f,  0xffff,  0xffff,  0xf000,
  0xf800,  0xfff,  0xffff,  0xfffc,  0x0,  0x7f,  0xfffe,  0x3fff,  0x9f01,  0x3f07,  0xfbff,  0xffff,  0xf000,
  0xf800,  0xfff,  0xffff,  0xfff8,  0x0,  0x3f,  0xfffc,  0x7fff,  0x1e06,  0x3f03,  0xfdff,  0xffff,  0xf000,
  0xf800,  0xfff,  0xffff,  0xffe0,  0x10,  0xf,  0xfff0,  0x7ffc,  0x1e38,  0xc00,  0xfc7f,  0xff9f,  0xf000,
  0xf800,  0xfff,  0xffff,  0xffc0,  0x38,  0x7,  0xffe0,  0x7ff8,  0x1e70,  0xc00,  0x7c3f,  0xff87,  0xf000,
  0xf800,  0xfff,  0xffff,  0xff00,  0xfc,  0x1,  0xffc0,  0xffe0,  0x3fc0,  0xc00,  0x1e0f,  0xffc1,  0xf000,
  0xf800,  0xfff,  0xffff,  0xfe00,  0x1fe,  0x0,  0xffc0,  0xffc0,  0x3f80,  0xc00,  0xe07,  0xffc0,  0xf000,
  0xf800,  0x0,  0x1,  0xfc00,  0x3ff,  0x0,  0x7fc0,  0xff80,  0x7f00,  0xc00,  0x201,  0xffe0,  0xf000,
  0xf800,  0x0,  0x3,  0xf000,  0x7ff,  0xc000,  0x1fc1,  0xfe00,  0x7e00,  0xc00,  0x0,  0x7fe0,  0xf000,
  0xf800,  0x0,  0x3,  0xe000,  0xfff,  0xe000,  0xfc1,  0xfe00,  0x7800,  0xc00,  0x0,  0x3fe0,  0xf000,
  0xf800,  0x0,  0x7,  0x8000,  0x3fff,  0xf000,  0xfc3,  0xf800,  0xf000,  0xc00,  0x0,  0xfe0,  0xf000,
  0xf800,  0x0,  0x7,  0xf800,  0x7fff,  0xf800,  0xffc3,  0xf000,  0xe000,  0x1e00,  0x0,  0x7f0,  0xf000,
  0xf800,  0x0,  0xf,  0xffe1,  0xffff,  0xfe0f,  0xffc3,  0xc000,  0x8000,  0xf3c0,  0x0,  0x1f0,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xfe7f,  0xffc3,  0x8001,  0x1,  0x80e0,  0x0,  0xf8,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc6,  0x0,  0x3,  0xf0,  0x0,  0x38,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc4,  0x0,  0x2,  0xf8,  0x0,  0x18,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc0,  0x0,  0x6,  0xf8,  0x0,  0x4,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc0,  0x0,  0x4,  0xf8,  0x0,  0x0,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc0,  0x0,  0xc,  0xf8,  0x0,  0x0,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc0,  0x0,  0xc,  0xf8,  0x0,  0x0,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc0,  0x0,  0xc,  0xf8,  0x0,  0x0,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc0,  0x0,  0x3e,  0x1f8,  0x0,  0x0,  0xf000,
  0xffff,  0xf87f,  0xffff,  0xfffe,  0x7fff,  0xf9ff,  0xffc0,  0x0,  0xfe,  0x3fe,  0x0,  0x0,  0xf000,
  0xffff,  0x801f,  0xf800,  0x7ff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0xfff,  0xfff,  0xe000,  0x0,  0xf000,
  0xffff,  0x1f,  0xf800,  0x7ff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x7fff,  0xffff,  0xfc00,  0x0,  0xf000,
  0xfffe,  0x1f,  0xf800,  0x7ff8,  0x7fff,  0xe1ff,  0xffc0,  0x7,  0xffff,  0xffff,  0xffc0,  0x0,  0xf000,
  0xfffc,  0xf,  0xf800,  0x3ff8,  0x7fff,  0xe1ff,  0xffc0,  0x7,  0xffff,  0xffff,  0xfff0,  0x0,  0xf000,
  0xfff8,  0xfcf,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x7fff,  0xffff,  0xfff8,  0x0,  0xf000,
  0xfff8,  0x1fff,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x1fff,  0xffff,  0xfff8,  0x0,  0xf000,
  0xfff8,  0x3fff,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x7ff,  0xffff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0x7fff,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x7f,  0xffff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0x7fff,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x1f,  0xffff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0x7fff,  0xf800,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x1,  0xffff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0xffff,  0xf800,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x0,  0x7fff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0xffff,  0xf800,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0xffff,  0xf800,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0x7fff,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0x7fff,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0x7fff,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xfff0,  0x3fff,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xfff8,  0x1fef,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xfffc,  0xfcf,  0xf87f,  0xfff8,  0x7fff,  0xe1ff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xfffc,  0xf,  0xf800,  0x3ff8,  0x7f,  0xe001,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xfffe,  0x1f,  0xf800,  0x3ff8,  0x7f,  0xe001,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xffff,  0x1f,  0xf800,  0x3ff8,  0x7f,  0xe003,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xffff,  0xc01f,  0xf800,  0x7ff8,  0xff,  0xe003,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xffff,  0xf87f,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffc0,  0x0,  0x0,  0xfff,  0xfff8,  0x0,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffe0,  0x0,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffe0,  0x0,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffe0,  0x0,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffe0,  0x0,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffe0,  0x0,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffe0,  0x0,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffe0,  0x0,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xfff0,  0x0,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xfff9,  0xffff,  0xffff,  0xffff,  0xfffe,  0x0,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffc0,  0x3f,  0xffbf,  0xffc1,  0xfff8,  0x0,  0x1fff,  0xffff,  0x8000,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffc0,  0x1f,  0xff8f,  0xffc1,  0xfff8,  0x0,  0x1fff,  0xffff,  0xf800,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffc0,  0x1f,  0xff87,  0xffc1,  0xfff8,  0x0,  0x1fff,  0xffff,  0xf800,  0xfff,  0xffff,  0xffff,  0xf000,
  0xffc0,  0x1f,  0xff83,  0xffc1,  0xfff0,  0x0,  0x1fff,  0xffff,  0xf800,  0xfff,  0x8fff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff81,  0xffc1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf000,  0xffe,  0xfff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff80,  0xffc1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf002,  0xff8,  0x7ff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff80,  0x3fc1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf007,  0xcff0,  0x7ff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff80,  0x1fc1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf007,  0xfff8,  0x7ff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff80,  0xfc1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf00f,  0xfff8,  0x7ff,  0xffff,  0xf000,
  0xffc0,  0x7f,  0xff80,  0x7c1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf00f,  0xfff8,  0x7ff,  0xffff,  0xf000,
  0xffc0,  0x7f,  0xff82,  0x1c1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf01f,  0xfffc,  0x7ff,  0xffff,  0xf000,
  0xffc0,  0x7f,  0xff83,  0xc1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf01f,  0xfffc,  0x7ff,  0xffff,  0xf000,
  0xffc0,  0x7f,  0xff83,  0x8041,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf03f,  0xfffe,  0x7ff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff83,  0xc001,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf03f,  0xfffe,  0x3ff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff83,  0xf001,  0xffff,  0xf83f,  0xffff,  0xffff,  0xe07f,  0xffff,  0x3ff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff83,  0xf801,  0xffff,  0xf83f,  0xffff,  0xffff,  0xe07f,  0xffff,  0x3ff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff83,  0xfc01,  0xffff,  0xf83f,  0xffff,  0xffff,  0xe07f,  0xffff,  0x3ff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff83,  0xfe01,  0xffff,  0xf83f,  0xffff,  0xffff,  0xe0ff,  0xffff,  0x83ff,  0xffff,  0xf000,
  0xffc1,  0xffff,  0xff83,  0xff01,  0xffff,  0xf83f,  0xffff,  0xffff,  0xe0ff,  0xffff,  0x83ff,  0xffff,  0xf000,
  0xffc0,  0xf,  0xff83,  0xff81,  0xffff,  0xf83f,  0xffff,  0xffff,  0xe1ff,  0xffff,  0xc3ff,  0xffff,  0xf000,
  0xffc0,  0xf,  0xff83,  0xffe1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xe1ff,  0xffff,  0xe3ff,  0xffff,  0xf000,
  0xffc0,  0xf,  0xff83,  0xfff1,  0xffff,  0xf83f,  0xffff,  0xffff,  0xf3ff,  0xffff,  0xe7ff,  0xffff,  0xf000,
  0xffc0,  0x1f,  0xff83,  0xfff9,  0xffff,  0xf83f,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffbf,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x1,  0xfff8,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x1,  0xfff8,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x1,  0xfff8,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x7f00,  0xff,  0xe000,  0x781e,  0x3,  0xfc00,  0x1e,  0x0,  0xf00,  0x7,  0xf000,  0xf000,
  0xf001,  0xff80,  0xff,  0xe000,  0x781e,  0x3,  0xff80,  0x1e,  0x0,  0x7ff0,  0x1f,  0xf800,  0xf000,
  0xf003,  0xe300,  0x1ff,  0xe000,  0x781e,  0x3,  0xffc0,  0x1e,  0x1,  0xfff8,  0x1f,  0x3000,  0xf000,
  0xf003,  0xe000,  0x1e,  0x0,  0x781e,  0x3,  0xc1e0,  0x1e,  0x3,  0xe07c,  0x1e,  0x0,  0xf000,
  0xf003,  0xf800,  0x1e,  0x0,  0x781e,  0x3,  0xc1f0,  0x1e,  0x3,  0xc03e,  0x1f,  0xc000,  0xf000,
  0xf001,  0xff00,  0x1e,  0x0,  0x781e,  0x3,  0xc0f0,  0x1e,  0x3,  0x801e,  0xf,  0xf800,  0xf000,
  0xf000,  0x7f80,  0x1e,  0x0,  0x781e,  0x3,  0xc0f0,  0x1e,  0x3,  0x801e,  0x3,  0xfc00,  0xf000,
  0xf000,  0x7c0,  0x1e,  0x0,  0x781e,  0x3,  0xc0f0,  0x1e,  0x3,  0xc03e,  0x0,  0x3c00,  0xf000,
  0xf000,  0x87c0,  0x1e,  0x0,  0x7c3e,  0x3,  0xc1e0,  0x1e,  0x3,  0xe07c,  0x0,  0x3c00,  0xf000,
  0xf001,  0xff80,  0x1e,  0x0,  0x3ffc,  0x3,  0xc7e0,  0x1e,  0x1,  0xfff8,  0x1f,  0xfc00,  0xf000,
  0xf003,  0xff00,  0x1e,  0x0,  0x3ff8,  0x3,  0xff80,  0x1e,  0x0,  0x7ff0,  0x3f,  0xf800,  0xf000,
  0xf001,  0xfe00,  0x1e,  0x0,  0xff0,  0x3,  0xff00,  0x1e,  0x0,  0x3fc0,  0xf,  0xe000,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xf000,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xffff,  0xf000,
/*  end of plane 0 */
};  /* end of excellent0_data[] */

struct Image excellent0_image =
{
  0, 0,               /* left, top */
  196, 139, 1,     /* width, height, depth */
  &excellent0_data[0],   /* image data */
  1, 0x0,       /* plane pick, plane on/off */
  NULL              /* next image */
};

// PROGRAM ---------------------------------------------------------------------

static char *MakeInfoStr(struct Image *img)
{
   static char info[64];

   sprintf(info,"%d x %d x %d",img->Width,img->Height,img->Depth);
   return(info);
}

/*************************/
/* Init & Fail Functions */
/*************************/

static VOID fail(APTR app,char *str)
{

	if (app)
		MUI_DisposeObject(app);

   if (loadReq)
      MUI_FreeAslRequest(loadReq);

	if (MUIMasterBase)
		CloseLibrary(MUIMasterBase);

   if (image.ImageData)
      FreeVec(image.ImageData);

   if (myimagegclass)
      Free_myimagegclass(myimagegclass);

	if (str)
	{
		puts(str);
		exit(20);
	}
	exit(0);
}

int CXBRK(void) { return(0); }
int _CXBRK(void) { return(0); }
void chkabort(void) {}

static VOID init(VOID)
{
	if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
		fail(NULL,"Failed to open "MUIMASTER_NAME".");

   if (!(myimagegclass = Init_myimagegclass()))
      fail(NULL,"Failed to init myimagegclass.");

	/*
	** Create the application.
	*/

	app = ApplicationObject,
		MUIA_Application_Title      , "myimagegclass Demo",
		MUIA_Application_Version    , "$VER: myimagegclass Demo 1.0  08 Jan 1994",
		MUIA_Application_Copyright  , "©1994 Excellent Studios",
		MUIA_Application_Author     , "Richard Reed",
		MUIA_Application_Description, "Demo program for myimagegclass BOOPSI",
		MUIA_Application_Base       , "myigclass_demo",

		SubWindow, WI_Pic = WindowObject,
			MUIA_Window_ID, 'PICT',
			MUIA_Window_Title, "myimagegclass Object",
			MUIA_Window_CloseGadget, FALSE,

			WindowContents, i_myImage = MyImageScaledRel(20,20,&excellent0_image,0,sFlags,relWidth,relHeight),
      End,
		SubWindow, WI_Options = WindowObject,
			MUIA_Window_ID, 'OPTS',
			MUIA_Window_Title, "myimagegclass Options",

			WindowContents, VGroup,
			   Child, HGroup,
			      Child, VGroup,
			         Child, HVSpace,
                  Child, HGroup,
                     Child, KeyLabel1("Image",'i'),
                     Child, t_name = TextSpace("Excellent!",100),
                     Child, g_popup = KeyImageButton(MUII_PopFile,'i'),
                  End,
                  Child, HGroup,
                     Child, Label1("Info"),
                     Child, t_info = TextSpace(MakeInfoStr(&excellent0_image),100),
                  End,
                  Child, HVSpace,
                  Child, HGroup,
                     Child, HVSpace,
                     Child, KeyLabel1("Beep every redraw",'b'),
                     Child, g_beep = KeyCheckMark(beep,'b'),
                     Child, HVSpace,
                  End,
               End,
               Child, i_miniImage = MyImageScaledBorder(50,50,&excellent0_image,0,GAFL_ScaleXYAspect),
            End,
            Child, HGroup,
               GroupFrameT("Scaling Flags"),
               Child, ColGroup(2),
                  Child, KeyLabel1("ScaleX",'x'),
                  Child, g_scaleX = KeyCheckMark(sFlags & GAFL_ScaleX,'x'),
                  Child, KeyLabel1("ScaleY",'y'),
                  Child, g_scaleY = KeyCheckMark(sFlags & GAFL_ScaleY,'y'),
                  Child, KeyLabel1("AspectRatio",'a'),
                  Child, g_aspect = KeyCheckMark(sFlags & GAFL_AspectRatio,'a'),
               End,
               Child, VGroup,
                  GroupFrame,
                  Child, HGroup,
                     Child, HVSpace,
                     Child, ColGroup(2),
                        Child, KeyLabel1("RelX",'r'),
                        Child, g_relX = KeyCheckMark(sFlags & GAFL_RelX,'r'),
                        Child, KeyLabel1("RelY",'e'),
                        Child, g_relY = KeyCheckMark(sFlags & GAFL_RelY,'e'),
                     End,
                  End,
                  Child, ColGroup(2),
                    Child, KeyLabel2("RelWidth",'w'),
                    Child, g_relWidth = KeyInteger(relWidth,5,'w'),
                    Child, KeyLabel2("RelHeight",'h'),
                    Child, g_relHeight = KeyInteger(relHeight,5,'h'),
                  End,
               End,
            End,
         End,
      End,
   End;

 	/*** application failed ? ***/
	if (!app)
		fail(app, "Creating application failed !");

   AppRetID(WI_Options, MUIA_Window_CloseRequest,TRUE,MUIV_Application_ReturnID_Quit);
   AppRetID(g_popup, MUIA_Selected,FALSE, ID_POPUP);
   AppRetID(g_beep, MUIA_Selected,MUIV_EveryTime, ID_BEEP);
   AppRetID(g_scaleX, MUIA_Selected,MUIV_EveryTime, ID_SCALEX);
   AppRetID(g_scaleY, MUIA_Selected,MUIV_EveryTime, ID_SCALEY);
   AppRetID(g_relX, MUIA_Selected,MUIV_EveryTime, ID_RELX);
   AppRetID(g_relY, MUIA_Selected,MUIV_EveryTime, ID_RELY);
   AppRetID(g_relWidth, MUIA_String_Acknowledge,MUIV_EveryTime, ID_RELWIDTH);
   AppRetID(g_relHeight, MUIA_String_Acknowledge,MUIV_EveryTime, ID_RELHEIGHT);
   AppRetID(g_aspect, MUIA_Selected,MUIV_EveryTime, ID_ASPECTRATIO);
   NotifyFromMyImage(i_myImage, ID_IMAGEBEEP);

   if (!(loadReq=MUI_AllocAslRequestTags(ASL_FileRequest,
         ASL_Hail, "Load ILBM to Image",
         TAG_DONE)))
      fail(app, "Couldn't allocate file requester!");

   set(WI_Pic, MUIA_Window_Open, TRUE);
   set(WI_Options, MUIA_Window_Open, TRUE);
}

int main(int argc,char *argv[])
{
	ULONG signals, returnID;
	BOOL running = TRUE;

	init();

	while (running)
	{
		switch (returnID = DoMethod(app,MUIM_Application_Input,&signals))
		{
		   case ID_POPUP:
		      // put our application to sleep while displaying the requester
            set(app,MUIA_Application_Sleep,TRUE);

            if (MUI_AslRequestTags(loadReq,TAG_DONE))
            {
               char picName[FNSIZE];

               if (image.ImageData)
               {
                  FreeVec(image.ImageData);
                  image.ImageData = NULL;
               }

               strmfp(picName, loadReq->rf_Dir,loadReq->rf_File);
               if (ReadILBM2Image(picName,&image,NULL))
               {
                  MUI_Request(app,WI_Options,0,"Alert!","Yikes!","An error has occurred reading %s.",picName);
                  set(t_name, MUIA_Text_Contents, "Excellent!"),
                  set(t_info, MUIA_Text_Contents, MakeInfoStr(&excellent0_image));
                  set(i_miniImage, GA_Image, &excellent0_image);
                  set(i_myImage, GA_Image, &excellent0_image);
               }
               else
               {
                  set(t_name, MUIA_Text_Contents, loadReq->rf_File);
                  set(t_info, MUIA_Text_Contents, MakeInfoStr(&image));
                  set(i_miniImage, GA_Image, &image);
                  set(i_myImage, GA_Image, &image);
               }
            }

            // wake up our application again
            set(app,MUIA_Application_Sleep,FALSE);
            break;
         case ID_BEEP:
            get(g_beep, MUIA_Selected, &beep);
            set(i_myImage,GA_ID,beep ? ID_IMAGEBEEP:0);
            break;
         case ID_IMAGEBEEP:  DisplayBeep(NULL);  break;
		   case ID_SCALEX:  sFlags ^= GAFL_ScaleX;  set(i_myImage,GA_ScaleFlags,sFlags);  break;
		   case ID_SCALEY:  sFlags ^= GAFL_ScaleY;  set(i_myImage,GA_ScaleFlags,sFlags);  break;
		   case ID_RELX:    sFlags ^= GAFL_RelX;  set(i_myImage,GA_ScaleFlags,sFlags);  break;
		   case ID_RELY:    sFlags ^= GAFL_RelY;  set(i_myImage,GA_ScaleFlags,sFlags);  break;
		   case ID_RELWIDTH:
            get(g_relWidth, MUIA_String_Integer, &relWidth);
            set(i_myImage, GA_ScaleRelWidth, relWidth);
            break;
		   case ID_RELHEIGHT:
            get(g_relHeight, MUIA_String_Integer, &relHeight);
            set(i_myImage, GA_ScaleRelHeight, relHeight);
            break;
		   case ID_ASPECTRATIO:  sFlags ^= GAFL_AspectRatio;  set(i_myImage,GA_ScaleFlags,sFlags);  break;
			case MUIV_Application_ReturnID_Quit:
				running = FALSE;
				break;
		}

		if (running && signals) Wait(signals);
	}

	set(WI_Options,MUIA_Window_Open,FALSE);
	set(WI_Pic,MUIA_Window_Open,FALSE);

/*
** Shut down...
*/

	fail(app,NULL);
}
