1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-16 14:00:40 +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:
Rémi Verschelde
2017-03-19 00:36:26 +01:00
parent 1d418afe86
commit f8db8a3faa
1308 changed files with 147754 additions and 174357 deletions

View File

@@ -35,10 +35,9 @@ bool ScrollContainer::clips_input() const {
Size2 ScrollContainer::get_minimum_size() const {
Size2 min_size;
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>();
if (!c)
@@ -49,161 +48,150 @@ Size2 ScrollContainer::get_minimum_size() const {
continue;
Size2 minsize = c->get_combined_minimum_size();
if (!scroll_h) {
min_size.x = MAX(min_size.x, minsize.x);
}
if (!scroll_v) {
min_size.y = MAX(min_size.y, minsize.y);
}
}
if (h_scroll->is_visible()) {
min_size.y+=h_scroll->get_minimum_size().y;
min_size.y += h_scroll->get_minimum_size().y;
}
if (v_scroll->is_visible()) {
min_size.x+=v_scroll->get_minimum_size().x;
min_size.x += v_scroll->get_minimum_size().x;
}
return min_size;
};
void ScrollContainer::_cancel_drag() {
set_fixed_process(false);
drag_touching_deaccel=false;
drag_touching=false;
drag_speed=Vector2();
drag_accum=Vector2();
last_drag_accum=Vector2();
drag_from=Vector2();
drag_touching_deaccel = false;
drag_touching = false;
drag_speed = Vector2();
drag_accum = Vector2();
last_drag_accum = Vector2();
drag_from = Vector2();
}
void ScrollContainer::_input_event(const InputEvent& p_input_event) {
void ScrollContainer::_input_event(const InputEvent &p_input_event) {
switch(p_input_event.type) {
switch (p_input_event.type) {
case InputEvent::MOUSE_BUTTON: {
const InputEventMouseButton &mb=p_input_event.mouse_button;
const InputEventMouseButton &mb = p_input_event.mouse_button;
if (mb.button_index==BUTTON_WHEEL_UP && mb.pressed) {
if (h_scroll->is_visible() && !v_scroll->is_visible()){
if (mb.button_index == BUTTON_WHEEL_UP && mb.pressed) {
if (h_scroll->is_visible() && !v_scroll->is_visible()) {
// only horizontal is enabled, scroll horizontally
h_scroll->set_val( h_scroll->get_val()-h_scroll->get_page()/8 );
h_scroll->set_val(h_scroll->get_val() - h_scroll->get_page() / 8);
} else if (v_scroll->is_visible()) {
v_scroll->set_val( v_scroll->get_val()-v_scroll->get_page()/8 );
v_scroll->set_val(v_scroll->get_val() - v_scroll->get_page() / 8);
}
}
if (mb.button_index==BUTTON_WHEEL_DOWN && mb.pressed) {
if (h_scroll->is_visible() && !v_scroll->is_visible()){
if (mb.button_index == BUTTON_WHEEL_DOWN && mb.pressed) {
if (h_scroll->is_visible() && !v_scroll->is_visible()) {
// only horizontal is enabled, scroll horizontally
h_scroll->set_val( h_scroll->get_val()+h_scroll->get_page()/8 );
h_scroll->set_val(h_scroll->get_val() + h_scroll->get_page() / 8);
} else if (v_scroll->is_visible()) {
v_scroll->set_val( v_scroll->get_val()+v_scroll->get_page()/8 );
v_scroll->set_val(v_scroll->get_val() + v_scroll->get_page() / 8);
}
}
if(!OS::get_singleton()->has_touchscreen_ui_hint())
if (!OS::get_singleton()->has_touchscreen_ui_hint())
return;
if (mb.button_index!=BUTTON_LEFT)
if (mb.button_index != BUTTON_LEFT)
break;
if (mb.pressed) {
if (drag_touching) {
set_fixed_process(false);
drag_touching_deaccel=false;
drag_touching=false;
drag_speed=Vector2();
drag_accum=Vector2();
last_drag_accum=Vector2();
drag_from=Vector2();
drag_touching_deaccel = false;
drag_touching = false;
drag_speed = Vector2();
drag_accum = Vector2();
last_drag_accum = Vector2();
drag_from = Vector2();
}
if (true) {
drag_speed=Vector2();
drag_accum=Vector2();
last_drag_accum=Vector2();
drag_from=Vector2(h_scroll->get_val(),v_scroll->get_val());
drag_touching=OS::get_singleton()->has_touchscreen_ui_hint();
drag_touching_deaccel=false;
time_since_motion=0;
drag_speed = Vector2();
drag_accum = Vector2();
last_drag_accum = Vector2();
drag_from = Vector2(h_scroll->get_val(), v_scroll->get_val());
drag_touching = OS::get_singleton()->has_touchscreen_ui_hint();
drag_touching_deaccel = false;
time_since_motion = 0;
if (drag_touching) {
set_fixed_process(true);
time_since_motion=0;
time_since_motion = 0;
}
}
} else {
if (drag_touching) {
if (drag_speed==Vector2()) {
drag_touching_deaccel=false;
drag_touching=false;
if (drag_speed == Vector2()) {
drag_touching_deaccel = false;
drag_touching = false;
set_fixed_process(false);
} else {
drag_touching_deaccel=true;
drag_touching_deaccel = true;
}
}
}
} break;
case InputEvent::MOUSE_MOTION: {
const InputEventMouseMotion &mm=p_input_event.mouse_motion;
const InputEventMouseMotion &mm = p_input_event.mouse_motion;
if (drag_touching && ! drag_touching_deaccel) {
if (drag_touching && !drag_touching_deaccel) {
Vector2 motion = Vector2(mm.relative_x,mm.relative_y);
drag_accum-=motion;
Vector2 diff = drag_from+drag_accum;
Vector2 motion = Vector2(mm.relative_x, mm.relative_y);
drag_accum -= motion;
Vector2 diff = drag_from + drag_accum;
if (scroll_h)
h_scroll->set_val(diff.x);
else
drag_accum.x=0;
drag_accum.x = 0;
if (scroll_v)
v_scroll->set_val(diff.y);
else
drag_accum.y=0;
time_since_motion=0;
drag_accum.y = 0;
time_since_motion = 0;
}
} break;
}
}
void ScrollContainer::_update_scrollbar_pos() {
Size2 hmin = h_scroll->get_combined_minimum_size();
Size2 vmin = v_scroll->get_combined_minimum_size();
v_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,vmin.width);
v_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0);
v_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,0);
v_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);
v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, vmin.width);
v_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0);
v_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0);
v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0);
h_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,0);
h_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0);
h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height);
h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);
h_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 0);
h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0);
h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, hmin.height);
h_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0);
h_scroll->raise();
v_scroll->raise();
}
void ScrollContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
@@ -211,18 +199,17 @@ void ScrollContainer::_notification(int p_what) {
call_deferred("_update_scrollbar_pos");
};
if (p_what==NOTIFICATION_SORT_CHILDREN) {
if (p_what == NOTIFICATION_SORT_CHILDREN) {
child_max_size = Size2(0, 0);
Size2 size = get_size();
if (h_scroll->is_visible())
size.y-=h_scroll->get_minimum_size().y;
size.y -= h_scroll->get_minimum_size().y;
if (v_scroll->is_visible())
size.x-=h_scroll->get_minimum_size().x;
size.x -= h_scroll->get_minimum_size().x;
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>();
if (!c)
@@ -235,24 +222,23 @@ void ScrollContainer::_notification(int p_what) {
child_max_size.x = MAX(child_max_size.x, minsize.x);
child_max_size.y = MAX(child_max_size.y, minsize.y);
Rect2 r = Rect2(-scroll,minsize);
if (!scroll_h || (!h_scroll->is_visible() && c->get_h_size_flags()&SIZE_EXPAND)) {
r.pos.x=0;
if (c->get_h_size_flags()&SIZE_EXPAND)
r.size.width=MAX(size.width,minsize.width);
Rect2 r = Rect2(-scroll, minsize);
if (!scroll_h || (!h_scroll->is_visible() && c->get_h_size_flags() & SIZE_EXPAND)) {
r.pos.x = 0;
if (c->get_h_size_flags() & SIZE_EXPAND)
r.size.width = MAX(size.width, minsize.width);
else
r.size.width=minsize.width;
r.size.width = minsize.width;
}
if (!scroll_v || (!v_scroll->is_visible() && c->get_v_size_flags()&SIZE_EXPAND)) {
r.pos.y=0;
r.size.height=size.height;
if (c->get_v_size_flags()&SIZE_EXPAND)
r.size.height=MAX(size.height,minsize.height);
if (!scroll_v || (!v_scroll->is_visible() && c->get_v_size_flags() & SIZE_EXPAND)) {
r.pos.y = 0;
r.size.height = size.height;
if (c->get_v_size_flags() & SIZE_EXPAND)
r.size.height = MAX(size.height, minsize.height);
else
r.size.height=minsize.height;
r.size.height = minsize.height;
}
fit_child_in_rect(c,r);
fit_child_in_rect(c, r);
}
update();
};
@@ -261,37 +247,37 @@ void ScrollContainer::_notification(int p_what) {
update_scrollbars();
VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
}
if (p_what==NOTIFICATION_FIXED_PROCESS) {
if (p_what == NOTIFICATION_FIXED_PROCESS) {
if (drag_touching) {
if (drag_touching) {
if (drag_touching_deaccel) {
Vector2 pos = Vector2(h_scroll->get_val(),v_scroll->get_val());
pos+=drag_speed*get_fixed_process_delta_time();
Vector2 pos = Vector2(h_scroll->get_val(), v_scroll->get_val());
pos += drag_speed * get_fixed_process_delta_time();
bool turnoff_h=false;
bool turnoff_v=false;
bool turnoff_h = false;
bool turnoff_v = false;
if (pos.x<0) {
pos.x=0;
turnoff_h=true;
if (pos.x < 0) {
pos.x = 0;
turnoff_h = true;
}
if (pos.x > (h_scroll->get_max()-h_scroll->get_page())) {
pos.x=h_scroll->get_max()-h_scroll->get_page();
turnoff_h=true;
if (pos.x > (h_scroll->get_max() - h_scroll->get_page())) {
pos.x = h_scroll->get_max() - h_scroll->get_page();
turnoff_h = true;
}
if (pos.y<0) {
pos.y=0;
turnoff_v=true;
if (pos.y < 0) {
pos.y = 0;
turnoff_v = true;
}
if (pos.y > (v_scroll->get_max()-v_scroll->get_page())) {
pos.y=v_scroll->get_max()-v_scroll->get_page();
turnoff_v=true;
if (pos.y > (v_scroll->get_max() - v_scroll->get_page())) {
pos.y = v_scroll->get_max() - v_scroll->get_page();
turnoff_v = true;
}
if (scroll_h)
@@ -299,48 +285,43 @@ void ScrollContainer::_notification(int p_what) {
if (scroll_v)
v_scroll->set_val(pos.y);
float sgn_x = drag_speed.x<0? -1 : 1;
float sgn_x = drag_speed.x < 0 ? -1 : 1;
float val_x = Math::abs(drag_speed.x);
val_x-=1000*get_fixed_process_delta_time();
val_x -= 1000 * get_fixed_process_delta_time();
if (val_x<0) {
turnoff_h=true;
if (val_x < 0) {
turnoff_h = true;
}
float sgn_y = drag_speed.y<0? -1 : 1;
float sgn_y = drag_speed.y < 0 ? -1 : 1;
float val_y = Math::abs(drag_speed.y);
val_y-=1000*get_fixed_process_delta_time();
val_y -= 1000 * get_fixed_process_delta_time();
if (val_y<0) {
turnoff_v=true;
if (val_y < 0) {
turnoff_v = true;
}
drag_speed=Vector2(sgn_x*val_x,sgn_y*val_y);
drag_speed = Vector2(sgn_x * val_x, sgn_y * val_y);
if (turnoff_h && turnoff_v) {
set_fixed_process(false);
drag_touching=false;
drag_touching_deaccel=false;
drag_touching = false;
drag_touching_deaccel = false;
}
} else {
if (time_since_motion==0 || time_since_motion>0.1) {
if (time_since_motion == 0 || time_since_motion > 0.1) {
Vector2 diff = drag_accum - last_drag_accum;
last_drag_accum=drag_accum;
drag_speed=diff/get_fixed_process_delta_time();
last_drag_accum = drag_accum;
drag_speed = diff / get_fixed_process_delta_time();
}
time_since_motion+=get_fixed_process_delta_time();
time_since_motion += get_fixed_process_delta_time();
}
}
}
};
void ScrollContainer::update_scrollbars() {
@@ -355,66 +336,62 @@ void ScrollContainer::update_scrollbars() {
if (!scroll_v || min.height <= size.height - hmin.height) {
v_scroll->hide();
scroll.y=0;
scroll.y = 0;
} else {
v_scroll->show();
scroll.y=v_scroll->get_val();
scroll.y = v_scroll->get_val();
}
v_scroll->set_max(min.height);
v_scroll->set_page(size.height - hmin.height);
if (!scroll_h || min.width <= size.width - vmin.width) {
h_scroll->hide();
scroll.x=0;
scroll.x = 0;
} else {
h_scroll->show();
h_scroll->set_max(min.width);
h_scroll->set_page(size.width - vmin.width);
scroll.x=h_scroll->get_val();
scroll.x = h_scroll->get_val();
}
}
void ScrollContainer::_scroll_moved(float) {
scroll.x=h_scroll->get_val();
scroll.y=v_scroll->get_val();
scroll.x = h_scroll->get_val();
scroll.y = v_scroll->get_val();
queue_sort();
update();
};
void ScrollContainer::set_enable_h_scroll(bool p_enable) {
scroll_h=p_enable;
scroll_h = p_enable;
queue_sort();
}
bool ScrollContainer::is_h_scroll_enabled() const{
bool ScrollContainer::is_h_scroll_enabled() const {
return scroll_h;
}
void ScrollContainer::set_enable_v_scroll(bool p_enable) {
scroll_v=p_enable;
scroll_v = p_enable;
queue_sort();
}
bool ScrollContainer::is_v_scroll_enabled() const{
bool ScrollContainer::is_v_scroll_enabled() const {
return scroll_v;
}
int ScrollContainer::get_v_scroll() const {
return v_scroll->get_val();
}
void ScrollContainer::set_v_scroll(int p_pos) {
@@ -431,27 +408,24 @@ void ScrollContainer::set_h_scroll(int p_pos) {
h_scroll->set_val(p_pos);
_cancel_drag();
}
void ScrollContainer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_scroll_moved"),&ScrollContainer::_scroll_moved);
ObjectTypeDB::bind_method(_MD("_input_event"),&ScrollContainer::_input_event);
ObjectTypeDB::bind_method(_MD("set_enable_h_scroll","enable"),&ScrollContainer::set_enable_h_scroll);
ObjectTypeDB::bind_method(_MD("is_h_scroll_enabled"),&ScrollContainer::is_h_scroll_enabled);
ObjectTypeDB::bind_method(_MD("set_enable_v_scroll","enable"),&ScrollContainer::set_enable_v_scroll);
ObjectTypeDB::bind_method(_MD("is_v_scroll_enabled"),&ScrollContainer::is_v_scroll_enabled);
ObjectTypeDB::bind_method(_MD("_update_scrollbar_pos"),&ScrollContainer::_update_scrollbar_pos);
ObjectTypeDB::bind_method(_MD("set_h_scroll","val"),&ScrollContainer::set_h_scroll);
ObjectTypeDB::bind_method(_MD("get_h_scroll"),&ScrollContainer::get_h_scroll);
ObjectTypeDB::bind_method(_MD("set_v_scroll","val"),&ScrollContainer::set_v_scroll);
ObjectTypeDB::bind_method(_MD("get_v_scroll"),&ScrollContainer::get_v_scroll);
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "scroll/horizontal"), _SCS("set_enable_h_scroll"),_SCS("is_h_scroll_enabled"));
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "scroll/vertical"), _SCS("set_enable_v_scroll"),_SCS("is_v_scroll_enabled"));
ObjectTypeDB::bind_method(_MD("_scroll_moved"), &ScrollContainer::_scroll_moved);
ObjectTypeDB::bind_method(_MD("_input_event"), &ScrollContainer::_input_event);
ObjectTypeDB::bind_method(_MD("set_enable_h_scroll", "enable"), &ScrollContainer::set_enable_h_scroll);
ObjectTypeDB::bind_method(_MD("is_h_scroll_enabled"), &ScrollContainer::is_h_scroll_enabled);
ObjectTypeDB::bind_method(_MD("set_enable_v_scroll", "enable"), &ScrollContainer::set_enable_v_scroll);
ObjectTypeDB::bind_method(_MD("is_v_scroll_enabled"), &ScrollContainer::is_v_scroll_enabled);
ObjectTypeDB::bind_method(_MD("_update_scrollbar_pos"), &ScrollContainer::_update_scrollbar_pos);
ObjectTypeDB::bind_method(_MD("set_h_scroll", "val"), &ScrollContainer::set_h_scroll);
ObjectTypeDB::bind_method(_MD("get_h_scroll"), &ScrollContainer::get_h_scroll);
ObjectTypeDB::bind_method(_MD("set_v_scroll", "val"), &ScrollContainer::set_v_scroll);
ObjectTypeDB::bind_method(_MD("get_v_scroll"), &ScrollContainer::get_v_scroll);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll/horizontal"), _SCS("set_enable_h_scroll"), _SCS("is_h_scroll_enabled"));
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll/vertical"), _SCS("set_enable_v_scroll"), _SCS("is_v_scroll_enabled"));
};
ScrollContainer::ScrollContainer() {
@@ -464,15 +438,12 @@ ScrollContainer::ScrollContainer() {
v_scroll->set_name("_v_scroll");
add_child(v_scroll);
h_scroll->connect("value_changed", this,"_scroll_moved");
v_scroll->connect("value_changed", this,"_scroll_moved");
drag_speed=Vector2();
drag_touching=false;
drag_touching_deaccel=false;
scroll_h=true;
scroll_v=true;
h_scroll->connect("value_changed", this, "_scroll_moved");
v_scroll->connect("value_changed", this, "_scroll_moved");
drag_speed = Vector2();
drag_touching = false;
drag_touching_deaccel = false;
scroll_h = true;
scroll_v = true;
};