Garfield Tan | 7e3457e | 2020-05-28 14:31:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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_SPRITE_ICON_H |
| 18 | #define _UI_SPRITE_ICON_H |
| 19 | |
| 20 | #include <android/graphics/bitmap.h> |
| 21 | #include <gui/Surface.h> |
Brandon Pollack | 015f5d9 | 2022-06-02 06:59:33 +0000 | [diff] [blame] | 22 | #include <input/Input.h> |
Garfield Tan | 7e3457e | 2020-05-28 14:31:29 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | /* |
| 27 | * Icon that a sprite displays, including its hotspot. |
| 28 | */ |
| 29 | struct SpriteIcon { |
Prabir Pradhan | 4b4f52f | 2024-02-09 18:09:50 +0000 | [diff] [blame] | 30 | explicit SpriteIcon() = default; |
| 31 | explicit SpriteIcon(const graphics::Bitmap& bitmap, PointerIconStyle style, float hotSpotX, |
| 32 | float hotSpotY, bool drawNativeDropShadow) |
Pat Manning | f919b6d | 2024-01-30 13:14:55 +0000 | [diff] [blame] | 33 | : bitmap(bitmap), |
| 34 | style(style), |
| 35 | hotSpotX(hotSpotX), |
| 36 | hotSpotY(hotSpotY), |
| 37 | drawNativeDropShadow(drawNativeDropShadow) {} |
Garfield Tan | 7e3457e | 2020-05-28 14:31:29 -0700 | [diff] [blame] | 38 | |
Prabir Pradhan | 4b4f52f | 2024-02-09 18:09:50 +0000 | [diff] [blame] | 39 | graphics::Bitmap bitmap{}; |
| 40 | PointerIconStyle style{PointerIconStyle::TYPE_NULL}; |
| 41 | float hotSpotX{}; |
| 42 | float hotSpotY{}; |
Pat Manning | acbe18d | 2024-03-05 17:54:30 +0000 | [diff] [blame] | 43 | bool drawNativeDropShadow{}; |
Garfield Tan | 7e3457e | 2020-05-28 14:31:29 -0700 | [diff] [blame] | 44 | |
| 45 | inline bool isValid() const { return bitmap.isValid() && !bitmap.isEmpty(); } |
| 46 | |
| 47 | inline int32_t width() const { return bitmap.getInfo().width; } |
| 48 | inline int32_t height() const { return bitmap.getInfo().height; } |
| 49 | |
| 50 | // Draw the bitmap onto the given surface. Returns true if it's successful, or false otherwise. |
| 51 | // Note it doesn't set any metadata to the surface. |
| 52 | bool draw(const sp<Surface> surface) const; |
| 53 | }; |
| 54 | |
| 55 | } // namespace android |
| 56 | |
| 57 | #endif // _UI_SPRITE_ICON_H |