From 3704c0f8b1bad6ab6cbc6b21d2e33c8bb0dda38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Mon, 5 Nov 2012 23:13:56 +0100 Subject: [PATCH] Add a totally useless Shelf screensaver * Allows dropping replicants, and showing them later on when idle. * Needs some cleanup. --- src/add-ons/screen_savers/Jamfile | 1 + src/add-ons/screen_savers/shelf/Jamfile | 6 + src/add-ons/screen_savers/shelf/Shelf.cpp | 263 ++++++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 src/add-ons/screen_savers/shelf/Jamfile create mode 100644 src/add-ons/screen_savers/shelf/Shelf.cpp diff --git a/src/add-ons/screen_savers/Jamfile b/src/add-ons/screen_savers/Jamfile index 8246ed0170..1116db75f6 100644 --- a/src/add-ons/screen_savers/Jamfile +++ b/src/add-ons/screen_savers/Jamfile @@ -9,6 +9,7 @@ SubInclude HAIKU_TOP src add-ons screen_savers icons ; SubInclude HAIKU_TOP src add-ons screen_savers ifs ; SubInclude HAIKU_TOP src add-ons screen_savers leaves ; SubInclude HAIKU_TOP src add-ons screen_savers message ; +SubInclude HAIKU_TOP src add-ons screen_savers shelf ; SubInclude HAIKU_TOP src add-ons screen_savers simpleclock ; SubInclude HAIKU_TOP src add-ons screen_savers slideshowsaver ; SubInclude HAIKU_TOP src add-ons screen_savers spider ; diff --git a/src/add-ons/screen_savers/shelf/Jamfile b/src/add-ons/screen_savers/shelf/Jamfile new file mode 100644 index 0000000000..09702e4466 --- /dev/null +++ b/src/add-ons/screen_savers/shelf/Jamfile @@ -0,0 +1,6 @@ +SubDir HAIKU_TOP src add-ons screen_savers shelf ; + +ScreenSaver Shelf : + Shelf.cpp : + be libscreensaver.so ; + diff --git a/src/add-ons/screen_savers/shelf/Shelf.cpp b/src/add-ons/screen_savers/shelf/Shelf.cpp new file mode 100644 index 0000000000..e304c515c7 --- /dev/null +++ b/src/add-ons/screen_savers/shelf/Shelf.cpp @@ -0,0 +1,263 @@ +/* + * Copyright 2007-2012, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ryan Leavengood + * François Revol + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +const rgb_color kMediumBlue = {0, 0, 100}; +const rgb_color kWhite = {255, 255, 255}; + +const char *kInConfigName = "InConfig"; +const char *kShelfArchiveName = "Shelf"; + + +// Inspired by the classic BeOS screensaver, of course +class Shelf : public BScreenSaver +{ + public: + Shelf(BMessage *archive, image_id); + void Draw(BView *view, int32 frame); + void StartConfig(BView *view); + void StopConfig(); + status_t StartSaver(BView *view, bool preview); + void StopSaver(); + status_t SaveState(BMessage *state) const; + + private: + BShelf *fShelf; + BWindow *fConfigWindow; + bool fInConfig; + bool fInEdit; + BMallocIO fShelfData; +}; + + +BScreenSaver *instantiate_screen_saver(BMessage *msg, image_id image) +{ + PRINT(("%s()\n", __FUNCTION__)); + return new Shelf(msg, image); +} + + +Shelf::Shelf(BMessage *archive, image_id id) + : BScreenSaver(archive, id) + , fShelf(NULL) + , fConfigWindow(NULL) + , fInConfig(false) + , fInEdit(false) + , fShelfData() +{ + archive->PrintToStream(); + if (archive->FindBool(kInConfigName, &fInConfig) < B_OK) + fInConfig = false; + + status_t status; + const void *data; + ssize_t length; + + status = archive->FindData(kShelfArchiveName, 'shlf', &data, &length); + if (status == B_OK) { + fShelfData.WriteAt(0LL, data, length); + fShelfData.Seek(SEEK_SET, 0LL); + } + + +/* + if (fInConfig) { + fInEdit = true; + fInConfig = false; + } +*/} + + +void +Shelf::StartConfig(BView *view) +{ + PRINT(("%p:%s()\n", this, __FUNCTION__)); + fInConfig = true; + view->AddChild(new BStringView(BRect(20, 10, 200, 35), "", + "Shelf, by François Revol.")); + + BScreen screen; + fConfigWindow = new BWindow(screen.Frame(), "Shelf Config", + B_UNTYPED_WINDOW, B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE + | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_AVOID_FRONT | B_AVOID_FOCUS); + + BView *shelfView = new BView(fConfigWindow->Bounds(), "ShelfView", + B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS); + shelfView->SetViewColor(216, 216, 216, 0); + + fConfigWindow->AddChild(shelfView); + + fShelfData.Seek(SEEK_SET, 0LL); + fShelf = new BShelf(&fShelfData, shelfView); + fShelf->SetDisplaysZombies(true); + fShelfData.Seek(SEEK_SET, 0LL); + + // start the Looper + fConfigWindow->Show(); + + fConfigWindow->Lock(); + fConfigWindow->SendBehind(view->Window()); + fConfigWindow->Unlock(); + + //"\nDrop replicants on me!" +} + + +void +Shelf::StopConfig() +{ + fInConfig = false; + PRINT(("%p:%s()\n", this, __FUNCTION__)); + fConfigWindow->Lock(); + fConfigWindow->Quit(); + fShelf = NULL; + + BScreenSaver::StopConfig(); +} + + +status_t +Shelf::StartSaver(BView *view, bool preview) +{ + PRINT(("%p:%s(, %d)\n", this, __FUNCTION__, preview)); + if (!preview) { + view->SetViewColor(216, 216, 216, 0); + fShelfData.Seek(SEEK_SET, 0LL); + fShelf = new BShelf(&fShelfData, view); + + } + BString s; + s << "preview: " << preview << " "; + s << "BView:Name: " << view->Name() << " "; + s << "BApp:Name: " << be_app->Name(); + + PRINT(("%p:%s:%s\n", this, __FUNCTION__, s.String())); + //BAlert *a = new BAlert("debug", s.String(), "Ok"); + //a->Go(); + return B_ERROR; +#if 0 + float width = view->Bounds().Width(); + float height = view->Bounds().Height(); + + BFont font; + view->GetFont(&font); + font.SetSize(height / 2.5); + view->SetFont(&font); + + BRect rect; + escapement_delta delta; + delta.nonspace = 0; + delta.space = 0; + // If anyone has suggestions for how to clean this up, speak up + font.GetBoundingBoxesForStrings(&fLine1, 1, B_SCREEN_METRIC, &delta, &rect); + float y = ((height - (rect.Height() * 2 + height / 10)) / 2) + rect.Height(); + fLine1Start.Set((width - rect.Width()) / 2, y); + font.GetBoundingBoxesForStrings(&fLine2, 1, B_SCREEN_METRIC, &delta, &rect); + fLine2Start.Set((width - rect.Width()) / 2, y + rect.Height() + height / 10); + +#endif + return B_OK; +} + + +void +Shelf::StopSaver() +{ + PRINT(("%p:%s()\n", this, __FUNCTION__)); + //if (fShelf) + //delete fShelf; + //fShelf = NULL; +} + + +status_t +Shelf::SaveState(BMessage *state) const +{ + status_t status; + + PRINT(("%p:%s()\n", this, __FUNCTION__)); + state->PrintToStream(); + + if (fInConfig) + state->AddBool(kInConfigName, fInConfig); + if (!fInConfig) + state->RemoveData(kInConfigName); + if (fInConfig && fShelf) { + status = state->AddBool("got it", true); + + fShelf->LockLooper(); + status = fShelf->Save(); + fShelf->UnlockLooper(); + if (status < B_OK) + return status; + status = state->AddData(kShelfArchiveName, 'shlf', fShelfData.Buffer(), + fShelfData.BufferLength()); + +// return B_OK; +//fShelfData.SetSize(0LL); +#if 0 + BMallocIO mio; + status = fShelf->SetSaveLocation(&mio); + if (status < B_OK) + return status; + status = fShelf->Save(); + fShelf->SetSaveLocation((BDataIO *)NULL); + if (status < B_OK) + return status; + status = state->AddData(kShelfArchiveName, 'shlf', mio.Buffer(), + mio.BufferLength()); +#endif + if (status < B_OK) + return status; + } + return B_OK; +} + + +void +Shelf::Draw(BView *view, int32 frame) +{ + PRINT(("%p:%s(, %d)\n", this, __FUNCTION__, frame)); + BScreenSaver::Draw(view, frame); +#if 0 + if (frame == 0) { + // fill with blue on first frame + view->SetLowColor(kMediumBlue); + view->FillRect(view->Bounds(), B_SOLID_LOW); + + // Set tick size to 500,000 microseconds = 0.5 second + SetTickSize(500000); + } else { + // Drawing the background color every other frame to make the text blink + if (frame % 2 == 1) + view->SetHighColor(kWhite); + else + view->SetHighColor(kMediumBlue); + + view->DrawString(fLine1, fLine1Start); + view->DrawString(fLine2, fLine2Start); + } +#endif +} + +