diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 9ee49bc4..c67e8922 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -113,6 +113,10 @@ void Renderer::drawLine(Line* line) const { } void Renderer::drawRectangle(Rect* rectangle) const { + float x = rectangle->getPosition().x; + float y = rectangle->getPosition().y; + float width = rectangle->getWidth(); + float height = rectangle->getHeight(); mColor fill_color = rectangle->getFillColor(); mColor outline_color = rectangle->getOutlineColor(); @@ -124,12 +128,21 @@ void Renderer::drawRectangle(Rect* rectangle) const { Gdiplus::Matrix original; graphics.GetTransform(&original); applyTransform(rectangle->getTransforms()); - graphics.FillRectangle(&RectFill, rectangle->getPosition().x, - rectangle->getPosition().y, rectangle->getWidth(), - rectangle->getHeight()); - graphics.DrawRectangle(&RectOutline, rectangle->getPosition().x, - rectangle->getPosition().y, rectangle->getWidth(), - rectangle->getHeight()); + if (rectangle->getRadius().x != 0 || rectangle->getRadius().y != 0) { + float dx = rectangle->getRadius().x * 2; + float dy = rectangle->getRadius().y * 2; + Gdiplus::GraphicsPath path; + path.AddArc(x, y, dx, dy, 180, 90); + path.AddArc(x + width - dx, y, dx, dy, 270, 90); + path.AddArc(x + width - dx, y + height - dy, dx, dy, 0, 90); + path.AddArc(x, y + height - dy, dx, dy, 90, 90); + path.CloseFigure(); + graphics.FillPath(&RectFill, &path); + graphics.DrawPath(&RectOutline, &path); + } else { + graphics.FillRectangle(&RectFill, x, y, width, height); + graphics.DrawRectangle(&RectOutline, x, y, width, height); + } graphics.SetTransform(&original); } diff --git a/src/main.cpp b/src/main.cpp index 38d4d9bb..14620855 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,21 +11,21 @@ using namespace rapidxml; -LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + +Parser* parser = nullptr; void OnPaint(HDC hdc, const std::string& filePath) { Gdiplus::Graphics graphics(hdc); - - Parser* parser = Parser::getInstance(filePath); + if (!parser) { + parser = Parser::getInstance(filePath); + } Renderer* renderer = Renderer::getInstance(graphics); SVGElement* root = parser->getRoot(); Group* group = dynamic_cast< Group* >(root); group->render(*renderer); - delete parser; } -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); - INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow) { HWND hWnd; MSG msg; @@ -69,6 +69,7 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow) { DispatchMessage(&msg); } + if (parser) delete parser; Gdiplus::GdiplusShutdown(gdiplusToken); return msg.wParam; } @@ -77,14 +78,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; - std::string filePath = ""; + std::string filePath; + if (__argc > 1) { + filePath = __argv[1]; + } switch (message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); - if (__argc > 1) { - filePath = __argv[1]; - } OnPaint(hdc, filePath); EndPaint(hWnd, &ps); return 0;