mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-24 11:23:36 +00:00
94 lines
2.9 KiB
C++
94 lines
2.9 KiB
C++
#include "UIControl_Progress.h"
|
|
|
|
#include "app/common/UI/Controls/UIControl.h"
|
|
#include "app/common/UI/Controls/UIControl_Base.h"
|
|
#include "app/common/UI/UIScene.h"
|
|
#include "app/common/UI/UIString.h"
|
|
#include "app/linux/Iggy/include/iggy.h"
|
|
#ifndef _ENABLEIGGY
|
|
#include "app/linux/Stubs/iggy_stubs.h"
|
|
#endif
|
|
#include "util/StringHelpers.h"
|
|
|
|
UIControl_Progress::UIControl_Progress() {
|
|
m_min = 0;
|
|
m_max = 100;
|
|
m_current = 0;
|
|
m_lastPercent = 0.0f;
|
|
m_showingBar = true;
|
|
}
|
|
|
|
bool UIControl_Progress::setupControl(UIScene* scene, IggyValuePath* parent,
|
|
const std::string& controlName) {
|
|
UIControl::setControlType(UIControl::eProgress);
|
|
bool success = UIControl_Base::setupControl(scene, parent, controlName);
|
|
|
|
// Progress specific initialisers
|
|
m_setProgressFunc = registerFastName("setProgress");
|
|
m_showBarFunc = registerFastName("ShowBar");
|
|
|
|
return success;
|
|
}
|
|
|
|
void UIControl_Progress::init(UIString label, int id, int min, int max,
|
|
int current) {
|
|
m_label = label;
|
|
m_id = id;
|
|
m_min = min;
|
|
m_max = max;
|
|
m_current = current;
|
|
|
|
IggyDataValue result;
|
|
IggyDataValue value[1];
|
|
value[0].type = IGGY_DATATYPE_string_UTF8;
|
|
IggyStringUTF8 stringVal;
|
|
|
|
stringVal.string = const_cast<char*>(label.getString().c_str());
|
|
stringVal.length = label.getString().length();
|
|
value[0].string8 = stringVal;
|
|
|
|
IggyResult out =
|
|
IggyPlayerCallMethodRS(m_parentScene->getMovie(), &result,
|
|
getIggyValuePath(), m_initFunc, 1, value);
|
|
}
|
|
|
|
void UIControl_Progress::ReInit() {
|
|
UIControl_Base::ReInit();
|
|
init(m_label, m_id, m_min, m_max, m_current);
|
|
}
|
|
|
|
void UIControl_Progress::setProgress(int current) {
|
|
m_current = current;
|
|
|
|
float percent = (float)((m_current - m_min)) / (m_max - m_min);
|
|
|
|
if (percent != m_lastPercent) {
|
|
m_lastPercent = percent;
|
|
// app.DebugPrintf("Setting progress value to %d/%f\n", m_current,
|
|
// percent);
|
|
|
|
IggyDataValue result;
|
|
IggyDataValue value[1];
|
|
value[0].type = IGGY_DATATYPE_number;
|
|
value[0].number = percent;
|
|
IggyResult out = IggyPlayerCallMethodRS(m_parentScene->getMovie(),
|
|
&result, getIggyValuePath(),
|
|
m_setProgressFunc, 1, value);
|
|
}
|
|
}
|
|
|
|
void UIControl_Progress::showBar(bool show) {
|
|
if (show != m_showingBar) {
|
|
m_showingBar = show;
|
|
// app.DebugPrintf("Setting progress value to %d/%f\n", m_current,
|
|
// percent);
|
|
|
|
IggyDataValue result;
|
|
IggyDataValue value[1];
|
|
value[0].type = IGGY_DATATYPE_boolean;
|
|
value[0].boolval = show;
|
|
IggyResult out =
|
|
IggyPlayerCallMethodRS(m_parentScene->getMovie(), &result,
|
|
getIggyValuePath(), m_showBarFunc, 1, value);
|
|
}
|
|
} |