Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement: glcd_draw_bitmap_area #8

Open
ghost opened this issue Feb 19, 2021 · 0 comments
Open

Implement: glcd_draw_bitmap_area #8

ghost opened this issue Feb 19, 2021 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 19, 2021

Description

A function to show icons anywhere on the screen.

Motivation

Be able to update icons anywhere on the display without fully refreshing display buffer. Useful for user interfaces with icons.

Status

Figured it's quite complex to calculate out the pixels in the buffer to update. @andygock do you know if there is perhaps a simpler more elegant approach to this ?

This the implementation I started, not complete:

const unsigned char data[] = {
     0x01, 0x00, 0xe0, 0xe0, 0x60, 0x60, 0x60, 0xfc, 0xfe, 0xe2, 0x02, 0x1e, 0x3c, 0x00, 0x00, 0x01, 
     0x80, 0x00, 0x0f, 0x0f, 0x0f, 0x0c, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
};
glcd_clear_buffer();
glcd_draw_bitmap_area(0, 0, 16, 16, data);
glcd_write();

void glcd_draw_bitmap_area(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const unsigned char *data)
{
	uint8_t i;

	if (y % 8 == 0) {
		for (i = 0; i < h / 8; i++) {
			memcpy(glcd_buffer_selected + x + i * GLCD_NUMBER_OF_COLS, data + i * w, w);
		}
	}
	else {
		for (i = 0; i < w; i++) {
			glcd_buffer_selected[i + x + (y / 8) * GLCD_NUMBER_OF_COLS] = data[i] & (uint8_t) (0xff << (y % 8));
			glcd_buffer_selected[i + x + (y / 8 + h / 8) * GLCD_NUMBER_OF_COLS] = data[i] & (0xff00 & (0x00ff << (y % 8))) >> 8;
		}
		if (h > 8)
			memcpy(glcd_buffer_selected + x + GLCD_NUMBER_OF_COLS, data + w, (w * h) - w);
	}

	glcd_bbox_reset();
	glcd_update_bbox(x, y, x + w - 1, y + h - 1);
}

Reporter

@silver-kuusik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants