xref: /haiku/src/tests/servers/app/playground/ObjectWindow.cpp (revision 8e05e376ac1a749dd8b5138426fa97241fbe2eb2)
178c1c29bSStephan Aßmus // main.cpp
278c1c29bSStephan Aßmus 
378c1c29bSStephan Aßmus #include <stdio.h>
478c1c29bSStephan Aßmus #include <stdlib.h>
578c1c29bSStephan Aßmus 
678c1c29bSStephan Aßmus #include <Application.h>
74dfc2afbSAxel Dörfler #include <Alert.h>
878c1c29bSStephan Aßmus #include <Box.h>
978c1c29bSStephan Aßmus #include <Button.h>
1078c1c29bSStephan Aßmus #include <CheckBox.h>
1178c1c29bSStephan Aßmus #include <Menu.h>
1278c1c29bSStephan Aßmus #include <MenuBar.h>
1381cc749fSStephan Aßmus #include <MenuField.h>
1478c1c29bSStephan Aßmus #include <MenuItem.h>
1581cc749fSStephan Aßmus #include <PopUpMenu.h>
16*8e05e376SStephan Aßmus #include <ScrollBar.h>
17*8e05e376SStephan Aßmus #include <ScrollView.h>
18b7f478e2SStephan Aßmus #include <Slider.h>
1978c1c29bSStephan Aßmus #include <String.h>
2078c1c29bSStephan Aßmus #include <RadioButton.h>
2178c1c29bSStephan Aßmus #include <TextControl.h>
2278c1c29bSStephan Aßmus #include <TextView.h>
2378c1c29bSStephan Aßmus 
2478c1c29bSStephan Aßmus #include "ObjectView.h"
2578c1c29bSStephan Aßmus #include "States.h"
2678c1c29bSStephan Aßmus 
2778c1c29bSStephan Aßmus #include "ObjectWindow.h"
2878c1c29bSStephan Aßmus 
2978c1c29bSStephan Aßmus enum {
3078c1c29bSStephan Aßmus 	MSG_SET_OBJECT_TYPE		= 'stot',
3178c1c29bSStephan Aßmus 	MSG_SET_FILL_OR_STROKE	= 'stfs',
3278c1c29bSStephan Aßmus 	MSG_SET_COLOR			= 'stcl',
3378c1c29bSStephan Aßmus 	MSG_SET_PEN_SIZE		= 'stps',
3481cc749fSStephan Aßmus 	MSG_SET_DRAWING_MODE	= 'stdm',
3578c1c29bSStephan Aßmus 
3678c1c29bSStephan Aßmus 	MSG_NEW_OBJECT			= 'nobj',
3778c1c29bSStephan Aßmus 
3878c1c29bSStephan Aßmus 	MSG_UNDO				= 'undo',
3978c1c29bSStephan Aßmus 	MSG_REDO				= 'redo',
4078c1c29bSStephan Aßmus 
4178c1c29bSStephan Aßmus 	MSG_CLEAR				= 'clir',
4278c1c29bSStephan Aßmus };
4378c1c29bSStephan Aßmus 
4478c1c29bSStephan Aßmus // constructor
4578c1c29bSStephan Aßmus ObjectWindow::ObjectWindow(BRect frame, const char* name)
46*8e05e376SStephan Aßmus 	: BWindow(frame, name, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
47b7f478e2SStephan Aßmus 			  B_ASYNCHRONOUS_CONTROLS)
48b7f478e2SStephan Aßmus //	: BWindow(frame, name, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
49b7f478e2SStephan Aßmus //			  B_ASYNCHRONOUS_CONTROLS)
50b7f478e2SStephan Aßmus //	: BWindow(frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
51b7f478e2SStephan Aßmus //			  B_ASYNCHRONOUS_CONTROLS)
52b7f478e2SStephan Aßmus //	: BWindow(frame, name, B_BORDERED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
53b7f478e2SStephan Aßmus //			  B_ASYNCHRONOUS_CONTROLS)
54b7f478e2SStephan Aßmus //	: BWindow(frame, name, B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
55b7f478e2SStephan Aßmus //			  B_ASYNCHRONOUS_CONTROLS)
5678c1c29bSStephan Aßmus {
5778c1c29bSStephan Aßmus 	BRect b(Bounds());
5878c1c29bSStephan Aßmus 
5978c1c29bSStephan Aßmus 	b.bottom = b.top + 8;
6078c1c29bSStephan Aßmus 	BMenuBar* menuBar = new BMenuBar(b, "menu bar");
6178c1c29bSStephan Aßmus 	AddChild(menuBar);
6278c1c29bSStephan Aßmus 
63d5233162SStephan Aßmus 	BMenu* menu = new BMenu("File");
6478c1c29bSStephan Aßmus 	menuBar->AddItem(menu);
6578c1c29bSStephan Aßmus 
66590fdd3fSStephan Aßmus 	BMenuItem* menuItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED),
67d5233162SStephan Aßmus 										'Q');
6878c1c29bSStephan Aßmus 	menu->AddItem(menuItem);
6978c1c29bSStephan Aßmus 
7078c1c29bSStephan Aßmus 	b = Bounds();
7178c1c29bSStephan Aßmus 	b.top = menuBar->Bounds().bottom + 1;
72*8e05e376SStephan Aßmus 	b.right = ceilf((b.left + b.right) / 3.0);
73*8e05e376SStephan Aßmus 	BBox* bg = new BBox(b, "bg box", B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW, B_PLAIN_BORDER);
7478c1c29bSStephan Aßmus 
7578c1c29bSStephan Aßmus 	AddChild(bg);
7678c1c29bSStephan Aßmus 	bg->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
7778c1c29bSStephan Aßmus 
78*8e05e376SStephan Aßmus 	// object view occupies the right side of the window
79*8e05e376SStephan Aßmus 	b.left = b.right + 1.0;
80*8e05e376SStephan Aßmus 	b.right = Bounds().right - B_V_SCROLL_BAR_WIDTH;
81*8e05e376SStephan Aßmus 	b.bottom -= B_H_SCROLL_BAR_HEIGHT;
8278c1c29bSStephan Aßmus 	fObjectView = new ObjectView(b, "object view", B_FOLLOW_ALL,
8378c1c29bSStephan Aßmus 								 B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
84*8e05e376SStephan Aßmus 	// wrap a scroll view around the object view
85*8e05e376SStephan Aßmus 	BScrollView* scrollView = new BScrollView("object scroller", fObjectView,
86*8e05e376SStephan Aßmus 											  B_FOLLOW_ALL, 0, true, true,
87*8e05e376SStephan Aßmus 											  B_NO_BORDER);
8878c1c29bSStephan Aßmus 
89*8e05e376SStephan Aßmus 	if (BScrollBar* scrollBar = fObjectView->ScrollBar(B_VERTICAL)) {
90*8e05e376SStephan Aßmus 		scrollBar->SetRange(0.0, fObjectView->Bounds().Height());
91*8e05e376SStephan Aßmus 		scrollBar->SetProportion(0.5);
92*8e05e376SStephan Aßmus 	}
93*8e05e376SStephan Aßmus 	if (BScrollBar* scrollBar = fObjectView->ScrollBar(B_HORIZONTAL)) {
94*8e05e376SStephan Aßmus 		scrollBar->SetRange(0.0, fObjectView->Bounds().Width());
95*8e05e376SStephan Aßmus 		scrollBar->SetProportion(0.5);
96*8e05e376SStephan Aßmus 	}
97*8e05e376SStephan Aßmus 	AddChild(scrollView);
9878c1c29bSStephan Aßmus 
9978c1c29bSStephan Aßmus 	b = bg->Bounds();
10078c1c29bSStephan Aßmus 	// controls occupy the left side of the window
101*8e05e376SStephan Aßmus 	b.InsetBy(5.0, 5.0);
10278c1c29bSStephan Aßmus 	BBox* controlGroup = new BBox(b, "controls box", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
10378c1c29bSStephan Aßmus 								  B_WILL_DRAW, B_FANCY_BORDER);
10478c1c29bSStephan Aßmus 
10578c1c29bSStephan Aßmus 	controlGroup->SetLabel("Controls");
10678c1c29bSStephan Aßmus 	bg->AddChild(controlGroup);
10778c1c29bSStephan Aßmus 
10878c1c29bSStephan Aßmus 	b = controlGroup->Bounds();
10978c1c29bSStephan Aßmus 	b.top += 10.0;
11078c1c29bSStephan Aßmus 	b.bottom = b.top + 25.0;
11178c1c29bSStephan Aßmus 	b.InsetBy(5.0, 5.0);
11278c1c29bSStephan Aßmus 
11378c1c29bSStephan Aßmus 	// new button
11478c1c29bSStephan Aßmus 	fNewB = new BButton(b, "new button", "New Object", new BMessage(MSG_NEW_OBJECT));
11578c1c29bSStephan Aßmus 	controlGroup->AddChild(fNewB);
11678c1c29bSStephan Aßmus 
11778c1c29bSStephan Aßmus 	// clear button
11878c1c29bSStephan Aßmus 	b.OffsetBy(0, fNewB->Bounds().Height() + 5.0);
11978c1c29bSStephan Aßmus 	fClearB = new BButton(b, "clear button", "Clear", new BMessage(MSG_CLEAR));
12078c1c29bSStephan Aßmus 	controlGroup->AddChild(fClearB);
12178c1c29bSStephan Aßmus 
12278c1c29bSStephan Aßmus 	// object type radio buttons
12378c1c29bSStephan Aßmus 	BMessage* message;
12478c1c29bSStephan Aßmus 	BRadioButton* radioButton;
12578c1c29bSStephan Aßmus 
12678c1c29bSStephan Aßmus 	b.OffsetBy(0, fClearB->Bounds().Height() + 5.0);
12778c1c29bSStephan Aßmus 	message = new BMessage(MSG_SET_OBJECT_TYPE);
12878c1c29bSStephan Aßmus 	message->AddInt32("type", OBJECT_LINE);
12978c1c29bSStephan Aßmus 	radioButton = new BRadioButton(b, "radio 1", "Line", message);
13078c1c29bSStephan Aßmus 	controlGroup->AddChild(radioButton);
13178c1c29bSStephan Aßmus 
13278c1c29bSStephan Aßmus 	radioButton->SetValue(B_CONTROL_ON);
13378c1c29bSStephan Aßmus 
13478c1c29bSStephan Aßmus 	b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
13578c1c29bSStephan Aßmus 	message = new BMessage(MSG_SET_OBJECT_TYPE);
13678c1c29bSStephan Aßmus 	message->AddInt32("type", OBJECT_RECT);
13778c1c29bSStephan Aßmus 	radioButton = new BRadioButton(b, "radio 2", "Rect", message);
13878c1c29bSStephan Aßmus 	controlGroup->AddChild(radioButton);
13978c1c29bSStephan Aßmus 
14078c1c29bSStephan Aßmus 	b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
14178c1c29bSStephan Aßmus 	message = new BMessage(MSG_SET_OBJECT_TYPE);
14278c1c29bSStephan Aßmus 	message->AddInt32("type", OBJECT_ROUND_RECT);
14378c1c29bSStephan Aßmus 	radioButton = new BRadioButton(b, "radio 3", "Round Rect", message);
14478c1c29bSStephan Aßmus 	controlGroup->AddChild(radioButton);
14578c1c29bSStephan Aßmus 
14678c1c29bSStephan Aßmus 	b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
14778c1c29bSStephan Aßmus 	message = new BMessage(MSG_SET_OBJECT_TYPE);
14878c1c29bSStephan Aßmus 	message->AddInt32("type", OBJECT_ELLIPSE);
14978c1c29bSStephan Aßmus 	radioButton = new BRadioButton(b, "radio 4", "Ellipse", message);
15078c1c29bSStephan Aßmus 	controlGroup->AddChild(radioButton);
15178c1c29bSStephan Aßmus 
15281cc749fSStephan Aßmus 	// drawing mode
153579be6b8SStephan Aßmus 	BPopUpMenu* popupMenu = new BPopUpMenu("<pick>");
15481cc749fSStephan Aßmus 
15581cc749fSStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
15681cc749fSStephan Aßmus 	message->AddInt32("mode", B_OP_COPY);
157579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Copy", message));
15881cc749fSStephan Aßmus 
15981cc749fSStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
16081cc749fSStephan Aßmus 	message->AddInt32("mode", B_OP_OVER);
161579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Over", message));
162579be6b8SStephan Aßmus 
163579be6b8SStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
164579be6b8SStephan Aßmus 	message->AddInt32("mode", B_OP_INVERT);
165579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Invert", message));
166579be6b8SStephan Aßmus 
167579be6b8SStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
168579be6b8SStephan Aßmus 	message->AddInt32("mode", B_OP_BLEND);
169579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Blend", message));
170579be6b8SStephan Aßmus 
171579be6b8SStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
172579be6b8SStephan Aßmus 	message->AddInt32("mode", B_OP_SELECT);
173579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Select", message));
174579be6b8SStephan Aßmus 
175579be6b8SStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
176579be6b8SStephan Aßmus 	message->AddInt32("mode", B_OP_ERASE);
177579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Erase", message));
178579be6b8SStephan Aßmus 
179579be6b8SStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
180579be6b8SStephan Aßmus 	message->AddInt32("mode", B_OP_ADD);
181579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Add", message));
182579be6b8SStephan Aßmus 
183579be6b8SStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
184579be6b8SStephan Aßmus 	message->AddInt32("mode", B_OP_SUBTRACT);
185579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Subtract", message));
186579be6b8SStephan Aßmus 
187579be6b8SStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
188579be6b8SStephan Aßmus 	message->AddInt32("mode", B_OP_MIN);
189579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Min", message));
190579be6b8SStephan Aßmus 
191579be6b8SStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
192579be6b8SStephan Aßmus 	message->AddInt32("mode", B_OP_MAX);
193579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Max", message));
194579be6b8SStephan Aßmus 
195579be6b8SStephan Aßmus 	message = new BMessage(MSG_SET_DRAWING_MODE);
196579be6b8SStephan Aßmus 	message->AddInt32("mode", B_OP_ALPHA);
197579be6b8SStephan Aßmus 	popupMenu->AddItem(new BMenuItem("Alpha", message));
19881cc749fSStephan Aßmus 
19981cc749fSStephan Aßmus 	b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
20081cc749fSStephan Aßmus 	fDrawingModeMF = new BMenuField(b, "drawing mode field", "Mode",
20181cc749fSStephan Aßmus 									popupMenu);
20281cc749fSStephan Aßmus 
20381cc749fSStephan Aßmus 	controlGroup->AddChild(fDrawingModeMF);
20481cc749fSStephan Aßmus 
20581cc749fSStephan Aßmus 	fDrawingModeMF->SetDivider(fDrawingModeMF->StringWidth(fDrawingModeMF->Label()) + 10.0);
206579be6b8SStephan Aßmus 
20778c1c29bSStephan Aßmus 	// red text control
208579be6b8SStephan Aßmus 	b.OffsetBy(0, fDrawingModeMF->Bounds().Height() + 5.0);
20978c1c29bSStephan Aßmus 	fRedTC = new BTextControl(b, "red text control", "Red", "",
21078c1c29bSStephan Aßmus 							  new BMessage(MSG_SET_COLOR));
21178c1c29bSStephan Aßmus 	controlGroup->AddChild(fRedTC);
21278c1c29bSStephan Aßmus 
21378c1c29bSStephan Aßmus 	// green text control
21478c1c29bSStephan Aßmus 	b.OffsetBy(0, fRedTC->Bounds().Height() + 5.0);
21578c1c29bSStephan Aßmus 	fGreenTC = new BTextControl(b, "green text control", "Green", "",
21678c1c29bSStephan Aßmus 								new BMessage(MSG_SET_COLOR));
21778c1c29bSStephan Aßmus 	controlGroup->AddChild(fGreenTC);
21878c1c29bSStephan Aßmus 
21978c1c29bSStephan Aßmus 	// blue text control
22078c1c29bSStephan Aßmus 	b.OffsetBy(0, fGreenTC->Bounds().Height() + 5.0);
22178c1c29bSStephan Aßmus 	fBlueTC = new BTextControl(b, "blue text control", "Blue", "",
22278c1c29bSStephan Aßmus 							   new BMessage(MSG_SET_COLOR));
22378c1c29bSStephan Aßmus 	controlGroup->AddChild(fBlueTC);
22478c1c29bSStephan Aßmus 
22578c1c29bSStephan Aßmus 	// alpha text control
22678c1c29bSStephan Aßmus 	b.OffsetBy(0, fBlueTC->Bounds().Height() + 5.0);
22778c1c29bSStephan Aßmus 	fAlphaTC = new BTextControl(b, "alpha text control", "Alpha", "",
22878c1c29bSStephan Aßmus 								new BMessage(MSG_SET_COLOR));
22978c1c29bSStephan Aßmus 	controlGroup->AddChild(fAlphaTC);
230*8e05e376SStephan Aßmus 
23178c1c29bSStephan Aßmus // TODO: while this block of code works in the Haiku app_server running under R5,
23278c1c29bSStephan Aßmus // it crashes pretty badly under Haiku. I have no idea why this happens, because
23378c1c29bSStephan Aßmus // I was doing the same thing before at other places.
23478c1c29bSStephan Aßmus 	// divide text controls the same
235*8e05e376SStephan Aßmus 	float mWidth = fDrawingModeMF->StringWidth(fDrawingModeMF->Label());
23678c1c29bSStephan Aßmus 	float rWidth = fRedTC->StringWidth(fRedTC->Label());
23778c1c29bSStephan Aßmus 	float gWidth = fGreenTC->StringWidth(fGreenTC->Label());
23878c1c29bSStephan Aßmus 	float bWidth = fBlueTC->StringWidth(fBlueTC->Label());
23978c1c29bSStephan Aßmus 	float aWidth = fAlphaTC->StringWidth(fAlphaTC->Label());
24078c1c29bSStephan Aßmus 
241*8e05e376SStephan Aßmus 	float width = max_c(mWidth, max_c(rWidth, max_c(gWidth, max_c(bWidth, aWidth)))) + 10.0;
242*8e05e376SStephan Aßmus 	fDrawingModeMF->SetDivider(width);
24378c1c29bSStephan Aßmus 	fRedTC->SetDivider(width);
24478c1c29bSStephan Aßmus 	fGreenTC->SetDivider(width);
24578c1c29bSStephan Aßmus 	fBlueTC->SetDivider(width);
246*8e05e376SStephan Aßmus 	fAlphaTC->SetDivider(width);
24778c1c29bSStephan Aßmus 
24878c1c29bSStephan Aßmus 	// fill check box
24978c1c29bSStephan Aßmus 	b.OffsetBy(0, fAlphaTC->Bounds().Height() + 5.0);
25078c1c29bSStephan Aßmus 	fFillCB = new BCheckBox(b, "fill check box", "Fill",
25178c1c29bSStephan Aßmus 							new BMessage(MSG_SET_FILL_OR_STROKE));
25278c1c29bSStephan Aßmus 	controlGroup->AddChild(fFillCB);
25378c1c29bSStephan Aßmus 
25478c1c29bSStephan Aßmus 	// pen size text control
25578c1c29bSStephan Aßmus 	b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
256b7f478e2SStephan Aßmus 	b.bottom = b.top + 10.0;//35;
257b7f478e2SStephan Aßmus 	fPenSizeS = new BSlider(b, "width slider", "Width",
258b7f478e2SStephan Aßmus 							NULL, 1, 100, B_TRIANGLE_THUMB);
259b7f478e2SStephan Aßmus 	fPenSizeS->SetLimitLabels("1", "100");
260b7f478e2SStephan Aßmus 	fPenSizeS->SetModificationMessage(new BMessage(MSG_SET_PEN_SIZE));
261b7f478e2SStephan Aßmus 	fPenSizeS->SetHashMarks(B_HASH_MARKS_BOTTOM);
262b7f478e2SStephan Aßmus 	fPenSizeS->SetHashMarkCount(10);
263b7f478e2SStephan Aßmus 
264b7f478e2SStephan Aßmus 	controlGroup->AddChild(fPenSizeS);
265b7f478e2SStephan Aßmus 
266b7f478e2SStephan Aßmus 	// enforce some size limits
267b7f478e2SStephan Aßmus 	float minWidth = controlGroup->Frame().Width() + 30.0;
268b7f478e2SStephan Aßmus 	float minHeight = fPenSizeS->Frame().bottom +
269b7f478e2SStephan Aßmus 					  menuBar->Bounds().Height() + 15.0;
270b7f478e2SStephan Aßmus 	float maxWidth = minWidth * 4.0;
271b7f478e2SStephan Aßmus 	float maxHeight = minHeight;
272b7f478e2SStephan Aßmus 	SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
27378c1c29bSStephan Aßmus 
274e4bcf6e0SStephan Aßmus 	ResizeTo(max_c(frame.Width(), minWidth), max_c(frame.Height(), minHeight));
275e4bcf6e0SStephan Aßmus 
27678c1c29bSStephan Aßmus 	_UpdateControls();
27778c1c29bSStephan Aßmus }
27878c1c29bSStephan Aßmus 
27978c1c29bSStephan Aßmus // destructor
28078c1c29bSStephan Aßmus ObjectWindow::~ObjectWindow()
28178c1c29bSStephan Aßmus {
28278c1c29bSStephan Aßmus }
28378c1c29bSStephan Aßmus 
28478c1c29bSStephan Aßmus // QuitRequested
28578c1c29bSStephan Aßmus bool
28678c1c29bSStephan Aßmus ObjectWindow::QuitRequested()
28778c1c29bSStephan Aßmus {
28878c1c29bSStephan Aßmus 	be_app->PostMessage(B_QUIT_REQUESTED);
28978c1c29bSStephan Aßmus 	return true;
29078c1c29bSStephan Aßmus }
29178c1c29bSStephan Aßmus 
29278c1c29bSStephan Aßmus // MessageReceived
29378c1c29bSStephan Aßmus void
29478c1c29bSStephan Aßmus ObjectWindow::MessageReceived(BMessage* message)
29578c1c29bSStephan Aßmus {
29678c1c29bSStephan Aßmus 	switch (message->what) {
29778c1c29bSStephan Aßmus 		case MSG_SET_OBJECT_TYPE: {
29878c1c29bSStephan Aßmus 			int32 type;
29978c1c29bSStephan Aßmus 			if (message->FindInt32("type", &type) >= B_OK) {
30078c1c29bSStephan Aßmus 				fObjectView->SetObjectType(type);
30178c1c29bSStephan Aßmus 				fFillCB->SetEnabled(type != OBJECT_LINE);
302e803c97cSStephan Aßmus 				if (!fFillCB->IsEnabled())
303b7f478e2SStephan Aßmus 					fPenSizeS->SetEnabled(true);
304e803c97cSStephan Aßmus 				else
305b7f478e2SStephan Aßmus 					fPenSizeS->SetEnabled(fFillCB->Value() == B_CONTROL_OFF);
30678c1c29bSStephan Aßmus 			}
30778c1c29bSStephan Aßmus 			break;
30878c1c29bSStephan Aßmus 		}
30978c1c29bSStephan Aßmus 		case MSG_SET_FILL_OR_STROKE: {
31078c1c29bSStephan Aßmus 			int32 value;
31178c1c29bSStephan Aßmus 			if (message->FindInt32("be:value", &value) >= B_OK) {
31278c1c29bSStephan Aßmus 				fObjectView->SetStateFill(value);
313b7f478e2SStephan Aßmus 				fPenSizeS->SetEnabled(value == B_CONTROL_OFF);
31478c1c29bSStephan Aßmus 			}
31578c1c29bSStephan Aßmus 			break;
31678c1c29bSStephan Aßmus 		}
31778c1c29bSStephan Aßmus 		case MSG_SET_COLOR:
31878c1c29bSStephan Aßmus 			fObjectView->SetStateColor(_GetColor());
31981cc749fSStephan Aßmus 			_UpdateColorControls();
32078c1c29bSStephan Aßmus 			break;
32178c1c29bSStephan Aßmus 		case MSG_OBJECT_COUNT_CHANGED:
32278c1c29bSStephan Aßmus 			fClearB->SetEnabled(fObjectView->CountObjects() > 0);
32378c1c29bSStephan Aßmus 			break;
32478c1c29bSStephan Aßmus 		case MSG_NEW_OBJECT:
32578c1c29bSStephan Aßmus 			fObjectView->SetState(NULL);
32678c1c29bSStephan Aßmus 			break;
3274dfc2afbSAxel Dörfler 		case MSG_CLEAR: {
328590fdd3fSStephan Aßmus 			BAlert *alert = new BAlert("Playground", "Do you really want to clear all drawing objects?", "No", "Yes");
329590fdd3fSStephan Aßmus 			if (alert->Go() == 1) {
33078c1c29bSStephan Aßmus 				fObjectView->MakeEmpty();
331590fdd3fSStephan Aßmus 			}
33278c1c29bSStephan Aßmus 			break;
3334dfc2afbSAxel Dörfler 		}
33478c1c29bSStephan Aßmus 		case MSG_SET_PEN_SIZE:
335b7f478e2SStephan Aßmus 			fObjectView->SetStatePenSize((float)fPenSizeS->Value());
33678c1c29bSStephan Aßmus 			break;
337*8e05e376SStephan Aßmus 		case MSG_SET_DRAWING_MODE: {
338*8e05e376SStephan Aßmus 			drawing_mode mode;
339*8e05e376SStephan Aßmus 			if (message->FindInt32("mode", (int32*)&mode) >= B_OK) {
340*8e05e376SStephan Aßmus 				fObjectView->SetStateDrawingMode(mode);
341*8e05e376SStephan Aßmus 			}
342*8e05e376SStephan Aßmus 			break;
343*8e05e376SStephan Aßmus 		}
34478c1c29bSStephan Aßmus 		default:
34578c1c29bSStephan Aßmus 			BWindow::MessageReceived(message);
34678c1c29bSStephan Aßmus 	}
34778c1c29bSStephan Aßmus }
34878c1c29bSStephan Aßmus 
34978c1c29bSStephan Aßmus // _UpdateControls
35078c1c29bSStephan Aßmus void
35178c1c29bSStephan Aßmus ObjectWindow::_UpdateControls() const
35278c1c29bSStephan Aßmus {
35381cc749fSStephan Aßmus 	_UpdateColorControls();
35481cc749fSStephan Aßmus 
35581cc749fSStephan Aßmus 	// update buttons
35681cc749fSStephan Aßmus 	fClearB->SetEnabled(fObjectView->CountObjects() > 0);
35781cc749fSStephan Aßmus 
35881cc749fSStephan Aßmus 	fFillCB->SetEnabled(fObjectView->ObjectType() != OBJECT_LINE);
35981cc749fSStephan Aßmus 
36081cc749fSStephan Aßmus 	// pen size
361b7f478e2SStephan Aßmus 	fPenSizeS->SetValue((int32)fObjectView->StatePenSize());
36281cc749fSStephan Aßmus 
36381cc749fSStephan Aßmus 	// disable penSize if fill is on
36481cc749fSStephan Aßmus 	if (!fFillCB->IsEnabled())
365b7f478e2SStephan Aßmus 		fPenSizeS->SetEnabled(true);
36681cc749fSStephan Aßmus 	else
367b7f478e2SStephan Aßmus 		fPenSizeS->SetEnabled(fFillCB->Value() == B_CONTROL_OFF);
36881cc749fSStephan Aßmus }
36981cc749fSStephan Aßmus 
37081cc749fSStephan Aßmus // _UpdateColorControls
37181cc749fSStephan Aßmus void
37281cc749fSStephan Aßmus ObjectWindow::_UpdateColorControls() const
37381cc749fSStephan Aßmus {
37478c1c29bSStephan Aßmus 	// update color
37578c1c29bSStephan Aßmus 	rgb_color c = fObjectView->StateColor();
37678c1c29bSStephan Aßmus 	char string[32];
37778c1c29bSStephan Aßmus 
37878c1c29bSStephan Aßmus 	sprintf(string, "%d", c.red);
37978c1c29bSStephan Aßmus 	fRedTC->SetText(string);
38078c1c29bSStephan Aßmus 
38178c1c29bSStephan Aßmus 	sprintf(string, "%d", c.green);
38278c1c29bSStephan Aßmus 	fGreenTC->SetText(string);
38378c1c29bSStephan Aßmus 
38478c1c29bSStephan Aßmus 	sprintf(string, "%d", c.blue);
38578c1c29bSStephan Aßmus 	fBlueTC->SetText(string);
38678c1c29bSStephan Aßmus 
38778c1c29bSStephan Aßmus 	sprintf(string, "%d", c.alpha);
38878c1c29bSStephan Aßmus 	fAlphaTC->SetText(string);
38978c1c29bSStephan Aßmus }
39078c1c29bSStephan Aßmus 
39178c1c29bSStephan Aßmus // _GetColor
39278c1c29bSStephan Aßmus rgb_color
39378c1c29bSStephan Aßmus ObjectWindow::_GetColor() const
39478c1c29bSStephan Aßmus {
39578c1c29bSStephan Aßmus 	rgb_color c;
39678c1c29bSStephan Aßmus 	c.red	= max_c(0, min_c(255, atoi(fRedTC->Text())));
39778c1c29bSStephan Aßmus 	c.green	= max_c(0, min_c(255, atoi(fGreenTC->Text())));
39878c1c29bSStephan Aßmus 	c.blue	= max_c(0, min_c(255, atoi(fBlueTC->Text())));
39978c1c29bSStephan Aßmus 	c.alpha	= max_c(0, min_c(255, atoi(fAlphaTC->Text())));
40078c1c29bSStephan Aßmus 
40178c1c29bSStephan Aßmus 	return c;
40278c1c29bSStephan Aßmus }
40378c1c29bSStephan Aßmus 
404