[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58368] branches/soc-2013-paint/source/ blender: User request: Add colours to palette when sampling with S and pressing
Antony Riakiotakis
kalast at gmail.com
Thu Jul 18 14:28:52 CEST 2013
Revision: 58368
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58368
Author: psy-fi
Date: 2013-07-18 12:28:51 +0000 (Thu, 18 Jul 2013)
Log Message:
-----------
User request: Add colours to palette when sampling with S and pressing
Left Click.
Also don't give a default palette to paint systems, it's not really
necessary and it can pollute the UI.
Modified Paths:
--------------
branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c
Modified: branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c 2013-07-18 11:44:34 UTC (rev 58367)
+++ branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c 2013-07-18 12:28:51 UTC (rev 58368)
@@ -331,22 +331,13 @@
void BKE_paint_init(Paint *p, const char col[3])
{
Brush *brush;
- Palette *palette;
/* If there's no brush, create one */
brush = BKE_paint_brush(p);
- palette = BKE_paint_palette(p);
if (brush == NULL)
brush = BKE_brush_add(G.main, "Brush");
- if (palette == NULL) {
- if (G.main->palettes.first)
- palette = (Palette *) G.main->palettes.first;
- else
- palette = BKE_palette_add(G.main, "Palette");
- }
BKE_paint_brush_set(p, brush);
- BKE_paint_palette_set(p, palette);
memcpy(p->paint_cursor_col, col, 3);
p->paint_cursor_col[3] = 128;
Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c 2013-07-18 11:44:34 UTC (rev 58367)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c 2013-07-18 12:28:51 UTC (rev 58368)
@@ -1036,8 +1036,10 @@
PaintMode mode = BKE_paintmode_get_active_from_context(C);
ARegion *ar = CTX_wm_region(C);
int location[2];
+ bool use_palette;
RNA_int_get_array(op->ptr, "location", location);
- paint_sample_color(C, ar, location[0], location[1], mode == PAINT_TEXTURE_PROJECTIVE);
+ use_palette = RNA_boolean_get(op->ptr, "palette");
+ paint_sample_color(C, ar, location[0], location[1], mode == PAINT_TEXTURE_PROJECTIVE, use_palette);
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
@@ -1080,6 +1082,14 @@
RNA_int_set_array(op->ptr, "location", event->mval);
sample_color_exec(C, op);
break;
+
+ case LEFTMOUSE:
+ if (event->val == KM_PRESS) {
+ RNA_boolean_set(op->ptr, "palette", true);
+ sample_color_exec(C, op);
+ RNA_boolean_set(op->ptr, "palette", false);
+ }
+ break;
}
return OPERATOR_RUNNING_MODAL;
@@ -1108,6 +1118,7 @@
/* properties */
RNA_def_int_vector(ot->srna, "location", 2, NULL, 0, INT_MAX, "Location", "Cursor location in region coordinates", 0, 16384);
+ RNA_def_boolean(ot->srna, "palette", 0, "Palette", "Add color to palette");
}
/******************** texture paint toggle operator ********************/
Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h 2013-07-18 11:44:34 UTC (rev 58367)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h 2013-07-18 12:28:51 UTC (rev 58368)
@@ -208,7 +208,7 @@
void imapaint_pick_uv(struct Scene *scene, struct Object *ob, unsigned int faceindex, const int xy[2], float uv[2]);
void brush_drawcursor_texpaint_uvsculpt(struct bContext *C, int x, int y, void *customdata);
-void paint_sample_color(bContext *C, struct ARegion *ar, int x, int y, bool texpaint_proj);
+void paint_sample_color(bContext *C, struct ARegion *ar, int x, int y, bool texpaint_proj, bool palette);
void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
void PAINT_OT_face_select_linked(struct wmOperatorType *ot);
Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c 2013-07-18 11:44:34 UTC (rev 58367)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c 2013-07-18 12:28:51 UTC (rev 58368)
@@ -369,15 +369,22 @@
}
/* used for both 3d view and image window */
-void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_proj) /* frontbuf */
+void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_proj, bool use_palette) /* frontbuf */
{
+ Paint *paint = BKE_paint_get_active_from_context(C);
+ Palette *palette = BKE_paint_palette(paint);
Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C));
unsigned int col;
- char *cp;
+ unsigned char *cp;
CLAMP(x, 0, ar->winx);
CLAMP(y, 0, ar->winy);
+ if (use_palette && !palette) {
+ palette = BKE_palette_add(CTX_data_main(C), "Palette");
+ BKE_paint_palette_set(paint, palette);
+ }
+
if (CTX_wm_view3d(C) && texpaint_proj) {
/* first try getting a colour directly from the mesh faces if possible */
Scene *scene = CTX_data_scene(C);
@@ -421,15 +428,22 @@
float rgba_fp[4];
bilinear_interpolation_color_wrap(ibuf, NULL, rgba_fp, u, v);
straight_to_premul_v4(rgba_fp);
- linearrgb_to_srgb_v3_v3(rgba_fp, rgba_fp);
- copy_v3_v3(br->rgb, rgba_fp);
+ if (use_palette) {
+ PaletteColor *color = BKE_palette_color_add(palette);
+ linearrgb_to_srgb_v3_v3(color->rgb, rgba_fp);
+ } else if (br) {
+ linearrgb_to_srgb_v3_v3(br->rgb, rgba_fp);
+ }
}
else {
unsigned char rgba[4];
- float rgba_fp[4];
bilinear_interpolation_color_wrap(ibuf, rgba, NULL, u, v);
- rgba_uchar_to_float(rgba_fp, rgba);
- copy_v3_v3(br->rgb, rgba_fp);
+ if (use_palette) {
+ PaletteColor *color = BKE_palette_color_add(palette);
+ rgba_uchar_to_float(color->rgb, rgba);
+ } else if (br) {
+ rgba_uchar_to_float(br->rgb, rgba);
+ }
}
}
@@ -450,12 +464,13 @@
glReadPixels(x + ar->winrct.xmin, y + ar->winrct.ymin, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
glReadBuffer(GL_BACK);
}
- cp = (char *)&col;
+ cp = (unsigned char *)&col;
- if (br) {
- br->rgb[0] = cp[0] / 255.0f;
- br->rgb[1] = cp[1] / 255.0f;
- br->rgb[2] = cp[2] / 255.0f;
+ if (use_palette && palette) {
+ PaletteColor *color = BKE_palette_color_add(palette);
+ rgba_uchar_to_float(color->rgb, cp);
+ } else if (br) {
+ rgba_uchar_to_float(br->rgb, cp);
}
}
More information about the Bf-blender-cvs
mailing list