static void getCTM(JNIEnv* env, jobject, jlong canvasHandle, jlong matrixHandle) { SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); get_canvas(canvasHandle)->getMatrix(matrix); }
Font GUIComponent::get_font() const { Canvas canvas = get_canvas(); return impl->element.get_font(canvas, get_resources()); }
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; } }
static jint getSaveCount(JNIEnv*, jobject, jlong canvasHandle) { return static_cast<jint>(get_canvas(canvasHandle)->getSaveCount()); }
static jint saveLayer(JNIEnv* env, jobject, jlong canvasHandle, jfloat l, jfloat t, jfloat r, jfloat b, jlong paintHandle, jint flagsHandle) { Paint* paint = reinterpret_cast<Paint*>(paintHandle); SkCanvas::SaveFlags flags = static_cast<SkCanvas::SaveFlags>(flagsHandle); return static_cast<jint>(get_canvas(canvasHandle)->saveLayer(l, t, r, b, paint, flags)); }
static jboolean isOpaque(JNIEnv*, jobject, jlong canvasHandle) { return get_canvas(canvasHandle)->isOpaque() ? JNI_TRUE : JNI_FALSE; }
static jint getHeight(JNIEnv*, jobject, jlong canvasHandle) { return static_cast<jint>(get_canvas(canvasHandle)->height()); }
static jboolean quickRejectRect(JNIEnv* env, jobject, jlong canvasHandle, jfloat left, jfloat top, jfloat right, jfloat bottom) { bool result = get_canvas(canvasHandle)->quickRejectRect(left, top, right, bottom); return result ? JNI_TRUE : JNI_FALSE; }
static jboolean quickRejectPath(JNIEnv* env, jobject, jlong canvasHandle, jlong pathHandle) { SkPath* path = reinterpret_cast<SkPath*>(pathHandle); bool result = get_canvas(canvasHandle)->quickRejectPath(*path); return result ? JNI_TRUE : JNI_FALSE; }
static void skew(JNIEnv*, jobject, jlong canvasHandle, jfloat sx, jfloat sy) { get_canvas(canvasHandle)->skew(sx, sy); }
static void translate(JNIEnv*, jobject, jlong canvasHandle, jfloat dx, jfloat dy) { get_canvas(canvasHandle)->translate(dx, dy); }
static void rotate(JNIEnv*, jobject, jlong canvasHandle, jfloat degrees) { get_canvas(canvasHandle)->rotate(degrees); }
static void concat(JNIEnv* env, jobject, jlong canvasHandle, jlong matrixHandle) { const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); get_canvas(canvasHandle)->concat(*matrix); }
static void setMatrix(JNIEnv* env, jobject, jlong canvasHandle, jlong matrixHandle) { const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); get_canvas(canvasHandle)->setMatrix(matrix ? *matrix : SkMatrix::I()); }
static void drawPath(JNIEnv* env, jobject, jlong canvasHandle, jlong pathHandle, jlong paintHandle) { const SkPath* path = reinterpret_cast<SkPath*>(pathHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle); get_canvas(canvasHandle)->drawPath(*path, *paint); }
static jboolean clipRect(JNIEnv*, jobject, jlong canvasHandle, jfloat l, jfloat t, jfloat r, jfloat b, jint opHandle) { SkRegion::Op op = static_cast<SkRegion::Op>(opHandle); bool emptyClip = get_canvas(canvasHandle)->clipRect(l, t, r, b, op); return emptyClip ? JNI_FALSE : JNI_TRUE; }
// Set the given bitmap as the new draw target (wrapped in a new SkCanvas), // optionally copying canvas matrix & clip state. static void setBitmap(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, jboolean copyState) { SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); get_canvas(canvasHandle)->setBitmap(bitmap, copyState); }
static void drawColor(JNIEnv* env, jobject, jlong canvasHandle, jint color, jint modeHandle) { SkPorterDuff::Mode mode = static_cast<SkPorterDuff::Mode>(modeHandle); get_canvas(canvasHandle)->drawColor(color, SkPorterDuff::ToXfermodeMode(mode)); }
static jint getWidth(JNIEnv*, jobject, jlong canvasHandle) { return static_cast<jint>(get_canvas(canvasHandle)->width()); }
static void drawPaint(JNIEnv* env, jobject, jlong canvasHandle, jlong paintHandle) { Paint* paint = reinterpret_cast<Paint*>(paintHandle); get_canvas(canvasHandle)->drawPaint(*paint); }
static void setDrawFilter(JNIEnv* env, jobject, jlong canvasHandle, jlong filterHandle) { get_canvas(canvasHandle)->setDrawFilter(reinterpret_cast<SkDrawFilter*>(filterHandle)); }
static void drawPoint(JNIEnv*, jobject, jlong canvasHandle, jfloat x, jfloat y, jlong paintHandle) { const Paint* paint = reinterpret_cast<Paint*>(paintHandle); get_canvas(canvasHandle)->drawPoint(x, y, *paint); }
static jint save(JNIEnv*, jobject, jlong canvasHandle, jint flagsHandle) { SkCanvas::SaveFlags flags = static_cast<SkCanvas::SaveFlags>(flagsHandle); return static_cast<jint>(get_canvas(canvasHandle)->save(flags)); }
static void drawLine(JNIEnv* env, jobject, jlong canvasHandle, jfloat startX, jfloat startY, jfloat stopX, jfloat stopY, jlong paintHandle) { Paint* paint = reinterpret_cast<Paint*>(paintHandle); get_canvas(canvasHandle)->drawLine(startX, startY, stopX, stopY, *paint); }
static jint saveLayerAlpha(JNIEnv* env, jobject, jlong canvasHandle, jfloat l, jfloat t, jfloat r, jfloat b, jint alpha, jint flagsHandle) { SkCanvas::SaveFlags flags = static_cast<SkCanvas::SaveFlags>(flagsHandle); return static_cast<jint>(get_canvas(canvasHandle)->saveLayerAlpha(l, t, r, b, alpha, flags)); }
static void drawCircle(JNIEnv* env, jobject, jlong canvasHandle, jfloat cx, jfloat cy, jfloat radius, jlong paintHandle) { const Paint* paint = reinterpret_cast<Paint*>(paintHandle); get_canvas(canvasHandle)->drawCircle(cx, cy, radius, *paint); }
void TileMap::_update_dirty_quadrants() { if (!pending_update) return; if (!is_inside_tree()) return; if (!tile_set.is_valid()) return; VisualServer *vs = VisualServer::get_singleton(); Physics2DServer *ps = Physics2DServer::get_singleton(); Vector2 tofs = get_cell_draw_offset(); Vector2 tcenter = cell_size/2; Matrix32 nav_rel; if (navigation) nav_rel = get_relative_transform_to_parent(navigation); Vector2 qofs; SceneTree *st=SceneTree::get_singleton(); Color debug_collision_color; bool debug_shapes = st && st->is_debugging_collisions_hint(); if (debug_shapes) { debug_collision_color=st->get_debug_collisions_color(); } while (dirty_quadrant_list.first()) { Quadrant &q = *dirty_quadrant_list.first()->self(); for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) { vs->free(E->get()); } q.canvas_items.clear(); ps->body_clear_shapes(q.body); int shape_idx=0; if (navigation) { for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) { navigation->navpoly_remove(E->get().id); } q.navpoly_ids.clear(); } for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) { VS::get_singleton()->free(E->get().id); } q.occluder_instances.clear(); Ref<CanvasItemMaterial> prev_material; RID prev_canvas_item; RID prev_debug_canvas_item; for(int i=0;i<q.cells.size();i++) { Map<PosKey,Cell>::Element *E=tile_map.find( q.cells[i] ); Cell &c=E->get(); //moment of truth if (!tile_set->has_tile(c.id)) continue; Ref<Texture> tex = tile_set->tile_get_texture(c.id); Vector2 tile_ofs = tile_set->tile_get_texture_offset(c.id); Vector2 wofs = _map_to_world(E->key().x, E->key().y); Vector2 offset = wofs - q.pos + tofs; if (!tex.is_valid()) continue; Ref<CanvasItemMaterial> mat = tile_set->tile_get_material(c.id); RID canvas_item; RID debug_canvas_item; if (prev_canvas_item==RID() || prev_material!=mat) { canvas_item=vs->canvas_item_create(); if (mat.is_valid()) vs->canvas_item_set_material(canvas_item,mat->get_rid()); vs->canvas_item_set_parent( canvas_item, get_canvas_item() ); Matrix32 xform; xform.set_origin( q.pos ); vs->canvas_item_set_transform( canvas_item, xform ); vs->canvas_item_set_light_mask(canvas_item,get_light_mask()); q.canvas_items.push_back(canvas_item); if (debug_shapes) { debug_canvas_item=vs->canvas_item_create(); vs->canvas_item_set_parent( debug_canvas_item, canvas_item ); vs->canvas_item_set_z_as_relative_to_parent(debug_canvas_item,false); vs->canvas_item_set_z(debug_canvas_item,VS::CANVAS_ITEM_Z_MAX-1); q.canvas_items.push_back(debug_canvas_item); prev_debug_canvas_item=debug_canvas_item; } prev_canvas_item=canvas_item; prev_material=mat; } else { canvas_item=prev_canvas_item; if (debug_shapes) { debug_canvas_item=prev_debug_canvas_item; } } Rect2 r = tile_set->tile_get_region(c.id); Size2 s = tex->get_size(); if (r==Rect2()) s = tex->get_size(); else { s = r.size; r.pos.x+=fp_adjust; r.pos.y+=fp_adjust; r.size.x-=fp_adjust*2.0; r.size.y-=fp_adjust*2.0; } Rect2 rect; rect.pos=offset.floor(); rect.size=s; if (rect.size.y > rect.size.x) { if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose)) tile_ofs.y += rect.size.y - rect.size.x; } else if (rect.size.y < rect.size.x) { if ((c.flip_v && (c.flip_h || c.transpose)) || (c.flip_h && !c.transpose)) tile_ofs.x += rect.size.x - rect.size.y; } /* rect.size.x+=fp_adjust; rect.size.y+=fp_adjust;*/ if (c.transpose) SWAP(tile_ofs.x, tile_ofs.y); if (c.flip_h) { rect.size.x=-rect.size.x; tile_ofs.x=-tile_ofs.x; } if (c.flip_v) { rect.size.y=-rect.size.y; tile_ofs.y=-tile_ofs.y; } Vector2 center_ofs; if (tile_origin==TILE_ORIGIN_TOP_LEFT) { rect.pos+=tile_ofs; } else if (tile_origin==TILE_ORIGIN_CENTER) { rect.pos+=tcenter; Vector2 center = (s/2) - tile_ofs; center_ofs=tcenter-(s/2); if (c.flip_h) rect.pos.x-=s.x-center.x; else rect.pos.x-=center.x; if (c.flip_v) rect.pos.y-=s.y-center.y; else rect.pos.y-=center.y; } if (r==Rect2()) { tex->draw_rect(canvas_item,rect,false,Color(1,1,1),c.transpose); } else { tex->draw_rect_region(canvas_item,rect,r,Color(1,1,1),c.transpose); } Vector< Ref<Shape2D> > shapes = tile_set->tile_get_shapes(c.id); for(int i=0;i<shapes.size();i++) { Ref<Shape2D> shape = shapes[i]; if (shape.is_valid()) { Vector2 shape_ofs = tile_set->tile_get_shape_offset(c.id); Matrix32 xform; xform.set_origin(offset.floor()); _fix_cell_transform(xform,c,shape_ofs+center_ofs,s); if (debug_canvas_item) { shape->draw(debug_canvas_item,debug_collision_color); } ps->body_add_shape(q.body,shape->get_rid(),xform); ps->body_set_shape_metadata(q.body,shape_idx++,Vector2(E->key().x,E->key().y)); } } if (navigation) { Ref<NavigationPolygon> navpoly = tile_set->tile_get_navigation_polygon(c.id); if (navpoly.is_valid()) { Vector2 npoly_ofs = tile_set->tile_get_navigation_polygon_offset(c.id); Matrix32 xform; xform.set_origin(offset.floor()+q.pos); _fix_cell_transform(xform,c,npoly_ofs+center_ofs,s); int pid = navigation->navpoly_create(navpoly,nav_rel * xform); Quadrant::NavPoly np; np.id=pid; np.xform=xform; q.navpoly_ids[E->key()]=np; } } Ref<OccluderPolygon2D> occluder=tile_set->tile_get_light_occluder(c.id); if (occluder.is_valid()) { Vector2 occluder_ofs = tile_set->tile_get_occluder_offset(c.id); Matrix32 xform; xform.set_origin(offset.floor()+q.pos); _fix_cell_transform(xform,c,occluder_ofs+center_ofs,s); RID orid = VS::get_singleton()->canvas_light_occluder_create(); VS::get_singleton()->canvas_light_occluder_set_transform(orid,get_global_transform() * xform); VS::get_singleton()->canvas_light_occluder_set_polygon(orid,occluder->get_rid()); VS::get_singleton()->canvas_light_occluder_attach_to_canvas(orid,get_canvas()); VS::get_singleton()->canvas_light_occluder_set_light_mask(orid,occluder_light_mask); Quadrant::Occluder oc; oc.xform=xform; oc.id=orid; q.occluder_instances[E->key()]=oc; } } dirty_quadrant_list.remove( dirty_quadrant_list.first() ); } pending_update=false; if (quadrant_order_dirty) { for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) { Quadrant &q=E->get(); for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) { VS::get_singleton()->canvas_item_raise(E->get()); } } quadrant_order_dirty=false; } _recompute_rect_cache(); }
static void drawOval(JNIEnv* env, jobject, jlong canvasHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, jlong paintHandle) { const Paint* paint = reinterpret_cast<Paint*>(paintHandle); get_canvas(canvasHandle)->drawOval(left, top, right, bottom, *paint); }
float Label::get_preferred_content_height(float width) { Canvas canvas = get_canvas(); return get_render_text_box(canvas, impl->text).get_height(); }
void ViewWorkspace::on_input_message(clan::GUIMessage_Input msg) { clan::Canvas canvas = get_canvas(); clan::InputEvent input_event = msg.input_event; if (input_event.type == clan::InputEvent::pressed && input_event.id == clan::mouse_left) { clan::Point mouse_pos = input_event.mouse_pos; for (std::vector<ViewPage>::size_type page_index = 0; page_index < pages.size(); page_index++) { if (pages[page_index].position.contains(mouse_pos)) { clan::SpanLayout::HitTestResult result = pages[page_index].span.hit_test(canvas, mouse_pos); if (page_index == current_page_index && result.type == clan::SpanLayout::HitTestResult::inside && result.object_id == 0) { if (!cb_view_close.is_null()) cb_view_close.invoke(pages[page_index].view); } else { show_view(page_index); } break; } } msg.consumed = true; } else if (input_event.type == clan::InputEvent::released && input_event.id == clan::mouse_left) { msg.consumed = true; } else if (input_event.type == clan::InputEvent::pointer_moved) { bool new_hot_state = false; clan::Point mouse_pos = input_event.mouse_pos; bool no_match = true; for (std::vector<ViewPage>::size_type page_index = 0; page_index < pages.size(); page_index++) { if (pages[page_index].position.contains(mouse_pos)) { no_match = false; clan::SpanLayout::HitTestResult result = pages[page_index].span.hit_test(canvas, mouse_pos); if (page_index == current_page_index && result.type == clan::SpanLayout::HitTestResult::inside && result.object_id == 0) { new_hot_state = true; } } } if (new_hot_state != hot) { hot = new_hot_state; request_repaint(); } msg.consumed = true; } else if (input_event.type == clan::InputEvent::pressed && input_event.ctrl) { switch (input_event.id) { case clan::keycode_tab: if (input_event.shift) previous_view(); else next_view(); msg.consumed = true; break; } } }