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