#include "commonheaders.h"
#include "cls-menu.h"
#include "initialization.h"

/////////////////////
// CUSTOM CLIPPING //
////////////////////////////////////////////////////////////////////////////////
BITMAP* custom_clip(int customnumber)
{
    FILE *file;
    char pathset[8];
    char fullpath[64];
    char clipval[18];
    char charnum[8];
    
    strclr(fullpath);
    strclr(charnum);
    strcat(fullpath, "Custom\\");
    strcat(fullpath, "clip");
    itoa(customnumber - 11, charnum, 10);
    strcat(fullpath, charnum);
    strcat(fullpath, ".clp");
    
    if((file = fopen(fullpath, "r")) == NULL)
    {
        return NULL;
    }
    else
    {
        BITMAP * temp = create_bitmap(16, 16);
        for(short yloop = 0; yloop < 16; yloop ++)
        {
            fgets(clipval, sizeof(char) * 18, file);
            for(short xloop = 0; xloop < 16; xloop ++)
            {
                if(clipval[xloop] == 49)
                    _putpixel16(temp, xloop, yloop, makecol(128, 0, 128));
            }
        }
	    fclose(file);
	    return temp;
    }
}
	short i = 0;
	ClipImages = (BITMAP **)qualloc(ClipImages, sizeof(BITMAP *) * (i + 1));
	while((ClipImages[i] = custom_clip(i)) != NULL) {
		i ++;
	}
	printf("clips loaded\n");
}
