summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/line_edit.cpp16
-rw-r--r--scene/gui/line_edit.h1
-rw-r--r--scene/gui/spin_box.cpp34
-rw-r--r--scene/gui/spin_box.h4
-rw-r--r--scene/gui/text_edit.cpp16
-rw-r--r--scene/gui/text_edit.h2
6 files changed, 25 insertions, 48 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 299c304c5f..42d7f1b080 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -831,7 +831,6 @@ void LineEdit::_notification(int p_what) {
OS::get_singleton()->set_ime_active(true);
OS::get_singleton()->set_ime_position(get_global_position() + Point2(using_placeholder ? 0 : x_ofs, y_ofs + caret_height));
- OS::get_singleton()->set_ime_intermediate_text_callback(_ime_text_callback, this);
}
} break;
case NOTIFICATION_FOCUS_ENTER: {
@@ -843,7 +842,6 @@ void LineEdit::_notification(int p_what) {
OS::get_singleton()->set_ime_active(true);
Point2 cursor_pos = Point2(get_cursor_position(), 1) * get_minimum_size().height;
OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos);
- OS::get_singleton()->set_ime_intermediate_text_callback(_ime_text_callback, this);
if (OS::get_singleton()->has_virtual_keyboard())
OS::get_singleton()->show_virtual_keyboard(text, get_global_rect());
@@ -852,7 +850,6 @@ void LineEdit::_notification(int p_what) {
case NOTIFICATION_FOCUS_EXIT: {
OS::get_singleton()->set_ime_position(Point2());
- OS::get_singleton()->set_ime_intermediate_text_callback(NULL, NULL);
OS::get_singleton()->set_ime_active(false);
ime_text = "";
ime_selection = Point2();
@@ -861,6 +858,12 @@ void LineEdit::_notification(int p_what) {
OS::get_singleton()->hide_virtual_keyboard();
} break;
+ case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
+
+ ime_text = OS::get_singleton()->get_ime_text();
+ ime_selection = OS::get_singleton()->get_ime_selection();
+ update();
+ } break;
}
}
@@ -1461,13 +1464,6 @@ void LineEdit::set_right_icon(const Ref<Texture> &p_icon) {
update();
}
-void LineEdit::_ime_text_callback(void *p_self, String p_text, Point2 p_selection) {
- LineEdit *self = (LineEdit *)p_self;
- self->ime_text = p_text;
- self->ime_selection = p_selection;
- self->update();
-}
-
void LineEdit::_text_changed() {
if (expand_to_text_length)
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index 5294d99da0..ddcdeda8c0 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -122,7 +122,6 @@ private:
Timer *caret_blink_timer;
- static void _ime_text_callback(void *p_self, String p_text, Point2 p_selection);
void _text_changed();
void _emit_text_change();
bool expand_to_text_length;
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index ace22dddff..4f43bb0581 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -110,6 +110,9 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
range_click_timer->start();
line_edit->grab_focus();
+
+ drag.allowed = true;
+ drag.capture_pos = mb->get_position();
} break;
case BUTTON_RIGHT: {
@@ -133,14 +136,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
}
}
- if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == 1) {
-
- //set_default_cursor_shape(CURSOR_VSIZE);
- Vector2 cpos = Vector2(mb->get_position().x, mb->get_position().y);
- drag.mouse_pos = cpos;
- }
-
- if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == 1) {
+ if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
//set_default_cursor_shape(CURSOR_ARROW);
range_click_timer->stop();
@@ -150,32 +146,24 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
warp_mouse(drag.capture_pos);
}
+ drag.allowed = false;
}
Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid() && mm->get_button_mask() & 1) {
-
- Vector2 cpos = mm->get_position();
+ if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
if (drag.enabled) {
- float diff_y = drag.mouse_pos.y - cpos.y;
- diff_y = Math::pow(ABS(diff_y), 1.8f) * SGN(diff_y);
- diff_y *= 0.1;
-
- drag.mouse_pos = cpos;
- drag.base_val = CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max());
-
- set_value(drag.base_val);
-
- } else if (drag.mouse_pos.distance_to(cpos) > 2) {
+ drag.diff_y += mm->get_relative().y;
+ float diff_y = -0.01 * Math::pow(ABS(drag.diff_y), 1.8f) * SGN(drag.diff_y);
+ set_value(CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max()));
+ } else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
drag.enabled = true;
drag.base_val = get_value();
- drag.mouse_pos = cpos;
- drag.capture_pos = cpos;
+ drag.diff_y = 0;
}
}
}
diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h
index f1ee26d9f3..6425af7158 100644
--- a/scene/gui/spin_box.h
+++ b/scene/gui/spin_box.h
@@ -54,10 +54,10 @@ class SpinBox : public Range {
struct Drag {
float base_val;
+ bool allowed;
bool enabled;
- Vector2 from;
- Vector2 mouse_pos;
Vector2 capture_pos;
+ float diff_y;
} drag;
void _line_edit_focus_exit();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 18c80ba9a3..1504ad7bf1 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1438,7 +1438,6 @@ void TextEdit::_notification(int p_what) {
if (has_focus()) {
OS::get_singleton()->set_ime_active(true);
OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos + Point2(0, get_row_height()));
- OS::get_singleton()->set_ime_intermediate_text_callback(_ime_text_callback, this);
}
} break;
@@ -1451,7 +1450,6 @@ void TextEdit::_notification(int p_what) {
OS::get_singleton()->set_ime_active(true);
Point2 cursor_pos = Point2(cursor_get_column(), cursor_get_line()) * get_row_height();
OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos);
- OS::get_singleton()->set_ime_intermediate_text_callback(_ime_text_callback, this);
if (OS::get_singleton()->has_virtual_keyboard())
OS::get_singleton()->show_virtual_keyboard(get_text(), get_global_rect());
@@ -1459,7 +1457,6 @@ void TextEdit::_notification(int p_what) {
case NOTIFICATION_FOCUS_EXIT: {
OS::get_singleton()->set_ime_position(Point2());
- OS::get_singleton()->set_ime_intermediate_text_callback(NULL, NULL);
OS::get_singleton()->set_ime_active(false);
ime_text = "";
ime_selection = Point2();
@@ -1467,14 +1464,13 @@ void TextEdit::_notification(int p_what) {
if (OS::get_singleton()->has_virtual_keyboard())
OS::get_singleton()->hide_virtual_keyboard();
} break;
- }
-}
+ case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
-void TextEdit::_ime_text_callback(void *p_self, String p_text, Point2 p_selection) {
- TextEdit *self = (TextEdit *)p_self;
- self->ime_text = p_text;
- self->ime_selection = p_selection;
- self->update();
+ ime_text = OS::get_singleton()->get_ime_text();
+ ime_selection = OS::get_singleton()->get_ime_selection();
+ update();
+ } break;
+ }
}
void TextEdit::_consume_pair_symbol(CharType ch) {
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 4d398f56b6..7ecb2be6e7 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -382,8 +382,6 @@ private:
void _scroll_lines_up();
void _scroll_lines_down();
- static void _ime_text_callback(void *p_self, String p_text, Point2 p_selection);
-
//void mouse_motion(const Point& p_pos, const Point& p_rel, int p_button_mask);
Size2 get_minimum_size() const;