void ConsoleInfo::drawBackground() { /* * Draw console background to see the text */ Gui_DrawRect(0.0, m_cursorY + m_lineHeight - 8, screen_info.w, screen_info.h, m_backgroundColor, m_backgroundColor, m_backgroundColor, m_backgroundColor, loader::BlendingMode::Screen); /* * Draw finalise line */ GLfloat white[4] = { 1.0f, 1.0f, 1.0f, 0.7f }; Gui_DrawRect(0.0, m_cursorY + m_lineHeight - 8, screen_info.w, 2, white, white, white, white, loader::BlendingMode::Screen); }
void ConsoleInfo::drawCursor() { GLint y = m_cursorY; if(m_blinkPeriod) { m_blinkTime += engine_frame_time; if(m_blinkTime > m_blinkPeriod) { m_blinkTime = 0.0; m_showCursor = !m_showCursor; } } if(m_showCursor) { GLfloat white[4] = { 1.0f, 1.0f, 1.0f, 0.7f }; Gui_DrawRect(m_cursorX, y + m_lineHeight * 0.9f, 1, m_lineHeight * 0.8f, white, white, white, white, loader::BlendingMode::Screen); } }
void Gui_DrawLoadScreen(int value) { qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); qglPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); qglPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); qglPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); qglPixelStorei(GL_UNPACK_ALIGNMENT, 1); qglEnableClientState(GL_VERTEX_ARRAY); qglEnableClientState(GL_TEXTURE_COORD_ARRAY); qglEnableClientState(GL_COLOR_ARRAY); qglDisableClientState(GL_NORMAL_ARRAY); qglEnable(GL_BLEND); qglEnable(GL_TEXTURE_2D); qglDisable(GL_ALPHA_TEST); qglDepthMask(GL_FALSE); qglPolygonMode(GL_FRONT, GL_FILL); qglFrontFace(GL_CCW); const GLfloat color_w[4] = {1.0f, 1.0f, 1.0f, 1.0f}; const text_shader_description *shader = renderer.shaderManager->getTextShader(); screenSize[0] = screen_info.w; screenSize[1] = screen_info.h; qglUseProgramObjectARB(shader->program); qglUniform1iARB(shader->sampler, 0); qglUniform2fvARB(shader->screenSize, 1, screenSize); Gui_DrawRect(0.0, 0.0, screen_info.w, screen_info.h, color_w, color_w, color_w, color_w, BM_OPAQUE, load_screen_tex); if(value >= 0) { Bar[BAR_LOADING].Show(value); } qglDepthMask(GL_TRUE); qglPopClientAttrib(); qglPopAttrib(); Engine_GLSwapWindow(); }
// Main bar show procedure. // Draws a bar with a given value. Please note that it also accepts float, // so effectively you can create bars for floating-point parameters. void gui_ProgressBar::Show(float value) { // Initial value limiters (to prevent bar overflow). value = (value >= 0.0f) ? (value) : (0.0f); value = (value > mMaxValue) ? (mMaxValue):(value); // Enable blink mode, if value is gone below warning value. mBlink = (value <= mWarnValue); if(mAutoShow) // Check autoshow visibility conditions. { // 0. If bar drawing was forced, then show a bar without additional // autoshow delay set. This condition has to be overwritten by // any other conditions, that's why it is set first. if(Forced) { Visible = true; Forced = false; } else { Visible = false; } // 1. If bar value gone less than warning value, we show it // in any case, bypassing all other conditions. if(value <= mWarnValue) Visible = true; // 2. Check if bar's value changed, // and if so, start showing it automatically for a given delay time. if(mLastValue != value) { mLastValue = value; Visible = true; mAutoShowCnt = mAutoShowDelay; } // 3. If autoshow time is up, then we hide bar, // otherwise decrease delay counter. if(mAutoShowCnt > 0.0f) { Visible = true; mAutoShowCnt -= engine_frame_time; if(mAutoShowCnt <= 0.0f) { mAutoShowCnt = 0.0f; Visible = false; } } } // end if(AutoShow) if(mAutoShowFade) // Process fade-in and fade-out effect, if enabled. { if(!Visible) { // If visibility flag is off and bar is still on-screen, gradually decrease // fade counter, else simply don't draw anything and exit. if(mAutoShowFadeCnt == 0) { return; } else { mAutoShowFadeCnt -= engine_frame_time * mAutoShowFadeDelay; if(mAutoShowFadeCnt < 0) mAutoShowFadeCnt = 0; } } else { // If visibility flag is on, and bar is not yet fully visible, gradually // increase fade counter, until it's 1 (i. e. fully opaque). if(mAutoShowFadeCnt < 1) { mAutoShowFadeCnt += engine_frame_time * mAutoShowFadeDelay; if(mAutoShowFadeCnt > 1) mAutoShowFadeCnt = 1; } } // end if(!Visible) // Multiply all layers' alpha by current fade counter. mBaseMainColor[3] = mBaseMainColor[4] * mAutoShowFadeCnt; mBaseFadeColor[3] = mBaseFadeColor[4] * mAutoShowFadeCnt; mAltMainColor[3] = mAltMainColor[4] * mAutoShowFadeCnt; mAltFadeColor[3] = mAltFadeColor[4] * mAutoShowFadeCnt; mBackMainColor[3] = mBackMainColor[4] * mAutoShowFadeCnt; mBackFadeColor[3] = mBackFadeColor[4] * mAutoShowFadeCnt; mBorderMainColor[3] = mBorderMainColor[4] * mAutoShowFadeCnt; mBorderFadeColor[3] = mBorderFadeColor[4] * mAutoShowFadeCnt; mExtrudeDepth[3] = mExtrudeDepth[4] * mAutoShowFadeCnt; } else { if(!Visible) return; // Obviously, quit, if bar is not visible. } // end if(mAutoShowFade) // Draw border rect. // Border rect should be rendered first, as it lies beneath actual bar, // and additionally, we need to show it in any case, even if bar is in // warning state (blinking). Gui_DrawRect(mX, mY, mWidth + (mBorderWidth * 2), mHeight + (mBorderHeight * 2), mBorderMainColor, mBorderMainColor, mBorderFadeColor, mBorderFadeColor, BM_OPAQUE); // SECTION FOR BASE BAR RECTANGLE. // We check if bar is in a warning state. If it is, we blink it continously. if(mBlink) { mBlinkCnt -= engine_frame_time; if(mBlinkCnt > mBlinkInterval) { value = 0; // Force zero value, which results in empty bar. } else if(mBlinkCnt <= 0) { mBlinkCnt = mBlinkInterval * 2.0f; } } // If bar value is zero, just render background overlay and immediately exit. // It is needed in case bar is used as a simple UI box to bypass unnecessary calculations. if(!value) { // Draw full-sized background rect (instead of base bar rect) Gui_DrawRect(mX + mBorderWidth, mY + mBorderHeight, mWidth, mHeight, mBackMainColor, (Vertical) ? (mBackFadeColor) : (mBackMainColor), (Vertical) ? (mBackMainColor) : (mBackFadeColor), mBackFadeColor, BM_OPAQUE); return; } // Calculate base bar width, according to current value and range unit. mBaseSize = mRangeUnit * value; mBaseRatio = value / mMaxValue; float RectAnchor; // Anchor to stick base bar rect, according to Invert flag. float RectFirstColor[4]; // Used to recalculate gradient, according to current value. float RectSecondColor[4]; // If invert decrease direction style flag is set, we position bar in a way // that it seems like it's decreasing to another side, and also swap main / fade colours. if(Invert) { memcpy(RectFirstColor, (Alternate) ? (mAltMainColor) : (mBaseMainColor), sizeof(float) * 4); // Main-fade gradient is recalculated according to current / maximum value ratio. for(int i = 0; i <= 3; i++) RectSecondColor[i] = (Alternate) ? ((mBaseRatio * mAltFadeColor[i]) + ((1 - mBaseRatio) * mAltMainColor[i])) : ((mBaseRatio * mBaseFadeColor[i]) + ((1 - mBaseRatio) * mBaseMainColor[i])); } else { memcpy(RectSecondColor, (Alternate) ? (mAltMainColor) : (mBaseMainColor), sizeof(float) * 4); // Main-fade gradient is recalculated according to current / maximum value ratio. for(int i = 0; i <= 3; i++) RectFirstColor[i] = (Alternate) ? ((mBaseRatio * mAltFadeColor[i]) + ((1 - mBaseRatio) * mAltMainColor[i])) : ((mBaseRatio * mBaseFadeColor[i]) + ((1 - mBaseRatio) * mBaseMainColor[i])); } // end if(Invert) // If vertical style flag is set, we draw bar base top-bottom, else we draw it left-right. if(Vertical) { RectAnchor = ((Invert) ? (mY + mHeight - mBaseSize) : (mY)) + mBorderHeight; // Draw actual bar base. Gui_DrawRect(mX + mBorderWidth, RectAnchor, mWidth, mBaseSize, RectFirstColor, RectFirstColor, RectSecondColor, RectSecondColor, BM_OPAQUE); // Draw background rect. Gui_DrawRect(mX + mBorderWidth, (Invert) ? (mY + mBorderHeight) : (RectAnchor + mBaseSize), mWidth, mHeight - mBaseSize, mBackMainColor, mBackFadeColor, mBackMainColor, mBackFadeColor, BM_OPAQUE); if(mExtrude) // Draw extrude overlay, if flag is set. { float transparentColor[4] = {0}; // Used to set counter-shade to transparent. Gui_DrawRect(mX + mBorderWidth, RectAnchor, mWidth / 2, mBaseSize, mExtrudeDepth, transparentColor, mExtrudeDepth, transparentColor, BM_OPAQUE); Gui_DrawRect(mX + mBorderWidth + mWidth / 2, RectAnchor, mWidth / 2, mBaseSize, transparentColor, mExtrudeDepth, transparentColor, mExtrudeDepth, BM_OPAQUE); } } else { RectAnchor = ((Invert) ? (mX + mWidth - mBaseSize) : (mX)) + mBorderWidth; // Draw actual bar base. Gui_DrawRect(RectAnchor, mY + mBorderHeight, mBaseSize, mHeight, RectSecondColor, RectFirstColor, RectSecondColor, RectFirstColor, BM_OPAQUE); // Draw background rect. Gui_DrawRect((Invert) ? (mX + mBorderWidth) : (RectAnchor + mBaseSize), mY + mBorderHeight, mWidth - mBaseSize, mHeight, mBackMainColor, mBackMainColor, mBackFadeColor, mBackFadeColor, BM_OPAQUE); if(mExtrude) // Draw extrude overlay, if flag is set. { float transparentColor[4] = {0}; // Used to set counter-shade to transparent. Gui_DrawRect(RectAnchor, mY + mBorderHeight, mBaseSize, mHeight / 2, transparentColor, transparentColor, mExtrudeDepth, mExtrudeDepth, BM_OPAQUE); Gui_DrawRect(RectAnchor, mY + mBorderHeight + (mHeight / 2), mBaseSize, mHeight / 2, mExtrudeDepth, mExtrudeDepth, transparentColor, transparentColor, BM_OPAQUE); } } // end if(Vertical) }