Adding Star definitions to shapes.

This commit is contained in:
Pere Pujal i Carabantes 2014-10-19 23:33:51 +00:00
parent 783b0ef9ab
commit bc1fe2d6fe
2 changed files with 174 additions and 20 deletions

View file

@ -49,6 +49,12 @@ enum
SHAPE_RHOMBUS_FILL,
SHAPE_OCTAGON,
SHAPE_OCTAGON_FILL,
SHAPE_TRIANGLE_STAR,
SHAPE_TRIANGLE_STAR_FILL,
SHAPE_RHOMBUS_STAR,
SHAPE_RHOMBUS_STAR_FILL,
SHAPE_PENTAGON_STAR,
SHAPE_PENTAGON_STAR_FILL,
NUM_SHAPES
};
@ -71,7 +77,13 @@ const int shape_sides[NUM_SHAPES] = {
4, /* Rhombus */
4, /* Rhombus */
8, /* Octagon */
8 /* Octagon */
8, /* Octagon */
3, /* 3 points star*/
3, /* 3 points star*/
4, /* 4 points star*/
4, /* 4 points star*/
5, /* 5 points star*/
5 /* 5 points star*/
};
@ -93,7 +105,13 @@ const int shape_locked[NUM_SHAPES] = {
0, /* Rhombus */
0, /* Rhombus */
1, /* Octagon */
1 /* Octagon */
1, /* Octagon */
0, /* 3 points star*/
0, /* 3 points star*/
0, /* 4 points star*/
0, /* 4 points star*/
0, /* 5 points star*/
0 /* 5 points star*/
};
@ -115,7 +133,13 @@ const int shape_filled[NUM_SHAPES] = {
0, /* Rhombus */
1, /* Rhombus */
0, /* Octagon */
1 /* Octagon */
1, /* Octagon */
0, /* 3 points star*/
1, /* 3 points star*/
0, /* 4 points star*/
1, /* 4 points star*/
0, /* 5 points star*/
1 /* 5 points star*/
};
@ -138,7 +162,13 @@ const int shape_init_ang[NUM_SHAPES] = {
0, /* Rhombus */
0, /* Rhombus */
22, /* Octagon */
22 /* Octagon */
22, /* Octagon */
210, /* 3 points star*/
210, /* 3 points star*/
0, /* 4 points star*/
0, /* 4 points star*/
162, /* 5 points star */
162 /* 5 points star */
};
@ -160,7 +190,40 @@ const int shape_no_rotate[NUM_SHAPES] = {
0, /* Rhombus */
0, /* Rhombus */
0, /* Octagon */
0 /* Octagon */
0, /* Octagon */
0, /* 3 points star */
0, /* 3 points star */
0, /* 4 points star */
0, /* 4 points star */
0, /* 5 points star */
0 /* 5 points star */
};
/* Valley of stars in percent of size */
const int shape_valley[NUM_SHAPES] = {
100, /* Square */
100, /* Square */
100, /* Rectangle */
100, /* Rectangle */
100, /* Circle */
100, /* Circle */
100, /* Ellipse */
100, /* Ellipse */
100, /* Triangle */
100, /* Triangle */
100, /* Pentagon */
100, /* Pentagon */
100, /* Rhombus */
100, /* Rhombus */
100, /* Octagon */
100, /* Octagon */
20, /* 3 points star */
20, /* 3 points star */
30, /* 4 points star */
30, /* 4 points star */
35, /* 5 points star */
35 /* 5 points star */
};
@ -197,7 +260,26 @@ const char *const shape_names[NUM_SHAPES] = {
// Octagon shape tool (8 sides)
gettext_noop("Octagon"),
gettext_noop("Octagon")
gettext_noop("Octagon"),
// Triangle star (3 points star)
gettext_noop("3p Star"),
// Triangle star (3 points star)
gettext_noop("3p Star"),
// Rhombus star (4 points star)
gettext_noop("4p Star"),
// Rhombus star (4 points star)
gettext_noop("4p Star"),
// Pentagone star (5 points star)
gettext_noop("5p Star"),
// Pentagone star (5 points star)
gettext_noop("5p Star")
};
@ -240,7 +322,15 @@ const char *const shape_tips[NUM_SHAPES] = {
gettext_noop
("An octagon has eight equal sides."),
gettext_noop
("An octagon has eight equal sides.")
("An octagon has eight equal sides."),
gettext_noop("A star with 3 points."),
gettext_noop("A star with 3 points."),
gettext_noop("A star with 4 points."),
gettext_noop("A star with 4 points."),
gettext_noop("A star with 5 points."),
gettext_noop("A star with 5 points.")
};
@ -262,5 +352,12 @@ const char *const shape_img_fnames[NUM_SHAPES] = {
DATA_PREFIX "images/shapes/diamond.png",
DATA_PREFIX "images/shapes/diamond_f.png",
DATA_PREFIX "images/shapes/octagon.png",
DATA_PREFIX "images/shapes/octagon_f.png"
DATA_PREFIX "images/shapes/octagon_f.png",
DATA_PREFIX "images/shapes/rectangle.png",
DATA_PREFIX "images/shapes/rectangle.png",
DATA_PREFIX "images/shapes/rectangle.png",
DATA_PREFIX "images/shapes/rectangle.png",
DATA_PREFIX "images/shapes/rectangle.png",
DATA_PREFIX "images/shapes/rectangle.png"
};

