From c5867c77cc27f8cf752b2b34bfd1a1beebabc6de Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Thu, 8 Dec 2016 23:22:39 +0000 Subject: [PATCH] SoftwareUpdater: Add a fancy looking stripe view --- src/apps/softwareupdater/Jamfile | 1 + .../softwareupdater/SoftwareUpdaterApp.cpp | 1 - .../softwareupdater/SoftwareUpdaterWindow.cpp | 34 +++++++-- .../softwareupdater/SoftwareUpdaterWindow.h | 8 ++ src/apps/softwareupdater/StripeView.cpp | 73 +++++++++++++++++++ src/apps/softwareupdater/StripeView.h | 33 +++++++++ 6 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 src/apps/softwareupdater/StripeView.cpp create mode 100644 src/apps/softwareupdater/StripeView.h diff --git a/src/apps/softwareupdater/Jamfile b/src/apps/softwareupdater/Jamfile index 7342a2aed4..bdea8f0286 100644 --- a/src/apps/softwareupdater/Jamfile +++ b/src/apps/softwareupdater/Jamfile @@ -5,6 +5,7 @@ UsePrivateHeaders interface shared ; Application SoftwareUpdater : SoftwareUpdaterApp.cpp SoftwareUpdaterWindow.cpp + StripeView.cpp : be localestub tracker translation [ TargetLibsupc++ ] : SoftwareUpdater.rdef ; diff --git a/src/apps/softwareupdater/SoftwareUpdaterApp.cpp b/src/apps/softwareupdater/SoftwareUpdaterApp.cpp index 05b33c4156..c21eb5d9e7 100644 --- a/src/apps/softwareupdater/SoftwareUpdaterApp.cpp +++ b/src/apps/softwareupdater/SoftwareUpdaterApp.cpp @@ -9,7 +9,6 @@ #include "SoftwareUpdaterApp.h" #include - #include #include "SoftwareUpdaterWindow.h" diff --git a/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp b/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp index c15dcd069c..655b869609 100644 --- a/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp +++ b/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp @@ -10,14 +10,16 @@ #include "SoftwareUpdaterWindow.h" #include - #include #include #include #include #include +#include #include #include +#include +#include #include @@ -31,19 +33,41 @@ const uint32 UPDATE_MESSAGE = 'iUPD'; SoftwareUpdaterWindow::SoftwareUpdaterWindow() : BWindow(BRect(0, 0, 500, 300), "Software Update", - B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE) + B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE), + fStripeView(NULL) { + BBitmap* icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32); + + team_info teamInfo; + get_team_info(B_CURRENT_TEAM, &teamInfo); + app_info appInfo; + be_roster->GetRunningAppInfo(teamInfo.team, &appInfo); + BNodeInfo::GetTrackerIcon(&appInfo.ref, icon, B_LARGE_ICON); + + fStripeView = new StripeView(icon); BStringView* introText = new BStringView("intro", "Software updates are available.", B_WILL_DRAW); + BFont font; + introText->GetFont(&font); + font.SetFace(B_BOLD_FACE); + font.SetSize(font.Size() * 1.5); + introText->SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE + | B_FONT_FLAGS); BButton* updateButton = new BButton("Apply Updates", new BMessage(UPDATE_MESSAGE)); - BLayoutBuilder::Group<>(this, B_VERTICAL, 0) - .AddGroup(B_VERTICAL, B_USE_ITEM_SPACING) - .SetInsets(B_USE_WINDOW_SPACING) + BLayoutBuilder::Group<>(this, B_HORIZONTAL, 0) + .Add(fStripeView) + .AddGroup(B_VERTICAL, B_USE_SMALL_SPACING) + .SetInsets(0, B_USE_DEFAULT_SPACING, + B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) + //.SetInsets(B_USE_WINDOW_SPACING) .Add(introText) .Add(updateButton) + .End() + .AddGlue() + //.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) ; CenterOnScreen(); Show(); diff --git a/src/apps/softwareupdater/SoftwareUpdaterWindow.h b/src/apps/softwareupdater/SoftwareUpdaterWindow.h index 2797530ac6..41e39820d0 100644 --- a/src/apps/softwareupdater/SoftwareUpdaterWindow.h +++ b/src/apps/softwareupdater/SoftwareUpdaterWindow.h @@ -9,14 +9,22 @@ #define _SOFTWARE_UPDATER_WINDOW_H +#include +#include #include +#include "StripeView.h" + class SoftwareUpdaterWindow : public BWindow { public: SoftwareUpdaterWindow(); ~SoftwareUpdaterWindow(); bool QuitRequested(); + +private: + StripeView* fStripeView; + app_info* fAppInfo; }; diff --git a/src/apps/softwareupdater/StripeView.cpp b/src/apps/softwareupdater/StripeView.cpp new file mode 100644 index 0000000000..de716283ff --- /dev/null +++ b/src/apps/softwareupdater/StripeView.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2007-2016 Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ryan Leavengood + * John Scipione + * Joseph Groover + */ + + +#include "StripeView.h" + + +static const float kStripeWidth = 30.0; + + +StripeView::StripeView(BBitmap* icon) + : + BView("StripeView", B_WILL_DRAW), + fIcon(icon) +{ + SetViewUIColor(B_PANEL_BACKGROUND_COLOR); + + float width = 0.0f; + if (icon != NULL) + width += icon->Bounds().Width() + 32.0f; + + SetExplicitMinSize(BSize(width, B_SIZE_UNSET)); + SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED)); +} + + +StripeView::~StripeView() +{ +} + + +void +StripeView::Draw(BRect updateRect) +{ + if (fIcon == NULL) + return; + + SetHighColor(ViewColor()); + FillRect(updateRect); + + BRect stripeRect = Bounds(); + stripeRect.right = kStripeWidth; + SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); + FillRect(stripeRect); + + SetDrawingMode(B_OP_ALPHA); + SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); + DrawBitmapAsync(fIcon, BPoint(15.0f, 10.0f)); +} + + +void +StripeView::SetIcon(BBitmap* icon) +{ + if (fIcon != NULL) + delete fIcon; + + fIcon = icon; + + float width = 0.0f; + if (icon != NULL) + width += icon->Bounds().Width() + 32.0f; + + SetExplicitMinSize(BSize(width, B_SIZE_UNSET)); + SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED)); +} diff --git a/src/apps/softwareupdater/StripeView.h b/src/apps/softwareupdater/StripeView.h new file mode 100644 index 0000000000..c03c3eeafa --- /dev/null +++ b/src/apps/softwareupdater/StripeView.h @@ -0,0 +1,33 @@ +/* + * Copyright 2007-2016 Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ryan Leavengood + * John Scipione + * Joseph Groover + */ +#ifndef _STRIPE_VIEW_H +#define _STRIPE_VIEW_H + + +#include +#include + + +class StripeView : public BView { +public: + StripeView(BBitmap* icon); + ~StripeView(); + + virtual void Draw(BRect updateRect); + + BBitmap* Icon() const { return fIcon; }; + void SetIcon(BBitmap* icon); + +private: + BBitmap* fIcon; +}; + + +#endif /* _STRIPE_VIEW_H */