예제 #1
0
// Level07 Screen Draw logic
void DrawLevel07Screen(void)
{
    // Draw Level07 screen here!
    DrawCircleV(leftCirclePos, circleRadius, leftCircleColor);
    DrawCircleV(middleCirclePos, circleRadius, middleCircleColor);
    DrawCircleV(rightCirclePos, circleRadius, rightCircleColor);
    
    if (leftCircleActive) DrawCircleV(leftBtnPos, btnRadius, GRAY);
    else DrawCircleV(leftBtnPos, btnRadius, LIGHTGRAY);
    
    if (middleCircleActive) DrawCircleV(middleBtnPos, btnRadius, GRAY);
    else DrawCircleV(middleBtnPos, btnRadius, LIGHTGRAY);
    
    if (rightCircleActive) DrawCircleV(rightBtnPos, btnRadius, GRAY);
    else DrawCircleV(rightBtnPos, btnRadius, LIGHTGRAY);
    
    
    
    if (levelFinished)
    {
        DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f));
        DrawText("LEVEL 07", GetScreenWidth()/2 - MeasureText("LEVEL 07", 30)/2, 20, 30, GRAY);
        DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY);
    }
    else DrawText("LEVEL 07", GetScreenWidth()/2 - MeasureText("LEVEL 07", 30)/2, 20, 30, LIGHTGRAY);
}
예제 #2
0
// returns number of characters of string s that fits in a given width dx
// note: could be speed up a bit because in our use case we already know
// the width of the whole string so we could supply it to the function, but
// this shouldn't happen often, so that's fine. It's also possible that
// a smarter approach is possible, but this usually only does 3 MeasureText
// calls, so it's not that bad
size_t StringLenForWidth(Graphics *g, Font *f, const WCHAR *s, size_t len, float dx, TextMeasureAlgorithm algo)
{
    RectF r = MeasureText(g, f, s, len, algo);
    if (r.Width <= dx)
        return len;
    // make the best guess of the length that fits
    size_t n = (size_t)((dx / r.Width) * (float)len);
    CrashIf((0 == n) || (n > len));
    r = MeasureText(g, f, s, n, algo);
    // find the length len of s that fits within dx iff width of len+1 exceeds dx
    int dir = 1; // increasing length
    if (r.Width > dx)
        dir = -1; // decreasing length
    for (;;) {
        n += dir;
        r = MeasureText(g, f, s, n, algo);
        if (1 == dir) {
            // if advancing length, we know that previous string did fit, so if
            // the new one doesn't fit, the previous length was the right one
            if (r.Width > dx)
                return n - 1;
        } else {
            // if decreasing length, we know that previous string didn't fit, so if
            // the one one fits, it's of the correct length
            if (r.Width < dx)
                return n;
        }
    }
}
예제 #3
0
void tcOOBView::PlaceIconsCategory(std::vector<tsOOBInfo>& objInfo)
{

    wxSize stringsize;

    for (size_t n=0; n < objInfo.size(); n++) 
    {
        tsOOBInfo& info = objInfo[n];

        MeasureText(defaultFont.get(), fontSize, info.mzName.c_str(), stringsize);
        float w = std::min(float(stringsize.GetWidth()), maxNameWidth);
        info.remcon.left = info.rectf.left + w + 12.0f;
        info.remcon.bottom = info.rectf.bottom - 2.0f;
        info.remcon.right = info.remcon.left + float(stringsize.GetHeight()-4);
        info.remcon.top = info.remcon.bottom + float(stringsize.GetHeight()-3);
        //info.remcon.Inflate(-2.0f,-2.0f);

        info.rleader = info.remcon;
        info.rleader.Offset(-info.remcon.Width(), 0);

        MeasureText(defaultFont.get(), fontSize, info.mzAction.c_str(), stringsize);

        info.raction.bottom = info.rectf.bottom - 1.0f;
        info.raction.left = info.remcon.GetRight() + 5.0f;
        if (info.raction.left < 120.0f) {info.raction.left = 120.0f;}
        info.raction.top = info.raction.bottom + float(stringsize.GetHeight());
        info.raction.right = info.raction.left + float(stringsize.GetHeight());
        //info.raction.Inflate(-2.0f,-2.0f);
    }

}
예제 #4
0
void CG16bitFont::DrawText (CG16bitImage &Dest, 
							int x, 
							int y, 
							WORD wColor, 
							DWORD byOpacity,
							const CString &sText,
							DWORD dwFlags,
							int *retx) const

