Skip to content

Commit 9fad0c5

Browse files
Banner generator code automates the huge number of details required to make nice icons
1 parent 3e02202 commit 9fad0c5

13 files changed

+1193
-35
lines changed

dev/banner_generator.cpp

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#include <math.h>
2+
#include <QApplication>
3+
#include <QImage>
4+
#include <QPainter>
5+
#include <QPixmap>
6+
7+
void drawPoint (QPainter *paint,
8+
const QColor &color,
9+
double x,
10+
double y,
11+
double axisLinewidth,
12+
int size)
13+
{
14+
QPen penOld = paint->pen();
15+
QBrush brushOld = paint->brush();
16+
17+
double radius = axisLinewidth * 3.0;
18+
19+
if (size < 32) {
20+
// Hack - at the start, line is too thick vertically so remove some pixels
21+
if (x == 4) {
22+
paint->setPen (Qt::white);
23+
paint->drawLine (QPointF (3, 11),
24+
QPointF (4, 11));
25+
26+
paint->setPen (color);
27+
paint->setBrush (Qt::NoBrush);
28+
29+
paint->drawLine (QPointF (x, y),
30+
QPointF (x + 2, y));
31+
paint->drawLine (QPointF (x + 1, y - 1),
32+
QPointF (x + 1, y + 1));
33+
} else {
34+
paint->setPen (color);
35+
paint->setBrush (Qt::NoBrush);
36+
37+
paint->drawLine (QPointF (x - 1, y),
38+
QPointF (x + 1, y));
39+
paint->drawLine (QPointF (x, y - 1),
40+
QPointF (x, y + 1));
41+
}
42+
} else {
43+
44+
paint->setPen (Qt::NoPen);
45+
paint->setBrush (color);
46+
47+
QPolygon polygon;
48+
polygon.append (QPoint (x + radius, y));
49+
polygon.append (QPoint (x, y - radius));
50+
polygon.append (QPoint (x - radius, y));
51+
polygon.append (QPoint (x, y + radius));
52+
polygon.append (QPoint (x + radius, y));
53+
paint->drawPolygon(polygon);
54+
}
55+
56+
paint->setPen (penOld);
57+
paint->setBrush (brushOld);
58+
}
59+
60+
61+
int main(int , char **)
62+
{
63+
for (int size = 16; size <= 256; size *= 2) {
64+
65+
int numAxisPoints = (size > 32 ? 5 : 4);
66+
int numCurvePoints = (size > 32 ? 4 : 3);
67+
double axisLinewidth = pow ((double) size, 0.8) / 16.0;
68+
double curveLinewidth = 1.5 * pow ((double) size / 16.0, 0.5);
69+
double margin = size / 8.0;
70+
double ticHalfHeight = size * 4.0 / 200.0;
71+
if (size == 32) ticHalfHeight *= 2; // Hack
72+
double pixelsPerCurvePoint = fmax (1, size / 32.0);
73+
74+
double xCurveMin = 2 * margin;
75+
double xCurveMax = size - margin;
76+
double yCurveMin = 2 * margin;
77+
double yCurveMax = size - margin;
78+
double xAxisMin = margin;
79+
double xAxisMax = size - margin;
80+
double yAxisMin = margin;
81+
double yAxisMax = size - margin;
82+
double xOffsetMax = xCurveMax - xCurveMin;
83+
double yOffsetMax = yCurveMax - yCurveMin;
84+
85+
QImage *img = new QImage (size, size, QImage::Format_ARGB32_Premultiplied);
86+
img->fill (QColor (Qt::white));
87+
88+
QPainter *paint = new QPainter (img);
89+
paint->begin(img);
90+
paint->setPen (QPen (QBrush (Qt::black), axisLinewidth));
91+
92+
// X and y axes
93+
paint->drawLine (QPointF (margin, size - margin),
94+
QPointF (size - margin, size - margin));
95+
paint->drawLine (QPointF (margin, size - margin),
96+
QPointF (margin, margin));
97+
98+
paint->setRenderHint (QPainter::Antialiasing, true);
99+
100+
// Quadratic line from (2*margin,size-2*margin) to (size-margin,margin)
101+
QPolygonF curve;
102+
int numCurveSteps = (xCurveMax - xCurveMin) / pixelsPerCurvePoint;
103+
for (int ic = 0; ic < numCurveSteps; ic++) {
104+
105+
double x = xCurveMin + ic * pixelsPerCurvePoint;
106+
107+
double xOffset = x - xCurveMin;
108+
double yOffset = yOffsetMax * xOffset * xOffset / (xOffsetMax * xOffsetMax);
109+
double y = size - 2 * margin - yOffset;
110+
111+
curve.append (QPointF (x, y));
112+
}
113+
QPen penOld = paint->pen();
114+
paint->setPen(QPen(QBrush (Qt::black), curveLinewidth));
115+
paint->drawPolyline (curve);
116+
paint->setPen(penOld);
117+
118+
paint->setRenderHint (QPainter::Antialiasing, false);
119+
120+
// Points along quadratic line. They are stretched evenly along the arc, rather than evenly
121+
// along the x direction, so it looks nicer
122+
double xDeltaCurve = (xCurveMax - xCurveMin) / (numCurvePoints - 1.0);
123+
for (int ip = 0; ip < numCurvePoints; ip++) {
124+
// Map from 0 through numAxisPoints-1 to 0 through numAxisPoints-1
125+
double xBefore = 1.0 + (2.71828 - 1.0) * ip / (double) (numCurvePoints - 1.0); // 1 to 2.71828
126+
double xAfter = log (xBefore); // 0 to 1
127+
double ipLog = (numCurvePoints - 1.0) * xAfter;
128+
129+
double x = xCurveMin + ipLog * xDeltaCurve;
130+
131+
double xOffset = x - xCurveMin;
132+
double yOffset = yOffsetMax * xOffset * xOffset / (xOffsetMax * xOffsetMax);
133+
double y = size - 2 * margin - yOffset;
134+
135+
drawPoint (paint, QColor (Qt::green), x, y, axisLinewidth, size);
136+
}
137+
138+
// X tics
139+
double xDelta = (xAxisMax - xAxisMin) / (numAxisPoints - 1.0);
140+
for (int ix = 0; ix < numAxisPoints; ix++) {
141+
double x = xAxisMin + ix * xDelta;
142+
double yCenter = size - margin;
143+
paint->drawLine (QPointF (x, yCenter - ticHalfHeight),
144+
QPointF (x, yCenter + ticHalfHeight));
145+
}
146+
147+
// Y tics
148+
double yDelta = (yAxisMax - yAxisMin) / (numAxisPoints- 1.0);
149+
for (int iy = 0; iy < numAxisPoints; iy++) {
150+
double xCenter = margin;
151+
double y = yAxisMin + iy * yDelta;
152+
paint->drawLine (QPointF (xCenter - ticHalfHeight, y),
153+
QPointF (xCenter + ticHalfHeight, y));
154+
}
155+
156+
drawPoint (paint, QColor (Qt::red), xAxisMin, size - margin, axisLinewidth, size);
157+
drawPoint (paint, QColor (Qt::red), xAxisMin, margin, axisLinewidth, size);
158+
drawPoint (paint, QColor (Qt::red), xAxisMax, size - margin, axisLinewidth, size);
159+
160+
paint->end();
161+
162+
// Save file
163+
QImage alpha = img->alphaChannel();
164+
for (int x = 0; x < img->width(); x++) {
165+
for (int y = 0; y < img->height(); y++) {
166+
QRgb pixel = img->pixel(x, y);
167+
if (qRed(pixel) == 255 && qGreen(pixel) == 255 && qBlue(pixel)) {
168+
alpha.setPixel(x, y, 255);
169+
}
170+
}
171+
}
172+
img->setAlphaChannel(alpha);
173+
QString filename = QString ("bannerapp_%1.xpm").arg (size);
174+
img->save (filename);
175+
176+
delete img;
177+
}
178+
}

