Ejemplo n.º 1
0
/*
 * Measure the containing box size of a string that spans multiple lines
 */
void CK_MeasureMultiline(const char *str, uint16_t *w, uint16_t *h)
{
	char c;
	uint16_t x, y;
	char buf[80] = {0};
	char *p;

	*h = *w = (uint16_t) 0;
	p = buf;	/* must be a local buffer */

	while ( (c = *str++) != 0 )
	{
		*p++ = c;

		if ( c == '\n' || *str == 0 )
		{
			VH_MeasurePropString( buf, &x, &y, US_GetPrintFont() );

			*h += y;
			if ( *w < x )
				*w = x;

			p = (char *) buf;
			// Shouldn't buf be cleared so that a newline is not read over by
			// VH_MeasurePropString?
		}
	}
}
Ejemplo n.º 2
0
static void USL_XORICursor(uint16_t x, uint16_t y, char *s, uint16_t cursor)
{
	//static	bool	status;		// VGA doesn't XOR...
	static char cursorStr[2] = {0x80, 0};
	char	buf[128];
	uint16_t w, h;

	strcpy(buf, s);
	buf[cursor] = '\0';
	VH_MeasurePropString(buf, &w, &h, us_printFont);
	// TODO: More changes to do here?

	US_SetPrintX(x + w - 1);
	US_SetPrintY(y);

	VH_DrawPropString(cursorStr, US_GetPrintX(), US_GetPrintY(), US_GetPrintFont(), US_GetPrintColour());
#if 0

	if (status^=true)
		VH_DrawPropString("\x80", US_GetPrintX(), US_GetPrintY(), US_GetPrintFont(), US_GetPrintColour());
	else
	{
		temp = us_printColour;
		us_printColour = us_backColour;
		VH_DrawPropString("\x80", US_GetPrintX(), US_GetPrintY(), US_GetPrintFont(), US_GetPrintColour());
		us_printColour = temp;
	}
#endif
}
Ejemplo n.º 3
0
void USL_PrintInCenter(const char *str, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
	uint16_t w, h, rw, rh, px, py;
	VH_MeasurePropString(str, &w, &h, us_printFont);
	rw = x2 - x1;
	rh = y2 - y1;
	px = x1 + (rw - w) / 2;
	py = y1 + (rh - h) / 2;
	VH_DrawPropString(str, px, py, us_printFont, us_printColour);
}
Ejemplo n.º 4
0
void US_CPrintLine(const char *str)
{
	uint16_t w, h;
	CA_CacheGrChunk(3); // TODO: What is this function call doing here?
	VH_MeasurePropString(str, &w, &h, us_printFont);
	if (w <= us_windowW)
	{
		int x = us_windowX + ((us_windowW - w) / 2);
		VH_DrawPropString(str, x, us_printY, us_printFont, us_printColour);
		us_printY += h;
	}
	else
	{
		Quit("US_CPrintLine() - String exceeds width");
	}
}
Ejemplo n.º 5
0
void US_Print(const char *str)
{
	char strbuf[256];
	int sboff = 0;

	while (*str)
	{
		char ch;
		sboff = 0;
		while (true)
		{
			// TODO: Modify this (and possibly more)
			ch = *str;
			str++;
			if (ch == '\0' || ch == '\n')
			{
				strbuf[sboff] = '\0';
				break;
			}
			strbuf[sboff] = ch;
			sboff++;
		}

		uint16_t w, h;
		// TODO: Should us_printFont and us_printColour
		// be passed as arguments or not?
		VH_MeasurePropString(strbuf, &w, &h, us_printFont);
		VH_DrawPropString(strbuf, us_printX, us_printY, us_printFont, us_printColour);


		if (ch)
		{
      // strbuf[sboff] = ch
      // str++;
			us_printX = us_windowX;
			us_printY += h;
		}
		else
		{
			us_printX += w;
			break;
		}
	}
}
Ejemplo n.º 6
0
bool US_LineInput(uint16_t x, uint16_t y, char *buf, char *def, bool escok, uint16_t maxchars, uint16_t maxwidth)
{
	bool		redraw,
		cursorvis, cursormoved,
		done, result;
	IN_ScanCode	sc;
	char	c,
		s[128], olds[128];
	uint16_t i,
	         cursor,
	         w, h,
	         len/*, temp*/;
	uint32_t lasttime;

	if (def)
		strcpy(s, def);
	else
		*s = '\0';
	*olds = '\0';
	cursor = strlen(s);
	cursormoved = redraw = true;

	cursorvis = done = false;
	lasttime = SD_GetTimeCount();

	IN_SetLastASCII(IN_KP_None);
	IN_SetLastScan(IN_SC_None);

	while (!done)
	{
		// TODO/FIXME: Handle this in a possibly better way
		// (no busy loop, updating gfx if required, etc..)
		IN_PumpEvents();
		//CK_SetTicsPerFrame();

		if (cursorvis)
			USL_XORICursor(x, y, s, cursor);

		sc = IN_GetLastScan();
		IN_SetLastScan(IN_SC_None);
		c = IN_GetLastASCII();
		IN_SetLastASCII(IN_KP_None);

		switch (sc)
		{
		case IN_SC_LeftArrow:
			if (cursor)
				cursor--;
			c = 0;
			cursormoved = true;
			break;
		case IN_SC_RightArrow:
			if (s[cursor])
				cursor++;
			c = 0;
			cursormoved = true;
			break;
		case IN_SC_Home:
			cursor = 0;
			c = 0;
			cursormoved = true;
			break;
		case IN_SC_End:
			cursor = strlen(s);
			c = 0;
			cursormoved = true;
			break;

		case IN_SC_Enter:
			strcpy(buf, s);
			done = true;
			result = true;
			c = 0;
			break;
		case IN_SC_Escape:
			if (escok)
			{
				done = true;
				result = false;
			}
			c = 0;
			break;

		case IN_SC_Backspace:
			if (cursor)
			{
				strcpy(s + cursor - 1, s + cursor);
				cursor--;
				redraw = true;
			}
			c = 0;
			cursormoved = true;
			break;
		case IN_SC_Delete:
			if (s[cursor])
			{
				strcpy(s + cursor, s + cursor + 1);
				redraw = true;
			}
			c = 0;
			cursormoved = true;
			break;

		case 0x4c:	// Keypad 5
		case IN_SC_UpArrow:
		case IN_SC_DownArrow:
		case IN_SC_PgUp:
		case IN_SC_PgDown:
		case IN_SC_Insert:
			c = 0;
			break;
		}

		if (c)
		{
			len = strlen(s);
			VH_MeasurePropString(s, &w, &h, US_GetPrintFont());

			if
				(
				 isprint(c)
				 &&	(len < 128 - 1)
				 &&	((!maxchars) || (len < maxchars))
				 &&	((!maxwidth) || (w < maxwidth))
				 )
			{
				for (i = len + 1; i > cursor; i--)
					s[i] = s[i - 1];
				s[cursor++] = c;
				redraw = true;
			}
		}

		if (redraw)
		{
			/*
			px = x;
			py = y;
			 */
			//temp = us_printColour;
			//us_printColour = us_backColour;
			VH_DrawPropString(olds, x, y, us_printFont, us_printColour);
			//us_printColour = temp;
			strcpy(olds, s);

			/*
			px = x;
			py = y;
			 */
			VH_DrawPropString(s, x, y, us_printFont, us_printColour);

			redraw = false;
		}

		if (cursormoved)
		{
			cursorvis = false;
			lasttime = SD_GetTimeCount() - 70 /*TimeCount - TickBase*/;

			cursormoved = false;
		}
		if (SD_GetTimeCount()-lasttime > 35 /*TimeCount - lasttime > TickBase / 2*/)
		{
			lasttime = SD_GetTimeCount();//TimeCount;

			cursorvis ^= true;
		}
		if (cursorvis)
			USL_XORICursor(x, y, s, cursor);

		//VW_UpdateScreen();
		VL_Present();
	}

	if (cursorvis)
		USL_XORICursor(x, y, s, cursor);
	if (!result)
	{
		/*
		px = x;
		py = y;
		*/
		VH_DrawPropString(olds, x, y, us_printFont, us_printColour);
	}

	//VW_UpdateScreen();
	VL_Present();

	IN_ClearKeysDown();
	return (result);
}