Wrapping up "shapes from corner" option

Works well, or at least well enough, for our current batch of
shapes.
This commit is contained in:
Bill Kendrick 2020-08-15 16:20:51 -07:00
parent f734d21fa4
commit d2d9b98291
4 changed files with 97 additions and 8 deletions

View file

@ -8,7 +8,7 @@ http://www.tuxpaint.org/
$Id$ $Id$
2020.August.14 (0.9.25) 2020.August.15 (0.9.25)
* New Features * New Features
------------ ------------
* Export drawings: * Export drawings:
@ -27,7 +27,7 @@ $Id$
* The "--exportdir" option can be used to override the default * The "--exportdir" option can be used to override the default
location (but a "TuxPaint" subdir. will NOT be placed there). location (but a "TuxPaint" subdir. will NOT be placed there).
* Shape controls: -- WORK IN PROGRESS * Shape controls:
* Draw shapes from the center (as in previous versions of Tux Paint) * Draw shapes from the center (as in previous versions of Tux Paint)
or from a corner (similar to the default mode of most other or from a corner (similar to the default mode of most other
graphics tools). graphics tools).

View file

@ -6,7 +6,7 @@
Copyright 2002-2020 by various contributors; see AUTHORS.txt Copyright 2002-2020 by various contributors; see AUTHORS.txt
http://www.tuxpaint.org/ http://www.tuxpaint.org/
June 14, 2002 - July 27, 2020 June 14, 2002 - August 15, 2020
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -285,10 +285,31 @@ Available Tools
Select a shape from the selector on the right (circle, Select a shape from the selector on the right (circle,
square, oval, etc.). square, oval, etc.).
Use the options at the bottom right to choose the shape
tool's behavior:
Shapes from center
The shape will expand from where you initially
clicked, and will be centered around that
position. (This was Tux Paint's only behavior
through version 0.9.24.)
Shapes from corner
The shape will extend with one corner starting
from where you initially clicked. This is the
default method of most other traditional
drawing software. (This option was added
starting with Tux Paint version 0.9.25.)
Note: If shape controls are disabled (e.g., with the
"--noshapecontrols" option), the controls will not be
presented, and the "shapes from center" method will be used.
In the canvas, click the mouse and hold it to stretch the In the canvas, click the mouse and hold it to stretch the
shape out from where you clicked. Some shapes can change shape out from where you clicked. Some shapes can change
proportion (e.g., rectangle and oval), others cannot (e.g., proportion (e.g., rectangle and oval may be wider than tall,
square and circle). or taller than wide), others cannot (e.g., square and
circle).
Let go of the mouse when you're done stretching. Let go of the mouse when you're done stretching.

View file

@ -35,7 +35,7 @@
</p> </p>
<p> <p>
June 14, 2002 - July 27, 2020 June 14, 2002 - August 15, 2020
</p> </p>
</center> </center>
@ -707,11 +707,47 @@
(circle, square, oval, etc.). (circle, square, oval, etc.).
</p> </p>
<p>
Use the options at the bottom right to choose
the shape tool's behavior:
</p>
<dl>
<dt>
Shapes from center
</dt>
<dd>
The shape will expand from where you initially
clicked, and will be centered around that position.
(This was Tux&nbsp;Paint's only behavior through
version 0.9.24.)
</dd>
<dt>
Shapes from corner
</dt>
<dd>
The shape will extend with one corner starting
from where you initially clicked. This is the
default method of most other traditional drawing
software. (This option was added starting with
Tux&nbsp;Paint version 0.9.25.)
</dd>
</dl>
<p>
Note: If shape controls are disabled (e.g., with the
"<code>--noshapecontrols</code>" option), the controls
will not be presented, and the "shapes from center"
method will be used.
</p>
<p> <p>
In the canvas, click the mouse and hold it to In the canvas, click the mouse and hold it to
stretch the shape out from where you clicked. Some stretch the shape out from where you clicked. Some
shapes can change proportion (e.g., rectangle and shapes can change proportion (e.g., rectangle and
oval), others cannot (e.g., square and circle). oval may be wider than tall, or taller than wide),
others cannot (e.g., square and circle).
</p> </p>
<p> <p>

View file

@ -12825,7 +12825,7 @@ static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
{ {
int side, angle_skip, init_ang, rx, ry, rmax, x1, y1, x2, y2, xp, yp, xv, yv, old_brush, step; int side, angle_skip, init_ang, rx, ry, rmax, x1, y1, x2, y2, xp, yp, xv, yv, old_brush, step;
float a1, a2, rotn_rad; float a1, a2, rotn_rad;
int xx, yy, offx, offy; int xx, yy, offx, offy, max_x, max_y;
/* Determine radius/shape of the shape to draw: */ /* Determine radius/shape of the shape to draw: */
@ -12882,6 +12882,38 @@ static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
init_ang = shape_init_ang[cur_shape]; init_ang = shape_init_ang[cur_shape];
if (shape_mode == SHAPEMODE_CORNER)
{
/* Get extent of shape based on it's vertices,
and scale up if we need to
(e.g., square's points are at 45, 135, 225 & 315 degrees,
which do not extend to the full radius).
This works well for square and rectangle; it mostly
works for triangle and 5-pointed star, but it seems
sufficient. -bjk 2020.08.15 */
max_x = 0;
max_y = 0;
for (side = 0; side < shape_sides[cur_shape]; side++)
{
a1 = (angle_skip * side + init_ang) * M_PI / 180;
a2 = (angle_skip * (side + 1) + init_ang) * M_PI / 180;
x1 = (int)(cos(a1) * rx);
y1 = (int)(-sin(a1) * ry);
if (abs(x1) > max_x)
max_x = abs(x1);
if (abs(y1) > max_y)
max_y = abs(y1);
}
if (max_x < rx)
rx = (rx * rx) / max_x;
if (max_y < ry)
ry = (ry * ry) / max_y;
}
step = 1; step = 1;
if (dont_do_xor && !use_brush) if (dont_do_xor && !use_brush)