rich_text_effect.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*************************************************************************/
  2. /* rich_text_effect.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "rich_text_effect.h"
  31. #include "core/script_language.h"
  32. void RichTextEffect::_bind_methods() {
  33. BIND_VMETHOD(MethodInfo(Variant::BOOL, "_process_custom_fx", PropertyInfo(Variant::OBJECT, "char_fx", PROPERTY_HINT_RESOURCE_TYPE, "CharFXTransform")));
  34. }
  35. Variant RichTextEffect::get_bbcode() const {
  36. Variant r;
  37. if (get_script_instance()) {
  38. if (!get_script_instance()->get("bbcode", r)) {
  39. String path = get_script_instance()->get_script()->get_path();
  40. r = path.get_file().get_basename();
  41. }
  42. }
  43. return r;
  44. }
  45. bool RichTextEffect::_process_effect_impl(Ref<CharFXTransform> p_cfx) {
  46. bool return_value = false;
  47. if (get_script_instance()) {
  48. Variant v = get_script_instance()->call("_process_custom_fx", p_cfx);
  49. if (v.get_type() != Variant::BOOL) {
  50. return_value = false;
  51. } else {
  52. return_value = (bool)v;
  53. }
  54. }
  55. return return_value;
  56. }
  57. RichTextEffect::RichTextEffect() {
  58. }
  59. void CharFXTransform::_bind_methods() {
  60. ClassDB::bind_method(D_METHOD("get_relative_index"), &CharFXTransform::get_relative_index);
  61. ClassDB::bind_method(D_METHOD("set_relative_index", "index"), &CharFXTransform::set_relative_index);
  62. ClassDB::bind_method(D_METHOD("get_absolute_index"), &CharFXTransform::get_absolute_index);
  63. ClassDB::bind_method(D_METHOD("set_absolute_index", "index"), &CharFXTransform::set_absolute_index);
  64. ClassDB::bind_method(D_METHOD("get_elapsed_time"), &CharFXTransform::get_elapsed_time);
  65. ClassDB::bind_method(D_METHOD("set_elapsed_time", "time"), &CharFXTransform::set_elapsed_time);
  66. ClassDB::bind_method(D_METHOD("is_visible"), &CharFXTransform::is_visible);
  67. ClassDB::bind_method(D_METHOD("set_visibility", "visibility"), &CharFXTransform::set_visibility);
  68. ClassDB::bind_method(D_METHOD("get_offset"), &CharFXTransform::get_offset);
  69. ClassDB::bind_method(D_METHOD("set_offset", "offset"), &CharFXTransform::set_offset);
  70. ClassDB::bind_method(D_METHOD("get_color"), &CharFXTransform::get_color);
  71. ClassDB::bind_method(D_METHOD("set_color", "color"), &CharFXTransform::set_color);
  72. ClassDB::bind_method(D_METHOD("get_environment"), &CharFXTransform::get_environment);
  73. ClassDB::bind_method(D_METHOD("set_environment", "environment"), &CharFXTransform::set_environment);
  74. ClassDB::bind_method(D_METHOD("get_character"), &CharFXTransform::get_character);
  75. ClassDB::bind_method(D_METHOD("set_character", "character"), &CharFXTransform::set_character);
  76. ADD_PROPERTY(PropertyInfo(Variant::INT, "relative_index"), "set_relative_index", "get_relative_index");
  77. ADD_PROPERTY(PropertyInfo(Variant::INT, "absolute_index"), "set_absolute_index", "get_absolute_index");
  78. ADD_PROPERTY(PropertyInfo(Variant::REAL, "elapsed_time"), "set_elapsed_time", "get_elapsed_time");
  79. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visibility", "is_visible");
  80. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
  81. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
  82. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "env"), "set_environment", "get_environment");
  83. ADD_PROPERTY(PropertyInfo(Variant::INT, "character"), "set_character", "get_character");
  84. }
  85. CharFXTransform::CharFXTransform() {
  86. relative_index = 0;
  87. absolute_index = 0;
  88. visibility = true;
  89. offset = Point2();
  90. color = Color();
  91. character = 0;
  92. elapsed_time = 0.0f;
  93. }
  94. CharFXTransform::~CharFXTransform() {
  95. environment.clear();
  96. }