Beispiel #1
0
void hgeFont::Render(float x, float y, int align, const char *string)
{
	int i;
	float	fx=x;

	align &= HGETEXT_HORZMASK;
	if(align==HGETEXT_RIGHT) fx-=GetStringWidth(string, false);
	if(align==HGETEXT_CENTER) fx-=int(GetStringWidth(string, false)/2.0f);

	while(*string)
	{
		if(*string=='\n')
		{
			y += int(fHeight*fScale*fSpacing);
			fx = x;
			if(align == HGETEXT_RIGHT)  fx -= GetStringWidth(string+1, false);
			if(align == HGETEXT_CENTER) fx -= int(GetStringWidth(string+1, false)/2.0f);
		}
		else
		{
			i=(unsigned char)*string;
			if(!letters[i]) i='?';
			if(letters[i])
			{
				fx += pre[i]*fScale*fProportion;
				letters[i]->RenderEx(fx, y, fRot, fScale*fProportion, fScale);
				fx += (letters[i]->GetWidth()+post[i]+fTracking)*fScale*fProportion;
			}
		}
		string++;
	}
}
Beispiel #2
0
/** Compute the size of a dialog window. */
void ComputeDimensions(const ClientNode *np)
{

    const ScreenType *sp;
    int width;
    int x;

    Assert(dialog);

    /* Get the min width from the size of the buttons. */
    if(!minWidth) {
        minWidth = GetStringWidth(FONT_MENU, GetCancelString()) * 3;
        width = GetStringWidth(FONT_MENU, GetOKString()) * 3;
        if(width > minWidth) {
            minWidth = width;
        }
        minWidth += 16 * 3;
    }
    dialog->width = minWidth;

    /* Take into account the size of the message. */
    for(x = 0; x < dialog->lineCount; x++) {
        width = GetStringWidth(FONT_MENU, dialog->message[x]);
        if(width > dialog->width) {
            dialog->width = width;
        }
    }
    dialog->lineHeight = GetStringHeight(FONT_MENU);
    dialog->width += 8;
    dialog->height = (dialog->lineCount + 2) * dialog->lineHeight;

    if(np) {

        dialog->x = np->x + (np->width - dialog->width) / 2;
        dialog->y = np->y + (np->height - dialog->height) / 2;

        if(dialog->x < 0) {
            dialog->x = 0;
        }
        if(dialog->y < 0) {
            dialog->y = 0;
        }
        if(dialog->x + dialog->width >= rootWidth) {
            dialog->x = rootWidth - dialog->width - (settings.borderWidth * 2);
        }
        if(dialog->y + dialog->height >= rootHeight) {
            dialog->y = rootHeight - dialog->height
                        - (settings.borderWidth * 2 + settings.titleHeight);
        }

    } else {

        sp = GetMouseScreen();

        dialog->x = (sp->width - dialog->width) / 2 + sp->x;
        dialog->y = (sp->height - dialog->height) / 2 + sp->y;

    }

}
Beispiel #3
0
void confirmComplete(double x1, double y1, double x2, double y2)//确认完成按钮函数
{
    MovePen(x1,y1);
    DrawLine(x2-x1,0);
    DrawLine(0,y2-y1);
    DrawLine(x1-x2,0);
    DrawLine(0,y1-y2);
    double distance1;
    double distance2;
    double X,Y;
    SetPenColor(RED);
    distance1=(x2-x1-GetStringWidth("输入完成"))/2;
    distance2=(y1-y2-GetStringWidth("输"))/2;
    MovePen(x1+distance1,y1-distance2);
    DrawString("输入完成");
    SetPenColor(BLACK);
    while(1)
    {
        while(!(WaitForEvent()==KEYDOWN)){}
        if(GetStruckKey() == VK_LBUTTON)
        {
            X = GetMouseX();
            Y = GetMouseY();
            if((X >= x1 && X <= x2) && (Y >= y2 && Y <= y1))//鼠标点击在所规定的范围内
            {
                EatEgg();//吃掉完成键和信息输入框的蛋
                break;
            }
        }
    }

}
Beispiel #4
0
/** Compute the size of a dialog window. */
void ComputeDimensions(DialogType *dp) {

   const ScreenType *sp;
   int width;
   int x;

   Assert(dp);

   /* Get the min width from the size of the buttons. */
   if(!minWidth) {
      minWidth = GetStringWidth(FONT_MENU, CANCEL_STRING) * 3;
      width = GetStringWidth(FONT_MENU, OK_STRING) * 3;
      if(width > minWidth) {
         minWidth = width;
      }
      minWidth += 16 * 3;
   }
   dp->width = minWidth;

   /* Take into account the size of the message. */
   for(x = 0; x < dp->lineCount; x++) {
      width = GetStringWidth(FONT_MENU, dp->message[x]);
      if(width > dp->width) {
         dp->width = width;
      }
   }
   dp->lineHeight = GetStringHeight(FONT_MENU);
   dp->width += 8;
   dp->height = (dp->lineCount + 2) * dp->lineHeight;

   if(dp->client) {

      dp->x = dp->client->x + (dp->client->width - dp->width) / 2;
      dp->y = dp->client->y + (dp->client->height - dp->height) / 2;

      if(dp->x < 0) {
         dp->x = 0;
      }
      if(dp->y < 0) {
         dp->y = 0;
      }
      if(dp->x + dp->width >= rootWidth) {
         dp->x = rootWidth - dp->width - (borderWidth * 2);
      }
      if(dp->y + dp->height >= rootHeight) {
         dp->y = rootHeight - dp->height - (borderWidth * 2 + titleHeight);
      }

   } else {

      sp = GetMouseScreen();

      dp->x = (sp->width - dp->width) / 2 + sp->x;
      dp->y = (sp->height - dp->height) / 2 + sp->y;

   }

}
Beispiel #5
0
void UIFont::DrawString(float x,
						float y,
						int32 align,
						const tchar *string,
						uint32 color,
						float rot,
						float fHScale,
						float fVScale)
{
	if(NULL == string)
	{
		return;
	}

	int32 i;
	float fx = x;

	align &= GTEXT_HORZMASK;
	if(align == GTEXT_RIGHT) fx -= GetStringWidth(string, fHScale, false);
	if(align == GTEXT_CENTER) fx -= int(GetStringWidth(string, fHScale, false)/2.0f);

	while(*string)
	{
		if(*string=='\n')
		{
			y += int32(fHeight*fVScale*fSpacing);
			fx = x;
			if(align == GTEXT_RIGHT)  fx -= GetStringWidth(string+1, fHScale, false);
			if(align == GTEXT_CENTER) fx -= int(GetStringWidth(string+1, fHScale, false)/2.0f);
		}
		else
		{
			i=(unsigned char)*string;

			fx += pre[i]*fHScale*fProportion;
			//letters[i]->RenderEx(fx, y, fRot, fScale*fProportion, fScale);
			m_pTexture->RenderRect(
				fx,
				y,
				(float)letters[i].x,
				(float)letters[i].y,
				(float)letters[i].w,
				(float)letters[i].h,
				color,
				rot,
				fHScale,
				fVScale
				);
			fx += (letters[i].w+post[i]+fTracking)*fHScale*fProportion;
		}
		string++;
	}
}
Beispiel #6
0
void CalcDisplay::Paint(const Rect &update)
{
	Rect cBounds = GetBounds();

	DrawFrame(cBounds, FRAME_RECESSED);

	SetFgColor(0,0,0,0);
	SetBgColor(get_default_color(COL_NORMAL));

	char *text = m_Contents;
	if(!text) text = "0";

	font_height fh;
	GetFontHeight(&fh);
	float fontheight = fh.ascender + fh.descender;
	float baseline = cBounds.top + (cBounds.Height() + 1)/2 - fontheight/2 + fh.ascender;
	float tw = GetStringWidth(text);

	MovePenTo(cBounds.right - 3.0f - tw, baseline);
	DrawString(text);

	float flagpos = cBounds.left + 5.0f;

	if(m_Mem) {
		MovePenTo(flagpos, baseline);
		DrawString("M");
		flagpos += GetStringWidth("M ");
	}

	if(m_Inv) {
		MovePenTo(flagpos, baseline);
		DrawString("INV");
		flagpos += GetStringWidth("INV ");
	}

	if(m_Hyp) {
		MovePenTo(flagpos, baseline);
		DrawString("HYP");
		flagpos += GetStringWidth("HYP ");
	}

	if(m_Par != 0) {
		char bfr[10];
		sprintf(bfr, "(%d ", m_Par);
		MovePenTo(flagpos, baseline);
		DrawString(bfr);
		flagpos += GetStringWidth(bfr);
	}
}
Beispiel #7
0
/** Draw the buttons on the dialog window. */
void DrawButtons(void)
{

    ButtonNode button;
    int temp;

    Assert(dialog);

    dialog->buttonWidth = GetStringWidth(FONT_MENU, GetCancelString());
    temp = GetStringWidth(FONT_MENU, GetOKString());
    if(temp > dialog->buttonWidth) {
        dialog->buttonWidth = temp;
    }
    dialog->buttonWidth += 16;
    dialog->buttonHeight = dialog->lineHeight + 4;

    ResetButton(&button, dialog->pmap);
    button.border = 1;
    button.font = FONT_MENU;
    button.width = dialog->buttonWidth;
    button.height = dialog->buttonHeight;
    button.alignment = ALIGN_CENTER;

    dialog->okx = dialog->width / 3 - dialog->buttonWidth / 2;
    dialog->cancelx = 2 * dialog->width / 3 - dialog->buttonWidth / 2;
    dialog->buttony = dialog->height - dialog->lineHeight
                      - dialog->lineHeight / 2;

    if(dialog->buttonState == DBS_OK) {
        button.type = BUTTON_MENU_ACTIVE;
    } else {
        button.type = BUTTON_MENU;
    }
    button.text = GetOKString();
    button.x = dialog->okx;
    button.y = dialog->buttony;
    DrawButton(&button);

    if(dialog->buttonState == DBS_CANCEL) {
        button.type = BUTTON_MENU_ACTIVE;
    } else {
        button.type = BUTTON_MENU;
    }
    button.text = GetCancelString();
    button.x = dialog->cancelx;
    button.y = dialog->buttony;
    DrawButton(&button);

}
Beispiel #8
0
/** Startup tray buttons. */
void StartupTrayButtons() {

   TrayButtonType *bp;

   for(bp = buttons; bp; bp = bp->next) {
      if(bp->label) {
         bp->cp->requestedWidth
            = GetStringWidth(FONT_TRAYBUTTON, bp->label) + 4;
         bp->cp->requestedHeight
            = GetStringHeight(FONT_TRAYBUTTON);
      } else {
         bp->cp->requestedWidth = 0;
         bp->cp->requestedHeight = 0;
      }
      if(bp->iconName) {
         bp->icon = LoadNamedIcon(bp->iconName);
         if(JLIKELY(bp->icon)) {
            bp->cp->requestedWidth += bp->icon->image->width;
            bp->cp->requestedHeight += bp->icon->image->height;
         } else {
            Warning(_("could not load tray icon: \"%s\""), bp->iconName);
         }
      }
      bp->cp->requestedWidth += 2 * BUTTON_SIZE;
      bp->cp->requestedHeight += 2 * BUTTON_SIZE;
   }

}
Beispiel #9
0
MsgView::MsgView(const string& text, va_list list)
        : os::View(os::Rect(0,0,1,1), "MsgView", os::CF_FOLLOW_ALL)
{
    const char* butName;

    uint i=0;
    while((butName = va_arg(list, const char*)) != NULL)
    {
        os::Button* button = new os::Button(os::Rect(0,0,1,1), butName, butName, new os::Message(i++));
        buttons.push_back(button);
        AddChild(button);

        os::Point size = button->GetPreferredSize(false);
        if(size.x > buttonSize.x)
        {
            buttonSize.x = size.x;
        }
        if(size.y > buttonSize.y)
        {
            buttonSize.y = size.y;
        }
    }

    float width = (buttonSize.x + 5) * buttons.size();

    int start = 0;
    for(i=0;i<=text.size();++i)
    {
        if(i==text.size() || text[i]=='\n')
        {
            std::string line(text, start, i-start);
            lines.push_back(line);

            float strLen = GetStringWidth(line.c_str())+20;
            if(strLen>width)
            {
                width=strLen;
            }
            start = i + 1;
        }
    }

    os::font_height fontHeight;
    GetFontHeight(&fontHeight);
    lineHeight = fontHeight.ascender + fontHeight.descender + fontHeight.line_gap;

    float height=lines.size()*lineHeight;
    height+=buttonSize.y + 30;

    float y=height - buttonSize.y - 5;
    float x=width - buttons.size() * (buttonSize.x + 5) - 5;

    for(i=0;i<buttons.size();++i)
    {
        buttons[i]->SetFrame(os::Rect(x, y, x+buttonSize.x-1, y+buttonSize.y-1));
        x+=buttonSize.x+5;
    }
    minSize.x=width;
    minSize.y=height;
}
Beispiel #10
0
void CRender::DrawString(bool CenterText, float x, float y, COLOR32 Color, PCoreString szText, ...)
{
	char szBuffer[1024];
	GET_VA_ARGS(szText, szBuffer);

	if (CenterText)
		x -= GetStringWidth(szBuffer) / 2;

	RECT Rect = { (int)x, (int)y, 0, 0 };
	RECT ShadowRect = { (int)x + 1, (int)y, 0, 0 };
	RECT ShadowRect2 = { (int)x + 1, (int)y + 1, 0, 0 };
	RECT ShadowRect3 = { (int)x, (int)y + 1, 0, 0 };
	RECT ShadowRect4 = { (int)x - 1, (int)y + 1, 0, 0 };
	RECT ShadowRect5 = { (int)x - 1, (int)y, 0, 0 };
	RECT ShadowRect6 = { (int)x - 1, (int)y - 1, 0, 0 };
	RECT ShadowRect7 = { (int)x, (int)y - 1, 0, 0 };
	RECT ShadowRect8 = { (int)x + 1, (int)y - 1, 0, 0 };
	pD3DFont->DrawText(NULL, szBuffer, -1, &ShadowRect, DT_LEFT | DT_NOCLIP, D3DCOLOR_RGBA(0, 0, 0, Color.a - 25));
	pD3DFont->DrawText(NULL, szBuffer, -1, &ShadowRect2, DT_LEFT | DT_NOCLIP, D3DCOLOR_RGBA(0, 0, 0, Color.a - 25));
	pD3DFont->DrawText(NULL, szBuffer, -1, &ShadowRect3, DT_LEFT | DT_NOCLIP, D3DCOLOR_RGBA(0, 0, 0, Color.a - 25));
	pD3DFont->DrawText(NULL, szBuffer, -1, &ShadowRect4, DT_LEFT | DT_NOCLIP, D3DCOLOR_RGBA(0, 0, 0, Color.a - 25));
	pD3DFont->DrawText(NULL, szBuffer, -1, &ShadowRect5, DT_LEFT | DT_NOCLIP, D3DCOLOR_RGBA(0, 0, 0, Color.a - 25));
	pD3DFont->DrawText(NULL, szBuffer, -1, &ShadowRect6, DT_LEFT | DT_NOCLIP, D3DCOLOR_RGBA(0, 0, 0, Color.a - 25));
	pD3DFont->DrawText(NULL, szBuffer, -1, &ShadowRect7, DT_LEFT | DT_NOCLIP, D3DCOLOR_RGBA(0, 0, 0, Color.a - 25));
	pD3DFont->DrawText(NULL, szBuffer, -1, &ShadowRect8, DT_LEFT | DT_NOCLIP, D3DCOLOR_RGBA(0, 0, 0, Color.a - 25));
	pD3DFont->DrawText(NULL, szBuffer, -1, &Rect, DT_LEFT | DT_NOCLIP, D3DCOLOR_RGBA(Color.r, Color.g, Color.g, Color.a));
}
Beispiel #11
0
void JLBFont::DrawString(const char *string, float x, float y, int align)
{
	char *p = (char*)string;
	float dx = x, dy = y;

	if (mQuad == NULL) return;
	
	float width = GetStringWidth(string);
			  
	if (align == JGETEXT_RIGHT)
		dx -= width;
	else if (align == JGETEXT_CENTER)
		dx -= width/2;

	int index;
	while (*p)
	{
		index = (*p - 32)+mBase;
		mQuad->SetTextureRect(mXPos[index], mYPos[index], mCharWidth[index], mHeight);
		mRenderer->RenderQuad(mQuad, dx, dy, mRotation, mScale, mScale);
		dx += (mCharWidth[index] + mTracking) * mScale;
		p++;

   }
  
}
Beispiel #12
0
/** Startup tray buttons. */
void StartupTrayButtons(void)
{
   TrayButtonType *bp;
   for(bp = buttons; bp; bp = bp->next) {
      if(bp->label) {
         bp->cp->requestedWidth
            = GetStringWidth(FONT_TRAY, bp->label) + 4;
         bp->cp->requestedHeight = GetStringHeight(FONT_TRAY);
      } else {
         bp->cp->requestedWidth = 0;
         bp->cp->requestedHeight = 0;
      }
      if(bp->iconName) {
         bp->icon = LoadNamedIcon(bp->iconName, 1, 1);
         if(JLIKELY(bp->icon)) {
            bp->cp->requestedWidth += bp->icon->images->width + 4;
            if(bp->label) {
               bp->cp->requestedWidth -= 2;
            }
            bp->cp->requestedHeight
               = Max(bp->icon->images->height + 4, bp->cp->requestedHeight);
         } else {
            Warning(_("could not load tray icon: \"%s\""), bp->iconName);
         }
      }
   }
}
Beispiel #13
0
/** Draw the buttons on the dialog window. */
void DrawButtons(DialogType *dp) {

   ButtonNode button;
   int temp;

   Assert(dp);

   dp->buttonWidth = GetStringWidth(FONT_MENU, CANCEL_STRING);
   temp = GetStringWidth(FONT_MENU, OK_STRING);
   if(temp > dp->buttonWidth) {
      dp->buttonWidth = temp;
   }
   dp->buttonWidth += 16;
   dp->buttonHeight = dp->lineHeight + 4;

   ResetButton(&button, dp->node->window, rootGC);
   button.font = FONT_MENU;
   button.width = dp->buttonWidth;
   button.height = dp->buttonHeight;
   button.alignment = ALIGN_CENTER;

   dp->okx = dp->width / 3 - dp->buttonWidth / 2;
   dp->cancelx = 2 * dp->width / 3 - dp->buttonWidth / 2;
   dp->buttony = dp->height - dp->lineHeight - dp->lineHeight / 2;

   if(dp->buttonState == DBS_OK) {
      button.type = BUTTON_TASK_ACTIVE;
   } else {
      button.type = BUTTON_TASK;
   }
   button.text = OK_STRING;
   button.x = dp->okx;
   button.y = dp->buttony;
   DrawButton(&button);

   if(dp->buttonState == DBS_CANCEL) {
      button.type = BUTTON_TASK_ACTIVE;
   } else {
      button.type = BUTTON_TASK;
   }
   button.text = CANCEL_STRING;
   button.x = dp->cancelx;
   button.y = dp->buttony;
   DrawButton(&button);

}
Beispiel #14
0
	void Paint(const Rect &cUpdateRect)
	{
		SetDrawingMode(DM_COPY);
		m_pcImage->Draw( Point( 0, 0 ), this  );

		SetDrawingMode(DM_OVER);
		
		font_height fh;
		GetFontHeight(&fh);
		
		MovePenTo(GetBounds().Width()/2 - GetStringWidth(MSG_ABOUTWND_TEXTONE)/2, 2 + fh.ascender);
		DrawString(MSG_ABOUTWND_TEXTONE);

		MovePenTo(GetBounds().Width()/2 - GetStringWidth(MSG_ABOUTWND_TEXTTWO)/2, GetBounds().Height() - 2 - fh.descender);
		DrawString(MSG_ABOUTWND_TEXTTWO);

	}
