xref: /haiku/src/apps/processcontroller/NoiseBarMenuItem.cpp (revision a127b88ecbfab58f64944c98aa47722a18e363b2)
1 /*
2  * Copyright 2000, Georges-Edouard Berenger. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "NoiseBarMenuItem.h"
8 #include "Catalog.h"
9 #include "Colors.h"
10 #include "ProcessController.h"
11 #include "Utilities.h"
12 
13 #undef B_TRANSLATION_CONTEXT
14 #define B_TRANSLATION_CONTEXT "ProcessController"
15 
16 NoiseBarMenuItem::NoiseBarMenuItem()
17 	: BMenuItem(B_TRANSLATE("Gone teams" B_UTF8_ELLIPSIS), NULL)
18 {
19 	fBusyWaiting = -1;
20 	fLost = -1;
21 	fGrenze1 = -1;
22 	fGrenze2 = -1;
23 }
24 
25 
26 void
27 NoiseBarMenuItem::DrawContent()
28 {
29 	DrawBar(true);
30 	Menu()->MovePenTo(ContentLocation());
31 	BMenuItem::DrawContent();
32 }
33 
34 
35 void
36 NoiseBarMenuItem::DrawBar(bool force)
37 {
38 	bool selected = IsSelected();
39 	BRect frame = Frame();
40 	BMenu* menu = Menu();
41 	rgb_color highColor = menu->HighColor();
42 
43 	BFont font;
44 	menu->GetFont(&font);
45 	frame = bar_rect(frame, &font);
46 
47 	if (fBusyWaiting < 0)
48 		return;
49 
50 	if (fGrenze1 < 0)
51 		force = true;
52 
53 	if (force) {
54 		if (selected)
55 			menu->SetHighColor(gFrameColorSelected);
56 		else
57 			menu->SetHighColor(gFrameColor);
58 		menu->StrokeRect(frame);
59 	}
60 
61 	frame.InsetBy(1, 1);
62 	BRect r = frame;
63 	float grenze1 = frame.left+(frame.right-frame.left)*fBusyWaiting;
64 	float grenze2 = frame.left+(frame.right-frame.left)*(fBusyWaiting+fLost);
65 	if (grenze1 > frame.right)
66 		grenze1 = frame.right;
67 	if (grenze2 > frame.right)
68 		grenze2 = frame.right;
69 	r.right = grenze1;
70 	if (!force)
71 		r.left = fGrenze1;
72 	if (r.left < r.right) {
73 		if (selected)
74 			menu->SetHighColor(tint_color (kGreen, B_HIGHLIGHT_BACKGROUND_TINT));
75 		else
76 			menu->SetHighColor(kGreen);
77 //		menu->SetHighColor(gKernelColor);
78 		menu->FillRect(r);
79 	}
80 	r.left = grenze1;
81 	r.right = grenze2;
82 	if (!force) {
83 		if (fGrenze2 > r.left && r.left >= fGrenze1)
84 			r.left = fGrenze2;
85 		if (fGrenze1 < r.right && r.right <= fGrenze2)
86 			r.right = fGrenze1;
87 	}
88 	if (r.left < r.right) {
89 		menu->SetHighColor(highColor);
90 //		menu->SetHighColor(gUserColor);
91 		menu->FillRect(r);
92 	}
93 	r.left = grenze2;
94 	r.right = frame.right;
95 	if (!force)
96 		r.right = fGrenze2;
97 	if (r.left < r.right) {
98 		if (selected)
99 			menu->SetHighColor(gWhiteSelected);
100 		else
101 			menu->SetHighColor(kWhite);
102 		menu->FillRect(r);
103 	}
104 	menu->SetHighColor(highColor);
105 	fGrenze1 = grenze1;
106 	fGrenze2 = grenze2;
107 }
108 
109 
110 void
111 NoiseBarMenuItem::GetContentSize(float* width, float* height)
112 {
113 	BMenuItem::GetContentSize(width, height);
114 	if (*height < 16)
115 		*height = 16;
116 	*width += 20 + kBarWidth;
117 }
118