Debian Codegraph @

libs/input/SpriteIcon.h

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