Beispiel #15
0
// ****************************************************************************
//
//  Function Name:	RFont::GetStringBounds( )
//
//  Description:		Return a rectangle that would bound the given string of characters
//
//  Returns:			Nothing
//
//  Exceptions:		Nothing
//
// ****************************************************************************
//
void RFont::GetStringBounds( const RMBCString& string, RIntRect* pBounds, BOOLEAN fKern ) const
	{
	RDataObjectLocker	locker( m_pWidthsTable );
	pBounds->m_Left	= 0;
	pBounds->m_Right	= GetStringWidth( string, fKern );
	pBounds->m_Top		= m_pWidthsTable->GetAscent( );
	pBounds->m_Bottom	= -(signed)m_pWidthsTable->GetDescent( );
	}
void CGitProgressList::ResizeColumns()
{
	SetRedraw(FALSE);

	TCHAR textbuf[MAX_PATH] = {0};

	CHeaderCtrl * pHeaderCtrl = (CHeaderCtrl*)(GetDlgItem(0));
	if (pHeaderCtrl)
	{
		int maxcol = pHeaderCtrl->GetItemCount()-1;
		for (int col = 0; col <= maxcol; ++col)
		{
			// find the longest width of all items
			int count = min((int)m_arData.size(), GetItemCount());
			HDITEM hdi = {0};
			hdi.mask = HDI_TEXT;
			hdi.pszText = textbuf;
			hdi.cchTextMax = _countof(textbuf);
			pHeaderCtrl->GetItem(col, &hdi);
			int cx = GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin

			for (int index = 0; index<count; ++index)
			{
				// get the width of the string and add 12 pixels for the column separator and margins
				int linewidth = cx;
				switch (col)
				{
				case 0:
					linewidth = GetStringWidth(m_arData[index]->sActionColumnText) + 12;
					break;
				case 1:
					linewidth = GetStringWidth(m_arData[index]->sPathColumnText) + 12;
					break;
				}
				if (cx < linewidth)
					cx = linewidth;
			}
			SetColumnWidth(col, cx);
		}
	}

	SetRedraw(TRUE);
}
Beispiel #17
0
int	GetStringWidth(char *szString, char* font, int size)
{
	int brect[8];
	char* err;
	gdFontPtr	pFont;

	if(strlen(font) != 0 && size > 0)
	{
		err = gdImageStringFT(NULL, brect, 0, font,size,0.,0,0,szString);
		if (err) 
		{
			/* if error occur, use native font */				
			return GetStringWidth(szString, "", size);			
		}
		return brect[2]-brect[0];	
	}
	else
	{		
		/* negative size */
		switch(size) {
			case UF_TINY:
				pFont = gdFontGetTiny();
				break;
			case UF_SMALL:
				pFont = gdFontGetSmall();
				break;
			case UF_MEDIUM:
				pFont = gdFontGetMediumBold();
				break;
			case UF_LARGE:
				pFont = gdFontGetLarge();
				break;
			case UF_GIANT:
				pFont = gdFontGetGiant();
				break;	
			default:
				pFont = gdFontGetMediumBold();
				break;
		}
		/* positive size */
		if(size > 0)
		{
			if(size > 9)
			{
				pFont = gdFontGetGiant();
			}
			else
			{
				pFont = gdFontGetSmall();
			}
		}
		return (int)strlen(szString) * pFont->w;
	}	
}
Beispiel #18
0
/*
 *******************************************************************
 * Function: DllEditorDlg* CreateToolbarDlg( HWND parentWindowHandle ) 
 *
 * Description : Adds a column to the listbox
 *		
 * Paramters : 
 *              LPCTSTR stringItem  r   string name of the column
 *              int columnIndex     r   column index
 *   
 * Returns : 
 *             BOOL - returns true if column added. false otherwise
 *   
 *******************************************************************
 */
