mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 12:25:12 +03:00
Projectkk2glider/issue 4449 drawline (#4464)
* Gtest pattern changed * Fixes #4449: lcdDrawLine_line() was wrong for slanted lines [128x64] * Fixes #4449: lcdDrawLine_line() was wrong for slanted lines [480x272] * lcdDrawLine() coordinates check moved to Lua API
This commit is contained in:
parent
53f55f8e1d
commit
ee43d3fb97
7 changed files with 53 additions and 42 deletions
|
@ -636,28 +636,28 @@ void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, Lc
|
|||
if (dxabs >= dyabs) {
|
||||
/* the line is more horizontal than vertical */
|
||||
for (int i=0; i<=dxabs; i++) {
|
||||
if ((1<<(px%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
y += dyabs;
|
||||
if (y>=dxabs) {
|
||||
y -= dxabs;
|
||||
py += sdy;
|
||||
}
|
||||
if ((1<<(px%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
px += sdx;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* the line is more vertical than horizontal */
|
||||
for (int i=0; i<=dyabs; i++) {
|
||||
if ((1<<(py%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
x += dxabs;
|
||||
if (x >= dyabs) {
|
||||
x -= dyabs;
|
||||
px += sdx;
|
||||
}
|
||||
if ((1<<(py%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
py += sdy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -420,8 +420,6 @@ void lcdDrawSolidHorizontalLine(coord_t x, coord_t y, coord_t w, LcdFlags att)
|
|||
#if !defined(BOOT)
|
||||
void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att)
|
||||
{
|
||||
if (lcdIsPointOutside(x1, y1) || lcdIsPointOutside(x2, y2)) return;
|
||||
|
||||
int dx = x2-x1; /* the horizontal distance of the line */
|
||||
int dy = y2-y1; /* the vertical distance of the line */
|
||||
int dxabs = abs(dx);
|
||||
|
|
|
@ -192,28 +192,28 @@ void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, Lc
|
|||
if (dxabs >= dyabs) {
|
||||
/* the line is more horizontal than vertical */
|
||||
for (int i=0; i<=dxabs; i++) {
|
||||
if ((1<<(px%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
y += dyabs;
|
||||
if (y>=dxabs) {
|
||||
y -= dxabs;
|
||||
py += sdy;
|
||||
}
|
||||
if ((1<<(px%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
px += sdx;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* the line is more vertical than horizontal */
|
||||
for (int i=0; i<=dyabs; i++) {
|
||||
if ((1<<(py%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
x += dxabs;
|
||||
if (x >= dyabs) {
|
||||
x -= dyabs;
|
||||
px += sdx;
|
||||
}
|
||||
if ((1<<(py%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
py += sdy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,6 +106,9 @@ static int luaLcdDrawLine(lua_State *L)
|
|||
int pat = luaL_checkinteger(L, 5);
|
||||
int flags = luaL_checkinteger(L, 6);
|
||||
|
||||
if (x1 < 0 || x1 >= LCD_W || y1 < 0 || y1 >= LCD_H || x2 < 0 || x2 >= LCD_W || y2 < 0 || y2 >= LCD_H)
|
||||
return 0;
|
||||
|
||||
if (pat == SOLID) {
|
||||
if (x1 == x2) {
|
||||
lcdDrawSolidVerticalLine(x1, y2 >= y1 ? y1 : y1+1, y2 >= y1 ? y2-y1+1 : y2-y1-1, flags);
|
||||
|
|
|
@ -404,7 +404,24 @@ TEST(Lcd, lcdDrawBitmapLoadAndDisplay)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(PCBTARANIS) && LCD_W >= 212
|
||||
#if defined(PCBTARANIS)
|
||||
|
||||
void drawDiamond(int x, int y, int size)
|
||||
{
|
||||
int x1 = x - size;
|
||||
int x2 = x;
|
||||
int x3 = x + size;
|
||||
|
||||
int y1 = y - size;
|
||||
int y2 = y;
|
||||
int y3 = y + size;
|
||||
|
||||
lcdDrawLine( x1, y2, x2, y1, SOLID, FORCE);
|
||||
lcdDrawLine( x2, y1, x3, y2, SOLID, FORCE);
|
||||
lcdDrawLine( x3, y2, x2, y3, SOLID, FORCE);
|
||||
lcdDrawLine( x2, y3, x1, y2, SOLID, FORCE);
|
||||
}
|
||||
|
||||
TEST(Lcd, lcdDrawLine)
|
||||
{
|
||||
int start, length, xOffset;
|
||||
|
@ -412,60 +429,53 @@ TEST(Lcd, lcdDrawLine)
|
|||
|
||||
lcdClear();
|
||||
|
||||
start = 5;
|
||||
start = 2;
|
||||
pattern = SOLID;
|
||||
length = 40;
|
||||
xOffset = 0;
|
||||
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
|
||||
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
|
||||
|
||||
start = 10;
|
||||
start = 4;
|
||||
pattern = DOTTED;
|
||||
length = 40;
|
||||
xOffset = 0;
|
||||
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
|
||||
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
|
||||
|
||||
start = 55;
|
||||
start = 56;
|
||||
pattern = SOLID;
|
||||
length = -40;
|
||||
xOffset = 80;
|
||||
xOffset = 65;
|
||||
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
|
||||
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
|
||||
|
||||
start = 50;
|
||||
start = 54;
|
||||
pattern = DOTTED;
|
||||
length = -40;
|
||||
xOffset = 80;
|
||||
xOffset = 65;
|
||||
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
|
||||
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
|
||||
|
||||
// 45 deg lines
|
||||
lcdDrawLine( 35, 40, 45, 40, SOLID, FORCE );
|
||||
lcdDrawLine( 40, 35, 40, 45, SOLID, FORCE );
|
||||
lcdDrawLine( 25, 30, 35, 30, SOLID, FORCE );
|
||||
lcdDrawLine( 30, 25, 30, 35, SOLID, FORCE );
|
||||
|
||||
lcdDrawLine( 20, 40, 40, 20, SOLID, FORCE );
|
||||
lcdDrawLine( 40, 20, 60, 40, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 40, 40, 60, SOLID, FORCE );
|
||||
lcdDrawLine( 40, 60, 20, 40, SOLID, FORCE );
|
||||
|
||||
lcdDrawLine( 31, 39, 39, 31, SOLID, FORCE );
|
||||
lcdDrawLine( 41, 31, 49, 39, SOLID, FORCE );
|
||||
lcdDrawLine( 49, 41, 41, 49, SOLID, FORCE );
|
||||
lcdDrawLine( 39, 49, 31, 41, SOLID, FORCE );
|
||||
drawDiamond(30, 30, 10);
|
||||
drawDiamond(30, 30, 20);
|
||||
|
||||
// slanted lines
|
||||
lcdDrawLine( 150, 10, 190, 10, SOLID, FORCE );
|
||||
lcdDrawLine( 150, 10, 190, 20, SOLID, FORCE );
|
||||
lcdDrawLine( 150, 10, 190, 30, SOLID, FORCE );
|
||||
lcdDrawLine( 150, 10, 190, 40, SOLID, FORCE );
|
||||
lcdDrawLine( 150, 10, 190, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 100, 10, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 100, 20, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 100, 30, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 100, 40, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 100, 50, SOLID, FORCE );
|
||||
|
||||
lcdDrawLine( 150, 10, 190, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 150, 10, 180, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 150, 10, 170, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 150, 10, 160, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 150, 10, 150, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 100, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 90, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 80, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 70, 50, SOLID, FORCE );
|
||||
lcdDrawLine( 60, 10, 60, 50, SOLID, FORCE );
|
||||
|
||||
EXPECT_TRUE(checkScreenshot("lcdDrawLine"));
|
||||
}
|
||||
|
|
BIN
radio/src/tests/lcdDrawLine_128x64.png
Normal file
BIN
radio/src/tests/lcdDrawLine_128x64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 929 B |
Binary file not shown.
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
Loading…
Add table
Add a link
Reference in a new issue