~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/sculpt_paint/paint_ops.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "MEM_guardedalloc.h"
26
26
 
27
27
#include <stdlib.h>
 
28
#include "BLI_listbase.h"
28
29
#include "BLI_string.h"
29
30
#include "BLI_utildefines.h"
30
31
 
59
60
static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
60
61
{
61
62
        /*int type = RNA_enum_get(op->ptr, "type");*/
62
 
        Paint *paint = paint_get_active(CTX_data_scene(C));
 
63
        Paint *paint = paint_get_active_from_context(C);
63
64
        struct Brush *br = paint_brush(paint);
 
65
        Main *bmain = CTX_data_main(C);
64
66
 
65
67
        if (br)
66
 
                br = copy_brush(br);
 
68
                br = BKE_brush_copy(br);
67
69
        else
68
 
                br = add_brush("Brush");
 
70
                br = BKE_brush_add(bmain, "Brush");
69
71
 
70
 
        paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
 
72
        paint_brush_set(paint, br);
71
73
 
72
74
        return OPERATOR_FINISHED;
73
75
}
90
92
static int brush_scale_size_exec(bContext *C, wmOperator *op)
91
93
{
92
94
        Scene *scene = CTX_data_scene(C);
93
 
        Paint  *paint =  paint_get_active(scene);
 
95
        Paint  *paint =  paint_get_active_from_context(C);
94
96
        struct Brush  *brush =  paint_brush(paint);
95
 
        // Object *ob=     CTX_data_active_object(C);
 
97
        // Object *ob = CTX_data_active_object(C);
96
98
        float scalar = RNA_float_get(op->ptr, "scalar");
97
99
 
98
100
        if (brush) {
99
101
                // pixel radius
100
102
                {
101
 
                        const int old_size = brush_size(scene, brush);
 
103
                        const int old_size = BKE_brush_size_get(scene, brush);
102
104
                        int size = (int)(scalar * old_size);
103
105
 
104
106
                        if (old_size == size) {
111
113
                        }
112
114
                        CLAMP(size, 1, 2000); // XXX magic number
113
115
 
114
 
                        brush_set_size(scene, brush, size);
 
116
                        BKE_brush_size_set(scene, brush, size);
115
117
                }
116
118
 
117
119
                // unprojected radius
118
120
                {
119
 
                        float unprojected_radius = scalar * brush_unprojected_radius(scene, brush);
 
121
                        float unprojected_radius = scalar * BKE_brush_unprojected_radius_get(scene, brush);
120
122
 
121
123
                        if (unprojected_radius < 0.001f) // XXX magic number
122
124
                                unprojected_radius = 0.001f;
123
125
 
124
 
                        brush_set_unprojected_radius(scene, brush, unprojected_radius);
 
126
                        BKE_brush_unprojected_radius_set(scene, brush, unprojected_radius);
125
127
                }
126
128
        }
127
129
 
160
162
        /* identifiers */
161
163
        ot->name = "Set Vertex Colors";
162
164
        ot->idname = "PAINT_OT_vertex_color_set";
 
165
        ot->description = "Fill the active vertex color layer with the current paint color";
163
166
        
164
167
        /* api callbacks */
165
168
        ot->exec = vertex_color_set_exec;
171
174
 
172
175
static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
173
176
{
174
 
        Paint *paint = paint_get_active(CTX_data_scene(C));
 
177
        Paint *paint = paint_get_active_from_context(C);
175
178
        struct Brush *brush = paint_brush(paint);
176
179
        Object *ob = CTX_data_active_object(C);
177
180
 
178
181
        if (!ob) return OPERATOR_CANCELLED;
179
182
 
180
183
        if (ob->mode & OB_MODE_SCULPT)
181
 
                brush_reset_sculpt(brush);
 
184
                BKE_brush_sculpt_reset(brush);
182
185
        /* TODO: other modes */
183
186
 
184
187
        return OPERATOR_FINISHED;
203
206
        return *(((char *)brush) + tool_offset);
204
207
}
205
208
 
 
209
static void brush_tool_set(const Brush *brush, size_t tool_offset, int tool)
 
210
{
 
211
        *(((char *)brush) + tool_offset) = tool;
 
212
}
 
213
 
206
214
/* generic functions for setting the active brush based on the tool */
207
215
static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
208
216
{
218
226
             brush = brush->id.next ? brush->id.next : bmain->brush.first)
219
227
        {
220
228
                if ((brush->ob_mode & ob_mode) &&
221
 
                    (brush_tool(brush, tool_offset) == tool)) {
 
229
                    (brush_tool(brush, tool_offset) == tool))
 
230
                {
222
231
                        return brush;
223
232
                }
224
233
        }
226
235
        return NULL;
227
236
}
228
237
 
