-
-
Notifications
You must be signed in to change notification settings - Fork 335
/
ConfigView.cpp
102 lines (83 loc) · 2.79 KB
/
ConfigView.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
101
102
/*
* Copyright 2012-2013 Tri-Edge AI <triedgeai@gmail.com>
* Copyright 2014 Haiku, Inc. All rights reserved.
*
* Distributed under the terms of the MIT license.
*
* Authors:
* Tri-Edge AI
* John Scipione, jscipione@gmail.com
*/
#include "ConfigView.h"
#include <LayoutBuilder.h>
#include <ListView.h>
#include <ScrollView.h>
#include <Slider.h>
#include <StringView.h>
#include <View.h>
#include "ColorItem.h"
#include "Gravity.h"
#include "RainbowItem.h"
static const int32 kMsgSize = 'size';
static const int32 kMsgShade = 'shad';
ConfigView::ConfigView(BRect frame, Gravity* parent)
:
BView(frame, B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
fParent(parent),
fTitleString(new BStringView(B_EMPTY_STRING, "OpenGL Gravity Effect")),
fAuthorString(new BStringView(B_EMPTY_STRING, "by Tri-Edge AI")),
fCountSlider(new BSlider(B_EMPTY_STRING, "Particle Count: ",
new BMessage(kMsgSize), 0, 4, B_HORIZONTAL, B_BLOCK_THUMB,
B_NAVIGABLE | B_WILL_DRAW)),
fShadeString(new BStringView(B_EMPTY_STRING, "Shade: ")),
fShadeList(new BListView(B_EMPTY_STRING, B_SINGLE_SELECTION_LIST,
B_WILL_DRAW | B_NAVIGABLE))
{
SetLayout(new BGroupLayout(B_HORIZONTAL));
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
fShadeList->SetSelectionMessage(new BMessage(kMsgShade));
fShadeList->AddItem(new ColorItem("Red", (rgb_color){ 255, 65, 54 }));
fShadeList->AddItem(new ColorItem("Green", (rgb_color){ 46, 204, 64 }));
fShadeList->AddItem(new ColorItem("Blue", (rgb_color){ 0, 116, 217 }));
fShadeList->AddItem(new ColorItem("Orange", (rgb_color){ 255, 133, 27 }));
fShadeList->AddItem(new ColorItem("Purple", (rgb_color){ 177, 13, 201 }));
fShadeList->AddItem(new ColorItem("White", (rgb_color){ 255, 255, 255 }));
fShadeList->AddItem(new RainbowItem("Rainbow"));
fShadeList->Select(parent->Config.ShadeID);
fShadeScroll = new BScrollView(B_EMPTY_STRING, fShadeList,
B_WILL_DRAW | B_FRAME_EVENTS, false, true);
fCountSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
fCountSlider->SetHashMarkCount(5);
fCountSlider->SetLimitLabels("128", "2048");
fCountSlider->SetModificationMessage(new BMessage(kMsgSize));
fCountSlider->SetValue(parent->Config.ParticleCount);
AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_DEFAULT_SPACING)
.AddGroup(B_VERTICAL, 0)
.Add(fTitleString)
.Add(fAuthorString)
.End()
.Add(fShadeString)
.Add(fShadeScroll)
.Add(fCountSlider)
.SetInsets(B_USE_DEFAULT_SPACING));
}
void
ConfigView::AttachedToWindow()
{
fShadeList->SetTarget(this);
fCountSlider->SetTarget(this);
}
void
ConfigView::MessageReceived(BMessage* message)
{
switch (message->what) {
case kMsgSize:
fParent->Config.ParticleCount = fCountSlider->Value();
break;
case kMsgShade:
fParent->Config.ShadeID = fShadeList->CurrentSelection();
break;
default:
BView::MessageReceived(message);
}
}