Exemple #1
0
/*
=================
UI_DrawProportionalString
=================
*/
void UI_DrawProportionalString(int x, int y, const char* str, int style, vec4_t color)
{
	vec4_t	drawcolor;
	int		width;
	float	sizeScale;

	sizeScale = UI_ProportionalSizeScale(style);

	switch (style & UI_FORMATMASK)
	{
		case UI_CENTER:
			width = UI_ProportionalStringWidth(str) * sizeScale;
			x -= width / 2;
			break;

		case UI_RIGHT:
			width = UI_ProportionalStringWidth(str) * sizeScale;
			x -= width;
			break;

		case UI_LEFT:
		default:
			break;
	}

	if (style & UI_DROPSHADOW)
	{
		drawcolor[0] = drawcolor[1] = drawcolor[2] = 0;
		drawcolor[3] = color[3];
		UI_DrawProportionalString2(x+2, y+2, str, drawcolor, sizeScale, uis.charsetProp);
	}

	if (style & UI_INVERSE)
	{
		drawcolor[0] = color[0] * 0.7;
		drawcolor[1] = color[1] * 0.7;
		drawcolor[2] = color[2] * 0.7;
		drawcolor[3] = color[3];
		UI_DrawProportionalString2(x, y, str, drawcolor, sizeScale, uis.charsetProp);
		return;
	}

	if (style & UI_PULSE)
	{
		drawcolor[0] = color[0] * 0.7;
		drawcolor[1] = color[1] * 0.7;
		drawcolor[2] = color[2] * 0.7;
		drawcolor[3] = color[3];
		UI_DrawProportionalString2(x, y, str, color, sizeScale, uis.charsetProp);

		drawcolor[0] = color[0];
		drawcolor[1] = color[1];
		drawcolor[2] = color[2];
		drawcolor[3] = 0.5 + 0.5 * sin(uis.realtime / PULSE_DIVISOR);
		UI_DrawProportionalString2(x, y, str, drawcolor, sizeScale, uis.charsetPropGlow);
		return;
	}

	UI_DrawProportionalString2(x, y, str, color, sizeScale, uis.charsetProp);
}
Exemple #2
0
/*
=================
PText_Init
=================
*/
static void PText_Init( menutext_s *t )
{
	int	x;
	int	y;
	int	w;
	int	h;
	float	sizeScale;

	sizeScale = UI_ProportionalSizeScale( t->style );

	x = t->generic.x;
	y = t->generic.y;
	w = UI_ProportionalStringWidth( t->string ) * sizeScale;
	h =	PROP_HEIGHT * sizeScale;

	if( t->generic.flags & QMF_RIGHT_JUSTIFY ) {
		x -= w;
	}
	else if( t->generic.flags & QMF_CENTER_JUSTIFY ) {
		x -= w / 2;
	}

	t->generic.left   = x - PROP_GAP_WIDTH * sizeScale;
	t->generic.right  = x + w + PROP_GAP_WIDTH * sizeScale;
	t->generic.top    = y;
	t->generic.bottom = y + h;
}
Exemple #3
0
/*
=================
UI_DrawProportionalString_Wrapped
=================
*/
void UI_DrawProportionalString_AutoWrapped( int x, int y, int xmax, int ystep, const char* str, int style, vec4_t color ) {
	int width;
	char *s1,*s2,*s3;
	char c_bcp;
	char buf[1024];
	float   sizeScale;

	if (!str || str[0]=='\0')
		return;
	
	sizeScale = UI_ProportionalSizeScale( style );
	
	Q_strncpyz(buf, str, sizeof(buf));
	s1 = s2 = s3 = buf;

	while (1) {
		do {
			s3++;
		} while (*s3!=' ' && *s3!='\0');
		c_bcp = *s3;
		*s3 = '\0';
		width = UI_ProportionalStringWidth(s1) * sizeScale;
		*s3 = c_bcp;
		if (width > xmax) {
			if (s1==s2)
			{
				// f**k, don't have a clean cut, we'll overflow
				s2 = s3;
			}
			*s2 = '\0';
			UI_DrawProportionalString(x, y, s1, style, color);
			y += ystep;
			if (c_bcp == '\0')
      {
        // that was the last word
        // we could start a new loop, but that wouldn't be much use
        // even if the word is too long, we would overflow it (see above)
        // so just print it now if needed
        s2++;
        if (*s2 != '\0') // if we are printing an overflowing line we have s2 == s3
          UI_DrawProportionalString(x, y, s2, style, color);
				break; 
      }
			s2++;
			s1 = s2;
			s3 = s2;
		}
		else
		{
			s2 = s3;
			if (c_bcp == '\0') // we reached the end
			{
				UI_DrawProportionalString(x, y, s1, style, color);
				break;
			}
		}
	}
}
/*
=================
StartServer_ItemPage_Old_Register

Always work in units of LINE_HEIGHT so left and right
columns are always aligned
=================
*/
static int StartServer_ItemPage_Old_RegisterGroup(groupposition_t* gp, int y)
{
	int id;
	int x;
	int dy;
	int index, ident;
	groupinfo_t* g;
	itemnode_t* node;

	g = gp->group;
	if (!g)
		return 0;

	x = 160 * gp->position;
	if (gp->title) {
		gp->x = x + 8;
		gp->y = y - PROP_HEIGHT * UI_ProportionalSizeScale( UI_SMALLFONT );
	}

	dy = 0;
	index = 0;
	while (index < g->size)
	{
		ident = g->itemlist[index].ident;
		node = &server_itemlist[ ident ];
		if (node->groupid != g->ident)
		{
			Com_Printf("Item in wrong group: %s expected %i, got %i\n",
				node->mapitem, g->ident, node->groupid);
		}

		id = s_itemcontrols_old.numitems;
		s_itemcontrols_old.itemCtrl[id].control.generic.type	= MTYPE_RADIOBUTTON;
		s_itemcontrols_old.itemCtrl[id].control.generic.flags	= QMF_PULSEIFFOCUS|QMF_SMALLFONT;
		s_itemcontrols_old.itemCtrl[id].control.generic.name 	= g->itemlist[index].name;
		s_itemcontrols_old.itemCtrl[id].control.generic.callback	= StartServer_ItemPage_Old_ItemEvent;
		s_itemcontrols_old.itemCtrl[id].control.generic.ownerdraw = StartServer_ItemPage_Old_DrawItemButton;
		s_itemcontrols_old.itemCtrl[id].control.generic.id		= id;	// self index
		s_itemcontrols_old.itemCtrl[id].control.generic.x		= x + 13*SMALLCHAR_WIDTH;
		s_itemcontrols_old.itemCtrl[id].control.generic.y		= y + dy;

		s_itemcontrols_old.itemCtrl[id].item = &g->itemlist[index];
		s_itemcontrols_old.itemCtrl[id].bg_index = StartServer_Old_GetItemFromMapObject(server_itemlist[ident].mapitem);

		g->itemlist[index].control = &s_itemcontrols_old.itemCtrl[id].control;

		s_itemcontrols_old.numitems++;
		index++;
		dy += LINE_HEIGHT;
	}

	dy += 3*LINE_HEIGHT;

	return dy;
}
Exemple #5
0
/*
=================
CG_DrawMotd
=================
*/
void CG_DrawMotd() {
	const char *s;

	s = CG_ConfigString( CS_MOTD );
	if ( s[0] ) {
		vec4_t color = { 0.5f, 0.5f, 0.5f, 0.3f };
		int len = (int)( (float)UI_ProportionalStringWidth( s ) * UI_ProportionalSizeScale( UI_EXSMALLFONT ) / 2 );
		CG_FillRect( 0, 448, 640, 14, color );
		CG_DrawStringExt( 320 - len, 445, s, colorWhite, qfalse, qtrue, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0 );
	}
}
/*
=================
PlayerSettings_DrawHandicap
=================
*/
static void PlayerSettings_DrawHandicap( void *self ) {
    menulist_s		*item;
    qboolean		focus;
    int				style;
    float			*color;

    item = (menulist_s *)self;
    focus = (item->generic.parent->cursor == item->generic.menuPosition);

    style = UI_LEFT|UI_SMALLFONT;
    color = text_color_normal;
    if( focus ) {
        style |= UI_PULSE;
        color = text_color_highlight;
    }

    UI_DrawProportionalString( item->generic.x, item->generic.y, "Handicap", style, UI_ProportionalSizeScale( style ), color );
    UI_DrawProportionalString( item->generic.x + 64, item->generic.y + PROP_HEIGHT, handicap_items[item->curvalue], style,UI_ProportionalSizeScale( style ), color );
}
/*
=================
PlayerSettings_DrawEffects
=================
*/
static void PlayerSettings_DrawEffects( void *self ) {
    menulist_s		*item;
    qboolean		focus;
    int				style;
    float			*color;

    item = (menulist_s *)self;
    focus = (item->generic.parent->cursor == item->generic.menuPosition);

    style = UI_LEFT|UI_SMALLFONT;
    color = text_color_normal;
    if( focus ) {
        style |= UI_PULSE;
        color = text_color_highlight;
    }

    UI_DrawProportionalString( item->generic.x, item->generic.y, "Effects", style, UI_ProportionalSizeScale( style ), color );

    UI_DrawHandlePic( item->generic.x + 64, item->generic.y + PROP_HEIGHT + 8, 128, 8, s_playersettings.fxBasePic );
    UI_DrawHandlePic( item->generic.x + 64 + item->curvalue * 16 + 8, item->generic.y + PROP_HEIGHT + 6, 16, 12, s_playersettings.fxPic[item->curvalue] );
}
Exemple #8
0
static void UI_DisplayDownloadInfo( const char *downloadName ) {
	static char dlText[]	= "Downloading:";
	static char etaText[]	= "Estimated time left:";
	static char xferText[]	= "Transfer rate:";

	int downloadSize, downloadCount, downloadTime;
	char dlSizeBuf[64], totalSizeBuf[64], xferRateBuf[64], dlTimeBuf[64];
	int xferRate;
	int width, leftWidth;
	int style = UI_LEFT|UI_SMALLFONT|UI_DROPSHADOW;
	const char *s;

	downloadSize = trap_Cvar_VariableValue( "cl_downloadSize" );
	downloadCount = trap_Cvar_VariableValue( "cl_downloadCount" );
	downloadTime = trap_Cvar_VariableValue( "cl_downloadTime" );

#if 0 // bk010104
	fprintf( stderr, "\n\n-----------------------------------------------\n");
	fprintf( stderr, "DB: downloadSize:  %16d\n", downloadSize );
	fprintf( stderr, "DB: downloadCount: %16d\n", downloadCount );
	fprintf( stderr, "DB: downloadTime:  %16d\n", downloadTime );  
  	fprintf( stderr, "DB: UI realtime:   %16d\n", uis.realtime );	// bk
	fprintf( stderr, "DB: UI frametime:  %16d\n", uis.frametime );	// bk
#endif

	leftWidth = width = UI_ProportionalStringWidth( dlText ) * UI_ProportionalSizeScale( style );
	width = UI_ProportionalStringWidth( etaText ) * UI_ProportionalSizeScale( style );
	if (width > leftWidth) leftWidth = width;
	width = UI_ProportionalStringWidth( xferText ) * UI_ProportionalSizeScale( style );
	if (width > leftWidth) leftWidth = width;
	leftWidth += 16;

	UI_DrawProportionalString( 8, 128, dlText, style, UI_ProportionalSizeScale( style ), color_white );
	UI_DrawProportionalString( 8, 160, etaText, style, UI_ProportionalSizeScale( style ), color_white );
	UI_DrawProportionalString( 8, 224, xferText, style, UI_ProportionalSizeScale( style ), color_white );

	if (downloadSize > 0) {
		s = va( "%s (%d%%)", downloadName, downloadCount * 100 / downloadSize );
	} else {
		s = downloadName;
	}

	UI_DrawProportionalString( leftWidth, 128, s, style, UI_ProportionalSizeScale( style ), color_white );

	UI_ReadableSize( dlSizeBuf,		sizeof dlSizeBuf,		downloadCount );
	UI_ReadableSize( totalSizeBuf,	sizeof totalSizeBuf,	downloadSize );

	if (downloadCount < 4096 || !downloadTime) {
		UI_DrawProportionalString( leftWidth, 160, "estimating", style, UI_ProportionalSizeScale( style ), color_white );
		UI_DrawProportionalString( leftWidth, 192, 
			va("(%s of %s copied)", dlSizeBuf, totalSizeBuf), style, UI_ProportionalSizeScale( style ), color_white );
	} else {
	  // bk010108
	  //float elapsedTime = (float)(uis.realtime - downloadTime); // current - start (msecs)
	  //elapsedTime = elapsedTime * 0.001f; // in seconds
	  //if ( elapsedTime <= 0.0f ) elapsedTime == 0.0f;
	  if ( (uis.realtime - downloadTime) / 1000) {
			xferRate = downloadCount / ((uis.realtime - downloadTime) / 1000);
		  //xferRate = (int)( ((float)downloadCount) / elapsedTime);
		} else {
			xferRate = 0;
		}

	  //fprintf( stderr, "DB: elapsedTime:  %16.8f\n", elapsedTime );	// bk
	  //fprintf( stderr, "DB: xferRate:   %16d\n", xferRate );	// bk

		UI_ReadableSize( xferRateBuf, sizeof xferRateBuf, xferRate );

		// Extrapolate estimated completion time
		if (downloadSize && xferRate) {
			int n = downloadSize / xferRate; // estimated time for entire d/l in secs

			// We do it in K (/1024) because we'd overflow around 4MB
			n = (n - (((downloadCount/1024) * n) / (downloadSize/1024))) * 1000;
			
			UI_PrintTime ( dlTimeBuf, sizeof dlTimeBuf, n ); // bk010104
				//(n - (((downloadCount/1024) * n) / (downloadSize/1024))) * 1000);

			UI_DrawProportionalString( leftWidth, 160, 
				dlTimeBuf, style, UI_ProportionalSizeScale( style ), color_white );
			UI_DrawProportionalString( leftWidth, 192, 
				va("(%s of %s copied)", dlSizeBuf, totalSizeBuf), style, UI_ProportionalSizeScale( style ), color_white );
		} else {
			UI_DrawProportionalString( leftWidth, 160, 
				"estimating", style, UI_ProportionalSizeScale( style ), color_white );
			if (downloadSize) {
				UI_DrawProportionalString( leftWidth, 192, 
					va("(%s of %s copied)", dlSizeBuf, totalSizeBuf), style, UI_ProportionalSizeScale( style ), color_white );
			} else {
				UI_DrawProportionalString( leftWidth, 192, 
					va("(%s copied)", dlSizeBuf), style, UI_ProportionalSizeScale( style ), color_white );
			}
		}

		if (xferRate) {
			UI_DrawProportionalString( leftWidth, 224, 
				va("%s/Sec", xferRateBuf), style, UI_ProportionalSizeScale( style ), color_white );
		}
	}
}
/*
=================
PlayerSettings_DrawName
=================
*/
static void PlayerSettings_DrawName( void *self ) {
    menufield_s		*f;
    qboolean		focus;
    int				style;
    char			*txt;
    char			c;
    float			*color;
    int				n;
    int				basex, x, y;
    char			name[32];

    f = (menufield_s*)self;
    basex = f->generic.x;
    y = f->generic.y;
    focus = (f->generic.parent->cursor == f->generic.menuPosition);

    style = UI_LEFT|UI_SMALLFONT;
    color = text_color_normal;
    if( focus ) {
        style |= UI_PULSE;
        color = text_color_highlight;
    }

    UI_DrawProportionalString( basex, y, "Name", style, UI_ProportionalSizeScale( style ),  color );

    // draw the actual name
    basex += 64;
    y += PROP_HEIGHT;
    txt = f->field.buffer;
    color = g_color_table[ColorIndex(COLOR_WHITE)];
    x = basex;
    while ( (c = *txt) != 0 ) {
        if ( !focus && Q_IsColorString( txt ) ) {
            n = ColorIndex( *(txt+1) );
            if( n == 0 ) {
                n = 7;
            }
            color = g_color_table[n];
            txt += 2;
            continue;
        }
        UI_DrawChar( x, y, c, style, color );
        txt++;
        x += SMALLCHAR_WIDTH;
    }

    // draw cursor if we have focus
    if( focus ) {
        if ( trap_Key_GetOverstrikeMode() ) {
            c = 11;
        } else {
            c = 10;
        }

        style &= ~UI_PULSE;
        style |= UI_BLINK;

        UI_DrawChar( basex + f->field.cursor * SMALLCHAR_WIDTH, y, c, style, color_white );
    }

    // draw at bottom also using proportional font
    Q_strncpyz( name, f->field.buffer, sizeof(name) );
    Q_CleanStr( name );
    UI_DrawProportionalString( 320, 440, name, UI_CENTER|UI_BIGFONT, 1.0, text_color_normal );
}