Path: blob/master/scene/resources/gradient_texture.h
21298 views
/**************************************************************************/1/* gradient_texture.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/resources/gradient.h"33#include "scene/resources/texture.h"3435class GradientTexture1D : public Texture2D {36GDCLASS(GradientTexture1D, Texture2D);3738private:39Ref<Gradient> gradient;40mutable bool update_pending = false;41mutable RID texture;42int width = 256;43bool use_hdr = false;4445void _queue_update();46void _update() const;4748protected:49static void _bind_methods();5051public:52void set_gradient(Ref<Gradient> p_gradient);53Ref<Gradient> get_gradient() const;5455void set_width(int p_width);56int get_width() const override;5758void set_use_hdr(bool p_enabled);59bool is_using_hdr() const;6061virtual RID get_rid() const override;62virtual int get_height() const override { return 1; }63virtual bool has_alpha() const override { return true; }6465virtual Ref<Image> get_image() const override;66void update_now() const;6768GradientTexture1D();69virtual ~GradientTexture1D();70};7172class GradientTexture2D : public Texture2D {73GDCLASS(GradientTexture2D, Texture2D);7475public:76enum Fill {77FILL_LINEAR,78FILL_RADIAL,79FILL_SQUARE,80FILL_CONIC,81};82enum Repeat {83REPEAT_NONE,84REPEAT,85REPEAT_MIRROR,86};8788private:89Ref<Gradient> gradient;90mutable RID texture;9192int width = 64;93int height = 64;9495bool use_hdr = false;9697Vector2 fill_from;98Vector2 fill_to = Vector2(1, 0);99100Fill fill = FILL_LINEAR;101Repeat repeat = REPEAT_NONE;102103float _get_gradient_offset_at(int x, int y) const;104105mutable bool update_pending = false;106void _queue_update();107void _update() const;108109protected:110static void _bind_methods();111112public:113void set_gradient(Ref<Gradient> p_gradient);114Ref<Gradient> get_gradient() const;115116void set_width(int p_width);117virtual int get_width() const override;118void set_height(int p_height);119virtual int get_height() const override;120121void set_use_hdr(bool p_enabled);122bool is_using_hdr() const;123124void set_fill(Fill p_fill);125Fill get_fill() const;126void set_fill_from(Vector2 p_fill_from);127Vector2 get_fill_from() const;128void set_fill_to(Vector2 p_fill_to);129Vector2 get_fill_to() const;130131void set_repeat(Repeat p_repeat);132Repeat get_repeat() const;133134virtual RID get_rid() const override;135virtual bool has_alpha() const override { return true; }136virtual Ref<Image> get_image() const override;137void update_now() const;138139GradientTexture2D();140virtual ~GradientTexture2D();141};142143VARIANT_ENUM_CAST(GradientTexture2D::Fill);144VARIANT_ENUM_CAST(GradientTexture2D::Repeat);145146147