SHOW:
|
|
- or go back to the newest paste.
| 1 | ||
| 2 | - | auto& damage_buffer = term_buffer.get_damage_buffer(); |
| 2 | + | |
| 3 | auto& damaged_buf = term_buffer.get_damage_buffer(); | |
| 4 | - | if (damage_buffer.empty()) {
|
| 4 | + | |
| 5 | if (damaged_buf.empty()) {
| |
| 6 | SDL_Delay(16); | |
| 7 | return; | |
| 8 | } | |
| 9 | - | for (auto i : damage_buffer) {
|
| 9 | + | |
| 10 | - | std::cout << i << " "; |
| 10 | + | |
| 11 | ||
| 12 | - | std::cout << std::endl; |
| 12 | + | |
| 13 | auto font_size = get_font_size(); | |
| 14 | ||
| 15 | auto render_limit = get_window_size().second / get_font_size().second; | |
| 16 | // std::cout << render_limit << std::endl; | |
| 17 | ||
| 18 | SDL_SetRenderTarget(renderer_, backbuffer_); | |
| 19 | - | if (SDL_SetRenderTarget(renderer_, backbuffer_) < 0) {
|
| 19 | + | |
| 20 | - | throw std::runtime_error("Hah");
|
| 20 | + | for (auto i : damaged_buf) {
|
| 21 | if (i < scroll_offset_ || i >= scroll_offset_ + render_limit) continue; | |
| 22 | ||
| 23 | int row_index = i - scroll_offset_; | |
| 24 | - | auto render_limit = get_window_size().second / font_size.second; // How many lines in the viewport |
| 24 | + | int row_y = row_index * font_size.second; |
| 25 | - | for (auto i = scroll_offset_; i < (scroll_offset_ + render_limit > buffer.size() ? buffer.size() : scroll_offset_ + render_limit); ++i) {
|
| 25 | + | SDL_Rect row_rect{0, row_y, width_, font_size.second};
|
| 26 | - | if (!damage_buffer.contains(i)) {
|
| 26 | + | |
| 27 | - | cursor_pos_.x = 10; |
| 27 | + | |
| 28 | - | cursor_pos_.y += font_size.second; |
| 28 | + | SDL_RenderFillRect(renderer_, &row_rect); |
| 29 | - | continue; |
| 29 | + | |
| 30 | cursor_pos_.x = 10; | |
| 31 | cursor_pos_.y = row_y; | |
| 32 | - | SDL_Rect row_dim{0, cursor_pos_.y, width_, font_size.second};
|
| 32 | + | |
| 33 | for (auto cell : buffer[i]) {
| |
| 34 | - | SDL_RenderFillRect(renderer_, &row_dim); // Clearing damaged row |
| 34 | + | |
| 35 | auto* atlas = glyph_cache_->atlas(); | |
| 36 | ||
| 37 | SDL_Rect src = glyph_cache_->get_or_create_glyph_pos(renderer_, font_, cell.codepoint); | |
| 38 | SDL_Rect glyph_rect{cursor_pos_.x, cursor_pos_.y, src.w, src.h};
| |
| 39 | - | |
| 39 | + | |
| 40 | SDL_SetTextureColorMod(atlas, cell.fg_color.r, cell.fg_color.g, cell.fg_color.b); | |
| 41 | ||
| 42 | if (cell.bg_color != SDL_Color{0, 0, 0, 255}) {
| |
| 43 | SDL_SetRenderDrawColor(renderer_, cell.bg_color.r, cell.bg_color.g, cell.bg_color.b, cell.bg_color.a); | |
| 44 | SDL_RenderFillRect(renderer_, &glyph_rect); | |
| 45 | - | if (cell.bg_color != SDL_Color{0, 0, 0, 255}) { // Default background
|
| 45 | + | |
| 46 | } | |
| 47 | - | SDL_Rect glyph_rect{ cursor_pos_.x, cursor_pos_.y, src.w, src.h};
|
| 47 | + | |
| 48 | if (cell.is_underline()) {
| |
| 49 | SDL_SetRenderDrawColor(renderer_, cell.fg_color.r, cell.fg_color.g, cell.fg_color.b, cell.fg_color.a); | |
| 50 | SDL_RenderDrawLine(renderer_, cursor_pos_.x, cursor_pos_.y + src.h - src.h / 5, | |
| 51 | cursor_pos_.x + src.w, cursor_pos_.y + src.h - src.h / 5); | |
| 52 | } | |
| 53 | ||
| 54 | - | SDL_RenderDrawLine(renderer_, cursor_pos_.x, cursor_pos_.y + src.h - src.h / 5, cursor_pos_.x + src.w, cursor_pos_.y + src.h - src.h / 5); |
| 54 | + | |
| 55 | SDL_SetTextureColorMod(atlas, 255, 255, 255); | |
| 56 | } | |
| 57 | ||
| 58 | if (cell.is_strikethrough()) {
| |
| 59 | SDL_SetRenderDrawColor(renderer_, 255, 255, 255, 255); | |
| 60 | SDL_RenderDrawLine(renderer_, cursor_pos_.x, cursor_pos_.y + src.h / 2, | |
| 61 | cursor_pos_.x + src.w, cursor_pos_.y + src.h / 2); | |
| 62 | } | |
| 63 | - | SDL_RenderDrawLine(renderer_, cursor_pos_.x, cursor_pos_.y + src.h / 2, cursor_pos_.x + src.w, cursor_pos_.y + src.h / 2); |
| 63 | + | |
| 64 | SDL_RenderCopy(renderer_, atlas, &src, &glyph_rect); | |
| 65 | cursor_pos_.x += src.w; | |
| 66 | } | |
| 67 | } | |
| 68 | // auto [cursor_x, cursor_y] = term_buffer.get_cursor_pos(); | |
| 69 | ||
| 70 | // const auto& row = buffer[cursor_y]; | |
| 71 | - | cursor_pos_.y += font_size.second; |
| 71 | + | |
| 72 | // SDL_SetRenderDrawColor(renderer_, 255, 255, 255, 255); | |
| 73 | // SDL_RenderFillRect(renderer_, &cursor_rect); | |
| 74 | ||
| 75 | SDL_SetRenderTarget(renderer_, nullptr); | |
| 76 | for (auto i : damaged_buf) {
| |
| 77 | auto row = i - scroll_offset_; | |
| 78 | std::cout << row << std::endl; | |
| 79 | SDL_Rect row_rect {0, (int)row * font_size.second, width_, font_size.second};
| |
| 80 | SDL_RenderCopy(renderer_, backbuffer_, &row_rect, &row_rect); | |
| 81 | } | |
| 82 | ||
| 83 | - | for (auto i : damage_buffer) {
|
| 83 | + | |
| 84 | - | SDL_Rect row_dim {0, static_cast<int>((i - scroll_offset_) * font_size.second), width_, font_size.second};
|
| 84 | + | |
| 85 | ||
| 86 | - | SDL_RenderCopy(renderer_, backbuffer_, &row_dim, &row_dim); |
| 86 | + | damaged_buf.clear(); |
| 87 | } |