summaryrefslogtreecommitdiff
path: root/indra/llui/lltimectrl.cpp
diff options
context:
space:
mode:
authorVadim ProductEngine <vsavchuk@productengine.com>2011-05-30 22:34:56 +0300
committerVadim ProductEngine <vsavchuk@productengine.com>2011-05-30 22:34:56 +0300
commit657e434fd59139436e8b97e5ecd01ca686e82269 (patch)
treebebf0c4c8adff3587cec47f6403757f841f5c872 /indra/llui/lltimectrl.cpp
parent6f1cdd4926444567d21b1d6e0735a445b981e56b (diff)
STORM-1253 WIP New day cycle editor.
Done: * Creating new local day cycles. * Editing existing local day cycles. * Deleting day cycles. To do: * Editing region day cycle, dealing with skies in region scope. * Handle teleport while editing a day cycle. * Update UI when a day cycle or sky preset gets deleted. * Make the time ctrl increase/decrease consistently.
Diffstat (limited to 'indra/llui/lltimectrl.cpp')
-rw-r--r--indra/llui/lltimectrl.cpp86
1 files changed, 76 insertions, 10 deletions
diff --git a/indra/llui/lltimectrl.cpp b/indra/llui/lltimectrl.cpp
index a77842a392..ce376f001d 100644
--- a/indra/llui/lltimectrl.cpp
+++ b/indra/llui/lltimectrl.cpp
@@ -108,7 +108,7 @@ LLTimeCtrl::LLTimeCtrl(const LLTimeCtrl::Params& p)
mEditor = LLUICtrlFactory::create<LLLineEditor> (params);
mEditor->setPrevalidateInput(LLTextValidate::validateNonNegativeS32NoSpace);
mEditor->setPrevalidate(boost::bind(&LLTimeCtrl::isTimeStringValid, this, _1));
- mEditor->setText(LLStringExplicit("0:00 AM"));
+ mEditor->setText(LLStringExplicit("12:00 AM"));
addChild(mEditor);
//================= Spin Buttons ==========//
@@ -130,6 +130,66 @@ LLTimeCtrl::LLTimeCtrl(const LLTimeCtrl::Params& p)
setUseBoundingRect( TRUE );
}
+F32 LLTimeCtrl::getTime24() const
+{
+ return getHours24() + getMinutes() / 60.0f;
+}
+
+U32 LLTimeCtrl::getHours24() const
+{
+ U32 h = mHours;
+
+ if (h == 12)
+ {
+ h = 0;
+ }
+
+ if (mCurrentDayPeriod == PM)
+ {
+ h += 12;
+ }
+
+ return h;
+}
+
+U32 LLTimeCtrl::getMinutes() const
+{
+ return mMinutes;
+}
+
+void LLTimeCtrl::setTime24(F32 time)
+{
+ time = llclamp(time, 0.0f, 23.99f); // fix out of range values
+
+ U32 h = time;
+ U32 m = llround((time - h) * 60); // fixes values like 4.99999
+
+ // fix rounding error
+ if (m == 60)
+ {
+ m = 0;
+ ++h;
+ }
+
+ mCurrentDayPeriod = (h >= 12 ? PM : AM);
+
+ if (h >= 12)
+ {
+ h -= 12;
+ }
+
+ if (h == 0)
+ {
+ h = 12;
+ }
+
+
+ mHours = h;
+ mMinutes = m;
+
+ updateText();
+}
+
BOOL LLTimeCtrl::handleKeyHere(KEY key, MASK mask)
{
if (mEditor->hasFocus())
@@ -144,6 +204,11 @@ BOOL LLTimeCtrl::handleKeyHere(KEY key, MASK mask)
onDownBtn();
return TRUE;
}
+ if (key == KEY_RETURN)
+ {
+ onCommit();
+ return TRUE;
+ }
}
return FALSE;
}
@@ -165,8 +230,8 @@ void LLTimeCtrl::onUpBtn()
break;
}
- buildTimeString();
- mEditor->setText(mTimeString);
+ updateText();
+ onCommit();
}
void LLTimeCtrl::onDownBtn()
@@ -186,15 +251,14 @@ void LLTimeCtrl::onDownBtn()
break;
}
- buildTimeString();
- mEditor->setText(mTimeString);
+ updateText();
+ onCommit();
}
void LLTimeCtrl::onFocusLost()
{
- buildTimeString();
- mEditor->setText(mTimeString);
-
+ updateText();
+ onCommit();
LLUICtrl::onFocusLost();
}
@@ -300,6 +364,7 @@ LLWString LLTimeCtrl::getMinutesWString(const LLWString& wstr)
void LLTimeCtrl::increaseMinutes()
{
+ // *TODO: snap to 5 min
if (++mMinutes > MINUTES_MAX)
{
mMinutes = MINUTES_MIN;
@@ -316,6 +381,7 @@ void LLTimeCtrl::increaseHours()
void LLTimeCtrl::decreaseMinutes()
{
+ // *TODO: snap to 5 min
if (mMinutes-- == MINUTES_MIN)
{
mMinutes = MINUTES_MAX;
@@ -344,7 +410,7 @@ void LLTimeCtrl::switchDayPeriod()
}
}
-void LLTimeCtrl::buildTimeString()
+void LLTimeCtrl::updateText()
{
std::stringstream time_buf;
time_buf << mHours << ":";
@@ -367,7 +433,7 @@ void LLTimeCtrl::buildTimeString()
break;
}
- mTimeString = time_buf.str();
+ mEditor->setText(time_buf.str());
}
LLTimeCtrl::EEditingPart LLTimeCtrl::getEditingPart()