Skip to content

Commit

Permalink
Merge pull request #62906 from bruvzg/ts_bit_fields
Browse files Browse the repository at this point in the history
Use BitField hint for the TextServer enums.
  • Loading branch information
akien-mga authored Jul 15, 2022
2 parents e5a1640 + cbe3a2d commit 9904a9d
Show file tree
Hide file tree
Showing 35 changed files with 395 additions and 334 deletions.
1 change: 1 addition & 0 deletions core/core_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ void register_global_constants() {
BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_GROUP);
BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_CATEGORY);
BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_SUBGROUP);
BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_CLASS_IS_BITFIELD);
BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_NO_INSTANCE_STATE);
BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_RESTART_IF_CHANGED);
BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_SCRIPT_VARIABLE);
Expand Down
5 changes: 4 additions & 1 deletion core/extension/extension_api_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ static String get_type_name(const PropertyInfo &p_info) {
return p_info.hint_string + "*";
}
}
if (p_info.type == Variant::INT && (p_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD))) {
if (p_info.type == Variant::INT && (p_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM))) {
return String("enum::") + String(p_info.class_name);
}
if (p_info.type == Variant::INT && (p_info.usage & (PROPERTY_USAGE_CLASS_IS_BITFIELD))) {
return String("bitfield::") + String(p_info.class_name);
}
if (p_info.class_name != StringName()) {
return p_info.class_name;
}
Expand Down
2 changes: 1 addition & 1 deletion core/extension/gdnative_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ typedef struct {

void (*classdb_register_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs);
void (*classdb_register_extension_class_method)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info);
void (*classdb_register_extension_class_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value);
void (*classdb_register_extension_class_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, bool p_is_bitfield);
void (*classdb_register_extension_class_property)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter);
void (*classdb_register_extension_class_property_group)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_group_name, const char *p_prefix);
void (*classdb_register_extension_class_property_subgroup)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix);
Expand Down
4 changes: 2 additions & 2 deletions core/extension/native_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ void NativeExtension::_register_extension_class_method(const GDNativeExtensionCl

ClassDB::bind_method_custom(class_name, method);
}
void NativeExtension::_register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value) {
void NativeExtension::_register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, bool p_is_bitfield) {
NativeExtension *self = static_cast<NativeExtension *>(p_library);

StringName class_name = p_class_name;
ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension constant '" + String(p_constant_name) + "' for unexisting class '" + class_name + "'.");

//Extension *extension = &self->extension_classes[class_name];

ClassDB::bind_integer_constant(class_name, p_enum_name, p_constant_name, p_constant_value);
ClassDB::bind_integer_constant(class_name, p_enum_name, p_constant_name, p_constant_value, p_is_bitfield);
}

void NativeExtension::_register_extension_class_property(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter) {
Expand Down
2 changes: 1 addition & 1 deletion core/extension/native_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class NativeExtension : public Resource {

static void _register_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs);
static void _register_extension_class_method(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info);
static void _register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value);
static void _register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, bool p_is_bitfield);
static void _register_extension_class_property(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter);
static void _register_extension_class_property_group(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_group_name, const char *p_prefix);
static void _register_extension_class_property_subgroup(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix);
Expand Down
1 change: 1 addition & 0 deletions core/variant/type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class BitField {
_FORCE_INLINE_ void clear_flag(T p_flag) { return value &= ~p_flag; }
_FORCE_INLINE_ BitField(uint32_t p_value) { value = p_value; }
_FORCE_INLINE_ operator uint32_t() const { return value; }
_FORCE_INLINE_ operator Variant() const { return value; }
};

#define TEMPL_MAKE_BITFIELD_TYPE_INFO(m_enum, m_impl) \
Expand Down
2 changes: 2 additions & 0 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,8 @@
<constant name="PROPERTY_USAGE_SUBGROUP" value="256" enum="PropertyUsageFlags">
Used to group properties together in the editor in a subgroup (under a group). See [EditorInspector].
</constant>
<constant name="PROPERTY_USAGE_CLASS_IS_BITFIELD" value="512" enum="PropertyUsageFlags">
</constant>
<constant name="PROPERTY_USAGE_NO_INSTANCE_STATE" value="1024" enum="PropertyUsageFlags">
The property does not save its state in [PackedScene].
</constant>
Expand Down
18 changes: 10 additions & 8 deletions doc/classes/CanvasItem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@
<argument index="5" name="font_size" type="int" default="16" />
<argument index="6" name="max_lines" type="int" default="-1" />
<argument index="7" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<argument index="8" name="flags" type="int" default="99" />
<argument index="9" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="10" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<argument index="8" name="brk_flags" type="int" enum="TextServer.LineBreakFlag" default="3" />
<argument index="9" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="10" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="11" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Breaks [code]text[/code] to the lines and draws it using the specified [code]font[/code] at the [code]position[/code] (top-left corner). The text will have its color multiplied by [code]modulate[/code]. If [code]clip_w[/code] is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
</description>
Expand All @@ -187,9 +188,10 @@
<argument index="6" name="max_lines" type="int" default="-1" />
<argument index="7" name="size" type="int" default="1" />
<argument index="8" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<argument index="9" name="flags" type="int" default="99" />
<argument index="10" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="11" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<argument index="9" name="brk_flags" type="int" enum="TextServer.LineBreakFlag" default="3" />
<argument index="10" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="11" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="12" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Breaks [code]text[/code] to the lines and draws text outline using the specified [code]font[/code] at the [code]position[/code] (top-left corner). The text will have its color multiplied by [code]modulate[/code]. If [code]clip_w[/code] is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
</description>
Expand Down Expand Up @@ -279,7 +281,7 @@
<argument index="4" name="width" type="float" default="-1" />
<argument index="5" name="font_size" type="int" default="16" />
<argument index="6" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<argument index="7" name="flags" type="int" default="3" />
<argument index="7" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="8" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="9" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Expand Down Expand Up @@ -316,7 +318,7 @@
<argument index="5" name="font_size" type="int" default="16" />
<argument index="6" name="size" type="int" default="1" />
<argument index="7" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<argument index="8" name="flags" type="int" default="3" />
<argument index="8" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="9" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="10" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Expand Down
29 changes: 16 additions & 13 deletions doc/classes/Font.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
<argument index="5" name="font_size" type="int" default="16" />
<argument index="6" name="max_lines" type="int" default="-1" />
<argument index="7" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<argument index="8" name="flags" type="int" default="99" />
<argument index="9" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="10" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<argument index="8" name="brk_flags" type="int" enum="TextServer.LineBreakFlag" default="3" />
<argument index="9" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="10" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="11" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Breaks [code]text[/code] to the lines using rules specified by [code]flags[/code] and draws it into a canvas item using the font, at a given position, with [code]modulate[/code] color, optionally clipping the width and aligning horizontally. [code]position[/code] specifies the baseline of the first line, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis.
See also [method CanvasItem.draw_multiline_string].
Expand All @@ -63,9 +64,10 @@
<argument index="6" name="max_lines" type="int" default="-1" />
<argument index="7" name="size" type="int" default="1" />
<argument index="8" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<argument index="9" name="flags" type="int" default="99" />
<argument index="10" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="11" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<argument index="9" name="brk_flags" type="int" enum="TextServer.LineBreakFlag" default="3" />
<argument index="10" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="11" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="12" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Breaks [code]text[/code] to the lines using rules specified by [code]flags[/code] and draws text outline into a canvas item using the font, at a given position, with [code]modulate[/code] color and [code]size[/code] outline size, optionally clipping the width and aligning horizontally. [code]position[/code] specifies the baseline of the first line, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis.
See also [method CanvasItem.draw_multiline_string_outline].
Expand All @@ -80,7 +82,7 @@
<argument index="4" name="width" type="float" default="-1" />
<argument index="5" name="font_size" type="int" default="16" />
<argument index="6" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<argument index="7" name="flags" type="int" default="3" />
<argument index="7" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="8" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="9" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Expand All @@ -98,7 +100,7 @@
<argument index="5" name="font_size" type="int" default="16" />
<argument index="6" name="size" type="int" default="1" />
<argument index="7" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<argument index="8" name="flags" type="int" default="3" />
<argument index="8" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="9" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="10" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Expand Down Expand Up @@ -160,7 +162,7 @@
</description>
</method>
<method name="get_font_style" qualifiers="const">
<return type="int" />
<return type="int" enum="TextServer.FontStyle" />
<description>
Returns font style flags, see [enum TextServer.FontStyle].
</description>
Expand All @@ -186,9 +188,10 @@
<argument index="2" name="width" type="float" default="-1" />
<argument index="3" name="font_size" type="int" default="16" />
<argument index="4" name="max_lines" type="int" default="-1" />
<argument index="5" name="flags" type="int" default="96" />
<argument index="6" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="7" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<argument index="5" name="brk_flags" type="int" enum="TextServer.LineBreakFlag" default="3" />
<argument index="6" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="7" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="8" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Returns the size of a bounding box of a string broken into the lines, taking kerning and advance into account.
See also [method draw_multiline_string].
Expand Down Expand Up @@ -219,7 +222,7 @@
<argument index="1" name="alignment" type="int" enum="HorizontalAlignment" default="0" />
<argument index="2" name="width" type="float" default="-1" />
<argument index="3" name="font_size" type="int" default="16" />
<argument index="4" name="flags" type="int" default="3" />
<argument index="4" name="jst_flags" type="int" enum="TextServer.JustificationFlag" default="3" />
<argument index="5" name="direction" type="int" enum="TextServer.Direction" default="0" />
<argument index="6" name="orientation" type="int" enum="TextServer.Orientation" default="0" />
<description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/FontFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@
<member name="font_name" type="String" setter="set_font_name" getter="get_font_name" default="&quot;&quot;">
Font family name.
</member>
<member name="font_style" type="int" setter="set_font_style" getter="get_font_style" default="0">
<member name="font_style" type="int" setter="set_font_style" getter="get_font_style" enum="TextServer.FontStyle" default="0">
Font style flags, see [enum TextServer.FontStyle].
</member>
<member name="force_autohinter" type="bool" setter="set_force_autohinter" getter="is_force_autohinter" default="false">
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/TextLine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
<member name="direction" type="int" setter="set_direction" getter="get_direction" enum="TextServer.Direction" default="0">
Text writing direction.
</member>
<member name="flags" type="int" setter="set_flags" getter="get_flags" default="3">
Line Alignment rules. For more info see [TextServer].
<member name="flags" type="int" setter="set_flags" getter="get_flags" enum="TextServer.JustificationFlag" default="3">
Line alignment rules. For more info see [TextServer].
</member>
<member name="orientation" type="int" setter="set_orientation" getter="get_orientation" enum="TextServer.Orientation" default="0">
Text orientation.
Expand Down
7 changes: 5 additions & 2 deletions doc/classes/TextParagraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,17 @@
<member name="alignment" type="int" setter="set_alignment" getter="get_alignment" enum="HorizontalAlignment" default="0">
Paragraph horizontal alignment.
</member>
<member name="break_flags" type="int" setter="set_break_flags" getter="get_break_flags" enum="TextServer.LineBreakFlag" default="3">
Line breaking rules. For more info see [TextServer].
</member>
<member name="custom_punctuation" type="String" setter="set_custom_punctuation" getter="get_custom_punctuation" default="&quot;&quot;">
Custom punctuation character list, used for word breaking. If set to empty string, server defaults are used.
</member>
<member name="direction" type="int" setter="set_direction" getter="get_direction" enum="TextServer.Direction" default="0">
Text writing direction.
</member>
<member name="flags" type="int" setter="set_flags" getter="get_flags" default="99">
Line breaking and alignment rules. For more info see [TextServer].
<member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" default="3">
Line alignment rules. For more info see [TextServer].
</member>
<member name="max_lines_visible" type="int" setter="set_max_lines_visible" getter="get_max_lines_visible" default="-1">
Limits the lines of text shown.
Expand Down
Loading

0 comments on commit 9904a9d

Please sign in to comment.