#ifndef IMG_H
#define IMG_H

//
//  img.h
//
//  Copyright (c) 2017 Michael Heras
//
//  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 2 of the License, 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 the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307,
//  USA.
//


#define MAX_SHOW_COLORS 100

#include <X11/Xlib.h>
#include </usr/include/Imlib2.h>
#include <random>

enum eDir {STOP = 0, LEFT = 1, UPLEFT = 2, DOWNLEFT = 3, RIGHT = 4, UPRIGHT = 5, DOWNRIGHT = 6};

typedef struct mvImage
{
	private:
		int x,y;
		int width,height;
		int orginalX, orginalY;
		eDir direction;
	public:
        mvImage(void)
		{
			orginalX = 0;
			orginalY = 0;
			x = 0;
			y = 0;
			direction = STOP;
		}
		mvImage(int Xpos, int Ypos)
		{
			orginalX = Xpos;
			orginalY = Ypos;
			x = Xpos;
			y = Ypos;
			direction = STOP;
		}
		void setPos(int posX, int posY)
		{
			x = posX;
			y = posX;
		}
		void reset()
		{
			x = orginalX;
			y = orginalY;
			direction = STOP;
		}
		void start()
		{
			direction = RIGHT;
		}
		void changeDirecton(eDir d)
		{
			direction = d;
		}
		void randomDirection()
		{
			direction = (eDir)((rand() % 6 ) + 1);
		}
		void setWidth(int w)
		{
			width = w;
		}
		void setHeight(int h)
		{
			height = h;
		}
		void setWidth_Height(int w, int h)
		{
			width = w;
			height = h;
		}
		inline int getWidth() { return width; }
		inline int getHeight() { return height; }
		inline int getX() { return x; }
		inline int getY() { return y; }
		inline eDir getDirection() { return direction; }

		void move()
		{
			switch(direction)
			{
				case STOP:
					break;
				case LEFT:
					//x--;
					x -= 50;
					break;
				case RIGHT:
					//x++;
					x += 50;
					break;
				case UPLEFT:
				//	x--; y--;
					x -= 50;
					y -= 50;
					break;
				case DOWNLEFT:
					//x--; y++;
					x -= 50;
					y += 50;
					break;
				case UPRIGHT:
					//x++; y++;
					x += 50;
					y += 50;
					break;
				case DOWNRIGHT:
					//x++; y++;
					x += 50;
					y += 50;
					break;
				default:
					break;
			}
		}
}mvImage;


typedef struct move_image
{
int ww = 0,hh = 0;
int xx = 0;
int yy = 0;
int x =0,y = 0;
int flag = 0;

} move_image;



typedef struct Color
{

int r,g,b,a;

}Color;

typedef struct RandomColors
{
int r1,g1,b1,a1;
int r2,g2,b2,a2;
} RandomColors;


//enum mode_typ
typedef enum   {
    // whatever size image is display it modes.
    //            0                     1           2     3        4         5         6         7
        IMAGE_MODE_DUMMY_ELEMENT = 0, FULLSCREEN, FILL, CENTER,  FLIPIMGD, FLIPIMGH, FLIPIMGV, FLIPAH,
        //8       9       10                    11     12       13     14      15      16     17
        FLIPAV, FLIPAVTH, FLIPAVTV, /*FLIPAD, */ TILE, TILEV, TILEH, TILEHV, TILED, SPACE_TILE, MOVEIMAGE,
     // modified size from orginal size image modes
    // 18     19          20          21        22     23      24      25        26         27
      DCENTER, DFLIPIMGH, DFLIPIMGV, DFLIPIMGD, DTILE, DTILEH, DTILEV, DTILEHV, DTILED, ANGLED_TITLE,
    // 28
      ROTATE

} ImageMode;




typedef struct
{
	Display *display;
	Visual *vis;
	Colormap cm;
	Pixmap pixmap;
	Imlib_Image buffer;
	Imlib_Image image;
	Imlib_Color_Range range;
	Imlib_Context context;
	Imlib_Color_Modifier modifier; // = NULL;
} imlib_data;

typedef struct
{
// Globals for Display and Image:

    int alpha = 256;
    unsigned char mode;
    char *timerSolidColor;
    char *solidColor;
    char findX[15];
    char oppsXChar[15];
	char timer_1_FindX[15];
	char timer_2_FindX[15];
 	char *color1;
 	char *color2;
 	char *name1;
 	char *name2;
	char *rsize;
	char *lsize;
	int image_flag = 0;
    int set_randomize = 0;
    int distance = 0;
    int angle = 0;
    int set_ordered_list = 0;
    int printlistintake = 0;
    int set_over_drive = 0;
    int set_over_ride_system = 0;
    int set_newimg_w = 0;
    int set_newimg_h = 0;
    int set_2_colors = 0;
    int color_flag = 0;
    int flip = 0;
    int set_random_color_num = 0;
    int flips_mode = 0;
    int angle_flag = 0;
    int rotate_angle_flag = 0;
    int rotate_angle_num = 0;
    int screenW = 0;
    int screenH = 0;
    int depth = 0;
    int time = 0;
    size_t file_number = 0;


}image_data;


void Load_OOPs_Image();
bool is_file_exist(const char *fileName);

void setup_images();
void load_image();
void display_image();
void setAlpha(void);
int setRootAtoms (void);
int parse_color(char *col, int *r, int *g, int *b, int *a);
double get_aspect(int x);
int get_adjusted_by_aspect(double aspect, int x);
int get_readjusted_size(int h, int w, int wantedSize);
int64_t int_or_ch(char *data);
int findX(char *whereisX, unsigned int *wantW, unsigned int *wantH);


int findXChar(char *whereisX, char *wantW, char *wantH);

int gettingWidthHeight(char *data, unsigned int *w, unsigned int *h);

int seconds_or_minutes(char *what_is_it);
void set_image();
void set_buffer();
void set_blend();
double space_tile_gap(int which_gap);
void set_flip_tile(int w, int h, int flip);
void Flips_Spaced_Tile_Switch(void);
void BadFindX(char *bad);
void BeyondMaxColors(char *c);
void set_oops_color();
void NoParse(char *clr);
void warning_message();
char *getUserName();
void usage(char *argv[]);
void get_randoms();
int rotate_angle(int d);
void set_display();
int get_readjusted_size(int h, int w, int wantedSize);
void fill_rectangle(void);
void set_color(void);
void set_one_solid_color(void);
void set_two_colors(void);
void set_one_random_color(void);
void set_two_random_colors(void);
void set_colors(void);
int getPoints(char *data, unsigned int *x, unsigned int *y);

int Max(double x, double y);

extern imlib_data imgdata;
extern image_data img;
extern Color c;
extern RandomColors rc;
extern move_image mi;
extern mvImage mvi;

#endif
