xref: /haiku/src/apps/gradients/GradientsWindow.cpp (revision 7974d3dcf39ce78e5885b481eee12e561ad6e096)
198a9fe15SFredrik Modeen /*
298a9fe15SFredrik Modeen  * Copyright (c) 2008-2009, Haiku, Inc.
398a9fe15SFredrik Modeen  * Distributed under the terms of the MIT license.
498a9fe15SFredrik Modeen  *
598a9fe15SFredrik Modeen  * Authors:
698a9fe15SFredrik Modeen  *		Artur Wyszynski <harakash@gmail.com>
798a9fe15SFredrik Modeen  */
898a9fe15SFredrik Modeen 
998a9fe15SFredrik Modeen 
1098a9fe15SFredrik Modeen #include "GradientsWindow.h"
1198a9fe15SFredrik Modeen 
1298a9fe15SFredrik Modeen 
GradientsWindow()1398a9fe15SFredrik Modeen GradientsWindow::GradientsWindow()
1498a9fe15SFredrik Modeen 	: BWindow(BRect(0, 0, 230, 490), "Gradients Test", B_TITLED_WINDOW,
1598a9fe15SFredrik Modeen 		B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
1698a9fe15SFredrik Modeen {
1798a9fe15SFredrik Modeen 	BRect field(10, 10, Bounds().Width() - 10, 30);
1898a9fe15SFredrik Modeen 	fGradientsMenu = new BPopUpMenu("gradientsType");
1998a9fe15SFredrik Modeen 	fLinearItem = new BMenuItem("Linear", new BMessage(MSG_LINEAR));
2098a9fe15SFredrik Modeen 	fRadialItem = new BMenuItem("Radial", new BMessage(MSG_RADIAL));
21*7974d3dcSStephan Aßmus 	fRadialFocusItem = new BMenuItem("Radial focus",
2298a9fe15SFredrik Modeen 		new BMessage(MSG_RADIAL_FOCUS));
2398a9fe15SFredrik Modeen 
2498a9fe15SFredrik Modeen 	fDiamondItem = new BMenuItem("Diamond", new BMessage(MSG_DIAMOND));
2598a9fe15SFredrik Modeen 	fConicItem = new BMenuItem("Conic", new BMessage(MSG_CONIC));
2698a9fe15SFredrik Modeen 	fGradientsMenu->AddItem(fLinearItem);
2798a9fe15SFredrik Modeen 	fGradientsMenu->AddItem(fRadialItem);
2898a9fe15SFredrik Modeen 	fGradientsMenu->AddItem(fRadialFocusItem);
2998a9fe15SFredrik Modeen 	fGradientsMenu->AddItem(fDiamondItem);
3098a9fe15SFredrik Modeen 	fGradientsMenu->AddItem(fConicItem);
3198a9fe15SFredrik Modeen 	fLinearItem->SetMarked(true);
3298a9fe15SFredrik Modeen 	fGradientsTypeField = new BMenuField(field, "gradientsField",
3398a9fe15SFredrik Modeen 		"Gradient type:", fGradientsMenu, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
3498a9fe15SFredrik Modeen 		B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS);
3598a9fe15SFredrik Modeen 	fGradientsTypeField->SetViewColor(255, 255, 255);
3698a9fe15SFredrik Modeen 	fGradientsTypeField->SetDivider(110);
3798a9fe15SFredrik Modeen 	AddChild(fGradientsTypeField);
3898a9fe15SFredrik Modeen 
3998a9fe15SFredrik Modeen 	BRect bounds = Bounds();
4098a9fe15SFredrik Modeen 	bounds.top = 40;
4198a9fe15SFredrik Modeen 	fGradientsView = new GradientsView(bounds);
4298a9fe15SFredrik Modeen 	AddChild(fGradientsView);
4398a9fe15SFredrik Modeen 
4498a9fe15SFredrik Modeen 	MoveTo((BScreen().Frame().Width() - Bounds().Width()) / 2,
4598a9fe15SFredrik Modeen 		(BScreen().Frame().Height() - Bounds().Height()) / 2 );
4698a9fe15SFredrik Modeen }
4798a9fe15SFredrik Modeen 
4898a9fe15SFredrik Modeen 
4998a9fe15SFredrik Modeen bool
QuitRequested()5098a9fe15SFredrik Modeen GradientsWindow::QuitRequested()
5198a9fe15SFredrik Modeen {
5298a9fe15SFredrik Modeen 	be_app->PostMessage(B_QUIT_REQUESTED);
5398a9fe15SFredrik Modeen 	return true;
5498a9fe15SFredrik Modeen }
5598a9fe15SFredrik Modeen 
5698a9fe15SFredrik Modeen 
5798a9fe15SFredrik Modeen void
MessageReceived(BMessage * msg)5898a9fe15SFredrik Modeen GradientsWindow::MessageReceived(BMessage *msg)
5998a9fe15SFredrik Modeen {
6098a9fe15SFredrik Modeen 	switch (msg->what) {
6198a9fe15SFredrik Modeen 		case MSG_LINEAR:
6298a9fe15SFredrik Modeen 			fGradientsView->SetType(BGradient::TYPE_LINEAR);
6398a9fe15SFredrik Modeen 			break;
6498a9fe15SFredrik Modeen 		case MSG_RADIAL:
6598a9fe15SFredrik Modeen 			fGradientsView->SetType(BGradient::TYPE_RADIAL);
6698a9fe15SFredrik Modeen 			break;
6798a9fe15SFredrik Modeen 		case MSG_RADIAL_FOCUS:
6898a9fe15SFredrik Modeen 			fGradientsView->SetType(BGradient::TYPE_RADIAL_FOCUS);
6998a9fe15SFredrik Modeen 			break;
7098a9fe15SFredrik Modeen 		case MSG_DIAMOND:
7198a9fe15SFredrik Modeen 			fGradientsView->SetType(BGradient::TYPE_DIAMOND);
7298a9fe15SFredrik Modeen 			break;
7398a9fe15SFredrik Modeen 		case MSG_CONIC:
7498a9fe15SFredrik Modeen 			fGradientsView->SetType(BGradient::TYPE_CONIC);
7598a9fe15SFredrik Modeen 			break;
7698a9fe15SFredrik Modeen 		default:
7798a9fe15SFredrik Modeen 			BWindow::MessageReceived(msg);
7898a9fe15SFredrik Modeen 			break;
7998a9fe15SFredrik Modeen 	}
8098a9fe15SFredrik Modeen }
81