void SplitContainer::_resort() { /** First pass, determine minimum size AND amount of stretchable elements */ int axis = vertical?1:0; bool has_first=_getch(0); bool has_second=_getch(1); if (!has_first && !has_second) { return; } else if (! (has_first && has_second)) { if (has_first) fit_child_in_rect(_getch(0),Rect2(Point2(),get_size())); else fit_child_in_rect(_getch(1),Rect2(Point2(),get_size())); return; } Control *first=_getch(0); Control *second=_getch(1); bool ratiomode=false; bool expand_first_mode=false; if (vertical) { ratiomode=first->get_v_size_flags()&SIZE_EXPAND && second->get_v_size_flags()&SIZE_EXPAND; expand_first_mode=first->get_v_size_flags()&SIZE_EXPAND && !(second->get_v_size_flags()&SIZE_EXPAND); } else { ratiomode=first->get_h_size_flags()&SIZE_EXPAND && second->get_h_size_flags()&SIZE_EXPAND; expand_first_mode=first->get_h_size_flags()&SIZE_EXPAND && !(second->get_h_size_flags()&SIZE_EXPAND); } int sep=get_constant("separation"); Ref<Texture> g = get_icon("grabber"); if (collapsed || !dragger_visible) { sep=0; } else { sep=MAX(sep,vertical?g->get_height():g->get_width()); } int total = vertical?get_size().height:get_size().width; total-=sep; int minimum=0; Size2 ms_first = first->get_combined_minimum_size(); Size2 ms_second = second->get_combined_minimum_size(); if (vertical) { minimum=ms_first.height+ms_second.height; } else { minimum=ms_first.width+ms_second.width; } int available=total-minimum; if (available<0) available=0; middle_sep=0; if (collapsed) { if (ratiomode) { middle_sep=ms_first[axis]+available/2; } else if (expand_first_mode) { middle_sep=get_size()[axis]-ms_second[axis]-sep; } else { middle_sep=ms_first[axis]; } } else if (ratiomode) { if (expand_ofs<-(available/2)) expand_ofs=-(available/2); else if (expand_ofs>(available/2)) expand_ofs=(available/2); middle_sep=ms_first[axis]+available/2+expand_ofs; } else if (expand_first_mode) { if (expand_ofs>0) expand_ofs=0; if (expand_ofs < -available) expand_ofs=-available; middle_sep=get_size()[axis]-ms_second[axis]-sep+expand_ofs; } else { if (expand_ofs<0) expand_ofs=0; if (expand_ofs > available) expand_ofs=available; middle_sep=ms_first[axis]+expand_ofs; } if (vertical) { fit_child_in_rect(first,Rect2(Point2(0,0),Size2(get_size().width,middle_sep))); int sofs=middle_sep+sep; fit_child_in_rect(second,Rect2(Point2(0,sofs),Size2(get_size().width,get_size().height-sofs))); } else { fit_child_in_rect(first,Rect2(Point2(0,0),Size2(middle_sep,get_size().height))); int sofs=middle_sep+sep; fit_child_in_rect(second,Rect2(Point2(sofs,0),Size2(get_size().width-sofs,get_size().height))); } update(); _change_notify("split/offset"); }
void ItemListOptionButtonPlugin::add_item() { ob->add_item(vformat(TTR("Item %d"), ob->get_item_count())); _change_notify(); }
void TileSet::clear() { tile_map.clear(); _change_notify(""); emit_changed(); }
void ShaderMaterial::_shader_changed() { _change_notify(); //also all may have changed then }
void Object::property_list_changed_notify() { _change_notify(); }
virtual void erase(int p_idx) { pp->remove_item(p_idx); _change_notify();}
void Light::set_project_shadows(bool p_enabled) { shadows=p_enabled; VisualServer::get_singleton()->light_set_shadow(light, p_enabled); _change_notify("shadow"); }
void Node2D::edit_rotate(float p_rot) { angle+=p_rot; _update_transform(); _change_notify("transform/rot"); }
void GraphNode::_resort() { int sep=get_constant("separation"); Ref<StyleBox> sb=get_stylebox("frame"); bool first=true; Size2 minsize; for(int i=0;i<get_child_count();i++) { Control *c=get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; Size2i size=c->get_combined_minimum_size(); minsize.y+=size.y; minsize.x=MAX(minsize.x,size.x); if (first) first=false; else minsize.y+=sep; } int vofs=0; int w = get_size().x - sb->get_minimum_size().x; cache_y.clear(); for(int i=0;i<get_child_count();i++) { Control *c=get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; Size2i size=c->get_combined_minimum_size(); Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y); fit_child_in_rect(c,r); cache_y.push_back(vofs+size.y*0.5); if (vofs>0) vofs+=sep; vofs+=size.y; } _change_notify(); update(); connpos_dirty=true; }
void BakedLight::clear_lightmaps(){ lightmaps.clear(); _update_lightmaps(); _change_notify(); }
void ItemListItemListPlugin::erase(int p_idx) { pp->remove_item(p_idx); _change_notify(); }
void ItemListItemListPlugin::add_item() { pp->add_item(vformat(TTR("Item %d"), pp->get_item_count())); _change_notify(); }
void ItemListOptionButtonPlugin::erase(int p_idx) { ob->remove_item(p_idx); _change_notify(); }
void AudioStreamPlayer2D::_bus_layout_changed() { _change_notify(); }
void CanvasItem::_shader_changed() { _change_notify(); }
bool _set(const StringName& p_name, const Variant& p_value) { String n = p_name; if (n=="extra_space/char") char_extra_spacing=p_value; else if (n=="extra_space/space") space_extra_spacing=p_value; else if (n=="extra_space/top") top_extra_spacing=p_value; else if (n=="extra_space/bottom") bottom_extra_spacing=p_value; else if (n=="character_set/mode") { character_set=CharacterSet(int(p_value)); _change_notify(); } else if (n=="character_set/custom") custom_file=p_value; else if (n=="shadow/enabled") { shadow=p_value; _change_notify(); }else if (n=="shadow/radius") shadow_radius=p_value; else if (n=="shadow/offset") shadow_offset=p_value; else if (n=="shadow/color") shadow_color=p_value; else if (n=="shadow/transition") shadow_transition=p_value; else if (n=="shadow2/enabled") { shadow2=p_value; _change_notify(); }else if (n=="shadow2/radius") shadow2_radius=p_value; else if (n=="shadow2/offset") shadow2_offset=p_value; else if (n=="shadow2/color") shadow2_color=p_value; else if (n=="shadow2/transition") shadow2_transition=p_value; else if (n=="color/mode") { color_type=ColorType(int(p_value)); _change_notify(); }else if (n=="color/color") color=p_value; else if (n=="color/begin") gradient_begin=p_value; else if (n=="color/end") gradient_end=p_value; else if (n=="color/image") gradient_image=p_value; else if (n=="color/monochrome") color_use_monochrome=p_value; else if (n=="advanced/round_advance") round_advance=p_value; else if (n=="advanced/disable_filter") disable_filter=p_value; else return false; emit_signal("changed"); return true; }
void ImageTexture::set_data(const Ref<Image> &p_image) { VisualServer::get_singleton()->texture_set_data(texture, p_image); _change_notify(); }
void AnimatedSprite::_notification(int p_what) { switch(p_what) { case NOTIFICATION_PROCESS: { if (frames.is_null()) return; if (!frames->has_animation(animation)) return; if (frame<0) return; float speed = frames->get_animation_speed(animation); if (speed==0) return; //do nothing float remaining = get_process_delta_time(); while(remaining) { if (timeout<=0) { timeout=1.0/speed; int fc = frames->get_frame_count(animation); if (frame>=fc-1) { if (frames->get_animation_loop(animation)) { frame=0; } else { frame=fc-1; } } else { frame++; } update(); _change_notify("frame"); } float to_process = MIN(timeout,remaining); remaining-=to_process; timeout-=to_process; } } break; case NOTIFICATION_DRAW: { if (frames.is_null()) { print_line("no draw no faemos"); return; } if (frame<0) { print_line("no draw frame <0"); return; } if (!frames->has_animation(animation)) { print_line("no draw no anim: "+String(animation)); return; } Ref<Texture> texture = frames->get_frame(animation,frame); if (texture.is_null()) { print_line("no draw texture is null"); return; } //print_line("DECIDED TO DRAW"); RID ci = get_canvas_item(); /* texture->draw(ci,Point2()); break; */ Size2i s; s = texture->get_size(); Point2 ofs=offset; if (centered) ofs-=s/2; if (OS::get_singleton()->get_use_pixel_snap()) { ofs=ofs.floor(); } Rect2 dst_rect(ofs,s); if (hflip) dst_rect.size.x=-dst_rect.size.x; if (vflip) dst_rect.size.y=-dst_rect.size.y; //texture->draw_rect(ci,dst_rect,false,modulate); texture->draw_rect_region(ci,dst_rect,Rect2(Vector2(),texture->get_size()),modulate); // VisualServer::get_singleton()->canvas_item_add_texture_rect_region(ci,dst_rect,texture->get_rid(),src_rect,modulate); } break; } }
void Resource::set_name(const String& p_name) { name=p_name; _change_notify("resource/name"); }
virtual void add_item() { pp->add_item( "New Item "+itos(pp->get_item_count())); _change_notify();}
void SamplePlayer::set_sample_library(const Ref<SampleLibrary>& p_library) { library=p_library; _change_notify(); }
void Button::set_flat(bool p_flat) { flat=p_flat; update(); _change_notify("flat"); }
void CPUParticles2D::set_emission_shape(EmissionShape p_shape) { emission_shape = p_shape; _change_notify(); }
void FixedMaterial::set_uv_transform(const Transform& p_transform) { uv_transform=p_transform; VisualServer::get_singleton()->fixed_material_set_uv_transform(material, p_transform ); _change_notify(); }
void Particles2D::_process_particles(float p_delta) { if (particles.size()==0 || lifetime==0) return; p_delta*=time_scale; float frame_time=p_delta; if (emit_timeout > 0) { time_to_live -= frame_time; if (time_to_live < 0) { emitting = false; _change_notify("config/emitting"); }; }; float next_time = time+frame_time; if (next_time > lifetime) next_time=Math::fmod(next_time,lifetime); Particle *pdata=&particles[0]; int particle_count=particles.size(); Matrix32 xform; if (!local_space) xform=get_global_transform(); active_count=0; DVector<Point2>::Read r; int emission_point_count=0; if (emission_points.size()) { emission_point_count=emission_points.size(); r=emission_points.read(); } int attractor_count=0; AttractorCache *attractor_ptr=NULL; if (attractors.size()) { if (attractors.size()!=attractor_cache.size()) { attractor_cache.resize(attractors.size()); } int idx=0; Matrix32 m; if (local_space) { m= get_global_transform().affine_inverse(); } for (Set<ParticleAttractor2D*>::Element *E=attractors.front();E;E=E->next()) { attractor_cache[idx].pos=m.xform( E->get()->get_global_position() ); attractor_cache[idx].attractor=E->get(); idx++; } attractor_ptr=attractor_cache.ptr(); attractor_count=attractor_cache.size(); } for(int i=0;i<particle_count;i++) { Particle &p=pdata[i]; float restart_time = (i * lifetime / particle_count) * explosiveness; bool restart=false; if ( next_time < time ) { if (restart_time > time || restart_time < next_time ) restart=true; } else if (restart_time > time && restart_time < next_time ) { restart=true; } if (restart) { if (emitting) { p.pos=emissor_offset; if (emission_point_count) { Vector2 ep = r[Math::rand()%emission_point_count]; if (!local_space) { p.pos=xform.xform(p.pos+ep*extents); } else { p.pos+=ep*extents; } } else { if (!local_space) { p.pos=xform.xform(p.pos+Vector2(Math::random(-extents.x,extents.x),Math::random(-extents.y,extents.y))); } else { p.pos+=Vector2(Math::random(-extents.x,extents.x),Math::random(-extents.y,extents.y)); } } p.seed=Math::rand() % 12345678; uint32_t rand_seed=p.seed*(i+1); float angle = Math::deg2rad(param[PARAM_DIRECTION]+_rand_from_seed(&rand_seed)*param[PARAM_SPREAD]); p.velocity=Vector2( Math::sin(angle), Math::cos(angle) ); if (!local_space) { p.velocity = xform.basis_xform(p.velocity).normalized(); } p.velocity*=param[PARAM_LINEAR_VELOCITY]+param[PARAM_LINEAR_VELOCITY]*_rand_from_seed(&rand_seed)*randomness[PARAM_LINEAR_VELOCITY]; p.velocity+=initial_velocity; p.active=true; p.rot=Math::deg2rad(param[PARAM_INITIAL_ANGLE]+param[PARAM_INITIAL_ANGLE]*randomness[PARAM_INITIAL_ANGLE]*_rand_from_seed(&rand_seed)); active_count++; p.frame=Math::fmod(param[PARAM_ANIM_INITIAL_POS]+randomness[PARAM_ANIM_INITIAL_POS]*_rand_from_seed(&rand_seed),1.0); } else { p.active=false; } } else { if (!p.active) continue; uint32_t rand_seed=p.seed*(i+1); Vector2 force; //apply gravity float gravity_dir = Math::deg2rad( param[PARAM_GRAVITY_DIRECTION]+180*randomness[PARAM_GRAVITY_DIRECTION]*_rand_from_seed(&rand_seed)); force+=Vector2( Math::sin(gravity_dir), Math::cos(gravity_dir) ) * (param[PARAM_GRAVITY_STRENGTH]+param[PARAM_GRAVITY_STRENGTH]*randomness[PARAM_GRAVITY_STRENGTH]*_rand_from_seed(&rand_seed)); //apply radial Vector2 rvec = (p.pos - emissor_offset).normalized(); force+=rvec*(param[PARAM_RADIAL_ACCEL]+param[PARAM_RADIAL_ACCEL]*randomness[PARAM_RADIAL_ACCEL]*_rand_from_seed(&rand_seed)); //apply orbit float orbitvel = (param[PARAM_ORBIT_VELOCITY]+param[PARAM_ORBIT_VELOCITY]*randomness[PARAM_ORBIT_VELOCITY]*_rand_from_seed(&rand_seed)); if (orbitvel!=0) { Vector2 rel = p.pos - xform.elements[2]; Matrix32 rot(orbitvel*frame_time,Vector2()); p.pos = rot.xform(rel) + xform.elements[2]; } Vector2 tvec=rvec.tangent(); force+=tvec*(param[PARAM_TANGENTIAL_ACCEL]+param[PARAM_TANGENTIAL_ACCEL]*randomness[PARAM_TANGENTIAL_ACCEL]*_rand_from_seed(&rand_seed)); for(int j=0;j<attractor_count;j++) { Vector2 vec = (attractor_ptr[j].pos - p.pos); float vl = vec.length(); if (!attractor_ptr[j].attractor->enabled || vl==0 || vl > attractor_ptr[j].attractor->radius) continue; force+=vec*attractor_ptr[j].attractor->gravity; float fvl = p.velocity.length(); if (fvl && attractor_ptr[j].attractor->absorption) { Vector2 target = vec.normalized(); p.velocity = p.velocity.normalized().linear_interpolate(target,MIN(frame_time*attractor_ptr[j].attractor->absorption,1))*fvl; } if (attractor_ptr[j].attractor->disable_radius && vl < attractor_ptr[j].attractor->disable_radius) { p.active=false; } } p.velocity+=force*frame_time; if (param[PARAM_DAMPING]) { float dmp = param[PARAM_DAMPING]+param[PARAM_DAMPING]*randomness[PARAM_DAMPING]*_rand_from_seed(&rand_seed); float v = p.velocity.length(); v -= dmp * frame_time; if (v<=0) { p.velocity=Vector2(); } else { p.velocity=p.velocity.normalized() * v; } } p.pos+=p.velocity*frame_time; p.rot+=Math::lerp(param[PARAM_SPIN_VELOCITY],param[PARAM_SPIN_VELOCITY]*randomness[PARAM_SPIN_VELOCITY]*_rand_from_seed(&rand_seed),randomness[PARAM_SPIN_VELOCITY])*frame_time; float anim_spd=param[PARAM_ANIM_SPEED_SCALE]+param[PARAM_ANIM_SPEED_SCALE]*randomness[PARAM_ANIM_SPEED_SCALE]*_rand_from_seed(&rand_seed); p.frame=Math::fposmod(p.frame+(frame_time/lifetime)*anim_spd,1.0); active_count++; } } time=Math::fmod( time+frame_time, lifetime ); if (!emitting && active_count==0) { set_process(false); } update(); }
void Material::set_line_width(float p_width) { line_width=p_width; VisualServer::get_singleton()->material_set_line_width(material,p_width); _change_notify("line_width"); }
bool VisualScriptInputFilter::_set(const StringName& p_name, const Variant& p_value) { if (p_name=="filter_count") { filters.resize(p_value); _change_notify(); ports_changed_notify(); return true; } if (String(p_name).begins_with("filter_")) { int idx = String(p_name).replace_first("filters_","").get_slice("/",0).to_int(); ERR_FAIL_INDEX_V(idx,filters.size(),false); String what = String(p_name).get_slice("/",1); if (what=="type") { filters[idx]=InputEvent(); filters[idx].type=InputEvent::Type(int(p_value)); if (filters[idx].type==InputEvent::JOYSTICK_MOTION) { filters[idx].joy_motion.axis_value=0.5; //for treshold } else if (filters[idx].type==InputEvent::KEY) { filters[idx].key.pressed=true; //put these as true to make it more user friendly } else if (filters[idx].type==InputEvent::MOUSE_BUTTON) { filters[idx].mouse_button.pressed=true; } else if (filters[idx].type==InputEvent::JOYSTICK_BUTTON) { filters[idx].joy_button.pressed=true; } else if (filters[idx].type==InputEvent::SCREEN_TOUCH) { filters[idx].screen_touch.pressed=true; } else if (filters[idx].type==InputEvent::ACTION) { filters[idx].action.pressed=true; } _change_notify(); ports_changed_notify(); return true; } if (what=="device") { filters[idx].device=p_value; ports_changed_notify(); return true; } switch(filters[idx].type) { case InputEvent::KEY: { if (what=="scancode") { String sc = p_value; if (sc==String()) { filters[idx].key.scancode=0; } else { filters[idx].key.scancode=find_keycode(p_value); } } else if (what=="unicode") { String uc = p_value; if (uc==String()) { filters[idx].key.unicode=0; } else { filters[idx].key.unicode=uc[0]; } } else if (what=="pressed") { filters[idx].key.pressed=p_value; } else if (what=="echo") { filters[idx].key.echo=p_value; } else if (what=="mod_alt") { filters[idx].key.mod.alt=p_value; } else if (what=="mod_shift") { filters[idx].key.mod.shift=p_value; } else if (what=="mod_ctrl") { filters[idx].key.mod.control=p_value; } else if (what=="mod_meta") { filters[idx].key.mod.meta=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::MOUSE_MOTION: { if (what=="button_mask") { filters[idx].mouse_motion.button_mask=p_value; } else if (what=="mod_alt") { filters[idx].mouse_motion.mod.alt=p_value; } else if (what=="mod_shift") { filters[idx].mouse_motion.mod.shift=p_value; } else if (what=="mod_ctrl") { filters[idx].mouse_motion.mod.control=p_value; } else if (what=="mod_meta") { filters[idx].mouse_motion.mod.meta=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::MOUSE_BUTTON: { if (what=="button_index") { filters[idx].mouse_button.button_index=p_value; } else if (what=="pressed") { filters[idx].mouse_button.pressed=p_value; } else if (what=="doubleclicked") { filters[idx].mouse_button.doubleclick=p_value; } else if (what=="mod_alt") { filters[idx].mouse_button.mod.alt=p_value; } else if (what=="mod_shift") { filters[idx].mouse_button.mod.shift=p_value; } else if (what=="mod_ctrl") { filters[idx].mouse_button.mod.control=p_value; } else if (what=="mod_meta") { filters[idx].mouse_button.mod.meta=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::JOYSTICK_MOTION: { if (what=="axis") { filters[idx].joy_motion.axis=int(p_value)<<1|filters[idx].joy_motion.axis; } else if (what=="mode") { filters[idx].joy_motion.axis|=int(p_value); } else if (what=="treshold") { filters[idx].joy_motion.axis_value=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::JOYSTICK_BUTTON: { if (what=="button_index") { filters[idx].joy_button.button_index=p_value; } else if (what=="pressed") { filters[idx].joy_button.pressed=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::SCREEN_TOUCH: { if (what=="finger_index") { filters[idx].screen_touch.index=p_value; } else if (what=="pressed") { filters[idx].screen_touch.pressed=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::SCREEN_DRAG: { if (what=="finger_index") { filters[idx].screen_drag.index=p_value; } else { return false; } ports_changed_notify(); return true; } break; case InputEvent::ACTION: { if (what=="action_name") { List<PropertyInfo> pinfo; Globals::get_singleton()->get_property_list(&pinfo); int index=1; for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { const PropertyInfo &pi=E->get(); if (!pi.name.begins_with("input/")) continue; String name = pi.name.substr(pi.name.find("/")+1,pi.name.length()); if (name==String(p_value)) { filters[idx].action.action=index; ports_changed_notify(); return true; } index++; } filters[idx].action.action=0; ports_changed_notify(); return false; } else if (what=="pressed") { filters[idx].action.pressed=p_value; ports_changed_notify(); return true; } } break; } } return false; }
void notify_changed() { _change_notify(); }
void update() { _change_notify(); }