Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

StyleBoxTexture

继承: StyleBox < Resource < RefCounted < Object

基于纹理的九宫格 StyleBox

描述

基于纹理的九宫格 StyleBox,类似于 NinePatchRect。这种样式盒对纹理执行 3×3 缩放,只有中心单元格会被完全拉伸。这样就能够为不同大小的样式盒设计带边框的样式。

属性

AxisStretchMode

axis_stretch_horizontal

0

AxisStretchMode

axis_stretch_vertical

0

bool

draw_center

true

float

expand_margin_bottom

0.0

float

expand_margin_left

0.0

float

expand_margin_right

0.0

float

expand_margin_top

0.0

Color

modulate_color

Color(1, 1, 1, 1)

Rect2

region_rect

Rect2(0, 0, 0, 0)

Texture2D

texture

float

texture_margin_bottom

0.0

float

texture_margin_left

0.0

float

texture_margin_right

0.0

float

texture_margin_top

0.0

方法

float

get_expand_margin ( Side margin ) const

float

get_texture_margin ( Side margin ) const

void

set_expand_margin ( Side margin, float size )

void

set_expand_margin_all ( float size )

void

set_texture_margin ( Side margin, float size )

void

set_texture_margin_all ( float size )


枚举

enum AxisStretchMode:

AxisStretchMode AXIS_STRETCH_MODE_STRETCH = 0

拉伸样式盒的纹理。这会导致可见的失真,除非纹理大小与样式盒的大小完美匹配。

AxisStretchMode AXIS_STRETCH_MODE_TILE = 1

根据九宫格系统,重复样式盒的纹理,以匹配样式盒的大小。

AxisStretchMode AXIS_STRETCH_MODE_TILE_FIT = 2

根据九宫格系统,重复样式盒的纹理,以匹配样式盒的大小。与 AXIS_STRETCH_MODE_TILE 不同,可能会稍微拉伸纹理以使九宫格纹理平铺无缝。


属性说明

AxisStretchMode axis_stretch_horizontal = 0

控制如何水平拉伸或平铺样式盒的纹理。可能的取值见 AxisStretchMode


AxisStretchMode axis_stretch_vertical = 0

控制如何垂直拉伸或平铺样式盒的纹理。可能的取值见 AxisStretchMode


bool draw_center = true

  • void set_draw_center ( bool value )

  • bool is_draw_center_enabled ( )

如果为 true,将绘制九宫格纹理的中心图块。


float expand_margin_bottom = 0.0

  • void set_expand_margin ( Side margin, float size )

  • float get_expand_margin ( Side margin ) const

绘制时扩展此样式盒的下边距,使其绘制得比请求的大。


float expand_margin_left = 0.0

  • void set_expand_margin ( Side margin, float size )

  • float get_expand_margin ( Side margin ) const

绘制时扩展此样式盒的左边距,使其绘制得比请求的大。


float expand_margin_right = 0.0

  • void set_expand_margin ( Side margin, float size )

  • float get_expand_margin ( Side margin ) const

绘制时扩展此样式盒的右边距,使其绘制得比请求的大。


float expand_margin_top = 0.0

  • void set_expand_margin ( Side margin, float size )

  • float get_expand_margin ( Side margin ) const

绘制时扩展此样式盒的上边距,使其绘制得比请求的大。


Color modulate_color = Color(1, 1, 1, 1)

  • void set_modulate ( Color value )

  • Color get_modulate ( )

绘制此样式盒时用于调制纹理的颜色。


Rect2 region_rect = Rect2(0, 0, 0, 0)

  • void set_region_rect ( Rect2 value )

  • Rect2 get_region_rect ( )

指定要使用的纹理的子区域。

这相当于首先将纹理包裹在具有相同区域的 AtlasTexture 中。

如果为空(Rect2(0, 0, 0, 0)),则将使用整个纹理。


Texture2D texture

绘制此样式盒时所使用的纹理。


float texture_margin_bottom = 0.0

  • void set_texture_margin ( Side margin, float size )

  • float get_texture_margin ( Side margin ) const

增加 3×3 StyleBox 的底边距。

更高的值意味着更多的源纹理被认为是 3×3 box的底边的一部分。

如果 StyleBox.content_margin_bottom 为负值,这个值也是作为后备值使用。


float texture_margin_left = 0.0

  • void set_texture_margin ( Side margin, float size )

  • float get_texture_margin ( Side margin ) const

增加 3×3 StyleBox 的左边距。

较高的值意味着更多的源纹理被认为是 3×3 box左边框的一部分。

如果 StyleBox.content_margin_left 为负值,这个值也是作为后备值使用。


float texture_margin_right = 0.0

  • void set_texture_margin ( Side margin, float size )

  • float get_texture_margin ( Side margin ) const

增加 3×3 StyleBox 的右边距。

较高的值意味着更多的源纹理被认为是 3×3 box右边框的一部分。

如果 StyleBox.content_margin_right 为负值,这个值也是作为后备值使用。


float texture_margin_top = 0.0

  • void set_texture_margin ( Side margin, float size )

  • float get_texture_margin ( Side margin ) const

增加 3×3 StyleBox 的上边距。

较高的值意味着更多的源纹理被认为是 3×3 box上边框的一部分。

如果 StyleBox.content_margin_top 为负值,这个值也是作为后备值使用。


方法说明

float get_expand_margin ( Side margin ) const

返回指定边 Side 的扩展边距大小。


float get_texture_margin ( Side margin ) const

返回指定边 Side 的边距大小。


void set_expand_margin ( Side margin, float size )

将指定边 Side 的扩展边距设置为 size 像素。


void set_expand_margin_all ( float size )

将所有边的扩展边距都设置为 size 像素。


void set_texture_margin ( Side margin, float size )

将指定边 Side 的边距设置为 size 像素。


void set_texture_margin_all ( float size )

将所有边的边距都设置为 size 像素。