Add feature

This commit is contained in:
3djc
2020-10-15 15:47:00 +02:00
parent 66253e1f7d
commit dc747da1fa
+123 -119
View File
@@ -195,23 +195,23 @@ void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, ui
} }
} }
// void BitmapBuffer::invertRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags att)
//void BitmapBuffer::invertRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags att) {
//{ APPLY_OFFSET();
// pixel_t color = lcdColorTable[COLOR_IDX(att)];
// RGB_SPLIT(color, red, green, blue); pixel_t color = lcdColorTable[COLOR_IDX(att)];
// RGB_SPLIT(color, red, green, blue);
// for (int i=y; i<y+h; i++) {
// pixel_t * p = getPixelPtr(x, i); for (int i = y; i < y + h; i++) {
// for (int j=0; j<w; j++) { pixel_t * p = getPixelPtr(x, i);
// // TODO ASSERT_IN_DISPLAY(p); for (int j = 0; j < w; j++) {
// RGB_SPLIT(*p, bgRed, bgGreen, bgBlue); // TODO ASSERT_IN_DISPLAY(p);
// drawPixel(p, RGB_JOIN(0x1F + red - bgRed, 0x3F + green - bgGreen, 0x1F + blue - bgBlue)); RGB_SPLIT(*p, bgRed, bgGreen, bgBlue);
// MOVE_TO_NEXT_RIGHT_PIXEL(p); drawPixel(p, RGB_JOIN(0x1F + red - bgRed, 0x3F + green - bgGreen, 0x1F + blue - bgBlue));
// } MOVE_TO_NEXT_RIGHT_PIXEL(p);
// } }
//} }
// }
void BitmapBuffer::drawCircle(coord_t x, coord_t y, coord_t radius, LcdFlags flags) void BitmapBuffer::drawCircle(coord_t x, coord_t y, coord_t radius, LcdFlags flags)
{ {
@@ -264,84 +264,84 @@ 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 (start.left) { if (end.left)
if (end.left) return value <= end.value;
return start.value > end.value; else
else return end.value > start.value;
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 {
Slope & invertVertical() if (start.left) {
{ if (end.left)
value = -value; return start.value > end.value;
return *this; 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);
}
} }
}
Slope & invertHorizontal() Slope & invertVertical()
{ {
left = !left; value = -value;
return *this; return *this;
} }
protected: Slope & invertHorizontal()
bool left; {
int value; left = !left;
return *this;
}
protected:
bool left;
int value;
}; };
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)
@@ -667,39 +667,43 @@ void drawSolidRect(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h
// } // }
//} //}
// //
//void BitmapBuffer::drawBitmapPatternPie(coord_t x0, coord_t y0, const uint8_t * img, LcdFlags flags, int startAngle, int endAngle) void BitmapBuffer::drawBitmapPatternPie(coord_t x, coord_t y, const uint8_t * img, LcdFlags flags, int startAngle, int endAngle)
//{ {
// coord_t width = *((uint16_t *)img); if (endAngle == startAngle) {
// coord_t height = *(((uint16_t *)img)+1); endAngle += 1;
// const uint8_t * q = img+4; }
//
// int slopes[4]; Slope startSlope(startAngle);
// if (!evalSlopes(slopes, startAngle, endAngle)) Slope endSlope(endAngle);
// return;
// pixel_t color = lcdColorTable[COLOR_IDX(flags)];
// pixel_t color = lcdColorTable[COLOR_IDX(flags)]; APPLY_OFFSET();
//
// int w2 = width/2; coord_t width = *((uint16_t *)img);
// int h2 = height/2; coord_t height = *(((uint16_t *)img) + 1);
// const uint8_t * q = img + 4;
// for (int y=h2-1; y>=0; y--) {
// for (int x=w2-1; x>=0; x--) { int w2 = width / 2;
// int slope = (x==0 ? (y<0 ? -99000 : 99000) : y*100/x); int h2 = height / 2;
// if (slope >= slopes[0] && slope < slopes[1]) {
// drawAlphaPixel(x0+w2+x, y0+h2-y, q[(h2-y)*width + w2+x], color); for (int y1 = h2 - 1; y1 >= 0; y1--) {
// } for (int x1 = w2 - 1; x1 >= 0; x1--) {
// if (-slope >= slopes[0] && -slope < slopes[1]) { Slope slope(false, x1 == 0 ? 99000 : y1 * 100 / x1);
// drawAlphaPixel(x0+w2+x, y0+h2+y, q[(h2+y)*width + w2+x], color); if (slope.isBetween(startSlope, endSlope)) {
// } drawAlphaPixel(x + w2 + x1, y + h2 - y1, q[(h2 - y1) * width + w2 + x1], color);
// if (slope >= slopes[2] && slope < slopes[3]) { }
// drawAlphaPixel(x0+w2-x, y0+h2-y, q[(h2-y)*width + w2-x], color); if (slope.invertVertical().isBetween(startSlope, endSlope)) {
// } drawAlphaPixel(x + w2 + x1, y + h2 + y1, q[(h2 + y1) * width + w2 + x1], color);
// if (-slope >= slopes[2] && -slope < slopes[3]) { }
// drawAlphaPixel(x0+w2-x, y0+h2+y, q[(h2+y)*width + w2-x], 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)
{ {
@@ -1042,9 +1046,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)