hrev46915 adds 7 changesets to branch 'master' old head: 339e00cc32dc2e1d88eb1daa842481e5a645cb6c new head: 8e727810a7795df5c54b6f67a966969d8bbdb539 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=8e72781+%5E339e00c ---------------------------------------------------------------------------- ada2a0a: Screensaver: Small style fixes to PreviewView 0fb019b: Screensaver: Convert Screensaver to a BDirectWindow This allows OpenGL screensavers to be able to show a preview. 8237814: GLifeSaver: Show a preview Also, we are safe to enable direct mode now. 61935d5: Flurry: Show a preview Also, we are safe to enable direct mode now. This is untested due to this screensaver currently crashing but it should work once #10206 is fixed. ed18c89: Gravity: Show a preview Also, we are safe to enable direct mode now. 60f8c91: Gravity: Style fix, rename msg parameter to message 8e72781: Gravity: Live update settings and cleanup Now that this screensaver shows a preview, update the settings live so that the display updates immediately. Since this didn't work before this screensaver took a shortcut and only updated the settings when the saver started. Some other changes include: * Update copyright header, add myself to the authors list. * Convert Particle from using a BList to a BObjectList and remove casts. * Use switch statement to set particle color that has a default case for blue. * Initialize member variables to a default value in the constructor. * Remove Constants.h, the remaining constants are in ConfigView.cpp * Convert deprecated GroupLayoutBuilder to a LayoutBuilder template instance * Convert GravitySource from a class to a struct since all members are public. * Simplify realCount calculation to just a single left shift. * A bunch of style fixes - lots of whitespace fixes - rename rect to frame in GravityView and ConfigView - reorder the frame parameter first in GravityView and ConfigView - curly brace goes on same line as class or struct declaration This turned out to be a bigger change than I originally intended to make. [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- 19 files changed, 380 insertions(+), 292 deletions(-) src/add-ons/screen_savers/flurry/Flurry.cpp | 7 +- src/add-ons/screen_savers/glife/GLifeSaver.cpp | 26 +-- src/add-ons/screen_savers/glife/GLifeView.h | 5 +- src/add-ons/screen_savers/gravity/ConfigView.cpp | 85 +++++---- src/add-ons/screen_savers/gravity/ConfigView.h | 36 ++-- src/add-ons/screen_savers/gravity/Constants.h | 15 -- src/add-ons/screen_savers/gravity/Gravity.cpp | 45 ++--- src/add-ons/screen_savers/gravity/Gravity.h | 37 ++-- .../screen_savers/gravity/GravitySource.cpp | 11 +- .../screen_savers/gravity/GravitySource.h | 38 +++-- .../screen_savers/gravity/GravityView.cpp | 61 ++++--- src/add-ons/screen_savers/gravity/GravityView.h | 28 +-- src/add-ons/screen_savers/gravity/Particle.cpp | 171 ++++++++++++------- src/add-ons/screen_savers/gravity/Particle.h | 57 ++++--- src/preferences/screensaver/Jamfile | 3 +- src/preferences/screensaver/PreviewView.cpp | 8 +- src/preferences/screensaver/PreviewView.h | 6 +- .../screensaver/ScreenSaverWindow.cpp | 27 ++- src/preferences/screensaver/ScreenSaverWindow.h | 6 +- ############################################################################ Commit: ada2a0a1eff67cac1a6f98d72a51ef4433d72d3b URL: http://cgit.haiku-os.org/haiku/commit/?id=ada2a0a Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Feb 23 07:05:49 2014 UTC Screensaver: Small style fixes to PreviewView ---------------------------------------------------------------------------- diff --git a/src/preferences/screensaver/PreviewView.cpp b/src/preferences/screensaver/PreviewView.cpp index 3f2a5b2..c12881e 100644 --- a/src/preferences/screensaver/PreviewView.cpp +++ b/src/preferences/screensaver/PreviewView.cpp @@ -63,11 +63,11 @@ PreviewView::~PreviewView() void -PreviewView::Draw(BRect update) +PreviewView::Draw(BRect updateRect) { SetHighColor(184, 184, 184); FillRoundRect(scale2(0, 9, 0, 3, Bounds()), 4, 4); - // Outer shape + // outer shape FillRoundRect(scale2(2, 7, 3, 6, Bounds()), 2, 2); // control console outline @@ -75,7 +75,7 @@ PreviewView::Draw(BRect update) StrokeRoundRect(scale2(2, 7, 3, 6, Bounds()), 2, 2); // control console outline StrokeRoundRect(scale2(0, 9, 0, 3, Bounds()), 4, 4); - // Outline outer shape + // outline outer shape SetHighColor(0, 0, 0); FillRect(scale2(1, 8, 1, 2, Bounds())); @@ -84,7 +84,7 @@ PreviewView::Draw(BRect update) BRect outerShape = scale2(2, 7, 2, 6, Bounds()); outerShape.InsetBy(1, 1); FillRoundRect(outerShape, 4, 4); - // Outer shape + // outer shape SetHighColor(0, 255, 0); FillRect(scale2(3, 4, 4, 5, Bounds())); diff --git a/src/preferences/screensaver/PreviewView.h b/src/preferences/screensaver/PreviewView.h index c6518eb..b42a376 100644 --- a/src/preferences/screensaver/PreviewView.h +++ b/src/preferences/screensaver/PreviewView.h @@ -10,17 +10,17 @@ #define PREVIEW_VIEW_H -#include <View.h> #include <Box.h> #include <ScreenSaverRunner.h> +#include <View.h> -class PreviewView : public BView { +class PreviewView : public BView { public: PreviewView(const char* name); virtual ~PreviewView(); - virtual void Draw(BRect update); + virtual void Draw(BRect updateRect); BView* AddPreview(); BView* RemovePreview(); ############################################################################ Commit: 0fb019bbf21e791ae1f7644652fea3697b3f3d9f URL: http://cgit.haiku-os.org/haiku/commit/?id=0fb019b Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Feb 23 07:07:23 2014 UTC Screensaver: Convert Screensaver to a BDirectWindow This allows OpenGL screensavers to be able to show a preview. ---------------------------------------------------------------------------- diff --git a/src/preferences/screensaver/Jamfile b/src/preferences/screensaver/Jamfile index b8795a8..88698e0 100644 --- a/src/preferences/screensaver/Jamfile +++ b/src/preferences/screensaver/Jamfile @@ -18,8 +18,7 @@ Preference ScreenSaver : ScreenSaver.cpp # needed for some old/broken screen saver add-ons that do not # link against libscreensaver.so - - : tracker libscreensaver.so be $(TARGET_LIBSTDC++) localestub + : be game libscreensaver.so localestub tracker $(TARGET_LIBSTDC++) : ScreenSaver.rdef ; diff --git a/src/preferences/screensaver/ScreenSaverWindow.cpp b/src/preferences/screensaver/ScreenSaverWindow.cpp index f68666b..58cbb45 100644 --- a/src/preferences/screensaver/ScreenSaverWindow.cpp +++ b/src/preferences/screensaver/ScreenSaverWindow.cpp @@ -143,11 +143,12 @@ public: void SaveState(); + BScreenSaver* ScreenSaver(); + private: static int _CompareScreenSaverItems(const void* left, const void* right); - BScreenSaver* _ScreenSaver(); void _CloseSaver(); void _OpenSaver(); @@ -662,7 +663,7 @@ ModulesView::MessageReceived(BMessage* message) void ModulesView::SaveState() { - BScreenSaver* saver = _ScreenSaver(); + BScreenSaver* saver = ScreenSaver(); if (saver == NULL) return; @@ -746,7 +747,7 @@ ModulesView::_CompareScreenSaverItems(const void* left, const void* right) BScreenSaver* -ModulesView::_ScreenSaver() +ModulesView::ScreenSaver() { if (fSaverRunner != NULL) return fSaverRunner->ScreenSaver(); @@ -760,7 +761,7 @@ ModulesView::_CloseSaver() { // remove old screen saver preview & config - BScreenSaver* saver = _ScreenSaver(); + BScreenSaver* saver = ScreenSaver(); BView* view = fPreviewView->RemovePreview(); if (fSettingsView != NULL) fSettingsBox->RemoveChild(fSettingsView); @@ -802,7 +803,7 @@ ModulesView::_OpenSaver() fSettingsView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fSettingsBox->AddChild(fSettingsView); - BScreenSaver* saver = _ScreenSaver(); + BScreenSaver* saver = ScreenSaver(); if (saver != NULL && fSettingsView != NULL) { saver->StartConfig(fSettingsView); if (saver->StartSaver(view, false) == B_OK) @@ -827,8 +828,9 @@ ModulesView::_OpenSaver() ScreenSaverWindow::ScreenSaverWindow() : - BWindow(BRect(50, 50, 496, 375), B_TRANSLATE_SYSTEM_NAME("ScreenSaver"), - B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) + BDirectWindow(BRect(50, 50, 496, 375), + B_TRANSLATE_SYSTEM_NAME("ScreenSaver"), B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { fSettings.Load(); @@ -898,6 +900,15 @@ ScreenSaverWindow::~ScreenSaverWindow() void +ScreenSaverWindow::DirectConnected(direct_buffer_info* info) +{ + BScreenSaver* saver = fModulesView->ScreenSaver(); + if (saver != NULL) + saver->DirectConnected(info); +} + + +void ScreenSaverWindow::MessageReceived(BMessage* message) { switch (message->what) { @@ -912,7 +923,7 @@ ScreenSaverWindow::MessageReceived(BMessage* message) break; default: - BWindow::MessageReceived(message); + BDirectWindow::MessageReceived(message); } } diff --git a/src/preferences/screensaver/ScreenSaverWindow.h b/src/preferences/screensaver/ScreenSaverWindow.h index c3d70d6..3928394 100644 --- a/src/preferences/screensaver/ScreenSaverWindow.h +++ b/src/preferences/screensaver/ScreenSaverWindow.h @@ -12,7 +12,7 @@ #define SCREEN_SAVER_WINDOW_H -#include <Window.h> +#include <DirectWindow.h> #include "PasswordWindow.h" #include "ScreenSaverSettings.h" @@ -26,11 +26,13 @@ class FadeView; class ModulesView; -class ScreenSaverWindow : public BWindow { +class ScreenSaverWindow : public BDirectWindow { public: ScreenSaverWindow(); virtual ~ScreenSaverWindow(); + virtual void DirectConnected(direct_buffer_info* info); + virtual void MessageReceived(BMessage* message); virtual void ScreenChanged(BRect frame, color_space space); virtual bool QuitRequested(); ############################################################################ Commit: 823781426ff1e24083056d679211ee549a86e7af URL: http://cgit.haiku-os.org/haiku/commit/?id=8237814 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Feb 23 07:10:18 2014 UTC GLifeSaver: Show a preview Also, we are safe to enable direct mode now. ---------------------------------------------------------------------------- diff --git a/src/add-ons/screen_savers/glife/GLifeSaver.cpp b/src/add-ons/screen_savers/glife/GLifeSaver.cpp index 6b11f75..fdb0b7c 100644 --- a/src/add-ons/screen_savers/glife/GLifeSaver.cpp +++ b/src/add-ons/screen_savers/glife/GLifeSaver.cpp @@ -73,21 +73,15 @@ GLifeSaver::StartConfig(BView* pbvView) status_t GLifeSaver::StartSaver(BView* pbvView, bool bPreview) { - if (bPreview) { - // We do not use the preview option - fGLifeViewport = 0; - return B_ERROR; - } else { - SetTickSize(c_iTickSize); - - fGLifeViewport = new GLifeView(pbvView->Bounds(), - "GLifeView", B_FOLLOW_NONE, BGL_RGB | BGL_DEPTH | BGL_DOUBLE, - &fGLifeState); - - pbvView->AddChild(fGLifeViewport); - - return B_OK; - } + SetTickSize(c_iTickSize); + + fGLifeViewport = new GLifeView(pbvView->Bounds(), + "GLifeView", B_FOLLOW_NONE, BGL_RGB | BGL_DEPTH | BGL_DOUBLE, + &fGLifeState); + + pbvView->AddChild(fGLifeViewport); + + return B_OK; } @@ -107,12 +101,10 @@ void GLifeSaver::DirectConnected(direct_buffer_info* pdbiInfo) { // Enable or disable direct rendering - #if 1 if (fGLifeViewport != NULL) { fGLifeViewport->DirectConnected(pdbiInfo); fGLifeViewport->EnableDirectMode(true); } - #endif } diff --git a/src/add-ons/screen_savers/glife/GLifeView.h b/src/add-ons/screen_savers/glife/GLifeView.h index 4fe1b22..2b249e3 100644 --- a/src/add-ons/screen_savers/glife/GLifeView.h +++ b/src/add-ons/screen_savers/glife/GLifeView.h @@ -19,9 +19,10 @@ class GLifeView : public BGLView { public: // Constructor & Destructor - GLifeView(BRect, const char*, ulong, ulong, GLifeState*); + GLifeView(BRect, const char*, ulong, + ulong, GLifeState*); ~GLifeView(void); - + // Public Methods void AttachedToWindow(void); virtual void Draw(BRect updateRect); ############################################################################ Commit: 61935d56e6bd01fd58cb174969cd95bf3f0ab7e1 URL: http://cgit.haiku-os.org/haiku/commit/?id=61935d5 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Feb 23 07:12:39 2014 UTC Ticket: https://dev.haiku-os.org/ticket/10206 Flurry: Show a preview Also, we are safe to enable direct mode now. This is untested due to this screensaver currently crashing but it should work once #10206 is fixed. ---------------------------------------------------------------------------- diff --git a/src/add-ons/screen_savers/flurry/Flurry.cpp b/src/add-ons/screen_savers/flurry/Flurry.cpp index 1ac93e2..d6b462b 100644 --- a/src/add-ons/screen_savers/flurry/Flurry.cpp +++ b/src/add-ons/screen_savers/flurry/Flurry.cpp @@ -334,9 +334,6 @@ Flurry::StartSaver(BView* view, bool preview) { status_t result = B_ERROR; - if (preview) - return result; - SetTickSize(50000); fFlurryView = new (std::nothrow) FlurryView(view->Bounds()); @@ -374,8 +371,8 @@ Flurry::DirectConnected(direct_buffer_info* info) { // Enable or disable direct rendering if (fFlurryView != NULL) { - fFlurryView->DirectConnected(info); - fFlurryView->EnableDirectMode(true); + //fFlurryView->DirectConnected(info); + //fFlurryView->EnableDirectMode(true); } } ############################################################################ Commit: ed18c89481ec615c2d00ca4f6d50d85774a08152 URL: http://cgit.haiku-os.org/haiku/commit/?id=ed18c89 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Feb 23 07:14:09 2014 UTC Gravity: Show a preview Also, we are safe to enable direct mode now. ---------------------------------------------------------------------------- diff --git a/src/add-ons/screen_savers/gravity/Gravity.cpp b/src/add-ons/screen_savers/gravity/Gravity.cpp index afef0fe..2b000b0 100644 --- a/src/add-ons/screen_savers/gravity/Gravity.cpp +++ b/src/add-ons/screen_savers/gravity/Gravity.cpp @@ -52,16 +52,12 @@ Gravity::StartConfig(BView* view) status_t Gravity::StartSaver(BView* view, bool preview) { - if (preview) { - fView = NULL; - return B_ERROR; - } else { - SetTickSize((1000 / 20) * 1000); - // ~20 FPS - fView = new GravityView(this, view->Bounds()); - view->AddChild(fView); - return B_OK; - } + SetTickSize((1000 / 20) * 1000); + // ~20 FPS + fView = new GravityView(this, view->Bounds()); + view->AddChild(fView); + + return B_OK; } @@ -77,9 +73,8 @@ void Gravity::DirectConnected(direct_buffer_info* info) { if (fView != NULL) { - // TODO: Find out why I had to uncomment this. - // view->DirectConnected(pdbiInfo); - // view->EnableDirectMode(true); + fView->DirectConnected(info); + fView->EnableDirectMode(true); } } ############################################################################ Commit: 60f8c913552f23a88e7064f882f51da5fb30d8db URL: http://cgit.haiku-os.org/haiku/commit/?id=60f8c91 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Feb 23 07:16:29 2014 UTC Gravity: Style fix, rename msg parameter to message ---------------------------------------------------------------------------- diff --git a/src/add-ons/screen_savers/gravity/ConfigView.cpp b/src/add-ons/screen_savers/gravity/ConfigView.cpp index 3a4fe18..119b44e 100644 --- a/src/add-ons/screen_savers/gravity/ConfigView.cpp +++ b/src/add-ons/screen_savers/gravity/ConfigView.cpp @@ -87,9 +87,9 @@ ConfigView::AttachedToWindow() void -ConfigView::MessageReceived(BMessage* msg) +ConfigView::MessageReceived(BMessage* message) { - switch (msg->what) { + switch (message->what) { case MSG_COUNT: fParent->Config.ParticleCount = fCountSlider->Value(); break; @@ -99,6 +99,6 @@ ConfigView::MessageReceived(BMessage* msg) break; default: - BView::MessageReceived(msg); + BView::MessageReceived(message); } } diff --git a/src/add-ons/screen_savers/gravity/ConfigView.h b/src/add-ons/screen_savers/gravity/ConfigView.h index adfa77c..e0bca7e 100644 --- a/src/add-ons/screen_savers/gravity/ConfigView.h +++ b/src/add-ons/screen_savers/gravity/ConfigView.h @@ -21,7 +21,7 @@ public: ConfigView(Gravity* parent, BRect rect); void AttachedToWindow(); - void MessageReceived(BMessage* pbmMessage); + void MessageReceived(BMessage* message); private: Gravity* fParent; ############################################################################ Revision: hrev46915 Commit: 8e727810a7795df5c54b6f67a966969d8bbdb539 URL: http://cgit.haiku-os.org/haiku/commit/?id=8e72781 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Feb 23 08:50:15 2014 UTC Gravity: Live update settings and cleanup Now that this screensaver shows a preview, update the settings live so that the display updates immediately. Since this didn't work before this screensaver took a shortcut and only updated the settings when the saver started. Some other changes include: * Update copyright header, add myself to the authors list. * Convert Particle from using a BList to a BObjectList and remove casts. * Use switch statement to set particle color that has a default case for blue. * Initialize member variables to a default value in the constructor. * Remove Constants.h, the remaining constants are in ConfigView.cpp * Convert deprecated GroupLayoutBuilder to a LayoutBuilder template instance * Convert GravitySource from a class to a struct since all members are public. * Simplify realCount calculation to just a single left shift. * A bunch of style fixes - lots of whitespace fixes - rename rect to frame in GravityView and ConfigView - reorder the frame parameter first in GravityView and ConfigView - curly brace goes on same line as class or struct declaration This turned out to be a bigger change than I originally intended to make. ---------------------------------------------------------------------------- diff --git a/src/add-ons/screen_savers/gravity/ConfigView.cpp b/src/add-ons/screen_savers/gravity/ConfigView.cpp index 119b44e..ddaba2c 100644 --- a/src/add-ons/screen_savers/gravity/ConfigView.cpp +++ b/src/add-ons/screen_savers/gravity/ConfigView.cpp @@ -1,47 +1,48 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ #include "ConfigView.h" -#include "Constants.h" -#include "Gravity.h" - -#include <GroupLayoutBuilder.h> +#include <LayoutBuilder.h> #include <ListView.h> #include <ScrollView.h> #include <Slider.h> #include <StringView.h> #include <View.h> +#include "Gravity.h" + -ConfigView::ConfigView(Gravity* parent, BRect rect) +static const int32 kMsgSize = 'size'; +static const int32 kMsgShade = 'shad'; + + +ConfigView::ConfigView(BRect frame, Gravity* parent) : - BView(rect, B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, B_WILL_DRAW) + BView(frame, B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, B_WILL_DRAW), + fParent(parent), + fTitleString(new BStringView(B_EMPTY_STRING, "OpenGL Gravity Effect")), + fAuthorString(new BStringView(B_EMPTY_STRING, "by Tri-Edge AI")), + fCountSlider(new BSlider(B_EMPTY_STRING, "Particle Count: ", + new BMessage(kMsgSize), 0, 4, B_HORIZONTAL, B_BLOCK_THUMB, + B_NAVIGABLE | B_WILL_DRAW)), + fShadeString(new BStringView(B_EMPTY_STRING, "Shade: ")), + fShadeList(new BListView(B_EMPTY_STRING, B_SINGLE_SELECTION_LIST, + B_WILL_DRAW | B_NAVIGABLE)) { - fParent = parent; - SetLayout(new BGroupLayout(B_HORIZONTAL)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - fTitleString = new BStringView(RECT_0, B_EMPTY_STRING, - "OpenGL Gravity Effect", B_FOLLOW_LEFT); - - fAuthorString = new BStringView(RECT_0, B_EMPTY_STRING, - "by Tri-Edge AI", B_FOLLOW_LEFT); - - fCountSlider = new BSlider(RECT_0, B_EMPTY_STRING, "Particle Count: ", - new BMessage(MSG_COUNT), 0, 4, B_BLOCK_THUMB); - - fShadeString = new BStringView(RECT_0, B_EMPTY_STRING, "Shade: ", - B_FOLLOW_LEFT); - - fShadeList = new BListView(RECT_0, B_EMPTY_STRING, B_SINGLE_SELECTION_LIST, - B_FOLLOW_ALL); - - fShadeList->SetSelectionMessage(new BMessage(MSG_SHADE)); + fShadeList->SetSelectionMessage(new BMessage(kMsgShade)); fShadeList->AddItem(new BStringItem("Red")); fShadeList->AddItem(new BStringItem("Green")); @@ -59,22 +60,18 @@ ConfigView::ConfigView(Gravity* parent, BRect rect) fCountSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fCountSlider->SetHashMarkCount(5); fCountSlider->SetLimitLabels("128", "2048"); - + fCountSlider->SetModificationMessage(new BMessage(kMsgSize)); fCountSlider->SetValue(parent->Config.ParticleCount); - AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_DEFAULT_SPACING) - .Add(BGroupLayoutBuilder(B_VERTICAL, 0) - .Add(fTitleString) - .Add(fAuthorString) - ) - .Add(fShadeString) - .Add(fShadeScroll) - .Add(fCountSlider) - .SetInsets(B_USE_DEFAULT_SPACING, - B_USE_DEFAULT_SPACING, - B_USE_DEFAULT_SPACING, - B_USE_DEFAULT_SPACING) - ); + AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_DEFAULT_SPACING) + .AddGroup(B_VERTICAL, 0) + .Add(fTitleString) + .Add(fAuthorString) + .End() + .Add(fShadeString) + .Add(fShadeScroll) + .Add(fCountSlider) + .SetInsets(B_USE_DEFAULT_SPACING)); } @@ -90,11 +87,11 @@ void ConfigView::MessageReceived(BMessage* message) { switch (message->what) { - case MSG_COUNT: + case kMsgSize: fParent->Config.ParticleCount = fCountSlider->Value(); break; - case MSG_SHADE: + case kMsgShade: fParent->Config.ShadeID = fShadeList->CurrentSelection(); break; diff --git a/src/add-ons/screen_savers/gravity/ConfigView.h b/src/add-ons/screen_savers/gravity/ConfigView.h index e0bca7e..b6f87fc 100644 --- a/src/add-ons/screen_savers/gravity/ConfigView.h +++ b/src/add-ons/screen_savers/gravity/ConfigView.h @@ -1,6 +1,12 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ #ifndef GRAVITY_CONFIG_VIEW_H #define GRAVITY_CONFIG_VIEW_H @@ -8,6 +14,7 @@ #include <View.h> + class Gravity; class BListView; @@ -15,27 +22,26 @@ class BScrollView; class BSlider; class BStringView; -class ConfigView : public BView -{ + +class ConfigView : public BView { public: - ConfigView(Gravity* parent, BRect rect); + ConfigView(BRect frame, Gravity* parent); - void AttachedToWindow(); - void MessageReceived(BMessage* message); + void AttachedToWindow(); + void MessageReceived(BMessage* message); private: - Gravity* fParent; - - BStringView* fTitleString; - BStringView* fAuthorString; + Gravity* fParent; - BListView* fShadeList; - BStringView* fShadeString; - BScrollView* fShadeScroll; + BStringView* fTitleString; + BStringView* fAuthorString; - BSlider* fCountSlider; + BSlider* fCountSlider; + BStringView* fShadeString; + BListView* fShadeList; + BScrollView* fShadeScroll; }; -#endif +#endif // GRAVITY_CONFIG_VIEW_H diff --git a/src/add-ons/screen_savers/gravity/Constants.h b/src/add-ons/screen_savers/gravity/Constants.h deleted file mode 100644 index 15df98d..0000000 --- a/src/add-ons/screen_savers/gravity/Constants.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef CONSTANTS_H -#define CONSTANTS_H - - -#define MSG_SHADE 'm000' -#define MSG_COUNT 'm001' - -#define RECT_0 BRect(0, 0, 0, 0) - - -#endif diff --git a/src/add-ons/screen_savers/gravity/Gravity.cpp b/src/add-ons/screen_savers/gravity/Gravity.cpp index 2b000b0..b78aee6 100644 --- a/src/add-ons/screen_savers/gravity/Gravity.cpp +++ b/src/add-ons/screen_savers/gravity/Gravity.cpp @@ -1,6 +1,12 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ @@ -14,9 +20,12 @@ #include <stdlib.h> + Gravity::Gravity(BMessage* prefs, image_id imageID) : - BScreenSaver(prefs, imageID) + BScreenSaver(prefs, imageID), + fGravityView(NULL), + fConfigView(NULL) { srand(time(NULL)); @@ -45,7 +54,8 @@ Gravity::SaveState(BMessage* prefs) const void Gravity::StartConfig(BView* view) { - view->AddChild(new ConfigView(this, view->Bounds())); + fConfigView = new ConfigView(view->Bounds(), this); + view->AddChild(fConfigView); } @@ -54,8 +64,8 @@ Gravity::StartSaver(BView* view, bool preview) { SetTickSize((1000 / 20) * 1000); // ~20 FPS - fView = new GravityView(this, view->Bounds()); - view->AddChild(fView); + fGravityView = new GravityView(view->Bounds(), this); + view->AddChild(fGravityView); return B_OK; } @@ -64,17 +74,17 @@ Gravity::StartSaver(BView* view, bool preview) void Gravity::StopSaver() { - if (fView != NULL) - fView->EnableDirectMode(false); + if (fGravityView != NULL) + fGravityView->EnableDirectMode(false); } void Gravity::DirectConnected(direct_buffer_info* info) { - if (fView != NULL) { - fView->DirectConnected(info); - fView->EnableDirectMode(true); + if (fGravityView != NULL) { + fGravityView->DirectConnected(info); + fGravityView->EnableDirectMode(true); } } @@ -82,5 +92,5 @@ Gravity::DirectConnected(direct_buffer_info* info) void Gravity::DirectDraw(int32 frame) { - fView->DirectDraw(); + fGravityView->DirectDraw(); } diff --git a/src/add-ons/screen_savers/gravity/Gravity.h b/src/add-ons/screen_savers/gravity/Gravity.h index 6fc25f6..b549aa6 100644 --- a/src/add-ons/screen_savers/gravity/Gravity.h +++ b/src/add-ons/screen_savers/gravity/Gravity.h @@ -1,6 +1,12 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ #ifndef GRAVITY_SCREEN_SAVER_H #define GRAVITY_SCREEN_SAVER_H @@ -8,36 +14,37 @@ #include <ScreenSaver.h> -class GravityView; class BMessage; class BView; +class ConfigView; +class GravityView; + -class Gravity : public BScreenSaver -{ +class Gravity : public BScreenSaver { public: - struct - { + struct { int32 ShadeID; int32 ParticleCount; } Config; - Gravity(BMessage* prefs, image_id imageID); + Gravity(BMessage* prefs, image_id imageID); - status_t SaveState(BMessage* prefs) const; + status_t SaveState(BMessage* prefs) const; - void StartConfig(BView* view); + void StartConfig(BView* view); - status_t StartSaver(BView* view, bool preview); - void StopSaver(); + status_t StartSaver(BView* view, bool preview); + void StopSaver(); - void DirectConnected(direct_buffer_info* info); - void DirectDraw(int32 frame); + void DirectConnected(direct_buffer_info* info); + void DirectDraw(int32 frame); private: - GravityView* fView; + GravityView* fGravityView; + ConfigView* fConfigView; }; -#endif +#endif // GRAVITY_SCREEN_SAVER_H diff --git a/src/add-ons/screen_savers/gravity/GravitySource.cpp b/src/add-ons/screen_savers/gravity/GravitySource.cpp index 0348768..83c9630 100644 --- a/src/add-ons/screen_savers/gravity/GravitySource.cpp +++ b/src/add-ons/screen_savers/gravity/GravitySource.cpp @@ -1,9 +1,16 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ + #include "GravitySource.h" #include "Particle.h" @@ -59,7 +66,7 @@ GravitySource::Tick() } for (int32 i = 0; i < Particle::list->CountItems(); i++) { - Particle* p = (Particle*)Particle::list->ItemAt(i); + Particle* p = Particle::list->ItemAt(i); dx = x - p->x; dy = y - p->y; dz = z - p->z; diff --git a/src/add-ons/screen_savers/gravity/GravitySource.h b/src/add-ons/screen_savers/gravity/GravitySource.h index 0a44ef7..057a397 100644 --- a/src/add-ons/screen_savers/gravity/GravitySource.h +++ b/src/add-ons/screen_savers/gravity/GravitySource.h @@ -1,34 +1,36 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ + #ifndef GRAVITY_SOURCE_H #define GRAVITY_SOURCE_H -class GravitySource -{ -public: - float x; - float y; - float z; +struct GravitySource { + float x; + float y; + float z; float r; - float vx; - float vy; - float vz; + float vx; + float vy; + float vz; - float tx; - float ty; - float tz; + float tx; + float ty; + float tz; GravitySource(); - void Tick(); - -private: - + void Tick(); }; -#endif +#endif // GRAVITY_SOURCE_H diff --git a/src/add-ons/screen_savers/gravity/GravityView.cpp b/src/add-ons/screen_savers/gravity/GravityView.cpp index 3ae454d..3f92083 100644 --- a/src/add-ons/screen_savers/gravity/GravityView.cpp +++ b/src/add-ons/screen_savers/gravity/GravityView.cpp @@ -1,6 +1,12 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ @@ -13,29 +19,16 @@ #include <GL/glu.h> -GravityView::GravityView(Gravity* parent, BRect rect) +GravityView::GravityView(BRect frame, Gravity* parent) : - BGLView(rect, B_EMPTY_STRING, B_FOLLOW_NONE, 0, - BGL_RGB | BGL_DEPTH | BGL_DOUBLE) + BGLView(frame, B_EMPTY_STRING, B_FOLLOW_NONE, 0, + BGL_RGB | BGL_DEPTH | BGL_DOUBLE), + fParent(parent), + fGravitySource(new GravitySource()), + fSize(128 << parent->Config.ParticleCount), + fShade(parent->Config.ShadeID) { - fParent = parent; - - int realCount; - - if (parent->Config.ParticleCount == 0) - realCount = 128; - else if (parent->Config.ParticleCount == 1) - realCount = 256; - else if (parent->Config.ParticleCount == 2) - realCount = 512; - else if (parent->Config.ParticleCount == 3) - realCount = 1024; - else if (parent->Config.ParticleCount == 4) - realCount = 2048; - else - realCount = 128; - - Particle::Initialize(realCount, parent->Config.ShadeID); + Particle::Initialize(fSize, fShade); LockGL(); @@ -46,7 +39,7 @@ GravityView::GravityView(Gravity* parent, BRect rect) glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(45.0f, rect.Width() / rect.Height(), 2.0f, 20000.0f); + gluPerspective(45.0f, frame.Width() / frame.Height(), 2.0f, 20000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -55,15 +48,13 @@ GravityView::GravityView(Gravity* parent, BRect rect) glDepthMask(GL_FALSE); UnlockGL(); - - fGravSource = new GravitySource(); } GravityView::~GravityView() { Particle::Terminate(); - delete fGravSource; + delete fGravitySource; } @@ -79,13 +70,29 @@ GravityView::AttachedToWindow() void GravityView::DirectDraw() { + int32 size = 128 << fParent->Config.ParticleCount; + int32 shade = fParent->Config.ShadeID; + + // resize particle list if needed + if (size > fSize) + Particle::AddParticles(size, shade); + else if (size < fSize) + Particle::RemoveParticles(size, shade); + + // recolor particles if needed + if (shade != fShade) + Particle::ColorParticles(size, shade); + + fSize = size; + fShade = shade; + LockGL(); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Particle::Tick(); - fGravSource->Tick(); + fGravitySource->Tick(); SwapBuffers(); diff --git a/src/add-ons/screen_savers/gravity/GravityView.h b/src/add-ons/screen_savers/gravity/GravityView.h index 4557b60..b8072bc 100644 --- a/src/add-ons/screen_savers/gravity/GravityView.h +++ b/src/add-ons/screen_savers/gravity/GravityView.h @@ -1,6 +1,12 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ #ifndef GRAVITY_VIEW_H #define GRAVITY_VIEW_H @@ -12,21 +18,23 @@ class Gravity; class GravitySource; -class GravityView : public BGLView -{ + +class GravityView : public BGLView { public: - GravityView(Gravity* parent, BRect rect); - ~GravityView(); + GravityView(BRect frame, Gravity* parent); + ~GravityView(); - void AttachedToWindow(); + void AttachedToWindow(); - void DirectDraw(); + void DirectDraw(); private: - Gravity* fParent; - GravitySource* fGravSource; + Gravity* fParent; + GravitySource* fGravitySource; + int32 fSize; + int32 fShade; }; -#endif +#endif // GRAVITY_VIEW_H diff --git a/src/add-ons/screen_savers/gravity/Particle.cpp b/src/add-ons/screen_savers/gravity/Particle.cpp index 93cea67..8db7246 100644 --- a/src/add-ons/screen_savers/gravity/Particle.cpp +++ b/src/add-ons/screen_savers/gravity/Particle.cpp @@ -1,101 +1,81 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ #include "Particle.h" -#include <List.h> - #include <stdlib.h> #define frand() ((float)rand() / (float)RAND_MAX) -BList* Particle::list; +BObjectList<Particle>* Particle::list; -void +/*static*/ void Particle::Initialize(int32 size, int32 shade) { - list = new BList(); + list = new BObjectList<Particle>(2048); for (int32 i = 0; i < size; i++) { Particle* p = new Particle(); + Particle::_FillParticle(p, size, shade); + list->AddItem(p); + } +} - p->x = frand() * 30.0f - 15.0f; - p->y = frand() * 30.0f - 15.0f; - p->z = frand() * 5.0f; - p->r = frand() * 360.0f; - p->vx = frand() - 0.5f; - p->vy = frand() - 0.5f; - p->vz = frand() - 0.5f; - p->vr = (frand() - 0.5f) * 180.0f; +/*static*/ void +Particle::AddParticles(int32 size, int32 shade) +{ + for (int32 i = list->CountItems(); i < size; i++) { + Particle* p = new Particle(); + Particle::_FillParticle(p, size, shade); + list->AddItem(p); + } +} - if (shade == 0) { - // Red - p->red = 0.1f + frand() * 0.2f; - p->green = 0.0f; - p->blue = frand() * 0.05f; - } else if (shade == 1) { - // Green - p->red = 0; - p->green = 0.1f + frand() * 0.2f; - p->blue = frand() * 0.05f; - } else if (shade == 2) { - // Blue - p->red = 0; - p->green = frand() * 0.05f; - p->blue = 0.1f + frand() * 0.2f; - } else if (shade == 3) { - // Orange - p->red = 0.1f + frand() * 0.1f; - p->green = 0.05f + frand() * 0.1f; - p->blue = 0.0f; - } else if (shade == 4) { - // Purple - p->red = 0.1f + frand() * 0.2f; - p->green = 0.0f; - p->blue = 0.1f + frand() * 0.2f; - } else if (shade == 5) { - // White - p->red = p->green = p->blue = 0.1f + frand() * 0.2f; - } else if (shade == 6) { - // Rainbow - p->red = 0.1f + frand() * 0.2f; - p->green = 0.1f + frand() * 0.2f; - p->blue = 0.1f + frand() * 0.2f; - } else { - // Man, this shouldn't even happen.. Blue. - p->red = 0; - p->green = frand() * 0.05f; - p->blue = 0.1f + frand() * 0.2f; - } - list->AddItem(p); +/*static*/ void +Particle::RemoveParticles(int32 size, int32 shade) +{ + while (list->CountItems() > size) + delete list->RemoveItemAt(list->CountItems() - 1); +} + + +/*static*/ void +Particle::ColorParticles(int32 size, int32 shade) +{ + for (int32 i = 0; i < size; i++) { + Particle* p = list->ItemAt(i); + Particle::_ColorParticle(p, size, shade); } } -void +/*static*/ void Particle::Terminate() { - for (int32 i = 0; i < list->CountItems(); i++) - delete (Particle*)list->ItemAt(i); - list->MakeEmpty(); delete list; } -void +/*static*/ void Particle::Tick() { for (int32 i = 0; i < list->CountItems(); i++) { - Particle* p = (Particle*)list->ItemAt(i); + Particle* p = list->ItemAt(i); p->_Logic(); p->_Render(); } @@ -134,3 +114,74 @@ Particle::_Render() const glEnd(); glPopMatrix(); } + + +/*static*/ void +Particle::_FillParticle(Particle* p, int32 size, int32 shade) +{ + p->x = frand() * 30.0f - 15.0f; + p->y = frand() * 30.0f - 15.0f; + p->z = frand() * 5.0f; + p->r = frand() * 360.0f; + + p->vx = frand() - 0.5f; + p->vy = frand() - 0.5f; + p->vz = frand() - 0.5f; + p->vr = (frand() - 0.5f) * 180.0f; + + Particle::_ColorParticle(p, size, shade); +} + + +/*static*/ void +Particle::_ColorParticle(Particle* p, int32 size, int32 shade) +{ + switch(shade) { + case 0: + // Red + p->red = 0.1f + frand() * 0.2f; + p->green = 0.0f; + p->blue = frand() * 0.05f; + break; + + case 1: + // Green + p->red = 0; + p->green = 0.1f + frand() * 0.2f; + p->blue = frand() * 0.05f; + break; + + case 2: + default: + // Blue + p->red = 0; + p->green = frand() * 0.05f; + p->blue = 0.1f + frand() * 0.2f; + break; + + case 3: + // Orange + p->red = 0.1f + frand() * 0.1f; + p->green = 0.05f + frand() * 0.1f; + p->blue = 0.0f; + break; + + case 4: + // Purple + p->red = 0.1f + frand() * 0.2f; + p->green = 0.0f; + p->blue = 0.1f + frand() * 0.2f; + break; + + case 5: + // White + p->red = p->green = p->blue = 0.1f + frand() * 0.2f; + + case 6: + // Rainbow + p->red = 0.1f + frand() * 0.2f; + p->green = 0.1f + frand() * 0.2f; + p->blue = 0.1f + frand() * 0.2f; + break; + } +} diff --git a/src/add-ons/screen_savers/gravity/Particle.h b/src/add-ons/screen_savers/gravity/Particle.h index 1d7be18..69ff6d3 100644 --- a/src/add-ons/screen_savers/gravity/Particle.h +++ b/src/add-ons/screen_savers/gravity/Particle.h @@ -1,44 +1,55 @@ /* * Copyright 2012-2013 Tri-Edge AI <triedgeai@xxxxxxxxx> - * All rights reserved. Distributed under the terms of the MIT license. + * Copyright 2014 Haiku, Inc. All rights reserved. + * + * Distributed under the terms of the MIT license. + * + * Authors: + * Tri-Edge AI + * John Scipione, jscipione@xxxxxxxxx */ #ifndef PARTICLE_H #define PARTICLE_H +#include <ObjectList.h> #include <GLView.h> -class BList; - -class Particle -{ +class Particle { public: - static BList* list; + static BObjectList<Particle>* list; - static void Initialize(int32 size, int32 shade); - static void Terminate(); - static void Tick(); + static void Initialize(int32 size, int32 shade); + static void AddParticles(int32 size, int32 shade); + static void RemoveParticles(int32 size, int32 shade); + static void ColorParticles(int32 size, int32 shade); + static void Terminate(); + static void Tick(); - float x; - float y; - float z; - float r; + float x; + float y; + float z; + float r; - float vx; - float vy; - float vz; - float vr; + float vx; + float vy; + float vz; + float vr; - float red; - float green; - float blue; + float red; + float green; + float blue; private: - void _Logic(); - void _Render() const; + void _Logic(); + void _Render() const; + static void _FillParticle(Particle* p, int32 size, + int32 shade); + static void _ColorParticle(Particle* p, int32 size, + int32 shade); }; -#endif +#endif // PARTICLE_H