84 const float old_aspect = oldwidth / oldheight;
92 if ((
node->flag & node_flag) == node_flag) {
105 const float new_aspect = width / height;
107 if (old_aspect < new_aspect) {
108 const float height_new = width / old_aspect;
109 cur_new.
ymin = cur_new.
ymin - height_new / 4.0f;
110 cur_new.
ymax = cur_new.
ymax + height_new / 4.0f;
113 const float width_new = height * old_aspect;
114 cur_new.
xmin = cur_new.
xmin - width_new / 4.0f;
115 cur_new.
xmax = cur_new.
xmax + width_new / 4.0f;
145 ot->
name =
"Frame All";
146 ot->
idname =
"NODE_OT_view_all";
147 ot->
description =
"Resize view so you can see all nodes";
178 ot->
name =
"Frame Selected";
179 ot->
idname =
"NODE_OT_view_selected";
180 ot->
description =
"Resize view so you can see selected nodes";
209 switch (event->
type) {
212 snode->
xof -= (nvm->
mvalo.x -
event->mval[0]);
213 snode->
yof -= (nvm->
mvalo.y -
event->mval[1]);
214 nvm->
mvalo.x =
event->mval[0];
215 nvm->
mvalo.y =
event->mval[1];
263 const float pad = 32.0f;
270 if (ibuf ==
nullptr) {
277 nvm->
mvalo.x =
event->mval[0];
278 nvm->
mvalo.y =
event->mval[1];
306 ot->
name =
"Background Image Move";
308 ot->
idname =
"NODE_OT_backimage_move";
365 MEM_SAFE_DELETE(zdata);
389 float2 img_offset = {snode->
xof + (
event->mval[0] - img_center.x) * (1 - fac),
390 snode->
yof + (
event->mval[1] - img_center.y) * (1 - fac)};
392 zdata->
offset = {img_offset.x, img_offset.y};
402 ot->
name =
"Background Image Zoom";
403 ot->
idname =
"NODE_OT_backimage_zoom";
404 ot->
description =
"Zoom in/out the background image";
416 RNA_def_boolean(ot->
srna,
"use_mouse_pos",
true,
"Use Mouse Position",
"Zoom to mouse position");
434 const float pad = 32.0f;
443 if ((ibuf ==
nullptr) || (ibuf->
x == 0) || (ibuf->
y == 0)) {
448 facx = 1.0f * (region->
sizex -
pad) / (ibuf->
x * snode->
zoom);
449 facy = 1.0f * (region->
sizey -
pad) / (ibuf->
y * snode->
zoom);
469 ot->
name =
"Background Image Fit";
470 ot->
idname =
"NODE_OT_backimage_fit";
471 ot->
description =
"Fit the background image to the view";
538 float bufx = ibuf->
x * snode->
zoom;
539 float bufy = ibuf->
y * snode->
zoom;
540 fpos[0] = (bufx > 0.0f ? (
float(mval[0]) - 0.5f * region->
winx - snode->
xof) / bufx + 0.5f :
542 fpos[1] = (bufy > 0.0f ? (
float(mval[1]) - 0.5f * region->
winy - snode->
yof) / bufy + 0.5f :
555 float fx, fy, bufx, bufy;
572 bufx = ibuf->
x * snode->
zoom;
573 bufy = ibuf->
y * snode->
zoom;
574 fx = (bufx > 0.0f ? (
float(mval[0]) - 0.5f * region->
winx - snode->
xof) / bufx + 0.5f : 0.0f);
575 fy = (bufy > 0.0f ? (
float(mval[1]) - 0.5f * region->
winy - snode->
yof) / bufy + 0.5f : 0.0f);
577 if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
580 int x = int(fx * ibuf->
x),
y = int(fy * ibuf->
y);
585 if (
const float *float_data = ibuf->
float_data()) {
586 fp = (float_data + (ibuf->
channels) * (
y * ibuf->
x +
x));
591 cp = byte_data + 4 * (
y * ibuf->
x +
x);
603namespace ed::space_node {
614 float fx, fy, bufx, bufy;
628 bufx = ibuf->
x * snode->
zoom;
629 bufy = ibuf->
y * snode->
zoom;
630 fx = (bufx > 0.0f ? (
float(event->
mval[0]) - 0.5f * region->
winx - snode->
xof) / bufx + 0.5f :
632 fy = (bufy > 0.0f ? (
float(event->
mval[1]) - 0.5f * region->
winy - snode->
yof) / bufy + 0.5f :
635 if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
638 int x = int(fx * ibuf->
x),
y = int(fy * ibuf->
y);
649 cp = byte_data + 4 * (
y * ibuf->
x +
x);
651 info->
col[0] = cp[0];
652 info->
col[1] = cp[1];
653 info->
col[2] = cp[2];
654 info->
col[3] = cp[3];
667 if (
const float *float_data = ibuf->
float_data()) {
668 fp = float_data + (ibuf->
channels) * (
y * ibuf->
x +
x);
670 info->
colf[0] = fp[0];
671 info->
colf[1] = fp[1];
672 info->
colf[2] = fp[2];
673 info->
colf[3] = fp[3];
731 switch (event->
type) {
758 ot->
name =
"Backimage Sample";
759 ot->
idname =
"NODE_OT_backimage_sample";
760 ot->
description =
"Use mouse to sample background image";
#define REGION_DRAW_POST_PIXEL
Read Blender memory allocation and freeing.
#define ND_SPACE_NODE_VIEW
int pad[32 - sizeof(int)]
static bool space_node_composite_active_view_poll(bContext *C)
static wmOperatorStatus node_view_all_exec(bContext *C, wmOperator *op)
static wmOperatorStatus backimage_fit_exec(bContext *C, wmOperator *)
bool space_node_view_flag(bContext &C, SpaceNode &snode, ARegion ®ion, int node_flag, int smooth_viewtx)
void NODE_OT_backimage_sample(wmOperatorType *ot)
static wmOperatorStatus sample_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void NODE_OT_backimage_zoom(wmOperatorType *ot)
static wmOperatorStatus node_view_selected_exec(bContext *C, wmOperator *op)
void NODE_OT_backimage_move(wmOperatorType *ot)
static void sample_exit(bContext *C, wmOperator *op)
static void sample_cancel(bContext *C, wmOperator *op)
void NODE_OT_view_selected(wmOperatorType *ot)
static wmOperatorStatus backimage_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus sample_modal(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus snode_bg_viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void sample_draw(const bContext *C, ARegion *region, void *arg_info)
static bool space_node_active_view_poll(bContext *C)
static void snode_bg_viewmove_cancel(bContext *, wmOperator *op)
void NODE_OT_view_all(wmOperatorType *ot)
bool node_or_socket_isect_event(const bContext &C, const wmEvent &event)
static void backimage_zoom_init(bContext *C, wmOperator *op)
static wmOperatorStatus backimage_zoom_exec(bContext *C, wmOperator *op)
bool composite_node_active(bContext *C)
static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus snode_bg_viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
void NODE_OT_backimage_fit(wmOperatorType *ot)
void view2d_smooth_view(const bContext *C, ARegion *region, const rctf *cur, int smooth_viewtx)
MINLINE float min_ff(float a, float b)
void WM_main_add_notifier(uint type, void *reference)
bool ED_node_is_compositor(const SpaceNode *snode)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool ED_operator_node_active(bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void ED_node_sample_set(const float col[4])
int WM_operator_smooth_viewtx_get(const wmOperator *op)
void ED_image_draw_info(Scene *scene, ARegion *region, bool color_manage, bool use_default_view, int channels, int x, int y, const unsigned char cp[4], const float fp[4], const float linearcol[4])
void BLI_rctf_scale(rctf *rect, float scale)
void ED_region_tag_redraw(ARegion *region)
void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], const ColorSpace *colorspace)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
void BLI_rctf_init_minmax(struct rctf *rect)
SpaceNode * CTX_wm_space_node(const bContext *C)
bool ED_space_node_color_sample(Main *bmain, SpaceNode *snode, ARegion *region, const int mval[2], float r_col[3])
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, const ColorSpace *colorspace)
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
Main * CTX_data_main(const bContext *C)
void IMB_byte_from_float(ImBuf *ibuf)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Image * BKE_image_ensure_viewer(Main *bmain, int type, const char *name)
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
Scene * CTX_data_scene(const bContext *C)
MINLINE void copy_v4_v4(float r[4], const float a[4])
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool ED_space_node_get_position(Main *bmain, SpaceNode *snode, ARegion *region, const int mval[2], float fpos[2])
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
ARegion * CTX_wm_region(const bContext *C)
float RNA_float_get(PointerRNA *ptr, const char *name)
void ED_area_tag_redraw(ScrArea *area)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
const ColorSpace * colorspace
ImBufByteBuffer byte_buffer
const uint8_t * byte_data() const
const float * float_data() const
struct bNodeTree * edittree
struct ARegionType * type
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(*) cancel(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT