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