summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/item_list.cpp35
-rw-r--r--scene/gui/line_edit.cpp21
-rw-r--r--scene/gui/text_edit.cpp22
-rw-r--r--scene/gui/tree.cpp31
-rw-r--r--scene/gui/tree.h3
5 files changed, 78 insertions, 34 deletions
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 89cd509fbd..f69ad8fa7e 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -959,7 +959,23 @@ void ItemList::_notification(int p_what) {
shape_changed=false;
}
+ //ensure_selected_visible needs to be checked before we draw the list.
+ if (ensure_selected_visible && current>=0 && current <=items.size()) {
+ Rect2 r = items[current].rect_cache;
+ int from = scroll_bar->get_val();
+ int to = from + scroll_bar->get_page();
+
+ if (r.pos.y < from) {
+ scroll_bar->set_val(r.pos.y);
+ } else if (r.pos.y+r.size.y > to) {
+ scroll_bar->set_val(r.pos.y+r.size.y - (to-from));
+ }
+
+
+ }
+
+ ensure_selected_visible=false;
Vector2 base_ofs = bg->get_offset();
base_ofs.y-=int(scroll_bar->get_val());
@@ -1147,25 +1163,6 @@ void ItemList::_notification(int p_what) {
for(int i=0;i<separators.size();i++) {
draw_line(Vector2(bg->get_margin(MARGIN_LEFT),base_ofs.y+separators[i]),Vector2(size.width-bg->get_margin(MARGIN_LEFT),base_ofs.y+separators[i]),guide_color);
}
-
-
- if (ensure_selected_visible && current>=0 && current <=items.size()) {
-
- Rect2 r = items[current].rect_cache;
- int from = scroll_bar->get_val();
- int to = from + scroll_bar->get_page();
-
- if (r.pos.y < from) {
- scroll_bar->set_val(r.pos.y);
- } else if (r.pos.y+r.size.y > to) {
- scroll_bar->set_val(r.pos.y+r.size.y - (to-from));
- }
-
-
- }
-
- ensure_selected_visible=false;
-
}
}
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 90a8af9238..f7d74b2b49 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -639,6 +639,7 @@ void LineEdit::_notification(int p_what) {
if(text.empty())
font_color.a *= placeholder_alpha;
+ int caret_height = font->get_height() > y_area ? y_area : font->get_height();
while(true) {
//end of string, break!
@@ -657,14 +658,14 @@ void LineEdit::_notification(int p_what) {
bool selected=selection.enabled && char_ofs>=selection.begin && char_ofs<selection.end;
if (selected)
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, y_area)), selection_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color);
font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color);
if (char_ofs==cursor_pos && draw_caret) {
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
- Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color );
+ Point2( x_ofs , y_ofs ), Size2( 1, caret_height ) ), cursor_color );
}
x_ofs+=char_width;
@@ -673,7 +674,7 @@ void LineEdit::_notification(int p_what) {
if (char_ofs==cursor_pos && draw_caret) {//may be at the end
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
- Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color );
+ Point2( x_ofs , y_ofs ), Size2( 1, caret_height ) ), cursor_color );
}
} break;
case NOTIFICATION_FOCUS_ENTER: {
@@ -1191,24 +1192,28 @@ void LineEdit::menu_option(int p_option) {
switch(p_option) {
case MENU_CUT: {
- cut_text();
+ if (editable) {
+ cut_text();
+ }
} break;
case MENU_COPY: {
copy_text();
} break;
case MENU_PASTE: {
-
- paste_text();
+ if (editable) {
+ paste_text();
+ }
} break;
case MENU_CLEAR: {
- clear();
+ if (editable) {
+ clear();
+ }
} break;
case MENU_SELECT_ALL: {
select_all();
} break;
case MENU_UNDO: {
-
undo();
} break;
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 9db0a66395..8a9ed98a5f 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -2542,7 +2542,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
} break;
case KEY_X: {
-
+ if (readonly) {
+ break;
+ }
if (!k.mod.command || k.mod.shift || k.mod.alt) {
scancode_handled=false;
break;
@@ -2574,7 +2576,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
undo();
} break;
case KEY_V: {
-
+ if (readonly) {
+ break;
+ }
if (!k.mod.command || k.mod.shift || k.mod.alt) {
scancode_handled=false;
break;
@@ -4527,18 +4531,22 @@ void TextEdit::menu_option(int p_option) {
switch( p_option ) {
case MENU_CUT: {
-
- cut();
+ if (!readonly) {
+ cut();
+ }
} break;
case MENU_COPY: {
copy();
} break;
case MENU_PASTE: {
-
- paste();
+ if (!readonly) {
+ paste();
+ }
} break;
case MENU_CLEAR: {
- clear();
+ if (!readonly) {
+ clear();
+ }
} break;
case MENU_SELECT_ALL: {
select_all();
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 20794b2faa..5a614fb1b2 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -32,6 +32,7 @@
#include "os/keyboard.h"
#include "globals.h"
#include "os/input.h"
+#include "scene/main/viewport.h"
@@ -829,6 +830,8 @@ void Tree::update_cache() {
cache.guide_width=get_constant("guide_width");
cache.draw_relationship_lines=get_constant("draw_relationship_lines");
cache.relationship_line_color=get_color("relationship_line_color");
+ cache.scroll_border=get_constant("scroll_border");
+ cache.scroll_speed=get_constant("scroll_speed");
cache.title_button = get_stylebox("title_button_normal");
cache.title_button_pressed = get_stylebox("title_button_pressed");
@@ -2681,11 +2684,17 @@ void Tree::_notification(int p_what) {
if (p_what==NOTIFICATION_DRAG_END) {
drop_mode_flags=0;
+ scrolling = false;
+ set_fixed_process(false);
update();
}
if (p_what==NOTIFICATION_DRAG_BEGIN) {
single_select_defer=NULL;
+ if (cache.scroll_speed > 0 && get_rect().has_point(get_viewport()->get_mouse_pos() - get_global_pos())) {
+ scrolling = true;
+ set_fixed_process(true);
+ }
}
if (p_what==NOTIFICATION_FIXED_PROCESS) {
@@ -2731,6 +2740,28 @@ void Tree::_notification(int p_what) {
}
}
+
+ if (scrolling) {
+ Point2 point = get_viewport()->get_mouse_pos() - get_global_pos();
+ if (point.x < cache.scroll_border) {
+ point.x -= cache.scroll_border;
+ } else if (point.x > get_size().width - cache.scroll_border) {
+ point.x -= get_size().width - cache.scroll_border;
+ } else {
+ point.x = 0;
+ }
+ if (point.y < cache.scroll_border) {
+ point.y -= cache.scroll_border;
+ } else if (point.y > get_size().height - cache.scroll_border) {
+ point.y -= get_size().height - cache.scroll_border;
+ } else {
+ point.y = 0;
+ }
+ point *= cache.scroll_speed * get_fixed_process_delta_time();
+ point += get_scroll();
+ h_scroll->set_val(point.x);
+ v_scroll->set_val(point.y);
+ }
}
if (p_what==NOTIFICATION_DRAW) {
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 2124dce749..6c2f1dae40 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -390,6 +390,8 @@ friend class TreeItem;
int button_margin;
Point2 offset;
int draw_relationship_lines;
+ int scroll_border;
+ int scroll_speed;
enum ClickType {
CLICK_NONE,
@@ -448,6 +450,7 @@ friend class TreeItem;
bool drag_touching_deaccel;
bool click_handled;
bool allow_rmb_select;
+ bool scrolling;
bool force_select_on_already_selected;