summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/color_picker.cpp45
-rw-r--r--scene/gui/color_picker.h1
-rw-r--r--scene/gui/control.cpp26
-rw-r--r--scene/gui/control.h4
-rw-r--r--scene/gui/label.cpp16
-rw-r--r--scene/gui/label.h1
-rw-r--r--scene/gui/line_edit.cpp9
-rw-r--r--scene/gui/menu_button.cpp4
-rw-r--r--scene/gui/text_edit.cpp5
-rw-r--r--scene/main/viewport.cpp35
-rw-r--r--scene/resources/default_theme/default_theme.cpp8
-rw-r--r--scene/resources/font.cpp6
-rw-r--r--scene/resources/font.h1
-rw-r--r--scene/resources/theme.cpp15
14 files changed, 143 insertions, 33 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 06f8c27957..c8bd9749df 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -140,14 +140,13 @@ void ColorPicker::_value_changed(double) {
if (updating)
return;
- for(int i=0;i<3;i++) {
+ for(int i=0;i<4;i++) {
color.components[i] = scroll[i]->get_val()/(raw_mode_enabled?1.0:255.0);
}
- color.components[3] = scroll[3]->get_val()/255.0;
set_color(color);
- c_text->set_text(color.to_html(edit_alpha && color.a<1));
+ _update_text_value();
emit_signal("color_changed",color);
@@ -174,22 +173,16 @@ void ColorPicker::_update_color() {
for(int i=0;i<4;i++) {
scroll[i]->set_max(255);
scroll[i]->set_step(0.01);
- if (raw_mode_enabled && i != 3)
+ if (raw_mode_enabled) {
+ if (i == 3)
+ scroll[i]->set_max(1);
scroll[i]->set_val(color.components[i]);
- else
- scroll[i]->set_val(color.components[i]*255);
+ } else {
+ scroll[i]->set_val(color.components[i] * 255);
+ }
}
- if (text_is_constructor) {
- String t = "Color("+String::num(color.r)+","+String::num(color.g)+","+String::num(color.b);
- if (edit_alpha && color.a<1)
- t+=(","+String::num(color.a)+")") ;
- else
- t+=")";
- c_text->set_text(t);
- } else {
- c_text->set_text(color.to_html(edit_alpha && color.a<1));
- }
+ _update_text_value();
sample->update();
updating=false;
@@ -262,6 +255,20 @@ bool ColorPicker::is_raw_mode() const {
return raw_mode_enabled;
}
+
+void ColorPicker::_update_text_value() {
+ if (text_is_constructor) {
+ String t = "Color("+String::num(color.r)+","+String::num(color.g)+","+String::num(color.b);
+ if (edit_alpha && color.a<1)
+ t+=(","+String::num(color.a)+")") ;
+ else
+ t+=")";
+ c_text->set_text(t);
+ } else {
+ c_text->set_text(color.to_html(edit_alpha && color.a<1));
+ }
+}
+
void ColorPicker::_sample_draw() {
sample->draw_rect(Rect2(Point2(),Size2(256,20)),color);
}
@@ -271,12 +278,12 @@ void ColorPicker::_hsv_draw(int p_wich,Control* c)
if (!c)
return;
if (p_wich==0) {
- int x=c->get_size().x*s;
- int y=c->get_size().y-c->get_size().y*v;
+ int x = CLAMP(c->get_size().x * s, 0, c->get_size().x);
+ int y = CLAMP(c->get_size().y-c->get_size().y * v, 0, c->get_size().y);
Color col = color;
col.a=1;
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(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) {
int y=c->get_size().y-c->get_size().y*h;
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index b9ef1f1e2f..5e2cc57274 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -80,6 +80,7 @@ private:
void _update_controls();
void _update_color();
void _update_presets();
+ void _update_text_value();
void _text_type_toggled();
void _sample_draw();
void _hsv_draw(int p_wich,Control *c);
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index fc27c0d24f..c176e50cee 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1865,7 +1865,7 @@ void Control::_modal_stack_remove() {
}
-void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner) {
+void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner,bool p_assign) {
Control *c = p_at->cast_to<Control>();
@@ -1884,15 +1884,30 @@ void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner) {
if (c) {
- c->data.theme_owner=p_owner;
+ if (p_assign) {
+ c->data.theme_owner=p_owner;
+ }
c->_notification(NOTIFICATION_THEME_CHANGED);
c->update();
}
}
+
+void Control::_theme_changed() {
+
+ _propagate_theme_changed(this,this,false);
+}
+
void Control::set_theme(const Ref<Theme>& p_theme) {
+ if (data.theme==p_theme)
+ return;
+
+ if (data.theme.is_valid()) {
+ data.theme->disconnect("changed",this,"_theme_changed");
+ }
+
data.theme=p_theme;
if (!p_theme.is_null()) {
@@ -1909,6 +1924,9 @@ void Control::set_theme(const Ref<Theme>& p_theme) {
}
+ if (data.theme.is_valid()) {
+ data.theme->connect("changed",this,"_theme_changed");
+ }
}
@@ -2448,6 +2466,10 @@ void Control::_bind_methods() {
ObjectTypeDB::bind_method(_MD("minimum_size_changed"), &Control::minimum_size_changed);
+ ObjectTypeDB::bind_method(_MD("_theme_changed"), &Control::_theme_changed);
+
+
+
ObjectTypeDB::bind_method(_MD("_font_changed"), &Control::_font_changed);
BIND_VMETHOD(MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"event")));
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 830ebd1620..1337cbc4b9 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -172,7 +172,9 @@ private:
float _get_range(int p_idx) const;
float _s2a(float p_val, AnchorType p_anchor,float p_range) const;
float _a2s(float p_val, AnchorType p_anchor,float p_range) const;
- void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner);
+ void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign=true);
+ void _theme_changed();
+
void _change_notify_margins();
void _update_minimum_size();
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 0431d824fa..4c025e92df 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -356,6 +356,21 @@ int Label::get_line_count() const {
return line_count;
}
+int Label::get_visible_line_count() const {
+
+ int line_spacing = get_constant("line_spacing");
+ int font_h = get_font("font")->get_height()+line_spacing;
+ int lines_visible = (get_size().y+line_spacing)/font_h;
+
+ if (lines_visible > line_count)
+ lines_visible = line_count;
+
+ if (max_lines_visible >= 0 && lines_visible > max_lines_visible)
+ lines_visible = max_lines_visible;
+
+ return lines_visible;
+}
+
void Label::regenerate_word_cache() {
while (word_cache) {
@@ -640,6 +655,7 @@ void Label::_bind_methods() {
ObjectTypeDB::bind_method(_MD("is_uppercase"),&Label::is_uppercase);
ObjectTypeDB::bind_method(_MD("get_line_height"),&Label::get_line_height);
ObjectTypeDB::bind_method(_MD("get_line_count"),&Label::get_line_count);
+ ObjectTypeDB::bind_method(_MD("get_visible_line_count"),&Label::get_visible_line_count);
ObjectTypeDB::bind_method(_MD("get_total_character_count"),&Label::get_total_character_count);
ObjectTypeDB::bind_method(_MD("set_visible_characters","amount"),&Label::set_visible_characters);
ObjectTypeDB::bind_method(_MD("get_visible_characters"),&Label::get_visible_characters);
diff --git a/scene/gui/label.h b/scene/gui/label.h
index 3c14add60d..b472eca1a2 100644
--- a/scene/gui/label.h
+++ b/scene/gui/label.h
@@ -132,6 +132,7 @@ public:
int get_line_height() const;
int get_line_count() const;
+ int get_visible_line_count() const;
Label(const String& p_text=String());
~Label();
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 6c47072b33..89c235e101 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -118,7 +118,7 @@ void LineEdit::_input_event(InputEvent p_event) {
const InputEventMouseMotion& m=p_event.mouse_motion;
- if (m.button_mask&1) {
+ if (m.button_mask&BUTTON_LEFT) {
if (selection.creating) {
set_cursor_at_pixel_pos(m.x);
@@ -616,11 +616,11 @@ void LineEdit::_notification(int p_what) {
} break;
case ALIGN_CENTER: {
- x_ofs=x_ofs=int(size.width-(cached_width))/2;
+ x_ofs=int(size.width-(cached_width))/2;
} break;
case ALIGN_RIGHT: {
- x_ofs=x_ofs=int(size.width-style->get_offset().x-(cached_width));
+ x_ofs=int(size.width-style->get_offset().x-(cached_width));
} break;
}
@@ -811,6 +811,9 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
if ( (pixel_ofs-p_x) < (char_w >> 1 ) ) {
ofs+=1;
+ } else if ( (pixel_ofs-p_x) > (char_w >> 1 ) ) {
+
+ ofs-=1;
}
break;
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index d6e084765d..725f1ddf17 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -28,6 +28,7 @@
/*************************************************************************/
#include "menu_button.h"
#include "os/keyboard.h"
+#include "scene/main/viewport.h"
void MenuButton::_unhandled_key_input(InputEvent p_event) {
@@ -38,6 +39,9 @@ void MenuButton::_unhandled_key_input(InputEvent p_event) {
if (!get_parent() || !is_visible() || is_disabled())
return;
+ if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this))
+ return; //ignore because of modal window
+
if (popup->activate_item_by_event(p_event))
accept_event();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 46b64ce401..50b44c55a9 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1007,12 +1007,13 @@ void TextEdit::_notification(int p_what) {
cursor_pos.y += (get_row_height() - 3);
}
+ int caret_w = (str[j]=='\t') ? cache.font->get_char_size(' ').width : char_w;
if (draw_caret) {
if (insert_mode) {
int caret_h = (block_caret) ? 4 : 1;
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(char_w,caret_h)),cache.caret_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(caret_w,caret_h)),cache.caret_color);
} else {
- int caret_w = (block_caret) ? char_w : 1;
+ caret_w = (block_caret) ? caret_w : 1;
VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(caret_w,get_row_height())),cache.caret_color);
}
}
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index bb6e6e289b..bdb2754e5e 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1346,13 +1346,21 @@ Matrix32 Viewport::_get_input_pre_xform() const {
void Viewport::_make_input_local(InputEvent& ev) {
+
switch(ev.type) {
case InputEvent::MOUSE_BUTTON: {
+ Vector2 vp_ofs;
+ if (parent_control) {
+ vp_ofs = (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin();
+ }
+
Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
Vector2 g = ai.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y));
- Vector2 l = ai.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y));
+ Vector2 l = ai.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y)-vp_ofs);
+
+
ev.mouse_button.x=l.x;
ev.mouse_button.y=l.y;
ev.mouse_button.global_x=g.x;
@@ -1361,11 +1369,18 @@ void Viewport::_make_input_local(InputEvent& ev) {
} break;
case InputEvent::MOUSE_MOTION: {
+ Vector2 vp_ofs;
+ if (parent_control) {
+ vp_ofs = (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin();
+ }
+
Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
Vector2 g = ai.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y));
- Vector2 l = ai.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y));
+ Vector2 l = ai.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y)-vp_ofs);
Vector2 r = ai.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y));
Vector2 s = ai.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_y));
+
+
ev.mouse_motion.x=l.x;
ev.mouse_motion.y=l.y;
ev.mouse_motion.global_x=g.x;
@@ -1378,16 +1393,28 @@ void Viewport::_make_input_local(InputEvent& ev) {
} break;
case InputEvent::SCREEN_TOUCH: {
+ Vector2 vp_ofs;
+ if (parent_control) {
+ vp_ofs = (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin();
+ }
+
Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
- Vector2 t = ai.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y));
+ Vector2 t = ai.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y)-vp_ofs);
+
+
ev.screen_touch.x=t.x;
ev.screen_touch.y=t.y;
} break;
case InputEvent::SCREEN_DRAG: {
+ Vector2 vp_ofs;
+ if (parent_control) {
+ vp_ofs = (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin();
+ }
+
Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
- Vector2 t = ai.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y));
+ Vector2 t = ai.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y)-vp_ofs);
Vector2 r = ai.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y));
Vector2 s = ai.basis_xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y));
ev.screen_drag.x=t.x;
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index ffc5232e8f..499cf0a169 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -54,8 +54,10 @@ static Ref<StyleBoxTexture> make_stylebox(T p_src,float p_left, float p_top, flo
texture = Ref<ImageTexture>( memnew( ImageTexture ) );
Image img(p_src);
- if (scale>1)
+ if (scale>1) {
+ img.convert(Image::FORMAT_RGBA);
img.expand_x2_hq2x();
+ }
texture->create_from_image( img,ImageTexture::FLAG_FILTER );
(*tex_cache)[p_src]=texture;
}
@@ -92,8 +94,10 @@ static Ref<Texture> make_icon(T p_src) {
Ref<ImageTexture> texture( memnew( ImageTexture ) );
Image img = Image(p_src);
- if (scale>1)
+ if (scale>1) {
+ img.convert(Image::FORMAT_RGBA);
img.expand_x2_hq2x();
+ }
texture->create_from_image( img,ImageTexture::FLAG_FILTER );
return texture;
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 6ad8a95565..1afa3fec19 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -71,6 +71,11 @@ void Font::draw(RID p_canvas_item, const Point2& p_pos, const String& p_text, co
}
}
+void Font::update_changes() {
+
+ emit_changed();
+}
+
void Font::_bind_methods() {
ObjectTypeDB::bind_method(_MD("draw","canvas_item","pos","string","modulate","clip_w"),&Font::draw,DEFVAL(Color(1,1,1)),DEFVAL(-1));
@@ -80,6 +85,7 @@ void Font::_bind_methods() {
ObjectTypeDB::bind_method(_MD("is_distance_field_hint"),&Font::is_distance_field_hint);
ObjectTypeDB::bind_method(_MD("get_string_size","string"),&Font::get_string_size);
ObjectTypeDB::bind_method(_MD("draw_char","canvas_item","pos","char","next","modulate"),&Font::draw_char,DEFVAL(-1),DEFVAL(Color(1,1,1)));
+ ObjectTypeDB::bind_method(_MD("update_changes"),&Font::update_changes);
}
diff --git a/scene/resources/font.h b/scene/resources/font.h
index 67836564cd..fe4558f9e3 100644
--- a/scene/resources/font.h
+++ b/scene/resources/font.h
@@ -61,6 +61,7 @@ public:
void draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,float p_width,const String& p_text,const Color& p_modulate=Color(1,1,1)) const;
virtual float draw_char(RID p_canvas_item, const Point2& p_pos, CharType p_char, CharType p_next=0,const Color& p_modulate=Color(1,1,1)) const=0;
+ void update_changes();
Font();
};
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index 92a6f0c0b9..b351167e10 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -219,7 +219,22 @@ Ref<Theme> Theme::get_default() {
void Theme::set_default_theme_font( const Ref<Font>& p_default_font ) {
+ if (default_theme_font==p_default_font)
+ return;
+
+ if (default_theme_font.is_valid()) {
+ _unref_font(default_theme_font);
+ }
+
default_theme_font=p_default_font;
+
+ if (default_theme_font.is_valid()) {
+ _ref_font(default_theme_font);
+ }
+
+ _change_notify();
+ emit_changed();;
+
}
Ref<Font> Theme::get_default_theme_font() const {