diff --git a/src/apps/gradients/GradientsApp.cpp b/src/apps/gradients/GradientsApp.cpp new file mode 100644 index 0000000000..8d4f875a66 --- /dev/null +++ b/src/apps/gradients/GradientsApp.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2008-2009, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Artur Wyszynski + */ + + +#include "GradientsApp.h" + + +#include "GradientsWindow.h" + + +GradientsApp::GradientsApp(void) + : BApplication("application/x-vnd.Haiku-Gradients") +{ + GradientsWindow* window = new GradientsWindow(); + window->Show(); +} + + +int +main() +{ + GradientsApp app; + app.Run(); + return 0; +} diff --git a/src/apps/gradients/GradientsApp.h b/src/apps/gradients/GradientsApp.h new file mode 100644 index 0000000000..a9114c04db --- /dev/null +++ b/src/apps/gradients/GradientsApp.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2008-2009, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Artur Wyszynski + */ + + +#include + + +class GradientsApp : public BApplication { +public: + GradientsApp(void); +}; diff --git a/src/apps/gradients/Gradients.cpp b/src/apps/gradients/GradientsView.cpp similarity index 60% rename from src/apps/gradients/Gradients.cpp rename to src/apps/gradients/GradientsView.cpp index 4d9c014d11..443c2d46e9 100644 --- a/src/apps/gradients/Gradients.cpp +++ b/src/apps/gradients/GradientsView.cpp @@ -1,161 +1,18 @@ /* - * Copyright (c) 2008, Haiku, Inc. + * Copyright (c) 2008-2009, Haiku, Inc. * Distributed under the terms of the MIT license. * * Authors: * Artur Wyszynski */ -#include + +#include "GradientsView.h" #include #include #include #include #include -#include -#include -#include -#include -#include -#include - - -#define MSG_LINEAR 'gtli' -#define MSG_RADIAL 'gtra' -#define MSG_RADIAL_FOCUS 'gtrf' -#define MSG_DIAMOND 'gtdi' -#define MSG_CONIC 'gtco' - -class GradientsApp : public BApplication { -public: - GradientsApp(void); -}; - - -class GradientsView : public BView { -public: - GradientsView(const BRect &r); - virtual ~GradientsView(void); - - virtual void Draw(BRect update); - void DrawLinear(BRect update); - void DrawRadial(BRect update); - void DrawRadialFocus(BRect update); - void DrawDiamond(BRect update); - void DrawConic(BRect update); - void SetType(BGradient::Type type); - -private: - BGradient::Type fType; -}; - - -class GradientsWindow : public BWindow { -public: - GradientsWindow(void); - - bool QuitRequested(void); - virtual void MessageReceived(BMessage *msg); - -private: - BPopUpMenu* fGradientsMenu; - BMenuItem* fLinearItem; - BMenuItem* fRadialItem; - BMenuItem* fRadialFocusItem; - BMenuItem* fDiamondItem; - BMenuItem* fConicItem; - BMenuField* fGradientsTypeField; - GradientsView* fGradientsView; -}; - - -// #pragma mark - - - -GradientsApp::GradientsApp(void) - : BApplication("application/x-vnd.Haiku-Gradients") -{ - GradientsWindow *window = new GradientsWindow(); - window->Show(); -} - - -// #pragma mark - - - -GradientsWindow::GradientsWindow() - : BWindow(BRect(0, 0, 230, 490), "Gradients Test", B_TITLED_WINDOW, - B_NOT_RESIZABLE | B_NOT_ZOOMABLE) -{ - BRect field(10, 10, Bounds().Width() - 10, 30); - fGradientsMenu = new BPopUpMenu("gradientsType"); - fLinearItem = new BMenuItem("Linear", new BMessage(MSG_LINEAR)); - fRadialItem = new BMenuItem("Radial", new BMessage(MSG_RADIAL)); - fRadialFocusItem = new BMenuItem("Radial Focus", - new BMessage(MSG_RADIAL_FOCUS)); - fDiamondItem = new BMenuItem("Diamond", new BMessage(MSG_DIAMOND)); - fConicItem = new BMenuItem("Conic", new BMessage(MSG_CONIC)); - fGradientsMenu->AddItem(fLinearItem); - fGradientsMenu->AddItem(fRadialItem); - fGradientsMenu->AddItem(fRadialFocusItem); - fGradientsMenu->AddItem(fDiamondItem); - fGradientsMenu->AddItem(fConicItem); - fLinearItem->SetMarked(true); - fGradientsTypeField = new BMenuField(field, "gradientsField", - "Gradient type:", - fGradientsMenu, - B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, - B_WILL_DRAW | B_NAVIGABLE - | B_FRAME_EVENTS); - fGradientsTypeField->SetViewColor(255, 255, 255); - fGradientsTypeField->SetDivider(110); - AddChild(fGradientsTypeField); - - BRect bounds = Bounds(); - bounds.top = 40; - fGradientsView = new GradientsView(bounds); - AddChild(fGradientsView); - - MoveTo((BScreen().Frame().Width() - Bounds().Width()) / 2, - (BScreen().Frame().Height() - Bounds().Height()) / 2 ); -} - - -bool -GradientsWindow::QuitRequested() -{ - be_app->PostMessage(B_QUIT_REQUESTED); - return true; -} - - -void -GradientsWindow::MessageReceived(BMessage *msg) -{ - switch (msg->what) { - case MSG_LINEAR: - fGradientsView->SetType(BGradient::TYPE_LINEAR); - break; - case MSG_RADIAL: - fGradientsView->SetType(BGradient::TYPE_RADIAL); - break; - case MSG_RADIAL_FOCUS: - fGradientsView->SetType(BGradient::TYPE_RADIAL_FOCUS); - break; - case MSG_DIAMOND: - fGradientsView->SetType(BGradient::TYPE_DIAMOND); - break; - case MSG_CONIC: - fGradientsView->SetType(BGradient::TYPE_CONIC); - break; - default: - BWindow::MessageReceived(msg); - break; - } -} - - -// #pragma mark - GradientsView::GradientsView(const BRect &rect) @@ -174,33 +31,33 @@ void GradientsView::Draw(BRect update) { switch (fType) { - case BGradient::TYPE_LINEAR: { + case BGradient::TYPE_LINEAR: DrawLinear(update); break; - } - case BGradient::TYPE_RADIAL: { + + case BGradient::TYPE_RADIAL: DrawRadial(update); break; - } - case BGradient::TYPE_RADIAL_FOCUS: { + + case BGradient::TYPE_RADIAL_FOCUS: DrawRadialFocus(update); break; - } - case BGradient::TYPE_DIAMOND: { + + case BGradient::TYPE_DIAMOND: DrawDiamond(update); break; - } - case BGradient::TYPE_CONIC: { + + case BGradient::TYPE_CONIC: DrawConic(update); break; - } + case BGradient::TYPE_NONE: - default: { + default: break; - } } } + void GradientsView::DrawLinear(BRect update) { @@ -238,7 +95,8 @@ GradientsView::DrawLinear(BRect update) FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330)); gradient.SetStart(BPoint(60, 230)); gradient.SetEnd(BPoint(60, 330)); - FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), gradient); + FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), + gradient); // Ellipse SetHighColor(0, 0, 0); @@ -283,7 +141,8 @@ GradientsView::DrawRadial(BRect update) SetHighColor(0, 0, 0); FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330)); gradient.SetCenter(BPoint(170, 280)); - FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), gradient); + FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), + gradient); // Ellipse SetHighColor(0, 0, 0); @@ -327,7 +186,8 @@ GradientsView::DrawRadialFocus(BRect update) SetHighColor(0, 0, 0); FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330)); gradient.SetCenter(BPoint(170, 280)); - FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), gradient); + FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), + gradient); // Ellipse SetHighColor(0, 0, 0); @@ -371,7 +231,8 @@ GradientsView::DrawDiamond(BRect update) SetHighColor(0, 0, 0); FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330)); gradient.SetCenter(BPoint(170, 280)); - FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), gradient); + FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), + gradient); // Ellipse SetHighColor(0, 0, 0); @@ -415,7 +276,8 @@ GradientsView::DrawConic(BRect update) SetHighColor(0, 0, 0); FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330)); gradient.SetCenter(BPoint(170, 280)); - FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), gradient); + FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), + gradient); // Ellipse SetHighColor(0, 0, 0); @@ -431,15 +293,3 @@ GradientsView::SetType(BGradient::Type type) fType = type; Invalidate(); } - - -// #pragma mark - - - -int -main() -{ - GradientsApp app; - app.Run(); - return 0; -} diff --git a/src/apps/gradients/GradientsView.h b/src/apps/gradients/GradientsView.h new file mode 100644 index 0000000000..b319e720c0 --- /dev/null +++ b/src/apps/gradients/GradientsView.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2008-2009, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Artur Wyszynski + */ + + +#include +#include + + +class GradientsView : public BView { +public: + GradientsView(const BRect &r); + virtual ~GradientsView(void); + + virtual void Draw(BRect update); + void DrawLinear(BRect update); + void DrawRadial(BRect update); + void DrawRadialFocus(BRect update); + void DrawDiamond(BRect update); + void DrawConic(BRect update); + void SetType(BGradient::Type type); + +private: + BGradient::Type fType; +}; diff --git a/src/apps/gradients/GradientsWindow.cpp b/src/apps/gradients/GradientsWindow.cpp new file mode 100644 index 0000000000..0668a7b31b --- /dev/null +++ b/src/apps/gradients/GradientsWindow.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2008-2009, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Artur Wyszynski + */ + + +#include "GradientsWindow.h" + + +GradientsWindow::GradientsWindow() + : BWindow(BRect(0, 0, 230, 490), "Gradients Test", B_TITLED_WINDOW, + B_NOT_RESIZABLE | B_NOT_ZOOMABLE) +{ + BRect field(10, 10, Bounds().Width() - 10, 30); + fGradientsMenu = new BPopUpMenu("gradientsType"); + fLinearItem = new BMenuItem("Linear", new BMessage(MSG_LINEAR)); + fRadialItem = new BMenuItem("Radial", new BMessage(MSG_RADIAL)); + fRadialFocusItem = new BMenuItem("Radial Focus", + new BMessage(MSG_RADIAL_FOCUS)); + + fDiamondItem = new BMenuItem("Diamond", new BMessage(MSG_DIAMOND)); + fConicItem = new BMenuItem("Conic", new BMessage(MSG_CONIC)); + fGradientsMenu->AddItem(fLinearItem); + fGradientsMenu->AddItem(fRadialItem); + fGradientsMenu->AddItem(fRadialFocusItem); + fGradientsMenu->AddItem(fDiamondItem); + fGradientsMenu->AddItem(fConicItem); + fLinearItem->SetMarked(true); + fGradientsTypeField = new BMenuField(field, "gradientsField", + "Gradient type:", fGradientsMenu, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, + B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS); + fGradientsTypeField->SetViewColor(255, 255, 255); + fGradientsTypeField->SetDivider(110); + AddChild(fGradientsTypeField); + + BRect bounds = Bounds(); + bounds.top = 40; + fGradientsView = new GradientsView(bounds); + AddChild(fGradientsView); + + MoveTo((BScreen().Frame().Width() - Bounds().Width()) / 2, + (BScreen().Frame().Height() - Bounds().Height()) / 2 ); +} + + +bool +GradientsWindow::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +void +GradientsWindow::MessageReceived(BMessage *msg) +{ + switch (msg->what) { + case MSG_LINEAR: + fGradientsView->SetType(BGradient::TYPE_LINEAR); + break; + case MSG_RADIAL: + fGradientsView->SetType(BGradient::TYPE_RADIAL); + break; + case MSG_RADIAL_FOCUS: + fGradientsView->SetType(BGradient::TYPE_RADIAL_FOCUS); + break; + case MSG_DIAMOND: + fGradientsView->SetType(BGradient::TYPE_DIAMOND); + break; + case MSG_CONIC: + fGradientsView->SetType(BGradient::TYPE_CONIC); + break; + default: + BWindow::MessageReceived(msg); + break; + } +} diff --git a/src/apps/gradients/GradientsWindow.h b/src/apps/gradients/GradientsWindow.h new file mode 100644 index 0000000000..cbf0c25475 --- /dev/null +++ b/src/apps/gradients/GradientsWindow.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008-2009, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Artur Wyszynski + */ + + +#include +#include +#include +#include +#include +#include + +#include "GradientsView.h" + +#define MSG_LINEAR 'gtli' +#define MSG_RADIAL 'gtra' +#define MSG_RADIAL_FOCUS 'gtrf' +#define MSG_DIAMOND 'gtdi' +#define MSG_CONIC 'gtco' + +class GradientsWindow : public BWindow { +public: + GradientsWindow(void); + + bool QuitRequested(void); + virtual void MessageReceived(BMessage* msg); + +private: + BPopUpMenu* fGradientsMenu; + BMenuItem* fLinearItem; + BMenuItem* fRadialItem; + BMenuItem* fRadialFocusItem; + BMenuItem* fDiamondItem; + BMenuItem* fConicItem; + BMenuField* fGradientsTypeField; + GradientsView* fGradientsView; +}; diff --git a/src/apps/gradients/Jamfile b/src/apps/gradients/Jamfile index d71ae003b7..ded51446f3 100644 --- a/src/apps/gradients/Jamfile +++ b/src/apps/gradients/Jamfile @@ -1,7 +1,10 @@ SubDir HAIKU_TOP src apps gradients ; Application Gradients : - Gradients.cpp +# Gradients.cpp + GradientsApp.cpp + GradientsWindow.cpp + GradientsView.cpp : be $(TARGET_LIBSUPC++) : Gradients.rdef ;