//	DrawText
//
//	Draws a line of text on the given image

	{
	char *pPos = sText.GetASCIIZPointer();
	char *pEndPos = pPos + sText.GetLength();
	int xPos = x;

	if (dwFlags & AlignCenter)
		{
		int cxWidth = MeasureText(sText);
		xPos -= cxWidth / 2;
		}
	else if (dwFlags & AlignRight)
		{
		int cxWidth = MeasureText(sText);
		xPos -= cxWidth;
		}

	bool bInQuotes = false;
	while (pPos < pEndPos)
		{
		//	Get metrics

		int iIndex = (int)(BYTE)(*pPos) - g_iStartChar;
		iIndex = max(0, iIndex);

		CharMetrics *pMetrics = (CharMetrics *)m_Metrics.GetStruct(iIndex);

		//	Paint

		Dest.FillMask(0,
				iIndex * m_cyHeight,
				pMetrics->cxWidth,
				m_cyHeight,
				m_FontImage,
				wColor,
				xPos,
				y,
				(BYTE)byOpacity);

		pPos++;
		xPos += pMetrics->cxAdvance;
		}
	
	if (retx)
		*retx = xPos;
	}
예제 #5
0
// Draw game (one frame)
void DrawGame(void)
{
    BeginDrawing();

        ClearBackground(RAYWHITE);

        if (!gameOver)
        {
            // Draw missiles
            for (int i = 0; i < MAX_MISSILES; i++)
            {
                if (missile[i].active)
                {
                    DrawLine(missile[i].origin.x, missile[i].origin.y, missile[i].position.x, missile[i].position.y, RED);

                    if (framesCounter % 16 < 8) DrawCircle(missile[i].position.x, missile[i].position.y, 3, YELLOW);
                }
            }
            
            // Draw interceptors
            for (int i = 0; i < MAX_INTERCEPTORS; i++)
            {
                if (interceptor[i].active)
                {
                    DrawLine(interceptor[i].origin.x, interceptor[i].origin.y, interceptor[i].position.x, interceptor[i].position.y, GREEN);

                    if (framesCounter % 16 < 8) DrawCircle(interceptor[i].position.x, interceptor[i].position.y, 3, BLUE);
                }
            }
            
            // Draw explosions
            for (int i = 0; i < MAX_EXPLOSIONS; i++)
            {
                if (explosion[i].active) DrawCircle(explosion[i].position.x, explosion[i].position.y, EXPLOSION_RADIUS*explosion[i].radiusMultiplier, EXPLOSION_COLOR);
            }

            // Draw buildings and launchers
            for (int i = 0; i < LAUNCHERS_AMOUNT; i++)
            {
                if (launcher[i].active) DrawRectangle(launcher[i].position.x - LAUNCHER_SIZE/2, launcher[i].position.y - LAUNCHER_SIZE/2, LAUNCHER_SIZE, LAUNCHER_SIZE, GRAY);
            }

            for (int i = 0; i < BUILDINGS_AMOUNT; i++)
            {
                if (building[i].active) DrawRectangle(building[i].position.x - BUILDING_SIZE/2, building[i].position.y - BUILDING_SIZE/2, BUILDING_SIZE, BUILDING_SIZE, LIGHTGRAY);
            }

            // Draw score
            DrawText(FormatText("SCORE %4i", score), 20, 20, 40, LIGHTGRAY);
            
            if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
        }
        else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);

    EndDrawing();
}
예제 #6
0
파일: printout.cpp 프로젝트: brho/xword
// This should throw an exception if the text runs off the page when we are
// measuring.
void
MyPrintout::DrawTextLine(const wxString & text,
                         int * x, int * y,
                         int * width, int * height)
{
    // Measure the text, draw it, and move the x and y variables to the location
    // that the next text line should be drawn.
    // The caller must ensure that the text is wrapped.

    int w, h;
    MeasureText(text, &w, &h);
    h += LINE_PADDING;

    AdjustColumn(x, y, w, h);

    const wxRect textRect(*x, *y, w, h);
    if (m_isDrawing)
        GetDC()->DrawLabel(text, textRect);
    else if (! m_pageRect.Contains(textRect))
        throw FontSizeError();

    if (width != NULL)
        *width = w;
    if (height != NULL)
        *height = h;

    *y += h;
}
예제 #7
0
void Config_Render(bool force)
{
	int x, y;
	
	if (force) configdirty = 2;
	if (!configdirty) return;
	configdirty--;
	
	ClearFramebuffer();
	DrawText(2, 2, RGB(255, 255, 255), "blargSNES config");
	
	y = 2 + 12 + 10;
	
	DrawCheckBox(10, y, RGB(255,255,255), "Hardware renderer", Config.HardwareRenderer);
	
	y += 26;
	
	DrawText(10, y+1, RGB(255,255,255), "Scaling:");
	x = 10 + MeasureText("Scaling:") + 6;
	
	char* scalemodes[] = {"1:1", "Fullscreen", "Cropped", "4:3", "Cropped 4:3"};
	int themode = Config.ScaleMode;
	if (themode < 0 || themode > 4) themode = 0;
	DrawButton(x, y-3, 140, RGB(255,255,255), scalemodes[themode]);
	
	
	DrawButton(10, 212, 0, RGB(255,128,128), "Cancel");
	DrawButton(-10, 212, 0, RGB(128,255,128), "Save changes");
}
예제 #8
0
// Update desired size of the button. If the size changes, trigger layout
// (which will in turn request repaints of affected areas)
// To keep size of the button stable (to avoid re-layouts) we use font
// line spacing to be the height of the button, even if text is empty.
// Note: it might be that for some cases button with no text should collapse
// in size but we don't have a need for that yet
void Button::RecalculateSize(bool repaintIfSizeDidntChange)
{
    Size prevSize = desiredSize;

    desiredSize = GetBorderAndPaddingSize(cachedStyle);
    Graphics *gfx = AllocGraphicsForMeasureText();
    CachedStyle *s = cachedStyle;
    Font *font = GetCachedFont(s->fontName, s->fontSize, s->fontWeight);

    textDx = 0;
    float fontDy = font->GetHeight(gfx);
    RectF bbox;
    if (text) {
        bbox = MeasureText(gfx, font, text);
        textDx = (size_t)bbox.Width; // TODO: round up?
        // bbox shouldn't be bigger than fontDy. We apply magic adjustment because
        // bbox is bigger in n-th decimal point
        CrashIf(fontDy + .5f < bbox.Height);
    }
    desiredSize.Width  += textDx;
    desiredSize.Height += (INT)fontDy; // TODO: round up?
    FreeGraphicsForMeasureText(gfx);

    if (!prevSize.Equals(desiredSize))
        RequestLayout(this);
    else if (repaintIfSizeDidntChange)
        RequestRepaint(this);
}
예제 #9
0
// TODO: not quite sure why spaceDx1 != spaceDx2, using spaceDx2 because
// is smaller and looks as better spacing to me
REAL GetSpaceDx(Graphics* g, Font* f, TextMeasureAlgorithm algo) {
    RectF bbox;
#if 0
    bbox = MeasureText(g, f, L" ", 1, algo);
    REAL spaceDx1 = bbox.Width;
    return spaceDx1;
#else
    // this method seems to return (much) smaller size that measuring
    // the space itself
    bbox = MeasureText(g, f, L"wa", 2, algo);
    REAL l1 = bbox.Width;
    bbox = MeasureText(g, f, L"w a", 3, algo);
    REAL l2 = bbox.Width;
    REAL spaceDx2 = l2 - l1;
    return spaceDx2;
#endif
}
예제 #10
0
/** Gets the text width, move and adjusts of the specified descriptor when displayed 
in this font.
@param aText The descriptor whose width should be determined. 
@param aParam Parameter block that controls how much of aText is measured
@param aCharWidth The width of the specified descriptor when displayed in this 
font, in pixels (including information on the width, move and adjusts of the 
descriptor). 
@publishedAll 
@released
*/
EXPORT_C void CFbsFont::TextWidthInPixels(const TDesC& aText,const TMeasureTextInput* aParam, SCharWidth& aCharWidth) const
	{
	TMeasureTextOutput output;
	aCharWidth.iMove = MeasureText(aText,aParam,&output);
	aCharWidth.iLeftAdjust = output.iBounds.iTl.iX;
	aCharWidth.iRightAdjust = aCharWidth.iMove - output.iBounds.iBr.iX;
	aCharWidth.iWidth = output.iBounds.Width();
	}
