Example #1
0
///////////////////////////////////////////////////////////////////////////
//
//	USL_XORICursor() - XORs the I-bar text cursor. Used by US_LineInput()
//
///////////////////////////////////////////////////////////////////////////
static void
USL_XORICursor(int x,int y,char *s,word cursor)
{
	static	boolean	status;		// VGA doesn't XOR...
	char	buf[MaxString];
	int		temp;
	word	w,h;

	strcpy(buf,s);
	buf[cursor] = '\0';
	USL_MeasureString(buf,&w,&h);

	px = x + w - 1;
	py = y;
	if (status^=1)
		USL_DrawString("\x80");
	else
	{
		temp = fontcolor;
		fontcolor = backcolor;
		USL_DrawString("\x80");
		fontcolor = temp;
	}

}
Example #2
0
void ShPrint(
    const char* text,
    int8_t shadow_color,
    bool single_char)
{
    uint16_t old_color = fontcolor, old_x = px, old_y = py;
    const char* string;
    char buf[2] = { 0, 0 };

    if (single_char) {
        string = buf;
        buf[0] = *(char*)text;
    } else {
        string = text;
    }

    fontcolor = shadow_color;
    py++;
    px++;
    USL_DrawString(string); // JTR - This marks blocks!

    fontcolor = static_cast<uint8_t>(old_color);
    py = old_y;
    px = old_x;
    USL_DrawString(string); // JTR - This marks blocks!
}
///////////////////////////////////////////////////////////////////////////
//
//  US_Print() - Prints a string in the current window. Newlines are
//      supported.
//
///////////////////////////////////////////////////////////////////////////
void US_Print(const char *sorg)
{
   word w,h;
   char c, *se;
   char *sstart = strdup(sorg);
   char *s = sstart;

   while (*s)
   {
      se = s;
      while ((c = *se)!=0 && (c != '\n'))
         se++;
      *se = '\0';

      USL_MeasureString(s,&w,&h);
      px = PrintX;
      py = PrintY;
      USL_DrawString(s);

      s = se;
      if (c)
      {
         *se = c;
         s++;

         PrintX = WindowX;
         PrintY += h;
      }
      else
         PrintX += w;
   }
   free(sstart);
}
Example #4
0
///////////////////////////////////////////////////////////////////////////
//
//	US_Print() - Prints a string in the current window. Newlines are
//		supported.
//
///////////////////////////////////////////////////////////////////////////
void
US_Print(char far *s)
{
	char	c,far *se;
	word	w,h;

	while (*s)
	{
		se = s;
		while ((c = *se) && (c != '\n'))
			se++;
		*se = '\0';

		USL_MeasureString(s,&w,&h);
		px = PrintX;
		py = PrintY;
		USL_DrawString(s);

		s = se;
		if (c)
		{
			*se = c;
			s++;

			PrintX = WindowX;
			PrintY += h;
		}
		else
			PrintX += w;
	}
}
Example #5
0
///////////////////////////////////////////////////////////////////////////
//
//	USL_PrintInCenter() - Prints a string in the center of the given rect
//
///////////////////////////////////////////////////////////////////////////
void USL_PrintInCenter(char *s, Rect r)
{
	word w, h, rw, rh;

	USL_MeasureString(s, &w, &h);
	rw = r.lr.x - r.ul.x;
	rh = r.lr.y - r.ul.y;

	px = r.ul.x + ((rw - w) / 2);
	py = r.ul.y + ((rh - h) / 2);
	USL_DrawString(s);
}
///////////////////////////////////////////////////////////////////////////
//
//  US_CPrintLine() - Prints a string centered on the current line and
//      advances to the next line. Newlines are not supported.
//
///////////////////////////////////////////////////////////////////////////
void US_CPrintLine(const char *s)
{
   word    w,h;

   USL_MeasureString(s,&w,&h);

   if (w > WindowW)
      Quit("US_CPrintLine() - String exceeds width");
   px = WindowX + ((WindowW - w) / 2);
   py = PrintY;
   USL_DrawString(s);
   PrintY += h;
}
Example #7
0
void ShPrint(char far *text, char shadow_color, boolean single_char)
{
	unsigned old_color=fontcolor,old_x=px,old_y=py;
	char far *str,buf[2]={0,0};

	if (single_char)
	{
		str = buf;
		buf[0]=*text;
	}
	else
		str = text;

	fontcolor = shadow_color;
	py++;
	px++;
	USL_DrawString(str);						// JTR - This marks blocks!

	fontcolor = old_color;
	py = old_y;
	px = old_x;
	USL_DrawString(str);						// JTR - This marks blocks!
}
///////////////////////////////////////////////////////////////////////////
//
//      USL_XORICursor() - XORs the I-bar text cursor. Used by US_LineInput()
//
///////////////////////////////////////////////////////////////////////////
static void
USL_XORICursor(int x,int y,char *s,word cursor)
{
	char    buf[MaxString];
	word    w,h;

	strcpy(buf,s);
	buf[cursor] = '\0';
	USL_MeasureString(buf,&w,&h);

	px = x + w - 1;
	py = y;
	USL_DrawString("\x80");
}
Example #9
0
///////////////////////////////////////////////////////////////////////////
//
//	US_Print() - Prints a string in the current window. Newlines are
//		supported.
//
///////////////////////////////////////////////////////////////////////////
void
US_Print(const char *sorg)
{
	char c;
	char *sstart = strdup(sorg);
	char *s = sstart;
	char *se;
	word w,h;
//	slPrint((char *)sorg,slLocate(2,10));
//#if 0
	while (*s)
	{
		se = s;
		while ((c = *se)!=0 && (c != '\n'))
			se++;
		*se = '\0';

		USL_MeasureString(s,&w,&h);
		px = PrintX;
		py = PrintY;
		USL_DrawString(s);

		s = se;
		if (c)
		{
			*se = c;
			s++;

			PrintX = WindowX;
			PrintY += h;
		}
		else
			PrintX += w;
	}
	free(sstart);
//#endif
}
Example #10
0
///////////////////////////////////////////////////////////////////////////
//
//	US_Print() - Prints a string in the current window. Newlines are
//		supported.
//
///////////////////////////////////////////////////////////////////////////
void US_Print(char *str)
{
	char c, *se, *s, *sz = strdup(str);
	word w, h;
	s = sz;
	
	while (*s)
	{
		se = s;
		while ((c = *se) && (c != '\n'))
			se++;
		*se = '\0';

		USL_MeasureString(s,&w,&h);
		px = PrintX;
		py = PrintY;
		USL_DrawString(s);

		s = se;
		if (c)
		{
			*se = c;
			s++;

			PrintX = WindowX;
			PrintY += h;
		}
		else
			PrintX += w;
	}
	
	px = PrintX;
	py = PrintY;
	
	free(sz);
}
Example #11
0
///////////////////////////////////////////////////////////////////////////
//
//  US_LineInput() - Gets a line of user input at (x,y), the string defaults
//      to whatever is pointed at by def. Input is restricted to maxchars
//      chars or maxwidth pixels wide. If the user hits escape (and escok is
//      true), nothing is copied into buf, and false is returned. If the
//      user hits return, the current string is copied into buf, and true is
//      returned
//
///////////////////////////////////////////////////////////////////////////
boolean
US_LineInput(int x,int y,char *buf,const char *def,boolean escok,
                int maxchars,int maxwidth)
{
   boolean     redraw,
               cursorvis,cursormoved,
               done,result, checkkey;
   ScanCode    sc;
   char        c;
   char        s[MaxString],olds[MaxString];
   int         cursor,len;
   word        i,
               w,h,
               temp;
   longword    curtime, lasttime, lastdirtime, lastbuttontime, lastdirmovetime;
   ControlInfo ci;
   Direction   lastdir = dir_None;

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

   cursorvis = done = false;
   lasttime = lastdirtime = lastdirmovetime = GetTimeCount();
   lastbuttontime = lasttime + TickBase / 4;   // 250 ms => first button press accepted after 500 ms
   LastASCII = key_None;
   LastScan = sc_None;

   while (!done)
   {
      ReadAnyControl(&ci);

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

      sc = LastScan;
      LastScan = sc_None;
      c = LastASCII;
      LastASCII = key_None;

      checkkey = true;
      curtime = GetTimeCount();

      // After each direction change accept the next change after 250 ms and then everz 125 ms
      if(ci.dir != lastdir || ((curtime - lastdirtime > TickBase / 4) && (curtime - lastdirmovetime > TickBase / 8)))
      {
         if(ci.dir != lastdir)
         {
            lastdir = ci.dir;
            lastdirtime = curtime;
         }
         lastdirmovetime = curtime;

         switch(ci.dir)
         {
            case dir_West:
               if(cursor)
               {
                  // Remove trailing whitespace if cursor is at end of string
                  if(s[cursor] == ' ' && s[cursor + 1] == 0)
                     s[cursor] = 0;
                  cursor--;
               }
               cursormoved = true;
               checkkey = false;
               break;
            case dir_East:
               if(cursor >= MaxString - 1) break;

               if(!s[cursor])
               {
                  USL_MeasureString(s,&w,&h);
                  if(len >= maxchars || (maxwidth && w >= maxwidth))
                     break;

                  s[cursor] = ' ';
                  s[cursor + 1] = 0;
               }
               cursor++;
               cursormoved = true;
               checkkey = false;
               break;

            case dir_North:
               if(!s[cursor])
               {
                  USL_MeasureString(s,&w,&h);
                  if(len >= maxchars || (maxwidth && w >= maxwidth))
                     break;
                  s[cursor + 1] = 0;
               }
               s[cursor] = USL_RotateChar(s[cursor], 1);
               redraw = true;
               checkkey = false;
               break;

            case dir_South:
               if(!s[cursor])
               {
                  USL_MeasureString(s,&w,&h);
                  if(len >= maxchars || (maxwidth && w >= maxwidth))
                     break;
                  s[cursor + 1] = 0;
               }
               s[cursor] = USL_RotateChar(s[cursor], -1);
               redraw = true;
               checkkey = false;
               break;
            default:
               break;
         }
      }

      if((int)(curtime - lastbuttontime) > TickBase / 4)   // 250 ms
      {
         if(ci.button0)             // acts as return
         {
            strcpy(buf,s);
            done = true;
            result = true;
            checkkey = false;
         }
         if(ci.button1 && escok)    // acts as escape
         {
            done = true;
            result = false;
            checkkey = false;
         }
         if(ci.button2)             // acts as backspace
         {
            lastbuttontime = curtime;
            if(cursor)
            {
               strcpy(s + cursor - 1,s + cursor);
               cursor--;
               redraw = true;
            }
            cursormoved = true;
            checkkey = false;
         }
      }

      if(checkkey)
      {
         switch (sc)
         {
            case sc_LeftArrow:
               if (cursor)
                  cursor--;
               c = key_None;
               cursormoved = true;
               break;
            case sc_RightArrow:
               if (s[cursor])
                  cursor++;
               c = key_None;
               cursormoved = true;
               break;
            case sc_Home:
               cursor = 0;
               c = key_None;
               cursormoved = true;
               break;
            case sc_End:
               cursor = (int) strlen(s);
               c = key_None;
               cursormoved = true;
               break;

            case sc_Return:
               strcpy(buf,s);
               done = true;
               result = true;
               c = key_None;
               break;
            case sc_Escape:
               if (escok)
               {
                  done = true;
                  result = false;
               }
               c = key_None;
               break;

            case sc_BackSpace:
               if (cursor)
               {
                  strcpy(s + cursor - 1,s + cursor);
                  cursor--;
                  redraw = true;
               }
               c = key_None;
               cursormoved = true;
               break;
            case sc_Delete:
               if (s[cursor])
               {
                  strcpy(s + cursor,s + cursor + 1);
                  redraw = true;
               }
               c = key_None;
               cursormoved = true;
               break;

            case SDLK_KP5: //0x4c:  // Keypad 5 // TODO: hmmm...
            case sc_UpArrow:
            case sc_DownArrow:
            case sc_PgUp:
            case sc_PgDn:
            case sc_Insert:
               c = key_None;
               break;
         }

         if (c)
         {
            len = (int) strlen(s);
            USL_MeasureString(s,&w,&h);

            if(isprint(c) && (len < MaxString - 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 = fontcolor;
         fontcolor = backcolor;
         USL_DrawString(olds);
         fontcolor = (byte) temp;
         strcpy(olds,s);

         px = x;
         py = y;
         USL_DrawString(s);

         redraw = false;
      }

      if (cursormoved)
      {
         cursorvis = false;
         lasttime = curtime - TickBase;

         cursormoved = false;
      }
      if (curtime - lasttime > TickBase / 2)    // 500 ms
      {
         lasttime = curtime;

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

      VW_UpdateScreen();
   }

   if (cursorvis)
      USL_XORICursor(x,y,s,cursor);
   if (!result)
   {
      px = x;
      py = y;
      USL_DrawString(olds);
   }
   VW_UpdateScreen();

   IN_ClearKeysDown();
   return(result);
}
Example #12
0
///////////////////////////////////////////////////////////////////////////
//
//	US_LineInput() - Gets a line of user input at (x,y), the string defaults
//		to whatever is pointed at by def. Input is restricted to maxchars
//		chars or maxwidth pixels wide. If the user hits escape (and escok is
//		true), nothing is copied into buf, and false is returned. If the
//		user hits return, the current string is copied into buf, and true is
//		returned
//
///////////////////////////////////////////////////////////////////////////
boolean US_LineInput(int x,int y,char *buf,char *def,boolean escok,
				int maxchars,int maxwidth)
{
	boolean	redraw, cursorvis, cursormoved, done, result = true;
	ScanCode sc;
	char c, s[MaxString], olds[MaxString];
	word i, cursor, w, h, len, temp;
	longword lasttime;

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

	cursorvis = done = false;
	lasttime = get_TimeCount();
	LastASCII = key_None;
	LastScan = sc_None;

	while (!done)
	{
		if (cursorvis)
			USL_XORICursor(x,y,s,cursor);

		IN_CheckAck();
		
		sc = LastScan;
		LastScan = sc_None;
		c = LastASCII;
		LastASCII = key_None;

		switch (sc)
		{
		case sc_LeftArrow:
			if (cursor)
				cursor--;
			c = key_None;
			cursormoved = true;
			break;
		case sc_RightArrow:
			if (s[cursor])
				cursor++;
			c = key_None;
			cursormoved = true;
			break;
		case sc_Home:
			cursor = 0;
			c = key_None;
			cursormoved = true;
			break;
		case sc_End:
			cursor = strlen(s);
			c = key_None;
			cursormoved = true;
			break;

		case sc_Return:
			strcpy(buf,s);
			done = true;
			result = true;
			c = key_None;
			break;
		case sc_Escape:
			if (escok)
			{
				done = true;
				result = false;
			}
			c = key_None;
			break;

		case sc_BackSpace:
			if (cursor)
			{
				strcpy(s + cursor - 1,s + cursor);
				cursor--;
				redraw = true;
			}
			c = key_None;
			cursormoved = true;
			break;
		case sc_Delete:
			if (s[cursor])
			{
				strcpy(s + cursor,s + cursor + 1);
				redraw = true;
			}
			c = key_None;
			cursormoved = true;
			break;

		case 0x4c:	// Keypad 5
		case sc_UpArrow:
		case sc_DownArrow:
		case sc_PgUp:
		case sc_PgDn:
		case sc_Insert:
			c = key_None;
			break;
		}

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

			if
			(
				isprint(c)
			&&	(len < MaxString - 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 = fontcolor;
			fontcolor = backcolor;
			USL_DrawString(olds);
			fontcolor = temp;
			strcpy(olds,s);

			px = x;
			py = y;
			USL_DrawString(s);

			redraw = false;
		}

		if (cursormoved)
		{
			cursorvis = false;
			lasttime = get_TimeCount() - TickBase;

			cursormoved = false;
		}
		if ( (get_TimeCount() - lasttime) > (TickBase / 2) )
		{
			lasttime = get_TimeCount();

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

		VW_UpdateScreen();
	}

	if (cursorvis)
		USL_XORICursor(x,y,s,cursor);
	if (!result)
	{
		px = x;
		py = y;
		USL_DrawString(olds);
	}
	VW_UpdateScreen();

	IN_ClearKeysDown();
	return(result);
}