editor_path.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*************************************************************************/
  2. /* editor_path.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  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. /*************************************************************************/
  29. #include "editor_path.h"
  30. void EditorPath::_notification(int p_what) {
  31. switch(p_what) {
  32. case NOTIFICATION_DRAW: {
  33. RID ci=get_canvas_item();
  34. Ref<Font> label_font = get_font("font","Label");
  35. Color label_color = get_color("font_color","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. name=r->get_name();
  61. if (name=="")
  62. name=r->get_type();
  63. } else if (obj->cast_to<Node>()) {
  64. name=obj->cast_to<Node>()->get_name();
  65. } else
  66. name=obj->get_type();
  67. label_font->draw(ci,Point2i(ofs,(size.height-label_font->get_height())/2+label_font->get_ascent()),name,Color(1,1,1),left);
  68. } else {
  69. //add arrow
  70. //sn->draw(ci,Point2i(ofs,(size.height-sn->get_height())/2));
  71. //ofs+=sn->get_width();
  72. ofs+=5; //just looks better! somehow
  73. }
  74. }
  75. } break;
  76. }
  77. }
  78. void EditorPath::update_path() {
  79. update();
  80. }
  81. EditorPath::EditorPath(EditorHistory *p_history) {
  82. history=p_history;
  83. }