summaryrefslogtreecommitdiff
path: root/scene/gui/popup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/popup.cpp')
-rw-r--r--scene/gui/popup.cpp160
1 files changed, 67 insertions, 93 deletions
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 1f0daa99ba..52ad37e9ab 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -29,18 +29,14 @@
#include "popup.h"
#include "os/keyboard.h"
-
-
void Popup::_gui_input(InputEvent p_event) {
-
-
}
void Popup::_notification(int p_what) {
- if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {
+ if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (popped_up && !is_visible_in_tree()) {
- popped_up=false;
+ popped_up = false;
notification(NOTIFICATION_POPUP_HIDE);
emit_signal("popup_hide");
}
@@ -48,20 +44,18 @@ void Popup::_notification(int p_what) {
update_configuration_warning();
}
- if (p_what==NOTIFICATION_ENTER_TREE) {
- //small helper to make editing of these easier in editor
+ if (p_what == NOTIFICATION_ENTER_TREE) {
+//small helper to make editing of these easier in editor
#ifdef TOOLS_ENABLED
if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) {
set_as_toplevel(false);
}
#endif
}
-
}
void Popup::_fix_size() {
-
#if 0
Point2 pos = get_pos();
Size2 size = get_size();
@@ -73,34 +67,32 @@ void Popup::_fix_size() {
Point2 window_size = get_viewport_rect().size;
#endif
- if (pos.x+size.width > window_size.width)
- pos.x=window_size.width-size.width;
- if (pos.x<0)
- pos.x=0;
-
- if (pos.y+size.height > window_size.height)
- pos.y=window_size.height-size.height;
- if (pos.y<0)
- pos.y=0;
+ if (pos.x + size.width > window_size.width)
+ pos.x = window_size.width - size.width;
+ if (pos.x < 0)
+ pos.x = 0;
+
+ if (pos.y + size.height > window_size.height)
+ pos.y = window_size.height - size.height;
+ if (pos.y < 0)
+ pos.y = 0;
#if 0
if (pos!=get_pos())
set_pos(pos);
#else
- if (pos!=get_pos())
+ if (pos != get_pos())
set_global_pos(pos);
#endif
-
}
-
void Popup::set_as_minsize() {
Size2 total_minsize;
- for(int i=0;i<get_child_count();i++) {
+ for (int i = 0; i < get_child_count(); i++) {
- Control *c=get_child(i)->cast_to<Control>();
+ Control *c = get_child(i)->cast_to<Control>();
if (!c)
continue;
if (!c->is_visible())
@@ -108,10 +100,10 @@ void Popup::set_as_minsize() {
Size2 minsize = c->get_combined_minimum_size();
- for(int j=0;j<2;j++) {
+ for (int j = 0; j < 2; j++) {
- Margin m_beg = Margin(0+j);
- Margin m_end = Margin(2+j);
+ Margin m_beg = Margin(0 + j);
+ Margin m_end = Margin(2 + j);
float margin_begin = c->get_margin(m_beg);
float margin_end = c->get_margin(m_end);
@@ -119,29 +111,25 @@ void Popup::set_as_minsize() {
AnchorType anchor_end = c->get_anchor(m_end);
if (anchor_begin == ANCHOR_BEGIN)
- minsize[j]+=margin_begin;
+ minsize[j] += margin_begin;
if (anchor_end == ANCHOR_END)
- minsize[j]+=margin_end;
-
+ minsize[j] += margin_end;
}
- total_minsize.width = MAX( total_minsize.width, minsize.width );
- total_minsize.height = MAX( total_minsize.height, minsize.height );
+ total_minsize.width = MAX(total_minsize.width, minsize.width);
+ total_minsize.height = MAX(total_minsize.height, minsize.height);
}
set_size(total_minsize);
-
}
+void Popup::popup_centered_minsize(const Size2 &p_minsize) {
-void Popup::popup_centered_minsize(const Size2& p_minsize) {
-
-
- Size2 total_minsize=p_minsize;
+ Size2 total_minsize = p_minsize;
- for(int i=0;i<get_child_count();i++) {
+ for (int i = 0; i < get_child_count(); i++) {
- Control *c=get_child(i)->cast_to<Control>();
+ Control *c = get_child(i)->cast_to<Control>();
if (!c)
continue;
if (!c->is_visible())
@@ -149,10 +137,10 @@ void Popup::popup_centered_minsize(const Size2& p_minsize) {
Size2 minsize = c->get_combined_minimum_size();
- for(int j=0;j<2;j++) {
+ for (int j = 0; j < 2; j++) {
- Margin m_beg = Margin(0+j);
- Margin m_end = Margin(2+j);
+ Margin m_beg = Margin(0 + j);
+ Margin m_end = Margin(2 + j);
float margin_begin = c->get_margin(m_beg);
float margin_end = c->get_margin(m_end);
@@ -160,33 +148,30 @@ void Popup::popup_centered_minsize(const Size2& p_minsize) {
AnchorType anchor_end = c->get_anchor(m_end);
if (anchor_begin == ANCHOR_BEGIN)
- minsize[j]+=margin_begin;
+ minsize[j] += margin_begin;
if (anchor_end == ANCHOR_END)
- minsize[j]+=margin_end;
-
+ minsize[j] += margin_end;
}
- total_minsize.width = MAX( total_minsize.width, minsize.width );
- total_minsize.height = MAX( total_minsize.height, minsize.height );
+ total_minsize.width = MAX(total_minsize.width, minsize.width);
+ total_minsize.height = MAX(total_minsize.height, minsize.height);
}
-
- popup_centered( total_minsize );
- popped_up=true;
-
+ popup_centered(total_minsize);
+ popped_up = true;
}
-void Popup::popup_centered(const Size2& p_size) {
+void Popup::popup_centered(const Size2 &p_size) {
Point2 window_size = get_viewport_rect().size;
emit_signal("about_to_show");
Rect2 rect;
- rect.size = p_size==Size2()?get_size():p_size;
+ rect.size = p_size == Size2() ? get_size() : p_size;
- rect.pos = ((window_size-rect.size)/2.0).floor();
- set_pos( rect.pos );
- set_size( rect.size );
+ rect.pos = ((window_size - rect.size) / 2.0).floor();
+ set_pos(rect.pos);
+ set_size(rect.size);
show_modal(exclusive);
_fix_size();
@@ -197,21 +182,19 @@ void Popup::popup_centered(const Size2& p_size) {
_post_popup();
notification(NOTIFICATION_POST_POPUP);
- popped_up=true;
+ popped_up = true;
}
void Popup::popup_centered_ratio(float p_screen_ratio) {
-
-
emit_signal("about_to_show");
Rect2 rect;
Point2 window_size = get_viewport_rect().size;
rect.size = (window_size * p_screen_ratio).floor();
- rect.pos = ((window_size-rect.size)/2.0).floor();
- set_pos( rect.pos );
- set_size( rect.size );
+ rect.pos = ((window_size - rect.size) / 2.0).floor();
+ set_pos(rect.pos);
+ set_size(rect.size);
show_modal(exclusive);
_fix_size();
@@ -222,11 +205,10 @@ void Popup::popup_centered_ratio(float p_screen_ratio) {
_post_popup();
notification(NOTIFICATION_POST_POPUP);
- popped_up=true;
-
+ popped_up = true;
}
-void Popup::popup(const Rect2& bounds) {
+void Popup::popup(const Rect2 &bounds) {
emit_signal("about_to_show");
show_modal(exclusive);
@@ -245,43 +227,40 @@ void Popup::popup(const Rect2& bounds) {
_post_popup();
notification(NOTIFICATION_POST_POPUP);
- popped_up=true;
+ popped_up = true;
}
void Popup::set_exclusive(bool p_exclusive) {
- exclusive=p_exclusive;
+ exclusive = p_exclusive;
}
-bool Popup::is_exclusive() const {
+bool Popup::is_exclusive() const {
return exclusive;
}
-
void Popup::_bind_methods() {
- ClassDB::bind_method(D_METHOD("popup_centered","size"),&Popup::popup_centered,DEFVAL(Size2()));
- ClassDB::bind_method(D_METHOD("popup_centered_ratio","ratio"),&Popup::popup_centered_ratio,DEFVAL(0.75));
- ClassDB::bind_method(D_METHOD("popup_centered_minsize","minsize"),&Popup::popup_centered_minsize,DEFVAL(Size2()));
- ClassDB::bind_method(D_METHOD("popup","bounds"),&Popup::popup,DEFVAL(Rect2()));
- ClassDB::bind_method(D_METHOD("set_exclusive","enable"),&Popup::set_exclusive);
- ClassDB::bind_method(D_METHOD("is_exclusive"),&Popup::is_exclusive);
- ADD_SIGNAL( MethodInfo("about_to_show") );
- ADD_SIGNAL( MethodInfo("popup_hide") );
- ADD_GROUP("Popup","popup_");
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "popup_exclusive"), "set_exclusive","is_exclusive") ;
+ ClassDB::bind_method(D_METHOD("popup_centered", "size"), &Popup::popup_centered, DEFVAL(Size2()));
+ ClassDB::bind_method(D_METHOD("popup_centered_ratio", "ratio"), &Popup::popup_centered_ratio, DEFVAL(0.75));
+ ClassDB::bind_method(D_METHOD("popup_centered_minsize", "minsize"), &Popup::popup_centered_minsize, DEFVAL(Size2()));
+ ClassDB::bind_method(D_METHOD("popup", "bounds"), &Popup::popup, DEFVAL(Rect2()));
+ ClassDB::bind_method(D_METHOD("set_exclusive", "enable"), &Popup::set_exclusive);
+ ClassDB::bind_method(D_METHOD("is_exclusive"), &Popup::is_exclusive);
+ ADD_SIGNAL(MethodInfo("about_to_show"));
+ ADD_SIGNAL(MethodInfo("popup_hide"));
+ ADD_GROUP("Popup", "popup_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "popup_exclusive"), "set_exclusive", "is_exclusive");
BIND_CONSTANT(NOTIFICATION_POST_POPUP);
BIND_CONSTANT(NOTIFICATION_POPUP_HIDE);
-
-
}
Popup::Popup() {
set_as_toplevel(true);
- exclusive=false;
- popped_up=false;
+ exclusive = false;
+ popped_up = false;
hide();
}
@@ -294,9 +273,7 @@ String Popup::get_configuration_warning() const {
return String();
}
-Popup::~Popup()
-{
-
+Popup::~Popup() {
}
void PopupPanel::set_child_rect(Control *p_child) {
@@ -304,21 +281,18 @@ void PopupPanel::set_child_rect(Control *p_child) {
Ref<StyleBox> p = get_stylebox("panel");
p_child->set_area_as_parent_rect();
- for(int i=0;i<4;i++) {
- p_child->set_margin(Margin(i),p->get_margin(Margin(i)));
+ for (int i = 0; i < 4; i++) {
+ p_child->set_margin(Margin(i), p->get_margin(Margin(i)));
}
}
void PopupPanel::_notification(int p_what) {
+ if (p_what == NOTIFICATION_DRAW) {
- if (p_what==NOTIFICATION_DRAW) {
-
- get_stylebox("panel")->draw(get_canvas_item(),Rect2(Point2(),get_size()));
+ get_stylebox("panel")->draw(get_canvas_item(), Rect2(Point2(), get_size()));
}
}
PopupPanel::PopupPanel() {
-
-
}