aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/native
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/platform/native')
-rw-r--r--include/cru/platform/native/Base.hpp52
-rw-r--r--include/cru/platform/native/Cursor.hpp15
-rw-r--r--include/cru/platform/native/InputMethod.hpp86
-rw-r--r--include/cru/platform/native/Keyboard.hpp120
-rw-r--r--include/cru/platform/native/UiApplication.hpp58
-rw-r--r--include/cru/platform/native/Window.hpp67
6 files changed, 0 insertions, 398 deletions
diff --git a/include/cru/platform/native/Base.hpp b/include/cru/platform/native/Base.hpp
deleted file mode 100644
index bba7b960..00000000
--- a/include/cru/platform/native/Base.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-#pragma once
-#include "cru/common/Base.hpp"
-#include "cru/common/Bitmask.hpp"
-#include "cru/platform/graph/Base.hpp"
-#include "Keyboard.hpp"
-
-namespace cru::platform::native {
-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
-
-using MouseButton = Bitmask<details::TagMouseButton>;
-
-namespace mouse_buttons {
-constexpr MouseButton left{0b1};
-constexpr MouseButton middle{0b10};
-constexpr MouseButton right{0b100};
-} // namespace mouse_buttons
-
-enum class SystemCursorType {
- Arrow,
- Hand,
-};
-
-struct NativeMouseButtonEventArgs {
- MouseButton button;
- Point point;
- KeyModifier modifier;
-};
-
-struct NativeKeyEventArgs {
- KeyCode key;
- KeyModifier modifier;
-};
-
-enum class FocusChangeType { Gain, Lost };
-
-enum class MouseEnterLeaveType { Enter, Leave };
-} // namespace cru::platform::native
diff --git a/include/cru/platform/native/Cursor.hpp b/include/cru/platform/native/Cursor.hpp
deleted file mode 100644
index 6c8f8068..00000000
--- a/include/cru/platform/native/Cursor.hpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-#include "../Resource.hpp"
-#include "Base.hpp"
-
-#include <memory>
-
-namespace cru::platform::native {
-struct ICursor : virtual INativeResource {};
-
-struct ICursorManager : virtual INativeResource {
- virtual std::shared_ptr<ICursor> GetSystemCursor(SystemCursorType type) = 0;
-
- // TODO: Add method to create cursor.
-};
-} // namespace cru::platform::native
diff --git a/include/cru/platform/native/InputMethod.hpp b/include/cru/platform/native/InputMethod.hpp
deleted file mode 100644
index 6f222a43..00000000
--- a/include/cru/platform/native/InputMethod.hpp
+++ /dev/null
@@ -1,86 +0,0 @@
-#pragma once
-#include "../Resource.hpp"
-#include "Base.hpp"
-
-#include "cru/common/Event.hpp"
-
-#include <fmt/format.h>
-#include <memory>
-#include <vector>
-
-namespace cru::platform::native {
-struct CompositionClause {
- int start;
- int end;
- bool target;
-};
-
-using CompositionClauses = std::vector<CompositionClause>;
-
-struct CompositionText {
- std::u16string text;
- CompositionClauses clauses;
- TextRange selection;
-};
-
-struct IInputMethodContext : virtual INativeResource {
- // Return true if you should draw composition text manually. Return false if
- // system will take care of that for you.
- virtual bool ShouldManuallyDrawCompositionText() = 0;
-
- virtual void EnableIME() = 0;
-
- virtual void DisableIME() = 0;
-
- virtual void CompleteComposition() = 0;
-
- virtual void CancelComposition() = 0;
-
- virtual CompositionText GetCompositionText() = 0;
-
- // Set the candidate window lefttop. Use this method to prepare typing.
- virtual void SetCandidateWindowPosition(const Point& point) = 0;
-
- // Triggered when user starts composition.
- virtual IEvent<std::nullptr_t>* CompositionStartEvent() = 0;
-
- // Triggered when user stops composition.
- virtual IEvent<std::nullptr_t>* CompositionEndEvent() = 0;
-
- // Triggered every time composition text changes.
- virtual IEvent<std::nullptr_t>* CompositionEvent() = 0;
-
- virtual IEvent<std::u16string_view>* TextEvent() = 0;
-};
-
-struct IInputMethodManager : virtual INativeResource {
- virtual std::unique_ptr<IInputMethodContext> GetContext(
- INativeWindow* window) = 0;
-};
-} // namespace cru::platform::native
-
-template <>
-struct fmt::formatter<cru::platform::native::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,
- FormatContext& ctx) {
- auto output = ctx.out();
- output = format_to(output, u"text: {}\n", ct.text);
- output = format_to(output, u"clauses:\n");
- for (gsl::index i = 0; i < static_cast<gsl::index>(ct.clauses.size());
- i++) {
- const auto& clause = ct.clauses[i];
- output =
- format_to(output, u"\t{}. start: {} end: {}{}\n", i, clause.start,
- clause.end, clause.target ? u" target" : u"");
- }
- output = format_to(output, u"selection: position: {} count: {}",
- ct.selection.position, ct.selection.count);
- return output;
- }
-};
diff --git a/include/cru/platform/native/Keyboard.hpp b/include/cru/platform/native/Keyboard.hpp
deleted file mode 100644
index 83c61bcc..00000000
--- a/include/cru/platform/native/Keyboard.hpp
+++ /dev/null
@@ -1,120 +0,0 @@
-#pragma once
-#include "cru/common/Bitmask.hpp"
-
-namespace cru::platform::native {
-// 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.
-enum class KeyCode {
- Unknown,
- LeftButton,
- MiddleButton,
- RightButton,
- Escape,
- F1,
- F2,
- F3,
- F4,
- F5,
- F6,
- F7,
- F8,
- F9,
- F10,
- F11,
- F12,
- N0,
- N1,
- N2,
- N3,
- N4,
- N5,
- N6,
- N7,
- N8,
- N9,
- A,
- B,
- C,
- D,
- E,
- F,
- G,
- H,
- I,
- J,
- K,
- L,
- M,
- N,
- O,
- P,
- Q,
- R,
- S,
- T,
- U,
- V,
- W,
- X,
- Y,
- Z,
- GraveAccent,
- Tab,
- CapsLock,
- LeftShift,
- LeftCtrl,
- LeftSuper,
- LeftAlt,
- Minus,
- Equal,
- Backspace,
- LeftSquareBracket,
- RightSquareBracket,
- BackSlash,
- Semicolon,
- Quote,
- Comma,
- Period,
- Slash,
- RightShift,
- RightCtrl,
- RightSuper,
- RightAlt,
- Insert,
- Delete,
- Home,
- End,
- PageUp,
- PageDown,
- Up,
- Left,
- Down,
- Right,
- PrintScreen,
- ScrollLock,
- Pause,
- NumPad0,
- NumPad1,
- NumPad2,
- NumPad3,
- NumPad4,
- NumPad5,
- NumPad6,
- NumPad7,
- NumPad8,
- NumPad9
-};
-
-namespace details {
-struct TagKeyModifier {};
-} // namespace details
-
-using KeyModifier = Bitmask<details::TagKeyModifier>;
-
-struct KeyModifiers {
- static constexpr KeyModifier shift{0b1};
- static constexpr KeyModifier ctrl{0b10};
- static constexpr KeyModifier alt{0b100};
-};
-} // namespace cru::platform::native
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
diff --git a/include/cru/platform/native/Window.hpp b/include/cru/platform/native/Window.hpp
deleted file mode 100644
index 1fcac1fc..00000000
--- a/include/cru/platform/native/Window.hpp
+++ /dev/null
@@ -1,67 +0,0 @@
-#pragma once
-#include "../Resource.hpp"
-#include "Base.hpp"
-#include "cru/common/Event.hpp"
-
-#include <string_view>
-
-namespace cru::platform::native {
-// 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;
-
- virtual bool IsVisible() = 0;
- virtual void SetVisible(bool is_visible) = 0;
-
- virtual Size GetClientSize() = 0;
- virtual void SetClientSize(const Size& size) = 0;
-
- // Get the rect of the window containing frame.
- // The lefttop of the rect is relative to screen lefttop.
- virtual Rect GetWindowRect() = 0;
-
- // Set the rect of the window containing frame.
- // The lefttop of the rect is relative to screen lefttop.
- virtual void SetWindowRect(const Rect& rect) = 0;
-
- // Relative to client lefttop.
- virtual Point GetMousePosition() = 0;
-
- virtual bool CaptureMouse() = 0;
- virtual bool ReleaseMouse() = 0;
-
- virtual void SetCursor(std::shared_ptr<ICursor> cursor) = 0;
-
- virtual void RequestRepaint() = 0;
-
- // Remember to call EndDraw on return value and destroy it.
- virtual std::unique_ptr<graph::IPainter> BeginPaint() = 0;
-
- virtual IEvent<std::nullptr_t>* DestroyEvent() = 0;
- virtual IEvent<std::nullptr_t>* PaintEvent() = 0;
- virtual IEvent<Size>* ResizeEvent() = 0;
- virtual IEvent<FocusChangeType>* FocusEvent() = 0;
- virtual IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() = 0;
- virtual IEvent<Point>* MouseMoveEvent() = 0;
- virtual IEvent<NativeMouseButtonEventArgs>* MouseDownEvent() = 0;
- 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;
-};
-} // namespace cru::platform::native