예제 #11
0
/** Gets how much of the specified descriptor can be displayed in this font without 
exceeding the specified width.
It also returns the excess width defined as the specified available width 
minus the width of the portion of the descriptor which can be displayed without 
exceeding the available width.
@param aText The descriptor. 
@param aWidthInPixels The available width for character display. 
@param aExcessWidthInPixels The excess width after displaying the portion of 
the descriptor, in pixels. 
@return The number of characters (starting from the beginning of the descriptor) 
which will be able to be displayed without exceeding the specified width. 
@see CFont::TextCount()
@see TextCount() 
@publishedAll 
@released
*/
EXPORT_C TInt CFbsFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidth) const
	{
	TMeasureTextInput input;
	input.iMaxAdvance = aWidthInPixels;
	TMeasureTextOutput output;
	aExcessWidth = aWidthInPixels - MeasureText(aText,&input,&output);
	return output.iChars;
	}
예제 #12
0
// Logo Screen Draw logic
void DrawLogoScreen(void)
{
    // Draw LOGO screen
    if (logoScreenState == 0)
    {
        if ((framesCounter/15)%2) DrawRectangle(logoPositionX, logoPositionY - 60, 16, 16, BLACK);
    }
    else if (logoScreenState == 1)
    {
        DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK);
        DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK);
    }
    else if (logoScreenState == 2)
    {
        DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK);
        DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK);

        DrawRectangle(logoPositionX + 240, logoPositionY - 60, 16, rightSideRecHeight, BLACK);
        DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK);
    }
    else if (logoScreenState == 3)
    {         
        DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK);
        DrawRectangle(logoPositionX, logoPositionY + 16 - 60, 16, leftSideRecHeight - 32, BLACK);

        DrawRectangle(logoPositionX + 240, logoPositionY + 16 - 60, 16, rightSideRecHeight - 32, BLACK);
        DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK);

        DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112 - 60, 224, 224, RAYWHITE);

        DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48 - 60, 50, BLACK);

        if (!msgLogoADone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY);
        else
        {
            DrawText(msgLogoA, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY);

            if (!msgLogoBDone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoB, 30)/2, logoPositionY + 280, 30, GRAY);
            else
            {
                DrawText(msgLogoB, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 280, 30, GRAY);
            }
        }
    }
}
예제 #13
0
void CTextPainter::SetText (const CString &sText)

//	SetText
//
//	Sets the text

	{
	m_sText = sText;
	MeasureText();
	}
예제 #14
0
/*!***************************************************************************
 @Function			GetSize
 @Output			pfWidth				Width of the string in pixels
 @Output			pfHeight			Height of the string in pixels
 @Input				pszUTF8				UTF8 string to take the size of
 @Description		Returns the size of a string in pixels.
*****************************************************************************/
void CPVRTPrint3D::MeasureText(
	float		* const pfWidth,
	float		* const pfHeight,
	float				fScale,
	const char	* const pszUTF8)
{
	m_CachedUTF32.Clear();
	PVRTUnicodeUTF8ToUTF32((PVRTuint8*)pszUTF8, m_CachedUTF32);
	MeasureText(pfWidth,pfHeight,fScale,m_CachedUTF32);
}
예제 #15
0
void CG16bitFont::DrawText (CG16bitImage &Dest, 
							const RECT &rcRect, 
							WORD wColor, 
							DWORD byOpacity,
							const CString &sText, 
							int iLineAdj, 
							DWORD dwFlags,
							int *retcyHeight) const

//	Draw
//
//	Draws wrapped text

	{
	int i;
	TArray<CString> Lines;

	BreakText(sText, RectWidth(rcRect), &Lines, dwFlags);
	int y = rcRect.top;
	for (i = 0; i < Lines.GetCount(); i++)
		{
		int x = rcRect.left;

		if (dwFlags & AlignCenter)
			{
			int cxWidth = MeasureText(Lines[i]);
			x = rcRect.left + (RectWidth(rcRect) - cxWidth) / 2;
			}
		else if (dwFlags & AlignRight)
			{
			int cxWidth = MeasureText(Lines[i]);
			x = rcRect.right - cxWidth;
			}

		if (!(dwFlags & MeasureOnly))
			DrawText(Dest, x, y, wColor, byOpacity, Lines[i]);

		y += m_cyHeight + iLineAdj;
		}

	if (retcyHeight)
		*retcyHeight = y - rcRect.top;
	}
예제 #16
0
// Level06 Screen Draw logic
void DrawLevel06Screen(void)
{
    // Draw Level06 screen
    DrawRectangleRec(centerRec, LIGHTGRAY);
    
    for (int i = 0; i < 4; i++)
    {
        DrawRectangleRec(movingRecs[i], GRAY);
    }
    
    if (!done & (mouseOverNum >= 0)) DrawRectangleLines(movingRecs[mouseOverNum].x - 5, movingRecs[mouseOverNum].y - 5, movingRecs[mouseOverNum].width + 10, movingRecs[mouseOverNum].height + 10, Fade(LIGHTGRAY, 0.8f));
        
    if (levelFinished)
    {
        DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f));
        DrawText("LEVEL 06", GetScreenWidth()/2 - MeasureText("LEVEL 06", 30)/2, 20, 30, GRAY);
        DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY);
    }
    else DrawText("LEVEL 06", GetScreenWidth()/2 - MeasureText("LEVEL 06", 30)/2, 20, 30, LIGHTGRAY);
}
예제 #17
0
int CBFontTT::GetTextHeight(byte  *Text, int Width) {
	WideString text;

	if (Game->m_TextEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
	else text = StringUtil::AnsiToWide((char *)Text);


	int textWidth, textHeight;
	MeasureText(text, Width, -1, textWidth, textHeight);

	return textHeight;
}
예제 #18
0
void CTextPainter::OnReadFromStream (SLoadCtx &Ctx)

//	OnReadFromStream
//
//	Reads from a stream
//
//	CString			m_sText

	{
	m_sText.ReadFromStream(Ctx.pStream);
	MeasureText();
	}
예제 #19
0
// Draw game (one frame)
void DrawGame(void)
{
    BeginDrawing();

        ClearBackground(RAYWHITE);
        
        if (!gameOver)
        {
            DrawRectangleRec(player.rec, player.color);

            if (wave == FIRST) DrawText("FIRST WAVE", screenWidth/2 - MeasureText("FIRST WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha));
            else if (wave == SECOND) DrawText("SECOND WAVE", screenWidth/2 - MeasureText("SECOND WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha));
            else if (wave == THIRD) DrawText("THIRD WAVE", screenWidth/2 - MeasureText("THIRD WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha));
            
            for (int i = 0; i < activeEnemies; i++)
            {
                if (enemy[i].active) DrawRectangleRec(enemy[i].rec, enemy[i].color);
            }

            for (int i = 0; i < NUM_SHOOTS; i++)
            {
                if (shoot[i].active) DrawRectangleRec(shoot[i].rec, shoot[i].color);
            }
            
            DrawText(FormatText("%04i", score), 20, 20, 40, GRAY);
        
            if (victory) DrawText("YOU WIN", screenWidth/2 - MeasureText("YOU WIN", 40)/2, screenHeight/2 - 40, 40, BLACK);
        
            if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
        }
        else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);

    EndDrawing();
}
예제 #20
0
int CBFontTT::GetTextWidth(byte  *Text, int MaxLength) {
	WideString text;

	if (Game->m_TextEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
	else text = StringUtil::AnsiToWide((char *)Text);

	if (MaxLength >= 0 && text.length() > MaxLength) text = text.substr(0, MaxLength);

	int textWidth, textHeight;
	MeasureText(text, -1, -1, textWidth, textHeight);

	return textWidth;
}
예제 #21
0
uint32 TTextLayout::OffsetToPoint(STextOffset offset, TPoint& point) const
{
	uint32 line = OffsetToLine(offset);
	ASSERT(line < fLineCount);

	LineRec& rec = fLineBreaks[line];
	point.v = rec.vertOffset + rec.ascent + fInset.v;	
	if (offset == rec.textOffset)
		point.h = fInset.h;
	else
		point.h = MeasureText(fText + rec.textOffset, offset - rec.textOffset, 0) + fInset.h;
	
	return line;
}
예제 #22
0
파일: arkanoid.c 프로젝트: AdanBB/raylib
// Draw game (one frame)
void DrawGame(void)
{
    BeginDrawing();

        ClearBackground(RAYWHITE);

        if (!gameOver)
        {
            // Draw player bar
            DrawRectangle(player.position.x - player.size.x/2, player.position.y - player.size.y/2, player.size.x, player.size.y, BLACK);

            // Draw player lives
            for (int i = 0; i < player.life; i++) DrawRectangle(20 + 40*i, screenHeight - 30, 35, 10, LIGHTGRAY);
            
            // Draw ball
            DrawCircleV(ball.position, ball.radius, MAROON);
            
            // Draw bricks
            for (int i = 0; i < LINES_OF_BRICKS; i++)
            {
                for (int j = 0; j < BRICKS_PER_LINE; j++)
                {
                    if (brick[i][j].active)
                    {
                        if ((i + j) % 2 == 0) DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, GRAY);
                        else DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, DARKGRAY);
                    }
                }
            }
            
            if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
        }
        else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);

    EndDrawing();
}
예제 #23
0
void ACanvasSkia::DrawText(ARect r,const AString& sText,StringAlignment hAlign /*= StringAlignmentNear*/,StringAlignmentV vAlign /*=StringAlignmentMiddle*/)
{
	AFont* pFont = GetFont();
	_clip();

	AAutoClip clip(this,r);

	int maxWidth = MeasureText(sText).cx;
	int nFontSize = pFont->GetSize();
	int x=r.left;
	int delta = ((int)r.GetWidth()-maxWidth)/2;
	switch(hAlign)
	{
	default:
	case StringAlignmentNear:
		x = (REAL)r.left;
		break;
	case StringAlignmentCenter:
		x = r.left+delta;
		break;
	case StringAlignmentFar:
		x = r.right - maxWidth;
		break;

	}
	int y = r.top;
	switch(vAlign)
	{
	default:
	case StringAlignmentTop:
		y = r.top;
		break;
	case StringAlignmentMiddle:
		y = r.top + (r.GetHeight()-nFontSize)/2 - ( (r.GetHeight()-nFontSize) % 2);
		break;
	case StringAlignmentBottom:
		y = r.bottom-nFontSize;
		break;
	}
	//y -= 2;//微调 fix me later
	//y -= nFontSize/2;
	DrawText(x,y,sText);
}
예제 #24
0
// Update desired size of the button. If the size changes, trigger layout
// (which will in turn request repaints of affected areas)
// To keep size of the button stable (to avoid re-layouts) we use font
// line spacing to be the height of the button, even if text is empty.
// Note: it might be that for some cases button with no text should collapse
// in size but we don't have a need for that yet
void Button::RecalculateSize(bool repaintIfSizeDidntChange)
{
    Size prevSize = desiredSize;

    desiredSize = GetBorderAndPaddingSize(cachedStyle);
    Graphics *gfx = AllocGraphicsForMeasureText();
    CachedStyle *s = cachedStyle;
    Font *font = GetCachedFont(s->fontName, s->fontSize, s->fontWeight);

    textDx = 0;
    float fontDy = font->GetHeight(gfx);
    RectF bbox;
    if (text) {
        bbox = MeasureText(gfx, font, text);
        textDx = CeilI(bbox.Width);
        // I theorize that bbox shouldn't be bigger than fontDy. However, in practice
        // it is (e.g. for Lucida Grande and text "Page: 0 / 0", bbox.Dy is 19.00
        // and fontDy is 18.11). I still want to know if the difference gets even bigger
        // than that
        float maxDiff = 1.f;
        if (bbox.Height > fontDy + maxDiff) {
            fontDy = bbox.Height;
            float diff = fontDy + maxDiff - bbox.Height;
            char *fontName = str::conv::ToUtf8(s->fontName);
            char *tmp = str::conv::ToUtf8(text);
            CrashLogFmt("fontDy=%.2f, bbox.Height=%.2f, diff=%.2f (should be > 0) font: %s, text='%s'\r\n", (float)fontDy, (float)bbox.Height, diff, fontName, tmp);
            CrashIf(diff < 0);
        }
    }
    desiredSize.Width  += textDx;
    desiredSize.Height += CeilI(fontDy);
    FreeGraphicsForMeasureText(gfx);

    if (!prevSize.Equals(desiredSize))
        RequestLayout(this);
    else if (repaintIfSizeDidntChange)
        RequestRepaint(this);
}
예제 #25
0
/*!***************************************************************************
@Function			MeasureText
@Output				pfWidth				Width of the string in pixels
@Output				pfHeight			Height of the string in pixels
@Input				pszUnicode			Wide character string to take the
length of.
@Description		Returns the size of a string in pixels.
*****************************************************************************/
void CPVRTPrint3D::MeasureText(
	float		* const pfWidth,
	float		* const pfHeight,
	float				fScale,
	const wchar_t* const pszUnicode)
{
	_ASSERT(pszUnicode);
	m_CachedUTF32.Clear();

#if PVRTSIZEOFWCHAR == 2			// 2 byte wchar.
	PVRTUnicodeUTF16ToUTF32((PVRTuint16*)pszUnicode, m_CachedUTF32);
#else								// 4 byte wchar (POSIX)
	unsigned int uiC = 0;
	PVRTuint32* pUTF32 = (PVRTuint32*)pszUnicode;
	while(*pUTF32 && uiC < MAX_LETTERS)
	{
		m_CachedUTF32.Append(*pUTF32++);
		uiC++;
	}
#endif
	
	MeasureText(pfWidth,pfHeight,fScale,m_CachedUTF32);
}
예제 #26
0
void tcNumberWidget<T>::OnLButtonDown(wxMouseEvent& event)
{
    wxPoint pos = event.GetPosition();
    leftButtonDown = true;
    
    buttonDownTime = tcTime::Get()->Get30HzCount();
    lastAutoChange = 0;

    bool upper = pos.y < mnHeight / 2;

    // measure could be done once per font size change instead
    wxSize numberSize;
    MeasureText(defaultFont.get(), 1.1f * fontSize, "8", numberSize);

    float maxDigit = floorf(log10f(double(maxVal) / double(smallestIncrement))) - 1.0f;

    float digitIdx = floorf(float(mnWidth - pos.x - 2.0f) / float(numberSize.GetWidth()));
    if (digitIdx < 0) digitIdx = 0;
    else if (digitIdx > maxDigit) digitIdx = maxDigit;

    T increment = smallestIncrement * T(powf(10.0f, digitIdx));

    

    if (upper)
    {
        changeIncrement = increment;
    }
    else
    {
        changeIncrement = -increment;
    }

    SendRedraw();

    tcSound::Get()->PlayEffect("MutedBeep");
}
예제 #27
0
		Gwen::Point Base::MeasureText( Gwen::Font* pFont, const Gwen::String & text )
		{
			Gwen::UnicodeString str = Gwen::Utility::StringToUnicode( text );
			return MeasureText( pFont, str );
		}
예제 #28
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing");

    // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)

    Image image = LoadImage("resources/parrots.png");   // Loaded in CPU memory (RAM)
    ImageFormat(&image, UNCOMPRESSED_R8G8B8A8);         // Format image to RGBA 32bit (required for texture update) <-- ISSUE
    Texture2D texture = LoadTextureFromImage(image);    // Image converted to texture, GPU memory (VRAM)

    int currentProcess = NONE;
    bool textureReload = false;

    Rectangle selectRecs[NUM_PROCESSES];
    
    for (int i = 0; i < NUM_PROCESSES; i++) selectRecs[i] = (Rectangle){ 40, 50 + 32*i, 150, 30 };
    
    SetTargetFPS(60);
    //---------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        if (IsKeyPressed(KEY_DOWN))
        {
            currentProcess++;
            if (currentProcess > 7) currentProcess = 0;
            textureReload = true;
        }
        else if (IsKeyPressed(KEY_UP))
        {
            currentProcess--;
            if (currentProcess < 0) currentProcess = 7;
            textureReload = true;
        }
        
        if (textureReload)
        {
            UnloadImage(image);                         // Unload current image data
            image = LoadImage("resources/parrots.png"); // Re-load image data

            // NOTE: Image processing is a costly CPU process to be done every frame, 
            // If image processing is required in a frame-basis, it should be done 
            // with a texture and by shaders
            switch (currentProcess)
            {
                case COLOR_GRAYSCALE: ImageColorGrayscale(&image); break;
                case COLOR_TINT: ImageColorTint(&image, GREEN); break;
                case COLOR_INVERT: ImageColorInvert(&image); break;
                case COLOR_CONTRAST: ImageColorContrast(&image, -40); break;
                case COLOR_BRIGHTNESS: ImageColorBrightness(&image, -80); break;
                case FLIP_VERTICAL: ImageFlipVertical(&image); break;
                case FLIP_HORIZONTAL: ImageFlipHorizontal(&image); break;
                default: break;
            }
            
            Color *pixels = GetImageData(image);        // Get pixel data from image (RGBA 32bit)
            UpdateTexture(texture, pixels);             // Update texture with new image data
            free(pixels);                               // Unload pixels data from RAM
            
            textureReload = false;
        }
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);
            
            DrawText("IMAGE PROCESSING:", 40, 30, 10, DARKGRAY);
            
            // Draw rectangles
            for (int i = 0; i < NUM_PROCESSES; i++)
            {
                DrawRectangleRec(selectRecs[i], (i == currentProcess) ? SKYBLUE : LIGHTGRAY);
                DrawRectangleLines(selectRecs[i].x, selectRecs[i].y, selectRecs[i].width, selectRecs[i].height, (i == currentProcess) ? BLUE : GRAY);
                DrawText(processText[i], selectRecs[i].x + selectRecs[i].width/2 - MeasureText(processText[i], 10)/2, selectRecs[i].y + 11, 10, (i == currentProcess) ? DARKBLUE : DARKGRAY);
            }

            DrawTexture(texture, screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, WHITE);
            DrawRectangleLines(screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, texture.width, texture.height, BLACK);
            
        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadTexture(texture);       // Unload texture from VRAM
    UnloadImage(image);           // Unload image from RAM

    CloseWindow();                // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
예제 #29
0
void GrBitmapTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip,
                                     const GrPaint& paint, const SkPaint& skPaint,
                                     const SkMatrix& viewMatrix,
                                     const char text[], size_t byteLength,
                                     SkScalar x, SkScalar y) {
    SkASSERT(byteLength == 0 || text != NULL);

    // nothing to draw
    if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) {
        return;
    }

    this->init(rt, clip, paint, skPaint);

    SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();

    SkAutoGlyphCache    autoCache(fSkPaint, &fDeviceProperties, &viewMatrix);
    SkGlyphCache*       cache = autoCache.getCache();
    GrFontScaler*       fontScaler = GetGrFontScaler(cache);

    // transform our starting point
    {
        SkPoint loc;
        viewMatrix.mapXY(x, y, &loc);
        x = loc.fX;
        y = loc.fY;
    }

    // need to measure first
    int numGlyphs;
    if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) {
        SkVector    stopVector;
        numGlyphs = MeasureText(cache, glyphCacheProc, text, byteLength, &stopVector);

        SkScalar    stopX = stopVector.fX;
        SkScalar    stopY = stopVector.fY;

        if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) {
            stopX = SkScalarHalf(stopX);
            stopY = SkScalarHalf(stopY);
        }
        x -= stopX;
        y -= stopY;
    } else {
        numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL);
    }
    fTotalVertexCount = kVerticesPerGlyph*numGlyphs;

    const char* stop = text + byteLength;

    SkAutoKern autokern;

    SkFixed fxMask = ~0;
    SkFixed fyMask = ~0;
    SkScalar halfSampleX, halfSampleY;
    if (cache->isSubpixel()) {
        halfSampleX = halfSampleY = SkFixedToScalar(SkGlyph::kSubpixelRound);
        SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(viewMatrix);
        if (kX_SkAxisAlignment == baseline) {
            fyMask = 0;
            halfSampleY = SK_ScalarHalf;
        } else if (kY_SkAxisAlignment == baseline) {
            fxMask = 0;
            halfSampleX = SK_ScalarHalf;
        }
    } else {
        halfSampleX = halfSampleY = SK_ScalarHalf;
    }

    Sk48Dot16 fx = SkScalarTo48Dot16(x + halfSampleX);
    Sk48Dot16 fy = SkScalarTo48Dot16(y + halfSampleY);

    // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix, but for
    // performance reasons we just invert here instead
    if (!viewMatrix.invert(&fLocalMatrix)) {
        SkDebugf("Cannot invert viewmatrix\n");
        return;
    }

    while (text < stop) {
        const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask);

        fx += autokern.adjust(glyph);

        if (glyph.fWidth) {
            this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
                                            glyph.getSubXFixed(),
                                            glyph.getSubYFixed(),
                                            GrGlyph::kCoverage_MaskStyle),
                              Sk48Dot16FloorToInt(fx),
                              Sk48Dot16FloorToInt(fy),
                              fontScaler);
        }

        fx += glyph.fAdvanceX;
        fy += glyph.fAdvanceY;
    }

    this->finish();
}
예제 #30
0
int CG16bitFont::BreakText (const CString &sText, int cxWidth, TArray<CString> *retLines, DWORD dwFlags) const

