xref: /haiku/src/apps/gradients/GradientsWindow.cpp (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 /*
2  * Copyright (c) 2008-2009, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Artur Wyszynski <harakash@gmail.com>
7  */
8 
9 
10 #include "GradientsWindow.h"
11 
12 
13 GradientsWindow::GradientsWindow()
14 	: BWindow(BRect(0, 0, 230, 490), "Gradients Test", B_TITLED_WINDOW,
15 		B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
16 {
17 	BRect field(10, 10, Bounds().Width() - 10, 30);
18 	fGradientsMenu = new BPopUpMenu("gradientsType");
19 	fLinearItem = new BMenuItem("Linear", new BMessage(MSG_LINEAR));
20 	fRadialItem = new BMenuItem("Radial", new BMessage(MSG_RADIAL));
21 	fRadialFocusItem = new BMenuItem("Radial focus",
22 		new BMessage(MSG_RADIAL_FOCUS));
23 
24 	fDiamondItem = new BMenuItem("Diamond", new BMessage(MSG_DIAMOND));
25 	fConicItem = new BMenuItem("Conic", new BMessage(MSG_CONIC));
26 	fGradientsMenu->AddItem(fLinearItem);
27 	fGradientsMenu->AddItem(fRadialItem);
28 	fGradientsMenu->AddItem(fRadialFocusItem);
29 	fGradientsMenu->AddItem(fDiamondItem);
30 	fGradientsMenu->AddItem(fConicItem);
31 	fLinearItem->SetMarked(true);
32 	fGradientsTypeField = new BMenuField(field, "gradientsField",
33 		"Gradient type:", fGradientsMenu, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
34 		B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS);
35 	fGradientsTypeField->SetViewColor(255, 255, 255);
36 	fGradientsTypeField->SetDivider(110);
37 	AddChild(fGradientsTypeField);
38 
39 	BRect bounds = Bounds();
40 	bounds.top = 40;
41 	fGradientsView = new GradientsView(bounds);
42 	AddChild(fGradientsView);
43 
44 	MoveTo((BScreen().Frame().Width() - Bounds().Width()) / 2,
45 		(BScreen().Frame().Height() - Bounds().Height()) / 2 );
46 }
47 
48 
49 bool
50 GradientsWindow::QuitRequested()
51 {
52 	be_app->PostMessage(B_QUIT_REQUESTED);
53 	return true;
54 }
55 
56 
57 void
58 GradientsWindow::MessageReceived(BMessage *msg)
59 {
60 	switch (msg->what) {
61 		case MSG_LINEAR:
62 			fGradientsView->SetType(BGradient::TYPE_LINEAR);
63 			break;
64 		case MSG_RADIAL:
65 			fGradientsView->SetType(BGradient::TYPE_RADIAL);
66 			break;
67 		case MSG_RADIAL_FOCUS:
68 			fGradientsView->SetType(BGradient::TYPE_RADIAL_FOCUS);
69 			break;
70 		case MSG_DIAMOND:
71 			fGradientsView->SetType(BGradient::TYPE_DIAMOND);
72 			break;
73 		case MSG_CONIC:
74 			fGradientsView->SetType(BGradient::TYPE_CONIC);
75 			break;
76 		default:
77 			BWindow::MessageReceived(msg);
78 			break;
79 	}
80 }
81