Ticket #7330: 0001-PowerStatus-New-Extended-info-window-s-layout.patch
File 0001-PowerStatus-New-Extended-info-window-s-layout.patch, 11.7 KB (added by , 8 years ago) |
---|
-
src/apps/powerstatus/ExtendedInfoWindow.cpp
From 168bde0a953fadeb721267f697515662f54a63b9 Mon Sep 17 00:00:00 2001 From: Kacper Kasper <kacperkasper@gmail.com> Date: Sun, 11 Sep 2016 12:46:01 +0000 Subject: [PATCH] PowerStatus: New Extended info window's layout. * Fixes #7330. --- src/apps/powerstatus/ExtendedInfoWindow.cpp | 87 ++++++++++++++++------------- src/apps/powerstatus/ExtendedInfoWindow.h | 11 +++- src/apps/powerstatus/PowerStatusView.cpp | 60 ++++++++++---------- src/apps/powerstatus/PowerStatusView.h | 3 +- src/apps/powerstatus/PowerStatusWindow.cpp | 4 +- 5 files changed, 89 insertions(+), 76 deletions(-) diff --git a/src/apps/powerstatus/ExtendedInfoWindow.cpp b/src/apps/powerstatus/ExtendedInfoWindow.cpp index 543fb87..9f8cdf1 100644
a b 1 1 /* 2 * Copyright 2009-201 5, Haiku, Inc. All Rights Reserved.2 * Copyright 2009-2016, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 20 20 21 21 22 22 const int kLineSpacing = 5; 23 const float kBorderMargin = 10.0f; 23 24 24 25 25 26 FontString::FontString() … … BatteryInfoView::Update(battery_info& info, acpi_extended_battery_info& extInfo) 60 61 void 61 62 BatteryInfoView::Draw(BRect updateRect) 62 63 { 63 SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 64 float fontHeight = _MeasureString("").height; 65 BPoint point(0.0f, kBorderMargin + fontHeight); 64 66 65 BPoint point(10, 10); 66 67 float space = _MeasureString("").height + kLineSpacing; 67 float space = fontHeight + kLineSpacing; 68 68 69 69 for (int i = 0; i < fStringList.CountItems(); i++) { 70 70 FontString* fontString = fStringList.ItemAt(i); … … BatteryInfoView::_FillStringList() 235 235 fontString->string += fBatteryExtendedInfo.oem_info; 236 236 _AddToStringList(fontString); 237 237 238 fPreferredSize.width = fMaxStringSize.width + 10;238 fPreferredSize.width = fMaxStringSize.width + kBorderMargin; 239 239 fPreferredSize.height = (fMaxStringSize.height + kLineSpacing) * 240 fStringList.CountItems() ;240 fStringList.CountItems() - kLineSpacing + kBorderMargin * 2; 241 241 } 242 242 243 243 … … ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface, 279 279 void 280 280 ExtPowerStatusView::Draw(BRect updateRect) 281 281 { 282 if (fSelected) 283 SetLowColor(102, 152, 203); 284 else 285 SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 282 // TODO: Use BeginLayer/EndLayer when #12937 is fixed 283 if (fDriverInterface->GetBatteryCount() > 1) { 284 if(fSelected == true) { 285 fAlpha = 255; 286 } else { 287 fAlpha = 100; 288 } 289 } 286 290 287 291 PowerStatusView::Draw(updateRect); 288 292 } … … ExtPowerStatusView::Update(bool force) 334 338 // #pragma mark - 335 339 336 340 341 BatteryView::BatteryView(BLayout* layout) 342 : 343 BView("battery view", B_WILL_DRAW | B_DRAW_ON_CHILDREN, layout) 344 { 345 } 346 347 348 void 349 BatteryView::Draw(BRect updateRect) 350 { 351 SetHighUIColor(B_PANEL_BACKGROUND_COLOR, B_DARKEN_2_TINT); 352 BRect drawBounds(Bounds()); 353 drawBounds.right /= 2; 354 FillRect(drawBounds); 355 } 356 357 358 // #pragma mark - 359 360 337 361 ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface) 338 362 : 339 363 BWindow(BRect(100, 150, 500, 500), B_TRANSLATE("Extended battery info"), … … ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface) 345 369 { 346 370 fDriverInterface->AcquireReference(); 347 371 348 BView *view = new BView(Bounds(), "view", B_FOLLOW_ALL, 0); 349 view->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); 350 AddChild(view); 351 352 BGroupLayout* mainLayout = new BGroupLayout(B_VERTICAL); 353 mainLayout->SetSpacing(10); 354 mainLayout->SetInsets(10, 10, 10, 10); 355 view->SetLayout(mainLayout); 356 357 BRect rect = Bounds(); 358 rect.InsetBy(5, 5); 359 BBox *infoBox = new BBox(rect, B_TRANSLATE("Power status box")); 360 infoBox->SetLabel(B_TRANSLATE("Battery info")); 361 BGroupLayout* infoLayout = new BGroupLayout(B_HORIZONTAL); 362 infoLayout->SetInsets(10, infoBox->TopBorderOffset() * 2 + 10, 10, 10); 363 infoLayout->SetSpacing(10); 364 infoBox->SetLayout(infoLayout); 365 mainLayout->AddView(infoBox); 366 367 BGroupView* batteryView = new BGroupView(B_VERTICAL); 368 batteryView->GroupLayout()->SetSpacing(10); 369 infoLayout->AddView(batteryView); 370 371 // create before the battery views 372 BGroupLayout* mainLayout = new BGroupLayout(B_HORIZONTAL, 0); 373 SetLayout(mainLayout); 374 375 BGroupLayout* batteryLayout = new BGroupLayout(B_VERTICAL, kBorderMargin); 376 batteryLayout->SetInsets(kBorderMargin); 377 378 BatteryView* batteryView = new BatteryView(batteryLayout); 379 mainLayout->AddView(batteryView); 380 372 381 fBatteryInfoView = new BatteryInfoView(); 382 mainLayout->AddView(fBatteryInfoView); 373 383 374 BGroupLayout* batteryLayout = batteryView->GroupLayout();375 384 BRect batteryRect(0, 0, 50, 30); 376 385 for (int i = 0; i < interface->GetBatteryCount(); i++) { 377 386 ExtPowerStatusView* view = new ExtPowerStatusView(interface, 378 387 batteryRect, B_FOLLOW_NONE, i, this); 379 view->SetExplicitMaxSize(BSize(70, 80));380 view->SetExplicitMinSize(BSize(70, 80));388 view->SetExplicitMaxSize(BSize(70, 70)); 389 view->SetExplicitMinSize(BSize(70, 70)); 381 390 382 391 batteryLayout->AddView(view); 383 392 fBatteryViewList.AddItem(view); … … ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface) 388 397 389 398 batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue()); 390 399 391 infoLayout->AddView(fBatteryInfoView);392 393 400 if (!fSelectedView && fBatteryViewList.CountItems() > 0) 394 401 fSelectedView = fBatteryViewList.ItemAt(0); 395 402 fSelectedView->Select(); -
src/apps/powerstatus/ExtendedInfoWindow.h
diff --git a/src/apps/powerstatus/ExtendedInfoWindow.h b/src/apps/powerstatus/ExtendedInfoWindow.h index 82b8748..15139d2 100644
a b 1 1 /* 2 * Copyright 2009 , Haiku, Inc. All Rights Reserved.2 * Copyright 2009-2016, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … private: 83 83 }; 84 84 85 85 86 class BatteryView : public BView 87 { 88 public: 89 BatteryView(BLayout* layout); 90 91 void Draw(BRect updateRect); 92 }; 93 94 86 95 class ExtendedInfoWindow : public BWindow 87 96 { 88 97 public: -
src/apps/powerstatus/PowerStatusView.cpp
diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index 8e8dc34..d114feb 100644
a b 1 1 /* 2 * Copyright 2006-201 5, Haiku, Inc. All Rights Reserved.2 * Copyright 2006-2016, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … PowerStatusView::_Init() 111 111 fPercent = 100; 112 112 fOnline = true; 113 113 fTimeLeft = 0; 114 fAlpha = 255; 114 115 } 115 116 116 117 … … PowerStatusView::MessageReceived(BMessage *message) 155 156 void 156 157 PowerStatusView::_DrawBattery(BRect rect) 157 158 { 159 SetDrawingMode(B_OP_ALPHA); 158 160 float quarter = floorf((rect.Height() + 1) / 4); 159 161 rect.top += quarter; 160 162 rect.bottom -= quarter; … … PowerStatusView::_DrawBattery(BRect rect) 165 167 rect.left += rect.Width() / 11; 166 168 167 169 if (LowColor().Brightness() > 100) 168 SetHighColor(0, 0, 0 );170 SetHighColor(0, 0, 0, fAlpha); 169 171 else 170 SetHighColor(128, 128, 128 );172 SetHighColor(128, 128, 128, fAlpha); 171 173 172 174 float gap = 1; 173 175 if (rect.Height() > 8) { … … PowerStatusView::_DrawBattery(BRect rect) 198 200 199 201 if (percent > 0) { 200 202 rect.InsetBy(gap, gap); 201 rgb_color base = (rgb_color){84, 84, 84, 255};203 rgb_color base = (rgb_color){84, 84, 84, fAlpha}; 202 204 if (LowColor().Brightness() < 128) 203 base = (rgb_color){172, 172, 172, 255};205 base = (rgb_color){172, 172, 172, fAlpha}; 204 206 205 207 if (be_control_look != NULL) { 206 208 BRect empty = rect; … … PowerStatusView::_DrawBattery(BRect rect) 218 220 219 221 if (fHasBattery) { 220 222 if (percent <= kLowBatteryPercentage) 221 base.set_to(180, 0, 0 );223 base.set_to(180, 0, 0, fAlpha); 222 224 else if (percent <= kNoteBatteryPercentage) 223 base.set_to(200, 140, 0 );225 base.set_to(200, 140, 0, fAlpha); 224 226 else 225 base.set_to(20, 180, 0 );227 base.set_to(20, 180, 0, fAlpha); 226 228 227 229 rect.right = rect.left + rect.Width() * percent / 100.0; 228 230 … … PowerStatusView::_DrawBattery(BRect rect) 236 238 237 239 if (fOnline) { 238 240 // When charging, draw a lightning symbol over the battery. 239 SetHighColor(255, 255, 0, 180); 240 SetDrawingMode(B_OP_ALPHA); 241 float alphaPercent = ((180 / 255.0f) * (fAlpha / 255.0f)); 242 uint8 alpha = static_cast<uint8>(alphaPercent * 255); 243 SetHighColor(255, 255, 0, alpha); 241 244 SetScale(std::min(Bounds().Width(), Bounds().Height()) / 16); 242 245 243 246 static const BPoint points[] = { … … PowerStatusView::_DrawBattery(BRect rect) 251 254 FillPolygon(points, 6); 252 255 253 256 SetScale(1); 254 SetDrawingMode(B_OP_OVER);255 257 } 256 258 257 SetHighColor(0, 0, 0); 259 SetHighColor(0, 0, 0, fAlpha); 260 SetDrawingMode(B_OP_OVER); 258 261 } 259 262 260 263 261 264 void 262 265 PowerStatusView::Draw(BRect updateRect) 263 266 { 264 bool drawBackground = Parent() == NULL 265 || (Parent()->Flags() & B_DRAW_ON_CHILDREN) == 0; 266 if (drawBackground) 267 FillRect(updateRect, B_SOLID_LOW); 268 269 float aspect = Bounds().Width() / Bounds().Height(); 270 bool below = aspect <= 1.0f; 267 bool inside = Bounds().Width() >= 70.0f && Bounds().Height() >= 40.0f; 271 268 272 269 font_height fontHeight; 273 270 GetFontHeight(&fontHeight); … … PowerStatusView::Draw(BRect updateRect) 285 282 if (fShowStatusIcon) { 286 283 iconRect = Bounds(); 287 284 if (showLabel) { 288 if (below) 289 iconRect.bottom -= textHeight + 4; 290 else 285 if (inside == false) 291 286 iconRect.right -= textWidth + 4; 292 287 } 293 288 … … PowerStatusView::Draw(BRect updateRect) 308 303 BPoint point(0, baseLine); 309 304 310 305 if (iconRect.IsValid()) { 311 if (below) { 312 point.x = (iconRect.Width() - textWidth) / 2; 313 point.y += iconRect.Height() + 2; 306 if (inside == true) { 307 point.x = (iconRect.Width() - textWidth) / 2 + 308 iconRect.Width() / 20; 309 point.y += (iconRect.Height() - textHeight) / 2; 314 310 } else { 315 311 point.x = iconRect.Width() + 2; 316 312 point.y += (iconRect.Height() - textHeight) / 2; … … PowerStatusView::Draw(BRect updateRect) 320 316 point.y += (Bounds().Height() - textHeight) / 2; 321 317 } 322 318 323 if (drawBackground) 324 SetHighColor(ui_color(B_CONTROL_TEXT_COLOR)); 319 SetDrawingMode(B_OP_ALPHA); 320 if (inside == false) 321 SetHighUIColor(B_CONTROL_TEXT_COLOR); 325 322 else { 326 SetDrawingMode(B_OP_OVER); 327 if (LowColor().Brightness() > 100) 328 SetHighColor(0, 0, 0); 329 else 330 SetHighColor(255, 255, 255); 323 SetHighColor(255, 255, 255, fAlpha); 324 DrawString(text, BPoint(point.x + 1, point.y + 1)); 325 SetHighColor(0, 0, 0, fAlpha); 331 326 } 332 327 333 328 DrawString(text, point); 329 SetDrawingMode(B_OP_OVER); 334 330 } 335 331 } 336 332 -
src/apps/powerstatus/PowerStatusView.h
diff --git a/src/apps/powerstatus/PowerStatusView.h b/src/apps/powerstatus/PowerStatusView.h index ca0d62e..220b90f 100644
a b 1 1 /* 2 * Copyright 2006-201 5, Haiku, Inc. All Rights Reserved.2 * Copyright 2006-2016, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … protected: 67 67 time_t fTimeLeft; 68 68 bool fOnline; 69 69 bool fHasBattery; 70 uint8 fAlpha; 70 71 }; 71 72 72 73 -
src/apps/powerstatus/PowerStatusWindow.cpp
diff --git a/src/apps/powerstatus/PowerStatusWindow.cpp b/src/apps/powerstatus/PowerStatusWindow.cpp index 6333e17..7e5388c 100644
a b 1 1 /* 2 * Copyright 2006-20 09, Haiku, Inc. All Rights Reserved.2 * Copyright 2006-2016, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 16 16 17 17 PowerStatusWindow::PowerStatusWindow() 18 18 : 19 BWindow(BRect(100, 150, 2 81, 299), B_TRANSLATE_SYSTEM_NAME("PowerStatus"),19 BWindow(BRect(100, 150, 250, 300), B_TRANSLATE_SYSTEM_NAME("PowerStatus"), 20 20 B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) 21 21 { 22 22 BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW);