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