diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2008-12-17 15:59:43 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2008-12-17 15:59:43 +0000 |
commit | 8a1c16ff38322f0210116fa7293eb8817c7e477e (patch) | |
tree | fe40e07f6c8983318a2f79032b9a706ede1090c1 /src/views/SkScrollBarView.cpp | |
parent | 2559c629078f738ac37095d896d580b681ac6a30 (diff) |
grab from latest android
git-svn-id: http://skia.googlecode.com/svn/trunk@27 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/views/SkScrollBarView.cpp')
-rw-r--r-- | src/views/SkScrollBarView.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/views/SkScrollBarView.cpp b/src/views/SkScrollBarView.cpp new file mode 100644 index 0000000000..2e087bd1ae --- /dev/null +++ b/src/views/SkScrollBarView.cpp @@ -0,0 +1,139 @@ +#include "SkScrollBarView.h" +#include "SkAnimator.h" +#include "SkWidgetViews.h" +#include "SkSystemEventTypes.h" +#include "SkTime.h" + +//see SkProgressBarView.cpp +//#include "SkWidgetViews.cpp" + +SkScrollBarView::SkScrollBarView() +{ + fAnim.setHostEventSink(this); + init_skin_anim(kScroll_SkinEnum, &fAnim); + + fTotalLength = 0; + fStartPoint = 0; + fShownLength = 0; + + this->adjust(); +} + +void SkScrollBarView::setStart(unsigned start) +{ + if ((int)start < 0) + start = 0; + + if (fStartPoint != start) + { + fStartPoint = start; + this->adjust(); + } +} + +void SkScrollBarView::setShown(unsigned shown) +{ + if ((int)shown < 0) + shown = 0; + + if (fShownLength != shown) + { + fShownLength = shown; + this->adjust(); + } +} + +void SkScrollBarView::setTotal(unsigned total) +{ + if ((int)total < 0) + total = 0; + + if (fTotalLength != total) + { + fTotalLength = total; + this->adjust(); + } +} + +/* virtual */ void SkScrollBarView::onInflate(const SkDOM& dom, const SkDOM::Node* node) +{ + this->INHERITED::onInflate(dom, node); + + int32_t value; + if (dom.findS32(node, "total", &value)) + this->setTotal(value); + if (dom.findS32(node, "shown", &value)) + this->setShown(value); +} + +/*virtual*/ void SkScrollBarView::onSizeChange() +{ + this->INHERITED::onSizeChange(); + SkEvent evt("user"); + evt.setString("id", "setDim"); + evt.setScalar("dimX", this->width()); + evt.setScalar("dimY", this->height()); + fAnim.doUserEvent(evt); +} + +/*virtual*/ void SkScrollBarView::onDraw(SkCanvas* canvas) +{ + SkPaint paint; + SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs()); + + if (diff == SkAnimator::kDifferent) + this->inval(NULL); + else if (diff == SkAnimator::kPartiallyDifferent) + { + SkRect bounds; + fAnim.getInvalBounds(&bounds); + this->inval(&bounds); + } +} + +/*virtual*/ bool SkScrollBarView::onEvent(const SkEvent& evt) +{ + if (evt.isType(SK_EventType_Inval)) + { + this->inval(NULL); + return true; + } + if (evt.isType("recommendDim")) + { + SkScalar width; + + if (evt.findScalar("x", &width)) + this->setWidth(width); + return true; + } + + return this->INHERITED::onEvent(evt); +} + +void SkScrollBarView::adjust() +{ + int total = fTotalLength; + int start = fStartPoint; + int shown = fShownLength; + int hideBar = 0; + + if (total <= 0 || shown <= 0 || shown >= total) // no bar to show + { + total = 1; // avoid divide-by-zero. should be done by skin/script + hideBar = 1; // signal we don't want a thumb + } + else + { + if (start + shown > total) + start = total - shown; + } + + SkEvent e("user"); + e.setString("id", "adjustScrollBar"); + e.setScalar("_totalLength", SkIntToScalar(total)); + e.setScalar("_startPoint", SkIntToScalar(start)); + e.setScalar("_shownLength", SkIntToScalar(shown)); +// e.setS32("hideBar", hideBar); + fAnim.doUserEvent(e); +} + |