mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
[escher] Rework of timers and bigger text in toolboxes
This commit is contained in:
15
escher/src/animation_timer.cpp
Normal file
15
escher/src/animation_timer.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <apps/apps_container.h>
|
||||
#include <escher/animation_timer.h>
|
||||
|
||||
|
||||
void AnimationTimer::setAnimated(Animated * animated) {
|
||||
m_animated = animated;
|
||||
AppsContainer::sharedAppsContainer()->addTimer(this);
|
||||
}
|
||||
|
||||
void AnimationTimer::removeAnimated(Animated * animated) {
|
||||
if (m_animated == animated || animated == nullptr) {
|
||||
m_animated = nullptr;
|
||||
AppsContainer::sharedAppsContainer()->removeTimer(this);
|
||||
}
|
||||
}
|
||||
@@ -55,23 +55,3 @@ void Container::run() {
|
||||
window()->redraw();
|
||||
RunLoop::run();
|
||||
}
|
||||
|
||||
int Container::numberOfTimers() {
|
||||
return s_activeApp->numberOfTimers() + numberOfContainerTimers();
|
||||
}
|
||||
|
||||
Timer * Container::timerAtIndex(int i) {
|
||||
if (i < s_activeApp->numberOfTimers()) {
|
||||
return s_activeApp->timerAtIndex(i);
|
||||
}
|
||||
return containerTimerAtIndex(i-s_activeApp->numberOfTimers());
|
||||
}
|
||||
|
||||
int Container::numberOfContainerTimers() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Timer * Container::containerTimerAtIndex(int i) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -1,39 +1,65 @@
|
||||
#include <escher/message_table_cell.h>
|
||||
#include <escher/palette.h>
|
||||
#include <escher/slideable_message_text_view.h>
|
||||
#include <assert.h>
|
||||
|
||||
MessageTableCell::MessageTableCell(I18n::Message label, const KDFont * font, Layout layout) :
|
||||
template<class T>
|
||||
MessageTableCell<T>::MessageTableCell(I18n::Message label, const KDFont * font, Layout layout) :
|
||||
TableCell(layout),
|
||||
m_messageTextView(font, label, 0, 0.5, Palette::PrimaryText, Palette::ListCellBackground),
|
||||
m_backgroundColor(KDColorWhite)
|
||||
{
|
||||
}
|
||||
|
||||
View * MessageTableCell::labelView() const {
|
||||
template<class T>
|
||||
View * MessageTableCell<T>::labelView() const {
|
||||
return (View *)&m_messageTextView;
|
||||
}
|
||||
|
||||
void MessageTableCell::setHighlighted(bool highlight) {
|
||||
template<>
|
||||
void MessageTableCell<SlideableMessageTextView>::setHighlighted(bool highlight) {
|
||||
HighlightCell::setHighlighted(highlight);
|
||||
KDColor backgroundColor = highlight? Palette::ListCellBackgroundSelected : Palette::ListCellBackground;
|
||||
m_messageTextView.setBackgroundColor(backgroundColor);
|
||||
static AnimationTimer s_animationTimer = AnimationTimer();
|
||||
if (highlight) {
|
||||
m_messageTextView.willStartAnimation();
|
||||
s_animationTimer.setAnimated(&m_messageTextView);
|
||||
} else {
|
||||
s_animationTimer.removeAnimated(&m_messageTextView);
|
||||
m_messageTextView.didStopAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void MessageTableCell<MessageTextView>::setHighlighted(bool highlight) {
|
||||
HighlightCell::setHighlighted(highlight);
|
||||
KDColor backgroundColor = highlight? Palette::ListCellBackgroundSelected : Palette::ListCellBackground;
|
||||
m_messageTextView.setBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
void MessageTableCell::setMessage(I18n::Message text) {
|
||||
template<class T>
|
||||
void MessageTableCell<T>::setMessage(I18n::Message text) {
|
||||
m_messageTextView.setMessage(text);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
void MessageTableCell::setTextColor(KDColor color) {
|
||||
template<class T>
|
||||
void MessageTableCell<T>::setTextColor(KDColor color) {
|
||||
m_messageTextView.setTextColor(color);
|
||||
}
|
||||
|
||||
void MessageTableCell::setMessageFont(const KDFont * font) {
|
||||
template<class T>
|
||||
void MessageTableCell<T>::setMessageFont(const KDFont * font) {
|
||||
m_messageTextView.setFont(font);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
void MessageTableCell::setBackgroundColor(KDColor color) {
|
||||
template<class T>
|
||||
void MessageTableCell<T>::setBackgroundColor(KDColor color) {
|
||||
m_backgroundColor = color;
|
||||
m_messageTextView.setBackgroundColor(color);
|
||||
}
|
||||
|
||||
template class MessageTableCell<MessageTextView>;
|
||||
template class MessageTableCell<SlideableMessageTextView>;
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
#include <escher/message_table_cell_with_chevron.h>
|
||||
|
||||
MessageTableCellWithChevron::MessageTableCellWithChevron(I18n::Message message, const KDFont * font) :
|
||||
MessageTableCell(message, font),
|
||||
template<>
|
||||
MessageTableCellWithChevron<MessageTextView>::MessageTableCellWithChevron(I18n::Message message, const KDFont * font) :
|
||||
MessageTableCell<MessageTextView>(message, font),
|
||||
m_accessoryView()
|
||||
{
|
||||
}
|
||||
|
||||
View * MessageTableCellWithChevron::accessoryView() const {
|
||||
template<>
|
||||
MessageTableCellWithChevron<SlideableMessageTextView>::MessageTableCellWithChevron(I18n::Message message, const KDFont * font) :
|
||||
MessageTableCell<SlideableMessageTextView>(message, font,TableCell::Layout::HorizontalRightOverlap),
|
||||
m_accessoryView()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
View * MessageTableCellWithChevron<T>::accessoryView() const {
|
||||
return (View *)&m_accessoryView;
|
||||
}
|
||||
|
||||
template class MessageTableCellWithChevron<MessageTextView>;
|
||||
template class MessageTableCellWithChevron<SlideableMessageTextView>;
|
||||
|
||||
|
||||
@@ -2,38 +2,47 @@
|
||||
#include <escher/palette.h>
|
||||
#include <string.h>
|
||||
|
||||
MessageTableCellWithMessage::MessageTableCellWithMessage(I18n::Message message, Layout layout) :
|
||||
MessageTableCell(message, KDFont::SmallFont, layout),
|
||||
template <class T>
|
||||
MessageTableCellWithMessage<T>::MessageTableCellWithMessage(I18n::Message message, TableCell::Layout layout) :
|
||||
MessageTableCell<T>(message, KDFont::SmallFont, layout),
|
||||
m_accessoryView(KDFont::SmallFont, (I18n::Message)0, 0.0f, 0.5f)
|
||||
{
|
||||
if (layout != Layout::Vertical) {
|
||||
if (layout != TableCell::Layout::Vertical) {
|
||||
m_accessoryView.setAlignment(1.0f, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageTableCellWithMessage::setAccessoryMessage(I18n::Message textBody) {
|
||||
template <class T>
|
||||
void MessageTableCellWithMessage<T>::setAccessoryMessage(I18n::Message textBody) {
|
||||
m_accessoryView.setMessage(textBody);
|
||||
reloadCell();
|
||||
this->reloadCell();
|
||||
}
|
||||
|
||||
View * MessageTableCellWithMessage::accessoryView() const {
|
||||
template <class T>
|
||||
View * MessageTableCellWithMessage<T>::accessoryView() const {
|
||||
if (strlen(m_accessoryView.text()) == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return (View *)&m_accessoryView;
|
||||
}
|
||||
|
||||
void MessageTableCellWithMessage::setHighlighted(bool highlight) {
|
||||
MessageTableCell::setHighlighted(highlight);
|
||||
KDColor backgroundColor = isHighlighted()? Palette::ListCellBackgroundSelected : Palette::ListCellBackground;
|
||||
template <class T>
|
||||
void MessageTableCellWithMessage<T>::setHighlighted(bool highlight) {
|
||||
MessageTableCell<T>::setHighlighted(highlight);
|
||||
KDColor backgroundColor = this->isHighlighted()? Palette::ListCellBackgroundSelected : Palette::ListCellBackground;
|
||||
m_accessoryView.setBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
void MessageTableCellWithMessage::setTextColor(KDColor color) {
|
||||
template <class T>
|
||||
void MessageTableCellWithMessage<T>::setTextColor(KDColor color) {
|
||||
m_accessoryView.setTextColor(color);
|
||||
MessageTableCell::setTextColor(color);
|
||||
MessageTableCell<T>::setTextColor(color);
|
||||
}
|
||||
|
||||
void MessageTableCellWithMessage::setAccessoryTextColor(KDColor color) {
|
||||
template <class T>
|
||||
void MessageTableCellWithMessage<T>::setAccessoryTextColor(KDColor color) {
|
||||
m_accessoryView.setTextColor(color);
|
||||
}
|
||||
|
||||
template class MessageTableCellWithMessage<MessageTextView>;
|
||||
template class MessageTableCellWithMessage<SlideableMessageTextView>;
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
#include <assert.h>
|
||||
|
||||
RunLoop::RunLoop() :
|
||||
m_time(0) {
|
||||
}
|
||||
|
||||
int RunLoop::numberOfTimers() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Timer * RunLoop::timerAtIndex(int i) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
m_time(0),
|
||||
m_firstTimer(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void RunLoop::run() {
|
||||
@@ -45,11 +38,12 @@ bool RunLoop::step() {
|
||||
|
||||
if (m_time >= Timer::TickDuration) {
|
||||
m_time -= Timer::TickDuration;
|
||||
for (int i=0; i<numberOfTimers(); i++) {
|
||||
Timer * timer = timerAtIndex(i);
|
||||
Timer * timer = m_firstTimer;
|
||||
while (timer) {
|
||||
if (timer->tick()) {
|
||||
dispatchEvent(Ion::Events::TimerFire);
|
||||
}
|
||||
timer = timer->next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +59,7 @@ bool RunLoop::step() {
|
||||
#endif
|
||||
|
||||
if (event != Ion::Events::None) {
|
||||
#if !PLATFORM_DEVICE
|
||||
#if !PLATFORM_DEVICEdidStopAnimation
|
||||
if (event == Ion::Events::ExternalText && !KDFont::CanBeWrittenWithGlyphs(event.text())) {
|
||||
return true;
|
||||
}
|
||||
@@ -75,3 +69,27 @@ bool RunLoop::step() {
|
||||
|
||||
return event != Ion::Events::Termination;
|
||||
}
|
||||
|
||||
void RunLoop::addTimer(Timer * timer) {
|
||||
if (m_firstTimer == nullptr) {
|
||||
m_firstTimer = timer;
|
||||
} else {
|
||||
Timer * actual = m_firstTimer;
|
||||
while (actual->next()) {
|
||||
actual = actual->next();
|
||||
}
|
||||
actual->setNext(timer);
|
||||
}
|
||||
}
|
||||
|
||||
void RunLoop::removeTimer(Timer * timer) {
|
||||
if (m_firstTimer == timer) {
|
||||
m_firstTimer = timer->next();
|
||||
} else {
|
||||
Timer * actual = m_firstTimer;
|
||||
while (actual->next() != timer) {
|
||||
actual = actual->next();
|
||||
}
|
||||
actual->setNext(timer->next());
|
||||
}
|
||||
}
|
||||
|
||||
63
escher/src/slideable_message_text_view.cpp
Normal file
63
escher/src/slideable_message_text_view.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <escher/slideable_message_text_view.h>
|
||||
#include <apps/apps_container.h>
|
||||
|
||||
SlideableMessageTextView::SlideableMessageTextView(const KDFont * font, I18n::Message message, float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor backgroundColor) :
|
||||
MessageTextView(font, message, horizontalAlignment, verticalAlignment, textColor, backgroundColor),
|
||||
m_textOffset(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SlideableMessageTextView::willStartAnimation() {
|
||||
m_textOffset = 0;
|
||||
m_goingLeft = true;
|
||||
m_paused = true;
|
||||
}
|
||||
|
||||
void SlideableMessageTextView::didStopAnimation() {
|
||||
m_textOffset = 0;
|
||||
}
|
||||
|
||||
void SlideableMessageTextView::animate() {
|
||||
if (m_paused) {
|
||||
m_paused = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (text() == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
KDSize textSize = m_font->stringSize(text());
|
||||
|
||||
if (textSize.width() <= bounds().width()) {
|
||||
return;
|
||||
}
|
||||
|
||||
KDCoordinate glyphWidth = m_font->glyphSize().width();
|
||||
m_textOffset += glyphWidth * (m_goingLeft ? -1 : 1);
|
||||
|
||||
if (m_goingLeft && textSize.width() + m_textOffset < bounds().width()) {
|
||||
m_goingLeft = false;
|
||||
m_textOffset = bounds().width() - textSize.width();
|
||||
m_paused = true;
|
||||
} else if (!m_goingLeft && m_textOffset > 0) {
|
||||
m_goingLeft = true;
|
||||
m_textOffset = 0;
|
||||
m_paused = true;
|
||||
}
|
||||
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
void SlideableMessageTextView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
if (text() == nullptr) {
|
||||
return;
|
||||
}
|
||||
KDSize textSize = m_font->stringSize(text());
|
||||
KDPoint origin(
|
||||
m_horizontalAlignment * (m_frame.width() - textSize.width()) + m_textOffset,
|
||||
m_verticalAlignment * (m_frame.height() - textSize.height()));
|
||||
ctx->fillRect(bounds(), m_backgroundColor);
|
||||
ctx->drawString(text(), origin, m_font, m_textColor, m_backgroundColor);
|
||||
}
|
||||
@@ -27,15 +27,16 @@ int Toolbox::reusableCellCount(int type) {
|
||||
void Toolbox::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
ToolboxMessageTree * messageTree = (ToolboxMessageTree *)m_messageTreeModel->childAtIndex(index);
|
||||
if (messageTree->numberOfChildren() == 0) {
|
||||
MessageTableCellWithMessage * myCell = (MessageTableCellWithMessage *)cell;
|
||||
MessageTableCellWithMessage<SlideableMessageTextView> * myCell = (MessageTableCellWithMessage<SlideableMessageTextView> *)cell;
|
||||
myCell->setMessage(messageTree->label());
|
||||
myCell->setAccessoryMessage(messageTree->text());
|
||||
myCell->setAccessoryTextColor(Palette::SecondaryText);
|
||||
return;
|
||||
} else {
|
||||
MessageTableCell<> * myCell = (MessageTableCell<> *)cell;
|
||||
myCell->setMessage(messageTree->label());
|
||||
myCell->reloadCell();
|
||||
}
|
||||
MessageTableCell * myCell = (MessageTableCell *)cell;
|
||||
myCell->setMessage(messageTree->label());
|
||||
myCell->reloadCell();
|
||||
}
|
||||
|
||||
int Toolbox::typeAtLocation(int i, int j) {
|
||||
|
||||
Reference in New Issue
Block a user