Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2011-01-31 17:42:55 +0300
committerLukas Toenne <lukas.toenne@googlemail.com>2011-01-31 17:42:55 +0300
commit56962346be08c6aacf3563530eebd2642a128fc4 (patch)
tree6b17b8a94dc1cb1c540ff1bd1dd9f877016a12b7 /source/blender/editors/space_node
parent7215e5085e803dd50272fad91cd1fe53ad2c905d (diff)
Added backdrop image color information to the node editor. When clicking on empty space in the node editor, the pixel color values will be displayed on the bottom like in image editor.
Diffstat (limited to 'source/blender/editors/space_node')
-rw-r--r--source/blender/editors/space_node/CMakeLists.txt1
-rw-r--r--source/blender/editors/space_node/drawnode.c43
-rw-r--r--source/blender/editors/space_node/node_edit.c167
-rw-r--r--source/blender/editors/space_node/node_intern.h3
-rw-r--r--source/blender/editors/space_node/node_ops.c3
5 files changed, 216 insertions, 1 deletions
diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt
index 6ade219583a..c615f5cc85f 100644
--- a/source/blender/editors/space_node/CMakeLists.txt
+++ b/source/blender/editors/space_node/CMakeLists.txt
@@ -21,6 +21,7 @@
set(INC
../include
+ ../../blenfont
../../blenkernel
../../blenlib
../../imbuf
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index a17fceb4fff..31706154dc2 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -55,6 +55,8 @@
#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "BLF_api.h"
+
#include "MEM_guardedalloc.h"
@@ -1409,6 +1411,47 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
}
}
+void draw_nodespace_color_info(ARegion *ar, int channels, int x, int y, char *cp, float *fp)
+{
+ char str[256];
+ int ofs;
+
+ ofs= sprintf(str, "X: %4d Y: %4d ", x, y);
+
+ if(channels==4) {
+ if(cp)
+ ofs+= sprintf(str+ofs, "| R: %3d G: %3d B: %3d A: %3d ", cp[0], cp[1], cp[2], cp[3]);
+ if (fp)
+ ofs+= sprintf(str+ofs, "| R: %.3f G: %.3f B: %.3f A: %.3f ", fp[0], fp[1], fp[2], fp[3]);
+ }
+ else if(channels==1) {
+ if(cp)
+ ofs+= sprintf(str+ofs, "| Val: %3d ", cp[0]);
+ if (fp)
+ ofs+= sprintf(str+ofs, "| Val: %.3f ", fp[0]);
+ }
+ else if(channels==3) {
+ if(cp)
+ ofs+= sprintf(str+ofs, "| R: %3d G: %3d B: %3d ", cp[0], cp[1], cp[2]);
+ if (fp)
+ ofs+= sprintf(str+ofs, "| R: %.3f G: %.3f B: %.3f ", fp[0], fp[1], fp[2]);
+ }
+
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glColor4f(.0,.0,.0,.25);
+ glRecti(0.0, 0.0, ar->winrct.xmax - ar->winrct.xmin + 1, 20);
+ glDisable(GL_BLEND);
+
+ glColor3ub(255, 255, 255);
+
+ // UI_DrawString(6, 6, str); // works ok but fixed width is nicer.
+ BLF_size(blf_mono_font, 11, 72);
+ BLF_position(blf_mono_font, 6, 6, 0);
+ BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+}
+
#if 0
/* note: needs to be userpref or opengl profile option */
static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index cf5822d0461..60eba173e1d 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -53,6 +53,7 @@
#include "BKE_node.h"
#include "BKE_material.h"
#include "BKE_paint.h"
+#include "BKE_screen.h"
#include "BKE_texture.h"
#include "BKE_report.h"
@@ -62,6 +63,7 @@
#include "ED_node.h"
#include "ED_screen.h"
+#include "ED_space_api.h"
#include "ED_render.h"
#include "RNA_access.h"
@@ -73,6 +75,8 @@
#include "UI_interface.h"
#include "UI_view2d.h"
+#include "IMB_imbuf.h"
+
#include "node_intern.h"
#define SOCK_IN 1
@@ -869,6 +873,169 @@ void NODE_OT_backimage_zoom(wmOperatorType *ot)
RNA_def_float(ot->srna, "factor", 1.2f, 0.0f, 10.0f, "Factor", "", 0.0f, 10.0f);
}
+/******************** sample backdrop operator ********************/
+
+typedef struct ImageSampleInfo {
+ ARegionType *art;
+ void *draw_handle;
+ int x, y;
+ int channels;
+ int color_manage;
+
+ char col[4];
+ float colf[4];
+
+ int draw;
+} ImageSampleInfo;
+
+static void sample_draw(const bContext *UNUSED(C), ARegion *ar, void *arg_info)
+{
+ ImageSampleInfo *info= arg_info;
+
+ draw_nodespace_color_info(ar, info->channels, info->x, info->y, info->col, info->colf);
+}
+
+static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
+{
+ SpaceNode *snode= CTX_wm_space_node(C);
+ ARegion *ar= CTX_wm_region(C);
+ ImageSampleInfo *info= op->customdata;
+ void *lock;
+ Image *ima;
+ ImBuf *ibuf;
+ float fx, fy, bufx, bufy;
+ int mx, my;
+
+ ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
+ ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
+ if(!ibuf)
+ return;
+
+ if(!ibuf->rect) {
+ if(info->color_manage)
+ ibuf->profile = IB_PROFILE_LINEAR_RGB;
+ else
+ ibuf->profile = IB_PROFILE_NONE;
+ IMB_rect_from_float(ibuf);
+ }
+
+ mx= event->x - ar->winrct.xmin;
+ my= event->y - ar->winrct.ymin;
+ /* map the mouse coords to the backdrop image space */
+ bufx = ibuf->x * snode->zoom;
+ bufy = ibuf->y * snode->zoom;
+ fx = (bufx > 0.0f ? ((float)mx - 0.5f*ar->winx - snode->xof) / bufx + 0.5f : 0.0f);
+ fy = (bufy > 0.0f ? ((float)my - 0.5f*ar->winy - snode->yof) / bufy + 0.5f : 0.0f);
+
+ if(fx>=0.0 && fy>=0.0 && fx<1.0 && fy<1.0) {
+ float *fp;
+ char *cp;
+ int x= (int)(fx*ibuf->x), y= (int)(fy*ibuf->y);
+
+ CLAMP(x, 0, ibuf->x-1);
+ CLAMP(y, 0, ibuf->y-1);
+
+ info->x= x;
+ info->y= y;
+ info->draw= 1;
+ info->channels= ibuf->channels;
+
+ if(ibuf->rect) {
+ cp= (char *)(ibuf->rect + y*ibuf->x + x);
+
+ info->col[0]= cp[0];
+ info->col[1]= cp[1];
+ 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;
+ }
+ if(ibuf->rect_float) {
+ fp= (ibuf->rect_float + (ibuf->channels)*(y*ibuf->x + x));
+
+ info->colf[0]= fp[0];
+ info->colf[1]= fp[1];
+ info->colf[2]= fp[2];
+ info->colf[3]= fp[3];
+ }
+ }
+ else
+ info->draw= 0;
+
+ BKE_image_release_ibuf(ima, lock);
+
+ ED_area_tag_redraw(CTX_wm_area(C));
+}
+
+static void sample_exit(bContext *C, wmOperator *op)
+{
+ ImageSampleInfo *info= op->customdata;
+
+ ED_region_draw_cb_exit(info->art, info->draw_handle);
+ ED_area_tag_redraw(CTX_wm_area(C));
+ MEM_freeN(info);
+}
+
+static int sample_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ SpaceNode *snode= CTX_wm_space_node(C);
+ ARegion *ar= CTX_wm_region(C);
+ ImageSampleInfo *info;
+
+ if(snode->treetype!=NTREE_COMPOSIT || !(snode->flag & SNODE_BACKDRAW))
+ return OPERATOR_CANCELLED;
+
+ info= MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo");
+ info->art= ar->type;
+ info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL);
+ op->customdata= info;
+
+ sample_apply(C, op, event);
+
+ WM_event_add_modal_handler(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int sample_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+ switch(event->type) {
+ case LEFTMOUSE:
+ case RIGHTMOUSE: // XXX hardcoded
+ sample_exit(C, op);
+ return OPERATOR_CANCELLED;
+ case MOUSEMOVE:
+ sample_apply(C, op, event);
+ break;
+ }
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int sample_cancel(bContext *C, wmOperator *op)
+{
+ sample_exit(C, op);
+ return OPERATOR_CANCELLED;
+}
+
+void NODE_OT_backimage_sample(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Backimage Sample";
+ ot->idname= "NODE_OT_backimage_sample";
+
+ /* api callbacks */
+ ot->invoke= sample_invoke;
+ ot->modal= sample_modal;
+ ot->cancel= sample_cancel;
+ ot->poll= ED_operator_node_active;
+
+ /* flags */
+ ot->flag= OPTYPE_BLOCKING;
+}
/* ********************** size widget operator ******************** */
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index cfe32846124..66bf9310db8 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -71,6 +71,7 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link);
void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 );
int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol);
void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage);
+void draw_nodespace_color_info(ARegion *ar, int channels, int x, int y, char *cp, float *fp);
void node_buts_group(struct uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
@@ -114,8 +115,10 @@ void NODE_OT_show_cyclic_dependencies(struct wmOperatorType *ot);
void NODE_OT_link_viewer(struct wmOperatorType *ot);
void NODE_OT_read_fullsamplelayers(struct wmOperatorType *ot);
void NODE_OT_read_renderlayers(struct wmOperatorType *ot);
+
void NODE_OT_backimage_move(struct wmOperatorType *ot);
void NODE_OT_backimage_zoom(struct wmOperatorType *ot);
+void NODE_OT_backimage_sample(wmOperatorType *ot);
void NODE_OT_add_file(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c
index 46cd8515f23..aa29f3e3d14 100644
--- a/source/blender/editors/space_node/node_ops.c
+++ b/source/blender/editors/space_node/node_ops.c
@@ -81,6 +81,7 @@ void node_operatortypes(void)
WM_operatortype_append(NODE_OT_backimage_move);
WM_operatortype_append(NODE_OT_backimage_zoom);
+ WM_operatortype_append(NODE_OT_backimage_sample);
WM_operatortype_append(NODE_OT_add_file);
}
@@ -136,7 +137,7 @@ void node_keymap(struct wmKeyConfig *keyconf)
RNA_float_set(kmi->ptr, "factor", 0.83333f);
kmi= WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, KM_ALT, 0);
RNA_float_set(kmi->ptr, "factor", 1.2f);
-
+ WM_keymap_add_item(keymap, "NODE_OT_backimage_sample", ACTIONMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
RNA_boolean_set(WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_CTRL, 0)->ptr, "replace", 1);