ui_image_view.h 7.5 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @addtogroup UI_Components
 * @{
 *
 * @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
 *
 * @since 1.0
 * @version 1.0
 */

/**
 * @file ui_image_view.h
 *
 * @brief Declares an image view.
 *
 * @since 1.0
 * @version 1.0
 */

#ifndef GRAPHIC_LITE_UI_IMAGE_VIEW_H
#define GRAPHIC_LITE_UI_IMAGE_VIEW_H

#include "common/image.h"
#include "components/ui_view.h"
Z
zhangguyuan 已提交
40
#include "gfx_utils/graphic_types.h"
M
mamingshuai 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
#ifndef VERSION_LITE
#include "animator/animator.h"
#endif

namespace OHOS {
/**
 * @brief Defines the functions related to an image view.
 *
 * @since 1.0
 * @version 1.0
 */
class UIImageView : public UIView {
public:
    /**
     * @brief A default constructor used to create a <b>UIImageView</b> instance.
     *
     * @since 1.0
     * @version 1.0
     */
    UIImageView();

    /**
     * @brief A destructor used to delete the <b>UIImageView</b> instance.
     *
     * @since 1.0
     * @version 1.0
     */
    virtual ~UIImageView();

    /**
     * @brief Obtains the view type.
     *
     * @return Returns <b>UI_IMAGE_VIEW</b>, as defined in {@link UIViewType}.
     * @since 1.0
     * @version 1.0
     */
    UIViewType GetViewType() const override
    {
        return UI_IMAGE_VIEW;
    }

    /**
     * @brief Obtains the width of this image view.
     *
     * @return Returns the width of this image view.
     * @since 1.0
     * @version 1.0
     */
    int16_t GetWidth() override
    {
        if (needRefresh_ && autoEnable_) {
            ReMeasure();
        }
        return UIView::GetWidth();
    }

    /**
     * @brief Obtains the height of this image view.
     *
     * @return Returns the height of this image view.
     * @since 1.0
     * @version 1.0
     */
    int16_t GetHeight() override
    {
        if (needRefresh_ && autoEnable_) {
            ReMeasure();
        }
        return UIView::GetHeight();
    }

    /**
     * @brief Checks whether this image view needs to be covered to optimize the drawing process.
     *
     * @param invalidatedArea Indicates the area to draw.
     * @return Returns <b>true</b> if this image view needs to be covered; returns <b> false</b> otherwise.
     * @since 1.0
     * @version 1.0
     */
    bool OnPreDraw(Rect& invalidatedArea) const override;

    /**
     * @brief Draws this image view.
     *
     * @param invalidatedArea Indicates the area to draw.
     * @since 1.0
     * @version 1.0
     */
N
niulihua 已提交
129
    void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
M
mamingshuai 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305

    /**
     * @brief Sets the image path.
     *
     * @param src Indicates the pointer to the image path represented by a string.
     * @since 1.0
     * @version 1.0
     */
    void SetSrc(const char* src);

    /**
     * @brief Sets the image information.
     *
     * @param src Indicates the pointer to the image information. For details, see {@link ImageInfo}.
     * @since 1.0
     * @version 1.0
     */
    void SetSrc(const ImageInfo* src);

    /**
     * @brief Sets whether the image view size needs to be adaptive to the image size.
     *
     * @param enable Specifies whether the image view size needs to be adaptive to the image size.
     * <b>true</b> indicates that automatic adaption is enabled, and <b> false</b> indicates the opposite case.
     * @since 1.0
     * @version 1.0
     */
    void SetAutoEnable(bool enable)
    {
        if (autoEnable_ != enable) {
            needRefresh_ = autoEnable_ ? needRefresh_ : true;
            autoEnable_ = enable;
        }
    }

    /*
     * @brief Checks whether automatic adaptation is enabled.
     *
     * @return Returns <b>true</b> if automatic adaptation is enabled; returns <b> false</b> otherwise.
     * @since 1.0
     * @version 1.0
     */
    bool GetAutoEnable() const
    {
        return autoEnable_;
    }

    /**
     * @brief Sets the blur level for this image when it is rotated or scaled.
     *
     * @param level Indicates the blur level to set. For details, see {@link BlurLevel}.
     * @since 1.0
     * @version 1.0
     */
    void SetBlurLevel(BlurLevel level)
    {
        blurLevel_ = level;
    }

    /**
     * @brief Obtains the blur level of this image when it is rotated or scaled.
     *
     * @return Returns the blur level of this image, as defined in {@link BlurLevel}.
     * @since 1.0
     * @version 1.0
     */
    BlurLevel GetBlurLevel() const
    {
        return static_cast<BlurLevel>(blurLevel_);
    }

    /**
     * @brief Sets the algorithm used for image rotation and scaling.
     *
     * @param algorithm Indicates the image transformation algorithm. For details, see {@link TransformAlgorithm}.
     * @since 1.0
     * @version 1.0
     */
    void SetTransformAlgorithm(TransformAlgorithm algorithm)
    {
        algorithm_ = algorithm;
    }

    /**
     * @brief Obtains the algorithm used for image rotation and scaling.
     *
     * @return Returns the image transform algorithm, as defined in {@link TransformAlgorithm}.
     * @since 1.0
     * @version 1.0
     */
    TransformAlgorithm GetTransformAlgorithm() const
    {
        return static_cast<TransformAlgorithm>(algorithm_);
    }

    /**
     * @brief Obtains the image path in binary.
     *
     * @return Returns the pointer to the image path.
     * @since 1.0
     * @version 1.0
     */
    const char* GetPath() const
    {
        return image_.GetPath();
    }

    /**
     * @brief Obtains the image information in an array.
     *
     * @return Returns the pointer to the image information.
     * @since 1.0
     * @version 1.0
     */
    const ImageInfo* GetImageInfo() const
    {
        return image_.GetImageInfo();
    }

    /**
     * @brief Obtains the image type.
     *
     * @return Returns <b>IMG_SRC_VARIABLE</b> for image information in an array; returns <b>IMG_SRC_FILE</b> for an
     * image path in binary.
     * @since 1.0
     * @version 1.0
     */
    uint8_t GetSrcType() const
    {
        return image_.GetSrcType();
    }

protected:
    /**
     * @brief Represents the width of this image.
     */
    int16_t imageWidth_;
    /**
     * @brief Represents the height of this image.
     */
    int16_t imageHeight_;
    /**
     * @brief Specifies whether automatic adaptation is enabled.
     */
    bool autoEnable_;
    /**
     * @brief Specifies whether a refresh is needed.
     */
    bool needRefresh_;
    /**
     * @brief Represents the color format of this image.
     */
    uint8_t colorFormat_ : 4;
    /**
     * @brief Represents the blur level of this image when it is rotated or scaled.
     */
    uint8_t blurLevel_ : 2;
    /**
     * @brief Represents the algorithm used for image rotation and scaling.
     */
    uint8_t algorithm_ : 1;
    uint8_t reserve_ : 1;
    Image image_;

private:
    void ReMeasure() override;
#ifndef VERSION_LITE
    friend class GifImageAnimator;
    void AddAndStartGifAnimator();
    void RemoveAndStopGifAnimator();
    Animator* gifImageAnimator_;
    bool gifFrameFlag_;
#endif
};
} // namespace OHOS
#endif // GRAPHIC_LITE_UI_IMAGE_VIEW_H