void OnRender(fDouble elapsedTime, ffGraphics *pGraph) { pGraph->Begin(); ffDrawer &drawer = ffDrawer::Get(); drawer.SetColor(m_color); fFloat scalePixelX = 400 * m_scale; fFloat scalePixelY = 300 * m_scale; drawer.DrawSolidRectangle(pGraph, fcyRect(400 - scalePixelX, 300 - scalePixelY, 400 + scalePixelX, 300 + scalePixelY)); pGraph->End(); }
void OnRender(fDouble elapsedTime, ffGraphics *pGraph) { pGraph->Begin(); if (m_elapse >= m_delay){ m_elapse = 0; swprintf_s(m_buffer, L"FPS:%.2f", 1.f / elapsedTime); } m_elapse += elapsedTime; ffDrawer &drawer = ffDrawer::Get(); drawer.SetColor(ffColors::White); drawer.DrawSolidRectangle(pGraph, fcyRect(48, 50, 135, 68)); drawer.SetColor(ffColors::Black); drawer.DrawWString(pGraph, fcyVec2(50, 50), m_buffer); pGraph->End(); }
fcyRect f2dFontRendererImpl::MeasureString(fcStrW String, bool bStrictWidth) { if (!m_pProvider) return fcyRect(); fcyVec2 tStartPos; fcyRect tBoundBox(2048.f, 2048.f, 0.f, 0.f); bool tMeasureable = false; fuInt tCount = wcslen(String); f2dGlyphInfo tInfo; for(fuInt i = 0; i<tCount; ++i) { if(String[i] == L'\n') { tStartPos.x = 0; tStartPos.y += m_pProvider->GetLineHeight(); } else { if(FCYOK(m_pProvider->QueryGlyph(NULL, String[i], &tInfo))) { tMeasureable = true; float tTop = tStartPos.y - tInfo.BrushPos.y; float tBottom = tStartPos.y + (tInfo.GlyphSize.y - tInfo.BrushPos.y); float tLeft = tStartPos.x - tInfo.BrushPos.x; float tWidth; if (bStrictWidth) { tWidth = tInfo.GlyphSize.x - tInfo.BrushPos.x; if (i + 1 < tCount && String[i + 1] != L'\n') { if (tWidth < tInfo.Advance.x) tWidth = tInfo.Advance.x; } } else tWidth = tInfo.Advance.x - tInfo.BrushPos.x; float tRight = tStartPos.x + tWidth; tBoundBox.a.x = FCYMIN(tBoundBox.a.x, tLeft); tBoundBox.b.x = FCYMAX(tBoundBox.b.x, tRight); tBoundBox.a.y = FCYMIN(tBoundBox.a.y, tTop); tBoundBox.b.y = FCYMAX(tBoundBox.b.y, tBottom); tStartPos += tInfo.Advance; } } } if (tMeasureable) { tBoundBox.b.x = tBoundBox.a.x + tBoundBox.GetWidth() * m_Scale.x; tBoundBox.b.y = tBoundBox.a.y + tBoundBox.GetHeight() * m_Scale.y; return tBoundBox; } else return fcyRect(); }