void Svg::render(const CanvasPtr &canvas, Rectf render_viewbox) { if (!root_node) { SvgTreeBuilder builder(canvas); auto element = xml->document_element(); builder.build(element); root_node = builder.node; } SvgAttributeReader attr_viewbox(xml->document_element(), "viewBox"); float x = (float)attr_viewbox.get_number(); float y = (float)attr_viewbox.get_number(); float w = (float)attr_viewbox.get_number(); float h = (float)attr_viewbox.get_number(); Rectf svg_viewport = Rectf::xywh(x, y, w, h); float aspect = svg_viewport.width() / svg_viewport.height(); auto center = render_viewbox.center(); render_viewbox.set_width(render_viewbox.height() * aspect); render_viewbox.set_position(center - Vec2f(render_viewbox.size() * 0.5f)); auto offset_svg = Mat4f::translate(-svg_viewport.x(), -svg_viewport.y(), 0.0f); auto scale = Mat4f::scale(render_viewbox.width() / svg_viewport.width(), render_viewbox.height() / svg_viewport.height(), 1.0f); auto offset_render = Mat4f::translate(render_viewbox.x(), render_viewbox.y(), 0.0f); root_node->transform = offset_render * scale * offset_svg; root_node->transform_active = true; root_node->render(canvas); }
void Camera::buildOrthographicProjectionMatrix(Matrix4x4& mat, const Rectf& viewport, float size, float zNear, float zFar, bool flipY) { const float wideSize = (size * viewport.width() ) / viewport.height(); const float left = -wideSize; const float right = wideSize; const float top = flipY ? - size : size; const float bottom = flipY ? size : -size; const float far = -zFar; const float near = zNear; const float a = 2.0f / (right - left); const float b = 2.0f / (top - bottom); const float c = -2.0f / (far - near); const float tx = -(right + left) / (right - left); const float ty = -(top + bottom) / (top - bottom); const float tz = -(far + near) / (far - near); mat.set( a, 0, 0, 0, 0, b, 0, 0, 0, 0, c, 0, tx, ty, tz, 1, false); }
void EERIEDrawBitmap2DecalY(Rectf rect, float z, TextureContainer * tex, Color color, float _fDeltaY) { rect.move(-.5f, -.5f); rect.top = rect.top + _fDeltaY * rect.height(); Vec2f uv = (tex) ? tex->uv : Vec2f_ZERO; float sv = uv.y * _fDeltaY; ColorRGBA col = color.toRGBA(); Vec2f uv1(0.f, sv); Vec2f uv2(uv.x, sv); Vec2f uv3(uv.x, uv.y); Vec2f uv4(0.f, uv.y); TexturedVertex v[4]; v[0] = TexturedVertex(Vec3f(rect.topLeft(), z), 1.f, col, uv1); v[1] = TexturedVertex(Vec3f(rect.topRight(), z), 1.f, col, uv2); v[2] = TexturedVertex(Vec3f(rect.bottomRight(), z), 1.f, col, uv3); v[3] = TexturedVertex(Vec3f(rect.bottomLeft(), z), 1.f, col, uv4); SetTextureDrawPrim(tex, v, Renderer::TriangleFan); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST(RectTest, RectTypes) { // Rectf { Rectf rect; EXPECT_FLOAT_EQ(0.0f, rect.min().x()); EXPECT_FLOAT_EQ(0.0f, rect.min().y()); EXPECT_FLOAT_EQ(0.0f, rect.width()); EXPECT_FLOAT_EQ(0.0f, rect.height()); EXPECT_FALSE(rect.isValid()); } { Rectf rect(-1.0f, -2.0f, 5.0f, 10.0f); EXPECT_FLOAT_EQ(-1.0f, rect.min().x()); EXPECT_FLOAT_EQ(-2.0f, rect.min().y()); EXPECT_FLOAT_EQ(5.0f, rect.width()); EXPECT_FLOAT_EQ(10.0f, rect.height()); EXPECT_TRUE(rect.isValid()); } // Recti { Recti rect; EXPECT_EQ(0, rect.min().x()); EXPECT_EQ(0, rect.min().y()); EXPECT_EQ(0, rect.width()); EXPECT_EQ(0, rect.height()); EXPECT_FALSE(rect.isValid()); } { Recti rect(-1, -2, 5, 10); EXPECT_EQ(-1, rect.min().x()); EXPECT_EQ(-2, rect.min().y()); EXPECT_EQ(5, rect.width()); EXPECT_EQ(10, rect.height()); EXPECT_TRUE(rect.isValid()); } // Rectui { Rectui rect; EXPECT_EQ(0, rect.min().x()); EXPECT_EQ(0, rect.min().y()); EXPECT_EQ(0, rect.width()); EXPECT_EQ(0, rect.height()); EXPECT_FALSE(rect.isValid()); } { Rectui rect(1, 2, 5, 10); EXPECT_EQ(1, rect.min().x()); EXPECT_EQ(2, rect.min().y()); EXPECT_EQ(5, rect.width()); EXPECT_EQ(10, rect.height()); EXPECT_TRUE(rect.isValid()); } }
void Note::render() { if(!allocate()) { return; } float z = 0.000001f; GRenderer->GetTextureStage(0)->setWrapMode(TextureStage::WrapClamp); if(background) { EERIEDrawBitmap2(_area.left, _area.top, _area.width(), _area.height(), z, background, Color::white); } if(pages.empty()) { return; } arx_assert(_page < pages.size()); // Draw the "previous page" button Rectf prevRect = prevPageButton(); if(!prevRect.empty()) { arx_assert(prevPage != NULL); EERIEDrawBitmap2(prevRect.left, prevRect.top, prevRect.width(), prevRect.height(), z, prevPage, Color::white); } // Draw the "next page" button Rectf nextRect = nextPageButton(); if(!nextRect.empty()) { arx_assert(nextPage != NULL); EERIEDrawBitmap2(nextRect.left, nextRect.top, nextRect.width(), nextRect.height(), z, nextPage, Color::white); } Font * font = hFontInGameNote; // Draw the left page { ARX_UNICODE_DrawTextInRect( font, _area.left + _textArea.left, _area.top + _textArea.top, _area.left + _textArea.right, pages[_page], Color::none ); } // Draw the right page if(_page + 1 < pages.size()) { ARX_UNICODE_DrawTextInRect( font, _area.left + _textArea.right + _pageSpacing, _area.top + _textArea.top, _area.left + _textArea.right + _pageSpacing + _textArea.width(), pages[_page + 1], Color::none ); } }