Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _UI_POINTER_CONTROLLER_H |
| 18 | #define _UI_POINTER_CONTROLLER_H |
| 19 | |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame^] | 20 | #include "SpriteController.h" |
| 21 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 22 | #include <ui/DisplayInfo.h> |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 23 | #include <ui/Input.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 25 | #include <utils/Looper.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 26 | #include <utils/String8.h> |
| 27 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 28 | #include <SkBitmap.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 32 | /** |
| 33 | * Interface for tracking a single (mouse) pointer. |
| 34 | * |
| 35 | * The pointer controller is responsible for providing synchronization and for tracking |
| 36 | * display orientation changes if needed. |
| 37 | */ |
| 38 | class PointerControllerInterface : public virtual RefBase { |
| 39 | protected: |
| 40 | PointerControllerInterface() { } |
| 41 | virtual ~PointerControllerInterface() { } |
| 42 | |
| 43 | public: |
| 44 | /* Gets the bounds of the region that the pointer can traverse. |
| 45 | * Returns true if the bounds are available. */ |
| 46 | virtual bool getBounds(float* outMinX, float* outMinY, |
| 47 | float* outMaxX, float* outMaxY) const = 0; |
| 48 | |
| 49 | /* Move the pointer. */ |
| 50 | virtual void move(float deltaX, float deltaY) = 0; |
| 51 | |
| 52 | /* Sets a mask that indicates which buttons are pressed. */ |
| 53 | virtual void setButtonState(uint32_t buttonState) = 0; |
| 54 | |
| 55 | /* Gets a mask that indicates which buttons are pressed. */ |
| 56 | virtual uint32_t getButtonState() const = 0; |
| 57 | |
| 58 | /* Sets the absolute location of the pointer. */ |
| 59 | virtual void setPosition(float x, float y) = 0; |
| 60 | |
| 61 | /* Gets the absolute location of the pointer. */ |
| 62 | virtual void getPosition(float* outX, float* outY) const = 0; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 63 | |
| 64 | /* Fades the pointer out now. */ |
| 65 | virtual void fade() = 0; |
| 66 | |
| 67 | /* Makes the pointer visible if it has faded out. */ |
| 68 | virtual void unfade() = 0; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | |
| 72 | /* |
| 73 | * Tracks pointer movements and draws the pointer sprite to a surface. |
| 74 | * |
| 75 | * Handles pointer acceleration and animation. |
| 76 | */ |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 77 | class PointerController : public PointerControllerInterface, public MessageHandler { |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 78 | protected: |
| 79 | virtual ~PointerController(); |
| 80 | |
| 81 | public: |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 82 | enum InactivityFadeDelay { |
| 83 | INACTIVITY_FADE_DELAY_NORMAL = 0, |
| 84 | INACTIVITY_FADE_DELAY_SHORT = 1, |
| 85 | }; |
| 86 | |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame^] | 87 | PointerController(const sp<Looper>& looper, const sp<SpriteController>& spriteController); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 88 | |
| 89 | virtual bool getBounds(float* outMinX, float* outMinY, |
| 90 | float* outMaxX, float* outMaxY) const; |
| 91 | virtual void move(float deltaX, float deltaY); |
| 92 | virtual void setButtonState(uint32_t buttonState); |
| 93 | virtual uint32_t getButtonState() const; |
| 94 | virtual void setPosition(float x, float y); |
| 95 | virtual void getPosition(float* outX, float* outY) const; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 96 | virtual void fade(); |
| 97 | virtual void unfade(); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 98 | |
| 99 | void setDisplaySize(int32_t width, int32_t height); |
| 100 | void setDisplayOrientation(int32_t orientation); |
| 101 | void setPointerIcon(const SkBitmap* bitmap, float hotSpotX, float hotSpotY); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 102 | void setInactivityFadeDelay(InactivityFadeDelay inactivityFadeDelay); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 103 | |
| 104 | private: |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 105 | enum { |
| 106 | MSG_FADE_STEP = 0, |
| 107 | }; |
| 108 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 109 | mutable Mutex mLock; |
| 110 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 111 | sp<Looper> mLooper; |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame^] | 112 | sp<SpriteController> mSpriteController; |
| 113 | sp<WeakMessageHandler> mHandler; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 114 | |
| 115 | struct Locked { |
| 116 | int32_t displayWidth; |
| 117 | int32_t displayHeight; |
| 118 | int32_t displayOrientation; |
| 119 | |
| 120 | float pointerX; |
| 121 | float pointerY; |
| 122 | uint32_t buttonState; |
| 123 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 124 | float fadeAlpha; |
| 125 | InactivityFadeDelay inactivityFadeDelay; |
| 126 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 127 | bool visible; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 128 | |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame^] | 129 | sp<Sprite> sprite; |
| 130 | } mLocked; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 131 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 132 | bool getBoundsLocked(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const; |
| 133 | void setPositionLocked(float x, float y); |
| 134 | void updateLocked(); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 135 | |
| 136 | void handleMessage(const Message& message); |
| 137 | bool unfadeBeforeUpdateLocked(); |
| 138 | void startFadeLocked(); |
| 139 | void startInactivityFadeDelayLocked(); |
| 140 | void fadeStepLocked(); |
| 141 | bool isFadingLocked(); |
| 142 | nsecs_t getInactivityFadeDelayTimeLocked(); |
| 143 | void sendFadeStepMessageDelayedLocked(nsecs_t delayTime); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | } // namespace android |
| 147 | |
| 148 | #endif // _UI_POINTER_CONTROLLER_H |