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