2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 __USE_CORTEX_NAMESPACE
45 // -------------------------------------------------------- //
47 // -------------------------------------------------------- //
49 const float TipView::s_xPad
= 5.0;
50 const float TipView::s_yPad
= 2.0;
52 // -------------------------------------------------------- //
54 // -------------------------------------------------------- //
56 TipView::~TipView() {}
62 B_WILL_DRAW
|B_FRAME_EVENTS
),
63 m_font(be_plain_font
) {
69 // -------------------------------------------------------- //
71 // -------------------------------------------------------- //
73 void TipView::setText(
79 // -------------------------------------------------------- //
81 // -------------------------------------------------------- //
83 // Adapted from c.lenz' ToolTipView::Draw()
89 // Draw border and fill
90 SetDrawingMode(B_OP_ALPHA
);
91 SetHighColor(m_borderLoColor
);
92 StrokeLine(r
.LeftBottom(), r
.RightBottom());
93 StrokeLine(r
.RightTop(), r
.RightBottom());
94 SetHighColor(m_borderHiColor
);
95 StrokeLine(r
.LeftTop(), r
.RightTop());
96 StrokeLine(r
.LeftTop(), r
.LeftBottom());
97 SetHighColor(m_viewColor
);
98 SetDrawingMode(B_OP_ALPHA
);
103 SetDrawingMode(B_OP_OVER
);
104 SetHighColor(m_textColor
);
107 for(uint32 n
= 0; n
< m_lineSet
.size(); ++n
) {
109 uint32 from
= m_lineSet
[n
];
110 uint32 to
= (n
< m_lineSet
.size()-1) ? m_lineSet
[n
+1]-1 :
115 m_text
.String() + from
,
119 p
.y
+= (m_fontHeight
.ascent
+ m_fontHeight
.descent
+ m_fontHeight
.leading
);
123 void TipView::FrameResized(
127 _inherited::FrameResized(width
, height
);
128 _updateLayout(width
, height
);
132 void TipView::GetPreferredSize(
136 // *outWidth = ceil(m_font.StringWidth(m_text.String()) + s_xPad*2);
137 *outWidth
= ceil(_maxTextWidth() + s_xPad
*2);
138 *outHeight
= ceil(_textHeight() + s_yPad
*2);
141 // -------------------------------------------------------- //
143 // -------------------------------------------------------- //
158 outColor
->green
= green
;
159 outColor
->blue
= blue
;
160 outColor
->alpha
= alpha
;
163 void TipView::_initColors() {
165 SetViewColor(B_TRANSPARENT_COLOR
);
167 _make_color(&m_textColor
, 0, 0, 0, 255);
168 _make_color(&m_borderHiColor
, 0, 0, 0, 255 /*196*/);
169 _make_color(&m_borderLoColor
, 0, 0, 0, 255 /*196*/);
170 _make_color(&m_viewColor
, 255, 255, 240, 255 /*216*/);
173 void TipView::_initFont() {
176 m_font
.GetHeight(&m_fontHeight
);
179 void TipView::_updateLayout(
184 m_offset
.x
= (width
- _maxTextWidth()) / 2;
186 m_offset
.y
= (height
- _textHeight()) / 2;
187 m_offset
.y
+= m_fontHeight
.ascent
;
190 void TipView::_setText(
198 // skip leading newlines
200 while(n
< m_text
.Length() && m_text
[n
] == '\n')
204 m_lineSet
.push_back(n
);
206 // break following lines
207 while(n
< m_text
.Length()) {
208 int32 nextBreak
= m_text
.FindFirst('\n', n
);
209 // no more line breaks?
213 m_lineSet
.push_back(n
);
217 float TipView::_maxTextWidth() {
219 for(uint32 n
= 0; n
< m_lineSet
.size(); ++n
) {
220 uint32 from
= m_lineSet
[n
];
221 uint32 to
= (n
< m_lineSet
.size()-1) ? m_lineSet
[n
+1]-1 :
223 float lineWidth
= m_font
.StringWidth(
224 m_text
.String() + from
,
232 float TipView::_textHeight() {
233 float height
= m_fontHeight
.ascent
+ m_fontHeight
.descent
;
234 if(m_lineSet
.size() > 1)
235 height
+= (m_lineSet
.size()-1) *
236 (m_fontHeight
.ascent
+ m_fontHeight
.descent
+ m_fontHeight
.leading
);
241 // END -- TipView.cpp --