View file

@ -12464,9 +12464,9 @@ static void update_shape(int cx, int ox1, int ox2, int cy, int oy1, int oy2, int
static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
{
int side, angle_skip, init_ang, rx, ry, rmax, x1, y1, x2, y2, xp, yp,
old_brush, step;
xv, yv, old_brush, step;
float a1, a2, rotn_rad;
int xx;
int xx, yy;
/* Determine radius/shape of the shape to draw: */
@ -12562,6 +12562,11 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
x2 = (int) (cos(a2) * rx);
y2 = (int) (-sin(a2) * ry);
xv = (int) (cos((a1 + a2) / 2) * rx * shape_valley[cur_shape] / 100);
yv = (int) (-sin((a1 + a2) / 2) * ry * shape_valley[cur_shape] / 100);
/* Rotate the line: */
@ -12580,6 +12585,12 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
x2 = xp;
y2 = yp;
xp = xv * cos(rotn_rad) - yv * sin(rotn_rad);
yp = xv * sin(rotn_rad) + yv * cos(rotn_rad);
xv = xp;
yv = yp;
}
@ -12589,6 +12600,8 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
y1 = y1 + cy;
x2 = x2 + cx;
y2 = y2 + cy;
xv = xv + cx;
yv = yv + cy;
/* Draw: */
@ -12596,35 +12609,65 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
if (!use_brush)
{
/* (XOR) */
line_xor(x1, y1, x2, y2);
if (shape_valley[cur_shape] == 100)
line_xor(x1, y1, x2, y2);
else
{
line_xor(x1, y1, xv, yv);
line_xor(xv, yv, x2, y2);
}
}
else
{
if (shape_valley[cur_shape] == 100)
/* Brush */
brush_draw(x1, y1, x2, y2, 0);
brush_draw(x1, y1, x2, y2, 0);
else
/* Stars */
{
brush_draw(x1, y1, xv, yv, 0);
brush_draw(xv, yv, x2, y2, 0);
}
}
}
if (use_brush && shape_filled[cur_shape])
if (use_brush && shape_filled[cur_shape] && rx > 0 && ry > 0)
{
/* FIXME: In the meantime, we'll do this lame radius-based fill: */
for (xx = abs(rx); xx >= 0; xx--)
for (xx = max(abs(rx), abs(ry)); xx > 0; xx--)
{
yy = min(xx * rx / ry,xx * ry / rx);
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) * xx);
y1 = (int) (-sin(a1) * ry);
if (yy == xx * ry / rx)
{
x1 = (int) (cos(a1) * xx);
y1 = (int) (-sin(a1) * yy);
x2 = (int) (cos(a2) * xx);
y2 = (int) (-sin(a2) * ry);
x2 = (int) (cos(a2) * xx);
y2 = (int) (-sin(a2) * yy);
xv = (int) (cos((a1 + a2) / 2) * xx * shape_valley[cur_shape] / 100);
yv = (int) (-sin((a1 + a2) / 2) * yy * shape_valley[cur_shape] / 100);
}
else
{
x1 = (int) (cos(a1) * yy);
y1 = (int) (-sin(a1) * xx);
x2 = (int) (cos(a2) * yy);
y2 = (int) (-sin(a2) * xx);
xv = (int) (cos((a1 + a2) / 2) * yy * shape_valley[cur_shape] / 100);
yv = (int) (-sin((a1 + a2) / 2) * xx * shape_valley[cur_shape] / 100);
}
/* Rotate the line: */
@ -12643,6 +12686,12 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
x2 = xp;
y2 = yp;
xp = xv * cos(rotn_rad) - yv * sin(rotn_rad);
yp = xv * sin(rotn_rad) + yv * cos(rotn_rad);
xv = xp;
yv = yp;
}
@ -12652,11 +12701,19 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
y1 = y1 + cy;
x2 = x2 + cx;
y2 = y2 + cy;
xv = xv + cx;
yv = yv + cy;
/* Draw: */
if (shape_valley[cur_shape] == 100)
brush_draw(x1, y1, x2, y2, 0);
else
/* Stars */
{
brush_draw(x1, y1, xv, yv, 0);
brush_draw(xv, yv, x2, y2, 0);
}
}
if (xx % 10 == 0)