summaryrefslogtreecommitdiff
path: root/scene/gui/popup_menu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/popup_menu.cpp')
-rw-r--r--scene/gui/popup_menu.cpp66
1 files changed, 34 insertions, 32 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 7999f50013..89000fcde1 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "popup_menu.h"
#include "os/input.h"
#include "os/keyboard.h"
@@ -122,8 +123,7 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
for (int i = 0; i < items.size(); i++) {
- if (i > 0)
- ofs.y += vseparation;
+ ofs.y += vseparation;
float h;
if (!items[i].icon.is_null()) {
@@ -189,6 +189,26 @@ void PopupMenu::_submenu_timeout() {
submenu_over = -1;
}
+void PopupMenu::_scroll(float p_factor, const Point2 &p_over) {
+
+ const float global_y = get_global_position().y;
+
+ int vseparation = get_constant("vseparation");
+ Ref<Font> font = get_font("font");
+
+ float dy = (vseparation + font->get_height()) * 3 * p_factor;
+ if (dy > 0 && global_y < 0)
+ dy = MIN(dy, -global_y - 1);
+ else if (dy < 0 && global_y + get_size().y > get_viewport_rect().size.y)
+ dy = -MIN(-dy, global_y + get_size().y - get_viewport_rect().size.y - 1);
+ set_position(get_position() + Vector2(0, dy));
+
+ Ref<InputEventMouseMotion> ie;
+ ie.instance();
+ ie->set_position(p_over - Vector2(0, dy));
+ _gui_input(ie);
+}
+
void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
@@ -286,39 +306,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
case BUTTON_WHEEL_DOWN: {
if (get_global_position().y + get_size().y > get_viewport_rect().size.y) {
-
- int vseparation = get_constant("vseparation");
- Ref<Font> font = get_font("font");
-
- Point2 pos = get_position();
- int s = (vseparation + font->get_height()) * 3;
- pos.y -= (s * b->get_factor());
- set_position(pos);
-
- //update hover
- Ref<InputEventMouseMotion> ie;
- ie.instance();
- ie->set_position(b->get_position() + Vector2(0, s));
- _gui_input(ie);
+ _scroll(-b->get_factor(), b->get_position());
}
} break;
case BUTTON_WHEEL_UP: {
if (get_global_position().y < 0) {
-
- int vseparation = get_constant("vseparation");
- Ref<Font> font = get_font("font");
-
- Point2 pos = get_position();
- int s = (vseparation + font->get_height()) * 3;
- pos.y += (s * b->get_factor());
- set_position(pos);
-
- //update hover
- Ref<InputEventMouseMotion> ie;
- ie.instance();
- ie->set_position(b->get_position() - Vector2(0, s));
- _gui_input(ie);
+ _scroll(b->get_factor(), b->get_position());
}
} break;
case BUTTON_LEFT: {
@@ -387,6 +381,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
update();
}
}
+
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+ if (get_global_position().y + get_size().y > get_viewport_rect().size.y || get_global_position().y < 0) {
+ _scroll(-pan_gesture->get_delta().y, pan_gesture->get_position());
+ }
+ }
}
bool PopupMenu::has_point(const Point2 &p_point) const {
@@ -459,7 +460,7 @@ void PopupMenu::_notification(int p_what) {
if (i == mouse_over) {
- hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation * 2)));
+ hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation)));
}
if (items[i].separator) {
@@ -1222,9 +1223,10 @@ void PopupMenu::_bind_methods() {
ClassDB::bind_method(D_METHOD("_submenu_timeout"), &PopupMenu::_submenu_timeout);
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_items", "_get_items");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items");
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_item_selection"), "set_hide_on_item_selection", "is_hide_on_item_selection");
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_checkable_item_selection"), "set_hide_on_checkable_item_selection", "is_hide_on_checkable_item_selection");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_state_item_selection"), "set_hide_on_state_item_selection", "is_hide_on_state_item_selection");
ADD_SIGNAL(MethodInfo("id_pressed", PropertyInfo(Variant::INT, "ID")));
ADD_SIGNAL(MethodInfo("index_pressed", PropertyInfo(Variant::INT, "index")));