Commit fafb0c54 authored by Vojtech Bocek's avatar Vojtech Bocek Committed by Gerrit Code Review

Unify indentation and little clean-up in TWRP files

Signed-off-by: default avatarVojtech Bocek <vbocek@gmail.com>
parent 8b44bbda
This diff is collapsed.
......@@ -17,13 +17,13 @@
#ifndef _DATA_HEADER
#define _DATA_HEADER
int DataManager_ResetDefaults();
void DataManager_LoadDefaults();
int DataManager_ResetDefaults(void);
void DataManager_LoadDefaults(void);
int DataManager_LoadValues(const char* filename);
int DataManager_Flush();
int DataManager_Flush(void);
const char* DataManager_GetStrValue(const char* varName);
const char* DataManager_GetCurrentStoragePath();
const char* DataManager_GetSettingsStoragePath();
const char* DataManager_GetCurrentStoragePath(void);
const char* DataManager_GetSettingsStoragePath(void);
int DataManager_GetIntValue(const char* varName);
int DataManager_SetStrValue(const char* varName, char* value);
......@@ -32,8 +32,8 @@ int DataManager_SetFloatValue(const char* varName, float value);
int DataManager_ToggleIntValue(const char* varName);
void DataManager_DumpValues();
void DataManager_ReadSettingsFile();
void DataManager_DumpValues(void);
void DataManager_ReadSettingsFile(void);
#endif // _DATA_HEADER
......@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
......@@ -26,32 +26,32 @@ using namespace std;
class DataManager
{
public:
static int ResetDefaults();
static int LoadValues(const string filename);
static int Flush();
static int ResetDefaults();
static int LoadValues(const string filename);
static int Flush();
// Core get routines
static int GetValue(const string varName, string& value);
static int GetValue(const string varName, int& value);
// Core get routines
static int GetValue(const string varName, string& value);
static int GetValue(const string varName, int& value);
static int GetValue(const string varName, float& value);
static unsigned long long GetValue(const string varName, unsigned long long& value);
static unsigned long long GetValue(const string varName, unsigned long long& value);
// This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
static string& GetValueRef(const string varName);
// This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
static string& GetValueRef(const string varName);
// Helper functions
static string GetStrValue(const string varName);
static int GetIntValue(const string varName);
// Helper functions
static string GetStrValue(const string varName);
static int GetIntValue(const string varName);
// Core set routines
static int SetValue(const string varName, string value, int persist = 0);
static int SetValue(const string varName, int value, int persist = 0);
static int SetValue(const string varName, float value, int persist = 0);
static int SetValue(const string varName, unsigned long long value, int persist = 0);
// Core set routines
static int SetValue(const string varName, string value, int persist = 0);
static int SetValue(const string varName, int value, int persist = 0);
static int SetValue(const string varName, float value, int persist = 0);
static int SetValue(const string varName, unsigned long long value, int persist = 0);
static int SetProgress(float Fraction);
static int ShowProgress(float Portion, float Seconds);
static void DumpValues();
static void DumpValues();
static void update_tz_environment_variables();
static void SetBackupFolder();
static void SetDefaultValues();
......@@ -64,20 +64,20 @@ public:
static string& CGetSettingsStoragePath();
protected:
typedef pair<string, int> TStrIntPair;
typedef pair<string, unsigned long long> TStrULLPair;
typedef pair<string, TStrIntPair> TNameValuePair;
static map<string, TStrIntPair> mValues;
static map<string, TStrULLPair> mULLValues;
static string mBackingFile;
static int mInitialized;
typedef pair<string, int> TStrIntPair;
typedef pair<string, unsigned long long> TStrULLPair;
typedef pair<string, TStrIntPair> TNameValuePair;
static map<string, TStrIntPair> mValues;
static map<string, TStrULLPair> mULLValues;
static string mBackingFile;
static int mInitialized;
static map<string, string> mConstValues;
static map<string, string> mConstValues;
protected:
static int SaveValues();
static int SaveValues();
static int GetMagicValue(string varName, string& value);
static int GetMagicValue(string varName, string& value);
private:
static void sanitize_device_id(char* device_id);
......
This diff is collapsed.
......@@ -28,109 +28,109 @@ extern "C" {
GUIAnimation::GUIAnimation(xml_node<>* node)
{
xml_node<>* child;
xml_attribute<>* attr;
mAnimation = NULL;
mFrame = 1;
mFPS = 1;
mLoop = -1;
mRender = 1;
mUpdateCount = 0;
if (!node) return;
child = node->first_node("resource");
if (child)
{
attr = child->first_attribute("name");
if (attr)
mAnimation = (AnimationResource*) PageManager::FindResource(attr->value());
}
// Load the placement
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
child = node->first_node("speed");
if (child)
{
attr = child->first_attribute("fps");
if (attr)
mFPS = atoi(attr->value());
attr = child->first_attribute("render");
if (attr)
mRender = atoi(attr->value());
}
if (mFPS > 30) mFPS = 30;
child = node->first_node("loop");
if (child)
{
attr = child->first_attribute("frame");
if (attr)
mLoop = atoi(attr->value()) - 1;
attr = child->first_attribute("start");
if (attr)
mFrame = atoi(attr->value());
}
// Fetch the render sizes
if (mAnimation && mAnimation->GetResource())
{
mRenderW = gr_get_width(mAnimation->GetResource());
mRenderH = gr_get_height(mAnimation->GetResource());
// Adjust for placement
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
{
if (mPlacement == CENTER)
mRenderX -= (mRenderW / 2);
else
mRenderX -= mRenderW;
}
if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
{
if (mPlacement == CENTER)
mRenderY -= (mRenderH / 2);
else
mRenderY -= mRenderH;
}
SetPlacement(TOP_LEFT);
}
xml_node<>* child;
xml_attribute<>* attr;
mAnimation = NULL;
mFrame = 1;
mFPS = 1;
mLoop = -1;
mRender = 1;
mUpdateCount = 0;
if (!node) return;
child = node->first_node("resource");
if (child)
{
attr = child->first_attribute("name");
if (attr)
mAnimation = (AnimationResource*) PageManager::FindResource(attr->value());
}
// Load the placement
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
child = node->first_node("speed");
if (child)
{
attr = child->first_attribute("fps");
if (attr)
mFPS = atoi(attr->value());
attr = child->first_attribute("render");
if (attr)
mRender = atoi(attr->value());
}
if (mFPS > 30) mFPS = 30;
child = node->first_node("loop");
if (child)
{
attr = child->first_attribute("frame");
if (attr)
mLoop = atoi(attr->value()) - 1;
attr = child->first_attribute("start");
if (attr)
mFrame = atoi(attr->value());
}
// Fetch the render sizes
if (mAnimation && mAnimation->GetResource())
{
mRenderW = gr_get_width(mAnimation->GetResource());
mRenderH = gr_get_height(mAnimation->GetResource());
// Adjust for placement
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
{
if (mPlacement == CENTER)
mRenderX -= (mRenderW / 2);
else
mRenderX -= mRenderW;
}
if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
{
if (mPlacement == CENTER)
mRenderY -= (mRenderH / 2);
else
mRenderY -= mRenderH;
}
SetPlacement(TOP_LEFT);
}
}
int GUIAnimation::Render(void)
{
if (!mAnimation || !mAnimation->GetResource(mFrame)) return -1;
if (!mAnimation || !mAnimation->GetResource(mFrame)) return -1;
gr_blit(mAnimation->GetResource(mFrame), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
return 0;
gr_blit(mAnimation->GetResource(mFrame), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
return 0;
}
int GUIAnimation::Update(void)
{
if (!mAnimation) return -1;
// Handle the "end-of-animation" state
if (mLoop == -2) return 0;
// Determine if we need the next frame yet...
if (++mUpdateCount > 30 / mFPS)
{
mUpdateCount = 0;
if (++mFrame >= mAnimation->GetResourceCount())
{
if (mLoop < 0)
{
mFrame = mAnimation->GetResourceCount() - 1;
mLoop = -2;
}
else
mFrame = mLoop;
}
if (mRender == 2) return 2;
return (Render() == 0 ? 1 : -1);
}
return 0;
if (!mAnimation) return -1;
// Handle the "end-of-animation" state
if (mLoop == -2) return 0;
// Determine if we need the next frame yet...
if (++mUpdateCount > 30 / mFPS)
{
mUpdateCount = 0;
if (++mFrame >= mAnimation->GetResourceCount())
{
if (mLoop < 0)
{
mFrame = mAnimation->GetResourceCount() - 1;
mLoop = -2;
}
else
mFrame = mLoop;
}
if (mRender == 2) return 2;
return (Render() == 0 ? 1 : -1);
}
return 0;
}
......@@ -24,31 +24,35 @@
using namespace std;
class blanktimer {
public:
blanktimer(void);
int setTimerThread(void);
void resetTimerAndUnblank(void);
void setTime(int newtime);
bool IsScreenOff();
private:
void setConBlank(int blank);
void setTimer(void);
timespec getTimer(void);
int getBrightness(void);
int setBrightness(int brightness);
int setBlankTimer(void);
int setClockTimer(void);
typedef int (blanktimer::*ThreadPtr)(void);
typedef void* (*PThreadPtr)(void*);
pthread_mutex_t conblankmutex;
pthread_mutex_t timermutex;
int conblank;
timespec btimer;
unsigned long long sleepTimer;
int orig_brightness;
bool screenoff;
class blanktimer
{
public:
blanktimer(void);
int setTimerThread(void);
void resetTimerAndUnblank(void);
void setTime(int newtime);
bool IsScreenOff();
private:
typedef int (blanktimer::*ThreadPtr)(void);
typedef void* (*PThreadPtr)(void*);
void setConBlank(int blank);
void setTimer(void);
timespec getTimer(void);
int getBrightness(void);
int setBrightness(int brightness);
int setBlankTimer(void);
int setClockTimer(void);
pthread_mutex_t conblankmutex;
pthread_mutex_t timermutex;
int conblank;
timespec btimer;
unsigned long long sleepTimer;
int orig_brightness;
bool screenoff;
};
extern blanktimer blankTimer;
......
......@@ -42,42 +42,42 @@ extern "C" {
#include "objects.hpp"
GUIButton::GUIButton(xml_node<>* node)
: Conditional(node)
: Conditional(node)
{
xml_attribute<>* attr;
xml_node<>* child;
xml_attribute<>* attr;
xml_node<>* child;
mButtonImg = NULL;
mButtonIcon = NULL;
mButtonLabel = NULL;
mAction = NULL;
mRendered = false;
mButtonImg = NULL;
mButtonIcon = NULL;
mButtonLabel = NULL;
mAction = NULL;
mRendered = false;
hasHighlightColor = false;
renderHighlight = false;
hasFill = false;
if (!node) return;
if (!node) return;
// Three of the four can be loaded directly from the node
mButtonImg = new GUIImage(node);
mButtonLabel = new GUIText(node);
mAction = new GUIAction(node);
// Three of the four can be loaded directly from the node
mButtonImg = new GUIImage(node);
mButtonLabel = new GUIText(node);
mAction = new GUIAction(node);
if (mButtonImg->Render() < 0)
{
delete mButtonImg;
mButtonImg = NULL;
}
if (mButtonLabel->Render() < 0)
{
delete mButtonLabel;
mButtonLabel = NULL;
}
if (mButtonImg->Render() < 0)
{
delete mButtonImg;
mButtonImg = NULL;
}
if (mButtonLabel->Render() < 0)
{
delete mButtonLabel;
mButtonLabel = NULL;
}
// Load fill if it exists
memset(&mFillColor, 0, sizeof(COLOR));
child = node->first_node("fill");
if (child)
{
if (child)
{
attr = child->first_attribute("color");
if (attr) {
hasFill = true;
......@@ -89,14 +89,14 @@ GUIButton::GUIButton(xml_node<>* node)
LOGERR("No image resource or fill specified for button.\n");
}
// The icon is a special case
child = node->first_node("icon");
if (child)
{
attr = child->first_attribute("resource");
if (attr)
mButtonIcon = PageManager::FindResource(attr->value());
}
// The icon is a special case
child = node->first_node("icon");
if (child)
{
attr = child->first_attribute("resource");
if (attr)
mButtonIcon = PageManager::FindResource(attr->value());
}
memset(&mHighlightColor, 0, sizeof(COLOR));
child = node->first_node("highlight");
......@@ -109,43 +109,43 @@ GUIButton::GUIButton(xml_node<>* node)
}
}
int x, y, w, h;
if (mButtonImg) {
int x, y, w, h;
if (mButtonImg) {
mButtonImg->GetRenderPos(x, y, w, h);
} else if (hasFill) {
LoadPlacement(node->first_node("placement"), &x, &y, &w, &h);
}
SetRenderPos(x, y, w, h);
return;
return;
}
GUIButton::~GUIButton()
{
if (mButtonImg) delete mButtonImg;
if (mButtonLabel) delete mButtonLabel;
if (mAction) delete mAction;
if (mButtonIcon) delete mButtonIcon;
if (mButtonImg) delete mButtonImg;
if (mButtonLabel) delete mButtonLabel;
if (mAction) delete mAction;
if (mButtonIcon) delete mButtonIcon;
}
int GUIButton::Render(void)
{
if (!isConditionTrue())
{
mRendered = false;
return 0;
}
if (!isConditionTrue())
{
mRendered = false;
return 0;
}
int ret = 0;
int ret = 0;
if (mButtonImg) ret = mButtonImg->Render();
if (ret < 0) return ret;
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) {
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) {
......@@ -163,109 +163,109 @@ int GUIButton::Render(void)
mButtonLabel->SetRenderPos(mTextX, mTextY);
}
ret = mButtonLabel->Render();
if (ret < 0) return ret;
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;
mRendered = true;
return ret;
}
int GUIButton::Update(void)
{
if (!isConditionTrue()) return (mRendered ? 2 : 0);
if (!mRendered) return 2;
if (!isConditionTrue()) return (mRendered ? 2 : 0);
if (!mRendered) return 2;
int ret = 0, ret2 = 0;
int ret = 0, ret2 = 0;
if (mButtonImg) ret = mButtonImg->Update();
if (ret < 0) return ret;
if (mButtonImg) ret = mButtonImg->Update();
if (ret < 0) return ret;
if (ret == 0)
{
if (mButtonLabel) {
if (ret == 0)
{
if (mButtonLabel) {
ret2 = mButtonLabel->Update();
if (ret2 < 0) return ret2;
if (ret2 > ret) ret = ret2;
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;
}
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 GUIButton::SetRenderPos(int x, int y, int w, int h)
{
mRenderX = x;
mRenderY = y;
if (w || h)
{
mRenderW = w;
mRenderH = h;
}
mRenderX = x;
mRenderY = y;
if (w || h)
{
mRenderW = w;
mRenderH = h;
}
mIconW = 0; mIconH = 0;
if (mButtonIcon && mButtonIcon->GetResource())
{
mIconW = gr_get_width(mButtonIcon->GetResource());
mIconH = gr_get_height(mButtonIcon->GetResource());
}
mIconW = 0; mIconH = 0;
if (mButtonIcon && mButtonIcon->GetResource())
{
mIconW = gr_get_width(mButtonIcon->GetResource());
mIconH = gr_get_height(mButtonIcon->GetResource());
}
mTextH = 0;
mTextW = 0;
mIconX = mRenderX + ((mRenderW - mIconW) / 2);
if (mButtonLabel) mButtonLabel->GetCurrentBounds(mTextW, mTextH);
if (mTextW)
{
// As a special case, we'll allow large text which automatically moves it to the right.
if (mTextW > mRenderW)
{
mTextX = mRenderW + mRenderX + 5;
mRenderW += mTextW + 5;
}
else
{
mTextX = mRenderX + ((mRenderW - mTextW) / 2);
}
}
mTextH = 0;
mTextW = 0;
mIconX = mRenderX + ((mRenderW - mIconW) / 2);
if (mButtonLabel) mButtonLabel->GetCurrentBounds(mTextW, mTextH);
if (mTextW)
{
// As a special case, we'll allow large text which automatically moves it to the right.
if (mTextW > mRenderW)
{
mTextX = mRenderW + mRenderX + 5;
mRenderW += mTextW + 5;
}
else
{
mTextX = mRenderX + ((mRenderW - mTextW) / 2);
}
}
if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH)
{
mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2);
mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2);
}
else
{
int divisor = mRenderH - (mIconH + mTextH);
mIconY = mRenderY + (divisor / 3);
mTextY = mRenderY + (divisor * 2 / 3) + mIconH;
}
if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH)
{
mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2);
mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2);
}
else
{
int divisor = mRenderH - (mIconH + mTextH);
mIconY = mRenderY + (divisor / 3);
mTextY = mRenderY + (divisor * 2 / 3) + mIconH;
}
if (mButtonLabel) mButtonLabel->SetRenderPos(mTextX, mTextY);
if (mAction) mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);