3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / screen_savers / gravity / ConfigView.cpp
blob8ff5bef569769e94002351367c88c5a98f91ddcc
1 /*
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.
7 * Authors:
8 * Tri-Edge AI
9 * John Scipione, jscipione@gmail.com
13 #include "ConfigView.h"
15 #include <LayoutBuilder.h>
16 #include <ListView.h>
17 #include <ScrollView.h>
18 #include <Slider.h>
19 #include <StringView.h>
20 #include <View.h>
22 #include "ColorItem.h"
23 #include "Gravity.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),
34 fParent(parent),
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)
66 .Add(fTitleString)
67 .Add(fAuthorString)
68 .End()
69 .Add(fShadeString)
70 .Add(fShadeScroll)
71 .Add(fCountSlider)
72 .SetInsets(B_USE_DEFAULT_SPACING)
73 .End();
77 void
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);
85 // select the shade
86 fShadeList->Select(fParent->Config.ShadeID);
90 void
91 ConfigView::AttachedToWindow()
93 fShadeList->SetTarget(this);
94 fCountSlider->SetTarget(this);
98 void
99 ConfigView::MessageReceived(BMessage* message)
101 switch (message->what) {
102 case kMsgSize:
103 fParent->Config.ParticleCount = fCountSlider->Value();
104 break;
106 case kMsgShade:
107 fParent->Config.ShadeID = fShadeList->CurrentSelection();
108 break;
110 default:
111 BView::MessageReceived(message);