void Camera2D::_notification(int p_what) { switch(p_what) { case NOTIFICATION_FIXED_PROCESS: { _update_scroll(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { if (!is_fixed_processing()) _update_scroll(); } break; case NOTIFICATION_ENTER_SCENE: { viewport = NULL; Node *n=this; while(n){ viewport = n->cast_to<Viewport>(); if (viewport) break; n=n->get_parent(); } canvas = get_canvas(); RID vp = viewport->get_viewport(); group_name = "__cameras_"+itos(vp.get_id()); canvas_group_name ="__cameras_c"+itos(canvas.get_id()); add_to_group(group_name); add_to_group(canvas_group_name); _update_scroll(); first=true; } break; case NOTIFICATION_EXIT_SCENE: { if (is_current()) { if (viewport) { viewport->set_canvas_transform( Matrix32() ); } } remove_from_group(group_name); remove_from_group(canvas_group_name); viewport=NULL; } break; } }
void Camera2D::set_zoom(const Vector2 &p_zoom) { zoom = p_zoom; Point2 old_smoothed_camera_pos = smoothed_camera_pos; _update_scroll(); smoothed_camera_pos = old_smoothed_camera_pos; };
void Camera2D::align() { ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id)); Size2 screen_size = viewport->get_visible_rect().size; Point2 current_camera_pos = get_global_transform().get_origin(); if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) { if (h_ofs < 0) { camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs; } else { camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs; } if (v_ofs < 0) { camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs; } else { camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs; } } else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) { camera_pos = current_camera_pos; } _update_scroll(); }
void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) { p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM); if (zoom == p_zoom) return; zoom_minus->set_disabled(zoom == MIN_ZOOM); zoom_plus->set_disabled(zoom == MAX_ZOOM); Vector2 sbofs = (Vector2(h_scroll->get_value(), v_scroll->get_value()) + p_center) / zoom; zoom = p_zoom; top_layer->update(); _update_scroll(); connections_layer->update(); if (is_visible_in_tree()) { Vector2 ofs = sbofs * zoom - p_center; h_scroll->set_value(ofs.x); v_scroll->set_value(ofs.y); } update(); }
void GraphEdit::_notification(int p_what) { if (p_what==NOTIFICATION_READY) { Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); v_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,vmin.width); v_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); v_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,0); v_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); h_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,0); h_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height); h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); } if (p_what==NOTIFICATION_DRAW) { VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); } if (p_what==NOTIFICATION_RESIZED) { _update_scroll(); top_layer->update(); } }
void GraphEdit::set_scroll_ofs(const Vector2 &p_ofs) { setting_scroll_ofs = true; h_scroll->set_value(p_ofs.x); v_scroll->set_value(p_ofs.y); _update_scroll(); setting_scroll_ofs = false; }
void Camera2D::_make_current(Object *p_which) { if (p_which==this) { current=true; _update_scroll(); } else { current=false; } }
void Camera2D::align() { Size2 screen_size = get_viewport_rect().size; screen_size = get_viewport_rect().size; Point2 current_camera_pos = get_global_transform().get_origin(); if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) { if (h_ofs < 0) { camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs; } else { camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs; } if (v_ofs < 0) { camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs; } else { camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs; } } else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) { camera_pos = current_camera_pos; } _update_scroll(); }
void GraphEdit::_top_layer_draw() { _update_scroll(); if (connecting) { Node *fromn = get_node(connecting_from); ERR_FAIL_COND(!fromn); GraphNode *from = Object::cast_to<GraphNode>(fromn); ERR_FAIL_COND(!from); Vector2 pos; if (connecting_out) pos = from->get_connection_output_position(connecting_index); else pos = from->get_connection_input_position(connecting_index); pos += from->get_position(); Vector2 topos; topos = connecting_to; Color col = connecting_color; if (connecting_target) { col.r += 0.4; col.g += 0.4; col.b += 0.4; } if (!connecting_out) { SWAP(pos, topos); } _draw_cos_line(top_layer, pos, topos, col, col); } if (box_selecting) top_layer->draw_rect(box_selecting_rect, Color(0.7, 0.7, 1.0, 0.3)); }
void Camera2D::set_anchor_mode(AnchorMode p_anchor_mode){ anchor_mode=p_anchor_mode; _update_scroll(); }
void GraphEdit::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { port_grab_distance_horizontal = get_constant("port_grab_distance_horizontal"); port_grab_distance_vertical = get_constant("port_grab_distance_vertical"); } if (p_what == NOTIFICATION_READY) { Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -vmin.width); v_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); v_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0); v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); h_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 0); h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -hmin.height); h_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); zoom_minus->set_icon(get_icon("minus")); zoom_reset->set_icon(get_icon("reset")); zoom_plus->set_icon(get_icon("more")); snap_button->set_icon(get_icon("snap")); } if (p_what == NOTIFICATION_DRAW) { draw_style_box(get_stylebox("bg"), Rect2(Point2(), get_size())); if (is_using_snap()) { //draw grid int snap = get_snap(); Vector2 offset = get_scroll_ofs() / zoom; Size2 size = get_size() / zoom; Point2i from = (offset / float(snap)).floor(); Point2i len = (size / float(snap)).floor() + Vector2(1, 1); Color grid_minor = get_color("grid_minor"); Color grid_major = get_color("grid_major"); for (int i = from.x; i < from.x + len.x; i++) { Color color; if (ABS(i) % 10 == 0) color = grid_major; else color = grid_minor; float base_ofs = i * snap * zoom - offset.x * zoom; draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color); } for (int i = from.y; i < from.y + len.y; i++) { Color color; if (ABS(i) % 10 == 0) color = grid_major; else color = grid_minor; float base_ofs = i * snap * zoom - offset.y * zoom; draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color); } } } if (p_what == NOTIFICATION_RESIZED) { _update_scroll(); top_layer->update(); } }
void Camera2D::reset_smoothing() { smoothed_camera_pos = camera_pos; _update_scroll(); }
void Camera2D::set_limit_smoothing_enabled(bool enable) { limit_smoothing_enabled = enable; _update_scroll(); }
void Camera2D::force_update_scroll() { _update_scroll(); }
void Camera2D::set_centered(bool p_centered){ centered=p_centered; _update_scroll(); }
void Camera2D::set_zoom(const Vector2 &p_zoom) { zoom = p_zoom; _update_scroll(); };
void Camera2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_FIXED_PROCESS: { _update_scroll(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { if (!is_fixed_processing()) _update_scroll(); } break; case NOTIFICATION_ENTER_TREE: { if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) { viewport = custom_viewport; } else { viewport = get_viewport(); } canvas = get_canvas(); RID vp = viewport->get_viewport_rid(); group_name = "__cameras_" + itos(vp.get_id()); canvas_group_name = "__cameras_c" + itos(canvas.get_id()); add_to_group(group_name); add_to_group(canvas_group_name); if (Engine::get_singleton()->is_editor_hint()) { set_fixed_process(false); } _update_scroll(); first = true; } break; case NOTIFICATION_EXIT_TREE: { if (is_current()) { if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) { viewport->set_canvas_transform(Transform2D()); } } remove_from_group(group_name); remove_from_group(canvas_group_name); viewport = NULL; } break; case NOTIFICATION_DRAW: { if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) break; if (screen_drawing_enabled) { Color area_axis_color(0.5, 0.42, 0.87, 0.63); float area_axis_width = 1; if (is_current()) { area_axis_width = 3; area_axis_color.a = 0.83; } Transform2D inv_camera_transform = get_camera_transform().affine_inverse(); Size2 screen_size = get_viewport_rect().size; Vector2 screen_endpoints[4] = { inv_camera_transform.xform(Vector2(0, 0)), inv_camera_transform.xform(Vector2(screen_size.width, 0)), inv_camera_transform.xform(Vector2(screen_size.width, screen_size.height)), inv_camera_transform.xform(Vector2(0, screen_size.height)) }; Transform2D inv_transform = get_global_transform().affine_inverse(); // undo global space for (int i = 0; i < 4; i++) { draw_line(inv_transform.xform(screen_endpoints[i]), inv_transform.xform(screen_endpoints[(i + 1) % 4]), area_axis_color, area_axis_width); } } if (limit_drawing_enabled) { Color limit_drawing_color(1, 1, 0, 0.63); float limit_drawing_width = 1; if (is_current()) { limit_drawing_color.a = 0.83; limit_drawing_width = 3; } Vector2 camera_origin = get_global_transform().get_origin(); Vector2 camera_scale = get_global_transform().get_scale().abs(); Vector2 limit_points[4] = { (Vector2(limit[MARGIN_LEFT], limit[MARGIN_TOP]) - camera_origin) / camera_scale, (Vector2(limit[MARGIN_RIGHT], limit[MARGIN_TOP]) - camera_origin) / camera_scale, (Vector2(limit[MARGIN_RIGHT], limit[MARGIN_BOTTOM]) - camera_origin) / camera_scale, (Vector2(limit[MARGIN_LEFT], limit[MARGIN_BOTTOM]) - camera_origin) / camera_scale }; for (int i = 0; i < 4; i++) { draw_line(limit_points[i], limit_points[(i + 1) % 4], limit_drawing_color, limit_drawing_width); } } if (margin_drawing_enabled) { Color margin_drawing_color(0, 1, 1, 0.63); float margin_drawing_width = 1; if (is_current()) { margin_drawing_width = 3; margin_drawing_color.a = 0.83; } Transform2D inv_camera_transform = get_camera_transform().affine_inverse(); Size2 screen_size = get_viewport_rect().size; Vector2 margin_endpoints[4] = { inv_camera_transform.xform(Vector2((screen_size.width / 2) - ((screen_size.width / 2) * drag_margin[MARGIN_LEFT]), (screen_size.height / 2) - ((screen_size.height / 2) * drag_margin[MARGIN_TOP]))), inv_camera_transform.xform(Vector2((screen_size.width / 2) + ((screen_size.width / 2) * drag_margin[MARGIN_RIGHT]), (screen_size.height / 2) - ((screen_size.height / 2) * drag_margin[MARGIN_TOP]))), inv_camera_transform.xform(Vector2((screen_size.width / 2) + ((screen_size.width / 2) * drag_margin[MARGIN_RIGHT]), (screen_size.height / 2) + ((screen_size.height / 2) * drag_margin[MARGIN_BOTTOM]))), inv_camera_transform.xform(Vector2((screen_size.width / 2) - ((screen_size.width / 2) * drag_margin[MARGIN_LEFT]), (screen_size.height / 2) + ((screen_size.height / 2) * drag_margin[MARGIN_BOTTOM]))) }; Transform2D inv_transform = get_global_transform().affine_inverse(); // undo global space for (int i = 0; i < 4; i++) { draw_line(inv_transform.xform(margin_endpoints[i]), inv_transform.xform(margin_endpoints[(i + 1) % 4]), margin_drawing_color, margin_drawing_width); } } } break; } }
void GraphEdit::_top_layer_draw() { _update_scroll(); if (connecting) { Node *fromn = get_node(connecting_from); ERR_FAIL_COND(!fromn); GraphNode *from = fromn->cast_to<GraphNode>(); ERR_FAIL_COND(!from); Vector2 pos; if (connecting_out) pos=from->get_connection_output_pos(connecting_index); else pos=from->get_connection_input_pos(connecting_index); pos+=from->get_pos(); Vector2 topos; topos=connecting_to; Color col=connecting_color; if (connecting_target) { col.r+=0.4; col.g+=0.4; col.b+=0.4; } _draw_cos_line(pos,topos,col); } List<List<Connection>::Element* > to_erase; for(List<Connection>::Element *E=connections.front();E;E=E->next()) { NodePath fromnp(E->get().from); Node * from = get_node(fromnp); if (!from) { to_erase.push_back(E); continue; } GraphNode *gfrom = from->cast_to<GraphNode>(); if (!gfrom) { to_erase.push_back(E); continue; } NodePath tonp(E->get().to); Node * to = get_node(tonp); if (!to) { to_erase.push_back(E); continue; } GraphNode *gto = to->cast_to<GraphNode>(); if (!gto) { to_erase.push_back(E); continue; } Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_pos(); Color color = gfrom->get_connection_output_color(E->get().from_port); Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_pos(); _draw_cos_line(frompos,topos,color); } while(to_erase.size()) { connections.erase(to_erase.front()->get()); to_erase.pop_front(); } if (box_selecting) top_layer->draw_rect(box_selecting_rect,Color(0.7,0.7,1.0,0.3)); }
void Camera2D::set_offset(const Vector2& p_offset) { offset=p_offset; _update_scroll(); }
void Camera2D::_notification(int p_what) { switch(p_what) { case NOTIFICATION_FIXED_PROCESS: { _update_scroll(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { if (!is_fixed_processing()) _update_scroll(); } break; case NOTIFICATION_ENTER_TREE: { viewport = NULL; Node *n=this; while(n){ viewport = n->cast_to<Viewport>(); if (viewport) break; n=n->get_parent(); } canvas = get_canvas(); RID vp = viewport->get_viewport(); group_name = "__cameras_"+itos(vp.get_id()); canvas_group_name ="__cameras_c"+itos(canvas.get_id()); add_to_group(group_name); add_to_group(canvas_group_name); _update_scroll(); first=true; } break; case NOTIFICATION_EXIT_TREE: { if (is_current()) { if (viewport) { viewport->set_canvas_transform( Matrix32() ); } } remove_from_group(group_name); remove_from_group(canvas_group_name); viewport=NULL; } break; case NOTIFICATION_DRAW: { if (!is_inside_tree() || !get_tree()->is_editor_hint()) break; Color area_axis_color(0.5, 0.42, 0.87, 0.63); float area_axis_width = 1; if(current) area_axis_width = 3; Matrix32 inv_camera_transform = get_camera_transform().affine_inverse(); Size2 screen_size = get_viewport_rect().size; Vector2 screen_endpoints[4]= { inv_camera_transform.xform(Vector2(0, 0)), inv_camera_transform.xform(Vector2(screen_size.width,0)), inv_camera_transform.xform(Vector2(screen_size.width, screen_size.height)), inv_camera_transform.xform(Vector2(0, screen_size.height)) }; Matrix32 inv_transform = get_transform().affine_inverse(); // undo global space draw_set_transform(inv_transform.get_origin(), inv_transform.get_rotation(), inv_transform.get_scale()); for(int i=0;i<4;i++) { draw_line(screen_endpoints[i], screen_endpoints[(i+1)%4], area_axis_color, area_axis_width); } } break; } }
void RichTextLabel::_notification(int p_what) { switch (p_what) { case NOTIFICATION_RESIZED: { main->first_invalid_line=0; //invalidate ALL update(); } break; case NOTIFICATION_ENTER_TREE: { set_bbcode(bbcode); main->first_invalid_line=0; //invalidate ALL update(); } break; case NOTIFICATION_THEME_CHANGED: { if (is_inside_tree() && use_bbcode) { parse_bbcode(bbcode); //first_invalid_line=0; //invalidate ALL //update(); } } break; case NOTIFICATION_DRAW: { _validate_line_caches(main); _update_scroll(); RID ci=get_canvas_item(); Size2 size = get_size(); VisualServer::get_singleton()->canvas_item_set_clip(ci,true); if (has_focus()) { VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci,true); draw_style_box(get_stylebox("focus"),Rect2(Point2(),size)); VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci,false); } int ofs = vscroll->get_val(); //todo, change to binary search int from_line = 0; int total_chars = 0; while (from_line<main->lines.size()) { if (main->lines[from_line].height_accum_cache>=ofs) break; from_line++; total_chars+=main->lines[from_line].char_count; } if (from_line>=main->lines.size()) break; //nothing to draw int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs; Ref<Font> base_font=get_font("normal_font"); Color base_color=get_color("default_color"); while (y<size.height && from_line<main->lines.size()) { _process_line(main,Point2(),y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color,Point2i(),NULL,NULL,NULL,total_chars); total_chars+=main->lines[from_line].char_count; from_line++; } } } }
void Camera2D::set_rotating(bool p_rotating){ rotating=p_rotating; _update_scroll(); }