229
 
static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
 
238
static Brush *brush_tool_toggle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
 
239
{
 
240
        if (!brush_orig || brush_tool(brush_orig, tool_offset) != tool) {
 
241
                Brush *br;
 
242
                /* if the current brush is not using the desired tool, look
 
243
                 * for one that is */
 
244
                br = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
 
245
                /* store the previously-selected brush */
 
246
                if (br)
 
247
                        br->toggle_brush = brush_orig;
 
248
                
 
249
                return br;
 
250
        }
 
251
        else if (brush_orig->toggle_brush &&
 
252
                 BLI_findindex(bmain->brush.first, brush_orig->toggle_brush) != -1)
 
253
        {
 
254
                /* if current brush is using the desired tool, try to toggle
 
255
                 * back to the previously selected brush (if it was set, and
 
256
                 * if it still exists) */
 
257
                return brush_orig->toggle_brush;
 
258
        }
 
259
        else
 
260
                return NULL;
 
261
}
 
262
 
 
263
static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool,
 
264
                                  const size_t tool_offset, const int ob_mode,
 
265
                                  const char *tool_name, int create_missing,
 
266
                                  int toggle)
230
267
{
231
268
        struct Brush *brush, *brush_orig = paint_brush(paint);
232
269
 
233
 
        brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
 
270
        if (toggle)
 
271
                brush = brush_tool_toggle(bmain, brush_orig, tool, tool_offset, ob_mode);
 
272
        else
 
273
                brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
 
274
 
 
275
        if (!brush && brush_tool(brush_orig, tool_offset) != tool && create_missing) {
 
276
                brush = BKE_brush_add(bmain, tool_name);
 
277
                brush_tool_set(brush, tool_offset, tool);
 
278
                brush->ob_mode = ob_mode;
 
279
                brush->toggle_brush = brush_orig;
 
280
        }
234
281
 
235
282
        if (brush) {
236
283
                paint_brush_set(paint, brush);
251
298
        ToolSettings *toolsettings = CTX_data_tool_settings(C);
252
299
        Paint *paint = NULL;
253
300
        int tool, paint_mode = RNA_enum_get(op->ptr, "paint_mode");
 
301
        int create_missing = RNA_boolean_get(op->ptr, "create_missing");
 
302
        int toggle = RNA_boolean_get(op->ptr, "toggle");
 
303
        const char *tool_name = "Brush";
254
304
        size_t tool_offset;
255
305
 
256
306
        if (paint_mode == OB_MODE_ACTIVE) {
273
323
                        paint = &toolsettings->sculpt->paint;
274
324
                        tool_offset = offsetof(Brush, sculpt_tool);
275
325
                        tool = RNA_enum_get(op->ptr, "sculpt_tool");
 
326
                        RNA_enum_name_from_value(brush_sculpt_tool_items, tool, &tool_name);
276
327
                        break;
277
328
                case OB_MODE_VERTEX_PAINT:
278
329
                        paint = &toolsettings->vpaint->paint;
279
330
                        tool_offset = offsetof(Brush, vertexpaint_tool);
280
331
                        tool = RNA_enum_get(op->ptr, "vertex_paint_tool");
 
332
                        RNA_enum_name_from_value(brush_vertex_tool_items, tool, &tool_name);
281
333
                        break;
282
334
                case OB_MODE_WEIGHT_PAINT:
283
335
                        paint = &toolsettings->wpaint->paint;
284
336
                        /* vertexpaint_tool is used for weight paint mode */
285
337
                        tool_offset = offsetof(Brush, vertexpaint_tool);
286
338
                        tool = RNA_enum_get(op->ptr, "weight_paint_tool");
 
339
                        RNA_enum_name_from_value(brush_vertex_tool_items, tool, &tool_name);
287
340
                        break;
288
341
                case OB_MODE_TEXTURE_PAINT:
289
342
                        paint = &toolsettings->imapaint.paint;
290
343
                        tool_offset = offsetof(Brush, imagepaint_tool);
291
344
                        tool = RNA_enum_get(op->ptr, "texture_paint_tool");
 
345
                        RNA_enum_name_from_value(brush_image_tool_items, tool, &tool_name);
292
346
                        break;
293
347
                default:
294
348
                        /* invalid paint mode */
295
349
                        return OPERATOR_CANCELLED;
296
350
        }
297
351
 
298
 
        return brush_generic_tool_set(bmain, paint, tool, tool_offset, paint_mode);
 
352
        return brush_generic_tool_set(bmain, paint, tool, tool_offset,
 
353
                                      paint_mode, tool_name, create_missing,
 
354
                                      toggle);
299
355
}
300
356
 
301
357
static void PAINT_OT_brush_select(wmOperatorType *ot)
326
382
        RNA_def_enum(ot->srna, "vertex_paint_tool", brush_vertex_tool_items, 0, "Vertex Paint Tool", "");
327
383
        RNA_def_enum(ot->srna, "weight_paint_tool", brush_vertex_tool_items, 0, "Weight Paint Tool", "");
328
384
        RNA_def_enum(ot->srna, "texture_paint_tool", brush_image_tool_items, 0, "Texture Paint Tool", "");
 
385
 
 
386
        RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle between two brushes rather than cycling");
 
387
        RNA_def_boolean(ot->srna, "create_missing", 0, "Create Missing", "If the requested brush type does not exist, create a new brush");
329
388
}
330
389
 
