Appropriately based on the name, DebugNow was full of bugs:

- The text was not centered because it was not taking into account the left
  offset of the text rendering, which can be gotten from the left value of the
  rect returned by GetBoundingBoxesForStrings. I'm pretty sure this was 0 on
  BeOS, so there might be problems with our GetBoundingBoxesForStrings. It
  doesn't make sense for flat edged glyphs like D and N to be offset. But
  nonetheless taking into account that left offset centers the text in this
  screensaver. This fixes #4261.
- The text rendering also could look weird because the low color was not set to
  blue. Again I'm pretty sure this was not a problem on BeOS, but could be
  related to the new subpixel AA rendering. Setting the low color fixes this
  and therefore fixes #4252.
- To avoid any weird repaint issues in the ScreenSaver preferences preview
  view, the whole background is painted every frame now.
- I also added an escapement_delta member which is used for both the
  GetBoundingBoxesForStrings call and the eventual text rendering. This may be
  pointless, but it is probably more consistent.

Other changes:
- This now makes use of the new settings view private function.
- I made the coding style compliant with our latest guidelines (I think I got
  most of the big ones at least.)
- Removed the references to the old BeOS screen saver kit stuff from the
  Jamfile.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33404 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ryan Leavengood 2009-10-01 21:03:44 +00:00
parent 1c5a1e55c1
commit 5d4dc64e6f
2 changed files with 56 additions and 52 deletions

View File

@ -3,80 +3,89 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Ryan Leavengood * Ryan Leavengood, leavengood@gmail.com
*/ */
#include <ScreenSaver.h>
#include <View.h>
#include <StringView.h>
#include <Font.h> #include <Font.h>
#include <ScreenSaver.h>
#include <StringView.h>
#include <View.h>
#include <BuildScreenSaverDefaultSettingsView.h>
const rgb_color kMediumBlue = {0, 0, 100}; const rgb_color kMediumBlue = {0, 0, 100};
const rgb_color kWhite = {255, 255, 255}; const rgb_color kWhite = {255, 255, 255};
// Inspired by the classic BeOS screensaver, of course // Inspired by the classic BeOS BuyNow screensaver, of course
class DebugNow : public BScreenSaver class DebugNow : public BScreenSaver
{ {
public: public:
DebugNow(BMessage *archive, image_id); DebugNow(BMessage *archive, image_id);
void Draw(BView *view, int32 frame); void Draw(BView *view, int32 frame);
void StartConfig(BView *view); void StartConfig(BView *view);
status_t StartSaver(BView *view, bool preview); status_t StartSaver(BView *view, bool preview);
private: private:
const char *fLine1; const char* fLine1;
const char *fLine2; const char* fLine2;
BPoint fLine1Start; BPoint fLine1Start;
BPoint fLine2Start; BPoint fLine2Start;
escapement_delta fDelta;
}; };
BScreenSaver *instantiate_screen_saver(BMessage *msg, image_id image) BScreenSaver* instantiate_screen_saver(BMessage *msg, image_id image)
{ {
return new DebugNow(msg, image); return new DebugNow(msg, image);
} }
DebugNow::DebugNow(BMessage *archive, image_id id) DebugNow::DebugNow(BMessage *archive, image_id id)
: BScreenSaver(archive, id) :
, fLine1("DEBUG") BScreenSaver(archive, id),
, fLine2("NOW") fLine1("DEBUG"),
fLine2("NOW")
{ {
} }
void void
DebugNow::StartConfig(BView *view) DebugNow::StartConfig(BView *view)
{ {
view->AddChild(new BStringView(BRect(20, 10, 200, 35), "", "DEBUG NOW, " BPrivate::BuildScreenSaverDefaultSettingsView(view, "DEBUG NOW",
"by Ryan Leavengood")); "by Ryan Leavengood");
} }
status_t status_t
DebugNow::StartSaver(BView *view, bool preview) DebugNow::StartSaver(BView *view, bool preview)
{ {
float width = view->Bounds().Width(); float viewWidth = view->Bounds().Width();
float height = view->Bounds().Height(); float viewHeight = view->Bounds().Height();
BFont font; BFont font;
view->GetFont(&font); view->GetFont(&font);
font.SetSize(height / 2.5); font.SetSize(viewHeight / 2.5);
view->SetFont(&font); view->SetFont(&font);
BRect rect; fDelta.nonspace = 0;
escapement_delta delta; fDelta.space = 0;
delta.nonspace = 0; BRect stringRect;
delta.space = 0; font.GetBoundingBoxesForStrings(&fLine1, 1, B_SCREEN_METRIC, &fDelta,
// If anyone has suggestions for how to clean this up, speak up &stringRect);
font.GetBoundingBoxesForStrings(&fLine1, 1, B_SCREEN_METRIC, &delta, &rect); float y = ((viewHeight - (stringRect.Height() * 2 + viewHeight / 10)) / 2)
float y = ((height - (rect.Height() * 2 + height / 10)) / 2) + rect.Height(); + stringRect.Height();
fLine1Start.Set((width - rect.Width()) / 2, y); fLine1Start.Set(((viewWidth - stringRect.Width()) / 2) - stringRect.left, y);
font.GetBoundingBoxesForStrings(&fLine2, 1, B_SCREEN_METRIC, &delta, &rect); font.GetBoundingBoxesForStrings(&fLine2, 1, B_SCREEN_METRIC, &fDelta,
fLine2Start.Set((width - rect.Width()) / 2, y + rect.Height() + height / 10); &stringRect);
fLine2Start.Set(((viewWidth - stringRect.Width()) / 2) - stringRect.left,
y + stringRect.Height() + viewHeight / 10);
// Set tick size to 500,000 microseconds = 0.5 second
SetTickSize(500000);
return B_OK; return B_OK;
} }
@ -85,22 +94,19 @@ DebugNow::StartSaver(BView *view, bool preview)
void void
DebugNow::Draw(BView *view, int32 frame) DebugNow::Draw(BView *view, int32 frame)
{ {
if (frame == 0) { // On first frame set the low color to make the text rendering correct
// fill with blue on first frame if (frame == 0)
view->SetLowColor(kMediumBlue); view->SetLowColor(kMediumBlue);
view->FillRect(view->Bounds(), B_SOLID_LOW);
// Set tick size to 500,000 microseconds = 0.5 second // Draw the background color every frame
SetTickSize(500000); view->SetHighColor(kMediumBlue);
} else { view->FillRect(view->Bounds());
// 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); // Draw the text every other frame to make the it blink
view->DrawString(fLine2, fLine2Start); if (frame % 2 == 1) {
view->SetHighColor(kWhite);
view->DrawString(fLine1, fLine1Start, &fDelta);
view->DrawString(fLine2, fLine2Start, &fDelta);
} }
} }

View File

@ -2,12 +2,10 @@ SubDir HAIKU_TOP src add-ons screen_savers debugnow ;
SetSubDirSupportedPlatformsBeOSCompatible ; SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders screen_saver ;
# For BuildScreenSaverDefaultSettingsView
ScreenSaver DebugNow : ScreenSaver DebugNow :
DebugNow.cpp : DebugNow.cpp :
be libscreensaver.so $(TARGET_LIBSUPC++) ; be libscreensaver.so $(TARGET_LIBSUPC++) ;
Package haiku-screensaverkit-cvs :
DebugNow :
boot home config add-ons Screen\ Savers
;