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 frame.right -= 24; 55 frame.left = frame.right - kBarWidth; 56 frame.top += 5; 57 frame.bottom = frame.top + 8; 58 if (fBusyWaiting < 0) 59 return; 60 61 if (fGrenze1 < 0) 62 force = true; 63 64 if (force) { 65 if (selected) 66 menu->SetHighColor(gFrameColorSelected); 67 else 68 menu->SetHighColor(gFrameColor); 69 menu->StrokeRect(frame); 70 } 71 72 frame.InsetBy(1, 1); 73 BRect r = frame; 74 float grenze1 = frame.left+(frame.right-frame.left)*fBusyWaiting; 75 float grenze2 = frame.left+(frame.right-frame.left)*(fBusyWaiting+fLost); 76 if (grenze1 > frame.right) 77 grenze1 = frame.right; 78 if (grenze2 > frame.right) 79 grenze2 = frame.right; 80 r.right = grenze1; 81 if (!force) 82 r.left = fGrenze1; 83 if (r.left < r.right) { 84 if (selected) 85 menu->SetHighColor(tint_color (kGreen, B_HIGHLIGHT_BACKGROUND_TINT)); 86 else 87 menu->SetHighColor(kGreen); 88 // menu->SetHighColor(gKernelColor); 89 menu->FillRect(r); 90 } 91 r.left = grenze1; 92 r.right = grenze2; 93 if (!force) { 94 if (fGrenze2 > r.left && r.left >= fGrenze1) 95 r.left = fGrenze2; 96 if (fGrenze1 < r.right && r.right <= fGrenze2) 97 r.right = fGrenze1; 98 } 99 if (r.left < r.right) { 100 menu->SetHighColor(kBlack); 101 // menu->SetHighColor(gUserColor); 102 menu->FillRect(r); 103 } 104 r.left = grenze2; 105 r.right = frame.right; 106 if (!force) 107 r.right = fGrenze2; 108 if (r.left < r.right) { 109 if (selected) 110 menu->SetHighColor(gWhiteSelected); 111 else 112 menu->SetHighColor(kWhite); 113 menu->FillRect(r); 114 } 115 menu->SetHighColor(kBlack); 116 fGrenze1 = grenze1; 117 fGrenze2 = grenze2; 118 } 119 120 121 void 122 NoiseBarMenuItem::GetContentSize(float* width, float* height) 123 { 124 BMenuItem::GetContentSize(width, height); 125 if (*height < 16) 126 *height = 16; 127 *width += 20 + kBarWidth; 128 } 129