BOOL CGBLListCtrl::AddColumn(LPCTSTR stringItem,int columnIndex)
{
	LV_COLUMN column;
	column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	column.fmt = LVCFMT_LEFT;
	column.pszText = (LPTSTR) stringItem;
	column.cx = GetStringWidth(column.pszText) + 15;
	column.iSubItem = columnIndex;

	return InsertColumn(columnIndex,&column);
}
Beispiel #19
0
void CText::DrawText(const std::string &text, FontType font,
                     float size, Math::Point pos, float width, TextAlign align,
                     int eol, Color color)
{
    float sw = 0.0f;

    if (align == TEXT_ALIGN_CENTER)
    {
        sw = GetStringWidth(text, font, size);
        if (sw > width) sw = width;
        pos.x -= sw / 2.0f;
    }
    else if (align == TEXT_ALIGN_RIGHT)
    {
        sw = GetStringWidth(text, font, size);
        if (sw > width) sw = width;
        pos.x -= sw;
    }

    DrawString(text, font, size, pos, width, eol, color);
}
Beispiel #20
0
float CFont::GetLineWidth(const ustring& text, size_t start /*= 0*/)
{
    size_t count = text.length()-start;
    for (int i = 0; i+start < text.size(); ++i)
    {
        if (text[i+start] == '\n')
        {
            count = i;
            break;
        }
    }
    return GetStringWidth(text.substr(start, count));
}
Beispiel #21
0
void CText::DrawText(const std::string &text, std::vector<FontMetaChar>::iterator format,
                     std::vector<FontMetaChar>::iterator end,
                     float size, Math::Point pos, float width, TextAlign align,
                     int eol, Color color)
{
    float sw = 0.0f;

    if (align == TEXT_ALIGN_CENTER)
    {
        sw = GetStringWidth(text, format, end, size);
        if (sw > width) sw = width;
        pos.x -= sw / 2.0f;
    }
    else if (align == TEXT_ALIGN_RIGHT)
    {
        sw = GetStringWidth(text, format, end, size);
        if (sw > width) sw = width;
        pos.x -= sw;
    }

    DrawString(text, format, end, size, pos, width, eol, color);
}
Beispiel #22
0
BOOL CListCtrlEx::AddColumn(LPCTSTR strItem,int nItem,int nSubItem,int nMask,int nFmt) {
	LV_COLUMN lvc;
	lvc.mask = nMask;
	lvc.fmt = nFmt;
	lvc.pszText = (LPTSTR) strItem;
	lvc.cx = GetStringWidth(lvc.pszText) + 15;
	if(nMask & LVCF_SUBITEM){
		if(nSubItem != -1)
			lvc.iSubItem = nSubItem;
		else
			lvc.iSubItem = nItem;
	}
	return InsertColumn(nItem,&lvc);
}
Beispiel #23
0
void hgeFont::Render(const float x, float y, int align, const char* string) {
    float fx = x;

    align &= HGETEXT_HORZMASK;
    if (align == HGETEXT_RIGHT) {
        fx -= GetStringWidth(string, false);
    }
    if (align == HGETEXT_CENTER) {
        fx -= int(GetStringWidth(string, false) / 2.0f);
    }

    while (*string) {
        if (*string == '\n') {
            y += int(height_ * scale_ * spacing_);
            fx = x;
            if (align == HGETEXT_RIGHT) {
                fx -= GetStringWidth(string + 1, false);
            }
            if (align == HGETEXT_CENTER) {
                fx -= int(GetStringWidth(string + 1, false) / 2.0f);
            }
        }
        else {
            int i = static_cast<unsigned char>(*string);
            if (!letters_[i]) {
                i = '?';
            }
            if (letters_[i]) {
                fx += pre_[i] * scale_ * proportion_;
                letters_[i]->RenderEx(fx, y, rot_, scale_ * proportion_, scale_);
                fx += (letters_[i]->GetWidth() + post_[i] + tracking_) * scale_ * proportion_;
            }
        }
        string++;
    }
}
Beispiel #24
0
/** Draw a clock tray component. */
void DrawClock(ClockType *clk, const TimeType *now)
{

   TrayComponentType *cp;
   const char *timeString;
   int width;
   int rwidth;

   /* Only draw if the time changed. */
   if(now->seconds == clk->lastTime.seconds) {
      return;
   }

   /* Clear the area. */
   cp = clk->cp;
   if(colors[COLOR_CLOCK_BG1] == colors[COLOR_CLOCK_BG2]) {
      JXSetForeground(display, rootGC, colors[COLOR_CLOCK_BG1]);
      JXFillRectangle(display, cp->pixmap, rootGC, 0, 0,
                      cp->width, cp->height);
   } else {
      DrawHorizontalGradient(cp->pixmap, rootGC,
                             colors[COLOR_CLOCK_BG1], colors[COLOR_CLOCK_BG2],
                             0, 0, cp->width, cp->height);
   }

   /* Determine if the clock is the right size. */
   timeString = GetTimeString(clk->format, clk->zone);
   width = GetStringWidth(FONT_CLOCK, timeString);
   rwidth = width + 4;
   if(rwidth == clk->cp->requestedWidth || clk->userWidth) {

      /* Draw the clock. */
      RenderString(cp->pixmap, FONT_CLOCK, COLOR_CLOCK_FG,
                   (cp->width - width) / 2,
                   (cp->height - GetStringHeight(FONT_CLOCK)) / 2,
                   cp->width, timeString);

      UpdateSpecificTray(clk->cp->tray, clk->cp);

   } else {

      /* Wrong size. Resize. */
      clk->cp->requestedWidth = rwidth;
      ResizeTray(clk->cp->tray);

   }

}
void
JFunctionWithVar::Render
	(
	const JExprRenderer& renderer,
	const JExprRectList& rectList
	)
	const
{
	// find ourselves in the list

	JIndex ourIndex;
	const JBoolean found = rectList.FindFunction(this, &ourIndex);
	assert( found );

	const JRect ourRect = rectList.GetRect(ourIndex);
	const JCoordinate ourMidline = rectList.GetMidline(ourIndex);
	const JSize fontSize = rectList.GetFontSize(ourIndex);

	// draw base name

	JString baseName, subscript;
	itsVariableList->GetVariableName(itsVariableIndex, &baseName, &subscript);
	DrawString(renderer, ourRect.left, ourMidline, fontSize, baseName);

	// draw subscript

	if (!subscript.IsEmpty())
		{
		const JCoordinate subLeft =
			ourRect.left + GetStringWidth(renderer, fontSize, baseName);
		const JSize subFontSize = renderer.GetSuperSubFontSize(fontSize);
		const JSize subHeight   = renderer.GetLineHeight(subFontSize);
		DrawString(renderer, subLeft, ourMidline + subHeight/2, subFontSize, subscript);
		}

	// draw our array index

	if (itsArrayIndex != NULL)
		{
		itsArrayIndex->Render(renderer, rectList);

		JIndex argIndex;
		const JBoolean found = rectList.FindFunction(itsArrayIndex, &argIndex);
		assert( found );
		renderer.DrawSquareBrackets(rectList.GetRect(argIndex));
		}
}
Beispiel #26
0
    void InGameContext::renderFunc()
    {
        try
        {
            float dt = _hge->Timer_GetDelta();

            auto bgSprite = _rm->getSprite(GfxType::BACKGROUND);
            auto puckSprite = _rm->getSprite(GfxType::PUCK);
            auto paddleSprite = _rm->getSprite(GfxType::PADDLE);

            bgSprite->Render(0, 0);
            puckSprite->Render(_puck->x, _puck->y);
            paddleSprite->Render(_players[0].paddle()->x, _players[0].paddle()->y);
            paddleSprite->Render(_players[1].paddle()->x, _players[1].paddle()->y);

            //render scores
            auto fnt = _rm->getFont(FontType::SCORE);

            std::stringstream scoresStr;
            scoresStr << "(" << _players[0].getName() << ")   "
                    << _players[0].getPoints()
                    << " ";

            float widthBeforeColon = fnt->GetStringWidth(scoresStr.str().c_str());

            scoresStr << ": " << _players[1].getPoints()
                    << "   (" + _players[1].getName() << ")";


            float x = _data->screenWidth / 2 - widthBeforeColon;
            float y = fnt->GetHeight() / 2;

            fnt->Render(x, y, HGETEXT_LEFT, scoresStr.str().c_str());

            timers.render(dt);
        }
        catch(std::exception &e)
        {
            std::cerr << e.what();
            std::cerr << "Check game.log for details" << std::endl;

            //Client::getInstance().stop();
            //TODO: change state or close the game. maybe?
        }
    }
