1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SkImageView_DEFINED 18 #define SkImageView_DEFINED 19 20 #include "SkView.h" 21 #include "SkString.h" 22 23 class SkAnimator; 24 class SkBitmap; 25 class SkMatrix; 26 27 class SkImageView : public SkView { 28 public: 29 SkImageView(); 30 virtual ~SkImageView(); 31 32 void getUri(SkString*) const; 33 void setUri(const char []); 34 void setUri(const SkString&); 35 36 37 enum ScaleType { 38 kMatrix_ScaleType, 39 kFitXY_ScaleType, 40 kFitStart_ScaleType, 41 kFitCenter_ScaleType, 42 kFitEnd_ScaleType 43 }; 44 ScaleType getScaleType() const { return (ScaleType)fScaleType; } 45 void setScaleType(ScaleType); 46 47 bool getImageMatrix(SkMatrix*) const; 48 void setImageMatrix(const SkMatrix*); 49 50 protected: 51 // overrides 52 virtual bool onEvent(const SkEvent&); 53 virtual void onDraw(SkCanvas*); 54 virtual void onInflate(const SkDOM&, const SkDOMNode*); 55 56 private: 57 SkString fUri; 58 SkMatrix* fMatrix; // null or copy of caller's matrix ,,,,, 59 union { 60 SkAnimator* fAnim; 61 SkBitmap* fBitmap; 62 } fData; 63 uint8_t fScaleType; 64 SkBool8 fDataIsAnim; // as opposed to bitmap 65 SkBool8 fUriIsValid; 66 67 void onUriChange(); 68 bool getDataBounds(SkRect* bounds); 69 bool freeData(); 70 bool ensureUriIsLoaded(); 71 72 typedef SkView INHERITED; 73 }; 74 75 #endif 76