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