Cosmetics

This commit is contained in:
3djc
2020-10-15 16:00:15 +02:00
parent dc747da1fa
commit 9d28df4aec
+107 -106
View File
@@ -264,86 +264,124 @@ void BitmapBuffer::drawFilledCircle(coord_t x, coord_t y, coord_t radius, LcdFla
} }
class Slope { class Slope {
public: public:
explicit Slope(int angle) { explicit Slope(int angle) {
if (angle < 0) if (angle < 0)
angle += 360; angle += 360;
if (angle > 360) if (angle > 360)
angle %= 360; angle %= 360;
float radians = float(angle) * (M_PI / 180.0f); float radians = float(angle) * (M_PI / 180.0f);
if (angle == 0) { if (angle == 0) {
left = false; left = false;
value = 100000; value = 100000;
}
else if (angle == 360) {
left = true;
value = 100000;
}
else if (angle >= 180) {
left = true;
value = -(cosf(radians) * 100 / sinf(radians));
}
else {
left = false;
value = (cosf(radians) * 100 / sinf(radians));
}
} }
else if (angle == 360) {
left = true;
value = 100000;
}
else if (angle >= 180) {
left = true;
value = -(cosf(radians) * 100 / sinf(radians));
}
else {
left = false;
value = (cosf(radians) * 100 / sinf(radians));
}
}
Slope(bool left, int value): Slope(bool left, int value):
left(left), left(left),
value(value) value(value)
{ {
} }
bool isBetween(const Slope & start, const Slope & end) const bool isBetween(const Slope & start, const Slope & end) const
{ {
if (left) { if (left) {
if (start.left) { if (start.left) {
if (end.left) if (end.left)
return end.value > start.value ? (value <= end.value && value >= start.value) : (value <= end.value || value >= start.value); return end.value > start.value ? (value <= end.value && value >= start.value) : (value <= end.value || value >= start.value);
else else
return value >= start.value; return value >= start.value;
}
else {
if (end.left)
return value <= end.value;
else
return end.value > start.value;
}
} }
else { else {
if (end.left) if (start.left) {
return value <= end.value; if (end.left)
else return start.value > end.value;
return end.value > start.value; else
return value >= end.value;
}
else {
if (end.left)
return value <= start.value;
else
return end.value < start.value ? (value >= end.value && value <= start.value) : (value <= start.value || value >= end.value);
}
} }
} }
else {
if (start.left) { Slope & invertVertical()
if (end.left) {
return start.value > end.value; value = -value;
else return *this;
return value >= end.value;
}
else {
if (end.left)
return value <= start.value;
else
return end.value < start.value ? (value >= end.value && value <= start.value) : (value <= start.value || value >= end.value);
}
} }
}
Slope & invertVertical() Slope & invertHorizontal()
{ {
value = -value; left = !left;
return *this; return *this;
} }
Slope & invertHorizontal() protected:
{ bool left;
left = !left; int value;
return *this;
}
protected:
bool left;
int value;
}; };
void BitmapBuffer::drawBitmapPatternPie(coord_t x, coord_t y, const uint8_t * img, LcdFlags flags, int startAngle, int endAngle)
{
if (endAngle == startAngle) {
endAngle += 1;
}
Slope startSlope(startAngle);
Slope endSlope(endAngle);
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
APPLY_OFFSET();
coord_t width = *((uint16_t *)img);
coord_t height = *(((uint16_t *)img) + 1);
const uint8_t * q = img + 4;
int w2 = width / 2;
int h2 = height / 2;
for (int y1 = h2 - 1; y1 >= 0; y1--) {
for (int x1 = w2 - 1; x1 >= 0; x1--) {
Slope slope(false, x1 == 0 ? 99000 : y1 * 100 / x1);
if (slope.isBetween(startSlope, endSlope)) {
drawAlphaPixel(x + w2 + x1, y + h2 - y1, q[(h2 - y1) * width + w2 + x1], color);
}
if (slope.invertVertical().isBetween(startSlope, endSlope)) {
drawAlphaPixel(x + w2 + x1, y + h2 + y1, q[(h2 + y1) * width + w2 + x1], color);
}
if (slope.invertHorizontal().isBetween(startSlope, endSlope)) {
drawAlphaPixel(x + w2 - x1, y + h2 + y1, q[(h2 + y1) * width + w2 - x1], color);
}
if (slope.invertVertical().isBetween(startSlope, endSlope)) {
drawAlphaPixel(x + w2 - x1, y + h2 - y1, q[(h2 - y1) * width + w2 - x1], color);
}
}
}
}
void BitmapBuffer::drawAnnulusSector(coord_t x, coord_t y, coord_t internalRadius, coord_t externalRadius, int startAngle, int endAngle, LcdFlags flags) void BitmapBuffer::drawAnnulusSector(coord_t x, coord_t y, coord_t internalRadius, coord_t externalRadius, int startAngle, int endAngle, LcdFlags flags)
{ {
if (endAngle == startAngle) { if (endAngle == startAngle) {
@@ -667,43 +705,6 @@ void drawSolidRect(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h
// } // }
//} //}
// //
void BitmapBuffer::drawBitmapPatternPie(coord_t x, coord_t y, const uint8_t * img, LcdFlags flags, int startAngle, int endAngle)
{
if (endAngle == startAngle) {
endAngle += 1;
}
Slope startSlope(startAngle);
Slope endSlope(endAngle);
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
APPLY_OFFSET();
coord_t width = *((uint16_t *)img);
coord_t height = *(((uint16_t *)img) + 1);
const uint8_t * q = img + 4;
int w2 = width / 2;
int h2 = height / 2;
for (int y1 = h2 - 1; y1 >= 0; y1--) {
for (int x1 = w2 - 1; x1 >= 0; x1--) {
Slope slope(false, x1 == 0 ? 99000 : y1 * 100 / x1);
if (slope.isBetween(startSlope, endSlope)) {
drawAlphaPixel(x + w2 + x1, y + h2 - y1, q[(h2 - y1) * width + w2 + x1], color);
}
if (slope.invertVertical().isBetween(startSlope, endSlope)) {
drawAlphaPixel(x + w2 + x1, y + h2 + y1, q[(h2 + y1) * width + w2 + x1], color);
}
if (slope.invertHorizontal().isBetween(startSlope, endSlope)) {
drawAlphaPixel(x + w2 - x1, y + h2 + y1, q[(h2 + y1) * width + w2 - x1], color);
}
if (slope.invertVertical().isBetween(startSlope, endSlope)) {
drawAlphaPixel(x + w2 - x1, y + h2 - y1, q[(h2 - y1) * width + w2 - x1], color);
}
}
}
}
BitmapBuffer * BitmapBuffer::loadBitmap(const char * filename) BitmapBuffer * BitmapBuffer::loadBitmap(const char * filename)
{ {
@@ -1046,9 +1047,9 @@ int stbc_eof(void *user)
// callbacks for stb-image // callbacks for stb-image
const stbi_io_callbacks stbCallbacks = { const stbi_io_callbacks stbCallbacks = {
stbc_read, stbc_read,
stbc_skip, stbc_skip,
stbc_eof stbc_eof
}; };
BitmapBuffer * BitmapBuffer::load_stb(const char * filename) BitmapBuffer * BitmapBuffer::load_stb(const char * filename)