From 34a64e6ffefaab007578932ddbab931a25f1d56e Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 15 May 2022 14:15:31 +0800 Subject: ... --- demos/CMakeLists.txt | 16 ++-- demos/InputMethod/CMakeLists.txt | 12 +++ demos/InputMethod/main.cpp | 149 ++++++++++++++++++++++++++++++++++++++ demos/ScrollView/CMakeLists.txt | 12 +++ demos/ScrollView/main.cpp | 87 ++++++++++++++++++++++ demos/SvgPath/CMakeLists.txt | 12 +++ demos/SvgPath/main.cpp | 48 ++++++++++++ demos/graphics/CMakeLists.txt | 2 +- demos/input_method/CMakeLists.txt | 12 --- demos/input_method/main.cpp | 149 -------------------------------------- demos/main/CMakeLists.txt | 2 +- demos/scroll_view/CMakeLists.txt | 12 --- demos/scroll_view/main.cpp | 87 ---------------------- demos/svg_path/CMakeLists.txt | 12 --- demos/svg_path/main.cpp | 48 ------------ 15 files changed, 330 insertions(+), 330 deletions(-) create mode 100644 demos/InputMethod/CMakeLists.txt create mode 100644 demos/InputMethod/main.cpp create mode 100644 demos/ScrollView/CMakeLists.txt create mode 100644 demos/ScrollView/main.cpp create mode 100644 demos/SvgPath/CMakeLists.txt create mode 100644 demos/SvgPath/main.cpp delete mode 100644 demos/input_method/CMakeLists.txt delete mode 100644 demos/input_method/main.cpp delete mode 100644 demos/scroll_view/CMakeLists.txt delete mode 100644 demos/scroll_view/main.cpp delete mode 100644 demos/svg_path/CMakeLists.txt delete mode 100644 demos/svg_path/main.cpp (limited to 'demos') diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index 220fbeae..9b8f0fec 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -1,23 +1,23 @@ -add_library(cru_demo_base INTERFACE) +add_library(CruDemoBase INTERFACE) -target_link_libraries(cru_demo_base INTERFACE CruPlatformBootstrap) +target_link_libraries(CruDemoBase INTERFACE CruPlatformBootstrap) if(WIN32) add_subdirectory(graphics) add_subdirectory(main) - add_subdirectory(scroll_view) + add_subdirectory(ScrollView) - add_subdirectory(input_method) - add_subdirectory(svg_path) + add_subdirectory(InputMethod) + add_subdirectory(SvgPath) elseif(APPLE) add_subdirectory(graphics) add_subdirectory(main) - add_subdirectory(scroll_view) + add_subdirectory(ScrollView) - add_subdirectory(input_method) - add_subdirectory(svg_path) + add_subdirectory(InputMethod) + add_subdirectory(SvgPath) elseif(UNIX) add_subdirectory(xcb) endif() diff --git a/demos/InputMethod/CMakeLists.txt b/demos/InputMethod/CMakeLists.txt new file mode 100644 index 00000000..8ceeaec9 --- /dev/null +++ b/demos/InputMethod/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(CruDemoInputMethod main.cpp) + +if(APPLE) + set_target_properties(CruDemoInputMethod PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_BUNDLE_NAME demo-input-method + MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-input-method + ) +endif() + +target_link_libraries(CruDemoInputMethod PRIVATE CruDemoBase) + diff --git a/demos/InputMethod/main.cpp b/demos/InputMethod/main.cpp new file mode 100644 index 00000000..abbbed2c --- /dev/null +++ b/demos/InputMethod/main.cpp @@ -0,0 +1,149 @@ +#include "cru/platform/Color.h" +#include "cru/platform/bootstrap/Bootstrap.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/graphics/Font.h" +#include "cru/platform/graphics/Painter.h" +#include "cru/platform/gui/InputMethod.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/platform/gui/Window.h" + +int main() { + using namespace cru; + using namespace cru::platform; + using namespace cru::platform::graphics; + using namespace cru::platform::gui; + + IUiApplication* application = bootstrap::CreateUiApplication(); + + auto graphics_factory = application->GetGraphicsFactory(); + + auto window = application->CreateWindow(); + + auto input_method_context = window->GetInputMethodContext(); + + auto brush = graphics_factory->CreateSolidColorBrush(); + brush->SetColor(colors::black); + + auto odd_clause_brush = graphics_factory->CreateSolidColorBrush(); + odd_clause_brush->SetColor(colors::yellow); + auto even_clause_brush = graphics_factory->CreateSolidColorBrush(); + even_clause_brush->SetColor(colors::green); + auto target_clause_brush = graphics_factory->CreateSolidColorBrush(); + target_clause_brush->SetColor(colors::blue); + + std::shared_ptr font = graphics_factory->CreateFont(String{}, 30); + + float window_width = 10000; + + auto prompt_text_layout = + graphics_factory->CreateTextLayout(font, + u"Ctrl+1: Enable IME\n" + u"Ctrl+2: Disable IME\n" + u"Ctrl+3: Complete composition.\n" + u"Ctrl+4: Cancel composition."); + + std::optional optional_composition_text; + String committed_text; + + window->ResizeEvent()->AddHandler( + [&prompt_text_layout, &window_width](const Size& size) { + prompt_text_layout->SetMaxWidth(size.width); + window_width = size.width; + }); + + window->PaintEvent()->AddHandler([&](auto) { + auto painter = window->BeginPaint(); + painter->Clear(colors::white); + + painter->DrawText(Point{}, prompt_text_layout.get(), brush.get()); + + const auto anchor_y = prompt_text_layout->GetTextBounds().height; + + auto text_layout = graphics_factory->CreateTextLayout( + font, committed_text + (optional_composition_text + ? optional_composition_text->text + : u"")); + text_layout->SetMaxWidth(window_width); + + if (optional_composition_text) { + const auto& composition_text = *optional_composition_text; + + for (int i = 0; i < static_cast(composition_text.clauses.size()); + i++) { + const auto& clause = composition_text.clauses[i]; + auto rects = text_layout->TextRangeRect(TextRange::FromTwoSides( + clause.start, clause.end, committed_text.size())); + const auto& b = clause.target + ? target_clause_brush + : (i % 2 ? odd_clause_brush : even_clause_brush); + for (auto& rect : rects) { + rect.top += anchor_y; + painter->FillRectangle(rect, b.get()); + } + } + } + + painter->DrawText(Point{0, anchor_y}, text_layout.get(), brush.get()); + + if (optional_composition_text) { + const auto& composition_text = *optional_composition_text; + + const auto cursor_pos = composition_text.selection.position + + gsl::narrow_cast(committed_text.size()); + + const auto cursor_lefttop = + text_layout->TextSinglePoint(cursor_pos, false); + + painter->FillRectangle( + Rect{cursor_lefttop.left, cursor_lefttop.top + anchor_y, 3, + cursor_lefttop.height}, + brush.get()); + } + + painter->EndDraw(); + }); + + window->KeyDownEvent()->AddHandler( + [&input_method_context](const NativeKeyEventArgs& args) { + if (args.modifier & KeyModifiers::ctrl) { + switch (args.key) { + case KeyCode::N1: + input_method_context->EnableIME(); + break; + case KeyCode::N2: + input_method_context->DisableIME(); + break; + case KeyCode::N3: + input_method_context->CompleteComposition(); + break; + case KeyCode::N4: + input_method_context->CancelComposition(); + break; + default: + break; + } + } + }); + + input_method_context->TextEvent()->AddHandler( + [window, &committed_text](const StringView& c) { + committed_text += c; + window->RequestRepaint(); + }); + + input_method_context->CompositionEvent()->AddHandler( + [window, &input_method_context, &optional_composition_text](auto) { + optional_composition_text = input_method_context->GetCompositionText(); + window->RequestRepaint(); + }); + + input_method_context->CompositionEndEvent()->AddHandler( + [window, &optional_composition_text](auto) { + optional_composition_text = std::nullopt; + window->RequestRepaint(); + }); + + window->SetVisibility(WindowVisibilityType::Show); + + return application->Run(); +} diff --git a/demos/ScrollView/CMakeLists.txt b/demos/ScrollView/CMakeLists.txt new file mode 100644 index 00000000..8b34f5d8 --- /dev/null +++ b/demos/ScrollView/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(CruDemoScrollView main.cpp) + +if(APPLE) + set_target_properties(CruDemoScrollView PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-scroll-view + MACOSX_BUNDLE_BUNDLE_NAME demo-scroll-view + ) +endif() + +target_add_resources(CruDemoScrollView cru/ui) +target_link_libraries(CruDemoScrollView PRIVATE CruDemoBase CruUi) diff --git a/demos/ScrollView/main.cpp b/demos/ScrollView/main.cpp new file mode 100644 index 00000000..b049a408 --- /dev/null +++ b/demos/ScrollView/main.cpp @@ -0,0 +1,87 @@ +#include "cru/platform/bootstrap/Bootstrap.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/platform/gui/Window.h" +#include "cru/ui/controls/ScrollView.h" +#include "cru/ui/controls/TextBlock.h" +#include "cru/ui/controls/Window.h" + +using cru::platform::gui::IUiApplication; +using cru::ui::controls::ScrollView; +using cru::ui::controls::TextBlock; +using cru::ui::controls::Window; + +int main() { + std::unique_ptr application( + cru::platform::bootstrap::CreateUiApplication()); + + Window window; + ScrollView scroll_view; + window.AddChild(&scroll_view); + + TextBlock text_block( + uR"([Verse 1] +The snow glows white on the mountain tonight +Not a footprint to be seen +A kingdom of isolation +And it looks like I'm the queen +The wind is howling like this swirling storm inside +Couldn't keep it in, Heaven knows I tried + +[Pre-Chorus] +Don't let them in, don't let them see +Be the good girl you always have to be +Conceal, don't feel, don't let them know +Well, now they know + +[Chorus] +Let it go, let it go +Can't hold it back anymore +Let it go, let it go +Turn away and slam the door +I don't care what they're going to say +Let the storm rage on +The cold never bothered me anyway + +[Verse 2] +It's funny how some distance +Makes everything seem small +And the fears that once controlled me +Can't get to me at all + +[Pre-Chorus] +It's time to see what I can do +To test the limits and break through +No right, no wrong, no rules for me +I'm free + +[Chorus] +Let it go, let it go +I'm one with the wind and sky +Let it go, let it go +You'll never see me cry +Here I stand, and here I'll stay +Let the storm rage on... + +[Bridge] +My power flurries through the air into the ground +My soul is spiraling in frozen fractals all around +And one thought crystallizes like an icy blast: +I'm never going back, the past is in the past! + +[Chorus] +Let it go, let it go +And I'll rise like the break of dawn +Let it go, let it go +That perfect girl is gone +Here I stand in the light of day +Let the storm rage on! +The cold never bothered me anyway)", + true); + + scroll_view.SetChild(&text_block); + + window.GetWindowHost()->GetNativeWindow()->SetVisibility( + cru::platform::gui::WindowVisibilityType::Show); + + return application->Run(); +} diff --git a/demos/SvgPath/CMakeLists.txt b/demos/SvgPath/CMakeLists.txt new file mode 100644 index 00000000..34120111 --- /dev/null +++ b/demos/SvgPath/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(CruDemoSvgPath main.cpp) + +if(APPLE) + set_target_properties(CruDemoSvgPath PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_BUNDLE_NAME cru-demo-svg-path + MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.demo-svg-path + ) +endif() + +target_link_libraries(CruDemoSvgPath PRIVATE CruDemoBase) + diff --git a/demos/SvgPath/main.cpp b/demos/SvgPath/main.cpp new file mode 100644 index 00000000..87c410e9 --- /dev/null +++ b/demos/SvgPath/main.cpp @@ -0,0 +1,48 @@ +#include "cru/platform/Color.h" +#include "cru/platform/bootstrap/Bootstrap.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/graphics/Font.h" +#include "cru/platform/graphics/Painter.h" +#include "cru/platform/gui/InputMethod.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/platform/gui/Window.h" + +int main() { + using namespace cru; + using namespace cru::platform; + using namespace cru::platform::graphics; + using namespace cru::platform::gui; + + IUiApplication* application = bootstrap::CreateUiApplication(); + + auto graphics_factory = application->GetGraphicsFactory(); + + auto window = application->CreateWindow(); + + auto brush = graphics_factory->CreateSolidColorBrush(colors::black); + + auto create_geometry = [graphics_factory](StringView path_d) { + auto geometry_builder = graphics_factory->CreateGeometryBuilder(); + geometry_builder->ParseAndApplySvgPathData(path_d); + return geometry_builder->Build(); + }; + + auto geometry = create_geometry( + 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 + )"); + + window->PaintEvent()->AddHandler([&](auto) { + auto painter = window->BeginPaint(); + painter->PushState(); + painter->ConcatTransform(Matrix::Scale(10, 10)); + painter->FillGeometry(geometry.get(), brush.get()); + painter->PopState(); + painter->EndDraw(); + }); + + window->SetVisibility(WindowVisibilityType::Show); + + return application->Run(); +} diff --git a/demos/graphics/CMakeLists.txt b/demos/graphics/CMakeLists.txt index 3a249b1d..b290ba13 100644 --- a/demos/graphics/CMakeLists.txt +++ b/demos/graphics/CMakeLists.txt @@ -1,3 +1,3 @@ add_executable(CruDemoGraphicsDrawCircle DrawCircle.cpp) -target_link_libraries(CruDemoGraphicsDrawCircle PRIVATE cru_demo_base) +target_link_libraries(CruDemoGraphicsDrawCircle PRIVATE CruDemoBase) diff --git a/demos/input_method/CMakeLists.txt b/demos/input_method/CMakeLists.txt deleted file mode 100644 index 7c19c4dd..00000000 --- a/demos/input_method/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_executable(CruDemoInputMethod main.cpp) - -if(APPLE) - set_target_properties(CruDemoInputMethod PROPERTIES - MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_BUNDLE_NAME demo-input-method - MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-input-method - ) -endif() - -target_link_libraries(CruDemoInputMethod PRIVATE cru_demo_base) - diff --git a/demos/input_method/main.cpp b/demos/input_method/main.cpp deleted file mode 100644 index abbbed2c..00000000 --- a/demos/input_method/main.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "cru/platform/Color.h" -#include "cru/platform/bootstrap/Bootstrap.h" -#include "cru/platform/graphics/Factory.h" -#include "cru/platform/graphics/Font.h" -#include "cru/platform/graphics/Painter.h" -#include "cru/platform/gui/InputMethod.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/platform/gui/Window.h" - -int main() { - using namespace cru; - using namespace cru::platform; - using namespace cru::platform::graphics; - using namespace cru::platform::gui; - - IUiApplication* application = bootstrap::CreateUiApplication(); - - auto graphics_factory = application->GetGraphicsFactory(); - - auto window = application->CreateWindow(); - - auto input_method_context = window->GetInputMethodContext(); - - auto brush = graphics_factory->CreateSolidColorBrush(); - brush->SetColor(colors::black); - - auto odd_clause_brush = graphics_factory->CreateSolidColorBrush(); - odd_clause_brush->SetColor(colors::yellow); - auto even_clause_brush = graphics_factory->CreateSolidColorBrush(); - even_clause_brush->SetColor(colors::green); - auto target_clause_brush = graphics_factory->CreateSolidColorBrush(); - target_clause_brush->SetColor(colors::blue); - - std::shared_ptr font = graphics_factory->CreateFont(String{}, 30); - - float window_width = 10000; - - auto prompt_text_layout = - graphics_factory->CreateTextLayout(font, - u"Ctrl+1: Enable IME\n" - u"Ctrl+2: Disable IME\n" - u"Ctrl+3: Complete composition.\n" - u"Ctrl+4: Cancel composition."); - - std::optional optional_composition_text; - String committed_text; - - window->ResizeEvent()->AddHandler( - [&prompt_text_layout, &window_width](const Size& size) { - prompt_text_layout->SetMaxWidth(size.width); - window_width = size.width; - }); - - window->PaintEvent()->AddHandler([&](auto) { - auto painter = window->BeginPaint(); - painter->Clear(colors::white); - - painter->DrawText(Point{}, prompt_text_layout.get(), brush.get()); - - const auto anchor_y = prompt_text_layout->GetTextBounds().height; - - auto text_layout = graphics_factory->CreateTextLayout( - font, committed_text + (optional_composition_text - ? optional_composition_text->text - : u"")); - text_layout->SetMaxWidth(window_width); - - if (optional_composition_text) { - const auto& composition_text = *optional_composition_text; - - for (int i = 0; i < static_cast(composition_text.clauses.size()); - i++) { - const auto& clause = composition_text.clauses[i]; - auto rects = text_layout->TextRangeRect(TextRange::FromTwoSides( - clause.start, clause.end, committed_text.size())); - const auto& b = clause.target - ? target_clause_brush - : (i % 2 ? odd_clause_brush : even_clause_brush); - for (auto& rect : rects) { - rect.top += anchor_y; - painter->FillRectangle(rect, b.get()); - } - } - } - - painter->DrawText(Point{0, anchor_y}, text_layout.get(), brush.get()); - - if (optional_composition_text) { - const auto& composition_text = *optional_composition_text; - - const auto cursor_pos = composition_text.selection.position + - gsl::narrow_cast(committed_text.size()); - - const auto cursor_lefttop = - text_layout->TextSinglePoint(cursor_pos, false); - - painter->FillRectangle( - Rect{cursor_lefttop.left, cursor_lefttop.top + anchor_y, 3, - cursor_lefttop.height}, - brush.get()); - } - - painter->EndDraw(); - }); - - window->KeyDownEvent()->AddHandler( - [&input_method_context](const NativeKeyEventArgs& args) { - if (args.modifier & KeyModifiers::ctrl) { - switch (args.key) { - case KeyCode::N1: - input_method_context->EnableIME(); - break; - case KeyCode::N2: - input_method_context->DisableIME(); - break; - case KeyCode::N3: - input_method_context->CompleteComposition(); - break; - case KeyCode::N4: - input_method_context->CancelComposition(); - break; - default: - break; - } - } - }); - - input_method_context->TextEvent()->AddHandler( - [window, &committed_text](const StringView& c) { - committed_text += c; - window->RequestRepaint(); - }); - - input_method_context->CompositionEvent()->AddHandler( - [window, &input_method_context, &optional_composition_text](auto) { - optional_composition_text = input_method_context->GetCompositionText(); - window->RequestRepaint(); - }); - - input_method_context->CompositionEndEvent()->AddHandler( - [window, &optional_composition_text](auto) { - optional_composition_text = std::nullopt; - window->RequestRepaint(); - }); - - window->SetVisibility(WindowVisibilityType::Show); - - return application->Run(); -} diff --git a/demos/main/CMakeLists.txt b/demos/main/CMakeLists.txt index 721ace19..2da90405 100644 --- a/demos/main/CMakeLists.txt +++ b/demos/main/CMakeLists.txt @@ -9,4 +9,4 @@ if(APPLE) endif() target_add_resources(CruDemoMain cru/ui) -target_link_libraries(CruDemoMain PRIVATE cru_demo_base CruUi) +target_link_libraries(CruDemoMain PRIVATE CruDemoBase CruUi) diff --git a/demos/scroll_view/CMakeLists.txt b/demos/scroll_view/CMakeLists.txt deleted file mode 100644 index 0b9196fe..00000000 --- a/demos/scroll_view/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_executable(CruDemoScrollView main.cpp) - -if(APPLE) - set_target_properties(CruDemoScrollView PROPERTIES - MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-scroll-view - MACOSX_BUNDLE_BUNDLE_NAME demo-scroll-view - ) -endif() - -target_add_resources(CruDemoScrollView cru/ui) -target_link_libraries(CruDemoScrollView PRIVATE cru_demo_base CruUi) diff --git a/demos/scroll_view/main.cpp b/demos/scroll_view/main.cpp deleted file mode 100644 index b049a408..00000000 --- a/demos/scroll_view/main.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "cru/platform/bootstrap/Bootstrap.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/platform/gui/Window.h" -#include "cru/ui/controls/ScrollView.h" -#include "cru/ui/controls/TextBlock.h" -#include "cru/ui/controls/Window.h" - -using cru::platform::gui::IUiApplication; -using cru::ui::controls::ScrollView; -using cru::ui::controls::TextBlock; -using cru::ui::controls::Window; - -int main() { - std::unique_ptr application( - cru::platform::bootstrap::CreateUiApplication()); - - Window window; - ScrollView scroll_view; - window.AddChild(&scroll_view); - - TextBlock text_block( - uR"([Verse 1] -The snow glows white on the mountain tonight -Not a footprint to be seen -A kingdom of isolation -And it looks like I'm the queen -The wind is howling like this swirling storm inside -Couldn't keep it in, Heaven knows I tried - -[Pre-Chorus] -Don't let them in, don't let them see -Be the good girl you always have to be -Conceal, don't feel, don't let them know -Well, now they know - -[Chorus] -Let it go, let it go -Can't hold it back anymore -Let it go, let it go -Turn away and slam the door -I don't care what they're going to say -Let the storm rage on -The cold never bothered me anyway - -[Verse 2] -It's funny how some distance -Makes everything seem small -And the fears that once controlled me -Can't get to me at all - -[Pre-Chorus] -It's time to see what I can do -To test the limits and break through -No right, no wrong, no rules for me -I'm free - -[Chorus] -Let it go, let it go -I'm one with the wind and sky -Let it go, let it go -You'll never see me cry -Here I stand, and here I'll stay -Let the storm rage on... - -[Bridge] -My power flurries through the air into the ground -My soul is spiraling in frozen fractals all around -And one thought crystallizes like an icy blast: -I'm never going back, the past is in the past! - -[Chorus] -Let it go, let it go -And I'll rise like the break of dawn -Let it go, let it go -That perfect girl is gone -Here I stand in the light of day -Let the storm rage on! -The cold never bothered me anyway)", - true); - - scroll_view.SetChild(&text_block); - - window.GetWindowHost()->GetNativeWindow()->SetVisibility( - cru::platform::gui::WindowVisibilityType::Show); - - return application->Run(); -} diff --git a/demos/svg_path/CMakeLists.txt b/demos/svg_path/CMakeLists.txt deleted file mode 100644 index 5488c6b0..00000000 --- a/demos/svg_path/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_executable(CruDemoSvgPath main.cpp) - -if(APPLE) - set_target_properties(CruDemoSvgPath PROPERTIES - MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_BUNDLE_NAME cru-demo-svg-path - MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.demo-svg-path - ) -endif() - -target_link_libraries(CruDemoSvgPath PRIVATE cru_demo_base) - diff --git a/demos/svg_path/main.cpp b/demos/svg_path/main.cpp deleted file mode 100644 index 87c410e9..00000000 --- a/demos/svg_path/main.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "cru/platform/Color.h" -#include "cru/platform/bootstrap/Bootstrap.h" -#include "cru/platform/graphics/Factory.h" -#include "cru/platform/graphics/Font.h" -#include "cru/platform/graphics/Painter.h" -#include "cru/platform/gui/InputMethod.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/platform/gui/Window.h" - -int main() { - using namespace cru; - using namespace cru::platform; - using namespace cru::platform::graphics; - using namespace cru::platform::gui; - - IUiApplication* application = bootstrap::CreateUiApplication(); - - auto graphics_factory = application->GetGraphicsFactory(); - - auto window = application->CreateWindow(); - - auto brush = graphics_factory->CreateSolidColorBrush(colors::black); - - auto create_geometry = [graphics_factory](StringView path_d) { - auto geometry_builder = graphics_factory->CreateGeometryBuilder(); - geometry_builder->ParseAndApplySvgPathData(path_d); - return geometry_builder->Build(); - }; - - auto geometry = create_geometry( - 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 - )"); - - window->PaintEvent()->AddHandler([&](auto) { - auto painter = window->BeginPaint(); - painter->PushState(); - painter->ConcatTransform(Matrix::Scale(10, 10)); - painter->FillGeometry(geometry.get(), brush.get()); - painter->PopState(); - painter->EndDraw(); - }); - - window->SetVisibility(WindowVisibilityType::Show); - - return application->Run(); -} -- cgit v1.2.3