1 /*
2 * Copyright 2007-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Ryan Leavengood, leavengood@gmail.com
7 */
8
9
10 #include "DebugNow.h"
11
12 #include <Catalog.h>
13 #include <DefaultSettingsView.h>
14 #include <Font.h>
15 #include <StringView.h>
16 #include <View.h>
17
18
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "Screensaver DebugNow"
21
22
23 static const rgb_color kMediumBlue = { 0, 0, 100 };
24 static const rgb_color kWhite = { 255, 255, 255 };
25
26
27 // #pragma mark - Instantiation function
28
29
instantiate_screen_saver(BMessage * message,image_id image)30 BScreenSaver* instantiate_screen_saver(BMessage* message, image_id image)
31 {
32 return new DebugNow(message, image);
33 }
34
35
36 // #pragma mark - DebugNow
37
38
DebugNow(BMessage * archive,image_id id)39 DebugNow::DebugNow(BMessage* archive, image_id id)
40 :
41 BScreenSaver(archive, id),
42 fLine1(B_TRANSLATE_COMMENT("DEBUG",
43 "keep it short and all uppercase, 5 characters or less")),
44 fLine2(B_TRANSLATE_COMMENT("NOW",
45 "keep it short and all uppercase, 5 characters or less"))
46 {
47 }
48
49
50 void
StartConfig(BView * view)51 DebugNow::StartConfig(BView* view)
52 {
53 BPrivate::BuildDefaultSettingsView(view, "DEBUG NOW",
54 B_TRANSLATE("by Ryan Leavengood"));
55 }
56
57
58 status_t
StartSaver(BView * view,bool preview)59 DebugNow::StartSaver(BView* view, bool preview)
60 {
61 float viewWidth = view->Bounds().Width();
62 float viewHeight = view->Bounds().Height();
63
64 BFont font;
65 view->GetFont(&font);
66 font.SetSize(viewHeight / 3);
67 view->SetFont(&font);
68
69 fDelta.nonspace = 0;
70 fDelta.space = 0;
71 BRect stringRect;
72 font.GetBoundingBoxesForStrings(&fLine1, 1, B_SCREEN_METRIC, &fDelta,
73 &stringRect);
74 float y = ((viewHeight - (stringRect.Height() * 2 + viewHeight / 10)) / 2)
75 + stringRect.Height();
76 fLine1Start.Set(((viewWidth - stringRect.Width()) / 2) - stringRect.left, y);
77 font.GetBoundingBoxesForStrings(&fLine2, 1, B_SCREEN_METRIC, &fDelta,
78 &stringRect);
79 fLine2Start.Set(((viewWidth - stringRect.Width()) / 2) - stringRect.left,
80 y + stringRect.Height() + viewHeight / 10);
81
82 // set tick size to 500,000 microseconds (0.5 seconds)
83 SetTickSize(500000);
84
85 return B_OK;
86 }
87
88
89 void
Draw(BView * view,int32 frame)90 DebugNow::Draw(BView* view, int32 frame)
91 {
92 // on first frame set the low color to make the text rendering correct
93 if (frame == 0)
94 view->SetLowColor(kMediumBlue);
95
96 // draw the background color every frame
97 view->SetHighColor(kMediumBlue);
98 view->FillRect(view->Bounds());
99
100 // draw the text every other frame to make the it blink
101 if (frame % 2 == 1) {
102 view->SetHighColor(kWhite);
103 view->DrawString(fLine1, fLine1Start, &fDelta);
104 view->DrawString(fLine2, fLine2Start, &fDelta);
105 }
106 }
107