* Changed the whole thing to use the layout engine, which makes it work okay
with larger font sizes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31099 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <Font.h>
|
#include <Font.h>
|
||||||
#include <fs_attr.h>
|
#include <fs_attr.h>
|
||||||
|
#include <LayoutBuilder.h>
|
||||||
#include <MessageRunner.h>
|
#include <MessageRunner.h>
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
@@ -67,71 +68,102 @@ static const rgb_color kLinkBlue = { 80, 80, 200, 255 };
|
|||||||
|
|
||||||
|
|
||||||
class AboutApp : public BApplication {
|
class AboutApp : public BApplication {
|
||||||
public:
|
public:
|
||||||
AboutApp();
|
AboutApp();
|
||||||
};
|
};
|
||||||
|
|
||||||
class AboutWindow : public BWindow {
|
class AboutWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
AboutWindow();
|
AboutWindow();
|
||||||
|
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
};
|
||||||
|
|
||||||
|
class LogoView : public BView {
|
||||||
|
public:
|
||||||
|
LogoView();
|
||||||
|
virtual ~LogoView();
|
||||||
|
|
||||||
|
virtual BSize MinSize();
|
||||||
|
virtual BSize MaxSize();
|
||||||
|
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BBitmap* fLogo;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CropView : public BView {
|
||||||
|
public:
|
||||||
|
CropView(BView* target, int32 left, int32 top,
|
||||||
|
int32 right, int32 bottom);
|
||||||
|
virtual ~CropView();
|
||||||
|
|
||||||
|
virtual BSize MinSize();
|
||||||
|
virtual BSize MaxSize();
|
||||||
|
|
||||||
|
virtual void DoLayout();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BView* fTarget;
|
||||||
|
int32 fCropLeft;
|
||||||
|
int32 fCropTop;
|
||||||
|
int32 fCropRight;
|
||||||
|
int32 fCropBottom;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AboutView : public BView {
|
class AboutView : public BView {
|
||||||
public:
|
public:
|
||||||
AboutView(const BRect& frame);
|
AboutView();
|
||||||
~AboutView();
|
~AboutView();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void Pulse();
|
virtual void Pulse();
|
||||||
|
|
||||||
virtual void FrameResized(float width, float height);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void MouseDown(BPoint point);
|
||||||
virtual void MessageReceived(BMessage* msg);
|
|
||||||
virtual void MouseDown(BPoint point);
|
|
||||||
|
|
||||||
void AddCopyrightEntry(const char* name,
|
void AddCopyrightEntry(const char* name,
|
||||||
const char* text,
|
const char* text,
|
||||||
const StringVector& licenses,
|
const StringVector& licenses,
|
||||||
const char* url);
|
const char* url);
|
||||||
void AddCopyrightEntry(const char* name,
|
void AddCopyrightEntry(const char* name,
|
||||||
const char* text, const char* url = NULL);
|
const char* text, const char* url = NULL);
|
||||||
void PickRandomHaiku();
|
void PickRandomHaiku();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<std::string, PackageCredit*> PackageCreditMap;
|
typedef std::map<std::string, PackageCredit*> PackageCreditMap;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _GetLicensePath(const char* license,
|
BView* _CreateLabel(const char* name, const char* label);
|
||||||
BPath& path);
|
BView* _CreateCreditsView();
|
||||||
void _AddCopyrightsFromAttribute();
|
status_t _GetLicensePath(const char* license,
|
||||||
void _AddPackageCredit(const PackageCredit& package);
|
BPath& path);
|
||||||
void _AddPackageCreditEntries();
|
void _AddCopyrightsFromAttribute();
|
||||||
|
void _AddPackageCredit(const PackageCredit& package);
|
||||||
|
void _AddPackageCreditEntries();
|
||||||
|
|
||||||
BStringView* fMemView;
|
BStringView* fMemView;
|
||||||
BTextView* fUptimeView;
|
BTextView* fUptimeView;
|
||||||
BView* fInfoView;
|
BView* fInfoView;
|
||||||
HyperTextView* fCreditsView;
|
HyperTextView* fCreditsView;
|
||||||
|
|
||||||
BBitmap* fLogo;
|
BBitmap* fLogo;
|
||||||
|
|
||||||
BPoint fDrawPoint;
|
bigtime_t fLastActionTime;
|
||||||
|
BMessageRunner* fScrollRunner;
|
||||||
bigtime_t fLastActionTime;
|
PackageCreditMap fPackageCredits;
|
||||||
BMessageRunner* fScrollRunner;
|
|
||||||
PackageCreditMap fPackageCredits;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
AboutApp::AboutApp(void)
|
AboutApp::AboutApp()
|
||||||
: BApplication("application/x-vnd.Haiku-About")
|
: BApplication("application/x-vnd.Haiku-About")
|
||||||
{
|
{
|
||||||
AboutWindow *window = new AboutWindow();
|
AboutWindow* window = new AboutWindow();
|
||||||
window->Show();
|
window->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,10 +173,15 @@ AboutApp::AboutApp(void)
|
|||||||
|
|
||||||
AboutWindow::AboutWindow()
|
AboutWindow::AboutWindow()
|
||||||
: BWindow(BRect(0, 0, 500, 300), "About This System", B_TITLED_WINDOW,
|
: BWindow(BRect(0, 0, 500, 300), "About This System", B_TITLED_WINDOW,
|
||||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE)
|
||||||
{
|
{
|
||||||
AboutView *view = new AboutView(Bounds());
|
SetLayout(new BGroupLayout(B_VERTICAL));
|
||||||
AddChild(view);
|
AddChild(new AboutView());
|
||||||
|
|
||||||
|
// Make sure we take the minimal window size into account when centering
|
||||||
|
BSize size = GetLayout()->MinSize();
|
||||||
|
ResizeTo(max_c(size.width, Bounds().Width()),
|
||||||
|
max_c(size.height, Bounds().Height()));
|
||||||
|
|
||||||
MoveTo((BScreen().Frame().Width() - Bounds().Width()) / 2,
|
MoveTo((BScreen().Frame().Width() - Bounds().Width()) / 2,
|
||||||
(BScreen().Frame().Height() - Bounds().Height()) / 2 );
|
(BScreen().Frame().Height() - Bounds().Height()) / 2 );
|
||||||
@@ -159,58 +196,136 @@ AboutWindow::QuitRequested()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AboutView::AboutView(const BRect &rect)
|
// #pragma mark - LogoView
|
||||||
: BView(rect, "aboutview", B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED),
|
|
||||||
|
|
||||||
|
LogoView::LogoView()
|
||||||
|
: BView("logo", B_WILL_DRAW)
|
||||||
|
{
|
||||||
|
fLogo = BTranslationUtils::GetBitmap(B_PNG_FORMAT, "haikulogo.png");
|
||||||
|
SetViewColor(255, 255, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LogoView::~LogoView()
|
||||||
|
{
|
||||||
|
delete fLogo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
LogoView::MinSize()
|
||||||
|
{
|
||||||
|
if (fLogo == NULL)
|
||||||
|
return BSize(0, 0);
|
||||||
|
|
||||||
|
return BSize(fLogo->Bounds().Width(), fLogo->Bounds().Height());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
LogoView::MaxSize()
|
||||||
|
{
|
||||||
|
if (fLogo == NULL)
|
||||||
|
return BSize(0, 0);
|
||||||
|
|
||||||
|
return BSize(B_SIZE_UNLIMITED, fLogo->Bounds().Height());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LogoView::Draw(BRect updateRect)
|
||||||
|
{
|
||||||
|
if (fLogo != NULL) {
|
||||||
|
DrawBitmap(fLogo,
|
||||||
|
BPoint((Bounds().Width() - fLogo->Bounds().Width()) / 2, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - CropView
|
||||||
|
|
||||||
|
|
||||||
|
CropView::CropView(BView* target, int32 left, int32 top, int32 right,
|
||||||
|
int32 bottom)
|
||||||
|
: BView("crop view", 0),
|
||||||
|
fTarget(target),
|
||||||
|
fCropLeft(left),
|
||||||
|
fCropTop(top),
|
||||||
|
fCropRight(right),
|
||||||
|
fCropBottom(bottom)
|
||||||
|
{
|
||||||
|
AddChild(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CropView::~CropView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
CropView::MinSize()
|
||||||
|
{
|
||||||
|
if (fTarget == NULL)
|
||||||
|
return BSize();
|
||||||
|
|
||||||
|
BSize size = fTarget->MinSize();
|
||||||
|
if (size.width != B_SIZE_UNSET)
|
||||||
|
size.width -= fCropLeft + fCropRight;
|
||||||
|
if (size.height != B_SIZE_UNSET)
|
||||||
|
size.height -= fCropTop + fCropBottom;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
CropView::MaxSize()
|
||||||
|
{
|
||||||
|
if (fTarget == NULL)
|
||||||
|
return BSize();
|
||||||
|
|
||||||
|
BSize size = fTarget->MaxSize();
|
||||||
|
if (size.width != B_SIZE_UNSET)
|
||||||
|
size.width -= fCropLeft + fCropRight;
|
||||||
|
if (size.height != B_SIZE_UNSET)
|
||||||
|
size.height -= fCropTop + fCropBottom;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CropView::DoLayout()
|
||||||
|
{
|
||||||
|
BView::DoLayout();
|
||||||
|
|
||||||
|
if (fTarget == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fTarget->MoveTo(-fCropLeft, -fCropTop);
|
||||||
|
fTarget->ResizeTo(Bounds().Width() + fCropLeft + fCropRight,
|
||||||
|
Bounds().Height() + fCropTop + fCropBottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - AboutView
|
||||||
|
|
||||||
|
|
||||||
|
AboutView::AboutView()
|
||||||
|
: BView("aboutview", B_WILL_DRAW | B_PULSE_NEEDED),
|
||||||
fLastActionTime(system_time()),
|
fLastActionTime(system_time()),
|
||||||
fScrollRunner(NULL)
|
fScrollRunner(NULL)
|
||||||
{
|
{
|
||||||
fLogo = BTranslationUtils::GetBitmap(B_PNG_FORMAT, "haikulogo.png");
|
|
||||||
if (fLogo) {
|
|
||||||
fDrawPoint.x = (225-fLogo->Bounds().Width()) / 2;
|
|
||||||
fDrawPoint.y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Begin Construction of System Information controls
|
// Begin Construction of System Information controls
|
||||||
|
|
||||||
font_height height;
|
|
||||||
float labelHeight, textHeight;
|
|
||||||
|
|
||||||
system_info systemInfo;
|
system_info systemInfo;
|
||||||
get_system_info(&systemInfo);
|
get_system_info(&systemInfo);
|
||||||
|
|
||||||
be_plain_font->GetHeight(&height);
|
// Create all the various labels for system infomation
|
||||||
textHeight = height.ascent + height.descent + height.leading;
|
|
||||||
|
|
||||||
be_bold_font->GetHeight(&height);
|
|
||||||
labelHeight = height.ascent + height.descent + height.leading;
|
|
||||||
|
|
||||||
BRect r(0, 0, 225, Bounds().bottom);
|
|
||||||
if (fLogo)
|
|
||||||
r.OffsetBy(0, fLogo->Bounds().Height());
|
|
||||||
|
|
||||||
fInfoView = new BView(r, "infoview", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
|
|
||||||
B_WILL_DRAW);
|
|
||||||
fInfoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
fInfoView->SetLowColor(fInfoView->ViewColor());
|
|
||||||
fInfoView->SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
|
|
||||||
AddChild(fInfoView);
|
|
||||||
|
|
||||||
// Add all the various labels for system infomation
|
|
||||||
|
|
||||||
BStringView *stringView;
|
|
||||||
|
|
||||||
// OS Version
|
// OS Version
|
||||||
r.Set(5, 5, 224, labelHeight + 5);
|
|
||||||
stringView = new BStringView(r, "oslabel", "Version:");
|
|
||||||
stringView->SetFont(be_bold_font);
|
|
||||||
fInfoView->AddChild(stringView);
|
|
||||||
stringView->ResizeToPreferred();
|
|
||||||
|
|
||||||
// we update "labelHeight" to the actual height of the string view
|
|
||||||
labelHeight = stringView->Bounds().Height();
|
|
||||||
|
|
||||||
r.OffsetBy(0, labelHeight);
|
|
||||||
r.bottom = r.top + textHeight;
|
|
||||||
|
|
||||||
char string[1024];
|
char string[1024];
|
||||||
strcpy(string, "Unknown");
|
strcpy(string, "Unknown");
|
||||||
@@ -244,9 +359,9 @@ AboutView::AboutView(const BRect &rect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stringView = new BStringView(r, "ostext", string);
|
BStringView* versionView = new BStringView("ostext", string);
|
||||||
fInfoView->AddChild(stringView);
|
versionView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
||||||
stringView->ResizeToPreferred();
|
B_ALIGN_VERTICAL_UNSET));
|
||||||
|
|
||||||
// GCC version
|
// GCC version
|
||||||
#if __GNUC__ != 2
|
#if __GNUC__ != 2
|
||||||
@@ -255,37 +370,26 @@ AboutView::AboutView(const BRect &rect)
|
|||||||
|
|
||||||
snprintf(string, sizeof(string), "GCC %d", __GNUC__);
|
snprintf(string, sizeof(string), "GCC %d", __GNUC__);
|
||||||
|
|
||||||
stringView = new BStringView(r, "gcctext", string);
|
BStringView* gccView = new BStringView("gcctext", string);
|
||||||
fInfoView->AddChild(stringView);
|
gccView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
||||||
stringView->ResizeToPreferred();
|
B_ALIGN_VERTICAL_UNSET));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// CPU count, type and clock speed
|
// CPU count, type and clock speed
|
||||||
r.OffsetBy(0, textHeight * 1.5);
|
char processorLabel[256];
|
||||||
r.bottom = r.top + labelHeight;
|
if (systemInfo.cpu_count > 1) {
|
||||||
|
snprintf(processorLabel, sizeof(processorLabel), "%ld Processors:",
|
||||||
if (systemInfo.cpu_count > 1)
|
systemInfo.cpu_count);
|
||||||
sprintf(string, "%ld Processors:", systemInfo.cpu_count);
|
} else
|
||||||
else
|
strlcpy(processorLabel, "Processor:", sizeof(processorLabel));
|
||||||
strcpy(string, "Processor:");
|
|
||||||
|
|
||||||
stringView = new BStringView(r, "cpulabel", string);
|
|
||||||
stringView->SetFont(be_bold_font);
|
|
||||||
fInfoView->AddChild(stringView);
|
|
||||||
stringView->ResizeToPreferred();
|
|
||||||
|
|
||||||
BString cpuType;
|
BString cpuType;
|
||||||
cpuType << get_cpu_vendor_string(systemInfo.cpu_type)
|
cpuType << get_cpu_vendor_string(systemInfo.cpu_type)
|
||||||
<< " " << get_cpu_model_string(&systemInfo);
|
<< " " << get_cpu_model_string(&systemInfo);
|
||||||
|
|
||||||
r.OffsetBy(0, labelHeight);
|
BStringView* cpuView = new BStringView("cputext", cpuType.String());
|
||||||
r.bottom = r.top + textHeight;
|
cpuView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
||||||
stringView = new BStringView(r, "cputext", cpuType.String());
|
B_ALIGN_VERTICAL_UNSET));
|
||||||
fInfoView->AddChild(stringView);
|
|
||||||
stringView->ResizeToPreferred();
|
|
||||||
|
|
||||||
r.OffsetBy(0, textHeight);
|
|
||||||
r.bottom = r.top + textHeight;
|
|
||||||
|
|
||||||
int32 clockSpeed = get_rounded_cpu_speed();
|
int32 clockSpeed = get_rounded_cpu_speed();
|
||||||
if (clockSpeed < 1000)
|
if (clockSpeed < 1000)
|
||||||
@@ -293,80 +397,274 @@ AboutView::AboutView(const BRect &rect)
|
|||||||
else
|
else
|
||||||
sprintf(string,"%.2f GHz", clockSpeed / 1000.0f);
|
sprintf(string,"%.2f GHz", clockSpeed / 1000.0f);
|
||||||
|
|
||||||
stringView = new BStringView(r, "mhztext", string);
|
BStringView* frequencyView = new BStringView("frequencytext", string);
|
||||||
fInfoView->AddChild(stringView);
|
frequencyView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
||||||
stringView->ResizeToPreferred();
|
B_ALIGN_VERTICAL_UNSET));
|
||||||
|
|
||||||
// RAM
|
// RAM
|
||||||
r.OffsetBy(0, textHeight * 1.5);
|
fMemView = new BStringView("ramtext",
|
||||||
r.bottom = r.top + labelHeight;
|
MemUsageToString(string, sizeof(string), &systemInfo));
|
||||||
stringView = new BStringView(r, "ramlabel", "Memory:");
|
fMemView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
||||||
stringView->SetFont(be_bold_font);
|
B_ALIGN_VERTICAL_UNSET));
|
||||||
fInfoView->AddChild(stringView);
|
|
||||||
stringView->ResizeToPreferred();
|
|
||||||
|
|
||||||
r.OffsetBy(0, labelHeight);
|
|
||||||
r.bottom = r.top + textHeight;
|
|
||||||
|
|
||||||
fMemView = new BStringView(r, "ramtext", "");
|
|
||||||
fInfoView->AddChild(fMemView);
|
|
||||||
fMemView->SetText(MemUsageToString(string, sizeof(string), &systemInfo));
|
|
||||||
|
|
||||||
// Kernel build time/date
|
// Kernel build time/date
|
||||||
r.OffsetBy(0, textHeight * 1.5);
|
|
||||||
r.bottom = r.top + labelHeight;
|
|
||||||
stringView = new BStringView(r, "kernellabel", "Kernel:");
|
|
||||||
stringView->SetFont(be_bold_font);
|
|
||||||
fInfoView->AddChild(stringView);
|
|
||||||
stringView->ResizeToPreferred();
|
|
||||||
|
|
||||||
r.OffsetBy(0, labelHeight);
|
|
||||||
r.bottom = r.top + textHeight;
|
|
||||||
|
|
||||||
snprintf(string, sizeof(string), "%s %s",
|
snprintf(string, sizeof(string), "%s %s",
|
||||||
systemInfo.kernel_build_date, systemInfo.kernel_build_time);
|
systemInfo.kernel_build_date, systemInfo.kernel_build_time);
|
||||||
|
|
||||||
stringView = new BStringView(r, "kerneltext", string);
|
BStringView* kernelView = new BStringView("kerneltext", string);
|
||||||
fInfoView->AddChild(stringView);
|
kernelView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
||||||
stringView->ResizeToPreferred();
|
B_ALIGN_VERTICAL_UNSET));
|
||||||
|
|
||||||
// Uptime
|
// Uptime
|
||||||
r.OffsetBy(0, textHeight * 1.5);
|
fUptimeView = new BTextView("uptimetext");
|
||||||
r.bottom = r.top + labelHeight;
|
|
||||||
stringView = new BStringView(r, "uptimelabel", "Time Running:");
|
|
||||||
stringView->SetFont(be_bold_font);
|
|
||||||
fInfoView->AddChild(stringView);
|
|
||||||
stringView->ResizeToPreferred();
|
|
||||||
|
|
||||||
r.OffsetBy(0, labelHeight);
|
|
||||||
r.bottom = r.top + textHeight * 3;
|
|
||||||
|
|
||||||
fUptimeView = new BTextView(r, "uptimetext", r.OffsetToCopy(0,0), B_FOLLOW_ALL);
|
|
||||||
fUptimeView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fUptimeView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
fUptimeView->MakeEditable(false);
|
fUptimeView->MakeEditable(false);
|
||||||
fUptimeView->MakeSelectable(false);
|
fUptimeView->MakeSelectable(false);
|
||||||
fUptimeView->SetWordWrap(true);
|
fUptimeView->SetWordWrap(true);
|
||||||
fInfoView->AddChild(fUptimeView);
|
|
||||||
// string width changes, so we don't do ResizeToPreferred()
|
|
||||||
|
|
||||||
fUptimeView->SetText(UptimeToString(string, sizeof(string)));
|
fUptimeView->SetText(UptimeToString(string, sizeof(string)));
|
||||||
|
|
||||||
// Begin construction of the credits view
|
const float offset = 5;
|
||||||
r = Bounds();
|
|
||||||
r.left += fInfoView->Bounds().right + 1;
|
|
||||||
r.right -= B_V_SCROLL_BAR_WIDTH;
|
|
||||||
|
|
||||||
fCreditsView = new HyperTextView(r, "credits",
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
r.OffsetToCopy(0, 0).InsetByCopy(5, 5), B_FOLLOW_ALL);
|
|
||||||
fCreditsView->SetFlags(fCreditsView->Flags() | B_FRAME_EVENTS );
|
BLayoutBuilder::Group<>((BGroupLayout*)GetLayout())
|
||||||
|
.AddGroup(B_VERTICAL)
|
||||||
|
.Add(new LogoView())
|
||||||
|
.AddGroup(B_VERTICAL)
|
||||||
|
.Add(_CreateLabel("oslabel", "Version:"))
|
||||||
|
.Add(versionView)
|
||||||
|
#if __GNUC__ != 2
|
||||||
|
.Add(gccView)
|
||||||
|
#endif
|
||||||
|
.AddStrut(offset)
|
||||||
|
.Add(_CreateLabel("cpulabel", processorLabel))
|
||||||
|
.Add(cpuView)
|
||||||
|
.Add(frequencyView)
|
||||||
|
.AddStrut(offset)
|
||||||
|
.Add(_CreateLabel("memlabel", "Memory:"))
|
||||||
|
.Add(fMemView)
|
||||||
|
.AddStrut(offset)
|
||||||
|
.Add(_CreateLabel("kernellabel", "Kernel:"))
|
||||||
|
.Add(kernelView)
|
||||||
|
.AddStrut(offset)
|
||||||
|
.Add(_CreateLabel("uptimelabel", "Time Running:"))
|
||||||
|
.Add(fUptimeView)
|
||||||
|
.SetInsets(5, 5, 5, 5)
|
||||||
|
.End()
|
||||||
|
// TODO: investigate: adding this causes the time to be cut
|
||||||
|
//.AddGlue()
|
||||||
|
.End()
|
||||||
|
.Add(_CreateCreditsView());
|
||||||
|
|
||||||
|
float min = fMemView->MinSize().width * 1.1f;
|
||||||
|
fCreditsView->SetExplicitMinSize(BSize(min, min));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AboutView::~AboutView()
|
||||||
|
{
|
||||||
|
delete fScrollRunner;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AboutView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
BView::AttachedToWindow();
|
||||||
|
Window()->SetPulseRate(500000);
|
||||||
|
SetEventMask(B_POINTER_EVENTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AboutView::MouseDown(BPoint point)
|
||||||
|
{
|
||||||
|
BRect r(92, 26, 105, 31);
|
||||||
|
if (r.Contains(point)) {
|
||||||
|
printf("Easter Egg\n");
|
||||||
|
PickRandomHaiku();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Bounds().Contains(point)) {
|
||||||
|
fLastActionTime = system_time();
|
||||||
|
delete fScrollRunner;
|
||||||
|
fScrollRunner = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AboutView::Pulse()
|
||||||
|
{
|
||||||
|
char string[255];
|
||||||
|
system_info info;
|
||||||
|
get_system_info(&info);
|
||||||
|
fUptimeView->SetText(UptimeToString(string, sizeof(string)));
|
||||||
|
fMemView->SetText(MemUsageToString(string, sizeof(string), &info));
|
||||||
|
|
||||||
|
if (fScrollRunner == NULL && system_time() > fLastActionTime + 10000000) {
|
||||||
|
BMessage message(SCROLL_CREDITS_VIEW);
|
||||||
|
//fScrollRunner = new BMessageRunner(this, &message, 25000, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AboutView::MessageReceived(BMessage *msg)
|
||||||
|
{
|
||||||
|
switch (msg->what) {
|
||||||
|
case SCROLL_CREDITS_VIEW:
|
||||||
|
{
|
||||||
|
BScrollBar *scrollBar = fCreditsView->ScrollBar(B_VERTICAL);
|
||||||
|
if (scrollBar == NULL)
|
||||||
|
break;
|
||||||
|
float max, min;
|
||||||
|
scrollBar->GetRange(&min, &max);
|
||||||
|
if (scrollBar->Value() < max)
|
||||||
|
fCreditsView->ScrollBy(0, 1);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AboutView::AddCopyrightEntry(const char *name, const char *text,
|
||||||
|
const char *url)
|
||||||
|
{
|
||||||
|
AddCopyrightEntry(name, text, StringVector(), url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AboutView::AddCopyrightEntry(const char *name, const char *text,
|
||||||
|
const StringVector& licenses, const char *url)
|
||||||
|
{
|
||||||
|
BFont font(be_bold_font);
|
||||||
|
//font.SetSize(be_bold_font->Size());
|
||||||
|
font.SetFace(B_BOLD_FACE | B_ITALIC_FACE);
|
||||||
|
|
||||||
|
fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuYellow);
|
||||||
|
fCreditsView->Insert(name);
|
||||||
|
fCreditsView->Insert("\n");
|
||||||
|
fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey);
|
||||||
|
fCreditsView->Insert(text);
|
||||||
|
fCreditsView->Insert("\n");
|
||||||
|
|
||||||
|
if (licenses.CountStrings() > 0) {
|
||||||
|
if (licenses.CountStrings() > 1)
|
||||||
|
fCreditsView->Insert("Licenses: ");
|
||||||
|
else
|
||||||
|
fCreditsView->Insert("License: ");
|
||||||
|
|
||||||
|
for (int32 i = 0; i < licenses.CountStrings(); i++) {
|
||||||
|
const char* license = licenses.StringAt(i);
|
||||||
|
|
||||||
|
if (i > 0)
|
||||||
|
fCreditsView->Insert(", ");
|
||||||
|
|
||||||
|
BPath licensePath;
|
||||||
|
if (_GetLicensePath(license, licensePath) == B_OK) {
|
||||||
|
fCreditsView->InsertHyperText(license,
|
||||||
|
new OpenFileAction(licensePath.Path()));
|
||||||
|
} else
|
||||||
|
fCreditsView->Insert(license);
|
||||||
|
}
|
||||||
|
|
||||||
|
fCreditsView->Insert("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kLinkBlue);
|
||||||
|
fCreditsView->InsertHyperText(url, new URLAction(url));
|
||||||
|
fCreditsView->Insert("\n");
|
||||||
|
}
|
||||||
|
fCreditsView->Insert("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AboutView::PickRandomHaiku()
|
||||||
|
{
|
||||||
|
BFile fortunes(
|
||||||
|
#ifdef __HAIKU__
|
||||||
|
"/etc/fortunes/Haiku",
|
||||||
|
#else
|
||||||
|
"data/etc/fortunes/Haiku",
|
||||||
|
#endif
|
||||||
|
B_READ_ONLY);
|
||||||
|
struct stat st;
|
||||||
|
if (fortunes.InitCheck() < B_OK)
|
||||||
|
return;
|
||||||
|
if (fortunes.GetStat(&st) < B_OK)
|
||||||
|
return;
|
||||||
|
char *buff = (char *)malloc((size_t)st.st_size + 1);
|
||||||
|
if (!buff)
|
||||||
|
return;
|
||||||
|
buff[(size_t)st.st_size] = '\0';
|
||||||
|
BList haikuList;
|
||||||
|
if (fortunes.Read(buff, (size_t)st.st_size) == (ssize_t)st.st_size) {
|
||||||
|
char *p = buff;
|
||||||
|
while (p && *p) {
|
||||||
|
char *e = strchr(p, '%');
|
||||||
|
BString *s = new BString(p, e ? (e - p) : -1);
|
||||||
|
haikuList.AddItem(s);
|
||||||
|
p = e;
|
||||||
|
if (p && (*p == '%'))
|
||||||
|
p++;
|
||||||
|
if (p && (*p == '\n'))
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(buff);
|
||||||
|
if (haikuList.CountItems() < 1)
|
||||||
|
return;
|
||||||
|
BString *s = (BString *)haikuList.ItemAt(rand() % haikuList.CountItems());
|
||||||
|
BFont font(be_bold_font);
|
||||||
|
font.SetSize(be_bold_font->Size());
|
||||||
|
font.SetFace(B_BOLD_FACE | B_ITALIC_FACE);
|
||||||
|
fCreditsView->SelectAll();
|
||||||
|
fCreditsView->Delete();
|
||||||
|
fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kDarkGrey);
|
||||||
|
fCreditsView->Insert(s->String());
|
||||||
|
fCreditsView->Insert("\n");
|
||||||
|
while ((s = (BString *)haikuList.RemoveItem((int32)0))) {
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BView*
|
||||||
|
AboutView::_CreateLabel(const char* name, const char* label)
|
||||||
|
{
|
||||||
|
BStringView* labelView = new BStringView(name, label);
|
||||||
|
labelView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
||||||
|
B_ALIGN_VERTICAL_UNSET));
|
||||||
|
labelView->SetFont(be_bold_font);
|
||||||
|
return labelView;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BView*
|
||||||
|
AboutView::_CreateCreditsView()
|
||||||
|
{
|
||||||
|
// Begin construction of the credits view
|
||||||
|
fCreditsView = new HyperTextView("credits");
|
||||||
|
fCreditsView->SetFlags(fCreditsView->Flags() | B_FRAME_EVENTS);
|
||||||
fCreditsView->SetStylable(true);
|
fCreditsView->SetStylable(true);
|
||||||
fCreditsView->MakeEditable(false);
|
fCreditsView->MakeEditable(false);
|
||||||
fCreditsView->SetWordWrap(true);
|
fCreditsView->SetWordWrap(true);
|
||||||
|
fCreditsView->SetInsets(5, 5, 5, 5);
|
||||||
|
|
||||||
BScrollView *creditsScroller = new BScrollView("creditsScroller",
|
BScrollView* creditsScroller = new BScrollView("creditsScroller",
|
||||||
fCreditsView, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true,
|
fCreditsView, B_WILL_DRAW | B_FRAME_EVENTS, false, true,
|
||||||
B_PLAIN_BORDER);
|
B_PLAIN_BORDER);
|
||||||
AddChild(creditsScroller);
|
|
||||||
|
|
||||||
// Haiku copyright
|
// Haiku copyright
|
||||||
BFont font(be_bold_font);
|
BFont font(be_bold_font);
|
||||||
@@ -375,6 +673,7 @@ AboutView::AboutView(const BRect &rect)
|
|||||||
fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuGreen);
|
fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuGreen);
|
||||||
fCreditsView->Insert("Haiku\n");
|
fCreditsView->Insert("Haiku\n");
|
||||||
|
|
||||||
|
char string[1024];
|
||||||
time_t time = ::time(NULL);
|
time_t time = ::time(NULL);
|
||||||
struct tm* tm = localtime(&time);
|
struct tm* tm = localtime(&time);
|
||||||
int32 year = tm->tm_year + 1900;
|
int32 year = tm->tm_year + 1900;
|
||||||
@@ -857,202 +1156,8 @@ AboutView::AboutView(const BRect &rect)
|
|||||||
|
|
||||||
_AddCopyrightsFromAttribute();
|
_AddCopyrightsFromAttribute();
|
||||||
_AddPackageCreditEntries();
|
_AddPackageCreditEntries();
|
||||||
}
|
|
||||||
|
|
||||||
|
return new CropView(creditsScroller, 0, 1, 1, 1);
|
||||||
AboutView::~AboutView(void)
|
|
||||||
{
|
|
||||||
delete fScrollRunner;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AboutView::AttachedToWindow(void)
|
|
||||||
{
|
|
||||||
BView::AttachedToWindow();
|
|
||||||
Window()->SetPulseRate(500000);
|
|
||||||
SetEventMask(B_POINTER_EVENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AboutView::MouseDown(BPoint pt)
|
|
||||||
{
|
|
||||||
BRect r(92, 26, 105, 31);
|
|
||||||
if (r.Contains(pt)) {
|
|
||||||
printf("Easter Egg\n");
|
|
||||||
PickRandomHaiku();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bounds().Contains(pt)) {
|
|
||||||
fLastActionTime = system_time();
|
|
||||||
delete fScrollRunner;
|
|
||||||
fScrollRunner = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AboutView::FrameResized(float width, float height)
|
|
||||||
{
|
|
||||||
BRect r = fCreditsView->Bounds();
|
|
||||||
r.OffsetTo(B_ORIGIN);
|
|
||||||
r.InsetBy(3, 3);
|
|
||||||
fCreditsView->SetTextRect(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AboutView::Draw(BRect update)
|
|
||||||
{
|
|
||||||
if (fLogo)
|
|
||||||
DrawBitmap(fLogo, fDrawPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AboutView::Pulse(void)
|
|
||||||
{
|
|
||||||
char string[255];
|
|
||||||
system_info info;
|
|
||||||
get_system_info(&info);
|
|
||||||
fUptimeView->SetText(UptimeToString(string, sizeof(string)));
|
|
||||||
fMemView->SetText(MemUsageToString(string, sizeof(string), &info));
|
|
||||||
|
|
||||||
if (fScrollRunner == NULL && (system_time() > fLastActionTime + 10000000)) {
|
|
||||||
BMessage message(SCROLL_CREDITS_VIEW);
|
|
||||||
//fScrollRunner = new BMessageRunner(this, &message, 300000, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AboutView::MessageReceived(BMessage *msg)
|
|
||||||
{
|
|
||||||
switch (msg->what) {
|
|
||||||
case SCROLL_CREDITS_VIEW:
|
|
||||||
{
|
|
||||||
BScrollBar *scrollBar = fCreditsView->ScrollBar(B_VERTICAL);
|
|
||||||
if (scrollBar == NULL)
|
|
||||||
break;
|
|
||||||
float max, min;
|
|
||||||
scrollBar->GetRange(&min, &max);
|
|
||||||
if (scrollBar->Value() < max)
|
|
||||||
fCreditsView->ScrollBy(0, 5);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
BView::MessageReceived(msg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AboutView::AddCopyrightEntry(const char *name, const char *text,
|
|
||||||
const char *url)
|
|
||||||
{
|
|
||||||
AddCopyrightEntry(name, text, StringVector(), url);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AboutView::AddCopyrightEntry(const char *name, const char *text,
|
|
||||||
const StringVector& licenses, const char *url)
|
|
||||||
{
|
|
||||||
BFont font(be_bold_font);
|
|
||||||
//font.SetSize(be_bold_font->Size());
|
|
||||||
font.SetFace(B_BOLD_FACE | B_ITALIC_FACE);
|
|
||||||
|
|
||||||
fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuYellow);
|
|
||||||
fCreditsView->Insert(name);
|
|
||||||
fCreditsView->Insert("\n");
|
|
||||||
fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey);
|
|
||||||
fCreditsView->Insert(text);
|
|
||||||
fCreditsView->Insert("\n");
|
|
||||||
|
|
||||||
if (licenses.CountStrings() > 0) {
|
|
||||||
if (licenses.CountStrings() > 1)
|
|
||||||
fCreditsView->Insert("Licenses: ");
|
|
||||||
else
|
|
||||||
fCreditsView->Insert("License: ");
|
|
||||||
|
|
||||||
for (int32 i = 0; i < licenses.CountStrings(); i++) {
|
|
||||||
const char* license = licenses.StringAt(i);
|
|
||||||
|
|
||||||
if (i > 0)
|
|
||||||
fCreditsView->Insert(", ");
|
|
||||||
|
|
||||||
BPath licensePath;
|
|
||||||
if (_GetLicensePath(license, licensePath) == B_OK) {
|
|
||||||
fCreditsView->InsertHyperText(license,
|
|
||||||
new OpenFileAction(licensePath.Path()));
|
|
||||||
} else
|
|
||||||
fCreditsView->Insert(license);
|
|
||||||
}
|
|
||||||
|
|
||||||
fCreditsView->Insert("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url) {
|
|
||||||
fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kLinkBlue);
|
|
||||||
fCreditsView->InsertHyperText(url, new URLAction(url));
|
|
||||||
fCreditsView->Insert("\n");
|
|
||||||
}
|
|
||||||
fCreditsView->Insert("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AboutView::PickRandomHaiku()
|
|
||||||
{
|
|
||||||
BFile fortunes(
|
|
||||||
#ifdef __HAIKU__
|
|
||||||
"/etc/fortunes/Haiku",
|
|
||||||
#else
|
|
||||||
"data/etc/fortunes/Haiku",
|
|
||||||
#endif
|
|
||||||
B_READ_ONLY);
|
|
||||||
struct stat st;
|
|
||||||
if (fortunes.InitCheck() < B_OK)
|
|
||||||
return;
|
|
||||||
if (fortunes.GetStat(&st) < B_OK)
|
|
||||||
return;
|
|
||||||
char *buff = (char *)malloc((size_t)st.st_size + 1);
|
|
||||||
if (!buff)
|
|
||||||
return;
|
|
||||||
buff[(size_t)st.st_size] = '\0';
|
|
||||||
BList haikuList;
|
|
||||||
if (fortunes.Read(buff, (size_t)st.st_size) == (ssize_t)st.st_size) {
|
|
||||||
char *p = buff;
|
|
||||||
while (p && *p) {
|
|
||||||
char *e = strchr(p, '%');
|
|
||||||
BString *s = new BString(p, e ? (e - p) : -1);
|
|
||||||
haikuList.AddItem(s);
|
|
||||||
p = e;
|
|
||||||
if (p && (*p == '%'))
|
|
||||||
p++;
|
|
||||||
if (p && (*p == '\n'))
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(buff);
|
|
||||||
if (haikuList.CountItems() < 1)
|
|
||||||
return;
|
|
||||||
BString *s = (BString *)haikuList.ItemAt(rand() % haikuList.CountItems());
|
|
||||||
BFont font(be_bold_font);
|
|
||||||
font.SetSize(be_bold_font->Size());
|
|
||||||
font.SetFace(B_BOLD_FACE | B_ITALIC_FACE);
|
|
||||||
fCreditsView->SelectAll();
|
|
||||||
fCreditsView->Delete();
|
|
||||||
fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kDarkGrey);
|
|
||||||
fCreditsView->Insert(s->String());
|
|
||||||
fCreditsView->Insert("\n");
|
|
||||||
while ((s = (BString *)haikuList.RemoveItem((int32)0))) {
|
|
||||||
delete s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
HyperTextView::HyperTextView(const char* name, uint32 flags)
|
||||||
|
:
|
||||||
|
BTextView(name, flags),
|
||||||
|
fActionInfos(new ActionInfoList(100, true))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
HyperTextView::HyperTextView(BRect frame, const char* name, BRect textRect,
|
HyperTextView::HyperTextView(BRect frame, const char* name, BRect textRect,
|
||||||
uint32 resizeMask, uint32 flags)
|
uint32 resizeMask, uint32 flags)
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ public:
|
|||||||
|
|
||||||
class HyperTextView : public BTextView {
|
class HyperTextView : public BTextView {
|
||||||
public:
|
public:
|
||||||
|
HyperTextView(const char* name,
|
||||||
|
uint32 flags = B_WILL_DRAW
|
||||||
|
| B_PULSE_NEEDED);
|
||||||
HyperTextView(BRect frame, const char* name,
|
HyperTextView(BRect frame, const char* name,
|
||||||
BRect textRect, uint32 resizeMask,
|
BRect textRect, uint32 resizeMask,
|
||||||
uint32 flags = B_WILL_DRAW
|
uint32 flags = B_WILL_DRAW
|
||||||
|
|||||||
Reference in New Issue
Block a user