From f68cfd6bb078482c4a779a6e26a56e2734edb5b8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 25 Sep 2022 18:33:28 +1000 Subject: Cleanup: replace C-style casts with functional casts for numeric types --- source/blender/editors/space_node/drawnode.cc | 2 +- source/blender/editors/space_node/node_draw.cc | 46 +++++++++++----------- source/blender/editors/space_node/node_edit.cc | 4 +- source/blender/editors/space_node/node_gizmo.cc | 4 +- .../editors/space_node/node_relationships.cc | 2 +- source/blender/editors/space_node/node_select.cc | 5 +-- source/blender/editors/space_node/node_view.cc | 24 +++++------ source/blender/editors/space_node/space_node.cc | 6 +-- 8 files changed, 46 insertions(+), 47 deletions(-) (limited to 'source/blender/editors/space_node') diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index b2510df9105..a4c054155dd 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -1764,7 +1764,7 @@ static void nodelink_batch_init() /* curve strip */ for (int i = 0; i < LINK_RESOL; i++) { - uv[0] = 255 * (i / (float)(LINK_RESOL - 1)); + uv[0] = 255 * (i / float(LINK_RESOL - 1)); uv[1] = 0; set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); uv[1] = 255; diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 98f10bfdfe5..8f72d292740 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -432,7 +432,7 @@ static void node_update_basis(const bContext &C, float aspect = 1.0f; if (node.preview_xsize && node.preview_ysize) { - aspect = (float)node.preview_ysize / (float)node.preview_xsize; + aspect = float(node.preview_ysize) / float(node.preview_xsize); } dy -= NODE_DYS / 2; @@ -597,7 +597,7 @@ static void node_update_hidden(bNode &node, uiBlock &block) float hiddenrad = HIDDEN_RAD; float tot = MAX2(totin, totout); if (tot > 4) { - hiddenrad += 5.0f * (float)(tot - 4); + hiddenrad += 5.0f * float(tot - 4); } node.totr.xmin = loc.x; @@ -606,7 +606,7 @@ static void node_update_hidden(bNode &node, uiBlock &block) node.totr.ymin = node.totr.ymax - 2 * hiddenrad; /* Output sockets. */ - float rad = (float)M_PI / (1.0f + (float)totout); + float rad = float(M_PI) / (1.0f + float(totout)); float drad = rad; LISTBASE_FOREACH (bNodeSocket *, socket, &node.outputs) { @@ -619,7 +619,7 @@ static void node_update_hidden(bNode &node, uiBlock &block) } /* Input sockets. */ - rad = drad = -(float)M_PI / (1.0f + (float)totin); + rad = drad = -float(M_PI) / (1.0f + float(totin)); LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) { if (!nodeSocketIsHidden(socket)) { @@ -1293,20 +1293,20 @@ static void node_draw_preview(bNodePreview *preview, rctf *prv) { float xrect = BLI_rctf_size_x(prv); float yrect = BLI_rctf_size_y(prv); - float xscale = xrect / ((float)preview->xsize); - float yscale = yrect / ((float)preview->ysize); + float xscale = xrect / float(preview->xsize); + float yscale = yrect / float(preview->ysize); float scale; /* Uniform scale and offset. */ rctf draw_rect = *prv; if (xscale < yscale) { - float offset = 0.5f * (yrect - ((float)preview->ysize) * xscale); + float offset = 0.5f * (yrect - float(preview->ysize) * xscale); draw_rect.ymin += offset; draw_rect.ymax -= offset; scale = xscale; } else { - float offset = 0.5f * (xrect - ((float)preview->xsize) * yscale); + float offset = 0.5f * (xrect - float(preview->xsize) * yscale); draw_rect.xmin += offset; draw_rect.xmax -= offset; scale = yscale; @@ -1930,8 +1930,8 @@ static void node_draw_extra_info_row(const bNode &node, UI_BTYPE_BUT, 0, extra_info_row.icon, - (int)but_icon_left, - (int)(rect.ymin + row * (20.0f * U.dpi_fac)), + int(but_icon_left), + int(rect.ymin + row * (20.0f * U.dpi_fac)), but_icon_width, UI_UNIT_Y, nullptr, @@ -1956,10 +1956,10 @@ static void node_draw_extra_info_row(const bNode &node, UI_BTYPE_LABEL, 0, extra_info_row.text.c_str(), - (int)but_text_left, - (int)(rect.ymin + row * (20.0f * U.dpi_fac)), - (short)but_text_width, - (short)NODE_DY, + int(but_text_left), + int(rect.ymin + row * (20.0f * U.dpi_fac)), + short(but_text_width), + short(NODE_DY), nullptr, 0, 0, @@ -2195,10 +2195,10 @@ static void node_draw_basis(const bContext &C, UI_BTYPE_LABEL, 0, showname, - (int)(rct.xmin + NODE_MARGIN_X + 0.4f), - (int)(rct.ymax - NODE_DY), - (short)(iconofs - rct.xmin - (18.0f * U.dpi_fac)), - (short)NODE_DY, + int(rct.xmin + NODE_MARGIN_X + 0.4f), + int(rct.ymax - NODE_DY), + short(iconofs - rct.xmin - (18.0f * U.dpi_fac)), + short(NODE_DY), nullptr, 0, 0, @@ -2425,8 +2425,8 @@ static void node_draw_hidden(const bContext &C, showname, round_fl_to_int(rct.xmin + NODE_MARGIN_X), round_fl_to_int(centy - NODE_DY * 0.5f), - (short)(BLI_rctf_size_x(&rct) - ((18.0f + 12.0f) * U.dpi_fac)), - (short)NODE_DY, + short(BLI_rctf_size_x(&rct) - ((18.0f + 12.0f) * U.dpi_fac)), + short(NODE_DY), nullptr, 0, 0, @@ -2722,7 +2722,7 @@ static void frame_node_draw_label(const bNodeTree &ntree, UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color); BLF_color3ubv(fontid, color); - const float margin = (float)(NODE_DY / 4); + const float margin = float(NODE_DY / 4); const float width = BLF_width(fontid, label, sizeof(label)); const float ascender = BLF_ascender(fontid); const int label_height = ((margin / aspect) + (ascender * aspect)); @@ -2866,7 +2866,7 @@ static void reroute_node_draw( x, y, width, - (short)NODE_DY, + short(NODE_DY), nullptr, 0, 0, @@ -3013,7 +3013,7 @@ static void snode_setup_v2d(SpaceNode &snode, ARegion ®ion, const float2 &cen UI_view2d_view_ortho(&v2d); /* Aspect + font, set each time. */ - snode.runtime->aspect = BLI_rctf_size_x(&v2d.cur) / (float)region.winx; + snode.runtime->aspect = BLI_rctf_size_x(&v2d.cur) / float(region.winx); // XXX snode->curfont = uiSetCurFont_ext(snode->aspect); } diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index 31d99eafbc1..e446d5421e7 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -2859,8 +2859,8 @@ static void viewer_border_corner_to_backdrop(SpaceNode *snode, float bufx = backdrop_width * snode->zoom; float bufy = backdrop_height * snode->zoom; - *fx = (bufx > 0.0f ? ((float)x - 0.5f * region->winx - snode->xof) / bufx + 0.5f : 0.0f); - *fy = (bufy > 0.0f ? ((float)y - 0.5f * region->winy - snode->yof) / bufy + 0.5f : 0.0f); + *fx = (bufx > 0.0f ? (float(x) - 0.5f * region->winx - snode->xof) / bufx + 0.5f : 0.0f); + *fy = (bufy > 0.0f ? (float(y) - 0.5f * region->winy - snode->yof) / bufy + 0.5f : 0.0f); } static int viewer_border_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/space_node/node_gizmo.cc b/source/blender/editors/space_node/node_gizmo.cc index f9126556b71..a6c9538d782 100644 --- a/source/blender/editors/space_node/node_gizmo.cc +++ b/source/blender/editors/space_node/node_gizmo.cc @@ -252,7 +252,7 @@ static void gizmo_node_crop_prop_matrix_get(const wmGizmo *gz, const float *dims = crop_group->state.dims; const bNode *node = (const bNode *)gz_prop->custom_func.user_data; const NodeTwoXYs *nxy = (const NodeTwoXYs *)node->storage; - bool is_relative = (bool)node->custom2; + bool is_relative = bool(node->custom2); rctf rct; two_xy_to_rect(nxy, &rct, dims, is_relative); matrix[0][0] = fabsf(BLI_rctf_size_x(&rct)); @@ -271,7 +271,7 @@ static void gizmo_node_crop_prop_matrix_set(const wmGizmo *gz, const float *dims = crop_group->state.dims; bNode *node = (bNode *)gz_prop->custom_func.user_data; NodeTwoXYs *nxy = (NodeTwoXYs *)node->storage; - bool is_relative = (bool)node->custom2; + bool is_relative = bool(node->custom2); rctf rct; two_xy_to_rect(nxy, &rct, dims, is_relative); const bool nx = rct.xmin > rct.xmax; diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index e12ab3191cb..f597bf20b55 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -2323,7 +2323,7 @@ static int node_insert_offset_modal(bContext *C, wmOperator *op, const wmEvent * return OPERATOR_PASS_THROUGH; } - const float duration = (float)iofsd->anim_timer->duration; + const float duration = float(iofsd->anim_timer->duration); /* handle animation - do this before possibly aborting due to duration, since * main thread might be so busy that node hasn't reached final position yet */ diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc index d93b205b1b7..1b47316ebd0 100644 --- a/source/blender/editors/space_node/node_select.cc +++ b/source/blender/editors/space_node/node_select.cc @@ -843,8 +843,7 @@ static int node_circleselect_exec(bContext *C, wmOperator *op) int x, y, radius; float2 offset; - float zoom = (float)(BLI_rcti_size_x(®ion->winrct)) / - (float)(BLI_rctf_size_x(®ion->v2d.cur)); + float zoom = float(BLI_rcti_size_x(®ion->winrct)) / float(BLI_rctf_size_x(®ion->v2d.cur)); const eSelectOp sel_op = ED_select_op_modal( (eSelectOp)RNA_enum_get(op->ptr, "mode"), @@ -867,7 +866,7 @@ static int node_circleselect_exec(bContext *C, wmOperator *op) /* Frame nodes are selectable by their borders (including their whole rect - as for other * nodes - would prevent selection of _only_ other nodes inside that frame. */ rctf frame_inside = node_frame_rect_inside(*node); - const float radius_adjusted = (float)radius / zoom; + const float radius_adjusted = float(radius) / zoom; BLI_rctf_pad(&frame_inside, -2.0f * radius_adjusted, -2.0f * radius_adjusted); if (BLI_rctf_isect_circle(&node->totr, offset, radius_adjusted) && !BLI_rctf_isect_circle(&frame_inside, offset, radius_adjusted)) { diff --git a/source/blender/editors/space_node/node_view.cc b/source/blender/editors/space_node/node_view.cc index 33a75385022..2c02e3c6ecc 100644 --- a/source/blender/editors/space_node/node_view.cc +++ b/source/blender/editors/space_node/node_view.cc @@ -464,9 +464,9 @@ bool ED_space_node_get_position( /* map the mouse coords to the backdrop image space */ float bufx = ibuf->x * snode->zoom; float bufy = ibuf->y * snode->zoom; - fpos[0] = (bufx > 0.0f ? ((float)mval[0] - 0.5f * region->winx - snode->xof) / bufx + 0.5f : + fpos[0] = (bufx > 0.0f ? (float(mval[0]) - 0.5f * region->winx - snode->xof) / bufx + 0.5f : 0.0f); - fpos[1] = (bufy > 0.0f ? ((float)mval[1] - 0.5f * region->winy - snode->yof) / bufy + 0.5f : + fpos[1] = (bufy > 0.0f ? (float(mval[1]) - 0.5f * region->winy - snode->yof) / bufy + 0.5f : 0.0f); BKE_image_release_ibuf(ima, ibuf, lock); @@ -498,13 +498,13 @@ bool ED_space_node_color_sample( /* map the mouse coords to the backdrop image space */ bufx = ibuf->x * snode->zoom; bufy = ibuf->y * snode->zoom; - fx = (bufx > 0.0f ? ((float)mval[0] - 0.5f * region->winx - snode->xof) / bufx + 0.5f : 0.0f); - fy = (bufy > 0.0f ? ((float)mval[1] - 0.5f * region->winy - snode->yof) / bufy + 0.5f : 0.0f); + fx = (bufx > 0.0f ? (float(mval[0]) - 0.5f * region->winx - snode->xof) / bufx + 0.5f : 0.0f); + fy = (bufy > 0.0f ? (float(mval[1]) - 0.5f * region->winy - snode->yof) / bufy + 0.5f : 0.0f); if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { const float *fp; uchar *cp; - int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); + int x = int(fx * ibuf->x), y = int(fy * ibuf->y); CLAMP(x, 0, ibuf->x - 1); CLAMP(y, 0, ibuf->y - 1); @@ -555,15 +555,15 @@ static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event) /* map the mouse coords to the backdrop image space */ bufx = ibuf->x * snode->zoom; bufy = ibuf->y * snode->zoom; - fx = (bufx > 0.0f ? ((float)event->mval[0] - 0.5f * region->winx - snode->xof) / bufx + 0.5f : + fx = (bufx > 0.0f ? (float(event->mval[0]) - 0.5f * region->winx - snode->xof) / bufx + 0.5f : 0.0f); - fy = (bufy > 0.0f ? ((float)event->mval[1] - 0.5f * region->winy - snode->yof) / bufy + 0.5f : + fy = (bufy > 0.0f ? (float(event->mval[1]) - 0.5f * region->winy - snode->yof) / bufy + 0.5f : 0.0f); if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { const float *fp; uchar *cp; - int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); + int x = int(fx * ibuf->x), y = int(fy * ibuf->y); CLAMP(x, 0, ibuf->x - 1); CLAMP(y, 0, ibuf->y - 1); @@ -584,10 +584,10 @@ static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event) info->col[2] = cp[2]; info->col[3] = cp[3]; - info->colf[0] = (float)cp[0] / 255.0f; - info->colf[1] = (float)cp[1] / 255.0f; - info->colf[2] = (float)cp[2] / 255.0f; - info->colf[3] = (float)cp[3] / 255.0f; + info->colf[0] = float(cp[0]) / 255.0f; + info->colf[1] = float(cp[1]) / 255.0f; + info->colf[2] = float(cp[2]) / 255.0f; + info->colf[3] = float(cp[3]) / 255.0f; copy_v4_v4(info->linearcol, info->colf); IMB_colormanagement_colorspace_to_scene_linear_v4( diff --git a/source/blender/editors/space_node/space_node.cc b/source/blender/editors/space_node/space_node.cc index fae3eb1a143..b02f22f378f 100644 --- a/source/blender/editors/space_node/space_node.cc +++ b/source/blender/editors/space_node/space_node.cc @@ -672,14 +672,14 @@ static void node_group_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *d { ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0); - RNA_int_set(drop->ptr, "session_uuid", (int)id->session_uuid); + RNA_int_set(drop->ptr, "session_uuid", int(id->session_uuid)); } static void node_id_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop) { ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0); - RNA_int_set(drop->ptr, "session_uuid", (int)id->session_uuid); + RNA_int_set(drop->ptr, "session_uuid", int(id->session_uuid)); } static void node_id_path_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop) @@ -687,7 +687,7 @@ static void node_id_path_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0); if (id) { - RNA_int_set(drop->ptr, "session_uuid", (int)id->session_uuid); + RNA_int_set(drop->ptr, "session_uuid", int(id->session_uuid)); RNA_struct_property_unset(drop->ptr, "filepath"); } else if (drag->path[0]) { -- cgit v1.2.3