1ed257f05SPreetpal Kaur /*
2ed257f05SPreetpal Kaur * Copyright 2020, Haiku, Inc. All rights reserved.
3ed257f05SPreetpal Kaur * Distributed under the terms of the MIT License.
4ed257f05SPreetpal Kaur */
5ed257f05SPreetpal Kaur
6ed257f05SPreetpal Kaur #include "InputIcons.h"
7ed257f05SPreetpal Kaur
8ed257f05SPreetpal Kaur #include <Application.h>
9*d052479fSAugustin Cavalier #include <ControlLook.h>
10ed257f05SPreetpal Kaur #include <File.h>
11ed257f05SPreetpal Kaur #include <IconUtils.h>
12ed257f05SPreetpal Kaur #include <Resources.h>
13ed257f05SPreetpal Kaur #include <Roster.h>
14ed257f05SPreetpal Kaur
15ed257f05SPreetpal Kaur #include "IconHandles.h"
16ed257f05SPreetpal Kaur
17ed257f05SPreetpal Kaur
18*d052479fSAugustin Cavalier const BRect InputIcons::sBounds;
19ed257f05SPreetpal Kaur
20ed257f05SPreetpal Kaur
InputIcons()21ed257f05SPreetpal Kaur InputIcons::InputIcons()
22ed257f05SPreetpal Kaur :
23*d052479fSAugustin Cavalier mouseIcon(NULL, false),
24*d052479fSAugustin Cavalier touchpadIcon(NULL, false),
25*d052479fSAugustin Cavalier keyboardIcon(NULL, false)
26ed257f05SPreetpal Kaur {
27*d052479fSAugustin Cavalier if (!sBounds.IsValid()) {
28*d052479fSAugustin Cavalier *const_cast<BRect*>(&sBounds) = BRect(BPoint(0, 0),
29*d052479fSAugustin Cavalier be_control_look->ComposeIconSize(B_MINI_ICON));
30*d052479fSAugustin Cavalier }
31*d052479fSAugustin Cavalier
32ed257f05SPreetpal Kaur app_info info;
33ed257f05SPreetpal Kaur be_app->GetAppInfo(&info);
34ed257f05SPreetpal Kaur BFile executableFile(&info.ref, B_READ_ONLY);
35ed257f05SPreetpal Kaur BResources resources(&executableFile);
36ed257f05SPreetpal Kaur resources.PreloadResourceType(B_VECTOR_ICON_TYPE);
37ed257f05SPreetpal Kaur
38ed257f05SPreetpal Kaur _LoadBitmap(&resources);
39ed257f05SPreetpal Kaur }
40ed257f05SPreetpal Kaur
41ed257f05SPreetpal Kaur
42ed257f05SPreetpal Kaur void
_LoadBitmap(BResources * resources)43ed257f05SPreetpal Kaur InputIcons::_LoadBitmap(BResources* resources)
44ed257f05SPreetpal Kaur {
45ed257f05SPreetpal Kaur const uint8* mouse;
46ed257f05SPreetpal Kaur const uint8* touchpad;
47ed257f05SPreetpal Kaur const uint8* keyboard;
48ed257f05SPreetpal Kaur
49ed257f05SPreetpal Kaur size_t size;
50ed257f05SPreetpal Kaur
51ed257f05SPreetpal Kaur mouse = (const uint8*)resources->LoadResource(
52ed257f05SPreetpal Kaur B_VECTOR_ICON_TYPE, "mouse_icon", &size);
53ed257f05SPreetpal Kaur if (mouse) {
54ed257f05SPreetpal Kaur mouseIcon = new BBitmap(sBounds, 0, B_RGBA32);
55ed257f05SPreetpal Kaur BIconUtils::GetVectorIcon(mouse, size, &mouseIcon);
56ed257f05SPreetpal Kaur }
57ed257f05SPreetpal Kaur
58ed257f05SPreetpal Kaur touchpad = (const uint8*)resources->LoadResource(
59ed257f05SPreetpal Kaur B_VECTOR_ICON_TYPE, "touchpad_icon", &size);
60ed257f05SPreetpal Kaur if (touchpad) {
61ed257f05SPreetpal Kaur touchpadIcon = new BBitmap(sBounds, 0, B_RGBA32);
62ed257f05SPreetpal Kaur BIconUtils::GetVectorIcon(touchpad, size, &touchpadIcon);
63ed257f05SPreetpal Kaur }
64ed257f05SPreetpal Kaur
65ed257f05SPreetpal Kaur keyboard = (const uint8*)resources->LoadResource(
66ed257f05SPreetpal Kaur B_VECTOR_ICON_TYPE, "keyboard_icon", &size);
67ed257f05SPreetpal Kaur if (keyboard) {
68ed257f05SPreetpal Kaur keyboardIcon = new BBitmap(sBounds, 0, B_RGBA32);
69ed257f05SPreetpal Kaur BIconUtils::GetVectorIcon(keyboard, size, &keyboardIcon);
70ed257f05SPreetpal Kaur }
71ed257f05SPreetpal Kaur }
72ed257f05SPreetpal Kaur
73ed257f05SPreetpal Kaur
74ed257f05SPreetpal Kaur BRect
IconRectAt(const BPoint & topLeft)75ed257f05SPreetpal Kaur InputIcons::IconRectAt(const BPoint& topLeft)
76ed257f05SPreetpal Kaur {
77ed257f05SPreetpal Kaur return BRect(sBounds).OffsetToSelf(topLeft);
78ed257f05SPreetpal Kaur }
79