1 /* 2 * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 * Mike Berg <mike@berg-net.us> 8 * Julun <host.haiku@gmx.de> 9 * 10 */ 11 12 #include <stdio.h> 13 14 #include "TZDisplay.h" 15 16 17 namespace { 18 float _FontHeight() 19 { 20 font_height fontHeight; 21 be_plain_font->GetHeight(&fontHeight); 22 float height = ceil(fontHeight.descent + fontHeight.ascent 23 + fontHeight.leading); 24 return height; 25 } 26 } 27 28 29 TTZDisplay::TTZDisplay(BRect frame, const char* name, const char* label) 30 : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW), 31 fLabel(label), 32 fText(""), 33 fTime("") 34 { 35 } 36 37 38 TTZDisplay::~TTZDisplay() 39 { 40 } 41 42 43 void 44 TTZDisplay::AttachedToWindow() 45 { 46 if (Parent()) 47 SetViewColor(Parent()->ViewColor()); 48 } 49 50 51 void 52 TTZDisplay::ResizeToPreferred() 53 { 54 ResizeTo(Bounds().Width(), _FontHeight() * 2.0 + 4.0); 55 } 56 57 58 void 59 TTZDisplay::Draw(BRect /* updateRect */) 60 { 61 SetLowColor(ViewColor()); 62 63 BRect bounds = Bounds(); 64 FillRect(Bounds(), B_SOLID_LOW); 65 66 float fontHeight = _FontHeight(); 67 68 BPoint pt(bounds.left + 2.0, fontHeight / 2.0 + 2.0); 69 DrawString(fLabel.String(), pt); 70 71 pt.y += fontHeight; 72 DrawString(fText.String(), pt); 73 74 pt.y -= fontHeight; 75 pt.x = bounds.right - StringWidth(fTime.String()) - 2.0; 76 DrawString(fTime.String(), pt); 77 } 78 79 80 const char* 81 TTZDisplay::Label() const 82 { 83 return fLabel.String(); 84 } 85 86 87 void 88 TTZDisplay::SetLabel(const char* label) 89 { 90 fLabel.SetTo(label); 91 Invalidate(); 92 } 93 94 95 const char* 96 TTZDisplay::Text() const 97 { 98 return fText.String(); 99 } 100 101 102 void 103 TTZDisplay::SetText(const char* text) 104 { 105 fText.SetTo(text); 106 Invalidate(); 107 } 108 109 110 const char* 111 TTZDisplay::Time() const 112 { 113 return fTime.String(); 114 } 115 116 117 void 118 TTZDisplay::SetTime(const char* time) 119 { 120 fTime.SetTo(time); 121 Invalidate(); 122 } 123 124