You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-17 14:11:06 +00:00
Bring that Whole New World to the Old Continent too
Applies the clang-format style to the 2.1 branch as done for master in
5dbf1809c6.
This commit is contained in:
@@ -28,10 +28,8 @@
|
||||
/*************************************************************************/
|
||||
#include "split_container.h"
|
||||
|
||||
#include "margin_container.h"
|
||||
#include "label.h"
|
||||
|
||||
|
||||
#include "margin_container.h"
|
||||
|
||||
struct _MinSizeCache {
|
||||
|
||||
@@ -40,235 +38,208 @@ struct _MinSizeCache {
|
||||
int final_size;
|
||||
};
|
||||
|
||||
|
||||
Control *SplitContainer::_getch(int p_idx) const {
|
||||
|
||||
int idx=0;
|
||||
int idx = 0;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
if (idx==p_idx)
|
||||
if (idx == p_idx)
|
||||
return c;
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SplitContainer::_resort() {
|
||||
|
||||
/** First pass, determine minimum size AND amount of stretchable elements */
|
||||
|
||||
int axis = vertical?1:0;
|
||||
int axis = vertical ? 1 : 0;
|
||||
|
||||
bool has_first=_getch(0);
|
||||
bool has_second=_getch(1);
|
||||
bool has_first = _getch(0);
|
||||
bool has_second = _getch(1);
|
||||
|
||||
if (!has_first && !has_second) {
|
||||
return;
|
||||
} else if (! (has_first && has_second)) {
|
||||
} else if (!(has_first && has_second)) {
|
||||
if (has_first)
|
||||
fit_child_in_rect(_getch(0),Rect2(Point2(),get_size()));
|
||||
fit_child_in_rect(_getch(0), Rect2(Point2(), get_size()));
|
||||
else
|
||||
fit_child_in_rect(_getch(1),Rect2(Point2(),get_size()));
|
||||
fit_child_in_rect(_getch(1), Rect2(Point2(), get_size()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Control *first = _getch(0);
|
||||
Control *second = _getch(1);
|
||||
|
||||
|
||||
Control *first=_getch(0);
|
||||
Control *second=_getch(1);
|
||||
|
||||
|
||||
bool ratiomode=false;
|
||||
bool expand_first_mode=false;
|
||||
|
||||
|
||||
|
||||
bool ratiomode = false;
|
||||
bool expand_first_mode = false;
|
||||
|
||||
if (vertical) {
|
||||
|
||||
ratiomode=first->get_v_size_flags()&SIZE_EXPAND && second->get_v_size_flags()&SIZE_EXPAND;
|
||||
expand_first_mode=first->get_v_size_flags()&SIZE_EXPAND && !(second->get_v_size_flags()&SIZE_EXPAND);
|
||||
ratiomode = first->get_v_size_flags() & SIZE_EXPAND && second->get_v_size_flags() & SIZE_EXPAND;
|
||||
expand_first_mode = first->get_v_size_flags() & SIZE_EXPAND && !(second->get_v_size_flags() & SIZE_EXPAND);
|
||||
} else {
|
||||
|
||||
ratiomode=first->get_h_size_flags()&SIZE_EXPAND && second->get_h_size_flags()&SIZE_EXPAND;
|
||||
expand_first_mode=first->get_h_size_flags()&SIZE_EXPAND && !(second->get_h_size_flags()&SIZE_EXPAND);
|
||||
ratiomode = first->get_h_size_flags() & SIZE_EXPAND && second->get_h_size_flags() & SIZE_EXPAND;
|
||||
expand_first_mode = first->get_h_size_flags() & SIZE_EXPAND && !(second->get_h_size_flags() & SIZE_EXPAND);
|
||||
}
|
||||
|
||||
|
||||
int sep=get_constant("separation");
|
||||
int sep = get_constant("separation");
|
||||
Ref<Texture> g = get_icon("grabber");
|
||||
|
||||
if (dragger_visibility==DRAGGER_HIDDEN_COLLAPSED) {
|
||||
sep=0;
|
||||
if (dragger_visibility == DRAGGER_HIDDEN_COLLAPSED) {
|
||||
sep = 0;
|
||||
} else {
|
||||
sep=MAX(sep,vertical?g->get_height():g->get_width());
|
||||
sep = MAX(sep, vertical ? g->get_height() : g->get_width());
|
||||
}
|
||||
|
||||
int total = vertical?get_size().height:get_size().width;
|
||||
int total = vertical ? get_size().height : get_size().width;
|
||||
|
||||
total-=sep;
|
||||
total -= sep;
|
||||
|
||||
int minimum=0;
|
||||
int minimum = 0;
|
||||
|
||||
Size2 ms_first = first->get_combined_minimum_size();
|
||||
Size2 ms_second = second->get_combined_minimum_size();
|
||||
|
||||
if (vertical) {
|
||||
|
||||
minimum=ms_first.height+ms_second.height;
|
||||
minimum = ms_first.height + ms_second.height;
|
||||
} else {
|
||||
|
||||
minimum=ms_first.width+ms_second.width;
|
||||
minimum = ms_first.width + ms_second.width;
|
||||
}
|
||||
|
||||
int available=total-minimum;
|
||||
if (available<0)
|
||||
available=0;
|
||||
int available = total - minimum;
|
||||
if (available < 0)
|
||||
available = 0;
|
||||
|
||||
|
||||
middle_sep=0;
|
||||
middle_sep = 0;
|
||||
|
||||
if (collapsed) {
|
||||
|
||||
|
||||
if (ratiomode) {
|
||||
|
||||
middle_sep=ms_first[axis]+available/2;
|
||||
|
||||
middle_sep = ms_first[axis] + available / 2;
|
||||
|
||||
} else if (expand_first_mode) {
|
||||
|
||||
middle_sep=get_size()[axis]-ms_second[axis]-sep;
|
||||
middle_sep = get_size()[axis] - ms_second[axis] - sep;
|
||||
|
||||
} else {
|
||||
|
||||
middle_sep=ms_first[axis];
|
||||
middle_sep = ms_first[axis];
|
||||
}
|
||||
|
||||
|
||||
} else if (ratiomode) {
|
||||
|
||||
if (expand_ofs<-(available/2))
|
||||
expand_ofs=-(available/2);
|
||||
else if (expand_ofs>(available/2))
|
||||
expand_ofs=(available/2);
|
||||
|
||||
middle_sep=ms_first[axis]+available/2+expand_ofs;
|
||||
if (expand_ofs < -(available / 2))
|
||||
expand_ofs = -(available / 2);
|
||||
else if (expand_ofs > (available / 2))
|
||||
expand_ofs = (available / 2);
|
||||
|
||||
middle_sep = ms_first[axis] + available / 2 + expand_ofs;
|
||||
|
||||
} else if (expand_first_mode) {
|
||||
|
||||
if (expand_ofs>0)
|
||||
expand_ofs=0;
|
||||
if (expand_ofs > 0)
|
||||
expand_ofs = 0;
|
||||
|
||||
if (expand_ofs < -available)
|
||||
expand_ofs=-available;
|
||||
expand_ofs = -available;
|
||||
|
||||
middle_sep=get_size()[axis]-ms_second[axis]-sep+expand_ofs;
|
||||
middle_sep = get_size()[axis] - ms_second[axis] - sep + expand_ofs;
|
||||
|
||||
} else {
|
||||
|
||||
if (expand_ofs<0)
|
||||
expand_ofs=0;
|
||||
if (expand_ofs < 0)
|
||||
expand_ofs = 0;
|
||||
|
||||
if (expand_ofs > available)
|
||||
expand_ofs=available;
|
||||
|
||||
middle_sep=ms_first[axis]+expand_ofs;
|
||||
expand_ofs = available;
|
||||
|
||||
middle_sep = ms_first[axis] + expand_ofs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (vertical) {
|
||||
|
||||
fit_child_in_rect(first,Rect2(Point2(0,0),Size2(get_size().width,middle_sep)));
|
||||
int sofs=middle_sep+sep;
|
||||
fit_child_in_rect(second,Rect2(Point2(0,sofs),Size2(get_size().width,get_size().height-sofs)));
|
||||
fit_child_in_rect(first, Rect2(Point2(0, 0), Size2(get_size().width, middle_sep)));
|
||||
int sofs = middle_sep + sep;
|
||||
fit_child_in_rect(second, Rect2(Point2(0, sofs), Size2(get_size().width, get_size().height - sofs)));
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
fit_child_in_rect(first,Rect2(Point2(0,0),Size2(middle_sep,get_size().height)));
|
||||
int sofs=middle_sep+sep;
|
||||
fit_child_in_rect(second,Rect2(Point2(sofs,0),Size2(get_size().width-sofs,get_size().height)));
|
||||
fit_child_in_rect(first, Rect2(Point2(0, 0), Size2(middle_sep, get_size().height)));
|
||||
int sofs = middle_sep + sep;
|
||||
fit_child_in_rect(second, Rect2(Point2(sofs, 0), Size2(get_size().width - sofs, get_size().height)));
|
||||
}
|
||||
|
||||
update();
|
||||
_change_notify("split/offset");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Size2 SplitContainer::get_minimum_size() const {
|
||||
|
||||
|
||||
/* Calculate MINIMUM SIZE */
|
||||
|
||||
Size2i minimum;
|
||||
int sep=get_constant("separation");
|
||||
int sep = get_constant("separation");
|
||||
Ref<Texture> g = get_icon("grabber");
|
||||
sep=(dragger_visibility!=DRAGGER_HIDDEN_COLLAPSED)?MAX(sep,vertical?g->get_height():g->get_width()):0;
|
||||
sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0;
|
||||
|
||||
for(int i=0;i<2;i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
||||
if (!_getch(i))
|
||||
break;
|
||||
|
||||
if (i==1) {
|
||||
if (i == 1) {
|
||||
|
||||
if (vertical)
|
||||
minimum.height+=sep;
|
||||
minimum.height += sep;
|
||||
else
|
||||
minimum.width+=sep;
|
||||
minimum.width += sep;
|
||||
}
|
||||
|
||||
Size2 ms = _getch(i)->get_combined_minimum_size();
|
||||
|
||||
if (vertical) {
|
||||
|
||||
minimum.height+=ms.height;
|
||||
minimum.width=MAX(minimum.width,ms.width);
|
||||
minimum.height += ms.height;
|
||||
minimum.width = MAX(minimum.width, ms.width);
|
||||
} else {
|
||||
|
||||
minimum.width+=ms.width;
|
||||
minimum.height=MAX(minimum.height,ms.height);
|
||||
minimum.width += ms.width;
|
||||
minimum.height = MAX(minimum.height, ms.height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return minimum;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SplitContainer::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_SORT_CHILDREN: {
|
||||
|
||||
_resort();
|
||||
} break;
|
||||
case NOTIFICATION_MOUSE_ENTER: {
|
||||
mouse_inside=true;
|
||||
mouse_inside = true;
|
||||
update();
|
||||
} break;
|
||||
case NOTIFICATION_MOUSE_EXIT: {
|
||||
mouse_inside=false;
|
||||
mouse_inside = false;
|
||||
update();
|
||||
} break;
|
||||
case NOTIFICATION_DRAW: {
|
||||
@@ -278,111 +249,105 @@ void SplitContainer::_notification(int p_what) {
|
||||
|
||||
if (collapsed || (!mouse_inside && get_constant("autohide")))
|
||||
return;
|
||||
int sep=dragger_visibility!=DRAGGER_HIDDEN_COLLAPSED?get_constant("separation"):0;
|
||||
int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_constant("separation") : 0;
|
||||
Ref<Texture> tex = get_icon("grabber");
|
||||
Size2 size=get_size();
|
||||
Size2 size = get_size();
|
||||
if (vertical) {
|
||||
|
||||
//draw_style_box( get_stylebox("bg"), Rect2(0,middle_sep,get_size().width,sep));
|
||||
if (dragger_visibility==DRAGGER_VISIBLE)
|
||||
draw_texture(tex,Point2i((size.x-tex->get_width())/2,middle_sep+(sep-tex->get_height())/2));
|
||||
if (dragger_visibility == DRAGGER_VISIBLE)
|
||||
draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2));
|
||||
|
||||
} else {
|
||||
|
||||
//draw_style_box( get_stylebox("bg"), Rect2(middle_sep,0,sep,get_size().height));
|
||||
if (dragger_visibility==DRAGGER_VISIBLE)
|
||||
draw_texture(tex,Point2i(middle_sep+(sep-tex->get_width())/2,(size.y-tex->get_height())/2));
|
||||
|
||||
if (dragger_visibility == DRAGGER_VISIBLE)
|
||||
draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void SplitContainer::_input_event(const InputEvent& p_event) {
|
||||
void SplitContainer::_input_event(const InputEvent &p_event) {
|
||||
|
||||
if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility!=DRAGGER_VISIBLE)
|
||||
if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE)
|
||||
return;
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON) {
|
||||
|
||||
const InputEventMouseButton &mb=p_event.mouse_button;
|
||||
const InputEventMouseButton &mb = p_event.mouse_button;
|
||||
|
||||
if (mb.button_index==BUTTON_LEFT) {
|
||||
if (mb.button_index == BUTTON_LEFT) {
|
||||
|
||||
if (mb.pressed) {
|
||||
int sep=get_constant("separation");
|
||||
int sep = get_constant("separation");
|
||||
|
||||
if (vertical) {
|
||||
|
||||
|
||||
if (mb.y > middle_sep && mb.y < middle_sep+sep) {
|
||||
dragging=true;
|
||||
drag_from=mb.y;
|
||||
drag_ofs=expand_ofs;
|
||||
if (mb.y > middle_sep && mb.y < middle_sep + sep) {
|
||||
dragging = true;
|
||||
drag_from = mb.y;
|
||||
drag_ofs = expand_ofs;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (mb.x > middle_sep && mb.x < middle_sep+sep) {
|
||||
dragging=true;
|
||||
drag_from=mb.x;
|
||||
drag_ofs=expand_ofs;
|
||||
if (mb.x > middle_sep && mb.x < middle_sep + sep) {
|
||||
dragging = true;
|
||||
drag_from = mb.x;
|
||||
drag_ofs = expand_ofs;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
dragging=false;
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_MOTION) {
|
||||
if (p_event.type == InputEvent::MOUSE_MOTION) {
|
||||
|
||||
const InputEventMouseMotion &mm=p_event.mouse_motion;
|
||||
const InputEventMouseMotion &mm = p_event.mouse_motion;
|
||||
|
||||
if (dragging) {
|
||||
|
||||
expand_ofs=drag_ofs+((vertical?mm.y:mm.x)-drag_from);
|
||||
expand_ofs = drag_ofs + ((vertical ? mm.y : mm.x) - drag_from);
|
||||
queue_sort();
|
||||
emit_signal("dragged",get_split_offset());
|
||||
emit_signal("dragged", get_split_offset());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Control::CursorShape SplitContainer::get_cursor_shape(const Point2& p_pos) const {
|
||||
Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const {
|
||||
|
||||
if (collapsed)
|
||||
return Control::get_cursor_shape(p_pos);
|
||||
|
||||
if (dragging)
|
||||
return (vertical?CURSOR_VSIZE:CURSOR_HSIZE);
|
||||
return (vertical ? CURSOR_VSIZE : CURSOR_HSIZE);
|
||||
|
||||
int sep=get_constant("separation");
|
||||
int sep = get_constant("separation");
|
||||
|
||||
if (vertical) {
|
||||
|
||||
|
||||
if (p_pos.y > middle_sep && p_pos.y < middle_sep+sep) {
|
||||
if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep) {
|
||||
return CURSOR_VSIZE;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (p_pos.x > middle_sep && p_pos.x < middle_sep+sep) {
|
||||
if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep) {
|
||||
return CURSOR_HSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
return Control::get_cursor_shape(p_pos);
|
||||
|
||||
}
|
||||
|
||||
void SplitContainer::set_split_offset(int p_offset) {
|
||||
|
||||
if (expand_ofs==p_offset)
|
||||
if (expand_ofs == p_offset)
|
||||
return;
|
||||
expand_ofs=p_offset;
|
||||
expand_ofs = p_offset;
|
||||
queue_sort();
|
||||
}
|
||||
|
||||
@@ -393,16 +358,15 @@ int SplitContainer::get_split_offset() const {
|
||||
|
||||
void SplitContainer::set_collapsed(bool p_collapsed) {
|
||||
|
||||
if (collapsed==p_collapsed)
|
||||
if (collapsed == p_collapsed)
|
||||
return;
|
||||
collapsed=p_collapsed;
|
||||
collapsed = p_collapsed;
|
||||
queue_sort();
|
||||
|
||||
}
|
||||
|
||||
void SplitContainer::set_dragger_visibility(DraggerVisibility p_visibility) {
|
||||
|
||||
dragger_visibility=p_visibility;
|
||||
dragger_visibility = p_visibility;
|
||||
queue_sort();
|
||||
update();
|
||||
}
|
||||
@@ -412,49 +376,41 @@ SplitContainer::DraggerVisibility SplitContainer::get_dragger_visibility() const
|
||||
return dragger_visibility;
|
||||
}
|
||||
|
||||
|
||||
bool SplitContainer::is_collapsed() const {
|
||||
|
||||
|
||||
return collapsed;
|
||||
}
|
||||
|
||||
|
||||
void SplitContainer::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&SplitContainer::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_split_offset","offset"),&SplitContainer::set_split_offset);
|
||||
ObjectTypeDB::bind_method(_MD("get_split_offset"),&SplitContainer::get_split_offset);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &SplitContainer::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_split_offset", "offset"), &SplitContainer::set_split_offset);
|
||||
ObjectTypeDB::bind_method(_MD("get_split_offset"), &SplitContainer::get_split_offset);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_collapsed","collapsed"),&SplitContainer::set_collapsed);
|
||||
ObjectTypeDB::bind_method(_MD("is_collapsed"),&SplitContainer::is_collapsed);
|
||||
ObjectTypeDB::bind_method(_MD("set_collapsed", "collapsed"), &SplitContainer::set_collapsed);
|
||||
ObjectTypeDB::bind_method(_MD("is_collapsed"), &SplitContainer::is_collapsed);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_dragger_visibility","mode"),&SplitContainer::set_dragger_visibility);
|
||||
ObjectTypeDB::bind_method(_MD("get_dragger_visibility"),&SplitContainer::get_dragger_visibility);
|
||||
ObjectTypeDB::bind_method(_MD("set_dragger_visibility", "mode"), &SplitContainer::set_dragger_visibility);
|
||||
ObjectTypeDB::bind_method(_MD("get_dragger_visibility"), &SplitContainer::get_dragger_visibility);
|
||||
|
||||
ADD_SIGNAL( MethodInfo("dragged",PropertyInfo(Variant::INT,"offset")));
|
||||
ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::INT, "offset")));
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"split/offset"),_SCS("set_split_offset"),_SCS("get_split_offset"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"split/collapsed"),_SCS("set_collapsed"),_SCS("is_collapsed"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"split/dragger_visibility",PROPERTY_HINT_ENUM,"Visible,Hidden,Hidden & Collapsed"),_SCS("set_dragger_visibility"),_SCS("get_dragger_visibility"));
|
||||
|
||||
BIND_CONSTANT( DRAGGER_VISIBLE );
|
||||
BIND_CONSTANT( DRAGGER_HIDDEN );
|
||||
BIND_CONSTANT( DRAGGER_HIDDEN_COLLAPSED );
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "split/offset"), _SCS("set_split_offset"), _SCS("get_split_offset"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "split/collapsed"), _SCS("set_collapsed"), _SCS("is_collapsed"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "split/dragger_visibility", PROPERTY_HINT_ENUM, "Visible,Hidden,Hidden & Collapsed"), _SCS("set_dragger_visibility"), _SCS("get_dragger_visibility"));
|
||||
|
||||
BIND_CONSTANT(DRAGGER_VISIBLE);
|
||||
BIND_CONSTANT(DRAGGER_HIDDEN);
|
||||
BIND_CONSTANT(DRAGGER_HIDDEN_COLLAPSED);
|
||||
}
|
||||
|
||||
SplitContainer::SplitContainer(bool p_vertical) {
|
||||
|
||||
|
||||
mouse_inside=false;
|
||||
expand_ofs=0;
|
||||
middle_sep=0;
|
||||
vertical=p_vertical;
|
||||
dragging=false;
|
||||
collapsed=false;
|
||||
dragger_visibility=DRAGGER_VISIBLE;
|
||||
|
||||
mouse_inside = false;
|
||||
expand_ofs = 0;
|
||||
middle_sep = 0;
|
||||
vertical = p_vertical;
|
||||
dragging = false;
|
||||
collapsed = false;
|
||||
dragger_visibility = DRAGGER_VISIBLE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user