SoftwareUpdater: Add a fancy looking stripe view

This commit is contained in:
Alexander von Gluck IV 2016-12-08 23:22:39 +00:00
parent f7d9c0110d
commit c5867c77cc
6 changed files with 144 additions and 6 deletions

View File

@ -5,6 +5,7 @@ UsePrivateHeaders interface shared ;
Application SoftwareUpdater :
SoftwareUpdaterApp.cpp
SoftwareUpdaterWindow.cpp
StripeView.cpp
: be localestub tracker translation [ TargetLibsupc++ ]
: SoftwareUpdater.rdef
;

View File

@ -9,7 +9,6 @@
#include "SoftwareUpdaterApp.h"
#include <stdio.h>
#include <AppDefs.h>
#include "SoftwareUpdaterWindow.h"

View File

@ -10,14 +10,16 @@
#include "SoftwareUpdaterWindow.h"
#include <stdio.h>
#include <AppDefs.h>
#include <Application.h>
#include <Button.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <NodeInfo.h>
#include <LayoutBuilder.h>
#include <Message.h>
#include <Resources.h>
#include <SeparatorView.h>
#include <StringView.h>
@ -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();

View File

@ -9,14 +9,22 @@
#define _SOFTWARE_UPDATER_WINDOW_H
#include <Roster.h>
#include <StatusBar.h>
#include <Window.h>
#include "StripeView.h"
class SoftwareUpdaterWindow : public BWindow {
public:
SoftwareUpdaterWindow();
~SoftwareUpdaterWindow();
bool QuitRequested();
private:
StripeView* fStripeView;
app_info* fAppInfo;
};

View File

@ -0,0 +1,73 @@
/*
* Copyright 2007-2016 Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ryan Leavengood <leavengood@gmail.com>
* John Scipione <jscipione@gmail.com>
* Joseph Groover <looncraz@looncraz.net>
*/
#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));
}

View File

@ -0,0 +1,33 @@
/*
* Copyright 2007-2016 Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ryan Leavengood <leavengood@gmail.com>
* John Scipione <jscipione@gmail.com>
* Joseph Groover <looncraz@looncraz.net>
*/
#ifndef _STRIPE_VIEW_H
#define _STRIPE_VIEW_H
#include <Bitmap.h>
#include <View.h>
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 */