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> 22 #include <input/Input.h> 23 24 namespace android { 25 26 /* 27 * Icon that a sprite displays, including its hotspot. 28 */ 29 struct SpriteIcon { SpriteIconSpriteIcon30 inline SpriteIcon() : style(PointerIconStyle::TYPE_NULL), hotSpotX(0), hotSpotY(0) {} SpriteIconSpriteIcon31 inline SpriteIcon(const graphics::Bitmap& bitmap, PointerIconStyle style, float hotSpotX, 32 float hotSpotY) 33 : bitmap(bitmap), style(style), hotSpotX(hotSpotX), hotSpotY(hotSpotY) {} 34 35 graphics::Bitmap bitmap; 36 PointerIconStyle style; 37 float hotSpotX; 38 float hotSpotY; 39 copySpriteIcon40 inline SpriteIcon copy() const { 41 return SpriteIcon(bitmap.copy(ANDROID_BITMAP_FORMAT_RGBA_8888), style, hotSpotX, hotSpotY); 42 } 43 resetSpriteIcon44 inline void reset() { 45 bitmap.reset(); 46 style = PointerIconStyle::TYPE_NULL; 47 hotSpotX = 0; 48 hotSpotY = 0; 49 } 50 isValidSpriteIcon51 inline bool isValid() const { return bitmap.isValid() && !bitmap.isEmpty(); } 52 widthSpriteIcon53 inline int32_t width() const { return bitmap.getInfo().width; } heightSpriteIcon54 inline int32_t height() const { return bitmap.getInfo().height; } 55 56 // Draw the bitmap onto the given surface. Returns true if it's successful, or false otherwise. 57 // Note it doesn't set any metadata to the surface. 58 bool draw(const sp<Surface> surface) const; 59 }; 60 61 } // namespace android 62 63 #endif // _UI_SPRITE_ICON_H 64