src/Transformation/TransformationStateDefined.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ void TransformationStateDefined::begin(CmdMediator &cmdMediator,
3434
transformation);
3535
}
3636

37-
void TransformationStateDefined::end(CmdMediator &cmdMediator,
38-
const Transformation &transformation)
37+
void TransformationStateDefined::end(CmdMediator & /* cmdMediator */,
38+
const Transformation & /* transformation */)
3939
{
4040
LOG4CPP_INFO_S ((*mainCat)) << "TransformationStateDefined::end";
4141

src/Transformation/TransformationStateUndefined.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ TransformationStateUndefined::TransformationStateUndefined(TransformationStateCo
1111
{
1212
}
1313

14-
void TransformationStateUndefined::begin(CmdMediator &cmdMediator,
15-
const Transformation &transformation)
14+
void TransformationStateUndefined::begin(CmdMediator & /* cmdMediator */,
15+
const Transformation & /* transformation */)
1616
{
1717
LOG4CPP_INFO_S ((*mainCat)) << "TransformationStateUndefined::begin";
1818
}
1919

20-
void TransformationStateUndefined::end(CmdMediator &cmdMediator,
21-
const Transformation &transformation)
20+
void TransformationStateUndefined::end(CmdMediator & /* cmdMediator */,
21+
const Transformation & /* transformation */)
2222
{
2323
LOG4CPP_INFO_S ((*mainCat)) << "TransformationStateUndefined::end";
2424
}

src/engauge.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ SOURCES += main/main.cpp
241241
TARGET = ../bin/engauge
242242

243243
QT += core gui network printsupport widgets
244+
244245
LIBS += -llog4cpp -lfftw3
245246
INCLUDEPATH += Callback \
246247
Checker \

src/engauge.pro.user.mmitchell

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 3.0.1, 2015-01-09T22:15:51. -->
3+
<!-- Written by QtCreator 3.0.1, 2015-01-18T22:04:19. -->
44
<qtcreator>
55
<data>
66
<variable>ProjectExplorer.Project.ActiveTarget</variable>

src/img/bannerapp.xpm

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)