1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/views/animated/SkBorderView.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 +#include "SkBorderView.h" 1.12 +#include "SkAnimator.h" 1.13 +#include "SkWidgetViews.h" 1.14 +#include "SkSystemEventTypes.h" 1.15 +#include "SkTime.h" 1.16 +#include "SkStackViewLayout.h" 1.17 + 1.18 +SkBorderView::SkBorderView() : fLeft(SkIntToScalar(0)), 1.19 + fRight(SkIntToScalar(0)), 1.20 + fTop(SkIntToScalar(0)), 1.21 + fBottom(SkIntToScalar(0)) 1.22 +{ 1.23 + fAnim.setHostEventSink(this); 1.24 + init_skin_anim(kBorder_SkinEnum, &fAnim); 1.25 +} 1.26 + 1.27 +SkBorderView::~SkBorderView() 1.28 +{ 1.29 + 1.30 +} 1.31 + 1.32 +void SkBorderView::setSkin(const char skin[]) 1.33 +{ 1.34 + init_skin_anim(skin, &fAnim); 1.35 +} 1.36 + 1.37 +/* virtual */ void SkBorderView::onInflate(const SkDOM& dom, const SkDOM::Node* node) 1.38 +{ 1.39 + this->INHERITED::onInflate(dom, node); 1.40 +} 1.41 + 1.42 +/*virtual*/ void SkBorderView::onSizeChange() 1.43 +{ 1.44 + this->INHERITED::onSizeChange(); 1.45 + SkEvent evt("user"); 1.46 + evt.setString("id", "setDim"); 1.47 + evt.setScalar("dimX", this->width()); 1.48 + evt.setScalar("dimY", this->height()); 1.49 + fAnim.doUserEvent(evt); 1.50 +} 1.51 + 1.52 +/*virtual*/ void SkBorderView::onDraw(SkCanvas* canvas) 1.53 +{ 1.54 + SkPaint paint; 1.55 + SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs()); 1.56 + 1.57 + if (diff == SkAnimator::kDifferent) 1.58 + this->inval(NULL); 1.59 + else if (diff == SkAnimator::kPartiallyDifferent) 1.60 + { 1.61 + SkRect bounds; 1.62 + fAnim.getInvalBounds(&bounds); 1.63 + this->inval(&bounds); 1.64 + } 1.65 +} 1.66 + 1.67 +/*virtual*/ bool SkBorderView::onEvent(const SkEvent& evt) 1.68 +{ 1.69 + if (evt.isType(SK_EventType_Inval)) 1.70 + { 1.71 + this->inval(NULL); 1.72 + return true; 1.73 + } 1.74 + if (evt.isType("recommendDim")) 1.75 + { 1.76 + evt.findScalar("leftMargin", &fLeft); 1.77 + evt.findScalar("rightMargin", &fRight); 1.78 + evt.findScalar("topMargin", &fTop); 1.79 + evt.findScalar("bottomMargin", &fBottom); 1.80 + 1.81 + //setup_views.cpp uses SkView::Layout instead of SkStackViewLayout 1.82 + //but that gives me an error 1.83 + SkStackViewLayout* layout; 1.84 + fMargin.set(fLeft, fTop, fRight, fBottom); 1.85 + if (this->getLayout()) 1.86 + { 1.87 + layout = (SkStackViewLayout*)this->getLayout(); 1.88 + layout->setMargin(fMargin); 1.89 + } 1.90 + else 1.91 + { 1.92 + layout = new SkStackViewLayout; 1.93 + layout->setMargin(fMargin); 1.94 + this->setLayout(layout)->unref(); 1.95 + } 1.96 + this->invokeLayout(); 1.97 + } 1.98 + return this->INHERITED::onEvent(evt); 1.99 +}