llvelocitybar.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llui.h"
00035 #include "llgl.h"
00036 #include "llfontgl.h"
00037 
00038 #include "llagent.h"
00039 
00040 #include "llvelocitybar.h"
00041 
00042 const char tab = '\t';
00043 
00044 void LLVelocityBar::draw()
00045 {
00046         const S32 BAR_TOP = 24;
00047         const S32 BAR_BOTTOM = 20;
00048         const S32 TICK_BOTTOM = 15;
00049         const S32 TICK_WIDTH = 2;
00050         const S32 MAGIC_CHAR_WIDTH = 6;
00051 
00052         S32 left, top, right, bottom;
00053 
00054 //      const F32 MS_TO_SECONDS = 0.001f;
00055 //      const S32 WIDTH_IN_MS = 66;
00056 //      const F32 WIDGET_TIME_FOR_WIDTH = WIDTH_IN_MS * MS_TO_SECONDS;
00057 
00058         F32 velocity = gAgent.getVelocity().magVec();
00059 
00060         LLColor4 bar_color(0.0f, 1.0f, 0.0f, 1.f);
00061 
00062         // 
00063         //  Set bar color 
00064         //
00065 
00066         LLGLSNoTexture gls_no_texture;
00067 
00068         // draw background box
00069         // gGL.color4f(0.f, 0.f, 0.f, 0.3f);
00070         // gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0);
00071 
00072         // draw white lines for special times 
00073         // (60 hz = 16 ms, 30 hz = 33 ms, 15 hz = 66 ms)
00074         LLColor4 color(1.f, 1.f, 1.f, 1.f);
00075 
00076         top = BAR_BOTTOM - 1;
00077         bottom = TICK_BOTTOM;
00078 
00079         left = 0;
00080         right = left + TICK_WIDTH;
00081         gl_rect_2d(left, top, right, bottom, color);
00082 
00083         left = (S32) (getRect().getWidth() * 1 / 6);
00084         right = left + TICK_WIDTH;
00085         gl_rect_2d(left, top, right, bottom, color);
00086 
00087         left = (S32) (getRect().getWidth() * 2 / 6);
00088         right = left + TICK_WIDTH;
00089         gl_rect_2d(left, top, right, bottom, color);
00090 
00091         left = (S32) (getRect().getWidth() * 3 / 6);
00092         right = left + TICK_WIDTH;
00093         gl_rect_2d(left, top, right, bottom, color);
00094 
00095         left = (S32) (getRect().getWidth() * 4 / 6);
00096         right = left + TICK_WIDTH;
00097         gl_rect_2d(left, top, right, bottom, color);
00098 
00099         left = (S32) (getRect().getWidth() * 5 / 6);
00100         right = left + TICK_WIDTH;
00101         gl_rect_2d(left, top, right, bottom, color);
00102 
00103         left = (S32) (getRect().getWidth() * 6 / 6);
00104         right = left + TICK_WIDTH;
00105         gl_rect_2d(left, top, right, bottom, color);
00106 
00107 
00108         // draw labels for the bar
00109 
00110         top = BAR_TOP + 15;
00111         left = 0;
00112         char str[80];           /* Flawfinder: ignore */
00113         snprintf(str, sizeof(str), "Velocity %.3fm/s", velocity);               /* Flawfinder: ignore */
00114         LLFontGL::sMonospace->renderUTF8(str, 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00115 
00116         top = TICK_BOTTOM;
00117 
00118         left = - MAGIC_CHAR_WIDTH/2;
00119         LLFontGL::sMonospace->renderUTF8("0", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00120 
00121         left = (getRect().getWidth()*1 / 6) - MAGIC_CHAR_WIDTH * 2;
00122         LLFontGL::sMonospace->renderUTF8("1", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00123 
00124         left = (getRect().getWidth()*2 / 6) - MAGIC_CHAR_WIDTH;
00125         LLFontGL::sMonospace->renderUTF8("2", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00126 
00127         left = (getRect().getWidth()*3 / 6) - MAGIC_CHAR_WIDTH * 2;
00128         LLFontGL::sMonospace->renderUTF8("3", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00129 
00130         left = (getRect().getWidth()*4 / 6) - MAGIC_CHAR_WIDTH;
00131         LLFontGL::sMonospace->renderUTF8("4", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00132 
00133         left = (getRect().getWidth()*5 / 6) - MAGIC_CHAR_WIDTH * 2;
00134         LLFontGL::sMonospace->renderUTF8("5", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00135 
00136         left = (getRect().getWidth()*6 / 6) - MAGIC_CHAR_WIDTH * 3;
00137         LLFontGL::sMonospace->renderUTF8("6 m/s", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00138 
00139         // draw idle time
00140         top = BAR_TOP;
00141         bottom = BAR_BOTTOM;
00142 
00143         //  Draw energy level
00144         left = 0;
00145         right = (S32) (left + velocity * 0.33333f * getRect().getWidth() / 2.f);
00146         gl_rect_2d(left, top, right, bottom, bar_color);
00147 }

Generated on Fri May 16 08:34:08 2008 for SecondLife by  doxygen 1.5.5