/* 

		ウィンドウ関係 

		3/29 スタートメニュー描写関数を追加 by is2os
		
*/

#include "bootpack.h"
#include <string.h>

void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act)
{
	boxfill8(buf, xsize, COL8_FFFFFF, 0,         0,         xsize - 1, 0        );
	boxfill8(buf, xsize, COL8_000000, 1,         1,         xsize - 2, 1        );
	boxfill8(buf, xsize, COL8_FFFFFF, 0,         0,         0,         ysize - 1);
	boxfill8(buf, xsize, COL8_000000, 1,         1,         1,         ysize - 2);
	boxfill8(buf, xsize, COL8_FFFFFF, xsize - 2, 1,         xsize - 2, ysize - 2);
	boxfill8(buf, xsize, COL8_000000, xsize - 1, 0,         xsize - 1, ysize - 1);
	boxfill8(buf, xsize, COL8_C6C6C6, 2,         2,         xsize - 3, ysize - 3);
	boxfill8(buf, xsize, COL8_FFFFFF, 1,         ysize - 2, xsize - 2, ysize - 2);
	boxfill8(buf, xsize, COL8_000000, 0,         ysize - 1, xsize - 1, ysize - 1);
	make_wtitle8(buf, xsize, title, act);
	return;
}

/* 一応グローバルに */
static char closebtn[17][18] = {
	"GGGG@@@@@@@@@@GGGG",
	"GGG@@@@@@@@@@@@GGG",
	"GG@@@OOOOOOOO@@@GG",
	"G@@@OOOOOOOOOO@@@G",
	"@@@O@@OOOOOO@@O@@@",
	"@@OO@@OOOOOO@@OO@@",
	"@@OOO@@OOOO@@OOO@@",
	"@@OOO@@OOOO@@OOO@@",
	"@@OOOO@@OO@@OOOO@@",
	"@@OOOOO@@@@OOOOO@@",
	"@@OOOOO@@@@OOOOO@@",
	"@@OOOO@@OO@@OOOO@@",
	"@@@O@@OOOOOO@@O@@@",
	"Q@@@OOOOOOOOOO@@@Q",
	"QQ@@@OOOOOOOO@@@QQ",
	"QQQ@@@@@@@@@@@@QQQ",
	"QQQQ@@@@@@@@@@QQQQ"
};
static char minimumbtn[17][18] = {
	"GGGG@@@@@@@@@@GGGG",
	"GGG@@@@@@@@@@@@GGG",
	"GG@@@OOOOOOOO@@@GG",
	"G@@@OOOO@@OOOO@@@G",
	"@@@OOOOO@@OOOOO@@@",
	"@@OOOOOO@@OOOOOO@@",
	"@@OOOOOO@@OOOOOO@@",
	"@@OOOOOO@@OOOOOO@@",
	"@@OOOOOO@@OOOOOO@@",
	"@@OOOOOO@@OOOOOO@@",
	"@@OOOOOO@@OOOOOO@@",
	"@@OO@@@@@@@@@@OO@@",
	"@@@OO@@@@@@@@OO@@@",
	"Q@@@OOO@@@@OOO@@@Q",
	"QQ@@@OOOOOOOO@@@QQ",
	"QQQ@@@@@@@@@@@@QQQ",
	"QQQQ@@@@@@@@@@QQQQ"
};

void make_wtitle8(unsigned char *buf, int xsize, char *title, char act)
{
	int x, y, slen;
	char c, tc, tbc;

	slen = strlen(title);
	slen = (int)slen * 5;
	slen--;

	if (act != 0) {
		tc = COL8_FFFFFF;
		tbc = 2;
	} else {
		tc = COL8_000000;
		tbc = 2;
	}
	boxfill8(buf, xsize, tbc, 3, 3, xsize - 4, 12);
	boxfill8(buf, xsize, 10, 3, 12, xsize - 4, 20);
	putfonts8_asc(buf, xsize, (int)(xsize / 2) - slen, 4, tc, title);

	/* クローズボタン */
	for (y = 0; y < 17; y++) {
		for (x = 0; x < 18; x++) {
			c = closebtn[y][x];
			if (c == '@') {
				c = COL8_000000;
			} else if (c == '$') {
				c = COL8_848484;
			} else if (c == 'Q') {
				c = 10;
			} else if (c == 'G') {
				c = 2;
			} else {
				c = COL8_FFFFFF;
			}
			buf[(3 + y) * xsize + (xsize - 21 + x)] = c;
		}
	}

	/* ミニマムボタン */
	for (y = 0;y < 17;y++) {
		for (x = 0;x < 18;x++) {
			c = minimumbtn[y][x];
			if (c == '@') {
				c = COL8_000000;
			} else if (c == '$') {
				c = COL8_848484;
			} else if (c == 'Q') {
				c = 10;
			} else if (c == 'G') {
				c = 2;
			} else {
				c = COL8_FFFFFF;
			}
			buf[(2 + y) * xsize + (xsize + 3 + x)] = c;		
		}
	}

	return;
}

void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l)
{
	struct TASK *task = task_now();
	boxfill8(sht->buf, sht->bxsize, b, x, y, x + l * 8 - 1, y + 15);
	if (task->langmode != 0 && task->langbyte1 != 0) {
		putfonts8_asc(sht->buf, sht->bxsize, x, y, c, s);
		sheet_refresh(sht, x - 8, y, x + l * 8, y + 16);
	} else {
		putfonts8_asc(sht->buf, sht->bxsize, x, y, c, s);
		sheet_refresh(sht, x, y, x + l * 8, y + 16);
	}
	return;
}

void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c)
{
	int x1 = x0 + sx, y1 = y0 + sy;
	boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 2, y0 - 3, x1 + 1, y0 - 3);
	boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 3, y0 - 3, x0 - 3, y1 + 1);
	boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 3, y1 + 2, x1 + 1, y1 + 2);
	boxfill8(sht->buf, sht->bxsize, COL8_000000, x1 + 2, y0 - 3, x1 + 2, y1 + 2);
	boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 1, y0 - 2, x1 + 0, y0 - 2);
	boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 2, y0 - 2, x0 - 2, y1 + 0);
	boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 2, y1 + 1, x1 + 0, y1 + 1);
	boxfill8(sht->buf, sht->bxsize, COL8_000000, x1 + 1, y0 - 2, x1 + 1, y1 + 1);
	boxfill8(sht->buf, sht->bxsize, c,           x0 - 1, y0 - 1, x1 + 0, y1 + 0);
	return;
}

void change_wtitle8(struct SHEET *sht, char act)
{
	int x, y, xsize = sht->bxsize;
	char c, tc_new, tbc_new, tc_old, tbc_old, *buf = sht->buf;
	if (act != 0) {
		tc_new  = COL8_FFFFFF;
		tbc_new = COL8_C6C6C6;
		tc_old  = COL8_000000;
		tbc_old = COL8_C6C6C6;
	} else {
		tc_new  = COL8_000000;
		tbc_new = COL8_C6C6C6;
		tc_old  = COL8_FFFFFF;
		tbc_old = COL8_C6C6C6;
	}
	for (y = 3; y <= 20; y++) {
		for (x = 22; x <= xsize - 4; x++) {
			c = buf[y * xsize + x];
			if (c == tc_old && x <= xsize - 22) {
				c = tc_new;
			} else if (c == tbc_old) {
				c = tbc_new;
			}
			buf[y * xsize + x] = c;
		}
	}
	sheet_refresh(sht, 3, 3, xsize, 21);
	return;
}



