source: synfigstudio/trunk/fuentes/src/brushlib/brushsettings.py @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 15.5 KB
Line 
1# brushlib - The MyPaint Brush Library
2# Copyright (C) 2007-2011 Martin Renold <martinxyz@gmx.ch>
3#
4# Permission to use, copy, modify, and/or distribute this software for any
5# purpose with or without fee is hereby granted, provided that the above
6# copyright notice and this permission notice appear in all copies.
7#
8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16"""Brush Settings / States
17
18This is used to generate brushsettings.hpp (see generate.py)
19It is also imported at runtime.
20"""
21
22from gettext import gettext as _
23
24inputs_list = [
25    # name, hard minimum, soft minimum, normal[1], soft maximum, hard maximum, displayed name, tooltip
26    ['pressure', 0.0,  0.0,  0.4,  1.0, 1.0,  _("Pressure"), _("The pressure reported by the tablet, between 0.0 and 1.0. If you use the mouse, it will be 0.5 when a button is pressed and 0.0 otherwise.")],
27    ['speed1',   None, 0.0,  0.5,  4.0, None, _("Fine speed"), _("How fast you currently move. This can change very quickly. Try 'print input values' from the 'help' menu to get a feeling for the range; negative values are rare but possible for very low speed.")],
28    ['speed2',   None, 0.0,  0.5,  4.0, None, _("Gross speed"), _("Same as fine speed, but changes slower. Also look at the 'gross speed filter' setting.")],
29    ['random',   0.0,  0.0,  0.5,  1.0, 1.0, _("Random"), _("Fast random noise, changing at each evaluation. Evenly distributed between 0 and 1.")],
30    ['stroke',   0.0,  0.0,  0.5,  1.0, 1.0, _("Stroke"), _("This input slowly goes from zero to one while you draw a stroke. It can also be configured to jump back to zero periodically while you move. Look at the 'stroke duration' and 'stroke hold time' settings.")],
31    ['direction',0.0,  0.0,  0.0,  180.0, 180.0, _("Direction"), _("The angle of the stroke, in degrees. The value will stay between 0.0 and 180.0, effectively ignoring turns of 180 degrees.")],
32    ['tilt_declination',0.0,  0.0,  0.0,  90.0, 90.0,  _("Declination"), _("Declination of stylus tilt. 0 when stylus is parallel to tablet and 90.0 when it's perpendicular to tablet.")],
33    ['tilt_ascension',-180.0,  -180.0,  0.0,  180.0, 180.0, _("Ascension"),  _("Right ascension of stylus tilt. 0 when stylus working end points to you, +90 when rotated 90 degrees clockwise, -90 when rotated 90 degrees counterclockwise.")],
34    #['motion_strength',0.0,0.0,  0.0,  1.0, 1.0,  "[EXPERIMENTAL] Same as angle, but wraps at 180 degrees. The dynamics are shared with BRUSH_OFFSET_BY_SPEED_FILTER (FIXME: which is a bad thing)."],
35    ['custom',   None,-2.0,  0.0, +2.0, None, _("Custom"), _("This is a user defined input. Look at the 'custom input' setting for details.")],
36    ]
37    # [1] If, for example, the user increases the "by pressure" slider
38    # in the "radius" control, then this should change the reaction to
39    # pressure and not the "normal" radius. To implement this, we need
40    # a guess what the user considers to be normal pressure.
41
42settings_list = [
43    # internal name, displayed name, constant, minimum, default, maximum, tooltip
44    ['opaque', _('Opacity'), False, 0.0, 1.0, 2.0, _("0 means brush is transparent, 1 fully visible\n(also known as alpha or opacity)")],
45    ['opaque_multiply', _('Opacity multiply'), False, 0.0, 0.0, 2.0, _("This gets multiplied with opaque. You should only change the pressure input of this setting. Use 'opaque' instead to make opacity depend on speed.\nThis setting is responsible to stop painting when there is zero pressure. This is just a convention, the behaviour is identical to 'opaque'.")],
46    ['opaque_linearize', _('Opacity linearize'), True, 0.0, 0.9, 2.0, _("Correct the nonlinearity introduced by blending multiple dabs on top of each other. This correction should get you a linear (\"natural\") pressure response when pressure is mapped to opaque_multiply, as it is usually done. 0.9 is good for standard strokes, set it smaller if your brush scatters a lot, or higher if you use dabs_per_second.\n0.0 the opaque value above is for the individual dabs\n1.0 the opaque value above is for the final brush stroke, assuming each pixel gets (dabs_per_radius*2) brushdabs on average during a stroke")],
47    ['radius_logarithmic', _('Radius'), False, -2.0, 2.0, 5.0, _("Basic brush radius (logarithmic)\n 0.7 means 2 pixels\n 3.0 means 20 pixels")],
48    ['hardness', _('Hardness'), False, 0.0, 0.8, 1.0, _("Hard brush-circle borders (setting to zero will draw nothing). To reach the maximum hardness, you need to disable Anti-aliasing.")],
49    ['anti_aliasing', _('Anti-aliasing'), False, 0.0, 1.0, 5.0, _("This setting decreases the hardness when necessary to prevent a pixel staircase effect.\n 0.0 disable (for very strong erasers and pixel brushes)\n 1.0 blur one pixel (good value)\n 5.0 notable blur, thin strokes will disappear")],
50    ['dabs_per_basic_radius', _('Dabs per basic radius'), True, 0.0, 0.0, 6.0, _("How many dabs to draw while the pointer moves a distance of one brush radius (more precise: the base value of the radius)")],
51    ['dabs_per_actual_radius', _('Dabs per actual radius'), True, 0.0, 2.0, 6.0, _("Same as above, but the radius actually drawn is used, which can change dynamically")],
52    ['dabs_per_second', _('Dabs per second'), True, 0.0, 0.0, 80.0, _("Dabs to draw each second, no matter how far the pointer moves")],
53    ['radius_by_random', _('Radius by random'), False, 0.0, 0.0, 1.5, _("Alter the radius randomly each dab. You can also do this with the by_random input on the radius setting. If you do it here, there are two differences:\n1) the opaque value will be corrected such that a big-radius dabs is more transparent\n2) it will not change the actual radius seen by dabs_per_actual_radius")],
54    ['speed1_slowness', _('Fine speed filter'), False, 0.0, 0.04, 0.2, _("How slow the input fine speed is following the real speed\n0.0 change immediately as your speed changes (not recommended, but try it)")],
55    ['speed2_slowness', _('Gross speed filter'), False, 0.0, 0.8, 3.0, _("Same as 'fine speed filter', but note that the range is different")],
56    ['speed1_gamma', _('Fine speed gamma'), True, -8.0, 4.0, 8.0, _("This changes the reaction of the 'fine speed' input to extreme physical speed. You will see the difference best if 'fine speed' is mapped to the radius.\n-8.0 very fast speed does not increase 'fine speed' much more\n+8.0 very fast speed increases 'fine speed' a lot\nFor very slow speed the opposite happens.")],
57    ['speed2_gamma', _('Gross speed gamma'), True, -8.0, 4.0, 8.0, _("Same as 'fine speed gamma' for gross speed")],
58    ['offset_by_random', _('Jitter'), False, 0.0, 0.0, 25.0, _("Add a random offset to the position where each dab is drawn\n 0.0 disabled\n 1.0 standard deviation is one basic radius away\n<0.0 negative values produce no jitter")],
59    ['offset_by_speed', _('Offset by speed'), False, -3.0, 0.0, 3.0, _("Change position depending on pointer speed\n= 0 disable\n> 0 draw where the pointer moves to\n< 0 draw where the pointer comes from")],
60    ['offset_by_speed_slowness', _('Offset by speed filter'), False, 0.0, 1.0, 15.0, _("How slow the offset goes back to zero when the cursor stops moving")],
61    ['slow_tracking', _('Slow position tracking'), True, 0.0, 0.0, 10.0, _("Slowdown pointer tracking speed. 0 disables it, higher values remove more jitter in cursor movements. Useful for drawing smooth, comic-like outlines.")],
62    ['slow_tracking_per_dab', _('Slow tracking per dab'), False, 0.0, 0.0, 10.0, _("Similar as above but at brushdab level (ignoring how much time has past, if brushdabs do not depend on time)")],
63    ['tracking_noise', _('Tracking noise'), True, 0.0, 0.0, 12.0, _("Add randomness to the mouse pointer; this usually generates many small lines in random directions; maybe try this together with 'slow tracking'")],
64
65    ['color_h', _('Color hue'), True, 0.0, 0.0, 1.0, _("Color hue")],
66    ['color_s', _('Color saturation'), True, -0.5, 0.0, 1.5, _("Color saturation")],
67    ['color_v', _('Color value'), True, -0.5, 0.0, 1.5, _("Color value (brightness, intensity)")],
68    ['restore_color', _('Save color'), True, 0.0, 0.0, 1.0, _("When selecting a brush, the color can be restored to the color that the brush was saved with.\n 0.0 do not modify the active color when selecting this brush\n 0.5 change active color towards brush color\n 1.0 set the active color to the brush color when selected")],
69    ['change_color_h', _('Change color hue'), False, -2.0, 0.0, 2.0, _("Change color hue.\n-0.1 small clockwise color hue shift\n 0.0 disable\n 0.5 counterclockwise hue shift by 180 degrees")],
70    ['change_color_l', _('Change color lightness (HSL)'), False, -2.0, 0.0, 2.0, _("Change the color lightness (luminance) using the HSL color model.\n-1.0 blacker\n 0.0 disable\n 1.0 whiter")],
71    ['change_color_hsl_s', _('Change color satur. (HSL)'), False, -2.0, 0.0, 2.0, _("Change the color saturation using the HSL color model.\n-1.0 more grayish\n 0.0 disable\n 1.0 more saturated")],
72    ['change_color_v', _('Change color value (HSV)'), False, -2.0, 0.0, 2.0, _("Change the color value (brightness, intensity) using the HSV color model. HSV changes are applied before HSL.\n-1.0 darker\n 0.0 disable\n 1.0 brighter")],
73    ['change_color_hsv_s', _('Change color satur. (HSV)'), False, -2.0, 0.0, 2.0, _("Change the color saturation using the HSV color model. HSV changes are applied before HSL.\n-1.0 more grayish\n 0.0 disable\n 1.0 more saturated")],
74    ['smudge', _('Smudge'), False, 0.0, 0.0, 1.0, _("Paint with the smudge color instead of the brush color. The smudge color is slowly changed to the color you are painting on.\n 0.0 do not use the smudge color\n 0.5 mix the smudge color with the brush color\n 1.0 use only the smudge color")],
75    ['smudge_length', _('Smudge length'), False, 0.0, 0.5, 1.0, _("This controls how fast the smudge color becomes the color you are painting on.\n0.0 immediately update the smudge color (requires more CPU cycles because of the frequent color checks)\n0.5 change the smudge color steadily towards the canvas color\n1.0 never change the smudge color")],
76    ['smudge_radius_log', _('Smudge radius'), False, -1.6, 0.0, 1.6, _("This modifies the radius of the circle where color is picked up for smudging.\n 0.0 use the brush radius\n-0.7 half the brush radius (fast, but not always intuitive)\n+0.7 twice the brush radius\n+1.6 five times the brush radius (slow performance)")],
77    ['eraser', _('Eraser'), False, 0.0, 0.0, 1.0, _("how much this tool behaves like an eraser\n 0.0 normal painting\n 1.0 standard eraser\n 0.5 pixels go towards 50% transparency")],
78
79    ['stroke_threshold', _('Stroke threshold'), True, 0.0, 0.0, 0.5, _("How much pressure is needed to start a stroke. This affects the stroke input only. Mypaint does not need a minimal pressure to start drawing.")],
80    ['stroke_duration_logarithmic', _('Stroke duration'), False, -1.0, 4.0, 7.0, _("How far you have to move until the stroke input reaches 1.0. This value is logarithmic (negative values will not inverse the process).")],
81    ['stroke_holdtime', _('Stroke hold time'), False, 0.0, 0.0, 10.0, _("This defines how long the stroke input stays at 1.0. After that it will reset to 0.0 and start growing again, even if the stroke is not yet finished.\n2.0 means twice as long as it takes to go from 0.0 to 1.0\n9.9 and bigger stands for infinite")],
82    ['custom_input', _('Custom input'), False, -5.0, 0.0, 5.0, _("Set the custom input to this value. If it is slowed down, move it towards this value (see below). The idea is that you make this input depend on a mixture of pressure/speed/whatever, and then make other settings depend on this 'custom input' instead of repeating this combination everywhere you need it.\nIf you make it change 'by random' you can generate a slow (smooth) random input.")],
83    ['custom_input_slowness', _('Custom input filter'), False, 0.0, 0.0, 10.0, _("How slow the custom input actually follows the desired value (the one above). This happens at brushdab level (ignoring how much time has past, if brushdabs do not depend on time).\n0.0 no slowdown (changes apply instantly)")],
84
85    ['elliptical_dab_ratio', _('Elliptical dab: ratio'), False, 1.0, 1.0, 10.0, _("Aspect ratio of the dabs; must be >= 1.0, where 1.0 means a perfectly round dab. TODO: linearize? start at 0.0 maybe, or log?")],
86    ['elliptical_dab_angle', _('Elliptical dab: angle'), False, 0.0, 90.0, 180.0, _("Angle by which elliptical dabs are tilted\n 0.0 horizontal dabs\n 45.0 45 degrees, turned clockwise\n 180.0 horizontal again")],
87    ['direction_filter', _('Direction filter'), False, 0.0, 2.0, 10.0, _("A low value will make the direction input adapt more quickly, a high value will make it smoother")],
88
89    ['lock_alpha', _('Lock alpha'), False, 0.0, 0.0, 1.0, _("Do not modify the alpha channel of the layer (paint only where there is paint already)\n 0.0 normal painting\n 0.5 half of the paint gets applied normally\n 1.0 alpha channel fully locked")],
90    ]
91
92settings_hidden = 'color_h color_s color_v'.split()
93
94settings_migrate = {
95    # old cname              new cname        scale function
96    'color_hue'          : ('change_color_h', lambda y: y*64.0/360.0),
97    'color_saturation'   : ('change_color_hsv_s', lambda y: y*128.0/256.0),
98    'color_value'        : ('change_color_v', lambda y: y*128.0/256.0),
99    'speed_slowness'     : ('speed1_slowness', None),
100    'change_color_s'     : ('change_color_hsv_s', None),
101    'stroke_treshold'    : ('stroke_threshold', None),
102    }
103
104# the states are not (yet?) exposed to the user
105# WARNING: only append to this list, for compatibility of replay files (brush.get_state() in stroke.py)
106states_list = '''
107# lowlevel
108x, y
109pressure
110dist              # "distance" moved since last dab, a new dab is drawn at 1.0
111actual_radius     # used by count_dabs_to, thus a state!
112
113smudge_ra, smudge_ga, smudge_ba, smudge_a  # smudge color stored with premultiplied alpha (low-pass filtered)
114last_getcolor_r, last_getcolor_g, last_getcolor_b, last_getcolor_a # cached result of last call to get_color()
115last_getcolor_recentness
116
117actual_x, actual_y  # for slow position
118norm_dx_slow, norm_dy_slow # note: now this is dx/dt * (1/radius)
119
120norm_speed1_slow, norm_speed2_slow
121
122stroke, stroke_started # stroke_started is used as boolean
123
124custom_input
125rng_seed
126
127actual_elliptical_dab_ratio, actual_elliptical_dab_angle # used by count_dabs_to
128
129direction_dx, direction_dy
130declination, ascension
131'''
132
133class BrushInput:
134    pass
135
136inputs = []
137inputs_dict = {}
138for i_list in inputs_list:
139    i = BrushInput()
140    i.name, i.hard_min, i.soft_min, i.normal, i.soft_max, i.hard_max, i.dname, i.tooltip = i_list
141    i.index = len(inputs)
142    inputs.append(i)
143    inputs_dict[i.name] = i
144
145class BrushSetting:
146    pass
147
148settings = []
149settings_dict = {}
150for s_list in settings_list:
151    s = BrushSetting()
152    s.cname, s.name, s.constant, s.min, s.default, s.max, s.tooltip = s_list
153    s.index = len(settings)
154    settings.append(s)
155    settings_dict[s.cname] = s
156    globals()[s.cname] = s
157
158settings_visible = [s for s in settings if s.cname not in settings_hidden]
159
160class BrushState:
161    pass
162
163states = []
164for line in states_list.split('\n'):
165    line = line.split('#')[0]
166    for cname in line.split(','):
167        cname = cname.strip()
168        if not cname: continue
169        st = BrushState()
170        st.cname = cname
171        st.index = len(states)
172        states.append(st)
Note: See TracBrowser for help on using the repository browser.