blob: 9e6cc81f0bb4ea260229af7e39126652ee045c9b [file] [log] [blame]
Garfield Tan7e3457e2020-05-28 14:31:29 -07001/*
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 Pollack015f5d92022-06-02 06:59:33 +000022#include <input/Input.h>
Garfield Tan7e3457e2020-05-28 14:31:29 -070023
24namespace android {
25
26/*
27 * Icon that a sprite displays, including its hotspot.
28 */
29struct SpriteIcon {
Brandon Pollack015f5d92022-06-02 06:59:33 +000030 inline SpriteIcon() : style(PointerIconStyle::TYPE_NULL), hotSpotX(0), hotSpotY(0) {}
31 inline SpriteIcon(const graphics::Bitmap& bitmap, PointerIconStyle style, float hotSpotX,
Pat Manningf919b6d2024-01-30 13:14:55 +000032 float hotSpotY, bool drawNativeDropShadow)
33 : bitmap(bitmap),
34 style(style),
35 hotSpotX(hotSpotX),
36 hotSpotY(hotSpotY),
37 drawNativeDropShadow(drawNativeDropShadow) {}
Garfield Tan7e3457e2020-05-28 14:31:29 -070038
39 graphics::Bitmap bitmap;
Brandon Pollack015f5d92022-06-02 06:59:33 +000040 PointerIconStyle style;
Garfield Tan7e3457e2020-05-28 14:31:29 -070041 float hotSpotX;
42 float hotSpotY;
Pat Manningf919b6d2024-01-30 13:14:55 +000043 bool drawNativeDropShadow;
Garfield Tan7e3457e2020-05-28 14:31:29 -070044
45 inline SpriteIcon copy() const {
Pat Manningf919b6d2024-01-30 13:14:55 +000046 return SpriteIcon(bitmap.copy(ANDROID_BITMAP_FORMAT_RGBA_8888), style, hotSpotX, hotSpotY,
47 drawNativeDropShadow);
Garfield Tan7e3457e2020-05-28 14:31:29 -070048 }
49
50 inline void reset() {
51 bitmap.reset();
Brandon Pollack015f5d92022-06-02 06:59:33 +000052 style = PointerIconStyle::TYPE_NULL;
Garfield Tan7e3457e2020-05-28 14:31:29 -070053 hotSpotX = 0;
54 hotSpotY = 0;
Pat Manningf919b6d2024-01-30 13:14:55 +000055 drawNativeDropShadow = false;
Garfield Tan7e3457e2020-05-28 14:31:29 -070056 }
57
58 inline bool isValid() const { return bitmap.isValid() && !bitmap.isEmpty(); }
59
60 inline int32_t width() const { return bitmap.getInfo().width; }
61 inline int32_t height() const { return bitmap.getInfo().height; }
62
63 // Draw the bitmap onto the given surface. Returns true if it's successful, or false otherwise.
64 // Note it doesn't set any metadata to the surface.
65 bool draw(const sp<Surface> surface) const;
66};
67
68} // namespace android
69
70#endif // _UI_SPRITE_ICON_H