int GUISliderValue::Render(void) { if (!isConditionTrue()) { mRendered = false; return 0; } if(mLabel) { int w, h; mLabel->GetCurrentBounds(w, h); if (w != mLabelW) { mLabelW = w; int textX = mRenderX + (mRenderW/2 - mLabelW/2); mLabel->SetRenderPos(textX, mRenderY); } int res = mLabel->Render(); if(res < 0) return res; } // line gr_color(mLineColor.red, mLineColor.green, mLineColor.blue, mLineColor.alpha); gr_fill(mLineX, mLineY, lineW, mLineH); // slider uint32_t sliderX = (mValuePct*lineW)/100 + mLineX; sliderX -= mSliderW/2; gr_color(mSliderColor.red, mSliderColor.green, mSliderColor.blue, mSliderColor.alpha); gr_fill(sliderX, mSliderY, mSliderW, mSliderH); void *fontResource = NULL; if(mFont) fontResource = mFont->GetResource(); gr_color(mTextColor.red, mTextColor.green, mTextColor.blue, mTextColor.alpha); if(mShowRange) { int rangeY = (mLineY - mLineH/2) - mFontHeight/2; gr_textEx(mRenderX + mPadding/2, rangeY, mMinStr.c_str(), fontResource); gr_textEx(mLineX + lineW + mPadding/2, rangeY, mMaxStr.c_str(), fontResource); } if(mValueStr && mShowCurr) { sprintf(mValueStr, "%d", mValue); int textW = measureText(mValueStr); gr_textEx(mRenderX + (mRenderW/2 - textW/2), mSliderY+mSliderH, mValueStr, fontResource); } mRendered = true; return 0; }
int GUIFileSelector::Render(void) { // First step, fill background gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); // Next, render the background resource (if it exists) if (mBackground && mBackground->GetResource()) { mBackgroundX = mRenderX + ((mRenderW - mBackgroundW) / 2); mBackgroundY = mRenderY + ((mRenderH - mBackgroundH) / 2); gr_blit(mBackground->GetResource(), 0, 0, mBackgroundW, mBackgroundH, mBackgroundX, mBackgroundY); } // Now, we need the lines (icon + text) gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, mFontColor.alpha); // This tells us how many lines we can actually render int lines = mRenderH / (mLineHeight + mLineSpacing); int line; int folderSize = mShowFolders ? mFolderList.size() : 0; int fileSize = mShowFiles ? mFileList.size() : 0; if (folderSize + fileSize < lines) lines = folderSize + fileSize; void* fontResource = NULL; if (mFont) fontResource = mFont->GetResource(); int yPos = mRenderY + (mLineSpacing / 2); for (line = 0; line < lines; line++) { Resource* icon; std::string label; if (line + mStart < folderSize) { icon = mFolderIcon; label = mFolderList.at(line + mStart).fileName; } else { icon = mFileIcon; label = mFileList.at((line + mStart) - folderSize).fileName; } if (icon && icon->GetResource()) { gr_blit(icon->GetResource(), 0, 0, mIconWidth, mIconHeight, mRenderX, yPos); } gr_textEx(mRenderX + mIconWidth + 5, yPos, label.c_str(), fontResource); // Move the yPos yPos += mLineHeight + mLineSpacing; } mUpdate = 0; return 0; }
int GUIText::Render(void) { if (!isConditionTrue()) return 0; void* fontResource = NULL; string displayValue; if (mFont) fontResource = mFont->GetResource(); mLastValue = parseText(); displayValue = mLastValue; if (charSkip) displayValue.erase(0, charSkip); mVarChanged = 0; int x = mRenderX, y = mRenderY; int width = gr_measureEx(displayValue.c_str(), fontResource); if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT) { if (mPlacement == CENTER || mPlacement == CENTER_X_ONLY) x -= (width / 2); else x -= width; } if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT) { if (mPlacement == CENTER) y -= (mFontHeight / 2); else if (mPlacement == BOTTOM_LEFT || mPlacement == BOTTOM_RIGHT) y -= mFontHeight; } if (hasHighlightColor && isHighlighted) gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); else gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha); if (maxWidth) gr_textExW(x, y, displayValue.c_str(), fontResource, maxWidth + x); else gr_textEx(x, y, displayValue.c_str(), fontResource); return 0; }
void GUIConsole::RenderItem(size_t itemindex, int yPos, bool selected) { // Set the color for the font if (rConsoleColor[itemindex] == "normal") { gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, mFontColor.alpha); } else { COLOR FontColor; std::string color = rConsoleColor[itemindex]; ConvertStrToColor(color, &FontColor); FontColor.alpha = 255; gr_color(FontColor.red, FontColor.green, FontColor.blue, FontColor.alpha); } // render text const char* text = rConsole[itemindex].c_str(); gr_textEx(mRenderX, yPos, text, mFont->GetResource()); }
int GUIConsole::RenderConsole(void) { void* fontResource = NULL; if (mFont) fontResource = mFont->GetResource(); // We fill the background gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); gr_fill(mConsoleX, mConsoleY, mConsoleW, mConsoleH); gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha); gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH); // Render the lines gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha); // Don't try to continue to render without data mLastCount = gConsole.size(); if (mLastCount == 0) return (mSlideout ? RenderSlideout() : 0); // Find the start point int start; int curLine = mCurrentLine; // Thread-safing (Another thread updates this value) if (curLine == -1) { start = mLastCount - mMaxRows; } else { if (curLine > (int) mLastCount) curLine = (int) mLastCount; if ((int) mMaxRows > curLine) curLine = (int) mMaxRows; start = curLine - mMaxRows; } unsigned int line; for (line = 0; line < mMaxRows; line++) { if ((start + (int) line) >= 0 && (start + (int) line) < (int) mLastCount) { gr_textEx(mConsoleX, mStartY + (line * mFontHeight), gConsole[start + line].c_str(), fontResource); } } return (mSlideout ? RenderSlideout() : 0); }
void GUIKeyboard::DrawKey(Key& key, int keyX, int keyY, int keyW, int keyH) { unsigned char keychar = key.key; if (!keychar) return; // key background COLOR& c = (keychar >= 32 && keychar < 127) ? mKeyColorAlphanumeric : mKeyColorOther; gr_color(c.red, c.green, c.blue, c.alpha); keyX += mKeyMarginX; keyY += mKeyMarginY; keyW -= mKeyMarginX * 2; keyH -= mKeyMarginY * 2; gr_fill(keyX, keyY, keyW, keyH); // key label FontResource* labelFont = mFont; string labelText; ImageResource* labelImage = NULL; if (keychar > 32 && keychar < 127) { labelText = (char) keychar; gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, mFontColor.alpha); } else { // search for a special key label for (std::vector<KeyLabel>::iterator it = mKeyLabels.begin(); it != mKeyLabels.end(); ++it) { if (it->layout_from > 0 && it->layout_from != currentLayout) continue; // this label is for another layout if (it->key == key.key && it->layout_to == key.layout) { // found a label labelText = it->text; labelImage = it->image; break; } } labelFont = mSmallFont; gr_color(mFontColorSmall.red, mFontColorSmall.green, mFontColorSmall.blue, mFontColorSmall.alpha); } if (labelImage) { int w = labelImage->GetWidth(); int h = labelImage->GetHeight(); int x = keyX + (keyW - w) / 2; int y = keyY + (keyH - h) / 2; gr_blit(labelImage->GetResource(), 0, 0, w, h, x, y); } else if (!labelText.empty()) { void* fontResource = labelFont->GetResource(); int textW = gr_measureEx(labelText.c_str(), fontResource); int textH = labelFont->GetHeight(); int textX = keyX + (keyW - textW) / 2; int textY = keyY + (keyH - textH) / 2; gr_textEx(textX, textY, labelText.c_str(), fontResource); } // longpress key label (only if font is defined) keychar = key.longpresskey; if (keychar > 32 && keychar < 127 && mLongpressFont->GetResource()) { void* fontResource = mLongpressFont->GetResource(); gr_color(mLongpressFontColor.red, mLongpressFontColor.green, mLongpressFontColor.blue, mLongpressFontColor.alpha); string text(1, keychar); int textH = mLongpressFont->GetHeight(); int textW = gr_measureEx(text.c_str(), fontResource); int textX = keyX + keyW - longpressOffsetX - textW; int textY = keyY + longpressOffsetY; gr_textEx(textX, textY, text.c_str(), fontResource); } }