1 /* 2 * Copyright 2007-2014 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus, superstippi@gmx.de 7 */ 8 9 10 #include "SpiderView.h" 11 12 #include <Catalog.h> 13 #include <ControlLook.h> 14 #include <Message.h> 15 #include <Menu.h> 16 #include <MenuField.h> 17 #include <MenuItem.h> 18 #include <Slider.h> 19 #include <StringView.h> 20 21 #include "SpiderSaver.h" 22 23 24 #undef B_TRANSLATION_CONTEXT 25 #define B_TRANSLATION_CONTEXT "SpiderView" 26 27 28 static const uint32 kMsgQueueNumber = 'qunm'; 29 static const uint32 kMsgPolyNumber = 'plnm'; 30 static const uint32 kMsgQueueDepth = 'qudp'; 31 static const uint32 kMsgColor = 'colr'; 32 33 34 // #pragma - SpiderView 35 36 37 SpiderView::SpiderView(BRect frame, SpiderSaver* saver, uint32 queueNumber, 38 uint32 maxPolyPoints, uint32 maxQueueDepth, uint32 color) 39 : 40 BView(frame, "spider view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED), 41 fSaver(saver) 42 { 43 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 44 45 frame.OffsetTo(0.0, 0.0); 46 frame.InsetBy(10.0, 5.0); 47 48 float viewHeight = floorf(frame.Height() / 5.0); 49 50 // title stuff 51 font_height fh; 52 be_bold_font->GetHeight(&fh); 53 float fontHeight = fh.ascent + fh.descent + 5.0; 54 frame.bottom = frame.top + fontHeight; 55 BStringView* title = new BStringView(frame, B_EMPTY_STRING, 56 B_TRANSLATE("Spider by stippi")); 57 title->SetFont(be_bold_font); 58 AddChild(title); 59 60 be_plain_font->GetHeight(&fh); 61 fontHeight = fh.ascent + fh.descent + 5.0; 62 frame.top = frame.bottom; 63 frame.bottom = frame.top + fontHeight; 64 title = new BStringView(frame, B_EMPTY_STRING, 65 B_TRANSLATE("for bonefish")); 66 BFont font(be_plain_font); 67 font.SetShear(110.0); 68 title->SetFont(&font); 69 title->SetAlignment(B_ALIGN_CENTER); 70 AddChild(title); 71 72 // controls 73 frame.top = 10.0f; 74 frame.bottom = frame.top + viewHeight; 75 76 // queue slider 77 frame.OffsetBy(0.0f, viewHeight); 78 fQueueNumberSlider = new BSlider(frame, "queue number", 79 B_TRANSLATE("Max. polygon count"), new BMessage(kMsgQueueNumber), 80 1, MAX_QUEUE_NUMBER); 81 fQueueNumberSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); 82 fQueueNumberSlider->SetHashMarkCount((MAX_QUEUE_NUMBER - 1) / 2 + 1); 83 fQueueNumberSlider->SetValue(queueNumber); 84 AddChild(fQueueNumberSlider); 85 86 // poly sliders 87 frame.OffsetBy(0.0f, viewHeight); 88 fPolyNumberSlider = new BSlider(frame, "poly points", 89 B_TRANSLATE("Max. points per polygon"), new BMessage(kMsgPolyNumber), 90 MIN_POLY_POINTS, MAX_POLY_POINTS); 91 fPolyNumberSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); 92 fPolyNumberSlider->SetHashMarkCount(MAX_POLY_POINTS - MIN_POLY_POINTS + 1); 93 fPolyNumberSlider->SetValue(maxPolyPoints); 94 AddChild(fPolyNumberSlider); 95 96 // queue depth slider 97 frame.OffsetBy(0.0f, viewHeight); 98 fQueueDepthSlider = new BSlider(frame, "queue depth", 99 B_TRANSLATE("Trail depth"), new BMessage(kMsgQueueDepth), 100 MIN_QUEUE_DEPTH, MAX_QUEUE_DEPTH); 101 fQueueDepthSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); 102 fQueueDepthSlider->SetHashMarkCount( 103 (MAX_QUEUE_DEPTH - MIN_QUEUE_DEPTH) / 4 + 1); 104 fQueueDepthSlider->SetValue(maxQueueDepth); 105 AddChild(fQueueDepthSlider); 106 107 // color menu field 108 BMenu* menu = new BMenu(B_TRANSLATE("Color")); 109 BMenuItem* item; 110 BMessage* message; 111 112 // red 113 message = new BMessage(kMsgColor); 114 message->AddInt32("color", RED); 115 item = new BMenuItem(B_TRANSLATE("Red"), message); 116 item->SetMarked(color == RED); 117 menu->AddItem(item); 118 119 // green 120 message = new BMessage(kMsgColor); 121 message->AddInt32("color", GREEN); 122 item = new BMenuItem(B_TRANSLATE("Green"), message); 123 item->SetMarked(color == GREEN); 124 menu->AddItem(item); 125 126 // blue 127 message = new BMessage(kMsgColor); 128 message->AddInt32("color", BLUE); 129 item = new BMenuItem(B_TRANSLATE("Blue"), message); 130 item->SetMarked(color == BLUE); 131 menu->AddItem(item); 132 133 // yellow 134 message = new BMessage(kMsgColor); 135 message->AddInt32("color", YELLOW); 136 item = new BMenuItem(B_TRANSLATE("Yellow"), message); 137 item->SetMarked(color == YELLOW); 138 menu->AddItem(item); 139 140 // purple 141 message = new BMessage(kMsgColor); 142 message->AddInt32("color", PURPLE); 143 item = new BMenuItem(B_TRANSLATE("Purple"), message); 144 item->SetMarked(color == PURPLE); 145 menu->AddItem(item); 146 147 // cyan 148 message = new BMessage(kMsgColor); 149 message->AddInt32("color", CYAN); 150 item = new BMenuItem(B_TRANSLATE("Cyan"), message); 151 item->SetMarked(color == CYAN); 152 menu->AddItem(item); 153 154 // gray 155 message = new BMessage(kMsgColor); 156 message->AddInt32("color", GRAY); 157 item = new BMenuItem(B_TRANSLATE("Gray"), message); 158 item->SetMarked(color == GRAY); 159 menu->AddItem(item); 160 161 menu->SetLabelFromMarked(true); 162 menu->SetRadioMode(true); 163 164 frame.OffsetBy(0.0f, viewHeight); 165 fColorMenuField = new BMenuField(frame, "color", B_TRANSLATE("Color"), 166 menu); 167 fColorMenuField->SetDivider(fColorMenuField->StringWidth( 168 B_TRANSLATE("Color")) + be_control_look->DefaultItemSpacing()); 169 AddChild(fColorMenuField); 170 } 171 172 173 SpiderView::~SpiderView() 174 { 175 } 176 177 178 void 179 SpiderView::AttachedToWindow() 180 { 181 fQueueNumberSlider->SetTarget(this); 182 fPolyNumberSlider->SetTarget(this); 183 fQueueDepthSlider->SetTarget(this); 184 fColorMenuField->Menu()->SetTargetForItems(this); 185 } 186 187 188 void 189 SpiderView::MessageReceived(BMessage* message) 190 { 191 switch (message->what) { 192 case kMsgQueueNumber: 193 fSaver->SetQueueNumber(fQueueNumberSlider->Value()); 194 break; 195 196 case kMsgPolyNumber: 197 fSaver->SetPolyPoints(fPolyNumberSlider->Value()); 198 break; 199 200 case kMsgQueueDepth: 201 fSaver->SetQueueDepth(fQueueDepthSlider->Value()); 202 break; 203 204 case kMsgColor: { 205 uint32 color; 206 if (message->FindInt32("color", (int32*)&color) == B_OK) 207 fSaver->SetColor(color); 208 209 break; 210 } 211 212 default: 213 BView::MessageReceived(message); 214 } 215 } 216