editor_log.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*************************************************************************/
  2. /* editor_log.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 "version.h"
  30. #include "editor_log.h"
  31. #include "scene/gui/center_container.h"
  32. #include "editor_node.h"
  33. void EditorLog::_error_handler(void *p_self, const char*p_func, const char*p_file,int p_line, const char*p_error,const char*p_errorexp,ErrorHandlerType p_type ) {
  34. EditorLog *self=(EditorLog *)p_self;
  35. if (self->current!=Thread::get_caller_ID())
  36. return;
  37. String err_str;
  38. if (p_errorexp && p_errorexp[0]) {
  39. err_str=p_errorexp;
  40. } else {
  41. err_str=String(p_file)+":"+itos(p_line)+" - "+String(p_error);
  42. }
  43. // if (!self->is_visible())
  44. // self->emit_signal("show_request");
  45. err_str=" "+err_str;
  46. self->log->add_newline();
  47. Ref<Texture> icon;
  48. switch(p_type) {
  49. case ERR_HANDLER_ERROR: {
  50. icon = self->get_icon("Error","EditorIcons");
  51. return; // these are confusing
  52. } break;
  53. case ERR_HANDLER_WARNING: {
  54. icon = self->get_icon("Error","EditorIcons");
  55. } break;
  56. case ERR_HANDLER_SCRIPT: {
  57. icon = self->get_icon("ScriptError","EditorIcons");
  58. } break;
  59. }
  60. self->add_message(err_str,true);
  61. }
  62. void EditorLog::_notification(int p_what) {
  63. if (p_what==NOTIFICATION_ENTER_SCENE) {
  64. log->add_color_override("default_color",get_color("font_color","Tree"));
  65. tb->set_normal_texture( get_icon("Collapse","EditorIcons"));
  66. tb->set_hover_texture( get_icon("CollapseHl","EditorIcons"));
  67. }
  68. /*if (p_what==NOTIFICATION_DRAW) {
  69. RID ci = get_canvas_item();
  70. get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
  71. int top_ofs = 20;
  72. int border_ofs=4;
  73. Ref<StyleBox> style = get_stylebox("normal","TextEdit");
  74. style->draw(ci,Rect2( Point2(border_ofs,top_ofs),get_size()-Size2(border_ofs*2,top_ofs+border_ofs)));
  75. }*/
  76. }
  77. void EditorLog::_close_request() {
  78. _flip_request();
  79. }
  80. void EditorLog::add_message(const String& p_msg,bool p_error) {
  81. if (p_error) {
  82. Ref<Texture> icon = get_icon("Error","EditorIcons");
  83. log->add_image( icon );
  84. button->set_icon(icon);
  85. log->push_color(get_color("fg_error","Editor"));
  86. } else {
  87. button->set_icon(Ref<Texture>());
  88. }
  89. log->add_newline();
  90. log->add_text(p_msg);
  91. button->set_text(p_msg);
  92. if (p_error)
  93. log->pop();
  94. }
  95. /*
  96. void EditorLog::_dragged(const Point2& p_ofs) {
  97. int ofs = ec->get_minsize().height;
  98. ofs = ofs-p_ofs.y;
  99. if (ofs<50)
  100. ofs=50;
  101. if (ofs>300)
  102. ofs=300;
  103. ec->set_minsize(Size2(ec->get_minsize().width,ofs));
  104. minimum_size_changed();
  105. }
  106. */
  107. ToolButton *EditorLog::get_button() {
  108. return button;
  109. }
  110. void EditorLog::_flip_request() {
  111. if (is_visible())
  112. hide();
  113. else
  114. show();
  115. }
  116. void EditorLog::_undo_redo_cbk(void *p_self,const String& p_name) {
  117. EditorLog *self=(EditorLog *)p_self;
  118. self->add_message(p_name);
  119. }
  120. void EditorLog::_bind_methods() {
  121. ObjectTypeDB::bind_method(_MD("_close_request"),&EditorLog::_close_request );
  122. ObjectTypeDB::bind_method(_MD("_flip_request"),&EditorLog::_flip_request );
  123. //ObjectTypeDB::bind_method(_MD("_dragged"),&EditorLog::_dragged );
  124. ADD_SIGNAL( MethodInfo("close_request"));
  125. ADD_SIGNAL( MethodInfo("show_request"));
  126. }
  127. EditorLog::EditorLog() {
  128. VBoxContainer *vb = memnew( VBoxContainer);
  129. add_child(vb);
  130. vb->set_v_size_flags(SIZE_EXPAND_FILL);
  131. HBoxContainer *hb = memnew( HBoxContainer );
  132. vb->add_child(hb);
  133. title = memnew( Label );
  134. title->set_text(" Output:");
  135. title->set_h_size_flags(SIZE_EXPAND_FILL);
  136. hb->add_child(title);
  137. button = memnew( ToolButton );
  138. button->set_text_align(Button::ALIGN_LEFT);
  139. button->connect("pressed",this,"_flip_request");
  140. button->set_focus_mode(FOCUS_NONE);
  141. button->set_clip_text(true);
  142. button->set_tooltip("Open/Close output panel.");
  143. //pd = memnew( PaneDrag );
  144. //hb->add_child(pd);
  145. //pd->connect("dragged",this,"_dragged");
  146. //pd->set_default_cursor_shape(Control::CURSOR_MOVE);
  147. tb = memnew( TextureButton );
  148. hb->add_child(tb);
  149. tb->connect("pressed",this,"_close_request");
  150. ec = memnew( EmptyControl);
  151. vb->add_child(ec);
  152. ec->set_minsize(Size2(0,100));
  153. ec->set_v_size_flags(SIZE_EXPAND_FILL);
  154. PanelContainer *pc = memnew( PanelContainer );
  155. pc->add_style_override("panel",get_stylebox("normal","TextEdit"));
  156. ec->add_child(pc);
  157. pc->set_area_as_parent_rect();
  158. log = memnew( RichTextLabel );
  159. log->set_scroll_follow(true);
  160. pc->add_child(log);
  161. add_message(VERSION_FULL_NAME" (c) 2008-2014 Juan Linietsky, Ariel Manzur.");
  162. //log->add_text("Initialization Complete.\n"); //because it looks cool.
  163. add_style_override("panel",get_stylebox("panelf","Panel"));
  164. eh.errfunc=_error_handler;
  165. eh.userdata=this;
  166. add_error_handler(&eh);
  167. current=Thread::get_caller_ID();
  168. EditorNode::get_undo_redo()->set_commit_notify_callback(_undo_redo_cbk,this);
  169. hide();
  170. }
  171. void EditorLog::deinit() {
  172. remove_error_handler(&eh);
  173. }
  174. EditorLog::~EditorLog() {
  175. }