diff options
author | Poommetee Ketson <poommetee@protonmail.com> | 2017-10-02 23:49:44 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-02 23:49:44 +0700 |
commit | 34ea27138072446947ee12bfcaba288f9ff825e5 (patch) | |
tree | 2ed1cb5352d2b3eb9c21102337a4f8ac8c8734aa /scene/gui | |
parent | c96fc380e5f6bd6a24a3c4a736eada7a0284975a (diff) | |
parent | 15986ea34322529637957d35ac66ad47ff936234 (diff) |
Merge pull request #11646 from djrm/pr_visual_improvements
Several visual improvements.
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/color_picker.cpp | 43 | ||||
-rw-r--r-- | scene/gui/item_list.cpp | 37 | ||||
-rw-r--r-- | scene/gui/slider.cpp | 4 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 1 | ||||
-rw-r--r-- | scene/gui/tree.h | 1 |
5 files changed, 40 insertions, 46 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 62a48ad496..e58cbe373b 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -177,29 +177,14 @@ void ColorPicker::_update_color() { void ColorPicker::_update_presets() { Size2 size = bt_add_preset->get_size(); - preset->set_custom_minimum_size(Size2(size.width * presets.size(), size.height)); - - PoolVector<uint8_t> img; - img.resize(size.x * presets.size() * size.y * 3); - - { - PoolVector<uint8_t>::Write w = img.write(); - for (int y = 0; y < size.y; y++) { - for (int x = 0; x < size.x * presets.size(); x++) { - int ofs = (y * (size.x * presets.size()) + x) * 3; - w[ofs + 0] = uint8_t(CLAMP(presets[(int)x / size.x].r * 255.0, 0, 255)); - w[ofs + 1] = uint8_t(CLAMP(presets[(int)x / size.x].g * 255.0, 0, 255)); - w[ofs + 2] = uint8_t(CLAMP(presets[(int)x / size.x].b * 255.0, 0, 255)); - } - } - } + Size2 preset_size = Size2(size.width * presets.size(), size.height); + preset->set_custom_minimum_size(preset_size); - Ref<Image> i = memnew(Image(size.x * presets.size(), size.y, false, Image::FORMAT_RGB8, img)); + preset->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), Rect2(Point2(), preset_size), true); - Ref<ImageTexture> t; - t.instance(); - t->create_from_image(i); - preset->set_texture(t); + for (int i = 0; i < presets.size(); i++) { + preset->draw_rect(Rect2(Point2(size.width * i, 0), size), presets[i]); + } } void ColorPicker::_text_type_toggled() { @@ -227,7 +212,7 @@ void ColorPicker::add_preset(const Color &p_color) { } else { presets.push_back(p_color); } - _update_presets(); + preset->update(); if (presets.size() == 10) bt_add_preset->hide(); } @@ -266,7 +251,11 @@ void ColorPicker::_update_text_value() { } void ColorPicker::_sample_draw() { - sample->draw_rect(Rect2(Point2(), Size2(uv_edit->get_size().width, sample->get_size().height * 0.95)), color); + Rect2 r = Rect2(Point2(), Size2(uv_edit->get_size().width, sample->get_size().height * 0.95)); + if (color.a < 1.0) { + sample->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), r, true); + } + sample->draw_rect(r, color); } void ColorPicker::_hsv_draw(int p_which, Control *c) { @@ -399,7 +388,7 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) { } else if (bev->is_pressed() && bev->get_button_index() == BUTTON_RIGHT) { int index = bev->get_position().x / (preset->get_size().x / presets.size()); presets.erase(presets[index]); - _update_presets(); + preset->update(); bt_add_preset->show(); } _update_color(); @@ -484,6 +473,7 @@ void ColorPicker::_bind_methods() { ClassDB::bind_method(D_METHOD("_add_preset_pressed"), &ColorPicker::_add_preset_pressed); ClassDB::bind_method(D_METHOD("_screen_pick_pressed"), &ColorPicker::_screen_pick_pressed); ClassDB::bind_method(D_METHOD("_sample_draw"), &ColorPicker::_sample_draw); + ClassDB::bind_method(D_METHOD("_update_presets"), &ColorPicker::_update_presets); ClassDB::bind_method(D_METHOD("_hsv_draw"), &ColorPicker::_hsv_draw); ClassDB::bind_method(D_METHOD("_uv_input"), &ColorPicker::_uv_input); ClassDB::bind_method(D_METHOD("_w_input"), &ColorPicker::_w_input); @@ -608,6 +598,7 @@ ColorPicker::ColorPicker() bbc->add_child(preset); //preset->set_ignore_mouse(false); preset->connect("gui_input", this, "_preset_input"); + preset->connect("draw", this, "_update_presets"); bt_add_preset = memnew(Button); bt_add_preset->set_icon(get_icon("add_preset")); @@ -636,7 +627,9 @@ void ColorPickerButton::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { Ref<StyleBox> normal = get_stylebox("normal"); - draw_rect(Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()), picker->get_pick_color()); + Rect2 r = Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()); + draw_texture_rect(Control::get_icon("bg", "ColorPickerButton"), r, true); + draw_rect(r, picker->get_pick_color()); } if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) { diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 74cc09d0a6..a034c7224f 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -524,11 +524,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { } return; - } else { - Vector<int> sItems = get_selected_items(); - for (int i = 0; i < sItems.size(); i++) { - unselect(sItems[i]); - } } } if (mb.is_valid() && mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) { @@ -750,8 +745,8 @@ void ItemList::_notification(int p_what) { Ref<StyleBox> bg = get_stylebox("bg"); int mw = scroll_bar->get_minimum_size().x; - scroll_bar->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -mw + bg->get_margin(MARGIN_RIGHT)); - scroll_bar->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -bg->get_margin(MARGIN_RIGHT)); + scroll_bar->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -mw); + scroll_bar->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); scroll_bar->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, bg->get_margin(MARGIN_TOP)); scroll_bar->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -bg->get_margin(MARGIN_BOTTOM)); @@ -838,6 +833,10 @@ void ItemList::_notification(int p_what) { if (fixed_column_width > 0) minsize.x = fixed_column_width; max_column_width = MAX(max_column_width, minsize.x); + + // elements need to adapt to the selected size + minsize.y += vseparation; + minsize.x += hseparation; items[i].rect_cache.size = minsize; items[i].min_rect_cache.size = minsize; } @@ -851,7 +850,6 @@ void ItemList::_notification(int p_what) { while (true) { //repeat util all fits - //print_line("try with "+itos(current_columns)); bool all_fit = true; Vector2 ofs; int col = 0; @@ -866,13 +864,11 @@ void ItemList::_notification(int p_what) { break; } - items[i].rect_cache = items[i].min_rect_cache; if (same_column_width) items[i].rect_cache.size.x = max_column_width; items[i].rect_cache.position = ofs; max_h = MAX(max_h, items[i].rect_cache.size.y); ofs.x += items[i].rect_cache.size.x + hseparation; - //print_line("item "+itos(i)+" ofs "+rtos(items[i].rect_cache.size.x)); col++; if (col == current_columns) { @@ -901,7 +897,6 @@ void ItemList::_notification(int p_what) { auto_height_value = ofs.y + max_h + bg->get_minimum_size().height; scroll_bar->set_max(max); scroll_bar->set_page(page); - //print_line("max: "+rtos(max)+" page "+rtos(page)); if (max <= page) { scroll_bar->set_value(0); scroll_bar->hide(); @@ -950,23 +945,23 @@ void ItemList::_notification(int p_what) { if (items[i].selected) { Rect2 r = rcache; r.position += base_ofs; + r.position.y -= vseparation / 2; + r.size.y += vseparation; + r.position.x -= hseparation / 2; + r.size.x += hseparation; - // Use stylebox to dimension potential bg color - r.position.x -= sbsel->get_margin(MARGIN_LEFT); - r.size.x += sbsel->get_margin(MARGIN_LEFT) + sbsel->get_margin(MARGIN_RIGHT); - r.position.y -= sbsel->get_margin(MARGIN_TOP); - r.size.y += sbsel->get_margin(MARGIN_TOP) + sbsel->get_margin(MARGIN_BOTTOM); draw_style_box(sbsel, r); } - if (items[i].custom_bg.a > 0.001) { - Rect2 r = rcache; r.position += base_ofs; // Size rect to make the align the temperature colors r.position.y -= vseparation / 2; r.size.y += vseparation; + r.position.x -= hseparation / 2; + r.size.x += hseparation; + draw_rect(r, items[i].custom_bg); } @@ -1103,12 +1098,16 @@ void ItemList::_notification(int p_what) { Rect2 r = rcache; r.position += base_ofs; + r.position.y -= vseparation / 2; + r.size.y += vseparation; + r.position.x -= hseparation / 2; + r.size.x += hseparation; draw_style_box(cursor, r); } } for (int i = 0; i < separators.size(); i++) { - draw_line(Vector2(bg->get_margin(MARGIN_LEFT), base_ofs.y + separators[i]), Vector2(size.width - bg->get_margin(MARGIN_LEFT), base_ofs.y + separators[i]), guide_color); + draw_line(Vector2(bg->get_margin(MARGIN_LEFT), base_ofs.y + separators[i]), Vector2(size.width - bg->get_margin(MARGIN_RIGHT), base_ofs.y + separators[i]), guide_color); } } } diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 8fda5df53c..116e0ac354 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -181,7 +181,7 @@ void Slider::_notification(int p_what) { for (int i = 0; i < ticks; i++) { if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) continue; int ofs = i * tickarea / (ticks - 1); - tick->draw(ci, Point2(0, ofs)); + tick->draw(ci, Point2i((size.width - widget_width) / 2, ofs)); } } grabber->draw(ci, Point2i(size.width / 2 - grabber->get_size().width / 2, size.height - get_as_ratio() * areasize - grabber->get_size().height)); @@ -202,7 +202,7 @@ void Slider::_notification(int p_what) { for (int i = 0; i < ticks; i++) { if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) continue; int ofs = i * tickarea / (ticks - 1); - tick->draw(ci, Point2(ofs, 0)); + tick->draw(ci, Point2i(ofs, (size.height - widget_height) / 2)); } } grabber->draw(ci, Point2i(get_as_ratio() * areasize, size.height / 2 - grabber->get_size().height / 2)); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 822136820e..613e5520a9 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -862,6 +862,7 @@ void Tree::update_cache() { cache.arrow_collapsed = get_icon("arrow_collapsed"); cache.arrow = get_icon("arrow"); cache.select_arrow = get_icon("select_arrow"); + cache.select_option = get_icon("select_option"); cache.updown = get_icon("updown"); cache.custom_button = get_stylebox("custom_button"); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index e723fa227b..2ee91a8b73 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -418,6 +418,7 @@ private: Ref<Texture> arrow_collapsed; Ref<Texture> arrow; Ref<Texture> select_arrow; + Ref<Texture> select_option; Ref<Texture> updown; Color font_color; |