-
-
Notifications
You must be signed in to change notification settings - Fork 336
/
CenteredViewContainer.cpp
48 lines (40 loc) · 1.1 KB
/
CenteredViewContainer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright 2007, Michael Pfeiffer, laplace@users.sourceforge.net.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "CenteredViewContainer.h"
CenteredViewContainer::CenteredViewContainer(BView* target, const char* name)
:
BView(name, B_WILL_DRAW | B_FRAME_EVENTS),
fTarget(target)
{
SetViewColor(B_TRANSPARENT_COLOR);
// to avoid flickering
AddChild(fTarget);
_CenterTarget(frame.Width(), frame.Height());
}
CenteredViewContainer::~CenteredViewContainer()
{
}
void
CenteredViewContainer::Draw(BRect updateRect)
{
FillRect(updateRect);
}
void
CenteredViewContainer::FrameResized(float width, float height)
{
BView::FrameResized(width, height);
_CenterTarget(width, height);
}
void CenteredViewContainer::_CenterTarget(float width, float height)
{
float size = width < height ? width : height;
float left = floor((width - size) / 2);
float top = floor((height - size) / 2);
fTarget->MoveTo(left, top);
fTarget->ResizeTo(size, size);
fTarget->FrameResized(size, size);
// in BeOS R5 BView::FrameResized is not (always) called automatically
// after ResizeTo()
}