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 26 #undef B_TRANSLATION_CONTEXT 27 #define B_TRANSLATION_CONTEXT "ProcessController" 28 29 NoiseBarMenuItem::NoiseBarMenuItem() 30 : BMenuItem(B_TRANSLATE("Gone teams" B_UTF8_ELLIPSIS), NULL) 31 { 32 fBusyWaiting = -1; 33 fLost = -1; 34 fGrenze1 = -1; 35 fGrenze2 = -1; 36 } 37 38 39 void 40 NoiseBarMenuItem::DrawContent() 41 { 42 DrawBar(true); 43 Menu()->MovePenTo(ContentLocation()); 44 BMenuItem::DrawContent(); 45 } 46 47 48 void 49 NoiseBarMenuItem::DrawBar(bool force) 50 { 51 bool selected = IsSelected(); 52 BRect frame = Frame(); 53 BMenu* menu = Menu(); 54 rgb_color highColor = menu->HighColor(); 55 frame.right -= 24; 56 frame.left = frame.right - kBarWidth; 57 frame.top += 5; 58 frame.bottom = frame.top + 8; 59 if (fBusyWaiting < 0) 60 return; 61 62 if (fGrenze1 < 0) 63 force = true; 64 65 if (force) { 66 if (selected) 67 menu->SetHighColor(gFrameColorSelected); 68 else 69 menu->SetHighColor(gFrameColor); 70 menu->StrokeRect(frame); 71 } 72 73 frame.InsetBy(1, 1); 74 BRect r = frame; 75 float grenze1 = frame.left+(frame.right-frame.left)*fBusyWaiting; 76 float grenze2 = frame.left+(frame.right-frame.left)*(fBusyWaiting+fLost); 77 if (grenze1 > frame.right) 78 grenze1 = frame.right; 79 if (grenze2 > frame.right) 80 grenze2 = frame.right; 81 r.right = grenze1; 82 if (!force) 83 r.left = fGrenze1; 84 if (r.left < r.right) { 85 if (selected) 86 menu->SetHighColor(tint_color (kGreen, B_HIGHLIGHT_BACKGROUND_TINT)); 87 else 88 menu->SetHighColor(kGreen); 89 // menu->SetHighColor(gKernelColor); 90 menu->FillRect(r); 91 } 92 r.left = grenze1; 93 r.right = grenze2; 94 if (!force) { 95 if (fGrenze2 > r.left && r.left >= fGrenze1) 96 r.left = fGrenze2; 97 if (fGrenze1 < r.right && r.right <= fGrenze2) 98 r.right = fGrenze1; 99 } 100 if (r.left < r.right) { 101 menu->SetHighColor(highColor); 102 // menu->SetHighColor(gUserColor); 103 menu->FillRect(r); 104 } 105 r.left = grenze2; 106 r.right = frame.right; 107 if (!force) 108 r.right = fGrenze2; 109 if (r.left < r.right) { 110 if (selected) 111 menu->SetHighColor(gWhiteSelected); 112 else 113 menu->SetHighColor(kWhite); 114 menu->FillRect(r); 115 } 116 menu->SetHighColor(highColor); 117 fGrenze1 = grenze1; 118 fGrenze2 = grenze2; 119 } 120 121 122 void 123 NoiseBarMenuItem::GetContentSize(float* width, float* height) 124 { 125 BMenuItem::GetContentSize(width, height); 126 if (*height < 16) 127 *height = 16; 128 *width += 20 + kBarWidth; 129 } 130