int GUIListBox::NotifyVarChange(const std::string& varName, const std::string& value) { GUIScrollList::NotifyVarChange(varName, value); if(!isConditionTrue()) return 0; // Check to see if the variable that we are using to store the list selected value has been updated if (varName == mVariable) { int i, listSize = mList.size(); currentValue = value; for (i = 0; i < listSize; i++) { if (mList.at(i).variableValue == currentValue) { mList.at(i).selected = 1; SetVisibleListLocation(i); } else mList.at(i).selected = 0; } mUpdate = 1; return 0; } return 0; }
int GUIKeyboard::Update(void) { if (!isConditionTrue()) return (mRendered ? 2 : 0); if (!mRendered) return 2; return 0; }
int GUISlider::Render(void) { if(!isConditionTrue()) return 0; if (!sSlider || !sSlider->GetResource()) return -1; // Draw the slider gr_blit(sSlider->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); // Draw the used if (sSliderUsed && sSliderUsed->GetResource() && sCurTouchX > mRenderX) gr_blit(sSliderUsed->GetResource(), 0, 0, sCurTouchX - mRenderX, mRenderH, mRenderX, mRenderY); // Draw the touch icon if (sTouch && sTouch->GetResource()) gr_blit(sTouch->GetResource(), 0, 0, sTouchW, sTouchH, sCurTouchX, (mRenderY + ((mRenderH - sTouchH) / 2))); if (sSliderLabel) { int ret = sSliderLabel->Render(); if (ret < 0) return ret; } sUpdate = 0; return 0; }
int GUIText::Update(void) { if (!isConditionTrue()) return 0; static int updateCounter = 3; // This hack just makes sure we update at least once a minute for things like clock and battery if (updateCounter) updateCounter--; else { mVarChanged = 1; updateCounter = 3; } if (mIsStatic || !mVarChanged) return 0; std::string newValue = parseText(); if (mLastValue == newValue) return 0; else mLastValue = newValue; return 2; }
int GUICheckbox::Render(void) { if (!isConditionTrue()) { mRendered = false; return 0; } int ret = 0; int lastState = 0; DataManager::GetValue(mVarName, lastState); if (lastState) { if (mChecked && mChecked->GetResource()) gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY); } else { if (mUnchecked && mUnchecked->GetResource()) gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY); } if (mLabel) ret = mLabel->Render(); mLastState = lastState; mRendered = true; return ret; }
int GUIButton::Render(void) { if (!isConditionTrue()) { mRendered = false; return 0; } int ret = 0; if (mButtonImg) ret = mButtonImg->Render(); if (ret < 0) return ret; if (hasFill) { gr_color(mFillColor.red, mFillColor.green, mFillColor.blue, mFillColor.alpha); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); } if (mButtonIcon && mButtonIcon->GetResource()) gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); if (mButtonLabel) { int w, h; mButtonLabel->GetCurrentBounds(w, h); if (w != mTextW) { mTextW = w; } ret = mButtonLabel->Render(); if (ret < 0) return ret; } if (renderHighlight && hasHighlightColor) { gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); } mRendered = true; return ret; }
int GUIButton::Update(void) { if (!isConditionTrue()) return (mRendered ? 2 : 0); if (!mRendered) return 2; int ret = 0, ret2 = 0; if (mButtonImg) ret = mButtonImg->Update(); if (ret < 0) return ret; if (ret == 0) { if (mButtonLabel) { ret2 = mButtonLabel->Update(); if (ret2 < 0) return ret2; if (ret2 > ret) ret = ret2; } } else if (ret == 1) { // The button re-rendered, so everyone else is a render if (mButtonIcon && mButtonIcon->GetResource()) gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); if (mButtonLabel) ret = mButtonLabel->Render(); if (ret < 0) return ret; ret = 1; } else { // Aparently, the button needs a background update ret = 2; } return ret; }
int GUIKeyboard::Render(void) { if (!isConditionTrue()) { mRendered = false; return 0; } int ret = 0; if (keyboardImg[currentLayout - 1] && keyboardImg[currentLayout - 1]->GetResource()) gr_blit(keyboardImg[currentLayout - 1]->GetResource(), 0, 0, KeyboardWidth, KeyboardHeight, mRenderX, mRenderY); if (hasHighlight && highlightRenderCount != 0) { int boxheight, boxwidth, x; if (rowY == 0) boxheight = row_heights[currentLayout - 1][rowY]; else boxheight = row_heights[currentLayout - 1][rowY] - row_heights[currentLayout - 1][rowY - 1]; if (colX == 0) { x = mRenderX; boxwidth = keyboard_keys[currentLayout - 1][rowY][colX].end_x; } else { x = mRenderX + keyboard_keys[currentLayout - 1][rowY][colX - 1].end_x; boxwidth = keyboard_keys[currentLayout - 1][rowY][colX].end_x - keyboard_keys[currentLayout - 1][rowY][colX - 1].end_x; } gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); gr_fill(x, mRenderY + row_heights[currentLayout - 1][rowY - 1], boxwidth, boxheight); if (highlightRenderCount > 0) highlightRenderCount--; } else mRendered = true; return ret; }
int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y) { static int last_state = 0; if (!isConditionTrue()) return -1; if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH || state == TOUCH_RELEASE) { if (last_state == 1) { last_state = 0; if (mButtonLabel != NULL) mButtonLabel->isHighlighted = false; if (mButtonImg != NULL) mButtonImg->isHighlighted = false; renderHighlight = false; mRendered = false; } } else { if (last_state == 0) { last_state = 1; DataManager::Vibrate("tw_button_vibrate"); if (mButtonLabel != NULL) mButtonLabel->isHighlighted = true; if (mButtonImg != NULL) mButtonImg->isHighlighted = true; renderHighlight = true; mRendered = false; } } if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH) return 0; return (mAction ? mAction->NotifyTouch(state, x, y) : 1); }
int GUIKeyboard::Render(void) { if (!isConditionTrue()) { mRendered = false; return 0; } Layout& lay = layouts[currentLayout - 1]; if (lay.keyboardImg && lay.keyboardImg->GetResource()) gr_blit(lay.keyboardImg->GetResource(), 0, 0, KeyboardWidth, KeyboardHeight, mRenderX, mRenderY); // Draw highlight for capslock if (hasCapsHighlight && lay.is_caps && CapsLockOn) { gr_color(mCapsHighlightColor.red, mCapsHighlightColor.green, mCapsHighlightColor.blue, mCapsHighlightColor.alpha); for (int indexy=0; indexy<MAX_KEYBOARD_ROWS; indexy++) { for (int indexx=0; indexx<MAX_KEYBOARD_KEYS; indexx++) { if ((int)lay.keys[indexy][indexx].key == KEYBOARD_LAYOUT && (int)lay.keys[indexy][indexx].layout == lay.revert_layout) { int boxheight, boxwidth, x; if (indexy == 0) boxheight = lay.row_end_y[indexy]; else boxheight = lay.row_end_y[indexy] - lay.row_end_y[indexy - 1]; if (indexx == 0) { x = mRenderX; boxwidth = lay.keys[indexy][indexx].end_x; } else { x = mRenderX + lay.keys[indexy][indexx - 1].end_x; boxwidth = lay.keys[indexy][indexx].end_x - lay.keys[indexy][indexx - 1].end_x; } gr_fill(x, mRenderY + lay.row_end_y[indexy - 1], boxwidth, boxheight); } } } } if (hasHighlight && highlightRenderCount != 0) { int boxheight, boxwidth, x; if (rowY == 0) boxheight = lay.row_end_y[rowY]; else boxheight = lay.row_end_y[rowY] - lay.row_end_y[rowY - 1]; if (colX == 0) { x = mRenderX; boxwidth = lay.keys[rowY][colX].end_x; } else { x = mRenderX + lay.keys[rowY][colX - 1].end_x; boxwidth = lay.keys[rowY][colX].end_x - lay.keys[rowY][colX - 1].end_x; } gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); gr_fill(x, mRenderY + lay.row_end_y[rowY - 1], boxwidth, boxheight); if (highlightRenderCount > 0) highlightRenderCount--; } else mRendered = true; return 0; }
int GUIProgressBar::Render(void) { if(!isConditionTrue()) return 0; // This handles making sure timing updates occur Update(); return RenderInternal(); }
int GUISlider::Update(void) { if(!isConditionTrue()) return 0; if (sUpdate) return 2; return 0; }
bool Conditional::isConditionTrue() { std::vector<Condition>::iterator iter; for (iter = mConditions.begin(); iter != mConditions.end(); iter++) { if (!isConditionTrue(&(*iter))) return false; } return true; }
int GUISliderValue::Update(void) { if (!isConditionTrue()) return mRendered ? 2 : 0; if (!mRendered) return 2; if(mLabel) return mLabel->Update(); return 0; }
int GUISlider::NotifyTouch(TOUCH_STATE state, int x, int y) { if(!isConditionTrue()) return -1; static bool dragging = false; switch (state) { case TOUCH_START: if (x >= mRenderX && x <= mRenderX + sTouchW && y >= mRenderY && y <= mRenderY + mRenderH) { sCurTouchX = x - (sTouchW / 2); if (sCurTouchX < mRenderX) sCurTouchX = mRenderX; dragging = true; } break; case TOUCH_DRAG: if (!dragging) return 0; if (y < mRenderY - sTouchH || y > mRenderY + (sTouchH * 2)) { sCurTouchX = mRenderX; dragging = false; sUpdate = 1; break; } sCurTouchX = x - (sTouchW / 2); if (sCurTouchX < mRenderX) sCurTouchX = mRenderX; if (sCurTouchX > mRenderX + mRenderW - sTouchW) sCurTouchX = mRenderX + mRenderW - sTouchW; sUpdate = 1; break; case TOUCH_RELEASE: if (!dragging) return 0; if (sCurTouchX >= mRenderX + mRenderW - sTouchW) { DataManager::Vibrate("tw_button_vibrate"); sAction->doActions(); } sCurTouchX = mRenderX; dragging = false; sUpdate = 1; case TOUCH_REPEAT: case TOUCH_HOLD: break; } return 0; }
int GUIConsole::Render(void) { if(!isConditionTrue()) return 0; if (mSlideout && mSlideoutState == hidden) return RenderSlideout(); return RenderConsole(); }
int GUIAction::NotifyVarChange(const std::string& varName, const std::string& value) { GUIObject::NotifyVarChange(varName, value); if (varName.empty() && !isConditionValid() && mKeys.empty() && !mActionW) doActions(); else if((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) doActions(); return 0; }
int GUICheckbox::Update(void) { if (!isConditionTrue()) return (mRendered ? 2 : 0); if (!mRendered) return 2; int lastState = 0; DataManager::GetValue(mVarName, lastState); if (lastState != mLastState) return 2; return 0; }
int GUIInput::Update(void) { if (!isConditionTrue()) return (mRendered ? 2 : 0); if (!mRendered) return 2; int ret = 0; if (mInputText) ret = mInputText->Update(); if (ret < 0) return ret; return ret; }
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 GUISliderValue::NotifyTouch(TOUCH_STATE state, int x, int y) { if (!isConditionTrue()) return -1; static bool dragging = false; switch (state) { case TOUCH_START: if (x >= mRenderX && x <= mRenderX + mRenderW && y >= mRenderY && y <= mRenderY + mRenderH) { dragging = true; } // no break case TOUCH_DRAG: { if (!dragging) return 0; x = std::max(mLineX, x); x = std::min(mLineX + lineW, x); mValuePct = float(((x - mLineX) * 100) / lineW); int newVal = valueFromPct(mValuePct); if (newVal != mValue) { mRendered = false; mValue = newVal; if (mChangeOnDrag) { if (!mVariable.empty()) DataManager::SetValue(mVariable, mValue); if (mAction) mAction->doActions(); } } break; } case TOUCH_RELEASE: { if (!dragging) return 0; dragging = false; if (!mVariable.empty()) DataManager::SetValue(mVariable, mValue); if (mAction) mAction->doActions(); break; } case TOUCH_REPEAT: case TOUCH_HOLD: break; } return 0; }
int GUICheckbox::NotifyTouch(TOUCH_STATE state, int x, int y) { if (!isConditionTrue()) return -1; if (state == TOUCH_RELEASE) { int lastState; DataManager::GetValue(mVarName, lastState); lastState = (lastState == 0) ? 1 : 0; DataManager::SetValue(mVarName, lastState); } return 0; }
int GUIPartitionList::NotifyVarChange(const std::string& varName, const std::string& value) { GUIObject::NotifyVarChange(varName, value); if(!isConditionTrue()) return 0; if (!mHeaderIsStatic) { std::string newValue = gui_parse_text(mHeaderText); if (mLastValue != newValue) { mLastValue = newValue; mStart = 0; scrollingY = 0; scrollingSpeed = 0; mUpdate = 1; } } if (varName == mVariable && !mUpdate) { if (ListType == "storage") { int i, listSize = mList.size(), selected_index = 0; currentValue = value; for (i=0; i<listSize; i++) { if (mList.at(i).Mount_Point == currentValue) { mList.at(i).selected = 1; selected_index = i; } else mList.at(i).selected = 0; } int lines = mRenderH / (mLineHeight + mLineSpacing); int line; if (selected_index > mStart + lines - 1) { mStart = selected_index; } else if (selected_index < mStart) { mStart = selected_index; } } else if (ListType == "backup") { MatchList(); } else if (ListType == "restore") { updateList = true; } mUpdate = 1; return 0; } return 0; }
int GUIAction::NotifyVarChange(std::string varName, std::string value) { if (varName.empty() && !isConditionValid() && !mKey && !mActionW) doActions(); // This handles notifying the condition system of page start if (varName.empty() && isConditionValid()) NotifyPageSet(); if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) doActions(); return 0; }
int GUIListBox::Update(void) { if(!isConditionTrue()) return 0; GUIScrollList::Update(); if (mUpdate) { mUpdate = 0; if (Render() == 0) return 2; } 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; }
int GUICheckbox::NotifyTouch(TOUCH_STATE state, int x __unused, int y __unused) { if (!isConditionTrue()) return -1; if (state == TOUCH_RELEASE) { int lastState; DataManager::GetValue(mVarName, lastState); lastState = (lastState == 0) ? 1 : 0; DataManager::SetValue(mVarName, lastState); DataManager::Vibrate("tw_button_vibrate"); } return 0; }
int GUIListBox::NotifyVarChange(const std::string& varName, const std::string& value) { GUIObject::NotifyVarChange(varName, value); if(!isConditionTrue()) return 0; if (!mHeaderIsStatic) { std::string newValue = gui_parse_text(mHeaderText); if (mLastValue != newValue) { mLastValue = newValue; mStart = 0; scrollingY = 0; scrollingSpeed = 0; mUpdate = 1; } } if (varName == mVariable) { int i, listSize = mList.size(), selected_index = 0; currentValue = value; for (i=0; i<listSize; i++) { if (mList.at(i).variableValue == currentValue) { mList.at(i).selected = 1; selected_index = i; } else mList.at(i).selected = 0; } int lines = mRenderH / (mLineHeight + mLineSpacing); int line; if (selected_index > mStart + lines - 1) mStart = selected_index; if (mStart > listSize - lines) { mStart = listSize - lines; } else if (selected_index < mStart) { mStart = selected_index; } mUpdate = 1; return 0; } return 0; }
// NotifyTouch - Notify of a touch event // Return 0 on success, >0 to ignore remainder of touch, and <0 on error int GUIConsole::NotifyTouch(TOUCH_STATE state, int x, int y) { if(!isConditionTrue()) return -1; if (mSlideout && x >= mSlideoutX && x < mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH) { if (state == TOUCH_START) { if (mSlideoutState == hidden) mSlideoutState = request_show; else if (mSlideoutState == visible) mSlideoutState = request_hide; } return 1; } scrollToEnd = false; return GUIScrollList::NotifyTouch(state, x, y); }
int GUIButton::Render(void) { if (!isConditionTrue()) { mRendered = false; return 0; } int ret = 0; if (mButtonImg) ret = mButtonImg->Render(); if (ret < 0) return ret; if (hasFill) { gr_color(mFillColor.red, mFillColor.green, mFillColor.blue, mFillColor.alpha); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); } if (mButtonIcon && mButtonIcon->GetResource()) gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); if (mButtonLabel) { int w, h; mButtonLabel->GetCurrentBounds(w, h); if (w != mTextW) { mTextW = w; if (TextPlacement == CENTER_X_ONLY) { mTextX = ((mRenderW - mRenderX) / 2); } else if (mTextW > mRenderW) { // As a special case, we'll allow large text which automatically moves it to the right. mTextX = mRenderW + mRenderX + 5; mRenderW += mTextW + 5; } else { mTextX = mRenderX + ((mRenderW - mTextW) / 2); } mButtonLabel->SetRenderPos(mTextX, mTextY); } ret = mButtonLabel->Render(); if (ret < 0) return ret; } if (renderHighlight && hasHighlightColor) { gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); } mRendered = true; return ret; }