331
390
static wmKeyMapItem *keymap_brush_select(wmKeyMap *keymap, int paint_mode,
417
476
        WM_operatortype_append(PAINT_OT_weight_paint);
418
477
        WM_operatortype_append(PAINT_OT_weight_set);
419
478
        WM_operatortype_append(PAINT_OT_weight_from_bones);
 
479
        WM_operatortype_append(PAINT_OT_weight_gradient);
420
480
        WM_operatortype_append(PAINT_OT_weight_sample);
421
481
        WM_operatortype_append(PAINT_OT_weight_sample_group);
422
482
 
425
485
 
426
486
        /* vertex selection */
427
487
        WM_operatortype_append(PAINT_OT_vert_select_all);
428
 
        WM_operatortype_append(PAINT_OT_vert_select_inverse);
429
488
 
430
489
        /* vertex */
431
490
        WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
436
495
        WM_operatortype_append(PAINT_OT_face_select_linked);
437
496
        WM_operatortype_append(PAINT_OT_face_select_linked_pick);
438
497
        WM_operatortype_append(PAINT_OT_face_select_all);
439
 
        WM_operatortype_append(PAINT_OT_face_select_inverse);
440
498
        WM_operatortype_append(PAINT_OT_face_select_hide);
441
499
        WM_operatortype_append(PAINT_OT_face_select_reveal);
442
500
 
443
501
        /* partial visibility */
444
502
        WM_operatortype_append(PAINT_OT_hide_show);
 
503
 
 
504
        /* paint masking */
 
505
        WM_operatortype_append(PAINT_OT_mask_flood_fill);
445
506
}
446
507
 
447
508
 
523
584
                                                 RCFlags flags)
524
585
{
525
586
        wmKeyMapItem *kmi;
 
587
        /* only size needs to follow zoom, strength shows fixed size circle */
 
588
        int flags_nozoom = flags & (~RC_ZOOM);
526
589
 
527
590
        kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
528
591
        set_brush_rc_props(kmi->ptr, paint, "size", "use_unified_size", flags);
529
592
 
530
593
        kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
531
 
        set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags);
 
594
        set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags_nozoom);
 
595
 
 
596
        kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", WKEY, KM_PRESS, 0, 0);
 
597
        set_brush_rc_props(kmi->ptr, paint, "weight", "use_unified_weight", flags_nozoom);
532
598
 
533
599
        if (flags & RC_ROTATION) {
534
600
                kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0);
535
 
                set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags);
 
601
                set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags_nozoom);
536
602
        }
537
603
}
538
604
 
539
 
void paint_partial_visibility_keys(wmKeyMap *keymap)
 
605
static void paint_partial_visibility_keys(wmKeyMap *keymap)
540
606
{
541
607
        wmKeyMapItem *kmi;
542
608
        
543
 
        /* Partial visiblity */
 
609
        /* Partial visibility */
544
610
        kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, KM_SHIFT, 0);
