Paint refactoring commit, non-disruptive (in theory :p)
[blender.git] / source / blender / editors / sculpt_paint / paint_cursor.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software  Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2009 by Nicholas Bishop
19  * All rights reserved.
20  *
21  * Contributor(s): Jason Wilkins, Tom Musgrove.
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  *
25  */
26
27 /** \file blender/editors/sculpt_paint/paint_cursor.c
28  *  \ingroup edsculpt
29  */
30
31 #include "MEM_guardedalloc.h"
32
33 #include "BLI_math.h"
34 #include "BLI_rect.h"
35 #include "BLI_utildefines.h"
36
37 #include "DNA_brush_types.h"
38 #include "DNA_color_types.h"
39 #include "DNA_object_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_screen_types.h"
42 #include "DNA_userdef_types.h"
43
44 #include "BKE_brush.h"
45 #include "BKE_context.h"
46 #include "BKE_image.h"
47 #include "BKE_paint.h"
48
49 #include "WM_api.h"
50
51 #include "BIF_gl.h"
52 #include "BIF_glutil.h"
53
54 #include "ED_view3d.h"
55
56 #include "paint_intern.h"
57 /* still needed for sculpt_stroke_get_location, should be
58  * removed eventually (TODO) */
59 #include "sculpt_intern.h"
60
61 /* TODOs:
62  *
63  * Some of the cursor drawing code is doing non-draw stuff
64  * (e.g. updating the brush rake angle). This should be cleaned up
65  * still.
66  *
67  * There is also some ugliness with sculpt-specific code.
68  */
69
70 typedef struct TexSnapshot {
71         int winx;
72         int winy;
73         bool init;
74 } TexSnapshot;
75
76 typedef struct CurveSnapshot {
77         int BKE_brush_size_get;
78         int curve_changed_timestamp;
79         bool init;
80 } CurveSnapshot;
81
82 static int same_tex_snap(TexSnapshot *snap, Brush *brush, ViewContext *vc)
83 {
84         MTex *mtex = &brush->mtex;
85
86         return (/* make brush smaller shouldn't cause a resample */
87                 //(mtex->brush_map_mode != MTEX_MAP_MODE_VIEW ||
88                 //(BKE_brush_size_get(vc->scene, brush) <= snap->BKE_brush_size_get)) &&
89
90                         (mtex->brush_map_mode != MTEX_MAP_MODE_TILED ||
91                 (vc->ar->winx == snap->winx &&
92                 vc->ar->winy == snap->winy))
93                 );
94 }
95
96 static void make_tex_snap(TexSnapshot *snap, ViewContext *vc)
97 {
98         snap->winx = vc->ar->winx;
99         snap->winy = vc->ar->winy;
100 }
101
102 static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col)
103 {
104         static GLuint overlay_texture = 0;
105         static int init = 0;
106         static TexSnapshot snap;
107         static int old_size = -1;
108         static int old_zoom = -1;
109         static bool old_col = -1;
110
111         int invalid = BKE_paint_get_overlay_flags();
112         GLubyte *buffer = NULL;
113
114         int size;
115         int j;
116         int refresh;
117         GLenum format = col ? GL_RGBA : GL_ALPHA;
118         
119         if (br->mtex.brush_map_mode != MTEX_MAP_MODE_VIEW && !br->mtex.tex) return 0;
120         
121         refresh = 
122             !overlay_texture ||
123             (br->mtex.tex &&
124              (invalid & PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY)) ||
125             (br->curve &&
126             (invalid & PAINT_INVALID_OVERLAY_CURVE)) ||
127             old_zoom != zoom ||
128             old_col != col ||
129             !same_tex_snap(&snap, br, vc);
130
131         if (refresh) {
132                 struct ImagePool *pool = NULL;
133                 /* stencil is rotated later */
134                 const float rotation = (br->mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) ?
135                                        -br->mtex.rot : 0;
136
137                 float radius = BKE_brush_size_get(vc->scene, br) * zoom;
138
139                 old_zoom = zoom;
140                 make_tex_snap(&snap, vc);
141
142                 if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) {
143                         int s = BKE_brush_size_get(vc->scene, br);
144                         int r = 1;
145
146                         for (s >>= 1; s > 0; s >>= 1)
147                                 r++;
148
149                         size = (1 << r);
150
151                         if (size < 256)
152                                 size = 256;
153
154                         if (size < old_size)
155                                 size = old_size;
156                 }
157                 else
158                         size = 512;
159
160                 if (old_size != size) {
161                         if (overlay_texture) {
162                                 glDeleteTextures(1, &overlay_texture);
163                                 overlay_texture = 0;
164                         }
165
166                         init = 0;
167
168                         old_size = size;
169                 }
170                 if (col)
171                         buffer = MEM_mallocN(sizeof(GLubyte) * size * size * 4, "load_tex");
172                 else
173                         buffer = MEM_mallocN(sizeof(GLubyte) * size * size, "load_tex");
174
175                 if (br->mtex.tex)
176                         pool = BKE_image_pool_new();
177
178                 #pragma omp parallel for schedule(static)
179                 for (j = 0; j < size; j++) {
180                         int i;
181                         float y;
182                         float len;
183
184                         for (i = 0; i < size; i++) {
185
186                                 // largely duplicated from tex_strength
187
188                                 int index = j * size + i;
189                                 float x;
190
191                                 x = (float)i / size;
192                                 y = (float)j / size;
193
194                                 if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) {
195                                         x *= vc->ar->winx / radius;
196                                         y *= vc->ar->winy / radius;
197                                 }
198                                 else {
199                                         x -= 0.5f;
200                                         y -= 0.5f;
201
202                                         x *= 2;
203                                         y *= 2;
204                                 }
205
206                                 len = sqrtf(x * x + y * y);
207
208                                 if (ELEM(br->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL) || len <= 1) {
209                                         /* it is probably worth optimizing for those cases where 
210                                          * the texture is not rotated by skipping the calls to
211                                          * atan2, sqrtf, sin, and cos. */
212                                         if (br->mtex.tex && (rotation > 0.001f || rotation < -0.001f)) {
213                                                 const float angle    = atan2f(y, x) + rotation;
214
215                                                 x = len * cosf(angle);
216                                                 y = len * sinf(angle);
217                                         }
218
219                                         x *= br->mtex.size[0];
220                                         y *= br->mtex.size[1];
221
222                                         x += br->mtex.ofs[0];
223                                         y += br->mtex.ofs[1];
224
225                                         if (col) {
226                                                 float rgba[4];
227
228                                                 if (br->mtex.tex)
229                                                         paint_get_tex_pixel_col(&br->mtex, x, y, rgba, pool);
230
231                                                 if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) {
232                                                         float curve_str = BKE_brush_curve_strength(br, len, 1);
233                                                         CLAMP(curve_str, 0.0, 1.0);
234                                                         mul_v4_fl(rgba, curve_str);  /* Falloff curve */
235                                                 }
236                                                 buffer[index * 4]     = rgba[0] * 255;
237                                                 buffer[index * 4 + 1] = rgba[1] * 255;
238                                                 buffer[index * 4 + 2] = rgba[2] * 255;
239                                                 buffer[index * 4 + 3] = rgba[3] * 255;
240                                         }
241                                         else {
242                                                 float avg = br->mtex.tex ? paint_get_tex_pixel(&br->mtex, x, y, pool) : 1;
243
244                                                 avg += br->texture_sample_bias;
245
246                                                 if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW)
247                                                         avg *= BKE_brush_curve_strength(br, len, 1);  /* Falloff curve */
248
249                                                 /* clamp to avoid precision overflow */
250                                                 CLAMP(avg, 0.0, 1.0);
251                                                 buffer[index] = 255 - (GLubyte)(255 * avg);
252                                         }
253                                 }
254                                 else {
255                                         if (col) {
256                                                 buffer[index * 4]     = 0;
257                                                 buffer[index * 4 + 1] = 0;
258                                                 buffer[index * 4 + 2] = 0;
259                                                 buffer[index * 4 + 3] = 0;
260                                         }
261                                         else {
262                                                 buffer[index] = 0;
263                                         }
264                                 }
265                         }
266                 }
267
268                 if (pool)
269                         BKE_image_pool_free(pool);
270
271                 if (!overlay_texture)
272                         glGenTextures(1, &overlay_texture);
273         }
274         else {
275                 size = old_size;
276         }
277
278         glBindTexture(GL_TEXTURE_2D, overlay_texture);
279
280         if (refresh) {
281                 if (!init || (old_col != col)) {
282                         glTexImage2D(GL_TEXTURE_2D, 0, format, size, size, 0, format, GL_UNSIGNED_BYTE, buffer);
283                         init = 1;
284                 }
285                 else {
286                         glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, format, GL_UNSIGNED_BYTE, buffer);
287                 }
288
289                 if (buffer)
290                         MEM_freeN(buffer);
291
292                 old_col = col;
293         }
294
295         glEnable(GL_TEXTURE_2D);
296
297         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
298         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
299         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
300
301         if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) {
302                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
303                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
304         }
305
306         BKE_paint_reset_overlay_invalid();
307
308         return 1;
309 }
310
311 static int project_brush_radius(ViewContext *vc,
312                                 float radius,
313                                 const float location[3])
314 {
315         float view[3], nonortho[3], ortho[3], offset[3], p1[2], p2[2];
316
317         ED_view3d_global_to_vector(vc->rv3d, location, view);
318
319         /* create a vector that is not orthogonal to view */
320
321         if (fabsf(view[0]) < 0.1f) {
322                 nonortho[0] = view[0] + 1.0f;
323                 nonortho[1] = view[1];
324                 nonortho[2] = view[2];
325         }
326         else if (fabsf(view[1]) < 0.1f) {
327                 nonortho[0] = view[0];
328                 nonortho[1] = view[1] + 1.0f;
329                 nonortho[2] = view[2];
330         }
331         else {
332                 nonortho[0] = view[0];
333                 nonortho[1] = view[1];
334                 nonortho[2] = view[2] + 1.0f;
335         }
336
337         /* get a vector in the plane of the view */
338         cross_v3_v3v3(ortho, nonortho, view);
339         normalize_v3(ortho);
340
341         /* make a point on the surface of the brush tagent to the view */
342         mul_v3_fl(ortho, radius);
343         add_v3_v3v3(offset, location, ortho);
344
345         /* project the center of the brush, and the tangent point to the view onto the screen */
346         if ((ED_view3d_project_float_global(vc->ar, location, p1, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
347             (ED_view3d_project_float_global(vc->ar, offset,   p2, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
348         {
349                 /* the distance between these points is the size of the projected brush in pixels */
350                 return len_v2v2(p1, p2);
351         }
352         else {
353                 BLI_assert(0);  /* assert because the code that sets up the vectors should disallow this */
354                 return 0;
355         }
356 }
357
358 static int sculpt_get_brush_geometry(bContext *C, ViewContext *vc,
359                                      int x, int y, int *pixel_radius,
360                                      float location[3])
361 {
362         Scene *scene = CTX_data_scene(C);
363         Paint *paint = BKE_paint_get_active_from_context(C);
364         float mouse[2];
365         int hit;
366
367         mouse[0] = x;
368         mouse[1] = y;
369
370         if (vc->obact->sculpt && vc->obact->sculpt->pbvh &&
371             sculpt_stroke_get_location(C, location, mouse))
372         {
373                 Brush *brush = BKE_paint_brush(paint);
374                 *pixel_radius =
375                     project_brush_radius(vc,
376                                          BKE_brush_unprojected_radius_get(scene, brush),
377                                          location);
378
379                 if (*pixel_radius == 0)
380                         *pixel_radius = BKE_brush_size_get(scene, brush);
381
382                 mul_m4_v3(vc->obact->obmat, location);
383
384                 hit = 1;
385         }
386         else {
387                 Sculpt *sd    = CTX_data_tool_settings(C)->sculpt;
388                 Brush *brush = BKE_paint_brush(&sd->paint);
389
390                 *pixel_radius = BKE_brush_size_get(scene, brush);
391                 hit = 0;
392         }
393
394         return hit;
395 }
396
397 /* Draw an overlay that shows what effect the brush's texture will
398  * have on brush strength */
399 /* TODO: sculpt only for now */
400 static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush,
401                                      ViewContext *vc, int x, int y, float zoom, PaintMode mode)
402 {
403         rctf quad;
404         bool col;
405         /* check for overlay mode */
406
407         if (!((brush->mtex.brush_map_mode == MTEX_MAP_MODE_STENCIL && brush->mtex.tex) ||
408             ((brush->flag & BRUSH_TEXTURE_OVERLAY) &&
409             ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_VIEW, MTEX_MAP_MODE_TILED))))
410         {
411                 return;
412         }
413
414         col = ELEM3(mode, PAINT_TEXTURE_PROJECTIVE, PAINT_TEXTURE_2D, PAINT_VERTEX) ? true: false;
415         /* save lots of GL state
416          * TODO: check on whether all of these are needed? */
417         glPushAttrib(GL_COLOR_BUFFER_BIT |
418                      GL_CURRENT_BIT |
419                      GL_DEPTH_BUFFER_BIT |
420                      GL_ENABLE_BIT |
421                      GL_LINE_BIT |
422                      GL_POLYGON_BIT |
423                      GL_STENCIL_BUFFER_BIT |
424                      GL_TRANSFORM_BIT |
425                      GL_VIEWPORT_BIT |
426                      GL_TEXTURE_BIT);
427
428         if (load_tex(brush, vc, zoom, col)) {
429                 glEnable(GL_BLEND);
430
431                 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
432                 glDepthMask(GL_FALSE);
433                 glDepthFunc(GL_ALWAYS);
434
435                 glMatrixMode(GL_TEXTURE);
436                 glPushMatrix();
437                 glLoadIdentity();
438
439                 if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) {
440                         /* brush rotation */
441                         glTranslatef(0.5, 0.5, 0);
442                         glRotatef((double)RAD2DEGF(ups->brush_rotation),
443                                   0.0, 0.0, 1.0);
444                         glTranslatef(-0.5f, -0.5f, 0);
445
446                         /* scale based on tablet pressure */
447                         if (ups->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush)) {
448                                 glTranslatef(0.5f, 0.5f, 0);
449                                 glScalef(1.0f / ups->pressure_value, 1.0f / ups->pressure_value, 1);
450                                 glTranslatef(-0.5f, -0.5f, 0);
451                         }
452
453                         if (ups->draw_anchored) {
454                                 const float *aim = ups->anchored_initial_mouse;
455                                 quad.xmin = aim[0] - ups->anchored_size;
456                                 quad.ymin = aim[1] - ups->anchored_size;
457                                 quad.xmax = aim[0] + ups->anchored_size;
458                                 quad.ymax = aim[1] + ups->anchored_size;
459                         }
460                         else {
461                                 const int radius = BKE_brush_size_get(vc->scene, brush) * zoom;
462                                 quad.xmin = x - radius;
463                                 quad.ymin = y - radius;
464                                 quad.xmax = x + radius;
465                                 quad.ymax = y + radius;
466                         }
467                 }
468                 else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) {
469                         quad.xmin = 0;
470                         quad.ymin = 0;
471                         quad.xmax = BLI_rcti_size_x(&vc->ar->winrct);
472                         quad.ymax = BLI_rcti_size_y(&vc->ar->winrct);
473                 }
474                 else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_STENCIL) {
475                         quad.xmin = -brush->stencil_dimension[0];
476                         quad.ymin = -brush->stencil_dimension[1];
477                         quad.xmax = brush->stencil_dimension[0];
478                         quad.ymax = brush->stencil_dimension[1];
479
480                         glMatrixMode(GL_MODELVIEW);
481                         glPushMatrix();
482                         glTranslatef(brush->stencil_pos[0], brush->stencil_pos[1], 0);
483                         glRotatef(RAD2DEGF(brush->mtex.rot), 0, 0, 1);
484                         glMatrixMode(GL_TEXTURE);
485                 }
486
487                 /* set quad color. Colored overlay does not get blending */
488                 if (col)
489                         glColor4f(1.0,
490                                       1.0,
491                                       1.0,
492                                       brush->texture_overlay_alpha / 100.0f);
493                 else
494                         glColor4f(U.sculpt_paint_overlay_col[0],
495                                       U.sculpt_paint_overlay_col[1],
496                                       U.sculpt_paint_overlay_col[2],
497                                       brush->texture_overlay_alpha / 100.0f);
498
499                 /* draw textured quad */
500                 glBegin(GL_QUADS);
501                 glTexCoord2f(0, 0);
502                 glVertex2f(quad.xmin, quad.ymin);
503                 glTexCoord2f(1, 0);
504                 glVertex2f(quad.xmax, quad.ymin);
505                 glTexCoord2f(1, 1);
506                 glVertex2f(quad.xmax, quad.ymax);
507                 glTexCoord2f(0, 1);
508                 glVertex2f(quad.xmin, quad.ymax);
509                 glEnd();
510
511                 glPopMatrix();
512
513                 if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_STENCIL) {
514                         glMatrixMode(GL_MODELVIEW);
515                         glPopMatrix();
516                 }
517         }
518
519         glPopAttrib();
520 }
521
522 /* Special actions taken when paint cursor goes over mesh */
523 /* TODO: sculpt only for now */
524 static void paint_cursor_on_hit(UnifiedPaintSettings *ups, Brush *brush, ViewContext *vc,
525                                 const float location[3])
526 {
527         float unprojected_radius, projected_radius;
528
529         /* update the brush's cached 3D radius */
530         if (!BKE_brush_use_locked_size(vc->scene, brush)) {
531                 /* get 2D brush radius */
532                 if (ups->draw_anchored)
533                         projected_radius = ups->anchored_size;
534                 else {
535                         if (brush->flag & BRUSH_ANCHORED)
536                                 projected_radius = 8;
537                         else
538                                 projected_radius = BKE_brush_size_get(vc->scene, brush);
539                 }
540         
541                 /* convert brush radius from 2D to 3D */
542                 unprojected_radius = paint_calc_object_space_radius(vc, location,
543                                                                     projected_radius);
544
545                 /* scale 3D brush radius by pressure */
546                 if (ups->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush))
547                         unprojected_radius *= ups->pressure_value;
548
549                 /* set cached value in either Brush or UnifiedPaintSettings */
550                 BKE_brush_unprojected_radius_set(vc->scene, brush, unprojected_radius);
551         }
552 }
553
554 static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
555 {
556         Scene *scene = CTX_data_scene(C);
557         UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
558         Paint *paint = BKE_paint_get_active_from_context(C);
559         Brush *brush = BKE_paint_brush(paint);
560         ViewContext vc;
561         PaintMode mode;
562         float final_radius;
563         float translation[2];
564         float outline_alpha, *outline_col;
565         float zoomx, zoomy;
566         
567         /* check that brush drawing is enabled */
568         if (!(paint->flags & PAINT_SHOW_BRUSH))
569                 return;
570
571         /* can't use stroke vc here because this will be called during
572          * mouse over too, not just during a stroke */
573         view3d_set_viewcontext(C, &vc);
574
575         get_imapaint_zoom(C, &zoomx, &zoomy);
576         zoomx = max_ff(zoomx, zoomy);
577         mode = BKE_paintmode_get_active_from_context(C);
578
579         /* set various defaults */
580         translation[0] = x;
581         translation[1] = y;
582         outline_alpha = 0.5;
583         outline_col = brush->add_col;
584         final_radius = BKE_brush_size_get(scene, brush) * zoomx;
585
586         if (brush->flag & BRUSH_RAKE)
587                 /* here, translation contains the mouse coordinates. */
588                 paint_calculate_rake_rotation(ups, translation);
589         else if (!(brush->flag & BRUSH_ANCHORED))
590                 ups->brush_rotation = 0.0;
591
592         /* draw overlay */
593         paint_draw_alpha_overlay(ups, brush, &vc, x, y, zoomx, mode);
594
595         /* TODO: as sculpt and other paint modes are unified, this
596          * special mode of drawing will go away */
597         if (vc.obact->sculpt) {
598                 float location[3];
599                 int pixel_radius, hit;
600
601                 /* test if brush is over the mesh */
602                 hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location);
603
604                 if (BKE_brush_use_locked_size(scene, brush))
605                         BKE_brush_size_set(scene, brush, pixel_radius);
606
607                 /* check if brush is subtracting, use different color then */
608                 /* TODO: no way currently to know state of pen flip or
609                  * invert key modifier without starting a stroke */
610                 if ((!(brush->flag & BRUSH_INVERTED) ^
611                      !(brush->flag & BRUSH_DIR_IN)) &&
612                     ELEM5(brush->sculpt_tool, SCULPT_TOOL_DRAW,
613                           SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY,
614                           SCULPT_TOOL_PINCH, SCULPT_TOOL_CREASE))
615                 {
616                         outline_col = brush->sub_col;
617                 }
618
619                 /* only do if brush is over the mesh */
620                 if (hit)
621                         paint_cursor_on_hit(ups, brush, &vc, location);
622
623                 if (ups->draw_anchored) {
624                         final_radius = ups->anchored_size;
625                         translation[0] = ups->anchored_initial_mouse[0];
626                         translation[1] = ups->anchored_initial_mouse[1];
627                 }
628         }
629
630         /* make lines pretty */
631         glEnable(GL_BLEND);
632         glEnable(GL_LINE_SMOOTH);
633
634         /* set brush color */
635         glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha);
636
637         /* draw brush outline */
638         glTranslatef(translation[0], translation[1], 0);
639
640         /* draw an inner brush */
641         if (ups->draw_pressure && BKE_brush_use_size_pressure(scene, brush)) {
642                 /* inner at full alpha */
643                 glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius * ups->pressure_value, 40);
644                 /* outer at half alpha */
645                 glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha * 0.5f);
646         }
647         glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius, 40);
648         glTranslatef(-translation[0], -translation[1], 0);
649
650         /* restore GL state */
651         glDisable(GL_BLEND);
652         glDisable(GL_LINE_SMOOTH);
653 }
654
655 /* Public API */
656
657 void paint_cursor_start(bContext *C, int (*poll)(bContext *C))
658 {
659         Paint *p = BKE_paint_get_active_from_context(C);
660
661         if (p && !p->paint_cursor)
662                 p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL);
663
664         /* invalidate the paint cursors */
665         BKE_paint_invalidate_overlay_all();
666 }
667
668 void paint_cursor_start_explicit(Paint *p, wmWindowManager *wm, int (*poll)(bContext *C))
669 {
670         if (p && !p->paint_cursor)
671                 p->paint_cursor = WM_paint_cursor_activate(wm, poll, paint_draw_cursor, NULL);
672 }