diff options
author | crupest <crupest@outlook.com> | 2023-10-06 20:55:42 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-10-06 20:55:42 +0800 |
commit | 538616817a749642836ad3b2faff16706500602e (patch) | |
tree | 4c1f00d653e7b339a4fbd505cd686993589c2c8c /demos/Graphics/DrawCircle | |
parent | ded4428d7286925db1f5ab9f18f549c85033839d (diff) | |
download | cru-538616817a749642836ad3b2faff16706500602e.tar.gz cru-538616817a749642836ad3b2faff16706500602e.tar.bz2 cru-538616817a749642836ad3b2faff16706500602e.zip |
...
Diffstat (limited to 'demos/Graphics/DrawCircle')
-rw-r--r-- | demos/Graphics/DrawCircle/CMakeLists.txt | 5 | ||||
-rw-r--r-- | demos/Graphics/DrawCircle/CairoMain.cpp | 12 | ||||
-rw-r--r-- | demos/Graphics/DrawCircle/DrawCircle.cpp | 29 | ||||
-rw-r--r-- | demos/Graphics/DrawCircle/DrawCircle.h | 7 | ||||
-rw-r--r-- | demos/Graphics/DrawCircle/PlatformMain.cpp | 12 |
5 files changed, 65 insertions, 0 deletions
diff --git a/demos/Graphics/DrawCircle/CMakeLists.txt b/demos/Graphics/DrawCircle/CMakeLists.txt new file mode 100644 index 00000000..da6611ef --- /dev/null +++ b/demos/Graphics/DrawCircle/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(CruDemoGraphicsDrawCircle DrawCircle.cpp PlatformMain.cpp) +add_executable(CruDemoGraphicsDrawCircleCairo DrawCircle.cpp CairoMain.cpp) + +target_link_libraries(CruDemoGraphicsDrawCircle PRIVATE CruDemoBase) +target_link_libraries(CruDemoGraphicsDrawCircleCairo PRIVATE CruDemoBase CruPlatformGraphicsCairo) diff --git a/demos/Graphics/DrawCircle/CairoMain.cpp b/demos/Graphics/DrawCircle/CairoMain.cpp new file mode 100644 index 00000000..35d6840b --- /dev/null +++ b/demos/Graphics/DrawCircle/CairoMain.cpp @@ -0,0 +1,12 @@ +#include "cru/platform/graphics/cairo/CairoGraphicsFactory.h" + +#include "DrawCircle.h" + +int main() { + std::unique_ptr<cru::platform::graphics::IGraphicsFactory> graphics_factory( + new cru::platform::graphics::cairo::CairoGraphicsFactory()); + + cru::demos::graphics::DrawCircle(graphics_factory.get()); + + return 0; +} diff --git a/demos/Graphics/DrawCircle/DrawCircle.cpp b/demos/Graphics/DrawCircle/DrawCircle.cpp new file mode 100644 index 00000000..aa73d44c --- /dev/null +++ b/demos/Graphics/DrawCircle/DrawCircle.cpp @@ -0,0 +1,29 @@ +#include "cru/common/io/CFileStream.h" +#include "cru/platform/Color.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/graphics/ImageFactory.h" +#include "cru/platform/graphics/Painter.h" + +#include <memory> + +namespace cru::demos::graphics { + void DrawCircle(platform::graphics::IGraphicsFactory* graphics_factory) { + + auto image = graphics_factory->GetImageFactory()->CreateBitmap(500, 500); + + { + auto brush = + graphics_factory->CreateSolidColorBrush(cru::platform::colors::skyblue); + auto painter = image->CreatePainter(); + painter->FillEllipse(cru::platform::Rect{200, 200, 100, 100}, brush.get()); + painter->EndDraw(); + } + + cru::io::CFileStream file_stream("./test_image.png", "w"); + + graphics_factory->GetImageFactory()->EncodeToStream( + image.get(), &file_stream, cru::platform::graphics::ImageFormat::Png, + 1.0f); + } +} + diff --git a/demos/Graphics/DrawCircle/DrawCircle.h b/demos/Graphics/DrawCircle/DrawCircle.h new file mode 100644 index 00000000..8e14dc84 --- /dev/null +++ b/demos/Graphics/DrawCircle/DrawCircle.h @@ -0,0 +1,7 @@ +#pragma once +#include "cru/platform/graphics/Factory.h" + +namespace cru::demos::graphics { + void DrawCircle(platform::graphics::IGraphicsFactory* graphics_factory); +} + diff --git a/demos/Graphics/DrawCircle/PlatformMain.cpp b/demos/Graphics/DrawCircle/PlatformMain.cpp new file mode 100644 index 00000000..3da1ec89 --- /dev/null +++ b/demos/Graphics/DrawCircle/PlatformMain.cpp @@ -0,0 +1,12 @@ +#include "cru/platform/bootstrap/Bootstrap.h" + +#include "DrawCircle.h" + +int main() { + std::unique_ptr<cru::platform::graphics::IGraphicsFactory> graphics_factory( + cru::platform::bootstrap::CreateGraphicsFactory()); + + cru::demos::graphics::DrawCircle(graphics_factory.get()); + + return 0; +} |