Skip to content

Commit

Permalink
Try to implement alternative version of scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamos82 committed Jul 31, 2024
1 parent 000ddc0 commit 6207465
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/kernel/framebuffer/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,53 @@ void draw_logo(uint32_t start_x, uint32_t start_y) {
}
}

void _fb_scroll(_fb_window_t *scrolling_window, uint32_t line_height, uint32_t number_of_lines_to_scroll, _fb_window_t *area_to_pin) {
_fb_window_t rectangles[4];
uint32_t *framebuffer = (uint32_t *) framebuffer_data.address;
uint8_t n_rects = _fb_get_rectangles(rectangles, &framebuffer_main_window, area_to_pin);
uint32_t line_total_height = line_height * framebuffer_data.number_of_lines;
pretty_logf(Verbose, "Line total height: %d : %d", line_height, number_of_lines);
for (int i=0; i<n_rects; i++) {
uint32_t cur_x = rectangles[i].x_orig;
uint32_t cur_y = rectangles[i].y_orig;
size_t offset = (line_height*framebuffer_data.width);
uint32_t line_s = cur_y * framebuffer_data.width + cur_x;
uint32_t line_d = (line_s + number_of_lines_to_scroll * offset) + cur_x;
pretty_logf(Verbose, "line height: %d - offset: %d", line_height, offset);
pretty_logf(Verbose, "Updating rectangle: %d - cur_x: %d cur_y: %d line_s: %d line_d: %d", i, cur_x, cur_y, line_s, line_d);
while ( cur_y < (rectangles[i].y_orig + rectangles[i].height)) {
while (cur_x < (rectangles[i].x_orig + rectangles[i].width)) {
*((PIXEL*) framebuffer + (uint32_t)line_s) = *((PIXEL*) framebuffer + (uint32_t)line_d);
line_s++;
line_d++;
cur_x++;
}
cur_y++;
cur_x = rectangles[i].x_orig;
line_s += cur_x + area_to_pin->width;
line_d += cur_x + area_to_pin->width;
}
pretty_logf(Verbose, "cur_x: %d cur_y: %d", cur_x, cur_y);
}
}

void _fb_scrollLine(_fb_window_t *scrolling_window, uint32_t line_height, uint32_t number_of_lines_to_scroll, _fb_window_t *area_to_pin) {
uint32_t *framebuffer = (uint32_t *) framebuffer_data.address;
uint32_t cur_x = scrolling_window->x_orig;
uint32_t cur_y = scrolling_window->y_orig;
uint32_t line_s, line_d;
size_t offset = (line_height*scrolling_window->width);
line_s = scrolling_window->y_orig * framebuffer_data.pitch;
line_d = number_of_lines_to_scroll * offset;
line_s = scrolling_window->y_orig * framebuffer_data.width+ cur_x;
line_d = number_of_lines_to_scroll * offset + cur_x;
uint32_t line_total_height = line_height * number_of_lines;
bool to_ignore = false;
pretty_logf(Verbose, "scrolling_window width: %d - %d", scrolling_window->width, line_total_height);

while ( cur_y < (scrolling_window->height - line_total_height) ) {
while (cur_x < scrolling_window->width) {
to_ignore = _fb_intersect_window(cur_x, cur_y, area_to_pin);
if (area_to_pin != NULL) {
to_ignore = _fb_intersect_window(cur_x, cur_y, area_to_pin);
}
if (!to_ignore) {
*((PIXEL*) framebuffer + (uint32_t)line_s) = *((PIXEL*) framebuffer + (uint32_t)line_d);
}
Expand Down
3 changes: 3 additions & 0 deletions src/kernel/graphics/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
* @return true if the point (x,y) is within the rectangle specified by area_to_intersect
*/
bool _fb_intersect_window(uint32_t x, uint32_t y, _fb_window_t *area_to_intersect) {
if ( area_to_intersect == NULL ) {
return false;
}
if ( x > area_to_intersect->x_orig + area_to_intersect->width)
return false;
if ( x < area_to_intersect->x_orig)
Expand Down

0 comments on commit 6207465

Please sign in to comment.