Convert PreviewView to layout kit
* Use a BGroupLayout with insets to make space for the monitor drawing * Don't put the "no preview available" inside the view passed to screensavers, this could confuse them * Have the actual preview area (not including borders) be 160x120
This commit is contained in:
@@ -13,9 +13,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
|
#include <GroupLayout.h>
|
||||||
#include <Point.h>
|
#include <Point.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <Size.h>
|
#include <Size.h>
|
||||||
|
#include <StringView.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
@@ -53,18 +55,16 @@ scale2(int x1, int x2, int y1, int y2, BRect area)
|
|||||||
|
|
||||||
PreviewView::PreviewView(const char* name)
|
PreviewView::PreviewView(const char* name)
|
||||||
:
|
:
|
||||||
BView(name, B_WILL_DRAW),
|
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||||
fSaverView(NULL),
|
fSaverView(NULL),
|
||||||
fNoPreview(NULL)
|
fNoPreview(NULL)
|
||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
float aspectRatio = 4.0f / 3.0f;
|
BGroupLayout* layout = new BGroupLayout(B_VERTICAL);
|
||||||
// 4:3 monitor
|
// We draw the "monitor" around the preview, hence the strange insets.
|
||||||
float previewWidth = 160.0f;
|
layout->SetInsets(10, 8, 11, 16);
|
||||||
float previewHeight = ceilf(previewWidth / aspectRatio);
|
SetLayout(layout);
|
||||||
|
|
||||||
SetExplicitSize(BSize(previewWidth, previewHeight));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,28 +107,32 @@ PreviewView::Draw(BRect updateRect)
|
|||||||
BView*
|
BView*
|
||||||
PreviewView::AddPreview()
|
PreviewView::AddPreview()
|
||||||
{
|
{
|
||||||
BRect rect(scale2(1, 8, 1, 2, Bounds()).InsetBySelf(1.0f, 1.0f));
|
fSaverView = new BView("preview", B_WILL_DRAW);
|
||||||
fSaverView = new BView(rect, "preview", B_FOLLOW_NONE, B_WILL_DRAW);
|
|
||||||
fSaverView->SetViewColor(0, 0, 0);
|
fSaverView->SetViewColor(0, 0, 0);
|
||||||
fSaverView->SetLowColor(0, 0, 0);
|
fSaverView->SetLowColor(0, 0, 0);
|
||||||
AddChild(fSaverView);
|
AddChild(fSaverView);
|
||||||
|
|
||||||
BRect textRect(rect);
|
float aspectRatio = 4.0f / 3.0f;
|
||||||
textRect.OffsetTo(-7.0f, 0.0f);
|
// 4:3 monitor
|
||||||
textRect.InsetBy(15.0f, 20.0f);
|
float previewWidth = 160.0f;
|
||||||
fNoPreview = new BTextView(rect, "no preview", textRect, B_FOLLOW_NONE,
|
float previewHeight = ceilf(previewWidth / aspectRatio);
|
||||||
B_WILL_DRAW);
|
|
||||||
fNoPreview->SetViewColor(0, 0, 0);
|
fSaverView->SetExplicitSize(BSize(previewWidth, previewHeight));
|
||||||
fNoPreview->SetLowColor(0, 0, 0);
|
fSaverView->ResizeTo(previewWidth, previewHeight);
|
||||||
fNoPreview->SetFontAndColor(be_plain_font, B_FONT_ALL, &kWhite);
|
|
||||||
fNoPreview->SetText(B_TRANSLATE("No preview available"));
|
fNoPreview = new BStringView("no preview",
|
||||||
fNoPreview->SetAlignment(B_ALIGN_CENTER);
|
B_TRANSLATE("No preview available"));
|
||||||
fNoPreview->MakeEditable(false);
|
|
||||||
fNoPreview->MakeResizable(false);
|
|
||||||
fNoPreview->MakeSelectable(false);
|
|
||||||
|
|
||||||
fNoPreview->Hide();
|
fNoPreview->Hide();
|
||||||
fSaverView->AddChild(fNoPreview);
|
fNoPreview->SetExplicitSize(BSize(previewWidth, previewHeight));
|
||||||
|
fNoPreview->ResizeTo(previewWidth, previewHeight);
|
||||||
|
|
||||||
|
AddChild(fNoPreview);
|
||||||
|
|
||||||
|
fNoPreview->SetViewColor(0, 0, 0);
|
||||||
|
fNoPreview->SetLowColor(0, 0, 0);
|
||||||
|
fNoPreview->SetHighColor(255, 255, 255);
|
||||||
|
fNoPreview->SetAlignment(B_ALIGN_CENTER);
|
||||||
|
|
||||||
return fSaverView;
|
return fSaverView;
|
||||||
}
|
}
|
||||||
@@ -156,6 +160,7 @@ PreviewView::SaverView()
|
|||||||
void
|
void
|
||||||
PreviewView::ShowNoPreview() const
|
PreviewView::ShowNoPreview() const
|
||||||
{
|
{
|
||||||
|
fSaverView->Hide();
|
||||||
fNoPreview->Show();
|
fNoPreview->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,4 +169,5 @@ void
|
|||||||
PreviewView::HideNoPreview() const
|
PreviewView::HideNoPreview() const
|
||||||
{
|
{
|
||||||
fNoPreview->Hide();
|
fNoPreview->Hide();
|
||||||
|
fSaverView->Show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
class BTextView;
|
class BStringView;
|
||||||
|
|
||||||
class PreviewView : public BView {
|
class PreviewView : public BView {
|
||||||
public:
|
public:
|
||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BView* fSaverView;
|
BView* fSaverView;
|
||||||
BTextView* fNoPreview;
|
BStringView* fNoPreview;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user