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