//	BreakText
//
//	Splits the given string into multiple lines so that they fit
//	in the given width

	{
	char *pPos = sText.GetASCIIZPointer();
	char *pStartLine = pPos;
	int iCharsInLine = 0;
	char *pStartWord = pPos;
	int iCharsInWord = 0;
	int cxWordWidth = 0;
	int cxRemainingWidth = cxWidth;
	int iLines = 0;

	//	Can't handle 0 widths

	if (cxWidth == 0)
		return 0;

	//	Smart quotes

	bool bInSmartQuotes = false;
	bool *ioInSmartQuotes;
	if (dwFlags & SmartQuotes)
		ioInSmartQuotes = &bInSmartQuotes;
	else
		ioInSmartQuotes = NULL;

	//	If we need to truncate, then we need to adjust the width

	if (dwFlags & TruncateLine)
		{
		cxWidth -= MeasureText(STR_ELLIPSIS);
		if (cxWidth < 0)
			return 0;
		}

	//	Do it

	bool bTruncate = false;
	while (*pPos != '\0')
		{
		//	If we've got a carriage return then we immediately end
		//	the line.

		if (*pPos == '\n')
			{
			//	Add the current word to the line

			iCharsInLine += iCharsInWord;

			//	Add the line to the array

			FormatLine(pStartLine, iCharsInLine, ioInSmartQuotes, retLines);
			iLines++;

			//	Reset the line and word

			pStartLine = pPos + 1;
			pStartWord = pStartLine;
			iCharsInLine = 0;
			iCharsInWord = 0;
			cxWordWidth = 0;
			cxRemainingWidth = cxWidth;

			//	Reset smartquotes (sometimes we end a paragraph without closing
			//	a quote. In that case, we need to start with an open quote).

			bInSmartQuotes = false;

			//	If we're truncating, we're out of here (we don't add an ellipsis)

			if (dwFlags & TruncateLine)
				break;
			}

		//	Otherwise, continue by trying to add the character to the word

		else
			{
			char chChar = *pPos;
			if (chChar == '"' && ioInSmartQuotes) chChar = '“';

			//	Get the metrics for the character

			int iIndex = (int)(BYTE)chChar - g_iStartChar;
			iIndex = max(0, iIndex);

			CharMetrics *pMetrics = (CharMetrics *)m_Metrics.GetStruct(iIndex);

			//	Does the character fit in the line?

			bool bCharFits = ((cxRemainingWidth - cxWordWidth) >= pMetrics->cxWidth);

			//	If the character doesn't fit, then we've reached the end
			//	of the line.

			if (!bCharFits)
				{
				//	If the character is a space then the entire word should
				//	fit on the line

				if (*pPos == ' ')
					{
					iCharsInLine += iCharsInWord;

					//	Reset the word

					pStartWord = pPos + 1;
					iCharsInWord = 0;
					cxWordWidth = 0;
					}

				//	If this is the first word in the line then we need to break
				//	up the word across lines.

				if (iCharsInLine == 0)
					{
					//	Add what we've got to the array

					FormatLine(pStartWord, iCharsInWord, ioInSmartQuotes, retLines);
					iLines++;

					//	Reset the word

					pStartWord = pPos;
					iCharsInWord = 1;
					cxWordWidth = pMetrics->cxAdvance;
					}

				//	Otherwise, add the line to the array

				else
					{
					FormatLine(pStartLine, iCharsInLine, ioInSmartQuotes, retLines);
					iLines++;

					//	Reset the line

					pStartLine = pStartWord;
					iCharsInLine = 0;
					cxRemainingWidth = cxWidth;

					//	Add the character that didn't fit to the word

					if (*pPos != ' ')
						{
						iCharsInWord++;
						cxWordWidth += pMetrics->cxAdvance;
						}
					}

				//	Done if we're truncating

				if (dwFlags & TruncateLine)
					{
					iCharsInLine = 0;
					iCharsInWord = 0;
					bTruncate = true;
					break;
					}
				}

			//	Otherwise, if it does fit, add it to the end of the word

			else
				{
				iCharsInWord++;
				cxWordWidth += pMetrics->cxAdvance;

				//	If this character is a space or a hyphen, add it to the
				//	end of the line

				if (*pPos == ' ' || *pPos == '-')
					{
					iCharsInLine += iCharsInWord;
					cxRemainingWidth -= cxWordWidth;

					//	Reset the word

					pStartWord = pPos + 1;
					iCharsInWord = 0;
					cxWordWidth = 0;
					}
				}
			}

		//	Next character
		
		pPos++;
		}

	//	Add the remainder

	iCharsInLine += iCharsInWord;
	if (iCharsInLine)
		{
		FormatLine(pStartLine, iCharsInLine, ioInSmartQuotes, retLines);
		iLines++;
		}

	//	Add ellipsis, if necessary

	if (bTruncate && retLines)
		retLines->GetAt(0).Append(STR_ELLIPSIS);

	//	Return the lines

	return iLines;
	}