aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-03-24 19:14:19 +0800
committercrupest <crupest@outlook.com>2021-03-24 19:14:19 +0800
commit7f15a1ff9a2007e119798053083a0a87d042990a (patch)
treecb35c01a7eaee867376d959b96c9bbd15df939e5 /include/cru/platform
parent74956951ee663012df0c3fe4ebe29799cb2f7732 (diff)
parent7703063a5816b089483e78ccd74bb9902ccfbea8 (diff)
downloadcru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.gz
cru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.bz2
cru-7f15a1ff9a2007e119798053083a0a87d042990a.zip
Merge branch 'master' of https://github.com/crupest/CruUI
Diffstat (limited to 'include/cru/platform')
-rw-r--r--include/cru/platform/GraphBase.hpp27
-rw-r--r--include/cru/platform/Matrix.hpp5
-rw-r--r--include/cru/platform/graphics/Base.hpp (renamed from include/cru/platform/graph/Base.hpp)2
-rw-r--r--include/cru/platform/graphics/Brush.hpp (renamed from include/cru/platform/graph/Brush.hpp)2
-rw-r--r--include/cru/platform/graphics/Factory.hpp (renamed from include/cru/platform/graph/Factory.hpp)10
-rw-r--r--include/cru/platform/graphics/Font.hpp (renamed from include/cru/platform/graph/Font.hpp)2
-rw-r--r--include/cru/platform/graphics/Geometry.hpp (renamed from include/cru/platform/graph/Geometry.hpp)2
-rw-r--r--include/cru/platform/graphics/Painter.hpp (renamed from include/cru/platform/graph/Painter.hpp)6
-rw-r--r--include/cru/platform/graphics/Resource.hpp (renamed from include/cru/platform/graph/Resource.hpp)2
-rw-r--r--include/cru/platform/graphics/TextLayout.hpp (renamed from include/cru/platform/graph/TextLayout.hpp)6
-rw-r--r--include/cru/platform/graphics/util/Painter.hpp (renamed from include/cru/platform/graph/util/Painter.hpp)6
-rw-r--r--include/cru/platform/gui/Base.hpp (renamed from include/cru/platform/native/Base.hpp)22
-rw-r--r--include/cru/platform/gui/Cursor.hpp (renamed from include/cru/platform/native/Cursor.hpp)7
-rw-r--r--include/cru/platform/gui/DebugFlags.hpp8
-rw-r--r--include/cru/platform/gui/InputMethod.hpp (renamed from include/cru/platform/native/InputMethod.hpp)17
-rw-r--r--include/cru/platform/gui/Keyboard.hpp (renamed from include/cru/platform/native/Keyboard.hpp)12
-rw-r--r--include/cru/platform/gui/UiApplication.hpp135
-rw-r--r--include/cru/platform/gui/Window.hpp (renamed from include/cru/platform/native/Window.hpp)22
-rw-r--r--include/cru/platform/native/UiApplication.hpp58
19 files changed, 229 insertions, 122 deletions
diff --git a/include/cru/platform/GraphBase.hpp b/include/cru/platform/GraphBase.hpp
index 186ee9d0..6bf2736f 100644
--- a/include/cru/platform/GraphBase.hpp
+++ b/include/cru/platform/GraphBase.hpp
@@ -1,9 +1,13 @@
#pragma once
#include "cru/common/Base.hpp"
+#include "cru/common/Format.hpp"
+
+#include <fmt/core.h>
#include <cstdint>
#include <limits>
#include <optional>
+#include <string>
#include <utility>
namespace cru::platform {
@@ -14,6 +18,16 @@ struct Point final {
constexpr Point(const float x, const float y) : x(x), y(y) {}
explicit constexpr Point(const Size& size);
+ std::u16string ToDebugString() const {
+ return fmt::format(u"({}, {})", ToUtf16String(x), ToUtf16String(y));
+ }
+
+ constexpr Point& operator+=(const Point& other) {
+ this->x += other.x;
+ this->y += other.y;
+ return *this;
+ }
+
float x = 0;
float y = 0;
};
@@ -46,6 +60,11 @@ struct Size final {
std::numeric_limits<float>::max()};
}
+ std::u16string ToDebugString() const {
+ return fmt::format(u"({}, {})", ToUtf16String(width),
+ ToUtf16String(height));
+ }
+
float width = 0;
float height = 0;
};
@@ -258,7 +277,7 @@ struct TextRange final {
gsl::index GetStart() const { return position; }
gsl::index GetEnd() const { return position + count; }
- void AdjustEnd(gsl::index new_end) { count = new_end - position; }
+ void ChangeEnd(gsl::index new_end) { count = new_end - position; }
TextRange Normalize() const {
auto result = *this;
@@ -297,6 +316,12 @@ struct Color {
(hex >> 24) & mask);
}
+ constexpr Color WithAlpha(std::uint8_t new_alpha) const {
+ auto result = *this;
+ result.alpha = new_alpha;
+ return result;
+ }
+
std::uint8_t red;
std::uint8_t green;
std::uint8_t blue;
diff --git a/include/cru/platform/Matrix.hpp b/include/cru/platform/Matrix.hpp
index e702df90..8ec5faaa 100644
--- a/include/cru/platform/Matrix.hpp
+++ b/include/cru/platform/Matrix.hpp
@@ -50,10 +50,15 @@ struct Matrix {
return Matrix{1.0f, 0.0f, 0.0f, 1.0f, x, y};
}
+ static Matrix Translation(const Point& point) {
+ return Translation(point.x, point.y);
+ }
+
static Matrix Scale(float sx, float sy) {
return Matrix{sx, 0.0f, 0.0f, sy, 0.0f, 0.0f};
}
+ // Clockwise.
static Matrix Rotation(float angle) {
float r = AngleToRadian(angle);
float s = std::sin(r);
diff --git a/include/cru/platform/graph/Base.hpp b/include/cru/platform/graphics/Base.hpp
index 61cfc5ef..e751ebdb 100644
--- a/include/cru/platform/graph/Base.hpp
+++ b/include/cru/platform/graphics/Base.hpp
@@ -5,7 +5,7 @@
#include <memory>
-namespace cru::platform::graph {
+namespace cru::platform::graphics {
// forward declarations
struct IGraphFactory;
struct IBrush;
diff --git a/include/cru/platform/graph/Brush.hpp b/include/cru/platform/graphics/Brush.hpp
index e67384de..10c666b5 100644
--- a/include/cru/platform/graph/Brush.hpp
+++ b/include/cru/platform/graphics/Brush.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "Resource.hpp"
-namespace cru::platform::graph {
+namespace cru::platform::graphics {
struct IBrush : virtual IGraphResource {};
struct ISolidColorBrush : virtual IBrush {
diff --git a/include/cru/platform/graph/Factory.hpp b/include/cru/platform/graphics/Factory.hpp
index b4e68f12..f9018e13 100644
--- a/include/cru/platform/graph/Factory.hpp
+++ b/include/cru/platform/graphics/Factory.hpp
@@ -9,7 +9,7 @@
#include <string>
#include <string_view>
-namespace cru::platform::graph {
+namespace cru::platform::graphics {
// Entry point of the graph module.
struct IGraphFactory : virtual INativeResource {
virtual std::unique_ptr<ISolidColorBrush> CreateSolidColorBrush() = 0;
@@ -21,5 +21,11 @@ struct IGraphFactory : virtual INativeResource {
virtual std::unique_ptr<ITextLayout> CreateTextLayout(
std::shared_ptr<IFont> font, std::u16string text) = 0;
+
+ std::unique_ptr<ISolidColorBrush> CreateSolidColorBrush(const Color& color) {
+ std::unique_ptr<ISolidColorBrush> brush = CreateSolidColorBrush();
+ brush->SetColor(color);
+ return brush;
+ }
};
-} // namespace cru::platform::graph
+} // namespace cru::platform::graphics
diff --git a/include/cru/platform/graph/Font.hpp b/include/cru/platform/graphics/Font.hpp
index 182cc15b..70392a69 100644
--- a/include/cru/platform/graph/Font.hpp
+++ b/include/cru/platform/graphics/Font.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "Resource.hpp"
-namespace cru::platform::graph {
+namespace cru::platform::graphics {
struct IFont : virtual IGraphResource {
virtual float GetFontSize() = 0;
};
diff --git a/include/cru/platform/graph/Geometry.hpp b/include/cru/platform/graphics/Geometry.hpp
index 354efd97..b0ce6ad9 100644
--- a/include/cru/platform/graph/Geometry.hpp
+++ b/include/cru/platform/graphics/Geometry.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "Resource.hpp"
-namespace cru::platform::graph {
+namespace cru::platform::graphics {
struct IGeometry : virtual IGraphResource {
virtual bool FillContains(const Point& point) = 0;
};
diff --git a/include/cru/platform/graph/Painter.hpp b/include/cru/platform/graphics/Painter.hpp
index 27ae420b..f75ea52b 100644
--- a/include/cru/platform/graph/Painter.hpp
+++ b/include/cru/platform/graphics/Painter.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "Resource.hpp"
-namespace cru::platform::graph {
+namespace cru::platform::graphics {
struct IPainter : virtual INativeResource {
virtual Matrix GetTransform() = 0;
@@ -9,6 +9,8 @@ struct IPainter : virtual INativeResource {
virtual void Clear(const Color& color) = 0;
+ virtual void DrawLine(const Point& start, const Point& end, IBrush* brush,
+ float width) = 0;
virtual void StrokeRectangle(const Rect& rectangle, IBrush* brush,
float width) = 0;
virtual void FillRectangle(const Rect& rectangle, IBrush* brush) = 0;
@@ -26,4 +28,4 @@ struct IPainter : virtual INativeResource {
virtual void EndDraw() = 0;
};
-} // namespace cru::platform::graph
+} // namespace cru::platform::graphics
diff --git a/include/cru/platform/graph/Resource.hpp b/include/cru/platform/graphics/Resource.hpp
index 8859360c..a1625ce4 100644
--- a/include/cru/platform/graph/Resource.hpp
+++ b/include/cru/platform/graphics/Resource.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "Base.hpp"
-namespace cru::platform::graph {
+namespace cru::platform::graphics {
struct IGraphFactory;
struct IGraphResource : virtual INativeResource {
diff --git a/include/cru/platform/graph/TextLayout.hpp b/include/cru/platform/graphics/TextLayout.hpp
index a101983f..b363fb77 100644
--- a/include/cru/platform/graph/TextLayout.hpp
+++ b/include/cru/platform/graphics/TextLayout.hpp
@@ -4,7 +4,7 @@
#include <string>
#include <vector>
-namespace cru::platform::graph {
+namespace cru::platform::graphics {
struct ITextLayout : virtual IGraphResource {
virtual std::u16string GetText() = 0;
virtual std::u16string_view GetTextView() = 0;
@@ -16,9 +16,9 @@ struct ITextLayout : virtual IGraphResource {
virtual void SetMaxWidth(float max_width) = 0;
virtual void SetMaxHeight(float max_height) = 0;
- virtual Rect GetTextBounds() = 0;
+ virtual Rect GetTextBounds(bool includingTrailingSpace = false) = 0;
virtual std::vector<Rect> TextRangeRect(const TextRange& text_range) = 0;
virtual Point TextSinglePoint(Index position, bool trailing) = 0;
virtual TextHitTestResult HitTest(const Point& point) = 0;
};
-} // namespace cru::platform::graph
+} // namespace cru::platform::graphics
diff --git a/include/cru/platform/graph/util/Painter.hpp b/include/cru/platform/graphics/util/Painter.hpp
index f9aec027..90457cf4 100644
--- a/include/cru/platform/graph/util/Painter.hpp
+++ b/include/cru/platform/graphics/util/Painter.hpp
@@ -4,14 +4,14 @@
#include <functional>
#include <type_traits>
-namespace cru::platform::graph::util {
+namespace cru::platform::graphics::util {
template <typename Fn>
void WithTransform(IPainter* painter, const Matrix& matrix, const Fn& action) {
static_assert(std::is_invocable_v<decltype(action), IPainter*>,
"Action must can be be invoked with painter.");
const auto old = painter->GetTransform();
- painter->SetTransform(old * matrix);
+ painter->SetTransform(matrix * old);
action(painter);
painter->SetTransform(old);
}
-} // namespace cru::platform::graph::util
+} // namespace cru::platform::graphics::util
diff --git a/include/cru/platform/native/Base.hpp b/include/cru/platform/gui/Base.hpp
index bba7b960..7a9d1889 100644
--- a/include/cru/platform/native/Base.hpp
+++ b/include/cru/platform/gui/Base.hpp
@@ -1,23 +1,18 @@
#pragma once
+#include "Keyboard.hpp"
#include "cru/common/Base.hpp"
#include "cru/common/Bitmask.hpp"
-#include "cru/platform/graph/Base.hpp"
-#include "Keyboard.hpp"
+#include "cru/platform/graphics/Base.hpp"
-namespace cru::platform::native {
+#include "../Resource.hpp"
+
+namespace cru::platform::gui {
struct ICursor;
struct ICursorManager;
struct IUiApplication;
struct INativeWindow;
-struct INativeWindowResolver;
-struct IInputMethodManager;
struct IInputMethodContext;
-struct Dpi {
- float x;
- float y;
-};
-
namespace details {
struct TagMouseButton {};
} // namespace details
@@ -30,11 +25,6 @@ constexpr MouseButton middle{0b10};
constexpr MouseButton right{0b100};
} // namespace mouse_buttons
-enum class SystemCursorType {
- Arrow,
- Hand,
-};
-
struct NativeMouseButtonEventArgs {
MouseButton button;
Point point;
@@ -49,4 +39,4 @@ struct NativeKeyEventArgs {
enum class FocusChangeType { Gain, Lost };
enum class MouseEnterLeaveType { Enter, Leave };
-} // namespace cru::platform::native
+} // namespace cru::platform::gui
diff --git a/include/cru/platform/native/Cursor.hpp b/include/cru/platform/gui/Cursor.hpp
index 6c8f8068..316496a0 100644
--- a/include/cru/platform/native/Cursor.hpp
+++ b/include/cru/platform/gui/Cursor.hpp
@@ -1,10 +1,11 @@
#pragma once
-#include "../Resource.hpp"
#include "Base.hpp"
#include <memory>
-namespace cru::platform::native {
+namespace cru::platform::gui {
+enum class SystemCursorType { Arrow, Hand, IBeam };
+
struct ICursor : virtual INativeResource {};
struct ICursorManager : virtual INativeResource {
@@ -12,4 +13,4 @@ struct ICursorManager : virtual INativeResource {
// TODO: Add method to create cursor.
};
-} // namespace cru::platform::native
+} // namespace cru::platform::gui
diff --git a/include/cru/platform/gui/DebugFlags.hpp b/include/cru/platform/gui/DebugFlags.hpp
new file mode 100644
index 00000000..2b7c7c19
--- /dev/null
+++ b/include/cru/platform/gui/DebugFlags.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+namespace cru::platform::gui {
+struct DebugFlags {
+ static constexpr int paint = 0;
+ static constexpr int input_method = 0;
+};
+} // namespace cru::platform::gui
diff --git a/include/cru/platform/native/InputMethod.hpp b/include/cru/platform/gui/InputMethod.hpp
index 6f222a43..9d090eab 100644
--- a/include/cru/platform/native/InputMethod.hpp
+++ b/include/cru/platform/gui/InputMethod.hpp
@@ -1,5 +1,4 @@
#pragma once
-#include "../Resource.hpp"
#include "Base.hpp"
#include "cru/common/Event.hpp"
@@ -8,7 +7,7 @@
#include <memory>
#include <vector>
-namespace cru::platform::native {
+namespace cru::platform::gui {
struct CompositionClause {
int start;
int end;
@@ -38,7 +37,8 @@ struct IInputMethodContext : virtual INativeResource {
virtual CompositionText GetCompositionText() = 0;
- // Set the candidate window lefttop. Use this method to prepare typing.
+ // Set the candidate window lefttop. Relative to window lefttop. Use this
+ // method to prepare typing.
virtual void SetCandidateWindowPosition(const Point& point) = 0;
// Triggered when user starts composition.
@@ -52,22 +52,17 @@ struct IInputMethodContext : virtual INativeResource {
virtual IEvent<std::u16string_view>* TextEvent() = 0;
};
-
-struct IInputMethodManager : virtual INativeResource {
- virtual std::unique_ptr<IInputMethodContext> GetContext(
- INativeWindow* window) = 0;
-};
-} // namespace cru::platform::native
+} // namespace cru::platform::gui
template <>
-struct fmt::formatter<cru::platform::native::CompositionText, char16_t>
+struct fmt::formatter<cru::platform::gui::CompositionText, char16_t>
: fmt::formatter<std::u16string_view, char16_t> {
auto parse(fmt::basic_format_parse_context<char16_t>& ctx) {
return fmt::formatter<std::u16string_view, char16_t>::parse(ctx);
}
template <typename FormatContext>
- auto format(const cru::platform::native::CompositionText& ct,
+ auto format(const cru::platform::gui::CompositionText& ct,
FormatContext& ctx) {
auto output = ctx.out();
output = format_to(output, u"text: {}\n", ct.text);
diff --git a/include/cru/platform/native/Keyboard.hpp b/include/cru/platform/gui/Keyboard.hpp
index 83c61bcc..6c29239b 100644
--- a/include/cru/platform/native/Keyboard.hpp
+++ b/include/cru/platform/gui/Keyboard.hpp
@@ -1,7 +1,10 @@
#pragma once
#include "cru/common/Bitmask.hpp"
-namespace cru::platform::native {
+#include <string>
+#include <string_view>
+
+namespace cru::platform::gui {
// Because of the complexity of keyboard layout, I only add code in US keyboard
// layout, the most widely used layout in China. We should try to make it easy
// to add new keyboard layout.
@@ -113,8 +116,13 @@ struct TagKeyModifier {};
using KeyModifier = Bitmask<details::TagKeyModifier>;
struct KeyModifiers {
+ static constexpr KeyModifier none{0};
static constexpr KeyModifier shift{0b1};
static constexpr KeyModifier ctrl{0b10};
static constexpr KeyModifier alt{0b100};
};
-} // namespace cru::platform::native
+
+std::u16string_view ToString(KeyCode key_code);
+std::u16string ToString(KeyModifier key_modifier,
+ std::u16string_view separator = u"+");
+} // namespace cru::platform::gui
diff --git a/include/cru/platform/gui/UiApplication.hpp b/include/cru/platform/gui/UiApplication.hpp
new file mode 100644
index 00000000..5a5b0b13
--- /dev/null
+++ b/include/cru/platform/gui/UiApplication.hpp
@@ -0,0 +1,135 @@
+#pragma once
+#include "Base.hpp"
+
+#include "cru/common/Bitmask.hpp"
+
+#include <chrono>
+#include <functional>
+#include <memory>
+#include <vector>
+
+namespace cru::platform::gui {
+namespace details {
+struct CreateWindowFlagTag;
+}
+
+using CreateWindowFlag = Bitmask<details::CreateWindowFlagTag>;
+
+struct CreateWindowFlags {
+ static constexpr CreateWindowFlag NoCaptionAndBorder{0b1};
+};
+
+// The entry point of a ui application.
+struct IUiApplication : public virtual INativeResource {
+ public:
+ static IUiApplication* GetInstance() { return instance; }
+
+ private:
+ static IUiApplication* instance;
+
+ protected:
+ IUiApplication();
+
+ public:
+ ~IUiApplication() override;
+
+ // Block current thread and run the message loop. Return the exit code when
+ // message loop gets a quit message (possibly posted by method RequestQuit).
+ virtual int Run() = 0;
+
+ // Post a quit message with given quit code.
+ virtual void RequestQuit(int quit_code) = 0;
+
+ virtual void AddOnQuitHandler(std::function<void()> handler) = 0;
+
+ // Timer id should always be positive (not 0) and never the same. So it's ok
+ // to use negative value (or 0) to represent no timer.
+ virtual long long SetImmediate(std::function<void()> action) = 0;
+ virtual long long SetTimeout(std::chrono::milliseconds milliseconds,
+ std::function<void()> action) = 0;
+ virtual long long SetInterval(std::chrono::milliseconds milliseconds,
+ std::function<void()> action) = 0;
+ // Implementation should guarantee calls on timer id already canceled have no
+ // effects and do not crash. Also canceling negative id or 0 should always
+ // result in no-op.
+ virtual void CancelTimer(long long id) = 0;
+
+ virtual std::vector<INativeWindow*> GetAllWindow() = 0;
+
+ INativeWindow* CreateWindow(INativeWindow* parent) {
+ return this->CreateWindow(parent, CreateWindowFlag(0));
+ };
+ virtual INativeWindow* CreateWindow(INativeWindow* parent,
+ CreateWindowFlag flags) = 0;
+
+ virtual cru::platform::graphics::IGraphFactory* GetGraphFactory() = 0;
+
+ virtual ICursorManager* GetCursorManager() = 0;
+};
+
+class TimerAutoCanceler {
+ public:
+ TimerAutoCanceler() : id_(0) {}
+ explicit TimerAutoCanceler(long long id) : id_(id) {}
+
+ CRU_DELETE_COPY(TimerAutoCanceler)
+
+ TimerAutoCanceler(TimerAutoCanceler&& other) : id_(other.id_) {
+ other.id_ = 0;
+ }
+
+ TimerAutoCanceler& operator=(TimerAutoCanceler&& other) {
+ if (&other == this) {
+ return *this;
+ }
+ Reset(other.id_);
+ other.id_ = 0;
+ return *this;
+ }
+
+ TimerAutoCanceler& operator=(long long other) {
+ return this->operator=(TimerAutoCanceler(other));
+ }
+
+ ~TimerAutoCanceler() { Reset(); }
+
+ long long Release() {
+ auto temp = id_;
+ id_ = 0;
+ return temp;
+ }
+
+ void Reset(long long id = 0) {
+ if (id_ > 0) IUiApplication::GetInstance()->CancelTimer(id_);
+ id_ = id;
+ }
+
+ explicit operator bool() const { return id_; }
+
+ private:
+ long long id_;
+};
+
+class TimerListAutoCanceler {
+ public:
+ TimerListAutoCanceler() = default;
+ CRU_DELETE_COPY(TimerListAutoCanceler)
+ CRU_DEFAULT_MOVE(TimerListAutoCanceler)
+ ~TimerListAutoCanceler() = default;
+
+ TimerListAutoCanceler& operator+=(long long id) {
+ list_.push_back(TimerAutoCanceler(id));
+ return *this;
+ }
+
+ void Clear() { list_.clear(); }
+
+ bool IsEmpty() const { return list_.empty(); }
+
+ private:
+ std::vector<TimerAutoCanceler> list_;
+};
+
+// Bootstrap from this.
+std::unique_ptr<IUiApplication> CreateUiApplication();
+} // namespace cru::platform::gui
diff --git a/include/cru/platform/native/Window.hpp b/include/cru/platform/gui/Window.hpp
index 1fcac1fc..26d1a476 100644
--- a/include/cru/platform/native/Window.hpp
+++ b/include/cru/platform/gui/Window.hpp
@@ -1,21 +1,14 @@
#pragma once
-#include "../Resource.hpp"
#include "Base.hpp"
+
#include "cru/common/Event.hpp"
#include <string_view>
-namespace cru::platform::native {
+namespace cru::platform::gui {
// Represents a native window, which exposes some low-level events and
// operations.
-//
-// Usually you save an INativeWindowResolver after creating a window. Because
-// window may be destroyed when user do certain actions like click the close
-// button. Then the INativeWindow instance is destroyed and
-// INativeWindowResolver::Resolve return nullptr to indicate the fact.
struct INativeWindow : virtual INativeResource {
- virtual std::shared_ptr<INativeWindowResolver> GetResolver() = 0;
-
virtual void Close() = 0;
virtual INativeWindow* GetParent() = 0;
@@ -45,8 +38,9 @@ struct INativeWindow : virtual INativeResource {
virtual void RequestRepaint() = 0;
// Remember to call EndDraw on return value and destroy it.
- virtual std::unique_ptr<graph::IPainter> BeginPaint() = 0;
+ virtual std::unique_ptr<graphics::IPainter> BeginPaint() = 0;
+ // Don't use this instance after receive this event.
virtual IEvent<std::nullptr_t>* DestroyEvent() = 0;
virtual IEvent<std::nullptr_t>* PaintEvent() = 0;
virtual IEvent<Size>* ResizeEvent() = 0;
@@ -57,11 +51,7 @@ struct INativeWindow : virtual INativeResource {
virtual IEvent<NativeMouseButtonEventArgs>* MouseUpEvent() = 0;
virtual IEvent<NativeKeyEventArgs>* KeyDownEvent() = 0;
virtual IEvent<NativeKeyEventArgs>* KeyUpEvent() = 0;
-};
-// See INativeWindow for more info.
-struct INativeWindowResolver : virtual INativeResource {
- // Think twice before you save the return value.
- virtual INativeWindow* Resolve() = 0;
+ virtual IInputMethodContext* GetInputMethodContext() = 0;
};
-} // namespace cru::platform::native
+} // namespace cru::platform::gui
diff --git a/include/cru/platform/native/UiApplication.hpp b/include/cru/platform/native/UiApplication.hpp
deleted file mode 100644
index 1aa4df57..00000000
--- a/include/cru/platform/native/UiApplication.hpp
+++ /dev/null
@@ -1,58 +0,0 @@
-#pragma once
-#include "../Resource.hpp"
-#include "Base.hpp"
-
-#include <chrono>
-#include <functional>
-#include <memory>
-#include <vector>
-
-namespace cru::platform::native {
-// The entry point of a ui application.
-struct IUiApplication : public virtual INativeResource {
- public:
- static IUiApplication* GetInstance() { return instance; }
-
- private:
- static IUiApplication* instance;
-
- protected:
- IUiApplication();
-
- public:
- ~IUiApplication() override;
-
- // Block current thread and run the message loop. Return the exit code when
- // message loop gets a quit message (possibly posted by method RequestQuit).
- virtual int Run() = 0;
-
- // Post a quit message with given quit code.
- virtual void RequestQuit(int quit_code) = 0;
-
- virtual void AddOnQuitHandler(std::function<void()> handler) = 0;
-
- virtual void InvokeLater(std::function<void()> action) = 0;
- // Timer id should always be positive and never the same. So it's ok to use
- // negative value to represent no timer.
- virtual long long SetTimeout(std::chrono::milliseconds milliseconds,
- std::function<void()> action) = 0;
- virtual long long SetInterval(std::chrono::milliseconds milliseconds,
- std::function<void()> action) = 0;
- // Implementation should guarantee calls on timer id already canceled have no
- // effects and do not crash. Also canceling negative id should always result
- // in no-op.
- virtual void CancelTimer(long long id) = 0;
-
- virtual std::vector<INativeWindow*> GetAllWindow() = 0;
- virtual std::shared_ptr<INativeWindowResolver> CreateWindow(
- INativeWindow* parent) = 0;
-
- virtual cru::platform::graph::IGraphFactory* GetGraphFactory() = 0;
-
- virtual ICursorManager* GetCursorManager() = 0;
- virtual IInputMethodManager* GetInputMethodManager() = 0;
-};
-
-// Bootstrap from this.
-std::unique_ptr<IUiApplication> CreateUiApplication();
-} // namespace cru::platform::native