* the custom ScrollView supports B_NO_BORDER, B_PLAIN_BORDER and B_FANCY_BORDER
and each side of the border can be turned off or on individually * -> cosmetic improvements git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22268 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f10474fc0b
commit
c4ce9e7607
@ -451,6 +451,12 @@ MainWindow::_Init()
|
||||
// create the GUI
|
||||
_CreateGUI(Bounds());
|
||||
|
||||
// fix up scrollbar layout in listviews
|
||||
_ImproveScrollBarLayout(fPathListView);
|
||||
_ImproveScrollBarLayout(fStyleListView);
|
||||
_ImproveScrollBarLayout(fShapeListView);
|
||||
_ImproveScrollBarLayout(fTransformerListView);
|
||||
|
||||
// TODO: move this to CanvasView?
|
||||
fState = new MultipleManipulatorState(fCanvasView);
|
||||
fCanvasView->SetState(fState);
|
||||
@ -615,11 +621,9 @@ MainWindow::_CreateGUI(BRect bounds)
|
||||
|
||||
// scroll view around property list view
|
||||
ScrollView* propScrollView = new ScrollView(fPropertyListView,
|
||||
SCROLL_VERTICAL | SCROLL_NO_FRAME,
|
||||
BRect(0, 0, splitWidth, 100),
|
||||
"property scroll view",
|
||||
B_FOLLOW_NONE,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS);
|
||||
SCROLL_VERTICAL, BRect(0, 0, splitWidth, 100), "property scroll view",
|
||||
B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER,
|
||||
BORDER_RIGHT);
|
||||
leftSideView->AddChild(propScrollView);
|
||||
|
||||
BGroupLayout* topSide = new BGroupLayout(B_HORIZONTAL);
|
||||
@ -635,9 +639,9 @@ MainWindow::_CreateGUI(BRect bounds)
|
||||
canvasBounds.right += B_V_SCROLL_BAR_WIDTH;
|
||||
ScrollView* canvasScrollView
|
||||
= new ScrollView(fCanvasView, SCROLL_VERTICAL | SCROLL_HORIZONTAL
|
||||
| SCROLL_NO_FRAME | SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS,
|
||||
| SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS,
|
||||
canvasBounds, "canvas scroll view",
|
||||
B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS);
|
||||
B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, B_NO_BORDER);
|
||||
layout->AddView(canvasScrollView, 1, 1);
|
||||
|
||||
// views along the top
|
||||
@ -730,12 +734,10 @@ MainWindow::_CreateGUI(BRect bounds)
|
||||
bounds.bottom += B_H_SCROLL_BAR_HEIGHT;
|
||||
bounds.right += B_V_SCROLL_BAR_WIDTH;
|
||||
ScrollView* canvasScrollView
|
||||
= new ScrollView(fCanvasView,
|
||||
SCROLL_HORIZONTAL | SCROLL_VERTICAL
|
||||
| SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS
|
||||
| SCROLL_NO_FRAME,
|
||||
bounds, "canvas scroll view",
|
||||
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS);
|
||||
= new ScrollView(fCanvasView, SCROLL_HORIZONTAL | SCROLL_VERTICAL
|
||||
| SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS, bounds,
|
||||
"canvas scroll view", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS,
|
||||
B_NO_BORDER);
|
||||
|
||||
// icon previews
|
||||
bounds.left = 5;
|
||||
@ -902,11 +904,9 @@ MainWindow::_CreateGUI(BRect bounds)
|
||||
// scroll view around property list view
|
||||
bounds.top = menuBar->Frame().bottom + 1;
|
||||
bounds.bottom = bg->Bounds().bottom;
|
||||
bg->AddChild(new ScrollView(fPropertyListView,
|
||||
SCROLL_VERTICAL | SCROLL_NO_FRAME,
|
||||
bounds, "property scroll view",
|
||||
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS));
|
||||
bg->AddChild(new ScrollView(fPropertyListView, SCROLL_VERTICAL,
|
||||
bounds, "property scroll view", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER, BORDER_RIGHT));
|
||||
|
||||
|
||||
bg->AddChild(canvasScrollView);
|
||||
@ -1063,3 +1063,20 @@ MainWindow::_CreateMenuBar(BRect frame)
|
||||
// PathManipulator* pathManipulator = new PathManipulator(path);
|
||||
// fState->AddManipulator(pathManipulator);
|
||||
//}
|
||||
|
||||
// _ImproveScrollBarLayout
|
||||
void
|
||||
MainWindow::_ImproveScrollBarLayout(BView* target)
|
||||
{
|
||||
// NOTE: The BListViews for which this function is used
|
||||
// are directly below a BMenuBar. If the BScrollBar and
|
||||
// the BMenuBar share bottom/top border respectively, the
|
||||
// GUI looks a little more polished. This trick can be
|
||||
// removed if/when the BScrollViews are embedded in a
|
||||
// surounding border like in WonderBrush.
|
||||
|
||||
if (BScrollBar* scrollBar = target->ScrollBar(B_VERTICAL)) {
|
||||
scrollBar->MoveBy(0, -1);
|
||||
scrollBar->ResizeBy(0, 1);
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ class MainWindow : public BWindow,
|
||||
void _CreateGUI(BRect frame);
|
||||
BMenuBar* _CreateMenuBar(BRect frame);
|
||||
|
||||
void _ImproveScrollBarLayout(BView* target);
|
||||
|
||||
IconEditorApp* fApp;
|
||||
Document* fDocument;
|
||||
Icon* fIcon;
|
||||
|
@ -260,22 +260,30 @@ ScrollCorner::SetDragging(bool dragging)
|
||||
|
||||
// constructor
|
||||
ScrollView::ScrollView(BView* child, uint32 scrollingFlags, BRect frame,
|
||||
const char *name, uint32 resizingMode, uint32 flags)
|
||||
: BView(frame, name, resizingMode, flags | B_FRAME_EVENTS | B_WILL_DRAW
|
||||
| B_FULL_UPDATE_ON_RESIZE),
|
||||
const char *name, uint32 resizingMode, uint32 viewFlags,
|
||||
uint32 borderStyle, uint32 borderFlags)
|
||||
: BView(frame, name, resizingMode, viewFlags | B_FRAME_EVENTS | B_WILL_DRAW
|
||||
| B_FULL_UPDATE_ON_RESIZE),
|
||||
Scroller(),
|
||||
fChild(NULL),
|
||||
fScrollingFlags(scrollingFlags),
|
||||
|
||||
fHScrollBar(NULL),
|
||||
fVScrollBar(NULL),
|
||||
fScrollCorner(NULL),
|
||||
|
||||
fHVisible(true),
|
||||
fVVisible(true),
|
||||
fCornerVisible(true),
|
||||
|
||||
fWindowActive(false),
|
||||
fChildFocused(false),
|
||||
|
||||
fHSmallStep(1),
|
||||
fVSmallStep(1)
|
||||
fVSmallStep(1),
|
||||
|
||||
fBorderStyle(borderStyle),
|
||||
fBorderFlags(borderFlags)
|
||||
{
|
||||
// Set transparent view color -- our area is completely covered by
|
||||
// our children.
|
||||
@ -321,6 +329,9 @@ ScrollView::AllAttached()
|
||||
// Draw
|
||||
void ScrollView::Draw(BRect updateRect)
|
||||
{
|
||||
if (fBorderStyle == B_NO_BORDER)
|
||||
return;
|
||||
|
||||
rgb_color keyboardFocus = keyboard_navigation_color();
|
||||
rgb_color light = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||
B_LIGHTEN_MAX_TINT);
|
||||
@ -328,50 +339,37 @@ void ScrollView::Draw(BRect updateRect)
|
||||
B_DARKEN_1_TINT);
|
||||
rgb_color darkShadow = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||
B_DARKEN_2_TINT);
|
||||
rgb_color darkerShadow = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||
B_DARKEN_3_TINT);
|
||||
float left = Bounds().left, right = Bounds().right;
|
||||
float top = Bounds().top, bottom = Bounds().bottom;
|
||||
|
||||
BRect r = Bounds();
|
||||
|
||||
if (fChildFocused && fWindowActive) {
|
||||
BeginLineArray(4);
|
||||
AddLine(BPoint(left, bottom),
|
||||
BPoint(left, top), keyboardFocus);
|
||||
AddLine(BPoint(left + 1.0, top),
|
||||
BPoint(right, top), keyboardFocus);
|
||||
AddLine(BPoint(right, top + 1.0),
|
||||
BPoint(right, bottom), keyboardFocus);
|
||||
AddLine(BPoint(right - 1.0, bottom),
|
||||
BPoint(left + 1.0, bottom), keyboardFocus);
|
||||
EndLineArray();
|
||||
SetHighColor(keyboardFocus);
|
||||
StrokeRect(r);
|
||||
} else {
|
||||
BeginLineArray(4);
|
||||
AddLine(BPoint(left, bottom),
|
||||
BPoint(left, top), shadow);
|
||||
AddLine(BPoint(left + 1.0, top),
|
||||
BPoint(right, top), shadow);
|
||||
AddLine(BPoint(right, top + 1.0),
|
||||
BPoint(right, bottom), light);
|
||||
AddLine(BPoint(right - 1.0, bottom),
|
||||
BPoint(left + 1.0, bottom), light);
|
||||
EndLineArray();
|
||||
if (fBorderStyle == B_PLAIN_BORDER) {
|
||||
SetHighColor(darkShadow);
|
||||
StrokeRect(r);
|
||||
} else {
|
||||
BeginLineArray(4);
|
||||
AddLine(BPoint(r.left, r.bottom),
|
||||
BPoint(r.left, r.top), shadow);
|
||||
AddLine(BPoint(r.left + 1.0, r.top),
|
||||
BPoint(r.right, r.top), shadow);
|
||||
AddLine(BPoint(r.right, r.top + 1.0),
|
||||
BPoint(r.right, r.bottom), light);
|
||||
AddLine(BPoint(r.right - 1.0, r.bottom),
|
||||
BPoint(r.left + 1.0, r.bottom), light);
|
||||
EndLineArray();
|
||||
}
|
||||
}
|
||||
if (fBorderStyle == B_PLAIN_BORDER)
|
||||
return;
|
||||
|
||||
// The right and bottom lines will be hidden if the scroll views are
|
||||
// visible. But that doesn't harm.
|
||||
BRect innerRect(_InnerRect());
|
||||
left = innerRect.left;
|
||||
top = innerRect.top;
|
||||
right = innerRect.right;
|
||||
bottom = innerRect.bottom;
|
||||
BeginLineArray(4);
|
||||
AddLine(BPoint(left, bottom),
|
||||
BPoint(left, top), darkerShadow);
|
||||
AddLine(BPoint(left + 1.0, top),
|
||||
BPoint(right, top), darkShadow);
|
||||
AddLine(BPoint(right, top + 1.0),
|
||||
BPoint(right, bottom), darkShadow);
|
||||
AddLine(BPoint(right - 1.0, bottom),
|
||||
BPoint(left + 1.0, bottom), darkShadow);
|
||||
EndLineArray();
|
||||
r.InsetBy(1, 1);
|
||||
SetHighColor(darkShadow);
|
||||
StrokeRect(r);
|
||||
}
|
||||
|
||||
// FrameResized
|
||||
@ -396,36 +394,15 @@ BSize
|
||||
ScrollView::MinSize()
|
||||
{
|
||||
BSize size = (fChild ? fChild->MinSize() : BSize(-1, -1));
|
||||
|
||||
if (fVVisible)
|
||||
size.width += B_V_SCROLL_BAR_WIDTH;
|
||||
if (fHVisible)
|
||||
size.height += B_H_SCROLL_BAR_HEIGHT;
|
||||
|
||||
float borderSize = BorderSize();
|
||||
size.width += 2 * borderSize;
|
||||
size.height += 2 * borderSize;
|
||||
|
||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||
return _Size(size);
|
||||
}
|
||||
|
||||
// PreferredSize
|
||||
BSize
|
||||
ScrollView::PreferredSize()
|
||||
{
|
||||
// TODO: This is not yet correct.
|
||||
BSize size = (fChild ? fChild->PreferredSize() : BSize(-1, -1));
|
||||
|
||||
if (fVVisible)
|
||||
size.width += B_V_SCROLL_BAR_WIDTH;
|
||||
if (fHVisible)
|
||||
size.height += B_H_SCROLL_BAR_HEIGHT;
|
||||
|
||||
float borderSize = BorderSize();
|
||||
size.width += 2 * borderSize;
|
||||
size.height += 2 * borderSize;
|
||||
|
||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||
return _Size(size);
|
||||
}
|
||||
|
||||
#endif // __HAIKU__
|
||||
@ -501,15 +478,6 @@ ScrollView::HVScrollCorner() const
|
||||
return fScrollCorner;
|
||||
}
|
||||
|
||||
// BorderSize
|
||||
float
|
||||
ScrollView::BorderSize() const
|
||||
{
|
||||
if (fScrollingFlags & SCROLL_NO_FRAME)
|
||||
return 0.0;
|
||||
return 2.0;
|
||||
}
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
// SetHSmallStep
|
||||
@ -659,14 +627,11 @@ ScrollView::_Layout(uint32 flags)
|
||||
float innerWidth = childRect.Width();
|
||||
float innerHeight = childRect.Height();
|
||||
BPoint scrollLT(_InnerRect().LeftTop());
|
||||
scrollLT.x--;
|
||||
scrollLT.y--;
|
||||
|
||||
BPoint scrollRB(childRect.RightBottom() + BPoint(1.0f, 1.0f));
|
||||
if (fScrollingFlags & SCROLL_NO_FRAME) {
|
||||
// cut off the top line and left line of the
|
||||
// scroll bars, otherwise they are used for the
|
||||
// frame appearance
|
||||
scrollLT.x--;
|
||||
scrollLT.y--;
|
||||
}
|
||||
|
||||
// layout scroll bars and scroll corner
|
||||
if (corner) {
|
||||
// In this case the scrollbars overlap one pixel.
|
||||
@ -849,9 +814,28 @@ ScrollView::_UpdateScrollBarVisibility()
|
||||
BRect
|
||||
ScrollView::_InnerRect() const
|
||||
{
|
||||
if (fScrollingFlags & SCROLL_NO_FRAME)
|
||||
return Bounds();
|
||||
return Bounds().InsetBySelf(1.0f, 1.0f);
|
||||
BRect r = Bounds();
|
||||
float borderWidth = 0;
|
||||
switch (fBorderStyle) {
|
||||
case B_NO_BORDER:
|
||||
break;
|
||||
case B_PLAIN_BORDER:
|
||||
borderWidth = 1;
|
||||
break;
|
||||
case B_FANCY_BORDER:
|
||||
default:
|
||||
borderWidth = 2;
|
||||
break;
|
||||
}
|
||||
if (fBorderFlags & BORDER_LEFT)
|
||||
r.left += borderWidth;
|
||||
if (fBorderFlags & BORDER_TOP)
|
||||
r.top += borderWidth;
|
||||
if (fBorderFlags & BORDER_RIGHT)
|
||||
r.right -= borderWidth;
|
||||
if (fBorderFlags & BORDER_BOTTOM)
|
||||
r.bottom -= borderWidth;
|
||||
return r;
|
||||
}
|
||||
|
||||
// _ChildRect
|
||||
@ -874,18 +858,11 @@ BRect
|
||||
ScrollView::_ChildRect(bool hbar, bool vbar) const
|
||||
{
|
||||
BRect rect(_InnerRect());
|
||||
float frameWidth = (fScrollingFlags & SCROLL_NO_FRAME) ? 0.0 : 1.0;
|
||||
|
||||
if (hbar)
|
||||
rect.bottom -= B_H_SCROLL_BAR_HEIGHT + frameWidth;
|
||||
else
|
||||
rect.bottom -= frameWidth;
|
||||
if (vbar)
|
||||
rect.right -= B_V_SCROLL_BAR_WIDTH + frameWidth;
|
||||
else
|
||||
rect.right -= frameWidth;
|
||||
rect.top += frameWidth;
|
||||
rect.left += frameWidth;
|
||||
rect.right -= B_V_SCROLL_BAR_WIDTH;
|
||||
if (hbar)
|
||||
rect.bottom -= B_H_SCROLL_BAR_HEIGHT;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
@ -915,4 +892,51 @@ ScrollView::_MaxVisibleRect() const
|
||||
return _GuessVisibleRect(true, true);
|
||||
}
|
||||
|
||||
#ifdef __HAIKU__
|
||||
BSize
|
||||
ScrollView::_Size(BSize size)
|
||||
{
|
||||
if (fVVisible)
|
||||
size.width += B_V_SCROLL_BAR_WIDTH;
|
||||
if (fHVisible)
|
||||
size.height += B_H_SCROLL_BAR_HEIGHT;
|
||||
|
||||
switch (fBorderStyle) {
|
||||
case B_NO_BORDER:
|
||||
// one line of pixels from scrollbar possibly hidden
|
||||
if (fBorderFlags & BORDER_RIGHT)
|
||||
size.width += fVVisible ? -1 : 0;
|
||||
if (fBorderFlags & BORDER_BOTTOM)
|
||||
size.height += fHVisible ? -1 : 0;
|
||||
break;
|
||||
|
||||
case B_PLAIN_BORDER:
|
||||
if (fBorderFlags & BORDER_LEFT)
|
||||
size.width += 1;
|
||||
if (fBorderFlags & BORDER_TOP)
|
||||
size.height += 1;
|
||||
// one line of pixels in frame possibly from scrollbar
|
||||
if (fBorderFlags & BORDER_RIGHT)
|
||||
size.width += fVVisible ? 0 : 1;
|
||||
if (fBorderFlags & BORDER_BOTTOM)
|
||||
size.height += fHVisible ? 0 : 1;
|
||||
break;
|
||||
|
||||
case B_FANCY_BORDER:
|
||||
default:
|
||||
if (fBorderFlags & BORDER_LEFT)
|
||||
size.width += 2;
|
||||
if (fBorderFlags & BORDER_TOP)
|
||||
size.height += 2;
|
||||
// one line of pixels in frame possibly from scrollbar
|
||||
if (fBorderFlags & BORDER_RIGHT)
|
||||
size.width += fVVisible ? 1 : 2;
|
||||
if (fBorderFlags & BORDER_BOTTOM)
|
||||
size.height += fHVisible ? 1 : 2;
|
||||
break;
|
||||
}
|
||||
|
||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||
}
|
||||
#endif // __HAIKU__
|
||||
|
||||
|
@ -23,17 +23,25 @@ enum {
|
||||
SCROLL_VERTICAL = 0x02,
|
||||
SCROLL_HORIZONTAL_MAGIC = 0x04,
|
||||
SCROLL_VERTICAL_MAGIC = 0x08,
|
||||
SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS = 0x10,
|
||||
SCROLL_NO_FRAME = 0x20,
|
||||
SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS = 0x10
|
||||
};
|
||||
|
||||
enum {
|
||||
BORDER_LEFT = 0x01,
|
||||
BORDER_TOP = 0x02,
|
||||
BORDER_RIGHT = 0x04,
|
||||
BORDER_BOTTOM = 0x08,
|
||||
BORDER_ALL = BORDER_LEFT | BORDER_TOP | BORDER_RIGHT | BORDER_BOTTOM
|
||||
};
|
||||
|
||||
|
||||
class ScrollView : public BView, public Scroller {
|
||||
public:
|
||||
ScrollView(BView* child,
|
||||
uint32 scrollingFlags,
|
||||
BRect frame,
|
||||
const char *name,
|
||||
uint32 resizingMode, uint32 flags);
|
||||
ScrollView(BView* child, uint32 scrollingFlags,
|
||||
BRect frame, const char *name,
|
||||
uint32 resizingMode, uint32 viewFlags,
|
||||
uint32 borderStyle = B_FANCY_BORDER,
|
||||
uint32 borderFlags = BORDER_ALL);
|
||||
virtual ~ScrollView();
|
||||
|
||||
virtual void AllAttached();
|
||||
@ -66,8 +74,6 @@ class ScrollView : public BView, public Scroller {
|
||||
float HSmallStep() const;
|
||||
float VSmallStep() const;
|
||||
|
||||
float BorderSize() const;
|
||||
|
||||
protected:
|
||||
virtual void DataRectChanged(BRect oldDataRect,
|
||||
BRect newDataRect);
|
||||
@ -94,6 +100,9 @@ class ScrollView : public BView, public Scroller {
|
||||
float fHSmallStep;
|
||||
float fVSmallStep;
|
||||
|
||||
uint32 fBorderStyle;
|
||||
uint32 fBorderFlags;
|
||||
|
||||
void _ScrollValueChanged(
|
||||
InternalScrollBar* scrollBar,
|
||||
float value);
|
||||
@ -111,6 +120,9 @@ private:
|
||||
BRect _ChildRect(bool hbar, bool vbar) const;
|
||||
BRect _GuessVisibleRect(bool hbar, bool vbar) const;
|
||||
BRect _MaxVisibleRect() const;
|
||||
#ifdef __HAIKU__
|
||||
virtual BSize _Size(BSize childSize);
|
||||
#endif
|
||||
|
||||
friend class InternalScrollBar;
|
||||
friend class ScrollCorner;
|
||||
|
Loading…
x
Reference in New Issue
Block a user