Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions dcs_lcd_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@
#include "dcs_lcd_color.h"
#include "font_data.h"

int dcs_lcd_find_max_line_len(const struct DCSLCDScreen *screen,
BaseDisplayItem items[], size_t items_len, int xpos, int ypos)
{
int line_len = screen->w - xpos;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];

if ((xpos < item->x) && (ypos >= item->y) && (ypos < item->y + item->height)) {
int len_to_item = item->x - xpos;
line_len = (line_len > len_to_item) ? len_to_item : line_len;
}
}

return line_len;
}

int dcs_lcd_draw_image_x(const struct DCSLCDScreen *screen,
int xpos, int ypos, int max_line_len, BaseDisplayItem *item)
{
Expand Down Expand Up @@ -201,10 +184,6 @@ int dcs_lcd_draw_scaled_cropped_img_x(const struct DCSLCDScreen *screen,
uint32_t *pixels = ((uint32_t *) data) + (source_y + ((ypos - y) / y_scale)) * img_width + source_x + ((xpos - x) / x_scale);
uint16_t *pixmem16 = (uint16_t *) (((uint8_t *) screen->pixels) + xpos * sizeof(uint16_t));

if (source_x + (width / x_scale) > img_width) {
width = (img_width - source_x) * x_scale;
}

if (width > xpos - x + max_line_len) {
width = xpos - x + max_line_len;
}
Expand Down Expand Up @@ -232,15 +211,26 @@ int dcs_lcd_draw_scaled_cropped_img_x(const struct DCSLCDScreen *screen,
int dcs_lcd_draw_x(const struct DCSLCDScreen *screen,
int xpos, int ypos, BaseDisplayItem items[], size_t items_len)
{
int line_len = screen->w - xpos;
bool below = false;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];
if ((xpos < item->x) || (xpos >= item->x + item->width) || (ypos < item->y) || (ypos >= item->y + item->height)) {
if ((ypos < item->y) || (ypos >= item->y + item->height)) {
continue;
}
if (xpos < item->x) {
int len_to_item = item->x - xpos;
if (len_to_item < line_len) {
line_len = len_to_item;
}
continue;
}
if (xpos >= item->x + item->width) {
continue;
}

int max_line_len = below ? 1 : dcs_lcd_find_max_line_len(screen, items, i, xpos, ypos);
int max_line_len = below ? 1 : line_len;

int drawn_pixels = 0;
switch (items[i].primitive) {
Expand Down
3 changes: 0 additions & 3 deletions dcs_lcd_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ int dcs_lcd_draw_text_x(const struct DCSLCDScreen *screen,
int dcs_lcd_draw_scaled_cropped_img_x(const struct DCSLCDScreen *screen,
int xpos, int ypos, int max_line_len, BaseDisplayItem *item);

int dcs_lcd_find_max_line_len(const struct DCSLCDScreen *screen,
BaseDisplayItem items[], size_t items_len, int xpos, int ypos);

int dcs_lcd_draw_x(const struct DCSLCDScreen *screen,
int xpos, int ypos, BaseDisplayItem items[], size_t items_len);

Expand Down
36 changes: 13 additions & 23 deletions epaper_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ void epaper_draw_pixel_x(const struct EpaperScreen *screen,
}
}

int epaper_find_max_line_len(const struct EpaperScreen *screen,
BaseDisplayItem items[], size_t items_len, int xpos, int ypos)
{
int line_len = screen->w - xpos;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];

if ((xpos < item->x) && (ypos >= item->y) && (ypos < item->y + item->height)) {
int len_to_item = item->x - xpos;
line_len = (line_len > len_to_item) ? len_to_item : line_len;
}
}

return line_len;
}

int epaper_draw_image_x(const struct EpaperScreen *screen,
uint8_t *line_buf, int xpos, int ypos, int max_line_len,
BaseDisplayItem *item)
Expand Down Expand Up @@ -259,10 +242,6 @@ int epaper_draw_scaled_cropped_img_x(const struct EpaperScreen *screen,

uint32_t *pixels = ((uint32_t *) data) + (source_y + ((ypos - y) / y_scale)) * img_width + source_x + ((xpos - x) / x_scale);

if (source_x + (width / x_scale) > img_width) {
width = (img_width - source_x) * x_scale;
}

if (width > xpos - x + max_line_len) {
width = xpos - x + max_line_len;
}
Expand Down Expand Up @@ -297,15 +276,26 @@ int epaper_draw_x(const struct EpaperScreen *screen,
uint8_t *line_buf, int xpos, int ypos,
BaseDisplayItem items[], size_t items_len)
{
int line_len = screen->w - xpos;
bool below = false;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];
if ((xpos < item->x) || (xpos >= item->x + item->width) || (ypos < item->y) || (ypos >= item->y + item->height)) {
if ((ypos < item->y) || (ypos >= item->y + item->height)) {
continue;
}
if (xpos < item->x) {
int len_to_item = item->x - xpos;
if (len_to_item < line_len) {
line_len = len_to_item;
}
continue;
}
if (xpos >= item->x + item->width) {
continue;
}

int max_line_len = below ? 1 : epaper_find_max_line_len(screen, items, i, xpos, ypos);
int max_line_len = below ? 1 : line_len;

int drawn_pixels = 0;
switch (items[i].primitive) {
Expand Down
3 changes: 0 additions & 3 deletions epaper_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ int epaper_draw_scaled_cropped_img_x(const struct EpaperScreen *screen,
uint8_t *line_buf, int xpos, int ypos, int max_line_len,
BaseDisplayItem *item);

int epaper_find_max_line_len(const struct EpaperScreen *screen,
BaseDisplayItem items[], size_t items_len, int xpos, int ypos);

int epaper_draw_x(const struct EpaperScreen *screen,
uint8_t *line_buf, int xpos, int ypos,
BaseDisplayItem items[], size_t items_len);
Expand Down
36 changes: 13 additions & 23 deletions mono_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,6 @@ void mono_draw_pixel_x(const struct MonoScreen *screen,
line_buf[xpos / 8] = (line_buf[xpos / 8] & ~(0x1 << bpos)) | (color << bpos);
}

int mono_find_max_line_len(const struct MonoScreen *screen,
BaseDisplayItem items[], size_t items_len, int xpos, int ypos)
{
int line_len = screen->w - xpos;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];

if ((xpos < item->x) && (ypos >= item->y) && (ypos < item->y + item->height)) {
int len_to_item = item->x - xpos;
line_len = (line_len > len_to_item) ? len_to_item : line_len;
}
}

return line_len;
}

int mono_draw_image_x(const struct MonoScreen *screen,
uint8_t *line_buf, int xpos, int ypos, int max_line_len,
BaseDisplayItem *item)
Expand Down Expand Up @@ -286,10 +269,6 @@ int mono_draw_scaled_cropped_img_x(const struct MonoScreen *screen,

uint32_t *pixels = ((uint32_t *) data) + (source_y + ((ypos - y) / y_scale)) * img_width + source_x + ((xpos - x) / x_scale);

if (source_x + (width / x_scale) > img_width) {
width = (img_width - source_x) * x_scale;
}

if (width > xpos - x + max_line_len) {
width = xpos - x + max_line_len;
}
Expand Down Expand Up @@ -322,15 +301,26 @@ int mono_draw_x(const struct MonoScreen *screen,
uint8_t *line_buf, int xpos, int ypos,
BaseDisplayItem items[], size_t items_len)
{
int line_len = screen->w - xpos;
bool below = false;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];
if ((xpos < item->x) || (xpos >= item->x + item->width) || (ypos < item->y) || (ypos >= item->y + item->height)) {
if ((ypos < item->y) || (ypos >= item->y + item->height)) {
continue;
}
if (xpos < item->x) {
int len_to_item = item->x - xpos;
if (len_to_item < line_len) {
line_len = len_to_item;
}
continue;
}
if (xpos >= item->x + item->width) {
continue;
}

int max_line_len = below ? 1 : mono_find_max_line_len(screen, items, i, xpos, ypos);
int max_line_len = below ? 1 : line_len;

int drawn_pixels = 0;
switch (items[i].primitive) {
Expand Down
3 changes: 0 additions & 3 deletions mono_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ int mono_draw_scaled_cropped_img_x(const struct MonoScreen *screen,
uint8_t *line_buf, int xpos, int ypos, int max_line_len,
BaseDisplayItem *item);

int mono_find_max_line_len(const struct MonoScreen *screen,
BaseDisplayItem items[], size_t items_len, int xpos, int ypos);

int mono_draw_x(const struct MonoScreen *screen,
uint8_t *line_buf, int xpos, int ypos,
BaseDisplayItem items[], size_t items_len);
Expand Down
33 changes: 12 additions & 21 deletions sdl_display/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,6 @@ static int draw_scaled_cropped_img_x(int xpos, int ypos, int max_line_len, BaseD
uint32_t *pixels = ((uint32_t *) data) + (source_y + ((ypos - y) / y_scale)) * img_width + source_x + ((xpos - x) / x_scale);
Uint32 *pixmem32 = (Uint32 *) (((uint8_t *) screen->pixels) + screen->w * ypos * BPP + xpos * BPP);

if (source_x + (width / x_scale) > img_width) {
width = (img_width - source_x) * x_scale;
}

if (width > xpos - x + max_line_len) {
width = xpos - x + max_line_len;
}
Expand Down Expand Up @@ -403,33 +399,28 @@ static int draw_text_x(int xpos, int ypos, int max_line_len, BaseDisplayItem *it
return drawn_pixels;
}

static int find_max_line_len(BaseDisplayItem items[], size_t items_len, int xpos, int ypos)
static int draw_x(int xpos, int ypos, BaseDisplayItem items[], size_t items_len)
{
int line_len = screen->w - xpos;
bool below = false;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];

if ((xpos < item->x) && (ypos >= item->y) && (ypos < item->y + item->height)) {
if ((ypos < item->y) || (ypos >= item->y + item->height)) {
continue;
}
if (xpos < item->x) {
int len_to_item = item->x - xpos;
line_len = (line_len > len_to_item) ? len_to_item : line_len;
if (len_to_item < line_len) {
line_len = len_to_item;
}
continue;
}
}

return line_len;
}

static int draw_x(int xpos, int ypos, BaseDisplayItem items[], size_t items_len)
{
bool below = false;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];
if ((xpos < item->x) || (xpos >= item->x + item->width) || (ypos < item->y) || (ypos >= item->y + item->height)) {
if (xpos >= item->x + item->width) {
continue;
}

int max_line_len = below ? 1 : find_max_line_len(items, i, xpos, ypos);
int max_line_len = below ? 1 : line_len;

int drawn_pixels = 0;
switch (items[i].primitive) {
Expand Down
Loading