diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/llvelocitybar.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/linden/indra/newview/llvelocitybar.cpp b/linden/indra/newview/llvelocitybar.cpp new file mode 100644 index 0000000..d285733 --- /dev/null +++ b/linden/indra/newview/llvelocitybar.cpp | |||
@@ -0,0 +1,159 @@ | |||
1 | /** | ||
2 | * @file llvelocitybar.cpp | ||
3 | * @brief A user interface widget that displays user energy level | ||
4 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "llui.h" | ||
31 | #include "llgl.h" | ||
32 | #include "llfontgl.h" | ||
33 | |||
34 | #include "llagent.h" | ||
35 | |||
36 | #include "llvelocitybar.h" | ||
37 | |||
38 | EWidgetType LLVelocityBar::getWidgetType() const | ||
39 | { | ||
40 | return WIDGET_TYPE_VELOCITY_BAR; | ||
41 | } | ||
42 | |||
43 | LLString LLVelocityBar::getWidgetTag() const | ||
44 | { | ||
45 | return LL_VELOCITY_BAR_TAG; | ||
46 | } | ||
47 | |||
48 | const char tab = '\t'; | ||
49 | |||
50 | void LLVelocityBar::draw() | ||
51 | { | ||
52 | const S32 BAR_TOP = 24; | ||
53 | const S32 BAR_BOTTOM = 20; | ||
54 | const S32 TICK_BOTTOM = 15; | ||
55 | const S32 TICK_WIDTH = 2; | ||
56 | const S32 MAGIC_CHAR_WIDTH = 6; | ||
57 | |||
58 | S32 left, top, right, bottom; | ||
59 | |||
60 | if (!getVisible()) | ||
61 | { | ||
62 | return; | ||
63 | } | ||
64 | |||
65 | // const F32 MS_TO_SECONDS = 0.001f; | ||
66 | // const S32 WIDTH_IN_MS = 66; | ||
67 | // const F32 WIDGET_TIME_FOR_WIDTH = WIDTH_IN_MS * MS_TO_SECONDS; | ||
68 | |||
69 | F32 velocity = gAgent.getVelocity().magVec(); | ||
70 | |||
71 | LLColor4 bar_color(0.0f, 1.0f, 0.0f, 1.f); | ||
72 | |||
73 | // | ||
74 | // Set bar color | ||
75 | // | ||
76 | |||
77 | LLGLSNoTexture gls_no_texture; | ||
78 | |||
79 | // draw background box | ||
80 | // glColor4f(0.f, 0.f, 0.f, 0.3f); | ||
81 | // gl_rect_2d(0, mRect.getHeight(), mRect.getWidth(), 0); | ||
82 | |||
83 | // draw white lines for special times | ||
84 | // (60 hz = 16 ms, 30 hz = 33 ms, 15 hz = 66 ms) | ||
85 | LLColor4 color(1.f, 1.f, 1.f, 1.f); | ||
86 | |||
87 | top = BAR_BOTTOM - 1; | ||
88 | bottom = TICK_BOTTOM; | ||
89 | |||
90 | left = 0; | ||
91 | right = left + TICK_WIDTH; | ||
92 | gl_rect_2d(left, top, right, bottom, color); | ||
93 | |||
94 | left = (S32) (mRect.getWidth() * 1 / 6); | ||
95 | right = left + TICK_WIDTH; | ||
96 | gl_rect_2d(left, top, right, bottom, color); | ||
97 | |||
98 | left = (S32) (mRect.getWidth() * 2 / 6); | ||
99 | right = left + TICK_WIDTH; | ||
100 | gl_rect_2d(left, top, right, bottom, color); | ||
101 | |||
102 | left = (S32) (mRect.getWidth() * 3 / 6); | ||
103 | right = left + TICK_WIDTH; | ||
104 | gl_rect_2d(left, top, right, bottom, color); | ||
105 | |||
106 | left = (S32) (mRect.getWidth() * 4 / 6); | ||
107 | right = left + TICK_WIDTH; | ||
108 | gl_rect_2d(left, top, right, bottom, color); | ||
109 | |||
110 | left = (S32) (mRect.getWidth() * 5 / 6); | ||
111 | right = left + TICK_WIDTH; | ||
112 | gl_rect_2d(left, top, right, bottom, color); | ||
113 | |||
114 | left = (S32) (mRect.getWidth() * 6 / 6); | ||
115 | right = left + TICK_WIDTH; | ||
116 | gl_rect_2d(left, top, right, bottom, color); | ||
117 | |||
118 | |||
119 | // draw labels for the bar | ||
120 | LLGLSTexture gls_texture; | ||
121 | |||
122 | top = BAR_TOP + 15; | ||
123 | left = 0; | ||
124 | char str[80]; | ||
125 | sprintf(str, "Velocity %.3fm/s", velocity); | ||
126 | LLFontGL::sMonospace->renderUTF8(str, 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); | ||
127 | |||
128 | top = TICK_BOTTOM; | ||
129 | |||
130 | left = - MAGIC_CHAR_WIDTH/2; | ||
131 | LLFontGL::sMonospace->renderUTF8("0", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); | ||
132 | |||
133 | left = (mRect.getWidth()*1 / 6) - MAGIC_CHAR_WIDTH * 2; | ||
134 | LLFontGL::sMonospace->renderUTF8("1", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); | ||
135 | |||
136 | left = (mRect.getWidth()*2 / 6) - MAGIC_CHAR_WIDTH; | ||
137 | LLFontGL::sMonospace->renderUTF8("2", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); | ||
138 | |||
139 | left = (mRect.getWidth()*3 / 6) - MAGIC_CHAR_WIDTH * 2; | ||
140 | LLFontGL::sMonospace->renderUTF8("3", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); | ||
141 | |||
142 | left = (mRect.getWidth()*4 / 6) - MAGIC_CHAR_WIDTH; | ||
143 | LLFontGL::sMonospace->renderUTF8("4", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); | ||
144 | |||
145 | left = (mRect.getWidth()*5 / 6) - MAGIC_CHAR_WIDTH * 2; | ||
146 | LLFontGL::sMonospace->renderUTF8("5", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); | ||
147 | |||
148 | left = (mRect.getWidth()*6 / 6) - MAGIC_CHAR_WIDTH * 3; | ||
149 | LLFontGL::sMonospace->renderUTF8("6 m/s", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); | ||
150 | |||
151 | // draw idle time | ||
152 | top = BAR_TOP; | ||
153 | bottom = BAR_BOTTOM; | ||
154 | |||
155 | // Draw energy level | ||
156 | left = 0; | ||
157 | right = (S32) (left + velocity * 0.33333f * mRect.getWidth() / 2.f); | ||
158 | gl_rect_2d(left, top, right, bottom, bar_color); | ||
159 | } | ||