From 195007d4f00dd2c04a0f2859a8bfff7632a45530 Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 8 May 2022 21:36:57 +0800 Subject: ... --- demos/CMakeLists.txt | 4 ++++ demos/graphics/CMakeLists.txt | 3 +++ demos/graphics/DrawCircle.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 demos/graphics/CMakeLists.txt create mode 100644 demos/graphics/DrawCircle.cpp (limited to 'demos') diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index f2f781bd..f6dd20c3 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -3,12 +3,16 @@ add_library(cru_demo_base INTERFACE) target_link_libraries(cru_demo_base INTERFACE cru_platform_bootstrap) if(WIN32) + add_subdirectory(graphics) + add_subdirectory(main) add_subdirectory(scroll_view) add_subdirectory(input_method) add_subdirectory(svg_path) elseif(APPLE) + add_subdirectory(graphics) + add_subdirectory(main) add_subdirectory(scroll_view) diff --git a/demos/graphics/CMakeLists.txt b/demos/graphics/CMakeLists.txt new file mode 100644 index 00000000..2ecd88bc --- /dev/null +++ b/demos/graphics/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(cru_demo_graphics_draw_circle DrawCircle.cpp) + +target_link_libraries(cru_demo_graphics_draw_circle PRIVATE cru_demo_base) diff --git a/demos/graphics/DrawCircle.cpp b/demos/graphics/DrawCircle.cpp new file mode 100644 index 00000000..9f1eb253 --- /dev/null +++ b/demos/graphics/DrawCircle.cpp @@ -0,0 +1,34 @@ +#include "cru/common/io/FileStream.h" +#include "cru/common/io/OpenFileFlag.h" +#include "cru/platform/Color.h" +#include "cru/platform/bootstrap/Bootstrap.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/graphics/ImageFactory.h" +#include "cru/platform/graphics/Painter.h" + +#include + +int main() { + std::unique_ptr graphics_factory( + cru::platform::bootstrap::CreateGraphicsFactory()); + + auto image = graphics_factory->GetImageFactory()->CreateBitmap(500, 500); + + { + auto brush = + graphics_factory->CreateSolidColorBrush(cru::platform::colors::black); + auto painter = image->CreatePainter(); + painter->FillEllipse(cru::platform::Rect{200, 200, 100, 100}, brush.get()); + painter->EndDraw(); + } + + cru::io::FileStream file_stream( + u"./test_image.png", + cru::io::OpenFileFlags::Write | cru::io::OpenFileFlags::Create); + + graphics_factory->GetImageFactory()->EncodeToStream( + image.get(), &file_stream, cru::platform::graphics::ImageFormat::Png, + 1.0f); + + return 0; +} -- cgit v1.2.3