82 const float old_aspect = oldwidth / oldheight;
88 bool has_frame =
false;
91 if ((node->flag & node_flag) == node_flag) {
95 if (node->is_frame()) {
108 const float new_aspect = width / height;
112 if ((tot == 1) && (has_frame ==
false) && ((oldwidth * oldheight) > (width * height))) {
117 if (old_aspect < new_aspect) {
118 const float height_new = width / old_aspect;
119 cur_new.
ymin = cur_new.
ymin - height_new / 2.0f;
120 cur_new.
ymax = cur_new.
ymax + height_new / 2.0f;
123 const float width_new = height * old_aspect;
124 cur_new.
xmin = cur_new.
xmin - width_new / 2.0f;
125 cur_new.
xmax = cur_new.
xmax + width_new / 2.0f;
156 ot->name =
"Frame All";
157 ot->idname =
"NODE_OT_view_all";
158 ot->description =
"Resize view so you can see all nodes";
189 ot->name =
"Frame Selected";
190 ot->idname =
"NODE_OT_view_selected";
191 ot->description =
"Resize view so you can see selected nodes";
220 switch (event->
type) {
223 snode->
xof -= (nvm->
mvalo.x -
event->mval[0]);
224 snode->
yof -= (nvm->
mvalo.y -
event->mval[1]);
225 nvm->
mvalo.x =
event->mval[0];
226 nvm->
mvalo.y =
event->mval[1];
274 const float pad = 32.0f;
281 if (ibuf ==
nullptr) {
288 nvm->
mvalo.x =
event->mval[0];
289 nvm->
mvalo.y =
event->mval[1];
317 ot->name =
"Background Image Move";
318 ot->description =
"Move node backdrop";
319 ot->idname =
"NODE_OT_backimage_move";
355 ot->name =
"Background Image Zoom";
356 ot->idname =
"NODE_OT_backimage_zoom";
357 ot->description =
"Zoom in/out the background image";
367 RNA_def_float(
ot->srna,
"factor", 1.2f, 0.0f, 10.0f,
"Factor",
"", 0.0f, 10.0f);
385 const float pad = 32.0f;
394 if ((ibuf ==
nullptr) || (ibuf->
x == 0) || (ibuf->
y == 0)) {
399 facx = 1.0f * (region->
sizex -
pad) / (ibuf->
x * snode->
zoom);
400 facy = 1.0f * (region->
sizey -
pad) / (ibuf->
y * snode->
zoom);
420 ot->name =
"Background Image Fit";
421 ot->idname =
"NODE_OT_backimage_fit";
422 ot->description =
"Fit the background image to the view";
489 float bufx = ibuf->
x * snode->
zoom;
490 float bufy = ibuf->
y * snode->
zoom;
491 fpos[0] = (bufx > 0.0f ? (
float(mval[0]) - 0.5f * region->
winx - snode->
xof) / bufx + 0.5f :
493 fpos[1] = (bufy > 0.0f ? (
float(mval[1]) - 0.5f * region->
winy - snode->
yof) / bufy + 0.5f :
506 float fx, fy, bufx, bufy;
523 bufx = ibuf->
x * snode->
zoom;
524 bufy = ibuf->
y * snode->
zoom;
525 fx = (bufx > 0.0f ? (
float(mval[0]) - 0.5f * region->
winx - snode->
xof) / bufx + 0.5f : 0.0f);
526 fy = (bufy > 0.0f ? (
float(mval[1]) - 0.5f * region->
winy - snode->
yof) / bufy + 0.5f : 0.0f);
528 if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
531 int x = int(fx * ibuf->
x),
y = int(fy * ibuf->
y);
566 float fx, fy, bufx, bufy;
580 bufx = ibuf->
x * snode->
zoom;
581 bufy = ibuf->
y * snode->
zoom;
582 fx = (bufx > 0.0f ? (
float(event->
mval[0]) - 0.5f * region->
winx - snode->
xof) / bufx + 0.5f :
584 fy = (bufy > 0.0f ? (
float(event->
mval[1]) - 0.5f * region->
winy - snode->
yof) / bufy + 0.5f :
587 if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
590 int x = int(fx * ibuf->
x),
y = int(fy * ibuf->
y);
603 info->
col[0] = cp[0];
604 info->
col[1] = cp[1];
605 info->
col[2] = cp[2];
606 info->
col[3] = cp[3];
622 info->
colf[0] = fp[0];
623 info->
colf[1] = fp[1];
624 info->
colf[2] = fp[2];
625 info->
colf[3] = fp[3];
683 switch (event->
type) {
710 ot->name =
"Backimage Sample";
711 ot->idname =
"NODE_OT_backimage_sample";
712 ot->description =
"Use mouse to sample background image";
SpaceNode * CTX_wm_space_node(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
Image * BKE_image_ensure_viewer(Main *bmain, int type, const char *name)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
MINLINE float min_ff(float a, float b)
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
void BLI_rctf_scale(rctf *rect, float scale)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
void BLI_rctf_resize(struct rctf *rect, float x, float y)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
void BLI_rctf_init_minmax(struct rctf *rect)
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 ED_node_sample_set(const float col[4])
bool ED_node_is_compositor(const SpaceNode *snode)
void ED_area_tag_redraw(ScrArea *area)
bool ED_operator_node_active(bContext *C)
void ED_region_tag_redraw(ARegion *region)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
#define REGION_DRAW_POST_PIXEL
void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], const ColorSpace *colorspace)
void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, const ColorSpace *colorspace)
void IMB_byte_from_float(ImBuf *ibuf)
Read Guarded memory(de)allocation.
void UI_view2d_smooth_view(const bContext *C, ARegion *region, const rctf *cur, int smooth_viewtx)
#define ND_SPACE_NODE_VIEW
int pad[32 - sizeof(int)]
void * MEM_callocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
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 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 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)
VecBase< int32_t, 2 > int2
bool ED_space_node_get_position(Main *bmain, SpaceNode *snode, ARegion *region, const int mval[2], float fpos[2])
bool ED_space_node_color_sample(Main *bmain, SpaceNode *snode, ARegion *region, const int mval[2], float r_col[3])
float RNA_float_get(PointerRNA *ptr, const char *name)
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)
ARegionRuntimeHandle * runtime
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
struct bNodeTree * edittree
void WM_main_add_notifier(uint type, void *reference)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
int WM_operator_smooth_viewtx_get(const wmOperator *op)