From f76b47291ac164ec0169f721dab5b1b0fe016322 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Tue, 23 Sep 2025 23:23:38 +0800 Subject: Organize platform demo. --- demos/CMakeLists.txt | 2 +- demos/Graphics/CMakeLists.txt | 8 ------- demos/Graphics/DrawCircle.cpp | 31 ------------------------- demos/Graphics/SvgPath.cpp | 41 ---------------------------------- demos/platform/CMakeLists.txt | 2 ++ demos/platform/graphics/CMakeLists.txt | 8 +++++++ demos/platform/graphics/DrawCircle.cpp | 31 +++++++++++++++++++++++++ demos/platform/graphics/SvgPath.cpp | 41 ++++++++++++++++++++++++++++++++++ demos/platform/gui/CMakeLists.txt | 5 +++++ demos/platform/gui/EmptyWindow.cpp | 19 ++++++++++++++++ 10 files changed, 107 insertions(+), 81 deletions(-) delete mode 100644 demos/Graphics/CMakeLists.txt delete mode 100644 demos/Graphics/DrawCircle.cpp delete mode 100644 demos/Graphics/SvgPath.cpp create mode 100644 demos/platform/CMakeLists.txt create mode 100644 demos/platform/graphics/CMakeLists.txt create mode 100644 demos/platform/graphics/DrawCircle.cpp create mode 100644 demos/platform/graphics/SvgPath.cpp create mode 100644 demos/platform/gui/CMakeLists.txt create mode 100644 demos/platform/gui/EmptyWindow.cpp (limited to 'demos') diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index 665f359a..46eda9c4 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -2,7 +2,7 @@ add_library(CruDemoBase INTERFACE) target_link_libraries(CruDemoBase INTERFACE CruPlatformBootstrap) -add_subdirectory(Graphics) +add_subdirectory(platform) if(WIN32) add_subdirectory(main) diff --git a/demos/Graphics/CMakeLists.txt b/demos/Graphics/CMakeLists.txt deleted file mode 100644 index 64982a19..00000000 --- a/demos/Graphics/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -add_library(CruDemoGraphicsBase INTERFACE) -target_link_libraries(CruDemoGraphicsBase INTERFACE CruPlatformGraphicsBootstrap) - -add_executable(CruDemoGraphicsDrawCircle DrawCircle.cpp) -target_link_libraries(CruDemoGraphicsDrawCircle PRIVATE CruDemoGraphicsBase) - -add_executable(CruDemoGraphicsSvgPath SvgPath.cpp) -target_link_libraries(CruDemoGraphicsSvgPath PRIVATE CruDemoGraphicsBase) diff --git a/demos/Graphics/DrawCircle.cpp b/demos/Graphics/DrawCircle.cpp deleted file mode 100644 index d3246527..00000000 --- a/demos/Graphics/DrawCircle.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "cru/base/io/CFileStream.h" -#include "cru/platform/Color.h" -#include "cru/platform/bootstrap/GraphicsBootstrap.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::skyblue); - auto painter = image->CreatePainter(); - painter->FillEllipse(cru::platform::Rect{200, 200, 100, 100}, brush.get()); - painter->EndDraw(); - } - - cru::io::CFileStream file_stream("draw-circle-demo.png", "wb"); - - graphics_factory->GetImageFactory()->EncodeToStream( - image.get(), &file_stream, cru::platform::graphics::ImageFormat::Png, - 1.0f); - - return 0; -} diff --git a/demos/Graphics/SvgPath.cpp b/demos/Graphics/SvgPath.cpp deleted file mode 100644 index 332456a8..00000000 --- a/demos/Graphics/SvgPath.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -#include "cru/base/io/CFileStream.h" -#include "cru/platform/Color.h" -#include "cru/platform/Matrix.h" -#include "cru/platform/bootstrap/GraphicsBootstrap.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 brush = - graphics_factory->CreateSolidColorBrush(cru::platform::colors::black); - - auto geometry_builder = graphics_factory->CreateGeometryBuilder(); - geometry_builder->ParseAndApplySvgPathData( - uR"( -M8.5 5.5a.5.5 0 0 0-1 0v3.362l-1.429 2.38a.5.5 0 1 0 .858.515l1.5-2.5A.5.5 0 0 0 8.5 9V5.5z -M6.5 0a.5.5 0 0 0 0 1H7v1.07a7.001 7.001 0 0 0-3.273 12.474l-.602.602a.5.5 0 0 0 .707.708l.746-.746A6.97 6.97 0 0 0 8 16a6.97 6.97 0 0 0 3.422-.892l.746.746a.5.5 0 0 0 .707-.708l-.601-.602A7.001 7.001 0 0 0 9 2.07V1h.5a.5.5 0 0 0 0-1h-3zm1.038 3.018a6.093 6.093 0 0 1 .924 0 6 6 0 1 1-.924 0zM0 3.5c0 .753.333 1.429.86 1.887A8.035 8.035 0 0 1 4.387 1.86 2.5 2.5 0 0 0 0 3.5zM13.5 1c-.753 0-1.429.333-1.887.86a8.035 8.035 0 0 1 3.527 3.527A2.5 2.5 0 0 0 13.5 1z - )"); - auto geometry = geometry_builder->Build(); - - auto image = graphics_factory->GetImageFactory()->CreateBitmap(160, 160); - auto painter = image->CreatePainter(); - - painter->ConcatTransform(cru::platform::Matrix::Scale(10, 10)); - painter->FillGeometry(geometry.get(), brush.get()); - painter->EndDraw(); - - cru::io::CFileStream file_stream("./svg-path-demo.png", "wb"); - - graphics_factory->GetImageFactory()->EncodeToStream( - image.get(), &file_stream, cru::platform::graphics::ImageFormat::Png, - 1.0f); - - return 0; -} diff --git a/demos/platform/CMakeLists.txt b/demos/platform/CMakeLists.txt new file mode 100644 index 00000000..36673acd --- /dev/null +++ b/demos/platform/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(graphics) +add_subdirectory(gui) diff --git a/demos/platform/graphics/CMakeLists.txt b/demos/platform/graphics/CMakeLists.txt new file mode 100644 index 00000000..e2a96c09 --- /dev/null +++ b/demos/platform/graphics/CMakeLists.txt @@ -0,0 +1,8 @@ +add_library(CruDemoPlatformGraphicsBase INTERFACE) +target_link_libraries(CruDemoPlatformGraphicsBase INTERFACE CruPlatformGraphicsBootstrap) + +add_executable(CruDemoPlatformGraphicsDrawCircle DrawCircle.cpp) +target_link_libraries(CruDemoPlatformGraphicsDrawCircle PRIVATE CruDemoPlatformGraphicsBase) + +add_executable(CruDemoPlatformGraphicsSvgPath SvgPath.cpp) +target_link_libraries(CruDemoPlatformGraphicsSvgPath PRIVATE CruDemoPlatformGraphicsBase) diff --git a/demos/platform/graphics/DrawCircle.cpp b/demos/platform/graphics/DrawCircle.cpp new file mode 100644 index 00000000..d3246527 --- /dev/null +++ b/demos/platform/graphics/DrawCircle.cpp @@ -0,0 +1,31 @@ +#include "cru/base/io/CFileStream.h" +#include "cru/platform/Color.h" +#include "cru/platform/bootstrap/GraphicsBootstrap.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::skyblue); + auto painter = image->CreatePainter(); + painter->FillEllipse(cru::platform::Rect{200, 200, 100, 100}, brush.get()); + painter->EndDraw(); + } + + cru::io::CFileStream file_stream("draw-circle-demo.png", "wb"); + + graphics_factory->GetImageFactory()->EncodeToStream( + image.get(), &file_stream, cru::platform::graphics::ImageFormat::Png, + 1.0f); + + return 0; +} diff --git a/demos/platform/graphics/SvgPath.cpp b/demos/platform/graphics/SvgPath.cpp new file mode 100644 index 00000000..332456a8 --- /dev/null +++ b/demos/platform/graphics/SvgPath.cpp @@ -0,0 +1,41 @@ + +#include "cru/base/io/CFileStream.h" +#include "cru/platform/Color.h" +#include "cru/platform/Matrix.h" +#include "cru/platform/bootstrap/GraphicsBootstrap.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 brush = + graphics_factory->CreateSolidColorBrush(cru::platform::colors::black); + + auto geometry_builder = graphics_factory->CreateGeometryBuilder(); + geometry_builder->ParseAndApplySvgPathData( + uR"( +M8.5 5.5a.5.5 0 0 0-1 0v3.362l-1.429 2.38a.5.5 0 1 0 .858.515l1.5-2.5A.5.5 0 0 0 8.5 9V5.5z +M6.5 0a.5.5 0 0 0 0 1H7v1.07a7.001 7.001 0 0 0-3.273 12.474l-.602.602a.5.5 0 0 0 .707.708l.746-.746A6.97 6.97 0 0 0 8 16a6.97 6.97 0 0 0 3.422-.892l.746.746a.5.5 0 0 0 .707-.708l-.601-.602A7.001 7.001 0 0 0 9 2.07V1h.5a.5.5 0 0 0 0-1h-3zm1.038 3.018a6.093 6.093 0 0 1 .924 0 6 6 0 1 1-.924 0zM0 3.5c0 .753.333 1.429.86 1.887A8.035 8.035 0 0 1 4.387 1.86 2.5 2.5 0 0 0 0 3.5zM13.5 1c-.753 0-1.429.333-1.887.86a8.035 8.035 0 0 1 3.527 3.527A2.5 2.5 0 0 0 13.5 1z + )"); + auto geometry = geometry_builder->Build(); + + auto image = graphics_factory->GetImageFactory()->CreateBitmap(160, 160); + auto painter = image->CreatePainter(); + + painter->ConcatTransform(cru::platform::Matrix::Scale(10, 10)); + painter->FillGeometry(geometry.get(), brush.get()); + painter->EndDraw(); + + cru::io::CFileStream file_stream("./svg-path-demo.png", "wb"); + + graphics_factory->GetImageFactory()->EncodeToStream( + image.get(), &file_stream, cru::platform::graphics::ImageFormat::Png, + 1.0f); + + return 0; +} diff --git a/demos/platform/gui/CMakeLists.txt b/demos/platform/gui/CMakeLists.txt new file mode 100644 index 00000000..b179fbc6 --- /dev/null +++ b/demos/platform/gui/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(CruDemoPlatformGuiBase INTERFACE) +target_link_libraries(CruDemoPlatformGuiBase INTERFACE CruPlatformBootstrap) + +add_executable(CruDemoPlatformGuiEmptyWindow EmptyWindow.cpp) +target_link_libraries(CruDemoPlatformGuiEmptyWindow PRIVATE CruDemoPlatformGuiBase) diff --git a/demos/platform/gui/EmptyWindow.cpp b/demos/platform/gui/EmptyWindow.cpp new file mode 100644 index 00000000..83e352af --- /dev/null +++ b/demos/platform/gui/EmptyWindow.cpp @@ -0,0 +1,19 @@ +#include "cru/platform/bootstrap/Bootstrap.h" +#include "cru/platform/gui/Base.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/platform/gui/Window.h" + +using cru::platform::gui::IUiApplication; +using cru::platform::gui::WindowVisibilityType; + +int main() { + std::unique_ptr application( + cru::platform::bootstrap::CreateUiApplication()); + + application->SetQuitOnAllWindowClosed(true); + auto window = application->CreateWindow(); + window->SetVisibility(WindowVisibilityType::Show); + window->SetToForeground(); + + return application->Run(); +} -- cgit v1.2.3