1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 */ 16 17 #pragma once 18 19 /** \file 20 * \ingroup bke 21 * 22 * General operations for brushes. 23 */ 24 25 #include "DNA_object_enums.h" 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 enum eCurveMappingPreset; 32 struct Brush; 33 struct ImBuf; 34 struct ImagePool; 35 struct Main; 36 struct Scene; 37 struct ToolSettings; 38 struct UnifiedPaintSettings; 39 40 // enum eCurveMappingPreset; 41 42 /* globals for brush execution */ 43 void BKE_brush_system_init(void); 44 void BKE_brush_system_exit(void); 45 46 /* datablock functions */ 47 struct Brush *BKE_brush_add(struct Main *bmain, const char *name, const eObjectMode ob_mode); 48 struct Brush *BKE_brush_add_gpencil(struct Main *bmain, 49 struct ToolSettings *ts, 50 const char *name, 51 eObjectMode mode); 52 bool BKE_brush_delete(struct Main *bmain, struct Brush *brush); 53 void BKE_brush_init_gpencil_settings(struct Brush *brush); 54 struct Brush *BKE_brush_first_search(struct Main *bmain, const eObjectMode ob_mode); 55 56 void BKE_brush_sculpt_reset(struct Brush *brush); 57 58 void BKE_brush_gpencil_paint_presets(struct Main *bmain, 59 struct ToolSettings *ts, 60 const bool reset); 61 void BKE_brush_gpencil_vertex_presets(struct Main *bmain, 62 struct ToolSettings *ts, 63 const bool reset); 64 void BKE_brush_gpencil_sculpt_presets(struct Main *bmain, 65 struct ToolSettings *ts, 66 const bool reset); 67 void BKE_brush_gpencil_weight_presets(struct Main *bmain, 68 struct ToolSettings *ts, 69 const bool reset); 70 void BKE_gpencil_brush_preset_set(struct Main *bmain, struct Brush *brush, const short type); 71 72 /* image icon function */ 73 struct ImBuf *get_brush_icon(struct Brush *brush); 74 75 /* jitter */ 76 void BKE_brush_jitter_pos(const struct Scene *scene, 77 struct Brush *brush, 78 const float pos[2], 79 float jitterpos[2]); 80 void BKE_brush_randomize_texture_coords(struct UnifiedPaintSettings *ups, bool mask); 81 82 /* brush curve */ 83 void BKE_brush_curve_preset(struct Brush *b, enum eCurveMappingPreset preset); 84 float BKE_brush_curve_strength_clamped(struct Brush *br, float p, const float len); 85 float BKE_brush_curve_strength(const struct Brush *br, float p, const float len); 86 87 /* sampling */ 88 float BKE_brush_sample_tex_3d(const struct Scene *scene, 89 const struct Brush *br, 90 const float point[3], 91 float rgba[4], 92 const int thread, 93 struct ImagePool *pool); 94 float BKE_brush_sample_masktex(const struct Scene *scene, 95 struct Brush *br, 96 const float point[2], 97 const int thread, 98 struct ImagePool *pool); 99 100 /* texture */ 101 unsigned int *BKE_brush_gen_texture_cache(struct Brush *br, int half_side, bool use_secondary); 102 103 /* radial control */ 104 struct ImBuf *BKE_brush_gen_radial_control_imbuf(struct Brush *br, 105 bool secondary, 106 bool display_gradient); 107 108 /* unified strength size and color */ 109 110 const float *BKE_brush_color_get(const struct Scene *scene, const struct Brush *brush); 111 const float *BKE_brush_secondary_color_get(const struct Scene *scene, const struct Brush *brush); 112 void BKE_brush_color_set(struct Scene *scene, struct Brush *brush, const float color[3]); 113 114 int BKE_brush_size_get(const struct Scene *scene, const struct Brush *brush); 115 void BKE_brush_size_set(struct Scene *scene, struct Brush *brush, int size); 116 117 float BKE_brush_unprojected_radius_get(const struct Scene *scene, const struct Brush *brush); 118 void BKE_brush_unprojected_radius_set(struct Scene *scene, 119 struct Brush *brush, 120 float unprojected_radius); 121 122 float BKE_brush_alpha_get(const struct Scene *scene, const struct Brush *brush); 123 void BKE_brush_alpha_set(struct Scene *scene, struct Brush *brush, float alpha); 124 float BKE_brush_weight_get(const struct Scene *scene, const struct Brush *brush); 125 void BKE_brush_weight_set(const struct Scene *scene, struct Brush *brush, float value); 126 127 bool BKE_brush_use_locked_size(const struct Scene *scene, const struct Brush *brush); 128 bool BKE_brush_use_alpha_pressure(const struct Brush *brush); 129 bool BKE_brush_use_size_pressure(const struct Brush *brush); 130 131 bool BKE_brush_sculpt_has_secondary_color(const struct Brush *brush); 132 133 /* scale unprojected radius to reflect a change in the brush's 2D size */ 134 void BKE_brush_scale_unprojected_radius(float *unprojected_radius, 135 int new_brush_size, 136 int old_brush_size); 137 138 /* scale brush size to reflect a change in the brush's unprojected radius */ 139 void BKE_brush_scale_size(int *r_brush_size, 140 float new_unprojected_radius, 141 float old_unprojected_radius); 142 143 /* Accessors */ 144 #define BKE_brush_tool_get(brush, p) \ 145 (CHECK_TYPE_ANY(brush, struct Brush *, const struct Brush *), \ 146 *(const char *)POINTER_OFFSET(brush, (p)->runtime.tool_offset)) 147 #define BKE_brush_tool_set(brush, p, tool) \ 148 { \ 149 CHECK_TYPE_ANY(brush, struct Brush *); \ 150 *(char *)POINTER_OFFSET(brush, (p)->runtime.tool_offset) = tool; \ 151 } \ 152 ((void)0) 153 154 /* debugging only */ 155 void BKE_brush_debug_print_state(struct Brush *br); 156 157 #ifdef __cplusplus 158 } 159 #endif 160