diff options
author | crupest <crupest@outlook.com> | 2022-05-08 21:36:57 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-05-08 21:36:57 +0800 |
commit | 195007d4f00dd2c04a0f2859a8bfff7632a45530 (patch) | |
tree | 2f12a344a5d4fc50f18946dec988cdd50ad88069 /demos | |
parent | a1bbc5da1fb0ae4842a54d89136a784832a76978 (diff) | |
download | cru-195007d4f00dd2c04a0f2859a8bfff7632a45530.tar.gz cru-195007d4f00dd2c04a0f2859a8bfff7632a45530.tar.bz2 cru-195007d4f00dd2c04a0f2859a8bfff7632a45530.zip |
...
Diffstat (limited to 'demos')
-rw-r--r-- | demos/CMakeLists.txt | 4 | ||||
-rw-r--r-- | demos/graphics/CMakeLists.txt | 3 | ||||
-rw-r--r-- | demos/graphics/DrawCircle.cpp | 34 |
3 files changed, 41 insertions, 0 deletions
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 <memory> + +int main() { + std::unique_ptr<cru::platform::graphics::IGraphicsFactory> 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; +} |