Path: blob/master/scene/resources/gradient_texture.h
20969 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,80};81enum Repeat {82REPEAT_NONE,83REPEAT,84REPEAT_MIRROR,85};8687private:88Ref<Gradient> gradient;89mutable RID texture;9091int width = 64;92int height = 64;9394bool use_hdr = false;9596Vector2 fill_from;97Vector2 fill_to = Vector2(1, 0);9899Fill fill = FILL_LINEAR;100Repeat repeat = REPEAT_NONE;101102float _get_gradient_offset_at(int x, int y) const;103104mutable bool update_pending = false;105void _queue_update();106void _update() const;107108protected:109static void _bind_methods();110111public:112void set_gradient(Ref<Gradient> p_gradient);113Ref<Gradient> get_gradient() const;114115void set_width(int p_width);116virtual int get_width() const override;117void set_height(int p_height);118virtual int get_height() const override;119120void set_use_hdr(bool p_enabled);121bool is_using_hdr() const;122123void set_fill(Fill p_fill);124Fill get_fill() const;125void set_fill_from(Vector2 p_fill_from);126Vector2 get_fill_from() const;127void set_fill_to(Vector2 p_fill_to);128Vector2 get_fill_to() const;129130void set_repeat(Repeat p_repeat);131Repeat get_repeat() const;132133virtual RID get_rid() const override;134virtual bool has_alpha() const override { return true; }135virtual Ref<Image> get_image() const override;136void update_now() const;137138GradientTexture2D();139virtual ~GradientTexture2D();140};141142VARIANT_ENUM_CAST(GradientTexture2D::Fill);143VARIANT_ENUM_CAST(GradientTexture2D::Repeat);144145146