editor_path.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*************************************************************************/
  2. /* editor_path.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 "editor_path.h"
  31. void EditorPath::_notification(int p_what) {
  32. switch (p_what) {
  33. case NOTIFICATION_DRAW: {
  34. RID ci = get_canvas_item();
  35. Ref<Font> label_font = get_font("font", "Label");
  36. Size2i size = get_size();
  37. Ref<Texture> sn = get_icon("SmallNext", "EditorIcons");
  38. int ofs = 5;
  39. for (int i = 0; i < history->get_path_size(); i++) {
  40. Object *obj = ObjectDB::get_instance(history->get_path_object(i));
  41. if (!obj)
  42. continue;
  43. String type = obj->get_type();
  44. Ref<Texture> icon;
  45. if (has_icon(obj->get_type(), "EditorIcons"))
  46. icon = get_icon(obj->get_type(), "EditorIcons");
  47. else
  48. icon = get_icon("Object", "EditorIcons");
  49. icon->draw(ci, Point2i(ofs, (size.height - icon->get_height()) / 2));
  50. ofs += icon->get_width();
  51. if (i == history->get_path_size() - 1) {
  52. //add name
  53. ofs += 4;
  54. int left = size.width - ofs;
  55. if (left < 0)
  56. continue;
  57. String name;
  58. if (obj->cast_to<Resource>()) {
  59. Resource *r = obj->cast_to<Resource>();
  60. if (r->get_path().is_resource_file())
  61. name = r->get_path().get_file();
  62. else
  63. name = r->get_name();
  64. if (name == "")
  65. name = r->get_type();
  66. } else if (obj->cast_to<Node>()) {
  67. name = obj->cast_to<Node>()->get_name();
  68. } else if (obj->cast_to<Resource>() && obj->cast_to<Resource>()->get_name() != "") {
  69. name = obj->cast_to<Resource>()->get_name();
  70. } else {
  71. name = obj->get_type();
  72. }
  73. set_tooltip(obj->get_type());
  74. label_font->draw(ci, Point2i(ofs, (size.height - label_font->get_height()) / 2 + label_font->get_ascent()), name, Color(1, 1, 1), left);
  75. } else {
  76. //add arrow
  77. //sn->draw(ci,Point2i(ofs,(size.height-sn->get_height())/2));
  78. //ofs+=sn->get_width();
  79. ofs += 5; //just looks better! somehow
  80. }
  81. }
  82. } break;
  83. }
  84. }
  85. void EditorPath::update_path() {
  86. update();
  87. }
  88. EditorPath::EditorPath(EditorHistory *p_history) {
  89. history = p_history;
  90. }