545
611
        RNA_enum_set(kmi->ptr, "action", PARTIALVIS_SHOW);
546
612
        RNA_enum_set(kmi->ptr, "area", PARTIALVIS_INSIDE);
560
626
        
561
627
        /* Sculpt mode */
562
628
        keymap = WM_keymap_find(keyconf, "Sculpt", 0, 0);
563
 
        keymap->poll = sculpt_poll;
 
629
        keymap->poll = sculpt_mode_poll;
564
630
 
565
631
        RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
566
632
        RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
572
638
        for (i = 0; i <= 5; i++)
573
639
                RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY + i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
574
640
 
 
641
        /* Clear mask */
 
642
        kmi = WM_keymap_add_item(keymap, "PAINT_OT_mask_flood_fill", MKEY, KM_PRESS, KM_ALT, 0);
 
643
        RNA_enum_set(kmi->ptr, "mode", PAINT_MASK_FLOOD_VALUE);
 
644
        RNA_float_set(kmi->ptr, "value", 0);
 
645
 
 
646
        /* Invert mask */
 
647
        kmi = WM_keymap_add_item(keymap, "PAINT_OT_mask_flood_fill", IKEY, KM_PRESS, KM_CTRL, 0);
 
648
        RNA_enum_set(kmi->ptr, "mode", PAINT_MASK_INVERT);
 
649
 
 
650
        /* Toggle dynamic topology */
 
651
        WM_keymap_add_item(keymap, "SCULPT_OT_dynamic_topology_toggle", DKEY, KM_PRESS, KM_CTRL, 0);
 
652
 
 
653
        /* Dynamic-topology detail size
 
654
         * 
 
655
         * This should be improved further, perhaps by showing a triangle
 
656
         * grid rather than brush alpha */
 
657
        kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", DKEY, KM_PRESS, KM_SHIFT, 0);
 
658
        set_brush_rc_props(kmi->ptr, "sculpt", "detail_size", NULL, 0);
 
659
        RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.sculpt.detail_size");
 
660
 
575
661
        /* multires switch */
576
662
        kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
577
663
        RNA_int_set(kmi->ptr, "level", 1);
594
680
        keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_FLATTEN, TKEY, KM_SHIFT);
595
681
        keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CLAY, CKEY, 0);
596
682
        keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CREASE, CKEY, KM_SHIFT);
 
683
        keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_SNAKE_HOOK, KKEY, 0);
 
684
        kmi = keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_MASK, MKEY, 0);
 
685
        RNA_boolean_set(kmi->ptr, "toggle", 1);
 
686
        RNA_boolean_set(kmi->ptr, "create_missing", 1);
597
687
 
598
688
        /* */
599
689
        kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
629
719
        WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
630
720
 
631
721
        /* these keys are from 2.4x but could be changed */
632
 
        WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
633
 
        WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
 
722
        WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0);
 
723
        WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
 
724
 
 
725
        RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_gradient", LEFTMOUSE, KM_PRESS, KM_ALT, 0)->ptr,           "type", WPAINT_GRADIENT_TYPE_LINEAR);
 
726
        RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_gradient", LEFTMOUSE, KM_PRESS, KM_ALT | KM_CTRL, 0)->ptr, "type", WPAINT_GRADIENT_TYPE_RADIAL);
634
727
 
635
728
        WM_keymap_add_item(keymap,
636
729
                           "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
653
746
        keymap = WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0);
654
747
        keymap->poll = vert_paint_poll;
655
748
        WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
656
 
        WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
 
749
        kmi = WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
 
750
        RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
657
751
        WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
658
752
        kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
659
753
        RNA_boolean_set(kmi->ptr, "deselect", FALSE);
682
776
        keymap->poll = facemask_paint_poll;
683
777
 
684
778
        WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
685
 
        WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
 
779
        kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
 
780
        RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
686
781
        kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
687
782
        RNA_boolean_set(kmi->ptr, "unselected", FALSE);
688
783
        kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
709
804
        RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", PKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_PINCH);
710
805
        RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", GKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_GRAB);
711
806
 
 
807
        /* paint stroke */
 
808
        keymap = paint_stroke_modal_keymap(keyconf);
 
809
        WM_modalkeymap_assign(keymap, "SCULPT_OT_brush_stroke");
712
810
}