reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | #include "SkBorderView.h" |
| 2 | #include "SkAnimator.h" |
| 3 | #include "SkWidgetViews.h" |
| 4 | #include "SkSystemEventTypes.h" |
| 5 | #include "SkTime.h" |
| 6 | #include "SkStackViewLayout.h" |
| 7 | |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 8 | SkBorderView::SkBorderView() : fLeft(SkIntToScalar(0)), |
| 9 | fRight(SkIntToScalar(0)), |
| 10 | fTop(SkIntToScalar(0)), |
| 11 | fBottom(SkIntToScalar(0)) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | { |
| 13 | fAnim.setHostEventSink(this); |
| 14 | init_skin_anim(kBorder_SkinEnum, &fAnim); |
| 15 | } |
| 16 | |
| 17 | SkBorderView::~SkBorderView() |
| 18 | { |
| 19 | |
| 20 | } |
| 21 | |
| 22 | void SkBorderView::setSkin(const char skin[]) |
| 23 | { |
| 24 | init_skin_anim(skin, &fAnim); |
| 25 | } |
| 26 | |
| 27 | /* virtual */ void SkBorderView::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
| 28 | { |
| 29 | this->INHERITED::onInflate(dom, node); |
| 30 | } |
| 31 | |
| 32 | /*virtual*/ void SkBorderView::onSizeChange() |
| 33 | { |
| 34 | this->INHERITED::onSizeChange(); |
| 35 | SkEvent evt("user"); |
| 36 | evt.setString("id", "setDim"); |
| 37 | evt.setScalar("dimX", this->width()); |
| 38 | evt.setScalar("dimY", this->height()); |
| 39 | fAnim.doUserEvent(evt); |
| 40 | } |
| 41 | |
| 42 | /*virtual*/ void SkBorderView::onDraw(SkCanvas* canvas) |
| 43 | { |
| 44 | SkPaint paint; |
| 45 | SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs()); |
| 46 | |
| 47 | if (diff == SkAnimator::kDifferent) |
deanm@chromium.org | 1599a43 | 2009-06-04 15:37:11 +0000 | [diff] [blame] | 48 | this->inval(NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | else if (diff == SkAnimator::kPartiallyDifferent) |
| 50 | { |
| 51 | SkRect bounds; |
| 52 | fAnim.getInvalBounds(&bounds); |
| 53 | this->inval(&bounds); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /*virtual*/ bool SkBorderView::onEvent(const SkEvent& evt) |
| 58 | { |
| 59 | if (evt.isType(SK_EventType_Inval)) |
| 60 | { |
deanm@chromium.org | 1599a43 | 2009-06-04 15:37:11 +0000 | [diff] [blame] | 61 | this->inval(NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | return true; |
| 63 | } |
| 64 | if (evt.isType("recommendDim")) |
| 65 | { |
| 66 | evt.findScalar("leftMargin", &fLeft); |
| 67 | evt.findScalar("rightMargin", &fRight); |
| 68 | evt.findScalar("topMargin", &fTop); |
| 69 | evt.findScalar("bottomMargin", &fBottom); |
| 70 | |
| 71 | //setup_views.cpp uses SkView::Layout instead of SkStackViewLayout |
| 72 | //but that gives me an error |
| 73 | SkStackViewLayout* layout; |
| 74 | fMargin.set(fLeft, fTop, fRight, fBottom); |
| 75 | if (this->getLayout()) |
| 76 | { |
| 77 | layout = (SkStackViewLayout*)this->getLayout(); |
| 78 | layout->setMargin(fMargin); |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | layout = new SkStackViewLayout; |
| 83 | layout->setMargin(fMargin); |
| 84 | this->setLayout(layout)->unref(); |
| 85 | } |
| 86 | this->invokeLayout(); |
| 87 | } |
| 88 | return this->INHERITED::onEvent(evt); |
| 89 | } |