OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef Window_DEFINED | 8 #ifndef Window_DEFINED |
9 #define Window_DEFINED | 9 #define Window_DEFINED |
10 | 10 |
| 11 #include "SkTypes.h" |
| 12 |
11 class SkCanvas; | 13 class SkCanvas; |
12 class VulkanTestContext; | 14 class VulkanTestContext; |
13 | 15 |
14 class Window { | 16 class Window { |
15 public: | 17 public: |
16 static Window* CreateNativeWindow(void* platformData); | 18 static Window* CreateNativeWindow(void* platformData); |
17 | 19 |
18 virtual ~Window() {}; | 20 virtual ~Window() {}; |
19 | 21 |
20 virtual void setTitle(const char*) = 0; | 22 virtual void setTitle(const char*) = 0; |
21 virtual void show() = 0; | 23 virtual void show() = 0; |
22 | 24 |
23 struct AttachmentInfo { | 25 struct AttachmentInfo { |
24 int fSampleCount; | 26 int fSampleCount; |
25 int fStencilBits; | 27 int fStencilBits; |
26 }; | 28 }; |
27 | 29 |
28 enum BackEndTypes { | 30 enum BackEndTypes { |
29 kNativeGL_BackendType, | 31 kNativeGL_BackendType, |
30 kVulkan_BackendType | 32 kVulkan_BackendType |
31 }; | 33 }; |
32 | 34 |
33 virtual bool attach(BackEndTypes attachType, int msaaSampleCount, Attachment
Info*) = 0; | 35 virtual bool attach(BackEndTypes attachType, int msaaSampleCount, Attachment
Info*) = 0; |
34 void detach(); | 36 void detach(); |
35 | 37 |
36 // input handling | 38 // input handling |
37 typedef bool(*OnKeyFunc)(int key, bool down, void* userData); | 39 enum Key { |
38 typedef bool(*OnMouseFunc)(int x, int y, bool down, void* userData); | 40 kNONE_Key, //corresponds to android's UNKNOWN |
| 41 |
| 42 kLeftSoftKey_Key, |
| 43 kRightSoftKey_Key, |
| 44 |
| 45 kHome_Key, //!< the home key - added to match android |
| 46 kBack_Key, //!< (CLR) |
| 47 kSend_Key, //!< the green (talk) key |
| 48 kEnd_Key, //!< the red key |
| 49 |
| 50 k0_Key, |
| 51 k1_Key, |
| 52 k2_Key, |
| 53 k3_Key, |
| 54 k4_Key, |
| 55 k5_Key, |
| 56 k6_Key, |
| 57 k7_Key, |
| 58 k8_Key, |
| 59 k9_Key, |
| 60 kStar_Key, //!< the * key |
| 61 kHash_Key, //!< the # key |
| 62 |
| 63 kUp_Key, |
| 64 kDown_Key, |
| 65 kLeft_Key, |
| 66 kRight_Key, |
| 67 |
| 68 kOK_Key, //!< the center key |
| 69 |
| 70 kVolUp_Key, //!< volume up - match android |
| 71 kVolDown_Key, //!< volume down - same |
| 72 kPower_Key, //!< power button - same |
| 73 kCamera_Key, //!< camera - same |
| 74 |
| 75 kLast_Key = kCamera_Key |
| 76 }; |
| 77 static const int kKeyCount = kLast_Key + 1; |
| 78 |
| 79 enum ModifierKeys { |
| 80 kShift_ModifierKey = 1 << 0, |
| 81 kControl_ModifierKey = 1 << 1, |
| 82 kOption_ModifierKey = 1 << 2, // same as ALT |
| 83 kCommand_ModifierKey = 1 << 3, |
| 84 kFirstPress_ModifierKey = 1 << 4, |
| 85 }; |
| 86 |
| 87 enum InputState { |
| 88 kDown_InputState, |
| 89 kUp_InputState, |
| 90 kMove_InputState // only valid for mouse |
| 91 }; |
| 92 |
| 93 // return value of 'true' means 'I have handled this event' |
| 94 typedef bool(*OnCharFunc)(SkUnichar c, uint32_t modifiers, void* userData); |
| 95 typedef bool(*OnKeyFunc)(Key key, InputState state, uint32_t modifiers, void
* userData); |
| 96 typedef bool(*OnMouseFunc)(int x, int y, InputState state, uint32_t modifier
s, void* userData); |
39 typedef void(*OnPaintFunc)(SkCanvas*, void* userData); | 97 typedef void(*OnPaintFunc)(SkCanvas*, void* userData); |
40 | 98 |
| 99 void registerCharFunc(OnCharFunc func, void* userData) { |
| 100 fCharFunc = func; |
| 101 fCharUserData = userData; |
| 102 } |
| 103 |
41 void registerKeyFunc(OnKeyFunc func, void* userData) { | 104 void registerKeyFunc(OnKeyFunc func, void* userData) { |
42 fKeyFunc = func; | 105 fKeyFunc = func; |
43 fKeyUserData = userData; | 106 fKeyUserData = userData; |
44 } | 107 } |
45 | 108 |
46 void registerMouseFunc(OnMouseFunc func, void* userData) { | 109 void registerMouseFunc(OnMouseFunc func, void* userData) { |
47 fMouseFunc = func; | 110 fMouseFunc = func; |
48 fMouseUserData = userData; | 111 fMouseUserData = userData; |
49 } | 112 } |
50 | 113 |
51 void registerPaintFunc(OnPaintFunc func, void* userData) { | 114 void registerPaintFunc(OnPaintFunc func, void* userData) { |
52 fPaintFunc = func; | 115 fPaintFunc = func; |
53 fPaintUserData = userData; | 116 fPaintUserData = userData; |
54 } | 117 } |
55 | 118 |
| 119 bool onChar(SkUnichar c, uint32_t modifiers); |
| 120 bool onKey(Key key, InputState state, uint32_t modifiers); |
| 121 bool onMouse(int x, int y, InputState state, uint32_t modifiers); |
56 void onPaint(); | 122 void onPaint(); |
57 void onSize(); | 123 void onResize(uint32_t width, uint32_t height); |
58 | 124 |
59 protected: | 125 protected: |
60 Window(); | 126 Window(); |
61 | 127 |
| 128 OnCharFunc fCharFunc; |
| 129 void* fCharUserData; |
62 OnKeyFunc fKeyFunc; | 130 OnKeyFunc fKeyFunc; |
63 void* fKeyUserData; | 131 void* fKeyUserData; |
64 OnMouseFunc fMouseFunc; | 132 OnMouseFunc fMouseFunc; |
65 void* fMouseUserData; | 133 void* fMouseUserData; |
66 OnPaintFunc fPaintFunc; | 134 OnPaintFunc fPaintFunc; |
67 void* fPaintUserData; | 135 void* fPaintUserData; |
68 | 136 |
69 VulkanTestContext* fTestContext; | 137 VulkanTestContext* fTestContext; |
70 }; | 138 }; |
71 | 139 |
72 | 140 |
73 #endif | 141 #endif |
OLD | NEW |