/**Iconize.c*************************************************************
 *									*
 *   SeePix -- by Hank Schafer						*
 *									*
 *   SeePix is an IFF Picture Viewer.  It works with Lo-Res,		*
 *   Med-Res, Hi-Res, HAM, and EHB formats.  I'm working on support     *
 *   for X-Specs, and Anim5 formats.					*
 *									*
 *   SeePix is based on a program by Olaf Barthel, called		*
 *   'LoadImage'.  As released, LoadImage had a couple of bugs. 	*
 *   The Amiga-Key alternatives to menu use didn't all work.  That's	*
 *   been fixed.  There were two separate print functions in LoadImage	*
 *   which behaved exactly the same.  The redundancy was eliminated.	*
 *   LoadImage used the Topaz ROMFONT, and made no allowances for a	*
 *   different system default font (under 2.04).  I added a built-in	*
 *   font.  I've reworked the code considerably from the original       *
 *   release, to allow for optimizations based on time and space.	*
 *									*
 *   SeePix features a palette tool which allows "tweaking" of colors	*
 *   prior to printing, allowing you to modify the color printout to	*
 *   more closely resemble the original graphics (Blue is Blue, not	*
 *   Purple).  SeePix can be Iconified.  SeePix features an ARP 	*
 *   interface.  SeePix now uses the PathMaster File Selector.		*
 *									*
 ************************************************************************
 *                                                                      *
 *   SeePix Copyright © 1992 by Hank Schafer; all rights reserved.      *
 *                                                                      *
 *   This program is free software; you can redistribute it and/or      *
 *   modify it under the terms of the GNU General Public License as     *
 *   published by the Free Software Foundation, either version 1, or    *
 *   (at your option) any later version.                                *
 *                                                                      *
 *   This program is distributed in the hope that it will be useful,    *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  *
 *   General Public License for more details.                           *
 *                                                                      *
 *   You should have received a copy of the GNU General Public License  *
 *   along with this program; if not, write to:                         *
 *                 Free Software Foundation, Inc.                       *
 *                 675 Massachusetts Ave.                               *
 *                 Cambridge  MA  02139, USA                            *
 *                                                                      *
 **************** Special Function Copyright Notices ********************
 *									*
 ****LoadImage Copyright Notice:					*
 *									*
 *   LoadImage is © Copyright 1988, 1989, 1990 by MXM, all rights	*
 *   reserved, written by Olaf Barthel.  No guarantees of any kind are	*
 *   made that this program is 100% reliable.  Use this program on	*
 *   your own risk!							*
 *									*
 ****Iconify Copyright Notice:						*
 *									*
 *   Copyright 1987 by Leo L. Schwab.					*
 *   Permission is hereby granted for use in any and all programs,	*
 *   both Public Domain and commercial in nature, provided this 	*
 *   Copyright notice is left intact.					*
 *									*
 ****ColorWindow (Palette) Copyright Notice:				*
 *									*
 * ColorWindow Routine	--  Color Window Routines			*
 *     from Book 1 of the Amiga Programmers' Suite by RJ Mical          *
 *									*
 * Copyright (C) 1986, 1987, Robert J. Mical				*
 * All Rights Reserved. 						*
 *									*
 ****PathMaster Copyright Notice:					*
 *									*
 * -------------------------------------------------------------------- *
 *   Copyright © 1989 Justin V. McCormick.  All Rights Reserved.	*
 * -------------------------------------------------------------------- *
 *									*
 *    The PathMaster name is a trademark of Justin V. McCormick.	*
 *									*
 *   PathMaster File Selector source and documentation written by:	*
 *									*
 *			 Justin V. McCormick.				*
 *	       Copyright © 1989 by Justin V. McCormick. 		*
 *			 All Rights Reserved.				*
 *									*
 * -------------------------------------------------------------------- *
 ************************************************************************
 *									*
 *   Hope this is something you can use and enjoy.			*
 *									*
 ************************************************************************/

/*
 * Iconize()
 *
 * The code that invokes Iconify(), plus the Icon itself.
 */

/* The SeePix Icon */

UWORD		Icon[54] =
{
    0x7E00, 0x00FE, 0x3000, 0xC000, 0x00C6, 0x0000,
    0x7C7C, 0x7CC6, 0x30C6, 0x06C6, 0xC6CC, 0x306C,
    0x06DE, 0xDEF8, 0x3038, 0x0CC0, 0xC0C0, 0x306C,
    0x187C, 0x7CC0, 0x30C6, 0x3000, 0x0000, 0x0000,
    0x0000, 0x0000, 0x0000, 0x7E00, 0x00FE, 0x3000,
    0xFE00, 0x00FE, 0x3000, 0xFC7C, 0x7CC6, 0x30C6,
    0x7EFE, 0xFECE, 0x30EE, 0x06DE, 0xDEFC, 0x307C,
    0x0EDE, 0xDEF8, 0x307C, 0x1CFC, 0xFCC0, 0x30EE,
    0x387C, 0x7CC0, 0x30C6, 0x3000, 0x0000, 0x0000
};

struct Image	iconimg =
{
    0, 0,			/* LeftEdge, TopEdge */
    47, 9, 2,			/* Width, Height, Depth */
    &Icon[0],			/* ImageData */
    0x03, 0x00,			/* PlanePick, PlaneOnOff */
    NULL			/* NextImage */
};

/* Macros to center the icon on the screen */

#define IkonW	47
#define	IkonH	9
#define CenterX(IkonW)(WinW/2-(IkonW)/2)
#define CenterY(IkonH)(WinH/2-(IkonH)/2)

int
Iconize()
{
    static UWORD    iconX = CenterX(IkonW), iconY = CenterY(IkonH);
    UWORD	   *chipbitmap;
    struct Image   *chipimg;
    extern WORD     toggling;
    if (NULL == (chipbitmap = (UWORD *) AllocMem((ULONG) sizeof(Icon), MEMF_CHIP | MEMF_PUBLIC))) {
	Printf("Can't allocate image bitmap");
	return FALSE;
    }
    BCopy((char *) Icon, (char *) chipbitmap, (int) sizeof(Icon));
    if (NULL == (chipimg = (struct Image *) AllocMem((ULONG) sizeof(iconimg), MEMF_CHIP | MEMF_PUBLIC))) {
	FreeMem(chipbitmap, (ULONG) sizeof(iconimg));
	Printf("Can't allocate image structure");
	return FALSE;
    }
    BCopy((char *) &iconimg, (char *) chipimg, (int) sizeof(iconimg));
    chipimg->ImageData = chipbitmap;
    Iconify(&iconX, &iconY, chipimg->Width, chipimg->Height, NULL, (CPTR) chipimg, (int) ICON_IMAGE);
    FreeMem(chipimg, (ULONG) sizeof(iconimg));
    FreeMem(chipbitmap, (ULONG) sizeof(Icon));
    return TRUE;
}
