added rotation and scale support to gui controls

This commit is contained in:
Juan Linietsky 2015-12-12 13:54:26 -03:00
parent cc7880fba5
commit 890b462ffb
6 changed files with 73 additions and 15 deletions

View File

@ -839,7 +839,7 @@ OS::VideoMode OS_OSX::get_default_video_mode() const {
VideoMode vm;
vm.width=1280;
vm.height=720;
vm.height=720 ;
vm.fullscreen=false;
vm.resizable=true;
return vm;

View File

@ -105,6 +105,8 @@ void Container::fit_child_in_rect(Control *p_child,const Rect2& p_rect) {
p_child->set_pos(r.pos);
p_child->set_size(r.size);
p_child->set_rotation(0);
p_child->set_scale(Vector2(1,1));
}
void Container::queue_sort() {

View File

@ -580,8 +580,8 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_DRAW: {
Matrix32 xform;
xform.set_origin(get_pos());
Matrix32 xform=Matrix32(data.rotation,get_pos());
xform.scale_basis(data.scale);
VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),xform);
VisualServer::get_singleton()->canvas_item_set_custom_rect( get_canvas_item(),true, Rect2(Point2(),get_size()));
//emit_signal(SceneStringNames::get_singleton()->draw);
@ -1927,6 +1927,7 @@ void Control::set_size(const Size2& p_size) {
data.margin[3] = _s2a( y+h, data.anchor[3], ph );
_size_changed();
}
@ -2412,9 +2413,9 @@ Control::CursorShape Control::get_cursor_shape(const Point2& p_pos) const {
Matrix32 Control::get_transform() const {
Matrix32 xf;
xf.set_origin(get_pos());
return xf;
Matrix32 xform=Matrix32(data.rotation,get_pos());
xform.scale_basis(data.scale);
return xform;
}
String Control::_get_tooltip() const {
@ -2728,6 +2729,39 @@ bool Control::is_text_field() const {
return false;
}
void Control::_set_rotation_deg(float p_rot) {
set_rotation(Math::deg2rad(p_rot));
}
float Control::_get_rotation_deg() const {
return Math::rad2deg(get_rotation());
}
void Control::set_rotation(float p_rotation) {
data.rotation=p_rotation;
update();
_notify_transform();
}
float Control::get_rotation() const{
return data.rotation;
}
void Control::set_scale(const Vector2& p_scale){
data.scale=p_scale;
update();
_notify_transform();
}
Vector2 Control::get_scale() const{
return data.scale;
}
void Control::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_window_input_event"),&Control::_window_input_event);
@ -2756,15 +2790,21 @@ void Control::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_size","size"),&Control::set_size);
ObjectTypeDB::bind_method(_MD("set_custom_minimum_size","size"),&Control::set_custom_minimum_size);
ObjectTypeDB::bind_method(_MD("set_global_pos","pos"),&Control::set_global_pos);
ObjectTypeDB::bind_method(_MD("set_rotation","rotation"),&Control::set_rotation);
ObjectTypeDB::bind_method(_MD("_set_rotation_deg","rotation"),&Control::_set_rotation_deg);
ObjectTypeDB::bind_method(_MD("set_scale","scale"),&Control::set_scale);
ObjectTypeDB::bind_method(_MD("get_margin","margin"),&Control::get_margin);
ObjectTypeDB::bind_method(_MD("get_begin"),&Control::get_begin);
ObjectTypeDB::bind_method(_MD("get_end"),&Control::get_end);
ObjectTypeDB::bind_method(_MD("get_pos"),&Control::get_pos);
ObjectTypeDB::bind_method(_MD("get_size"),&Control::get_size);
ObjectTypeDB::bind_method(_MD("get_rotation"),&Control::get_rotation);
ObjectTypeDB::bind_method(_MD("get_scale"),&Control::get_scale);
ObjectTypeDB::bind_method(_MD("get_custom_minimum_size"),&Control::get_custom_minimum_size);
ObjectTypeDB::bind_method(_MD("get_parent_area_size"),&Control::get_size);
ObjectTypeDB::bind_method(_MD("get_global_pos"),&Control::get_global_pos);
ObjectTypeDB::bind_method(_MD("get_rect"),&Control::get_rect);
ObjectTypeDB::bind_method(_MD("_get_rotation_deg"),&Control::_get_rotation_deg);
ObjectTypeDB::bind_method(_MD("get_global_rect"),&Control::get_global_rect);
ObjectTypeDB::bind_method(_MD("set_area_as_parent_rect","margin"),&Control::set_area_as_parent_rect,DEFVAL(0));
ObjectTypeDB::bind_method(_MD("show_modal","exclusive"),&Control::show_modal,DEFVAL(false));
@ -2846,6 +2886,8 @@ void Control::_bind_methods() {
ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"rect/pos", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_EDITOR), _SCS("set_pos"),_SCS("get_pos") );
ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"rect/size", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_EDITOR), _SCS("set_size"),_SCS("get_size") );
ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"rect/min_size"), _SCS("set_custom_minimum_size"),_SCS("get_custom_minimum_size") );
ADD_PROPERTYNZ( PropertyInfo(Variant::REAL,"rect/rotation",PROPERTY_HINT_RANGE,"-1080,1080,0.01"), _SCS("_set_rotation_deg"),_SCS("_get_rotation_deg") );
ADD_PROPERTYNO( PropertyInfo(Variant::VECTOR2,"rect/scale"), _SCS("set_scale"),_SCS("get_scale") );
ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"hint/tooltip", PROPERTY_HINT_MULTILINE_TEXT), _SCS("set_tooltip"),_SCS("_get_tooltip") );
ADD_PROPERTYINZ( PropertyInfo(Variant::NODE_PATH,"focus_neighbour/left" ), _SCS("set_focus_neighbour"),_SCS("get_focus_neighbour"),MARGIN_LEFT );
ADD_PROPERTYINZ( PropertyInfo(Variant::NODE_PATH,"focus_neighbour/top" ), _SCS("set_focus_neighbour"),_SCS("get_focus_neighbour"),MARGIN_TOP );
@ -2928,6 +2970,8 @@ Control::Control() {
data.v_size_flags=SIZE_FILL;
data.expand=1;
data.pending_min_size_update=false;
data.rotation=0;
data.scale=Vector2(1,1);
for (int i=0;i<4;i++) {

View File

@ -107,7 +107,10 @@ private:
float margin[4];
AnchorType anchor[4];
FocusMode focus_mode;
FocusMode focus_mode;
float rotation;
Vector2 scale;
bool pending_resize;
@ -211,6 +214,8 @@ private:
void _size_changed();
String _get_tooltip() const;
void _set_rotation_deg(float p_rot);
float _get_rotation_deg() const;
protected:
bool window_has_modal_stack() const;
@ -299,6 +304,13 @@ public:
Rect2 get_rect() const;
Rect2 get_global_rect() const;
Rect2 get_window_rect() const; ///< use with care, as it blocks waiting for the visual server
void set_rotation(float p_rotation);
float get_rotation() const;
void set_scale(const Vector2& p_scale);
Vector2 get_scale() const;
void set_area_as_parent_rect(int p_margin=0);
@ -382,7 +394,7 @@ public:
void warp_mouse(const Point2& p_to_pos);
virtual bool is_text_field() const;
virtual bool is_text_field() const;
Control();
~Control();

View File

@ -145,7 +145,7 @@ void TextureButton::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_disabled_texture","texture:Texture"),&TextureButton::set_disabled_texture);
ObjectTypeDB::bind_method(_MD("set_focused_texture","texture:Texture"),&TextureButton::set_focused_texture);
ObjectTypeDB::bind_method(_MD("set_click_mask","mask:BitMap"),&TextureButton::set_click_mask);
ObjectTypeDB::bind_method(_MD("set_scale","scale"),&TextureButton::set_scale);
ObjectTypeDB::bind_method(_MD("set_texture_scale","scale"),&TextureButton::set_texture_scale);
ObjectTypeDB::bind_method(_MD("set_modulate","color"),&TextureButton::set_modulate);
ObjectTypeDB::bind_method(_MD("get_normal_texture:Texture"),&TextureButton::get_normal_texture);
@ -154,7 +154,7 @@ void TextureButton::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_disabled_texture:Texture"),&TextureButton::get_disabled_texture);
ObjectTypeDB::bind_method(_MD("get_focused_texture:Texture"),&TextureButton::get_focused_texture);
ObjectTypeDB::bind_method(_MD("get_click_mask:BitMap"),&TextureButton::get_click_mask);
ObjectTypeDB::bind_method(_MD("get_scale"),&TextureButton::get_scale);
ObjectTypeDB::bind_method(_MD("get_texture_scale"),&TextureButton::get_texture_scale);
ObjectTypeDB::bind_method(_MD("get_modulate"),&TextureButton::get_modulate);
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/normal",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_normal_texture"), _SCS("get_normal_texture"));
@ -163,7 +163,7 @@ void TextureButton::_bind_methods() {
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/disabled",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_disabled_texture"), _SCS("get_disabled_texture"));
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/focused",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_focused_texture"), _SCS("get_focused_texture"));
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/click_mask",PROPERTY_HINT_RESOURCE_TYPE,"BitMap"), _SCS("set_click_mask"), _SCS("get_click_mask")) ;
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2,"params/scale",PROPERTY_HINT_RANGE,"0.01,1024,0.01"), _SCS("set_scale"), _SCS("get_scale"));
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2,"params/scale",PROPERTY_HINT_RANGE,"0.01,1024,0.01"), _SCS("set_texture_scale"), _SCS("set_texture_scale"));
ADD_PROPERTYNO(PropertyInfo(Variant::COLOR,"params/modulate"), _SCS("set_modulate"), _SCS("get_modulate"));
}
@ -232,14 +232,14 @@ void TextureButton::set_focused_texture(const Ref<Texture>& p_focused) {
focused = p_focused;
};
void TextureButton::set_scale(Size2 p_scale) {
void TextureButton::set_texture_scale(Size2 p_scale) {
scale=p_scale;
minimum_size_changed();
update();
}
Size2 TextureButton::get_scale() const{
Size2 TextureButton::get_texture_scale() const{
return scale;
}

View File

@ -68,8 +68,8 @@ public:
Ref<Texture> get_focused_texture() const;
Ref<BitMap> get_click_mask() const;
void set_scale(Size2 p_scale);
Size2 get_scale() const;
void set_texture_scale(Size2 p_scale);
Size2 get_texture_scale() const;
void set_modulate(const Color& p_modulate);
Color get_modulate() const;