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 <File.h> 10 #include <IconUtils.h> 11 #include <Resources.h> 12 #include <Roster.h> 13 14 #include "IconHandles.h" 15 16 17 #define ICON_SIZE 15 18 19 const BRect InputIcons::sBounds(0, 0, ICON_SIZE, ICON_SIZE); 20 21 22 InputIcons::InputIcons() 23 : 24 mouseIcon(sBounds, B_CMAP8), 25 touchpadIcon(sBounds, B_CMAP8), 26 keyboardIcon(sBounds, B_CMAP8) 27 { 28 app_info info; 29 be_app->GetAppInfo(&info); 30 BFile executableFile(&info.ref, B_READ_ONLY); 31 BResources resources(&executableFile); 32 resources.PreloadResourceType(B_VECTOR_ICON_TYPE); 33 34 _LoadBitmap(&resources); 35 } 36 37 38 void 39 InputIcons::_LoadBitmap(BResources* resources) 40 { 41 const uint8* mouse; 42 const uint8* touchpad; 43 const uint8* keyboard; 44 45 size_t size; 46 47 mouse = (const uint8*)resources->LoadResource( 48 B_VECTOR_ICON_TYPE, "mouse_icon", &size); 49 if (mouse) { 50 mouseIcon = new BBitmap(sBounds, 0, B_RGBA32); 51 BIconUtils::GetVectorIcon(mouse, size, &mouseIcon); 52 } 53 54 touchpad = (const uint8*)resources->LoadResource( 55 B_VECTOR_ICON_TYPE, "touchpad_icon", &size); 56 if (touchpad) { 57 touchpadIcon = new BBitmap(sBounds, 0, B_RGBA32); 58 BIconUtils::GetVectorIcon(touchpad, size, &touchpadIcon); 59 } 60 61 keyboard = (const uint8*)resources->LoadResource( 62 B_VECTOR_ICON_TYPE, "keyboard_icon", &size); 63 if (keyboard) { 64 keyboardIcon = new BBitmap(sBounds, 0, B_RGBA32); 65 BIconUtils::GetVectorIcon(keyboard, size, &keyboardIcon); 66 } 67 } 68 69 70 BRect 71 InputIcons::IconRectAt(const BPoint& topLeft) 72 { 73 return BRect(sBounds).OffsetToSelf(topLeft); 74 } 75