/*----------------------------------------------------------------------------------------
	Ver1.00	01/01/18 22:02:52
----------------------------------------------------------------------------------------*/

#include <sys/bios.h>
#include "..\WWCMain.h"
#include "BmpView.h"

/*----------------------------------------------------------------------------------------
	グローバル変数
----------------------------------------------------------------------------------------*/

UCHAR ImageBuf0[WWC_FORM_WIDTH*WWC_FORM_HEIGHT*32];
UCHAR ImageBuf1[10*10*32];
UCHAR ImageBuf2[10*10*32];
UCHAR ImageBuf3[10*10*32];
UCHAR FileList[18][MAXFNAME];
int FileListPos;

/*----------------------------------------------------------------------------------------
	WWCInitはWWCToolが管理しています。
----------------------------------------------------------------------------------------*/
/*WWCTool*/

/*--------------------------------------------------------------------------------------*/

void WWCInit(void)
{

	Form->OnCreate = &EFormCreate;
	Form->StartClose = true;
	Image0->Image = ImageBuf0;
	Image0->Enabled = true;
	Image0->OnKeyUp = &EImage0KeyUp;
	Image1->Left = 5;
	Image1->Top = 5;
	Image1->Width = 10;
	Image1->Height = 10;
	Image1->Image = ImageBuf1;
	Image1->ImageWidth = 10;
	Image1->ImageHeight = 10;
	Image1->OnKeyUp = &EImage1KeyUp;
	Image2->Width = 10;
	Image2->Top = 5;
	Image2->Left = 5;
	Image2->Height = 10;
	Image2->Image = ImageBuf2;
	Image2->ImageWidth = 10;
	Image2->ImageHeight = 10;
	Image3->Left = 5;
	Image3->Top = 5;
	Image3->Width = 10;
	Image3->Height = 10;
	Image3->Image = ImageBuf3;
	Image3->ImageWidth = 10;
	Image3->ImageHeight = 10;
}

/*--------------------------------------------------------------------------------------*/

void EFormCreate(void)
{
	chdir("/rom0/");
	EImage0KeyUp(Key->ExUp);
}

/*--------------------------------------------------------------------------------------*/

void EImage0KeyUp(UINT Keys)
{
	int Size, n;

	if(Keys & Key->ExUp){
		ImageFill(Image0, (WHITE<<4)|WHITE); 
		Size = FileGetName(FileList, "", 18);
		for(n=0;n < Size;n++){
			FileList[n][MAXFNAME-1] = 0;
			ImagePuts(Image0, 0, n, FileList[n], BLACK, WHITE);
		}
	}

	ImagePuts(Image0, 0, FileListPos, FileList[FileListPos], BLACK, WHITE);
	if(Keys & Key->Up){
		if(FileListPos > 0){
			FileListPos--;
		}
	}
	if(Keys & Key->Down){
		if(FileListPos < 18-1){
			FileListPos++;
		}
	}
	ImagePuts(Image0, 0, FileListPos, FileList[FileListPos], WHITE, BLACK);
	if(Keys & Key->Enter){
		Image12Fill(0x00, 0x00, 0x00); 
		if(Image12LoadFromFile(FileList[FileListPos]) == true){
			Form->Color12bit=true;
			Form->Focused = 1;
		}
	}
}

/*--------------------------------------------------------------------------------------*/

void EImage1KeyUp(UINT Keys)
{
	if(Keys & Key->ExUp){
		Form->Color12bit=false;
		Form->Focused = 0;
	}
	if(Keys & Key->Right){
		Image1->Left++;
	}
	if(Keys & Key->Left){
		Image1->Left--;
	}
	if(Keys & Key->Up){
		Image1->Top--;
	}
	if(Keys & Key->Down){
		Image1->Top++;
	}
	if(Keys & Key->Esc){
		FormViewChange(!Form->TateView);
		Form->Color12bit=false;
		Form->Focused = 0;
		EImage0KeyUp(Key->ExUp);
	}
}

/*--------------------------------------------------------------------------------------*/
