bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask) { if (p_result_max <= 0) return 0; Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape, 0); Rect2 aabb = p_shape_xform.xform(shape->get_aabb()); aabb = aabb.merge(Rect2(aabb.position + p_motion, aabb.size)); //motion aabb = aabb.grow(p_margin); int amount = space->broadphase->cull_aabb(aabb, space->intersection_query_results, Space2DSW::INTERSECTION_QUERY_MAX, space->intersection_query_subindex_results); bool collided = false; r_result_count = 0; Physics2DServerSW::CollCbkData cbk; cbk.max = p_result_max; cbk.amount = 0; cbk.ptr = r_results; CollisionSolver2DSW::CallbackResult cbkres = NULL; Physics2DServerSW::CollCbkData *cbkptr = NULL; if (p_result_max > 0) { cbkptr = &cbk; cbkres = Physics2DServerSW::_shape_col_cbk; } for (int i = 0; i < amount; i++) { if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) continue; const CollisionObject2DSW *col_obj = space->intersection_query_results[i]; int shape_idx = space->intersection_query_subindex_results[i]; if (p_exclude.has(col_obj->get_self())) continue; cbk.valid_dir = Vector2(); cbk.valid_depth = 0; if (CollisionSolver2DSW::solve(shape, p_shape_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), cbkres, cbkptr, NULL, p_margin)) { collided = p_result_max == 0 || cbk.amount > 0; } } r_result_count = cbk.amount; return collided; }
Rect2 AnimatedSprite3D::get_item_rect() const { if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) { return Rect2(0, 0, 1, 1); } Ref<Texture> t; if (animation) t = frames->get_frame(animation, frame); if (t.is_null()) return Rect2(0, 0, 1, 1); Size2i s = t->get_size(); Point2 ofs = get_offset(); if (centered) ofs -= s / 2; if (s == Size2(0, 0)) s = Size2(1, 1); return Rect2(ofs, s); }
void PopupMenu::_activate_submenu(int over) { Node* n = get_node(items[over].submenu); ERR_EXPLAIN("item subnode does not exist: "+items[over].submenu); ERR_FAIL_COND(!n); Popup *pm = n->cast_to<Popup>(); ERR_EXPLAIN("item subnode is not a Popup: "+items[over].submenu); ERR_FAIL_COND(!pm); if (pm->is_visible()) return; //already visible! Point2 p = get_global_pos(); Rect2 pr(p,get_size()); Ref<StyleBox> style = get_stylebox("panel"); Point2 pos = p+Point2(get_size().width,items[over]._ofs_cache-style->get_offset().y); Size2 size = pm->get_size(); // fix pos if (pos.x+size.width > get_viewport_rect().size.width) pos.x=p.x-size.width; pm->set_pos(pos); pm->popup(); PopupMenu *pum = pm->cast_to<PopupMenu>(); if (pum) { pr.pos-=pum->get_global_pos(); pum->clear_autohide_areas(); pum->add_autohide_area(Rect2(pr.pos.x,pr.pos.y,pr.size.x,items[over]._ofs_cache)); if (over<items.size()-1) { int from = items[over+1]._ofs_cache; pum->add_autohide_area(Rect2(pr.pos.x,pr.pos.y+from,pr.size.x,pr.size.y-from)); } } }
void BroadPhase2DHashGrid::remove(ID p_id) { Map<ID,Element>::Element *E=element_map.find(p_id); ERR_FAIL_COND(!E); Element &e=E->get(); if (e.aabb!=Rect2()) _exit_grid(&e,e.aabb,e._static); element_map.erase(p_id); }
void CollisionPolygon2D::set_polygon(const Vector<Point2>& p_polygon) { polygon=p_polygon; if (can_update_body) { for(int i=0;i<polygon.size();i++) { if (i==0) aabb=Rect2(polygon[i],Size2()); else aabb.expand_to(polygon[i]); } if (aabb==Rect2()) { aabb=Rect2(-10,-10,20,20); } else { aabb.pos-=aabb.size*0.3; aabb.size+=aabb.size*0.6; } _update_parent(); } update(); }
void Viewport::_vp_input(const InputEvent& p_ev) { if (render_target && to_screen_rect==Rect2()) return; //if render target, can't get input events //this one handles system input, p_ev are in system coordinates //they are converted to viewport coordinates InputEvent ev = p_ev; _make_input_local(ev); input(ev); }
void MenuButton::pressed() { emit_signal("about_to_show"); Size2 size=get_size(); Point2 gp = get_global_pos(); popup->set_global_pos( gp + Size2( 0, size.height ) ); popup->set_size( Size2( size.width, 0) ); popup->set_parent_rect( Rect2(Point2(gp-popup->get_global_pos()),get_size())); popup->popup(); popup->call_deferred("grab_click_focus"); }
void Path2DEditor::forward_draw_over_canvas(Control *p_canvas) { if (!node) return; if (!node->is_visible_in_tree()) return; if (!node->get_curve().is_valid()) return; Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); Size2 handle_size = handle->get_size(); Ref<Curve2D> curve = node->get_curve(); int len = curve->get_point_count(); Control *vpc = canvas_item_editor->get_viewport_control(); for (int i = 0; i < len; i++) { Vector2 point = xform.xform(curve->get_point_position(i)); vpc->draw_texture_rect(handle, Rect2(point - handle_size * 0.5, handle_size), false, Color(1, 1, 1, 1)); if (i < len - 1) { Vector2 pointout = xform.xform(curve->get_point_position(i) + curve->get_point_out(i)); vpc->draw_line(point, pointout, Color(0.5, 0.5, 1.0, 0.8), 1.0); vpc->draw_texture_rect(handle, Rect2(pointout - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3)); } if (i > 0) { Vector2 pointin = xform.xform(curve->get_point_position(i) + curve->get_point_in(i)); vpc->draw_line(point, pointin, Color(0.5, 0.5, 1.0, 0.8), 1.0); vpc->draw_texture_rect(handle, Rect2(pointin - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3)); } } }
void VisualServerViewport::draw_viewports() { //sort viewports //draw viewports clear_color = GLOBAL_GET("rendering/viewport/default_clear_color"); active_viewports.sort_custom<ViewportSort>(); for (int i = 0; i < active_viewports.size(); i++) { Viewport *vp = active_viewports[i]; if (vp->update_mode == VS::VIEWPORT_UPDATE_DISABLED) continue; ERR_CONTINUE(!vp->render_target.is_valid()); bool visible = vp->viewport_to_screen_rect != Rect2() || vp->update_mode == VS::VIEWPORT_UPDATE_ALWAYS || vp->update_mode == VS::VIEWPORT_UPDATE_ONCE; if (!visible) continue; VSG::rasterizer->set_current_render_target(vp->render_target); _draw_viewport(vp); if (vp->viewport_to_screen_rect != Rect2()) { //copy to screen if set as such VSG::rasterizer->set_current_render_target(RID()); VSG::rasterizer->blit_render_target_to_screen(vp->render_target, vp->viewport_to_screen_rect, vp->viewport_to_screen); } if (vp->update_mode == VS::VIEWPORT_UPDATE_ONCE) { vp->update_mode = VS::VIEWPORT_UPDATE_DISABLED; } } }
void ColorPickerButton::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { Ref<StyleBox> normal = get_stylebox("normal"); 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, color); } if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST && popup) { popup->hide(); } }
void LargeTexture::draw_rect(RID p_canvas_item,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) const { //tiling not supported for this if (size.x==0 || size.y==0) return; Size2 scale = p_rect.size/size; for(int i=0;i<pieces.size();i++) { // TODO pieces[i].texture->draw_rect(p_canvas_item,Rect2(pieces[i].offset*scale+p_rect.pos,pieces[i].texture->get_size()*scale),false,p_modulate,p_transpose); } }
void VideoPlayer::_notification(int p_notification) { switch (p_notification) { case NOTIFICATION_ENTER_SCENE: { //set_idle_process(false); //don't annoy if (stream.is_valid() && autoplay && !get_scene()->is_editor_hint()) play(); } break; case NOTIFICATION_PROCESS: { if (stream.is_null()) return; if (paused) return; while (stream->get_pending_frame_count()) { Image img = stream->pop_frame(); if (texture->get_width() == 0) { texture->create(img.get_width(),img.get_height(),img.get_format(),Texture::FLAG_VIDEO_SURFACE|Texture::FLAG_FILTER); update(); minimum_size_changed(); } else { if (stream->get_pending_frame_count() == 0) texture->set_data(img); }; }; } break; case NOTIFICATION_DRAW: { if (texture.is_null()) return; if (texture->get_width() == 0) return; Size2 s=expand?get_size():texture->get_size(); RID ci = get_canvas_item(); printf("drawing with size %f, %f\n", s.x, s.y); draw_texture_rect(texture,Rect2(Point2(),s),false); } break; }; };
void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { VisualServer *vs = VisualServer::get_singleton(); Rect2i r = p_rect; for (int i = 0; i < border_size; i++) { Color color_upleft = light_color; Color color_downright = dark_color; if (blend) { color_upleft.r = (border_size - i) * color_upleft.r / border_size + i * bg_color.r / border_size; color_upleft.g = (border_size - i) * color_upleft.g / border_size + i * bg_color.g / border_size; color_upleft.b = (border_size - i) * color_upleft.b / border_size + i * bg_color.b / border_size; color_downright.r = (border_size - i) * color_downright.r / border_size + i * bg_color.r / border_size; color_downright.g = (border_size - i) * color_downright.g / border_size + i * bg_color.g / border_size; color_downright.b = (border_size - i) * color_downright.b / border_size + i * bg_color.b / border_size; } vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r.position.x, r.position.y + r.size.y - 1), Size2(r.size.x, 1)), color_downright); vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r.position.x + r.size.x - 1, r.position.y), Size2(1, r.size.y)), color_downright); vs->canvas_item_add_rect(p_canvas_item, Rect2(r.position, Size2(r.size.x, 1)), color_upleft); vs->canvas_item_add_rect(p_canvas_item, Rect2(r.position, Size2(1, r.size.y)), color_upleft); r.position.x++; r.position.y++; r.size.x -= 2; r.size.y -= 2; } if (draw_center) vs->canvas_item_add_rect(p_canvas_item, Rect2(r.position, r.size), bg_color); Rect2i r_add = p_rect; vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x - additional_border_size[MARGIN_LEFT], r_add.position.y - additional_border_size[MARGIN_TOP]), Size2(r_add.size.width + additional_border_size[MARGIN_LEFT] + additional_border_size[MARGIN_RIGHT], additional_border_size[MARGIN_TOP])), light_color); vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x - additional_border_size[MARGIN_LEFT], r_add.position.y), Size2(additional_border_size[MARGIN_LEFT], r_add.size.height)), light_color); vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x + r_add.size.width, r_add.position.y), Size2(additional_border_size[MARGIN_RIGHT], r_add.size.height)), dark_color); vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x - additional_border_size[MARGIN_LEFT], r_add.position.y + r_add.size.height), Size2(r_add.size.width + additional_border_size[MARGIN_LEFT] + additional_border_size[MARGIN_RIGHT], additional_border_size[MARGIN_BOTTOM])), dark_color); }
void TileMap::_recompute_rect_cache() { #ifdef DEBUG_ENABLED if (!rect_cache_dirty) return; Rect2 r_total; for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) { Rect2 r; r.pos=_map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size()); r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()) ); r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) ); r.expand_to( _map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) ); if (E==quadrant_map.front()) r_total=r; else r_total=r_total.merge(r); } if (r_total==Rect2()) { rect_cache=Rect2(-10,-10,20,20); } else { rect_cache=r_total.grow(MAX(cell_size.x,cell_size.y)*_get_quadrant_size()); } item_rect_changed(); rect_cache_dirty=false; #endif }
Rect2 Sprite::get_rect() const { if (texture.is_null()) return Rect2(0, 0, 1, 1); Size2i s; if (region) { s = region_rect.size; } else { s = texture->get_size(); } s = s / Point2(hframes, vframes); Point2 ofs = offset; if (centered) ofs -= s / 2; if (s == Size2(0, 0)) s = Size2(1, 1); return Rect2(ofs, s); }
void Popup::_bind_methods() { ClassDB::bind_method(D_METHOD("popup_centered", "size"), &Popup::popup_centered, DEFVAL(Size2())); ClassDB::bind_method(D_METHOD("popup_centered_ratio", "ratio"), &Popup::popup_centered_ratio, DEFVAL(0.75)); ClassDB::bind_method(D_METHOD("popup_centered_minsize", "minsize"), &Popup::popup_centered_minsize, DEFVAL(Size2())); ClassDB::bind_method(D_METHOD("popup", "bounds"), &Popup::popup, DEFVAL(Rect2())); ClassDB::bind_method(D_METHOD("set_exclusive", "enable"), &Popup::set_exclusive); ClassDB::bind_method(D_METHOD("is_exclusive"), &Popup::is_exclusive); ADD_SIGNAL(MethodInfo("about_to_show")); ADD_SIGNAL(MethodInfo("popup_hide")); ADD_GROUP("Popup", "popup_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "popup_exclusive"), "set_exclusive", "is_exclusive"); BIND_CONSTANT(NOTIFICATION_POST_POPUP); BIND_CONSTANT(NOTIFICATION_POPUP_HIDE); }
void ProgressBar::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { Ref<StyleBox> bg = get_stylebox("bg"); Ref<StyleBox> fg = get_stylebox("fg"); Ref<Font> font = get_font("font"); Color font_color = get_color("font_color"); draw_style_box(bg, Rect2(Point2(), get_size())); float r = get_as_ratio(); int mp = fg->get_minimum_size().width; int p = r * get_size().width - mp; if (p > 0) { draw_style_box(fg, Rect2(Point2(), Size2(p + fg->get_minimum_size().width, get_size().height))); } if (percent_visible) { String txt = itos(int(get_as_ratio() * 100)) + "%"; font->draw_halign(get_canvas_item(), Point2(0, font->get_ascent() + (get_size().height - font->get_height()) / 2), HALIGN_CENTER, get_size().width, txt, font_color); } } }
void NinePatchRect::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { if (texture.is_null()) return; Rect2 rect = Rect2(Point2(), get_size()); Rect2 src_rect = region_rect; texture->get_rect_region(rect, src_rect, rect, src_rect); RID ci = get_canvas_item(); VS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center); } }
void BitmapFont::_set_chars(const PoolVector<int> &p_chars) { int len = p_chars.size(); //char 1 charsize 1 texture, 4 rect, 2 align, advance 1 ERR_FAIL_COND(len % 9); if (!len) return; //none to do int chars = len / 9; PoolVector<int>::Read r = p_chars.read(); for (int i = 0; i < chars; i++) { const int *data = &r[i * 9]; add_char(data[0], data[1], Rect2(data[2], data[3], data[4], data[5]), Size2(data[6], data[7]), data[8]); } }
static Rect2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size) { Size2 size = p_max_size; int tex_width = p_size.width * size.height / p_size.height; int tex_height = size.height; if (tex_width > size.width) { tex_width = size.width; tex_height = p_size.height * tex_width / p_size.width; } int ofs_x = (size.width - tex_width) / 2; int ofs_y = (size.height - tex_height) / 2; return Rect2(ofs_x, ofs_y, tex_width, tex_height); }
void MobileVRInterface::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { _THREAD_SAFE_METHOD_ // We must have a valid render target ERR_FAIL_COND(!p_render_target.is_valid()); // We must have an initialised shader ERR_FAIL_COND(lens_shader != NULL); // Because we are rendering to our device we must use our main viewport! ERR_FAIL_COND(p_screen_rect == Rect2()); float offset_x = 0.0; float aspect_ratio = 0.5 * p_screen_rect.size.x / p_screen_rect.size.y; Vector2 eye_center; if (p_eye == ARVRInterface::EYE_LEFT) { offset_x = -1.0; eye_center.x = ((-intraocular_dist / 2.0) + (display_width / 4.0)) / (display_width / 2.0); } else if (p_eye == ARVRInterface::EYE_RIGHT) { eye_center.x = ((intraocular_dist / 2.0) - (display_width / 4.0)) / (display_width / 2.0); } // unset our render target so we are outputting to our main screen by making RasterizerStorageGLES3::system_fbo our current FBO VSG::rasterizer->set_current_render_target(RID()); // now output to screen // VSG::rasterizer->blit_render_target_to_screen(p_render_target, screen_rect, 0); // get our render target RID eye_texture = VSG::storage->render_target_get_texture(p_render_target); uint32_t texid = VS::get_singleton()->texture_get_texid(eye_texture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texid); lens_shader->bind(); lens_shader->set_uniform(LensDistortedShaderGLES3::OFFSET_X, offset_x); lens_shader->set_uniform(LensDistortedShaderGLES3::K1, k1); lens_shader->set_uniform(LensDistortedShaderGLES3::K2, k2); lens_shader->set_uniform(LensDistortedShaderGLES3::EYE_CENTER, eye_center); lens_shader->set_uniform(LensDistortedShaderGLES3::UPSCALE, oversample); lens_shader->set_uniform(LensDistortedShaderGLES3::ASPECT_RATIO, aspect_ratio); glBindVertexArray(half_screen_array); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glBindVertexArray(0); };
float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_char,const CharType& p_next,const Color& p_modulate) const { const Character * c = char_map.getptr(p_char); if (!c) return 0; Point2 cpos=p_pos; cpos.x+=c->h_align; cpos.y-=ascent; cpos.y+=c->v_align; ERR_FAIL_COND_V( c->texture_idx<-1 || c->texture_idx>=textures.size(),0); if (c->texture_idx!=-1) VisualServer::get_singleton()->canvas_item_add_texture_rect_region( p_canvas_item, Rect2( cpos, c->rect.size ), textures[c->texture_idx]->get_rid(),c->rect, p_modulate ); return get_char_size(p_char,p_next).width; }
Rect2 Polygon2D::_edit_get_rect() const { if (rect_cache_dirty) { int l = polygon.size(); PoolVector<Vector2>::Read r = polygon.read(); item_rect = Rect2(); for (int i = 0; i < l; i++) { Vector2 pos = r[i] + offset; if (i == 0) item_rect.position = pos; else item_rect.expand_to(pos); } rect_cache_dirty = false; } return item_rect; }
Slider::Slider(): Minimum(0), Maximum(1), Value(0.5) { Width = 136; Height = 53/2; OnMouseClickHandler = NULL; OnMouseOverHandler = NULL; OnMouseAwayHandler = NULL; // Visual Representation //---------------------- //The Line of the slider spriteLine.SetPosition( AppPoint(this->Position.X,this->Position.Y) ); spriteLine.SetTexture(::MyApp::GetSingleton()->pControlsTexture);//this button default sprite AppRectangle Rect( AppPoint(0,192), AppPoint(93,234-18) ); spriteLine.SetRenderRectangle(Rect); spriteLine.SetWidth(136); spriteLine.SetHeight(53/2.5);//flatter spriteLine.Opacity = 0.60f; spriteLine.Visible = true; Representation.push_back(&spriteLine); //The pivot of the slider spritePivot.SetPosition( AppPoint(this->Position.X, this->Position.Y)); spritePivot.SetTexture(::MyApp::GetSingleton()->pControlsTexture);//this button default sprite AppRectangle Rect2( AppPoint(152,192), AppPoint(192,234) ); spritePivot.SetRenderRectangle(Rect2); spritePivot.SetWidth(26); spritePivot.SetHeight(53/2);//flatter spritePivot.Opacity = 1.0f; spritePivot.Visible = true; Representation.push_back(&spritePivot); // Collision Representation //------------------------- //coordinates in local space, defined from (-0.5,0.5) to (0.5,-0.5) D3DXVECTOR2 A(-0.5,0.5); D3DXVECTOR2 B(0.5,-0.5); GUIRectangle* bound = new GUIFramework::GUIRectangle(dynamic_cast<GUIObject*>(this),A,B); CollisionShape = bound; }
void AtlasTexture::draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate, bool p_transpose) const { Rect2 rc=region; if (!atlas.is_valid()) return; if (rc.size.width==0) { rc.size.width=atlas->get_width(); } if (rc.size.height==0) { rc.size.height=atlas->get_height(); } VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,Rect2(p_pos+margin.pos,rc.size),atlas->get_rid(),rc,p_modulate,p_transpose); }
void VisualServerCanvas::canvas_item_set_copy_to_backbuffer(RID p_item, bool p_enable, const Rect2 &p_rect) { Item *canvas_item = canvas_item_owner.getornull(p_item); ERR_FAIL_COND(!canvas_item); if (bool(canvas_item->copy_back_buffer != NULL) != p_enable) { if (p_enable) { canvas_item->copy_back_buffer = memnew(RasterizerCanvas::Item::CopyBackBuffer); } else { memdelete(canvas_item->copy_back_buffer); canvas_item->copy_back_buffer = NULL; } } if (p_enable) { canvas_item->copy_back_buffer->rect = p_rect; canvas_item->copy_back_buffer->full = p_rect == Rect2(); } }
Rect2 SpriteTextureBase::evaluate(float t) const { if(mPlayback == SpriteAnimationPlayback::None) return Rect2(mUVOffset.x, mUVOffset.y, mUVScale.x, mUVScale.y); // Note: Duration could be pre-calculated float duration = 0.0f; if (mAnimation.fps > 0) duration = mAnimation.count / (float)mAnimation.fps; switch(mPlayback) { default: case SpriteAnimationPlayback::Normal: t = Math::clamp(t, 0.0f, duration); break; case SpriteAnimationPlayback::Loop: t = Math::repeat(t, duration); break; case SpriteAnimationPlayback::PingPong: t = Math::pingPong(t, duration); break; } const float pct = t / duration; UINT32 frame = 0; if(mAnimation.count > 0) frame = Math::clamp(Math::floorToPosInt(pct * mAnimation.count), 0U, mAnimation.count - 1); const UINT32 row = frame / mAnimation.numRows; const UINT32 column = frame % mAnimation.numColumns; Rect2 output; // Note: These could be pre-calculated output.width = mUVScale.x / mAnimation.numColumns; output.height = mUVScale.y / mAnimation.numRows; output.x = mUVOffset.x + column * output.width; output.y = mUVOffset.y + row * output.height; return output; }
void ShaderEditor::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_SCENE) { close->set_normal_texture( get_icon("Close","EditorIcons")); close->set_hover_texture( get_icon("CloseHover","EditorIcons")); close->set_pressed_texture( get_icon("Close","EditorIcons")); close->connect("pressed",this,"_close_callback"); } if (p_what==NOTIFICATION_DRAW) { RID ci = get_canvas_item(); Ref<StyleBox> style = get_stylebox("panel","Panel"); style->draw( ci, Rect2( Point2(), get_size() ) ); } }
void ColorPicker::_hsv_draw(int p_which, Control *c) { if (!c) return; if (p_which == 0) { Vector<Point2> points; points.push_back(Vector2()); points.push_back(Vector2(c->get_size().x, 0)); points.push_back(c->get_size()); points.push_back(Vector2(0, c->get_size().y)); Vector<Color> colors; colors.push_back(Color(1, 1, 1, 1)); colors.push_back(Color(1, 1, 1, 1)); colors.push_back(Color(0, 0, 0, 1)); colors.push_back(Color(0, 0, 0, 1)); c->draw_polygon(points, colors); Vector<Color> colors2; Color col = color; col.set_hsv(h, 1, 1); col.a = 0; colors2.push_back(col); col.a = 1; colors2.push_back(col); col.set_hsv(h, 1, 0); colors2.push_back(col); col.a = 0; colors2.push_back(col); c->draw_polygon(points, colors2); 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); 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(x, y), Point2(x, y), Color(1, 1, 1), 2); } 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); Color col = Color(); col.set_hsv(h, 1, 1); c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted()); } }
Rect2 ConcavePolygonShape2D::get_rect() const { PoolVector<Vector2> s = get_segments(); int len = s.size(); if (len == 0) return Rect2(); Rect2 rect; PoolVector<Vector2>::Read r = s.read(); for (int i = 0; i < len; i++) { if (i == 0) rect.position = r[i]; else rect.expand_to(r[i]); } return rect; }