xref: /haiku/src/add-ons/screen_savers/gravity/ConfigView.cpp (revision 04a0e9c7b68cbe3a43d38e2bca8e860fd80936fb)
1 /*
2  * Copyright 2012-2013 Tri-Edge AI <triedgeai@gmail.com>
3  * All rights reserved. Distributed under the terms of the MIT license.
4  */
5 
6 
7 #include "ConfigView.h"
8 
9 #include "Constants.h"
10 #include "Gravity.h"
11 
12 #include <GroupLayoutBuilder.h>
13 #include <ListView.h>
14 #include <ScrollView.h>
15 #include <Slider.h>
16 #include <StringView.h>
17 #include <View.h>
18 
19 
20 ConfigView::ConfigView(Gravity* parent, BRect rect)
21 	:
22 	BView(rect, B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, B_WILL_DRAW)
23 {
24 	fParent = parent;
25 
26 	SetLayout(new BGroupLayout(B_HORIZONTAL));
27 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
28 
29 	fTitleString = new BStringView(RECT_0, B_EMPTY_STRING,
30 		"OpenGL Gravity Effect", B_FOLLOW_LEFT);
31 
32 	fAuthorString = new BStringView(RECT_0, B_EMPTY_STRING,
33 		"by Tri-Edge AI", B_FOLLOW_LEFT);
34 
35 	fCountSlider = new BSlider(RECT_0, B_EMPTY_STRING, "Particle Count: ",
36 		new BMessage(MSG_COUNT), 0, 4, B_BLOCK_THUMB);
37 
38 	fShadeString = new BStringView(RECT_0, B_EMPTY_STRING, "Shade: ",
39 		B_FOLLOW_LEFT);
40 
41 	fShadeList = new BListView(RECT_0, B_EMPTY_STRING, B_SINGLE_SELECTION_LIST,
42 		B_FOLLOW_ALL);
43 
44 	fShadeList->SetSelectionMessage(new BMessage(MSG_SHADE));
45 
46 	fShadeList->AddItem(new BStringItem("Red"));
47 	fShadeList->AddItem(new BStringItem("Green"));
48 	fShadeList->AddItem(new BStringItem("Blue"));
49 	fShadeList->AddItem(new BStringItem("Orange"));
50 	fShadeList->AddItem(new BStringItem("Purple"));
51 	fShadeList->AddItem(new BStringItem("White"));
52 	fShadeList->AddItem(new BStringItem("Rainbow"));
53 
54 	fShadeList->Select(parent->Config.ShadeID);
55 
56 	fShadeScroll = new BScrollView(B_EMPTY_STRING, fShadeList,
57 		B_WILL_DRAW | B_FRAME_EVENTS, false, true);
58 
59 	fCountSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
60 	fCountSlider->SetHashMarkCount(5);
61 	fCountSlider->SetLimitLabels("128", "2048");
62 
63 	fCountSlider->SetValue(parent->Config.ParticleCount);
64 
65 	AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_DEFAULT_SPACING)
66 			.Add(BGroupLayoutBuilder(B_VERTICAL, 0)
67 				.Add(fTitleString)
68 				.Add(fAuthorString)
69 			)
70 			.Add(fShadeString)
71 			.Add(fShadeScroll)
72 			.Add(fCountSlider)
73 			.SetInsets(B_USE_DEFAULT_SPACING,
74 				B_USE_DEFAULT_SPACING,
75 				B_USE_DEFAULT_SPACING,
76 				B_USE_DEFAULT_SPACING)
77 	);
78 }
79 
80 
81 void
82 ConfigView::AttachedToWindow()
83 {
84 	fShadeList->SetTarget(this);
85 	fCountSlider->SetTarget(this);
86 }
87 
88 
89 void
90 ConfigView::MessageReceived(BMessage* msg)
91 {
92 	switch (msg->what) {
93 		case MSG_COUNT:
94 			fParent->Config.ParticleCount = fCountSlider->Value();
95 			break;
96 
97 		case MSG_SHADE:
98 			fParent->Config.ShadeID = fShadeList->CurrentSelection();
99 			break;
100 
101 		default:
102 			BView::MessageReceived(msg);
103 	}
104 }
105