00001 /* 00002 * Copyright (C) 2006 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SkImageView_DEFINED 00018 #define SkImageView_DEFINED 00019 00020 #include "SkView.h" 00021 #include "SkString.h" 00022 00023 class SkAnimator; 00024 class SkBitmap; 00025 struct SkMatrix; 00026 00027 class SkImageView : public SkView { 00028 public: 00029 SkImageView(); 00030 virtual ~SkImageView(); 00031 00032 void getUri(SkString*) const; 00033 void setUri(const char []); 00034 void setUri(const SkString&); 00035 00036 00037 enum ScaleType { 00038 kMatrix_ScaleType, 00039 kFitXY_ScaleType, 00040 kFitStart_ScaleType, 00041 kFitCenter_ScaleType, 00042 kFitEnd_ScaleType 00043 }; 00044 ScaleType getScaleType() const { return (ScaleType)fScaleType; } 00045 void setScaleType(ScaleType); 00046 00047 bool getImageMatrix(SkMatrix*) const; 00048 void setImageMatrix(const SkMatrix*); 00049 00050 protected: 00051 // overrides 00052 virtual bool onEvent(const SkEvent&); 00053 virtual void onDraw(SkCanvas*); 00054 virtual void onInflate(const SkDOM&, const SkDOMNode*); 00055 00056 private: 00057 SkString fUri; 00058 SkMatrix* fMatrix; // null or copy of caller's matrix ,,,,, 00059 union { 00060 SkAnimator* fAnim; 00061 SkBitmap* fBitmap; 00062 } fData; 00063 uint8_t fScaleType; 00064 SkBool8 fDataIsAnim; // as opposed to bitmap 00065 SkBool8 fUriIsValid; 00066 00067 void onUriChange(); 00068 bool getDataBounds(SkRect* bounds); 00069 bool freeData(); 00070 bool ensureUriIsLoaded(); 00071 00072 typedef SkView INHERITED; 00073 }; 00074 00075 #endif