コード例 #1
0
//converts a string into a tranlation.
EColorRange SBarInfo::GetTranslation(FScanner &sc, const char* translation)
{
	EColorRange returnVal = CR_UNTRANSLATED;
	FString namedTranslation; //we must send in "[translation]"
	const BYTE *trans_ptr;
	namedTranslation.Format("[%s]", translation);
	trans_ptr = (const BYTE *)(&namedTranslation[0]);
	if((returnVal = V_ParseFontColor(trans_ptr, CR_UNTRANSLATED, CR_UNTRANSLATED)) == CR_UNDEFINED)
	{
		sc.ScriptError("Missing definition for color %s.", translation);
	}
	return returnVal;
}
コード例 #2
0
ファイル: g_skill.cpp プロジェクト: BenJamesbabala/ViZDoom
int FSkillInfo::GetTextColor() const
{
	if (TextColor.IsEmpty())
	{
		return CR_UNTRANSLATED;
	}
	const BYTE *cp = (const BYTE *)TextColor.GetChars();
	int color = V_ParseFontColor(cp, 0, 0);
	if (color == CR_UNDEFINED)
	{
		Printf("Undefined color '%s' in definition of skill %s\n", TextColor.GetChars(), Name.GetChars());
		color = CR_UNTRANSLATED;
	}
	return color;
}
コード例 #3
0
ファイル: teaminfo.cpp プロジェクト: 1Akula1/gzdoom
int FTeam::GetTextColor () const
{
	if (m_TextColor.IsEmpty ())
		return CR_UNTRANSLATED;

	const BYTE *pColor = (const BYTE *)m_TextColor.GetChars ();
	int iColor = V_ParseFontColor (pColor, 0, 0);

	if (iColor == CR_UNDEFINED)
	{
		Printf ("GetTextColor: Undefined color '%s' in definition of team '%s'.\n", m_TextColor.GetChars (), m_Name.GetChars ());
		return CR_UNTRANSLATED;
	}

	return iColor;
}
コード例 #4
0
ファイル: i_system.cpp プロジェクト: Tox86/gzdoom
static void DoPrintStr(const char *cp, HWND edit, HANDLE StdOut)
{
	if (edit == NULL && StdOut == NULL)
		return;

	char buf[256];
	wchar_t wbuf[countof(buf)];
	int bpos = 0;
	CHARRANGE selection;
	CHARRANGE endselection;
	LONG lines_before = 0, lines_after;
	CHARFORMAT format;

	if (edit != NULL)
	{
		// Store the current selection and set it to the end so we can append text.
		SendMessage(edit, EM_EXGETSEL, 0, (LPARAM)&selection);
		endselection.cpMax = endselection.cpMin = GetWindowTextLength(edit);
		SendMessage(edit, EM_EXSETSEL, 0, (LPARAM)&endselection);

		// GetWindowTextLength and EM_EXSETSEL can disagree on where the end of
		// the text is. Find out what EM_EXSETSEL thought it was and use that later.
		SendMessage(edit, EM_EXGETSEL, 0, (LPARAM)&endselection);

		// Remember how many lines there were before we added text.
		lines_before = (LONG)SendMessage(edit, EM_GETLINECOUNT, 0, 0);
	}

	while (*cp != 0)
	{
		// 28 is the escape code for a color change.
		if ((*cp == 28 && bpos != 0) || bpos == 255)
		{
			buf[bpos] = 0;
			if (edit != NULL)
			{
				ToEditControl(edit, buf, wbuf, bpos);
			}
			if (StdOut != NULL)
			{
				DWORD bytes_written;
				WriteFile(StdOut, buf, bpos, &bytes_written, NULL);
			}
			bpos = 0;
		}
		if (*cp != 28)
		{
			buf[bpos++] = *cp++;
		}
		else
		{
			const BYTE *color_id = (const BYTE *)cp + 1;
			EColorRange range = V_ParseFontColor(color_id, CR_UNTRANSLATED, CR_YELLOW);
			cp = (const char *)color_id;

			if (range != CR_UNDEFINED)
			{
				// Change the color of future text added to the control.
				PalEntry color = V_LogColorFromColorRange(range);
				if (StdOut != NULL && FancyStdOut)
				{
					// Unfortunately, we are pretty limited here: There are only
					// eight basic colors, and each comes in a dark and a bright
					// variety.
					float h, s, v, r, g, b;
					WORD attrib = 0;

					RGBtoHSV(color.r / 255.f, color.g / 255.f, color.b / 255.f, &h, &s, &v);
					if (s != 0)
					{ // color
						HSVtoRGB(&r, &g, &b, h, 1, 1);
						if (r == 1)  attrib  = FOREGROUND_RED;
						if (g == 1)  attrib |= FOREGROUND_GREEN;
						if (b == 1)  attrib |= FOREGROUND_BLUE;
						if (v > 0.6) attrib |= FOREGROUND_INTENSITY;
					}
					else
					{ // gray
						     if (v < 0.33) attrib = FOREGROUND_INTENSITY;
						else if (v < 0.90) attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
						else			   attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
					}
					SetConsoleTextAttribute(StdOut, attrib);
				}
				if (edit != NULL)
				{
					// GDI uses BGR colors, but color is RGB, so swap the R and the B.
					swapvalues(color.r, color.b);
					// Change the color.
					format.cbSize = sizeof(format);
					format.dwMask = CFM_COLOR;
					format.dwEffects = 0;
					format.crTextColor = color;
					SendMessage(edit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
				}
			}
		}
	}
	if (bpos != 0)
	{
		buf[bpos] = 0;
		if (edit != NULL)
		{
			ToEditControl(edit, buf, wbuf, bpos);
		}
		if (StdOut != NULL)
		{
			DWORD bytes_written;
			WriteFile(StdOut, buf, bpos, &bytes_written, NULL);
		}
	}

	if (edit != NULL)
	{
		// If the old selection was at the end of the text, keep it at the end and
		// scroll. Don't scroll if the selection is anywhere else.
		if (selection.cpMin == endselection.cpMin && selection.cpMax == endselection.cpMax)
		{
			selection.cpMax = selection.cpMin = GetWindowTextLength (edit);
			lines_after = (LONG)SendMessage(edit, EM_GETLINECOUNT, 0, 0);
			if (lines_after > lines_before)
			{
				SendMessage(edit, EM_LINESCROLL, 0, lines_after - lines_before);
			}
		}
		// Restore the previous selection.
		SendMessage(edit, EM_EXSETSEL, 0, (LPARAM)&selection);
		// Give the edit control a chance to redraw itself.
		I_GetEvent();
	}
	if (StdOut != NULL && FancyStdOut)
	{ // Set text back to gray, in case it was changed.
		SetConsoleTextAttribute(StdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	}
}
コード例 #5
0
ファイル: wl_text.cpp プロジェクト: JohnnyonFlame/ecwolf
void HandleCommand (bool helphack)
{
    int     i,margin,top,bottom;
    int     picmid;

    switch (toupper(*++text))
    {
    case 'B':
    {
        double bx = ParseNumber();
        double by = ParseNumber();
        double bw = ParseNumber();
        double bh = ParseNumber();
        MenuToRealCoords(bx, by, bw, bh, MENU_CENTER);
        VWB_DrawFill(backgroundFlat, (int)bx, (int)by, (int)(bx+bw), (int)(by+bh));
        RipToEOL();
        break;
    }
    case ';':               // comment
        RipToEOL();
        break;
    case 'P':               // ^P is start of next page, ^E is end of file
    case 'E':
        layoutdone = true;
        text--;             // back up to the '^'
        break;

    case 'C':               // ^c<hex digit> changes text color
        i = toupper(*++text);
        if(i == '[') // Textcolo translation
        {
            fontcolor = 255;
            const BYTE *colorname = (const BYTE *)(text);
            textcolor = V_ParseFontColor(colorname, CR_UNTRANSLATED, CR_UNTRANSLATED+1);
            while(*text++ != ']');
        }
        else
        {
            textcolor = CR_UNTRANSLATED;

            if (i>='0' && i<='9')
                fontcolor = i-'0';
            else if (i>='A' && i<='F')
                fontcolor = i-'A'+10;

            fontcolor *= 16;
            i = toupper(*++text);
            if (i>='0' && i<='9')
                fontcolor += i-'0';
            else if (i>='A' && i<='F')
                fontcolor += i-'A'+10;
            text++;
        }
        break;

    case '>':
        px = 160;
        text++;
        break;

    case 'L':
        py=ParseNumber();
        rowon = (py-TOPMARGIN)/FONTHEIGHT;
        py = TOPMARGIN+rowon*FONTHEIGHT;
        px=ParseNumber();
        while (*text++ != '\n')         // scan to end of line
            ;
        break;

    case 'T':               // ^Tyyy,xxx,ppp,ttt waits ttt tics, then draws pic
        TimedPicCommand (helphack);
        break;

    case 'G':               // ^Gyyy,xxx,ppp draws graphic
    {
        ParsePicCommand (helphack);

        if(!picnum.isValid())
            break;
        FTexture *picture = TexMan(picnum);
        VWB_DrawGraphic (picture, picx&~7,picy, MENU_CENTER);

        //
        // adjust margins
        //
        picmid = picx + picture->GetScaledWidth()/2;
        if (picmid > SCREENMID)
            margin = picx-PICMARGIN;                        // new right margin
        else
            margin = picx+picture->GetScaledWidth()+PICMARGIN;       // new left margin

        top = (picy-TOPMARGIN)/FONTHEIGHT;
        if (top<0)
            top = 0;
        bottom = (picy+picture->GetScaledHeight()-TOPMARGIN)/FONTHEIGHT;
        if (bottom>=TEXTROWS)
            bottom = TEXTROWS-1;

        for (i=top; i<=bottom; i++)
            if (picmid > SCREENMID)
                rightmargin[i] = margin;
            else
                leftmargin[i] = margin;

        //
        // adjust this line if needed
        //
        if (px < (int) leftmargin[rowon])
            px = leftmargin[rowon];
        break;
    }
    }
}
コード例 #6
0
ファイル: v_text.cpp プロジェクト: WChrisK/Zandronum
//
// DrawText
//
// Write a string using the given font
//
void STACK_ARGS DCanvas::DrawText (FFont *font, int normalcolor, int x, int y, const char *string, ...)
{
    va_list tags;
    DWORD tag;
    INTBOOL boolval;

    int			maxstrlen = INT_MAX;
    int 		w, maxwidth;
    const BYTE *ch;
    int 		c;
    int 		cx;
    int 		cy;
    int			boldcolor;
    const FRemapTable *range;
    int			height;
    int			forcedwidth = 0;
    // [BB] Since CleanX/Yfac are floats in Skulltag, scalex/y also need to be floats.
    float		scalex, scaley;
    int			kerning;
    FTexture *pic;

    if (font == NULL || string == NULL)
        return;

    if (normalcolor >= NumTextColors)
        normalcolor = CR_UNTRANSLATED;
    boldcolor = normalcolor ? normalcolor - 1 : NumTextColors - 1;

    range = font->GetColorTranslation ((EColorRange)normalcolor);
    height = font->GetHeight () + 1;
    kerning = font->GetDefaultKerning ();

    ch = (const BYTE *)string;
    cx = x;
    cy = y;

    // Parse the tag list to see if we need to adjust for scaling.
    maxwidth = Width;
    scalex = scaley = 1;

    va_start (tags, string);
    tag = va_arg (tags, DWORD);

    while (tag != TAG_DONE)
    {
        va_list *more_p;
        DWORD data;

        switch (tag)
        {
        case TAG_IGNORE:
        default:
            data = va_arg (tags, DWORD);
            break;

        case TAG_MORE:
            more_p = va_arg (tags, va_list*);
            va_end (tags);
#ifndef NO_VA_COPY
            va_copy (tags, *more_p);
#else
            tags = *more_p;
#endif
            break;

        // We don't handle these. :(
        case DTA_DestWidth:
        case DTA_DestHeight:
        case DTA_Translation:
            assert("Bad parameter for DrawText" && false);
            return;

        case DTA_CleanNoMove_1:
            boolval = va_arg (tags, INTBOOL);
            if (boolval)
            {
                scalex = CleanXfac_1;
                scaley = CleanYfac_1;
                maxwidth = Width - (Width % (int)scalex);
            }
            break;

        case DTA_CleanNoMove:
            boolval = va_arg (tags, INTBOOL);
            if (boolval)
            {
                scalex = CleanXfac;
                scaley = CleanYfac;
                maxwidth = Width - (Width % (int)scalex);
            }
            break;

        case DTA_Clean:
        case DTA_320x200:
            boolval = va_arg (tags, INTBOOL);
            if (boolval)
            {
                scalex = scaley = 1;
                maxwidth = 320;
            }
            break;

        case DTA_VirtualWidth:
            maxwidth = va_arg (tags, int);
            scalex = scaley = 1;
            break;

        case DTA_TextLen:
            maxstrlen = va_arg (tags, int);
            break;

        case DTA_CellX:
            forcedwidth = va_arg (tags, int);
            break;

        case DTA_CellY:
            height = va_arg (tags, int);
            break;

        // [BC] Is this text? If so, handle it slightly differently when we draw it.
        case DTA_IsText:

            va_arg( tags, int );
            break;
        }
        tag = va_arg (tags, DWORD);
    }

    height *= scaley;

    while ((const char *)ch - string < maxstrlen)
    {
        c = *ch++;
        if (!c)
            break;

        if (c == TEXTCOLOR_ESCAPE)
        {
            EColorRange newcolor = V_ParseFontColor (ch, normalcolor, boldcolor);
            if (newcolor != CR_UNDEFINED)
            {
                range = font->GetColorTranslation (newcolor);
            }
            continue;
        }

        if (c == '\n')
        {
            cx = x;
            cy += height;
            continue;
        }

        if (NULL != (pic = font->GetChar (c, &w)))
        {

            va_list taglist;
            va_start (taglist, string);
            // [BC] Flag this as being text.
            // [BB] Don't apply these text rules to the big font. This special handling of the big font formerly
            // was done in DCanvas::ParseDrawTextureTags.
            if (forcedwidth)
            {
                w = forcedwidth;
                DrawTexture (pic, cx, cy,
                             DTA_Translation, range,
                             DTA_DestWidth, forcedwidth,
                             DTA_DestHeight, height,
                             DTA_IsText, (font == BigFont) ? false : true,
                             TAG_MORE, &taglist);
            }
            else
            {
                DrawTexture (pic, cx, cy,
                             DTA_Translation, range,
                             DTA_IsText, (font == BigFont) ? false : true,
                             TAG_MORE, &taglist);
            }
            va_end (taglist);
        }
        cx += (w + kerning) * scalex;
    }
}
コード例 #7
0
ファイル: v_text.cpp プロジェクト: JohnnyonFlame/ecwolf
//
// DrawText
//
// Write a string using the given font
//
void DCanvas::DrawTextV(FFont *font, int normalcolor, int x, int y, const char *string, va_list taglist)
{
	INTBOOL boolval;
	va_list tags;
	uint32 tag;

	int			maxstrlen = INT_MAX;
	int 		w, maxwidth;
	const BYTE *ch;
	int 		c;
	int 		cx;
	int 		cy;
	int			boldcolor;
	const FRemapTable *range;
	int			height;
	int			forcedwidth = 0;
	int			scalex, scaley;
	int			kerning;
	FTexture *pic;

	if (font == NULL || string == NULL)
		return;

	if (normalcolor >= NumTextColors)
		normalcolor = CR_UNTRANSLATED;
	boldcolor = normalcolor ? normalcolor - 1 : NumTextColors - 1;

	range = font->GetColorTranslation ((EColorRange)normalcolor);
	height = font->GetHeight () + 1;
	kerning = font->GetDefaultKerning ();

	ch = (const BYTE *)string;
	cx = x;
	cy = y;

	// Parse the tag list to see if we need to adjust for scaling.
 	maxwidth = Width;
	scalex = scaley = 1;

#ifndef NO_VA_COPY
	va_copy(tags, taglist);
#else
	tags = taglist;
#endif
	tag = va_arg(tags, uint32);

	while (tag != TAG_DONE)
	{
		va_list *more_p;
		DWORD data;
		void *ptrval;

		switch (tag)
		{
		case TAG_IGNORE:
		default:
			data = va_arg (tags, DWORD);
			break;

		case TAG_MORE:
			more_p = va_arg (tags, va_list*);
			va_end (tags);
#ifndef NO_VA_COPY
			va_copy (tags, *more_p);
#else
			tags = *more_p;
#endif
			break;

		// We don't handle these. :(
		case DTA_DestWidth:
		case DTA_DestHeight:
			*(DWORD *)tags = TAG_IGNORE;
			data = va_arg (tags, DWORD);
			break;

		// Translation is specified explicitly by the text.
		case DTA_Translation:
			*(DWORD *)tags = TAG_IGNORE;
			ptrval = va_arg (tags, void*);
			break;

		case DTA_CleanNoMove_1:
			boolval = va_arg (tags, INTBOOL);
			if (boolval)
			{
				scalex = CleanXfac_1;
				scaley = CleanYfac_1;
				maxwidth = Width - (Width % scalex);
			}
			break;

		case DTA_CleanNoMove:
			boolval = va_arg (tags, INTBOOL);
			if (boolval)
			{
				scalex = CleanXfac;
				scaley = CleanYfac;
				maxwidth = Width - (Width % scalex);
			}
			break;

		case DTA_Clean:
		case DTA_320x200:
			boolval = va_arg (tags, INTBOOL);
			if (boolval)
			{
				scalex = scaley = 1;
				maxwidth = 320;
			}
			break;

		case DTA_VirtualWidth:
			maxwidth = va_arg (tags, int);
			scalex = scaley = 1;
			break;

		case DTA_TextLen:
			maxstrlen = va_arg (tags, int);
			break;

		case DTA_CellX:
			forcedwidth = va_arg (tags, int);
			break;

		case DTA_CellY:
			height = va_arg (tags, int);
			break;
		}
		tag = va_arg (tags, uint32);
	}
	va_end(tags);

	height *= scaley;
		
	while ((const char *)ch - string < maxstrlen)
	{
		c = *ch++;
		if (!c)
			break;

		if (c == TEXTCOLOR_ESCAPE)
		{
			EColorRange newcolor = V_ParseFontColor (ch, normalcolor, boldcolor);
			if (newcolor != CR_UNDEFINED)
			{
				range = font->GetColorTranslation (newcolor);
			}
			continue;
		}
		
		if (c == '\n')
		{
			cx = x;
			cy += height;
			continue;
		}

		if (NULL != (pic = font->GetChar (c, &w)))
		{
#ifndef NO_VA_COPY
			va_copy(tags, taglist);
#else
			tags = taglist;
#endif
			if (forcedwidth)
			{
				w = forcedwidth;
				DrawTexture (pic, cx, cy,
					DTA_Translation, range,
					DTA_DestWidth, forcedwidth,
					DTA_DestHeight, height,
					TAG_MORE, &tags);
			}
			else
			{
				DrawTexture (pic, cx, cy,
					DTA_Translation, range,
					TAG_MORE, &tags);
			}
			va_end (tags);
		}
		cx += (w + kerning) * scalex;
	}
	va_end(taglist);
}