/* Copyright 2008 Jeffrey Lee
   This file is part of Pale.
   Pale 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 3 of the License, or
   (at your option) any later version.
   Pale 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 Pale.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PALE_H
#define _PALE_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel.h" //NODEPP
#include "swis.h" //NODEPP

#include "/WoumInclude:lib/limpx.h"

//DEPPEND

#define RNG(a,b,c) ((a)<(b)?(b):((a)>(c)?(c):(a)))

typedef union {
	struct {
		char a;
		char r;
		char g;
		char b;
	};
	int c;
} rgb;

struct _sprfile;

typedef struct _paleditor {
	rgb pal[512]; /* Full 256x2 entry palette */
	int nsprites;
	void **sprites; /* sprite pointers to apply changes to */
	limpx_window *palwin;
	limpx_window *sprlistwin;
	int toolflags;
	int maskindex;
	int highlight;
	int selstart,selend;
	struct _sprfile *file;
	struct _paleditor *next,*prev; /* Linked list of editors */
} paleditor;

#define TOOL_LINK 1
#define TOOL_GRADIENT 2
#define TOOL_COPY 4
#define TOOL_SWAP 8
#define TOOL_SMALL 16

#define PALICON_PALETTE 0
#define PALICON_LINK 1
#define PALICON_GRADIENT 2
#define PALICON_COPY 3
#define PALICON_SWAP 4
#define PALICON_R 6
#define PALICON_G 8
#define PALICON_B 10
#define PALICON_HINT 11

typedef struct _preview {
	void *spr;
	limpx_window *win;
	struct _sprfile *file;
	paleditor *pal;
	int zoom;
	struct _preview *next,*prev;
} preview;

#define ZOOM_MIN -8
#define ZOOM_MAX 8

typedef struct _sprfile {
	char *name; /* filename */
	void *sprs; /* sprite area */
	int len; /* length of area */
	limpx_window *mainwin;
	paleditor *editors;
	preview *previews;
	int modified;
	struct _sprfile *next,*prev;
} sprfile;

extern sprfile *sprfiles;

extern int open_menu;
extern sprfile *open_menu_sprfile;
extern preview *open_menu_preview;
extern paleditor *open_menu_paleditor;

extern limpx_menu *menu_main,*menu_spritefile,*menu_palette,*menu_sprite,*menu_sprlist;
extern int menu_main_info,menu_main_help,menu_main_quit;
extern int menu_spritefile_save;
extern int menu_palette_save,menu_palette_small,menu_palette_mask;
extern int menu_sprite_newview,menu_sprite_save,menu_sprite_zin,menu_sprite_zout;
extern int menu_sprlist_view,menu_sprlist_remove;

#define MENU_NONE 0
#define MENU_MAIN 1
#define MENU_SPRITEFILE 2
#define MENU_PALETTE 3
#define MENU_SPRITE 4
#define MENU_SPRLIST 5
#define MENU_WARN 6

extern limpx_window_header *temp_sprite,*temp_spritefile,*temp_palette,*temp_smpalette,*temp_sprlist;

extern limpx_icon_block temp_iconblock;

extern _kernel_swi_regs regs;
extern int xeig,yeig;

extern int drag_box_active,last_small_flag;

extern void report_error(char *text);
extern int which_window(limpx_window *w,sprfile **ss,preview **pp,paleditor **ee);

#endif
