-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExpander.cpp
100 lines (87 loc) · 2.61 KB
/
Expander.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (C) 2017 Kai Niessen <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* File: Expander.cpp
* Author: Kai Niessen <[email protected]>
*
* Created on April 13, 2017, 4:50 PM
*/
#include "Expander.h"
#include <Shape.h>
#include <Window.h>
#include <Layout.h>
void
Expander::Draw(BRect updateRect) {
BRect r = Bounds();
SetHighColor(ViewColor());
FillRect(r);
r.InsetBy((Bounds().Width() - 80) / 2, 0);
BShape shape;
shape.MoveTo(r.LeftTop());
shape.BezierTo(r.LeftTop() + BPoint(10,0), r.LeftBottom() + BPoint(10, 0), r.LeftBottom() + BPoint(20, 0));
shape.LineTo(r.RightBottom() - BPoint(20, 0));
shape.BezierTo(r.RightBottom() - BPoint(10, 0), r.RightTop() - BPoint(10, 0), r.RightTop());
SetHighColor(ui_color(B_CONTROL_BACKGROUND_COLOR));
FillShape(&shape);
SetHighColor(ui_color(IsFocus() ? B_CONTROL_HIGHLIGHT_COLOR : B_CONTROL_BORDER_COLOR));
StrokeShape(&shape);
shape.Clear();
r.InsetBy(r.Width() / 3, 2);
if (fExpanded) {
shape.MoveTo(r.LeftTop());
shape.LineTo(r.RightTop());
shape.LineTo(r.LeftBottom() + BPoint(r.Width() / 2, 0));
shape.Close();
} else {
shape.MoveTo(r.LeftBottom());
shape.LineTo(r.RightBottom());
shape.LineTo(r.LeftTop() + BPoint(r.Width() / 2, 0));
shape.Close();
}
SetHighColor(tint_color(ViewColor(), B_DARKEN_2_TINT));
FillShape(&shape);
}
Expander::Expander(const char* name, BView* target, orientation orientation)
: BButton(name, "", NULL, B_WILL_DRAW),
fTarget(target),
fOrientation(orientation),
fExpanded(true)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetExplicitSize(BSize(B_SIZE_UNSET, 8));
SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_UNSET));
}
Expander::~Expander() {
}
void
Expander::SetExpanded(bool expanded) {
if (fExpanded == expanded)
return;
if (expanded) {
fTarget->Show();
} else {
fTarget->Hide();
}
Window()->Layout(true);
fExpanded = expanded;
Invalidate();
}
status_t
Expander::Invoke(BMessage* msg) {
SetExpanded(!fExpanded);
return B_OK;
}