Path: blob/master/scene/resources/gradient_texture.h
10277 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/texture.h"3334class GradientTexture1D : public Texture2D {35GDCLASS(GradientTexture1D, Texture2D);3637private:38Ref<Gradient> gradient;39mutable bool update_pending = false;40mutable RID texture;41int width = 256;42bool use_hdr = false;4344void _queue_update();45void _update() const;4647protected:48static void _bind_methods();4950public:51void set_gradient(Ref<Gradient> p_gradient);52Ref<Gradient> get_gradient() const;5354void set_width(int p_width);55int get_width() const override;5657void set_use_hdr(bool p_enabled);58bool is_using_hdr() const;5960virtual RID get_rid() const override;61virtual int get_height() const override { return 1; }62virtual bool has_alpha() const override { return true; }6364virtual Ref<Image> get_image() const override;65void update_now() const;6667GradientTexture1D();68virtual ~GradientTexture1D();69};7071class GradientTexture2D : public Texture2D {72GDCLASS(GradientTexture2D, Texture2D);7374public:75enum Fill {76FILL_LINEAR,77FILL_RADIAL,78FILL_SQUARE,79};80enum Repeat {81REPEAT_NONE,82REPEAT,83REPEAT_MIRROR,84};8586private:87Ref<Gradient> gradient;88mutable RID texture;8990int width = 64;91int height = 64;9293bool use_hdr = false;9495Vector2 fill_from;96Vector2 fill_to = Vector2(1, 0);9798Fill fill = FILL_LINEAR;99Repeat repeat = REPEAT_NONE;100101float _get_gradient_offset_at(int x, int y) const;102103mutable bool update_pending = false;104void _queue_update();105void _update() const;106107protected:108static void _bind_methods();109110public:111void set_gradient(Ref<Gradient> p_gradient);112Ref<Gradient> get_gradient() const;113114void set_width(int p_width);115virtual int get_width() const override;116void set_height(int p_height);117virtual int get_height() const override;118119void set_use_hdr(bool p_enabled);120bool is_using_hdr() const;121122void set_fill(Fill p_fill);123Fill get_fill() const;124void set_fill_from(Vector2 p_fill_from);125Vector2 get_fill_from() const;126void set_fill_to(Vector2 p_fill_to);127Vector2 get_fill_to() const;128129void set_repeat(Repeat p_repeat);130Repeat get_repeat() const;131132virtual RID get_rid() const override;133virtual bool has_alpha() const override { return true; }134virtual Ref<Image> get_image() const override;135void update_now() const;136137GradientTexture2D();138virtual ~GradientTexture2D();139};140141VARIANT_ENUM_CAST(GradientTexture2D::Fill);142VARIANT_ENUM_CAST(GradientTexture2D::Repeat);143144145