extmod/framebuf: Add the xstep!=0 case to scroll() method.
Adds horizontal scrolling. Right now, I'm just leaving the margins created by the scrolling as they were -- so they will repeat the edge of the framebuf. This is fast, and the user can always fill the margins themselves.
This commit is contained in:
parent
b4df3e74e1
commit
778729c597
|
@ -103,7 +103,7 @@ STATIC mp_obj_t framebuf1_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t y
|
||||||
mp_int_t xstep = mp_obj_get_int(xstep_in);
|
mp_int_t xstep = mp_obj_get_int(xstep_in);
|
||||||
mp_int_t ystep = mp_obj_get_int(ystep_in);
|
mp_int_t ystep = mp_obj_get_int(ystep_in);
|
||||||
int end = (self->height + 7) >> 3;
|
int end = (self->height + 7) >> 3;
|
||||||
if (xstep == 0 && ystep > 0) {
|
if (ystep > 0) {
|
||||||
for (int y = end; y > 0;) {
|
for (int y = end; y > 0;) {
|
||||||
--y;
|
--y;
|
||||||
for (int x = 0; x < self->width; ++x) {
|
for (int x = 0; x < self->width; ++x) {
|
||||||
|
@ -114,7 +114,7 @@ STATIC mp_obj_t framebuf1_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t y
|
||||||
self->buf[y * self->stride + x] = (self->buf[y * self->stride + x] << ystep) | prev;
|
self->buf[y * self->stride + x] = (self->buf[y * self->stride + x] << ystep) | prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (xstep == 0 && ystep < 0) {
|
} else if (ystep < 0) {
|
||||||
for (int y = 0; y < end; ++y) {
|
for (int y = 0; y < end; ++y) {
|
||||||
for (int x = 0; x < self->width; ++x) {
|
for (int x = 0; x < self->width; ++x) {
|
||||||
int prev = 0;
|
int prev = 0;
|
||||||
|
@ -125,7 +125,20 @@ STATIC mp_obj_t framebuf1_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO xstep!=0
|
if (xstep < 0) {
|
||||||
|
for (int y = 0; y < end; ++y) {
|
||||||
|
for (int x = 0; x < self->width + xstep; ++x) {
|
||||||
|
self->buf[y * self->stride + x] = self->buf[y * self->stride + x - xstep];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (xstep > 0) {
|
||||||
|
for (int y = 0; y < end; ++y) {
|
||||||
|
for (int x = self->width - 1; x >= xstep; --x) {
|
||||||
|
self->buf[y * self->stride + x] = self->buf[y * self->stride + x - xstep];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: Should we clear the margin created by scrolling?
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(framebuf1_scroll_obj, framebuf1_scroll);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_3(framebuf1_scroll_obj, framebuf1_scroll);
|
||||||
|
|
Loading…
Reference in New Issue