diff options
Diffstat (limited to '')
-rw-r--r-- | gui/patternpassword.cpp | 100 |
1 files changed, 59 insertions, 41 deletions
diff --git a/gui/patternpassword.cpp b/gui/patternpassword.cpp index ab446b9f0..c31737f32 100644 --- a/gui/patternpassword.cpp +++ b/gui/patternpassword.cpp @@ -1,3 +1,21 @@ +/* + Copyright 2017 TeamWin + This file is part of TWRP/TeamWin Recovery Project. + + TWRP is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + TWRP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with TWRP. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -54,7 +72,7 @@ GUIPatternPassword::GUIPatternPassword(xml_node<>* node) mAction = new GUIAction(node); child = FindNode(node, "dot"); - if(child) + if (child) { mDotColor = LoadAttrColor(child, "color", mDotColor); mActiveDotColor = LoadAttrColor(child, "activecolor", mActiveDotColor); @@ -65,18 +83,18 @@ GUIPatternPassword::GUIPatternPassword(xml_node<>* node) } child = FindNode(node, "line"); - if(child) + if (child) { mLineColor = LoadAttrColor(child, "color", mLineColor); mLineWidth = LoadAttrIntScaleX(child, "width", mLineWidth); } child = FindNode(node, "data"); - if(child) + if (child) mPassVar = LoadAttrString(child, "name", ""); child = FindNode(node, "size"); - if(child) { + if (child) { mSizeVar = LoadAttrString(child, "name", ""); // Use the configured default, if set. @@ -84,7 +102,7 @@ GUIPatternPassword::GUIPatternPassword(xml_node<>* node) Resize(size); } - if(!mDotImage || !mDotImage->GetResource() || !mActiveDotImage || !mActiveDotImage->GetResource()) + if (!mDotImage || !mDotImage->GetResource() || !mActiveDotImage || !mActiveDotImage->GetResource()) { mDotCircle = gr_render_circle(mDotRadius, mDotColor.red, mDotColor.green, mDotColor.blue, mDotColor.alpha); mActiveDotCircle = gr_render_circle(mDotRadius/2, mActiveDotColor.red, mActiveDotColor.green, mActiveDotColor.blue, mActiveDotColor.alpha); @@ -104,10 +122,10 @@ GUIPatternPassword::~GUIPatternPassword() delete[] mDots; delete[] mConnectedDots; - if(mDotCircle) + if (mDotCircle) gr_free_surface(mDotCircle); - if(mActiveDotCircle) + if (mActiveDotCircle) gr_free_surface(mActiveDotCircle); } @@ -115,7 +133,7 @@ void GUIPatternPassword::ResetActiveDots() { mConnectedDotsLen = 0; mCurLineX = mCurLineY = -1; - for(size_t i = 0; i < mGridSize * mGridSize; ++i) + for (size_t i = 0; i < mGridSize * mGridSize; ++i) mDots[i].active = false; } @@ -155,9 +173,9 @@ void GUIPatternPassword::CalculateDotPositions(void) * n*n-1 */ - for(size_t r = 0; r < mGridSize; ++r) + for (size_t r = 0; r < mGridSize; ++r) { - for(size_t c = 0; c < mGridSize; ++c) + for (size_t c = 0; c < mGridSize; ++c) { mDots[mGridSize*r + c].x = x; mDots[mGridSize*r + c].y = y; @@ -170,29 +188,29 @@ void GUIPatternPassword::CalculateDotPositions(void) int GUIPatternPassword::Render(void) { - if(!isConditionTrue()) + if (!isConditionTrue()) return 0; gr_color(mLineColor.red, mLineColor.green, mLineColor.blue, mLineColor.alpha); - for(size_t i = 1; i < mConnectedDotsLen; ++i) { + for (size_t i = 1; i < mConnectedDotsLen; ++i) { const Dot& dp = mDots[mConnectedDots[i-1]]; const Dot& dc = mDots[mConnectedDots[i]]; gr_line(dp.x + mDotRadius, dp.y + mDotRadius, dc.x + mDotRadius, dc.y + mDotRadius, mLineWidth); } - if(mConnectedDotsLen > 0 && mTrackingTouch) { + if (mConnectedDotsLen > 0 && mTrackingTouch) { const Dot& dc = mDots[mConnectedDots[mConnectedDotsLen-1]]; gr_line(dc.x + mDotRadius, dc.y + mDotRadius, mCurLineX, mCurLineY, mLineWidth); } - for(size_t i = 0; i < mGridSize * mGridSize; ++i) { - if(mDotCircle) { + for (size_t i = 0; i < mGridSize * mGridSize; ++i) { + if (mDotCircle) { gr_blit(mDotCircle, 0, 0, gr_get_width(mDotCircle), gr_get_height(mDotCircle), mDots[i].x, mDots[i].y); - if(mDots[i].active) { + if (mDots[i].active) { gr_blit(mActiveDotCircle, 0, 0, gr_get_width(mActiveDotCircle), gr_get_height(mActiveDotCircle), mDots[i].x + mDotRadius/2, mDots[i].y + mDotRadius/2); } } else { - if(mDots[i].active) { + if (mDots[i].active) { gr_blit(mActiveDotImage->GetResource(), 0, 0, mActiveDotImage->GetWidth(), mActiveDotImage->GetHeight(), mDots[i].x + (mDotRadius - mActiveDotImage->GetWidth()/2), mDots[i].y + (mDotRadius - mActiveDotImage->GetHeight()/2)); } else { @@ -205,7 +223,7 @@ int GUIPatternPassword::Render(void) int GUIPatternPassword::Update(void) { - if(!isConditionTrue()) + if (!isConditionTrue()) return 0; int res = mNeedRender ? 2 : 1; @@ -214,7 +232,7 @@ int GUIPatternPassword::Update(void) } void GUIPatternPassword::Resize(size_t n) { - if(mGridSize == n) + if (mGridSize == n) return; delete[] mDots; @@ -247,8 +265,8 @@ static bool IsInCircle(int x, int y, int ox, int oy, int r) int GUIPatternPassword::InDot(int x, int y) { - for(size_t i = 0; i < mGridSize * mGridSize; ++i) { - if(IsInCircle(x, y, mDots[i].x + mDotRadius, mDots[i].y + mDotRadius, mDotRadius*3)) + for (size_t i = 0; i < mGridSize * mGridSize; ++i) { + if (IsInCircle(x, y, mDots[i].x + mDotRadius, mDots[i].y + mDotRadius, mDotRadius*3)) return i; } return -1; @@ -256,8 +274,8 @@ int GUIPatternPassword::InDot(int x, int y) bool GUIPatternPassword::DotUsed(int dot_idx) { - for(size_t i = 0; i < mConnectedDotsLen; ++i) { - if(mConnectedDots[i] == dot_idx) + for (size_t i = 0; i < mConnectedDotsLen; ++i) { + if (mConnectedDots[i] == dot_idx) return true; } return false; @@ -265,7 +283,7 @@ bool GUIPatternPassword::DotUsed(int dot_idx) void GUIPatternPassword::ConnectDot(int dot_idx) { - if(mConnectedDotsLen >= mGridSize * mGridSize) + if (mConnectedDotsLen >= mGridSize * mGridSize) { LOGERR("mConnectedDots in GUIPatternPassword has overflown!\n"); return; @@ -277,7 +295,7 @@ void GUIPatternPassword::ConnectDot(int dot_idx) void GUIPatternPassword::ConnectIntermediateDots(int next_dot_idx) { - if(mConnectedDotsLen == 0) + if (mConnectedDotsLen == 0) return; const int prev_dot_idx = mConnectedDots[mConnectedDotsLen-1]; @@ -311,15 +329,15 @@ void GUIPatternPassword::ConnectIntermediateDots(int next_dot_idx) int Dy = (ny > py) ? 1 : -1; // Vertical lines. - if(px == nx) + if (px == nx) Dx = 0; // Horizontal lines. - else if(py == ny) + else if (py == ny) Dy = 0; // Diagonal lines (|∆x| = |∆y|). - else if(abs(px - nx) == abs(py - ny)) + else if (abs(px - nx) == abs(py - ny)) ; // No valid intermediate dots. @@ -327,19 +345,19 @@ void GUIPatternPassword::ConnectIntermediateDots(int next_dot_idx) return; // Iterate along axis, adding dots in the correct order. - while((Dy == 0 || y != ny - Dy) && (Dx == 0 || x != nx - Dx)) { + while ((Dy == 0 || y != ny - Dy) && (Dx == 0 || x != nx - Dx)) { x += Dx; y += Dy; int idx = mGridSize * y + x; - if(!DotUsed(idx)) + if (!DotUsed(idx)) ConnectDot(idx); } } int GUIPatternPassword::NotifyTouch(TOUCH_STATE state, int x, int y) { - if(!isConditionTrue()) + if (!isConditionTrue()) return -1; switch (state) @@ -347,7 +365,7 @@ int GUIPatternPassword::NotifyTouch(TOUCH_STATE state, int x, int y) case TOUCH_START: { const int dot_idx = InDot(x, y); - if(dot_idx == -1) + if (dot_idx == -1) break; mTrackingTouch = true; @@ -361,11 +379,11 @@ int GUIPatternPassword::NotifyTouch(TOUCH_STATE state, int x, int y) } case TOUCH_DRAG: { - if(!mTrackingTouch) + if (!mTrackingTouch) break; const int dot_idx = InDot(x, y); - if(dot_idx != -1 && !DotUsed(dot_idx)) + if (dot_idx != -1 && !DotUsed(dot_idx)) { ConnectIntermediateDots(dot_idx); ConnectDot(dot_idx); @@ -379,7 +397,7 @@ int GUIPatternPassword::NotifyTouch(TOUCH_STATE state, int x, int y) } case TOUCH_RELEASE: { - if(!mTrackingTouch) + if (!mTrackingTouch) break; mNeedRender = true; @@ -396,10 +414,10 @@ int GUIPatternPassword::NotifyTouch(TOUCH_STATE state, int x, int y) int GUIPatternPassword::NotifyVarChange(const std::string& varName, const std::string& value) { - if(!isConditionTrue()) + if (!isConditionTrue()) return 0; - if(varName == mSizeVar) { + if (varName == mSizeVar) { Resize(atoi(value.c_str())); mUpdate = true; } @@ -420,8 +438,8 @@ static unsigned int getSDKVersion(void) { std::string GUIPatternPassword::GeneratePassphrase() { char pattern[mConnectedDotsLen]; - for(size_t i = 0; i < mConnectedDotsLen; i++) { - pattern[i] = (char) mConnectedDots[i]; + for (size_t i = 0; i < mConnectedDotsLen; i++) { + pattern[i] = (char) mConnectedDots[i]; } std::stringstream pass; @@ -461,9 +479,9 @@ std::string GUIPatternPassword::GeneratePassphrase() void GUIPatternPassword::PatternDrawn() { - if(!mPassVar.empty() && mConnectedDotsLen > 0) + if (!mPassVar.empty() && mConnectedDotsLen > 0) DataManager::SetValue(mPassVar, GeneratePassphrase()); - if(mAction) + if (mAction) mAction->doActions(); } |