diff options
author | Franco Eusébio Garcia <francoegarcia@outlook.com> | 2016-05-01 05:33:32 -0300 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2016-05-01 10:33:32 +0200 |
commit | a735573327d26536bd29e14350f1e5811c030b86 (patch) | |
tree | e37ff9ff7c196f66178233c292af40dd833ee9eb /scene/gui | |
parent | ff40dcd83f7cc74446ee90a911b58c165b6e164f (diff) |
Add math/script expression evaluation in editor (#3620)
Rebase of #453
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/tree.cpp | 26 | ||||
-rw-r--r-- | scene/gui/tree.h | 6 |
2 files changed, 25 insertions, 7 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 718206dee1..278e6584fa 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -154,7 +154,7 @@ void TreeItem::set_text(int p_column,String p_text) { ERR_FAIL_INDEX( p_column, cells.size() ); cells[p_column].text=p_text; - if (cells[p_column].mode==TreeItem::CELL_MODE_RANGE) { + if (cells[p_column].mode==TreeItem::CELL_MODE_RANGE || cells[p_column].mode==TreeItem::CELL_MODE_RANGE_EXPRESSION) { cells[p_column].min=0; cells[p_column].max=p_text.get_slice_count(","); @@ -704,6 +704,7 @@ void TreeItem::_bind_methods() { BIND_CONSTANT( CELL_MODE_STRING ); BIND_CONSTANT( CELL_MODE_CHECK ); BIND_CONSTANT( CELL_MODE_RANGE ); + BIND_CONSTANT( CELL_MODE_RANGE_EXPRESSION ); BIND_CONSTANT( CELL_MODE_ICON ); BIND_CONSTANT( CELL_MODE_CUSTOM ); @@ -1127,7 +1128,8 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& //font->draw( ci, text_pos, p_item->cells[i].text, col,item_rect.size.x-check_w ); } break; - case TreeItem::CELL_MODE_RANGE: { + case TreeItem::CELL_MODE_RANGE: + case TreeItem::CELL_MODE_RANGE_EXPRESSION: { if (p_item->cells[i].text!="") { @@ -1594,7 +1596,8 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ } } break; - case TreeItem::CELL_MODE_RANGE: { + case TreeItem::CELL_MODE_RANGE: + case TreeItem::CELL_MODE_RANGE_EXPRESSION: { if (c.text!="") { @@ -1794,6 +1797,13 @@ void Tree::text_editor_enter(String p_text) { //popup_edited_item->edited_signal.call( popup_edited_item_col ); } break; + case TreeItem::CELL_MODE_RANGE_EXPRESSION: { + + if(evaluator) + c.val=evaluator->eval(p_text); + else + c.val=p_text.to_double(); + } break; default: { ERR_FAIL(); } } @@ -2372,7 +2382,7 @@ bool Tree::edit_selected() { item_edited(col,s); return true; - } else if (c.mode==TreeItem::CELL_MODE_RANGE && c.text!="") { + } else if ((c.mode==TreeItem::CELL_MODE_RANGE||c.mode==TreeItem::CELL_MODE_RANGE_EXPRESSION) && c.text!="") { popup_menu->clear(); for (int i=0;i<c.text.get_slice_count(",");i++) { @@ -2389,7 +2399,7 @@ bool Tree::edit_selected() { popup_edited_item_col=col; return true; - } else if (c.mode==TreeItem::CELL_MODE_STRING || c.mode==TreeItem::CELL_MODE_RANGE) { + } else if (c.mode==TreeItem::CELL_MODE_STRING || c.mode==TreeItem::CELL_MODE_RANGE || c.mode==TreeItem::CELL_MODE_RANGE_EXPRESSION ) { Point2i textedpos=get_global_pos() + rect.pos; text_editor->set_pos( textedpos ); @@ -2398,7 +2408,7 @@ bool Tree::edit_selected() { text_editor->set_text( c.mode==TreeItem::CELL_MODE_STRING?c.text:rtos(c.val) ); text_editor->select_all(); - if (c.mode==TreeItem::CELL_MODE_RANGE) { + if (c.mode==TreeItem::CELL_MODE_RANGE || c.mode==TreeItem::CELL_MODE_RANGE_EXPRESSION ) { value_editor->set_pos(textedpos + Point2i(0,text_editor->get_size().height) ); value_editor->set_size( Size2(rect.size.width,1)); @@ -3227,6 +3237,9 @@ bool Tree::is_folding_hidden() const { return hide_folding; } +void Tree::set_value_evaluator(ValueEvaluator *p_evaluator) { + evaluator = p_evaluator; +} void Tree::_bind_methods() { @@ -3367,6 +3380,7 @@ Tree::Tree() { hide_folding=false; + evaluator=NULL; } diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 1ba1c6a494..75bcfd8e33 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -34,6 +34,7 @@ #include "scene/gui/line_edit.h" #include "scene/gui/scroll_bar.h" #include "scene/gui/slider.h" +#include "core/helper/value_evaluator.h" /** @author Juan Linietsky <reduzio@gmail.com> @@ -52,6 +53,7 @@ public: CELL_MODE_STRING, ///< just a string CELL_MODE_CHECK, ///< string + check CELL_MODE_RANGE, ///< Contains a range + CELL_MODE_RANGE_EXPRESSION, ///< Contains a range CELL_MODE_ICON, ///< Contains a icon, not editable CELL_MODE_CUSTOM, ///< Contains a custom value, show a string, and an edit button }; @@ -422,6 +424,8 @@ friend class TreeItem; bool hide_folding; + ValueEvaluator *evaluator; + protected: static void _bind_methods(); @@ -482,7 +486,7 @@ public: void set_hide_folding(bool p_hide); bool is_folding_hidden() const; - + void set_value_evaluator(ValueEvaluator *p_evaluator); Tree(); ~Tree(); |