xref: /haiku/src/apps/processcontroller/NoiseBarMenuItem.cpp (revision 0f9ffb37c166a9d9257044c8937f6450f4257b75)
1 /*
2 	ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
3 	Copyright (C) 2004 beunited.org
4 
5 	This library is free software; you can redistribute it and/or
6 	modify it under the terms of the GNU Lesser General Public
7 	License as published by the Free Software Foundation; either
8 	version 2.1 of the License, or (at your option) any later version.
9 
10 	This library is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 	Lesser General Public License for more details.
14 
15 	You should have received a copy of the GNU Lesser General Public
16 	License along with this library; if not, write to the Free Software
17 	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19 
20 
21 #include "NoiseBarMenuItem.h"
22 #include "Catalog.h"
23 #include "Colors.h"
24 #include "ProcessController.h"
25 #include "Utilities.h"
26 
27 #undef B_TRANSLATION_CONTEXT
28 #define B_TRANSLATION_CONTEXT "ProcessController"
29 
30 NoiseBarMenuItem::NoiseBarMenuItem()
31 	: BMenuItem(B_TRANSLATE("Gone teams" B_UTF8_ELLIPSIS), NULL)
32 {
33 	fBusyWaiting = -1;
34 	fLost = -1;
35 	fGrenze1 = -1;
36 	fGrenze2 = -1;
37 }
38 
39 
40 void
41 NoiseBarMenuItem::DrawContent()
42 {
43 	DrawBar(true);
44 	Menu()->MovePenTo(ContentLocation());
45 	BMenuItem::DrawContent();
46 }
47 
48 
49 void
50 NoiseBarMenuItem::DrawBar(bool force)
51 {
52 	bool selected = IsSelected();
53 	BRect frame = Frame();
54 	BMenu* menu = Menu();
55 	rgb_color highColor = menu->HighColor();
56 
57 	BFont font;
58 	menu->GetFont(&font);
59 	frame = bar_rect(frame, &font);
60 
61 	if (fBusyWaiting < 0)
62 		return;
63 
64 	if (fGrenze1 < 0)
65 		force = true;
66 
67 	if (force) {
68 		if (selected)
69 			menu->SetHighColor(gFrameColorSelected);
70 		else
71 			menu->SetHighColor(gFrameColor);
72 		menu->StrokeRect(frame);
73 	}
74 
75 	frame.InsetBy(1, 1);
76 	BRect r = frame;
77 	float grenze1 = frame.left+(frame.right-frame.left)*fBusyWaiting;
78 	float grenze2 = frame.left+(frame.right-frame.left)*(fBusyWaiting+fLost);
79 	if (grenze1 > frame.right)
80 		grenze1 = frame.right;
81 	if (grenze2 > frame.right)
82 		grenze2 = frame.right;
83 	r.right = grenze1;
84 	if (!force)
85 		r.left = fGrenze1;
86 	if (r.left < r.right) {
87 		if (selected)
88 			menu->SetHighColor(tint_color (kGreen, B_HIGHLIGHT_BACKGROUND_TINT));
89 		else
90 			menu->SetHighColor(kGreen);
91 //		menu->SetHighColor(gKernelColor);
92 		menu->FillRect(r);
93 	}
94 	r.left = grenze1;
95 	r.right = grenze2;
96 	if (!force) {
97 		if (fGrenze2 > r.left && r.left >= fGrenze1)
98 			r.left = fGrenze2;
99 		if (fGrenze1 < r.right && r.right <= fGrenze2)
100 			r.right = fGrenze1;
101 	}
102 	if (r.left < r.right) {
103 		menu->SetHighColor(highColor);
104 //		menu->SetHighColor(gUserColor);
105 		menu->FillRect(r);
106 	}
107 	r.left = grenze2;
108 	r.right = frame.right;
109 	if (!force)
110 		r.right = fGrenze2;
111 	if (r.left < r.right) {
112 		if (selected)
113 			menu->SetHighColor(gWhiteSelected);
114 		else
115 			menu->SetHighColor(kWhite);
116 		menu->FillRect(r);
117 	}
118 	menu->SetHighColor(highColor);
119 	fGrenze1 = grenze1;
120 	fGrenze2 = grenze2;
121 }
122 
123 
124 void
125 NoiseBarMenuItem::GetContentSize(float* width, float* height)
126 {
127 	BMenuItem::GetContentSize(width, height);
128 	if (*height < 16)
129 		*height = 16;
130 	*width += 20 + kBarWidth;
131 }
132