Beispiel #27
0
/** Set the size of a button tray component. */
void SetSize(TrayComponentType *cp, int width, int height) {

   TrayButtonType *bp;
   int labelWidth, labelHeight;
   int iconWidth, iconHeight;
   int ratio;

   bp = (TrayButtonType*)cp->object;

   if(bp->icon) {

      if(bp->label) {
         labelWidth = GetStringWidth(FONT_TRAYBUTTON, bp->label) + 4;
         labelHeight = GetStringHeight(FONT_TRAYBUTTON);
      } else {
         labelWidth = 0;
         labelHeight = 0;
      }

      iconWidth = bp->icon->image->width;
      iconHeight = bp->icon->image->height;

      /* Fixed point with 16 bit fraction. */
      ratio = (iconWidth << 16) / iconHeight;

      if(width > 0) {

         /* Compute height from width. */
         iconWidth = width - labelWidth - 2 * BUTTON_SIZE;
         iconHeight = (iconWidth << 16) / ratio;
         height = Max(iconHeight, labelHeight) + 2 * BUTTON_SIZE;

      } else if(height > 0) {

         /* Compute width from height. */
         iconHeight = height - 2 * BUTTON_SIZE;
         iconWidth = (iconHeight * ratio) >> 16;
         width = iconWidth + labelWidth + 2 * BUTTON_SIZE;

      }

      cp->width = width;
      cp->height = height;

   }
Beispiel #28
0
void
vsBuiltInFont::WrapLine(const vsString &string, float size, float capSize, JustificationType j, float maxWidth)
{
	vsString remainingString = string;

	// okay, check where we need to wordwrap
	size_t lineEnd = 0;
	size_t seekPosition = 0;
	//bool done = false;

	s_wrappedLineCount = 0;

	while ( remainingString != vsEmptyString )
	{
		vsString line = remainingString;
		seekPosition = remainingString.find(' ',seekPosition+1);

		if ( seekPosition != vsString::npos )
		{
			line.erase(seekPosition);
		}

		// check if we want to do a line break here!
		if ( GetStringWidth(line, size, capSize) > maxWidth && lineEnd > 0)
		{
			// we've gone too far, and need to wrap!  Wrap to the last safe wrap point we found.
			line.erase(lineEnd);
			remainingString.erase(0,lineEnd+1);

			s_wrappedLine[s_wrappedLineCount++] = line;

			lineEnd = 0;
			seekPosition = 0;
		}
		else if ( seekPosition == vsString::npos )
		{
			s_wrappedLine[s_wrappedLineCount++] = remainingString;
			remainingString = vsEmptyString;
		}
		else
		{
			lineEnd = seekPosition;
		}
	}
}
Beispiel #29
0
/** Set the size of a button tray component. */
void SetSize(TrayComponentType *cp, int width, int height)
{

   TrayButtonType *bp;

   bp = (TrayButtonType*)cp->object;

   if(bp->icon) {

      int labelWidth, labelHeight;
      int iconWidth, iconHeight;
      int ratio;

      if(bp->label) {
         labelWidth = GetStringWidth(FONT_TRAY, bp->label) + 6;
         labelHeight = GetStringHeight(FONT_TRAY) + 6;
      } else {
         labelWidth = 4;
         labelHeight = 4;
      }

      iconWidth = bp->icon->images->width;
      iconHeight = bp->icon->images->height;

      /* Fixed point with 16 bit fraction. */
      ratio = (iconWidth << 16) / iconHeight;

      if(width > 0) {

         /* Compute height from width. */
         iconWidth = width - labelWidth;
         iconHeight = (iconWidth << 16) / ratio;
         height = Max(labelHeight, iconHeight + 4);

      } else if(height > 0) {

         /* Compute width from height. */
         iconHeight = height - 4;
         iconWidth = (iconHeight * ratio) >> 16;
         width = iconWidth + labelWidth;

      }
Beispiel #30
0
    void InGameContext::checkGoal()
    {
        auto data = std::dynamic_pointer_cast<InGameContextData>(_data);
        Player& currentPlayer = _players[data->currentPlayerId];

        int playerId = -1;
        int points = -1;
        if (Client::getInstance().getGoal(playerId, points))
        {
            handleGoal(playerId, points);
            Client::getInstance().sendPaddlePos(currentPlayer.paddle()->x, currentPlayer.paddle()->y);

            timers.createUntilTimer(
                TimerFactory::InvokeType::OnRender,
                1,
                true,
                [this](AbstractTimer *timer, float dt)
                {
                    auto goalFont = _rm->getFont(FontType::GOAL);

                    //TODO: GOAL string should appear on 'goaler' side
                    const char *goalStr = "GOAL";

                    float scale = timer->elapsed()*20;
                    goalFont->SetScale(scale);
                    int alpha = 255;
                    if(timer->elapsed() > 0.3)
                        alpha = 255 - timer->elapsed() * 255;

                    goalFont->SetColor(ARGB(alpha, 10, 200, 35));
                    goalFont->SetSpacing(dt*20);

                    auto strWidth = goalFont->GetStringWidth(goalStr);

                    goalFont->Render(_data->screenWidth/2 - strWidth/2,
                                     _data->screenHeight/6 - goalFont->GetHeight()/2*scale,
                                     HGETEXT_LEFT,
                                     goalStr);
                });
        }

    }