View difference between Paste ID: Fr02Jwb3 and WDkx7tFN
SHOW: | | - or go back to the newest paste.
1
2
void Window::draw(const TermBuffer& term_buffer) {
3
    auto& damaged_buf = term_buffer.get_damage_buffer();
4
5
    if (damaged_buf.empty()) {
6
        SDL_Delay(16);
7
        return;
8
    }
9
    cursor_pos_.x = 10;
10
    cursor_pos_.y = get_font_size().second / 2;
11
12
    decltype(auto) buffer = term_buffer.get_buffer();
13
    auto font_size = get_font_size();
14
    auto render_limit = get_window_size().second / get_font_size().second;
15
16-
    // std::cout << render_limit << std::endl;
16+
17
18
    for (auto i : damaged_buf) {
19
        if (i < scroll_offset_ || i >= scroll_offset_ + render_limit) continue;
20
    
21
        int row_index = i - scroll_offset_;
22
        int row_y = row_index * font_size.second;
23
        SDL_Rect row_rect{0, row_y, width_, font_size.second};
24
    
25
        SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 255);
26
        SDL_RenderFillRect(renderer_, &row_rect);
27
    
28
        cursor_pos_.x = 10;
29
        cursor_pos_.y = row_y;
30
    
31
        for (auto cell : buffer[i]) {
32
            if (cell.codepoint == 0) cell.codepoint = ' ';
33
            auto* atlas = glyph_cache_->atlas();
34
    
35
            SDL_Rect src = glyph_cache_->get_or_create_glyph_pos(renderer_, font_, cell.codepoint);
36
            SDL_Rect glyph_rect{cursor_pos_.x, cursor_pos_.y, src.w, src.h};
37
    
38
            SDL_SetTextureColorMod(atlas, cell.fg_color.r, cell.fg_color.g, cell.fg_color.b);
39
    
40
            if (cell.bg_color != SDL_Color{0, 0, 0, 255}) {
41
                SDL_SetRenderDrawColor(renderer_, cell.bg_color.r, cell.bg_color.g, cell.bg_color.b, cell.bg_color.a);
42
                SDL_RenderFillRect(renderer_, &glyph_rect);
43
                SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 255);
44
            }
45
    
46
            if (cell.is_underline()) {
47
                SDL_SetRenderDrawColor(renderer_, cell.fg_color.r, cell.fg_color.g, cell.fg_color.b, cell.fg_color.a);
48
                SDL_RenderDrawLine(renderer_, cursor_pos_.x, cursor_pos_.y + src.h - src.h / 5,
49
                                   cursor_pos_.x + src.w, cursor_pos_.y + src.h - src.h / 5);
50
            }
51
    
52
            if (cell.is_bold()) {
53
                SDL_SetTextureColorMod(atlas, 255, 255, 255);
54
            }
55
    
56
            if (cell.is_strikethrough()) {
57
                SDL_SetRenderDrawColor(renderer_, 255, 255, 255, 255);
58
                SDL_RenderDrawLine(renderer_, cursor_pos_.x, cursor_pos_.y + src.h / 2,
59
                                   cursor_pos_.x + src.w, cursor_pos_.y + src.h / 2);
60
            }
61
    
62
            SDL_RenderCopy(renderer_, atlas, &src, &glyph_rect);
63
            cursor_pos_.x += src.w;
64
        }
65
    }    
66
    // auto [cursor_x, cursor_y] = term_buffer.get_cursor_pos();
67
    
68
    SDL_Rect cursor_rect{cursor_pos_.x * font_size.first + font_size.first, (cursor_pos_.y - (int)scroll_offset_) * font_size.second + font_size.second / 2, 10, font_size.second};
69
    SDL_SetRenderDrawColor(renderer_, 255, 255, 255, 255);
70-
    // const auto& row = buffer[cursor_y];
70+
    SDL_RenderFillRect(renderer_, &cursor_rect);    
71-
    // SDL_Rect cursor_rect{cursor_x * font_size.first + font_size.first, (cursor_y - (int)scroll_offset_) * font_size.second + font_size.second / 2, 10, font_size.second};
71+
72-
    // SDL_SetRenderDrawColor(renderer_, 255, 255, 255, 255);
72+
73-
    // SDL_RenderFillRect(renderer_, &cursor_rect);    
73+
    SDL_SetRenderDrawColor(renderer_, 0,0,0,255);
74
    SDL_RenderClear(renderer_);
75
    SDL_Rect full = { 0, 0, width_, height_ };
76
    SDL_RenderCopy(renderer_, backbuffer_, &full, &full);
77-
        auto row = i - scroll_offset_;
77+
78-
        std::cout << row << std::endl;
78+
79-
        SDL_Rect row_rect {0, (int)row * font_size.second, width_, font_size.second};
79+
80-
        SDL_RenderCopy(renderer_, backbuffer_, &row_rect, &row_rect);
80+
81
    damaged_buf.clear();
82
}