2 * Copyright 2012-2013 Tri-Edge AI <triedgeai@gmail.com>
3 * Copyright 2014-2016 Haiku, Inc. All rights reserved.
5 * Distributed under the terms of the MIT license.
9 * John Scipione, jscipione@gmail.com
13 #include "ConfigView.h"
15 #include <LayoutBuilder.h>
17 #include <ScrollView.h>
19 #include <StringView.h>
22 #include "ColorItem.h"
24 #include "RainbowItem.h"
27 static const int32 kMsgSize
= 'size';
28 static const int32 kMsgShade
= 'shad';
31 ConfigView::ConfigView(BRect frame
, Gravity
* parent
)
33 BView(frame
, B_EMPTY_STRING
, B_FOLLOW_ALL_SIDES
, B_WILL_DRAW
),
35 fTitleString(new BStringView(B_EMPTY_STRING
, "OpenGL Gravity Effect")),
36 fAuthorString(new BStringView(B_EMPTY_STRING
, "by Tri-Edge AI")),
37 fCountSlider(new BSlider(B_EMPTY_STRING
, "Particle Count: ",
38 new BMessage(kMsgSize
), 0, 4, B_HORIZONTAL
, B_BLOCK_THUMB
,
39 B_NAVIGABLE
| B_WILL_DRAW
)),
40 fShadeString(new BStringView(B_EMPTY_STRING
, "Shade: ")),
41 fShadeList(new BListView(B_EMPTY_STRING
, B_SINGLE_SELECTION_LIST
,
42 B_WILL_DRAW
| B_NAVIGABLE
))
44 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
46 fShadeList
->SetSelectionMessage(new BMessage(kMsgShade
));
47 fShadeList
->AddItem(new ColorItem("Red", (rgb_color
){ 255, 65, 54 }));
48 fShadeList
->AddItem(new ColorItem("Green", (rgb_color
){ 46, 204, 64 }));
49 fShadeList
->AddItem(new ColorItem("Blue", (rgb_color
){ 0, 116, 217 }));
50 fShadeList
->AddItem(new ColorItem("Orange", (rgb_color
){ 255, 133, 27 }));
51 fShadeList
->AddItem(new ColorItem("Purple", (rgb_color
){ 177, 13, 201 }));
52 fShadeList
->AddItem(new ColorItem("White", (rgb_color
){ 255, 255, 255 }));
53 fShadeList
->AddItem(new RainbowItem("Rainbow"));
55 fShadeScroll
= new BScrollView(B_EMPTY_STRING
, fShadeList
,
56 B_WILL_DRAW
| B_FRAME_EVENTS
, false, true);
58 fCountSlider
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
59 fCountSlider
->SetHashMarkCount(5);
60 fCountSlider
->SetLimitLabels("128", "2048");
61 fCountSlider
->SetModificationMessage(new BMessage(kMsgSize
));
62 fCountSlider
->SetValue(parent
->Config
.ParticleCount
);
64 BLayoutBuilder::Group
<>(this, B_VERTICAL
, B_USE_DEFAULT_SPACING
)
65 .AddGroup(B_VERTICAL
, 0)
72 .SetInsets(B_USE_DEFAULT_SPACING
)
78 ConfigView::AllAttached()
80 // fixup scroll bar range
81 fShadeScroll
->ScrollBar(B_VERTICAL
)->SetRange(0.0f
,
82 fShadeList
->ItemFrame(fShadeList
->CountItems()).bottom
83 - fShadeList
->ItemFrame((int32
)0).top
);
86 fShadeList
->Select(fParent
->Config
.ShadeID
);
91 ConfigView::AttachedToWindow()
93 fShadeList
->SetTarget(this);
94 fCountSlider
->SetTarget(this);
99 ConfigView::MessageReceived(BMessage
* message
)
101 switch (message
->what
) {
103 fParent
->Config
.ParticleCount
= fCountSlider
->Value();
107 fParent
->Config
.ShadeID
= fShadeList
->CurrentSelection();
111 BView::MessageReceived(message
);