xref: /haiku/src/preferences/media/MediaIcons.cpp (revision f2b4344867e97c3f4e742a1b4a15e6879644601a)
1 /*
2  * Copyright 2010, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "MediaIcons.h"
7 
8 #include <Application.h>
9 #include <File.h>
10 #include <Resources.h>
11 #include <Roster.h>
12 
13 #include "IconHandles.h"
14 
15 
16 const BRect MediaIcons::sBounds(0, 0, 15, 15);
17 
18 
19 MediaIcons::IconSet::IconSet()
20 	:
21 	inputIcon(MediaIcons::sBounds, B_CMAP8),
22 	outputIcon(MediaIcons::sBounds, B_CMAP8)
23 {
24 }
25 
26 
27 
28 MediaIcons::MediaIcons()
29 	:
30 	devicesIcon(sBounds, B_CMAP8),
31 	mixerIcon(sBounds, B_CMAP8)
32 {
33 	app_info info;
34 	be_app->GetAppInfo(&info);
35 	BFile executableFile(&info.ref, B_READ_ONLY);
36 	BResources resources(&executableFile);
37 	resources.PreloadResourceType(B_COLOR_8_BIT_TYPE);
38 
39 	_LoadBitmap(&resources, devices_icon, &devicesIcon);
40 	_LoadBitmap(&resources, mixer_icon, &mixerIcon);
41 	_LoadBitmap(&resources, tv_icon, &videoIcons.outputIcon);
42 	_LoadBitmap(&resources, cam_icon, &videoIcons.inputIcon);
43 	_LoadBitmap(&resources, mic_icon, &audioIcons.inputIcon);
44 	_LoadBitmap(&resources, speaker_icon, &audioIcons.outputIcon);
45 }
46 
47 
48 void
49 MediaIcons::_LoadBitmap(BResources* resources, int32 id, BBitmap* bitmap)
50 {
51 	size_t size;
52 	const void* bits = resources->LoadResource(B_COLOR_8_BIT_TYPE, id, &size);
53 	bitmap->SetBits(bits, size, 0, B_CMAP8);
54 }
55 
56 
57 BRect
58 MediaIcons::IconRectAt(const BPoint& topLeft)
59 {
60 	return BRect(sBounds).OffsetToSelf(topLeft);
61 }
62