diff options
-rw-r--r-- | core/safe_refcount.cpp | 189 | ||||
-rw-r--r-- | core/safe_refcount.h | 8 | ||||
-rw-r--r-- | editor/SCsub | 2 | ||||
-rw-r--r-- | editor/animation_editor.cpp | 1 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 3 | ||||
-rw-r--r-- | editor/property_editor.cpp | 4 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 44 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 2 | ||||
-rw-r--r-- | scene/gui/gradient_edit.cpp | 4 | ||||
-rw-r--r-- | scene/gui/slider.cpp | 7 | ||||
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 10 |
11 files changed, 209 insertions, 65 deletions
diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp index e4a5a994e6..1bd16f9e4f 100644 --- a/core/safe_refcount.cpp +++ b/core/safe_refcount.cpp @@ -33,7 +33,10 @@ #ifdef NO_THREADS -uint32_t atomic_conditional_increment(register uint32_t *pw) { +/* Bogus implementation unaware of multiprocessing */ + +template <class T> +static _ALWAYS_INLINE_ T _atomic_conditional_increment_impl(register T *pw) { if (*pw == 0) return 0; @@ -43,74 +46,202 @@ uint32_t atomic_conditional_increment(register uint32_t *pw) { return *pw; } -uint32_t atomic_increment(register uint32_t *pw) { +template <class T> +static _ALWAYS_INLINE_ T _atomic_decrement_impl(register T *pw) { + + (*pw)--; + + return *pw; +} + +template <class T> +static _ALWAYS_INLINE_T _atomic_increment_impl(register T *pw) { (*pw)++; return *pw; } -uint32_t atomic_decrement(register uint32_t *pw) { +template <class T> +static _ALWAYS_INLINE_ T _atomic_sub_impl(register T *pw, register T val) { - (*pw)--; + (*pw) -= val; return *pw; } -#else +template <class T> +static _ALWAYS_INLINE_T _atomic_add_impl(register T *pw, register T val) { -#ifdef _MSC_VER + (*pw) += val; -// don't pollute my namespace! -#include <windows.h> -uint32_t atomic_conditional_increment(register uint32_t *pw) { + return *pw; +} + +#elif defined(__GNUC__) + +/* Implementation for GCC & Clang */ + +// GCC guarantees atomic intrinsics for sizes of 1, 2, 4 and 8 bytes. +// Clang states it supports GCC atomic builtins. - /* try to increment until it actually works */ - // taken from boost +template <class T> +static _ALWAYS_INLINE_ T _atomic_conditional_increment_impl(register T *pw) { while (true) { - uint32_t tmp = static_cast<uint32_t const volatile &>(*pw); + T tmp = static_cast<T const volatile &>(*pw); if (tmp == 0) return 0; // if zero, can't add to it anymore - if (InterlockedCompareExchange((LONG volatile *)pw, tmp + 1, tmp) == tmp) + if (__sync_val_compare_and_swap(pw, tmp, tmp + 1) == tmp) return tmp + 1; } } -uint32_t atomic_decrement(register uint32_t *pw) { +template <class T> +static _ALWAYS_INLINE_ T _atomic_decrement_impl(register T *pw) { + + return __sync_sub_and_fetch(pw, 1); +} + +template <class T> +static _ALWAYS_INLINE_ T _atomic_increment_impl(register T *pw) { + + return __sync_add_and_fetch(pw, 1); +} + +template <class T> +static _ALWAYS_INLINE_ T _atomic_sub_impl(register T *pw, register T val) { + + return __sync_sub_and_fetch(pw, val); +} + +template <class T> +static _ALWAYS_INLINE_ T _atomic_add_impl(register T *pw, register T val) { + + return __sync_add_and_fetch(pw, val); +} + +#elif defined(_MSC_VER) + +/* Implementation for MSVC-Windows */ + +// don't pollute my namespace! +#include <windows.h> + +#define ATOMIC_CONDITIONAL_INCREMENT_BODY(m_pw, m_win_type, m_win_cmpxchg, m_cpp_type) \ + /* try to increment until it actually works */ \ + /* taken from boost */ \ + while (true) { \ + m_cpp_type tmp = static_cast<m_cpp_type const volatile &>(*(m_pw)); \ + if (tmp == 0) \ + return 0; /* if zero, can't add to it anymore */ \ + if (m_win_cmpxchg((m_win_type volatile *)(m_pw), tmp + 1, tmp) == tmp) \ + return tmp + 1; \ + } + +static _ALWAYS_INLINE_ uint32_t _atomic_conditional_increment_impl(register uint32_t *pw) { + + ATOMIC_CONDITIONAL_INCREMENT_BODY(pw, LONG, InterlockedCompareExchange, uint32_t) +} + +static _ALWAYS_INLINE_ uint32_t _atomic_decrement_impl(register uint32_t *pw) { + return InterlockedDecrement((LONG volatile *)pw); } -uint32_t atomic_increment(register uint32_t *pw) { +static _ALWAYS_INLINE_ uint32_t _atomic_increment_impl(register uint32_t *pw) { + return InterlockedIncrement((LONG volatile *)pw); } -#elif defined(__GNUC__) -uint32_t atomic_conditional_increment(register uint32_t *pw) { +static _ALWAYS_INLINE_ uint32_t _atomic_sub_impl(register uint32_t *pw, register uint32_t val) { - while (true) { - uint32_t tmp = static_cast<uint32_t const volatile &>(*pw); - if (tmp == 0) - return 0; // if zero, can't add to it anymore - if (__sync_val_compare_and_swap(pw, tmp, tmp + 1) == tmp) - return tmp + 1; - } +#if _WIN32_WINNT >= 0x0601 // Windows 7+ + return InterlockedExchangeSubtract(pw, val) - val; +#else + return InterlockedExchangeAdd((LONG volatile *)pw, -(int32_t)val) - val; +#endif } -uint32_t atomic_decrement(register uint32_t *pw) { +static _ALWAYS_INLINE_ uint32_t _atomic_add_impl(register uint32_t *pw, register uint32_t val) { - return __sync_sub_and_fetch(pw, 1); + return InterlockedAdd((LONG volatile *)pw, val); } -uint32_t atomic_increment(register uint32_t *pw) { +static _ALWAYS_INLINE_ uint64_t _atomic_conditional_increment_impl(register uint64_t *pw) { - return __sync_add_and_fetch(pw, 1); + ATOMIC_CONDITIONAL_INCREMENT_BODY(pw, LONGLONG, InterlockedCompareExchange64, uint64_t) +} + +static _ALWAYS_INLINE_ uint64_t _atomic_decrement_impl(register uint64_t *pw) { + + return InterlockedDecrement64((LONGLONG volatile *)pw); +} + +static _ALWAYS_INLINE_ uint64_t _atomic_increment_impl(register uint64_t *pw) { + + return InterlockedIncrement64((LONGLONG volatile *)pw); +} + +static _ALWAYS_INLINE_ uint64_t _atomic_sub_impl(register uint64_t *pw, register uint64_t val) { + +#if _WIN32_WINNT >= 0x0601 // Windows 7+ + return InterlockedExchangeSubtract64(pw, val) - val; +#else + return InterlockedExchangeAdd64((LONGLONG volatile *)pw, -(int64_t)val) - val; +#endif +} + +static _ALWAYS_INLINE_ uint64_t _atomic_add_impl(register uint64_t *pw, register uint64_t val) { + + return InterlockedAdd64((LONGLONG volatile *)pw, val); } #else + //no threads supported? #error Must provide atomic functions for this platform or compiler! #endif -#endif +// The actual advertised functions; they'll call the right implementation + +uint32_t atomic_conditional_increment(register uint32_t *counter) { + return _atomic_conditional_increment_impl(counter); +} + +uint32_t atomic_decrement(register uint32_t *pw) { + return _atomic_decrement_impl(pw); +} + +uint32_t atomic_increment(register uint32_t *pw) { + return _atomic_increment_impl(pw); +} + +uint32_t atomic_sub(register uint32_t *pw, register uint32_t val) { + return _atomic_sub_impl(pw, val); +} + +uint32_t atomic_add(register uint32_t *pw, register uint32_t val) { + return _atomic_add_impl(pw, val); +} + +uint64_t atomic_conditional_increment(register uint64_t *counter) { + return _atomic_conditional_increment_impl(counter); +} + +uint64_t atomic_decrement(register uint64_t *pw) { + return _atomic_decrement_impl(pw); +} + +uint64_t atomic_increment(register uint64_t *pw) { + return _atomic_increment_impl(pw); +} + +uint64_t atomic_sub(register uint64_t *pw, register uint64_t val) { + return _atomic_sub_impl(pw, val); +} + +uint64_t atomic_add(register uint64_t *pw, register uint64_t val) { + return _atomic_add_impl(pw, val); +} diff --git a/core/safe_refcount.h b/core/safe_refcount.h index d30f563b56..a2d2b5e127 100644 --- a/core/safe_refcount.h +++ b/core/safe_refcount.h @@ -39,6 +39,14 @@ uint32_t atomic_conditional_increment(register uint32_t *counter); uint32_t atomic_decrement(register uint32_t *pw); uint32_t atomic_increment(register uint32_t *pw); +uint32_t atomic_sub(register uint32_t *pw, register uint32_t val); +uint32_t atomic_add(register uint32_t *pw, register uint32_t val); + +uint64_t atomic_conditional_increment(register uint64_t *counter); +uint64_t atomic_decrement(register uint64_t *pw); +uint64_t atomic_increment(register uint64_t *pw); +uint64_t atomic_sub(register uint64_t *pw, register uint64_t val); +uint64_t atomic_add(register uint64_t *pw, register uint64_t val); struct SafeRefCount { diff --git a/editor/SCsub b/editor/SCsub index f0d378c097..fd56c9d772 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -268,6 +268,8 @@ def make_license_header(target, source, env): tp_license = "" tp_current = 0 + tp_licensetext.append([tp_licensename, tp_licensebody]) + about_thirdparty = "" about_tp_copyright_count = "" about_tp_license = "" diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp index 1798e66e8a..45da365695 100644 --- a/editor/animation_editor.cpp +++ b/editor/animation_editor.cpp @@ -3774,6 +3774,7 @@ AnimationKeyEditor::AnimationKeyEditor() { zoom->set_max(2.0); zoom->set_value(1.0); zoom->set_h_size_flags(SIZE_EXPAND_FILL); + zoom->set_v_size_flags(SIZE_EXPAND_FILL); zoom->set_stretch_ratio(2); hb->add_child(zoom); zoom->connect("value_changed", this, "_scroll_changed"); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 83741c7fb8..e260b1ea22 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1276,8 +1276,6 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha)); } color_panel->set_position(get_global_transform().xform(get_local_mouse_pos())); - Size2 ms = Size2(300, color_picker->get_combined_minimum_size().height + 10); - color_panel->set_size(ms); } else { have_color = false; } @@ -1360,7 +1358,6 @@ ScriptTextEditor::ScriptTextEditor() { add_child(color_panel); color_picker = memnew(ColorPicker); color_panel->add_child(color_picker); - color_panel->set_child_rect(color_picker); //NOT color_picker->connect("color_changed", this, "_color_changed"); edit_hb = memnew(HBoxContainer); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 6fac9eb652..31be4e1818 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -815,16 +815,12 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: color_picker = memnew(ColorPicker); add_child(color_picker); color_picker->hide(); - color_picker->set_area_as_parent_rect(); - for (int i = 0; i < 4; i++) - color_picker->set_margin((Margin)i, 5); color_picker->connect("color_changed", this, "_color_changed"); } color_picker->show(); color_picker->set_edit_alpha(hint != PROPERTY_HINT_COLOR_NO_ALPHA); color_picker->set_pick_color(v); - set_size(Size2(307 * EDSCALE, 460 * EDSCALE)); color_picker->set_focus_on_line_edit(); /* int ofs=80; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 9ef340edbc..faaf761598 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -50,6 +50,19 @@ void ColorPicker::_notification(int p_what) { _update_color(); } break; + case NOTIFICATION_PARENTED: { + for (int i = 0; i < 4; i++) + set_margin((Margin)i, get_constant("margin")); + } break; + + case NOTIFICATION_VISIBILITY_CHANGED: { + if (get_parent()) { + Popup *p = get_parent()->cast_to<Popup>(); + if (p) + p->set_size(Size2(get_combined_minimum_size().width + get_constant("margin") * 2, get_combined_minimum_size().height + get_constant("margin") * 2)); + } + } break; + case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: { if (screen != NULL) { if (screen->is_visible()) { @@ -254,13 +267,13 @@ void ColorPicker::_update_text_value() { } void ColorPicker::_sample_draw() { - sample->draw_rect(Rect2(Point2(), Size2(uv_edit->get_size().width, 20)), color); + sample->draw_rect(Rect2(Point2(), Size2(uv_edit->get_size().width, sample->get_size().height * 0.95)), color); } -void ColorPicker::_hsv_draw(int p_wich, Control *c) { +void ColorPicker::_hsv_draw(int p_which, Control *c) { if (!c) return; - if (p_wich == 0) { + if (p_which == 0) { Vector<Point2> points; points.push_back(Vector2()); points.push_back(Vector2(c->get_size().x, 0)); @@ -291,7 +304,7 @@ void ColorPicker::_hsv_draw(int p_wich, Control *c) { c->draw_line(Point2(x, 0), Point2(x, c->get_size().y), col.inverted()); c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted()); c->draw_line(Point2(x, y), Point2(x, y), Color(1, 1, 1), 2); - } else if (p_wich == 1) { + } else if (p_which == 1) { Ref<Texture> hue = get_icon("color_hue", "ColorPicker"); c->draw_texture_rect(hue, Rect2(Point2(), c->get_size())); int y = c->get_size().y - c->get_size().y * (1.0 - h); @@ -512,23 +525,18 @@ ColorPicker::ColorPicker() uv_edit->set_mouse_filter(MOUSE_FILTER_PASS); uv_edit->set_h_size_flags(SIZE_EXPAND_FILL); uv_edit->set_v_size_flags(SIZE_EXPAND_FILL); - Vector<Variant> args = Vector<Variant>(); - args.push_back(0); - args.push_back(uv_edit); - uv_edit->connect("draw", this, "_hsv_draw", args); + uv_edit->set_custom_minimum_size(Size2(get_constant("sv_width"), get_constant("sv_height"))); + uv_edit->connect("draw", this, "_hsv_draw", make_binds(0, uv_edit)); add_child(hb_edit); w_edit = memnew(Control); //w_edit->set_ignore_mouse(false); - w_edit->set_custom_minimum_size(Size2(30, 0)); + w_edit->set_custom_minimum_size(Size2(get_constant("h_width"), 0)); w_edit->set_h_size_flags(SIZE_FILL); w_edit->set_v_size_flags(SIZE_EXPAND_FILL); w_edit->connect("gui_input", this, "_w_input"); - args.clear(); - args.push_back(1); - args.push_back(w_edit); - w_edit->connect("draw", this, "_hsv_draw", args); + w_edit->connect("draw", this, "_hsv_draw", make_binds(1, w_edit)); hb_edit->add_child(uv_edit); hb_edit->add_child(memnew(VSeparator)); @@ -549,10 +557,12 @@ ColorPicker::ColorPicker() HBoxContainer *hbc = memnew(HBoxContainer); labels[i] = memnew(Label(lt[i])); - labels[i]->set_custom_minimum_size(Size2(10, 0)); + labels[i]->set_custom_minimum_size(Size2(get_constant("label_width"), 0)); + labels[i]->set_v_size_flags(SIZE_SHRINK_CENTER); hbc->add_child(labels[i]); scroll[i] = memnew(HSlider); + scroll[i]->set_v_size_flags(SIZE_SHRINK_CENTER); hbc->add_child(scroll[i]); values[i] = memnew(SpinBox); @@ -571,7 +581,7 @@ ColorPicker::ColorPicker() HBoxContainer *hhb = memnew(HBoxContainer); btn_mode = memnew(CheckButton); - btn_mode->set_text(TTR("RAW Mode")); + btn_mode->set_text(TTR("Raw Mode")); btn_mode->connect("toggled", this, "set_raw_mode"); hhb->add_child(btn_mode); vbr->add_child(hhb); @@ -617,9 +627,7 @@ void ColorPickerButton::_color_changed(const Color &p_color) { void ColorPickerButton::pressed() { - Size2 ms = Size2(300, picker->get_combined_minimum_size().height + 10); - popup->set_position(get_global_position() - Size2(0, ms.height)); - popup->set_size(ms); + popup->set_position(get_global_position() - picker->get_combined_minimum_size()); popup->popup(); picker->set_focus_on_line_edit(); } diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index de624fd029..1a79266409 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -79,7 +79,7 @@ private: void _update_text_value(); void _text_type_toggled(); void _sample_draw(); - void _hsv_draw(int p_wich, Control *c); + void _hsv_draw(int p_which, Control *c); void _uv_input(const Ref<InputEvent> &p_input); void _w_input(const Ref<InputEvent> &p_input); diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp index 58bce57580..22de28ea7f 100644 --- a/scene/gui/gradient_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -61,10 +61,8 @@ int GradientEdit::_get_point_from_pos(int x) { void GradientEdit::_show_color_picker() { if (grabbed == -1) return; - Size2 ms = Size2(350, picker->get_combined_minimum_size().height + 10); picker->set_pick_color(points[grabbed].color); - popup->set_position(get_global_position() - Vector2(ms.width - get_size().width, ms.height)); - popup->set_size(ms); + popup->set_position(get_global_position() - popup->get_combined_minimum_size()); popup->popup(); } diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index c84608ef2e..9ba17ce34f 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -167,7 +167,8 @@ void Slider::_notification(int p_what) { if (orientation == VERTICAL) { - style->draw(ci, Rect2i(Point2i(), Size2i(style->get_minimum_size().width + style->get_center_size().width, size.height))); + int widget_width = style->get_minimum_size().width + style->get_center_size().width; + style->draw(ci, Rect2i(Point2i(size.width / 2 - widget_width / 2, 0), Size2i(widget_width, size.height))); /* if (mouse_inside||has_focus()) focus->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height))); @@ -183,7 +184,9 @@ void Slider::_notification(int p_what) { } grabber->draw(ci, Point2i(size.width / 2 - grabber->get_size().width / 2, size.height - get_as_ratio() * areasize - grabber->get_size().height)); } else { - style->draw(ci, Rect2i(Point2i(), Size2i(size.width, style->get_minimum_size().height + style->get_center_size().height))); + + int widget_height = style->get_minimum_size().height + style->get_center_size().height; + style->draw(ci, Rect2i(Point2i(0, size.height / 2 - widget_height / 2), Size2i(size.width, widget_height))); /* if (mouse_inside||has_focus()) focus->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height))); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index d70d91a17e..3e612c745f 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -761,11 +761,11 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref< // colorPicker - t->set_constant("value_height", "ColorPicker", 23 * scale); - t->set_constant("value_width", "ColorPicker", 50 * scale); - t->set_constant("color_width", "ColorPicker", 100 * scale); - t->set_constant("label_width", "ColorPicker", 20 * scale); - t->set_constant("hseparator", "ColorPicker", 4 * scale); + t->set_constant("margin", "ColorPicker", 4 * scale); + t->set_constant("sv_width", "ColorPicker", 256 * scale); + t->set_constant("sv_height", "ColorPicker", 256 * scale); + t->set_constant("h_width", "ColorPicker", 30 * scale); + t->set_constant("label_width", "ColorPicker", 10 * scale); t->set_icon("screen_picker", "ColorPicker", make_icon(icon_color_pick_png)); t->set_icon("add_preset", "ColorPicker", make_icon(icon_add_png)); |