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 EWidgetType LLVelocityBar::getWidgetType() const
00043 {
00044         return WIDGET_TYPE_VELOCITY_BAR;
00045 }
00046 
00047 LLString LLVelocityBar::getWidgetTag() const
00048 {
00049         return LL_VELOCITY_BAR_TAG;
00050 }
00051 
00052 const char tab = '\t';
00053 
00054 void LLVelocityBar::draw()
00055 {
00056         const S32 BAR_TOP = 24;
00057         const S32 BAR_BOTTOM = 20;
00058         const S32 TICK_BOTTOM = 15;
00059         const S32 TICK_WIDTH = 2;
00060         const S32 MAGIC_CHAR_WIDTH = 6;
00061 
00062         S32 left, top, right, bottom;
00063 
00064         if (!getVisible())
00065         {
00066                 return;
00067         }
00068 
00069 //      const F32 MS_TO_SECONDS = 0.001f;
00070 //      const S32 WIDTH_IN_MS = 66;
00071 //      const F32 WIDGET_TIME_FOR_WIDTH = WIDTH_IN_MS * MS_TO_SECONDS;
00072 
00073         F32 velocity = gAgent.getVelocity().magVec();
00074 
00075         LLColor4 bar_color(0.0f, 1.0f, 0.0f, 1.f);
00076 
00077         // 
00078         //  Set bar color 
00079         //
00080 
00081         LLGLSNoTexture gls_no_texture;
00082 
00083         // draw background box
00084         // glColor4f(0.f, 0.f, 0.f, 0.3f);
00085         // gl_rect_2d(0, mRect.getHeight(), mRect.getWidth(), 0);
00086 
00087         // draw white lines for special times 
00088         // (60 hz = 16 ms, 30 hz = 33 ms, 15 hz = 66 ms)
00089         LLColor4 color(1.f, 1.f, 1.f, 1.f);
00090 
00091         top = BAR_BOTTOM - 1;
00092         bottom = TICK_BOTTOM;
00093 
00094         left = 0;
00095         right = left + TICK_WIDTH;
00096         gl_rect_2d(left, top, right, bottom, color);
00097 
00098         left = (S32) (mRect.getWidth() * 1 / 6);
00099         right = left + TICK_WIDTH;
00100         gl_rect_2d(left, top, right, bottom, color);
00101 
00102         left = (S32) (mRect.getWidth() * 2 / 6);
00103         right = left + TICK_WIDTH;
00104         gl_rect_2d(left, top, right, bottom, color);
00105 
00106         left = (S32) (mRect.getWidth() * 3 / 6);
00107         right = left + TICK_WIDTH;
00108         gl_rect_2d(left, top, right, bottom, color);
00109 
00110         left = (S32) (mRect.getWidth() * 4 / 6);
00111         right = left + TICK_WIDTH;
00112         gl_rect_2d(left, top, right, bottom, color);
00113 
00114         left = (S32) (mRect.getWidth() * 5 / 6);
00115         right = left + TICK_WIDTH;
00116         gl_rect_2d(left, top, right, bottom, color);
00117 
00118         left = (S32) (mRect.getWidth() * 6 / 6);
00119         right = left + TICK_WIDTH;
00120         gl_rect_2d(left, top, right, bottom, color);
00121 
00122 
00123         // draw labels for the bar
00124         LLGLSTexture gls_texture;
00125 
00126         top = BAR_TOP + 15;
00127         left = 0;
00128         char str[80];           /* Flawfinder: ignore */
00129         snprintf(str, sizeof(str), "Velocity %.3fm/s", velocity);               /* Flawfinder: ignore */
00130         LLFontGL::sMonospace->renderUTF8(str, 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00131 
00132         top = TICK_BOTTOM;
00133 
00134         left = - MAGIC_CHAR_WIDTH/2;
00135         LLFontGL::sMonospace->renderUTF8("0", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00136 
00137         left = (mRect.getWidth()*1 / 6) - MAGIC_CHAR_WIDTH * 2;
00138         LLFontGL::sMonospace->renderUTF8("1", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00139 
00140         left = (mRect.getWidth()*2 / 6) - MAGIC_CHAR_WIDTH;
00141         LLFontGL::sMonospace->renderUTF8("2", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00142 
00143         left = (mRect.getWidth()*3 / 6) - MAGIC_CHAR_WIDTH * 2;
00144         LLFontGL::sMonospace->renderUTF8("3", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00145 
00146         left = (mRect.getWidth()*4 / 6) - MAGIC_CHAR_WIDTH;
00147         LLFontGL::sMonospace->renderUTF8("4", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00148 
00149         left = (mRect.getWidth()*5 / 6) - MAGIC_CHAR_WIDTH * 2;
00150         LLFontGL::sMonospace->renderUTF8("5", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00151 
00152         left = (mRect.getWidth()*6 / 6) - MAGIC_CHAR_WIDTH * 3;
00153         LLFontGL::sMonospace->renderUTF8("6 m/s", 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP);
00154 
00155         // draw idle time
00156         top = BAR_TOP;
00157         bottom = BAR_BOTTOM;
00158 
00159         //  Draw energy level
00160         left = 0;
00161         right = (S32) (left + velocity * 0.33333f * mRect.getWidth() / 2.f);
00162         gl_rect_2d(left, top, right, bottom, bar_color);
00163 }

Generated on Thu Jul 1 06:09:25 2010 for Second Life Viewer by  doxygen 1.4.7