LibGUI: Rework window rendering
Abstract drawing surface to Texture. All windows now contain a texture matching its size.
This commit is contained in:
parent
f78c7e7926
commit
f959905adf
|
@ -1,4 +1,5 @@
|
||||||
set(LIBGUI_SOURCES
|
set(LIBGUI_SOURCES
|
||||||
|
Texture.cpp
|
||||||
Window.cpp
|
Window.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#include "LibGUI/Window.h"
|
#include <LibGUI/Window.h>
|
||||||
|
|
||||||
#include <BAN/ScopeGuard.h>
|
#include <BAN/ScopeGuard.h>
|
||||||
|
|
||||||
#include <LibFont/Font.h>
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/banan-os.h>
|
#include <sys/banan-os.h>
|
||||||
|
@ -115,149 +113,13 @@ namespace LibGUI
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::fill_rect(int32_t x, int32_t y, uint32_t width, uint32_t height, uint32_t color)
|
|
||||||
{
|
|
||||||
if (!clamp_to_framebuffer(x, y, width, height))
|
|
||||||
return;
|
|
||||||
for (uint32_t y_off = 0; y_off < height; y_off++)
|
|
||||||
for (uint32_t x_off = 0; x_off < width; x_off++)
|
|
||||||
set_pixel(x + x_off, y + y_off, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::draw_character(uint32_t codepoint, const LibFont::Font& font, int32_t tl_x, int32_t tl_y, uint32_t color)
|
|
||||||
{
|
|
||||||
if (tl_y + (int32_t)font.height() < 0 || tl_y >= (int32_t)height())
|
|
||||||
return;
|
|
||||||
if (tl_x + (int32_t)font.width() < 0 || tl_x >= (int32_t)width())
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto glyph = font.glyph(codepoint);
|
|
||||||
if (glyph == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int32_t off_y = 0; off_y < (int32_t)font.height(); off_y++)
|
|
||||||
{
|
|
||||||
if (tl_y + off_y < 0)
|
|
||||||
continue;
|
|
||||||
uint32_t abs_y = tl_y + off_y;
|
|
||||||
if (abs_y >= height())
|
|
||||||
break;
|
|
||||||
for (int32_t off_x = 0; off_x < (int32_t)font.width(); off_x++)
|
|
||||||
{
|
|
||||||
if (tl_x + off_x < 0)
|
|
||||||
continue;
|
|
||||||
uint32_t abs_x = tl_x + off_x;
|
|
||||||
if (abs_x >= width())
|
|
||||||
break;
|
|
||||||
const uint8_t bitmask = 1 << (font.width() - off_x - 1);
|
|
||||||
if (glyph[off_y * font.pitch()] & bitmask)
|
|
||||||
set_pixel(abs_x, abs_y, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::draw_text(BAN::StringView text, const LibFont::Font& font, int32_t tl_x, int32_t tl_y, uint32_t color)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < text.size(); i++)
|
|
||||||
draw_character(text[i], font, tl_x + (int32_t)(i * font.width()), tl_y, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::shift_vertical(int32_t amount, uint32_t fill_color)
|
|
||||||
{
|
|
||||||
const uint32_t amount_abs = BAN::Math::abs(amount);
|
|
||||||
if (amount_abs == 0 || amount_abs >= height())
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint32_t* dst = (amount > 0) ? m_framebuffer.data() + width() * amount_abs : m_framebuffer.data();
|
|
||||||
uint32_t* src = (amount < 0) ? m_framebuffer.data() + width() * amount_abs : m_framebuffer.data();
|
|
||||||
memmove(dst, src, width() * (height() - amount_abs) * 4);
|
|
||||||
|
|
||||||
const uint32_t y_lo = (amount < 0) ? height() - amount_abs : 0;
|
|
||||||
const uint32_t y_hi = (amount < 0) ? height() : amount_abs;
|
|
||||||
for (uint32_t y = y_lo; y < y_hi; y++)
|
|
||||||
for (uint32_t x = 0; x < width(); x++)
|
|
||||||
set_pixel(x, y, fill_color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::copy_horizontal_slice(int32_t dst_y, int32_t src_y, uint32_t uamount, uint32_t fill_color)
|
|
||||||
{
|
|
||||||
int32_t amount = uamount;
|
|
||||||
if (dst_y < 0)
|
|
||||||
{
|
|
||||||
amount -= -dst_y;
|
|
||||||
src_y += -dst_y;
|
|
||||||
dst_y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
amount = BAN::Math::min<int32_t>(amount, height() - dst_y);
|
|
||||||
if (amount <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const int32_t copy_src_y = BAN::Math::clamp<int32_t>(src_y, 0, height());
|
|
||||||
const int32_t copy_amount = BAN::Math::clamp<int32_t>(src_y + amount, 0, height()) - copy_src_y;
|
|
||||||
if (copy_amount > 0)
|
|
||||||
{
|
|
||||||
memmove(
|
|
||||||
&m_framebuffer[width() * (dst_y + (copy_src_y - src_y))],
|
|
||||||
&m_framebuffer[width() * copy_src_y],
|
|
||||||
copy_amount * width() * 4
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint32_t fill_y_off = (src_y < copy_src_y) ? 0 : copy_amount;
|
|
||||||
const uint32_t fill_amount = amount - copy_amount;
|
|
||||||
for (uint32_t i = 0; i < fill_amount; i++)
|
|
||||||
for (uint32_t x = 0; x < width(); x++)
|
|
||||||
set_pixel(x, dst_y + fill_y_off + i, fill_color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::copy_rect(int32_t dst_x, int32_t dst_y, int32_t src_x, int32_t src_y, uint32_t width, uint32_t height, uint32_t fill_color)
|
|
||||||
{
|
|
||||||
fill_rect(dst_x, dst_y, width, height, fill_color);
|
|
||||||
|
|
||||||
if (!clamp_to_framebuffer(dst_x, dst_y, width, height))
|
|
||||||
return;
|
|
||||||
if (!clamp_to_framebuffer(src_x, src_y, width, height))
|
|
||||||
return;
|
|
||||||
|
|
||||||
const bool copy_dir = dst_y < src_y;
|
|
||||||
for (uint32_t i = 0; i < height; i++)
|
|
||||||
{
|
|
||||||
const uint32_t y_off = copy_dir ? i : height - i - 1;
|
|
||||||
memmove(
|
|
||||||
&m_framebuffer[(dst_y + y_off) * this->width()],
|
|
||||||
&m_framebuffer[(src_y + y_off) * this->width()],
|
|
||||||
width * 4
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Window::clamp_to_framebuffer(int32_t& signed_x, int32_t& signed_y, uint32_t& width, uint32_t& height) const
|
|
||||||
{
|
|
||||||
int32_t min_x = BAN::Math::max<int32_t>(signed_x, 0);
|
|
||||||
int32_t min_y = BAN::Math::max<int32_t>(signed_y, 0);
|
|
||||||
int32_t max_x = BAN::Math::min<int32_t>(this->width(), signed_x + (int32_t)width);
|
|
||||||
int32_t max_y = BAN::Math::min<int32_t>(this->height(), signed_y + (int32_t)height);
|
|
||||||
|
|
||||||
if (min_x >= max_x)
|
|
||||||
return false;
|
|
||||||
if (min_y >= max_y)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
signed_x = min_x;
|
|
||||||
signed_y = min_y;
|
|
||||||
width = max_x - min_x;
|
|
||||||
height = max_y - min_y;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::invalidate(int32_t x, int32_t y, uint32_t width, uint32_t height)
|
void Window::invalidate(int32_t x, int32_t y, uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
if (!clamp_to_framebuffer(x, y, width, height))
|
if (!m_texture.clamp_to_texture(x, y, width, height))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < height; i++)
|
for (uint32_t i = 0; i < height; i++)
|
||||||
memcpy(&m_framebuffer_smo[(y + i) * m_width + x], &m_framebuffer[(y + i) * m_width + x], width * sizeof(uint32_t));
|
memcpy(&m_framebuffer_smo[(y + i) * m_width + x], &m_texture.pixels()[(y + i) * m_width + x], width * sizeof(uint32_t));
|
||||||
|
|
||||||
WindowPacket::WindowInvalidate packet;
|
WindowPacket::WindowInvalidate packet;
|
||||||
packet.x = x;
|
packet.x = x;
|
||||||
|
@ -364,21 +226,13 @@ namespace LibGUI
|
||||||
munmap(m_framebuffer_smo, m_width * m_height * 4);
|
munmap(m_framebuffer_smo, m_width * m_height * 4);
|
||||||
m_framebuffer_smo = nullptr;
|
m_framebuffer_smo = nullptr;
|
||||||
|
|
||||||
BAN::Vector<uint32_t> framebuffer;
|
TRY(m_texture.resize(event.width, event.height));
|
||||||
TRY(framebuffer.resize(event.width * event.height, m_bg_color));
|
|
||||||
|
|
||||||
void* framebuffer_addr = smo_map(event.smo_key);
|
void* framebuffer_addr = smo_map(event.smo_key);
|
||||||
if (framebuffer_addr == nullptr)
|
if (framebuffer_addr == nullptr)
|
||||||
return BAN::Error::from_errno(errno);
|
return BAN::Error::from_errno(errno);
|
||||||
|
|
||||||
const uint32_t min_x = BAN::Math::min(m_width, event.width);
|
|
||||||
const uint32_t min_y = BAN::Math::min(m_height, event.height);
|
|
||||||
for (uint32_t y = 0; y < min_y; y++)
|
|
||||||
for (uint32_t x = 0; x < min_x; x++)
|
|
||||||
framebuffer[y * event.width + x] = m_framebuffer[y * m_width + x];
|
|
||||||
|
|
||||||
m_framebuffer_smo = static_cast<uint32_t*>(framebuffer_addr);
|
m_framebuffer_smo = static_cast<uint32_t*>(framebuffer_addr);
|
||||||
m_framebuffer = BAN::move(framebuffer);
|
|
||||||
m_width = event.width;
|
m_width = event.width;
|
||||||
m_height = event.height;
|
m_height = event.height;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <BAN/UniqPtr.h>
|
#include <BAN/UniqPtr.h>
|
||||||
|
|
||||||
#include <LibGUI/Packet.h>
|
#include <LibGUI/Packet.h>
|
||||||
|
#include <LibGUI/Texture.h>
|
||||||
|
|
||||||
namespace LibFont { class Font; }
|
namespace LibFont { class Font; }
|
||||||
|
|
||||||
|
@ -30,39 +31,8 @@ namespace LibGUI
|
||||||
|
|
||||||
static BAN::ErrorOr<BAN::UniqPtr<Window>> create(uint32_t width, uint32_t height, BAN::StringView title, Attributes attributes = default_attributes);
|
static BAN::ErrorOr<BAN::UniqPtr<Window>> create(uint32_t width, uint32_t height, BAN::StringView title, Attributes attributes = default_attributes);
|
||||||
|
|
||||||
void set_pixel(uint32_t x, uint32_t y, uint32_t color)
|
Texture& texture() { return m_texture; }
|
||||||
{
|
const Texture& texture() const { return m_texture; }
|
||||||
ASSERT(x < m_width);
|
|
||||||
ASSERT(y < m_height);
|
|
||||||
m_framebuffer[y * m_width + x] = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t get_pixel(uint32_t x, uint32_t y) const
|
|
||||||
{
|
|
||||||
ASSERT(x < m_width);
|
|
||||||
ASSERT(y < m_height);
|
|
||||||
return m_framebuffer[y * m_width + x];
|
|
||||||
}
|
|
||||||
|
|
||||||
BAN::Span<uint32_t> pixels() { return m_framebuffer.span(); }
|
|
||||||
|
|
||||||
void fill_rect(int32_t x, int32_t y, uint32_t width, uint32_t height, uint32_t color);
|
|
||||||
void fill(uint32_t color) { return fill_rect(0, 0, width(), height(), color); }
|
|
||||||
|
|
||||||
void draw_character(uint32_t codepoint, const LibFont::Font& font, int32_t x, int32_t y, uint32_t color);
|
|
||||||
void draw_text(BAN::StringView text, const LibFont::Font& font, int32_t x, int32_t y, uint32_t color);
|
|
||||||
|
|
||||||
// shift whole vertically by amount pixels, sign determines the direction
|
|
||||||
// fill_color is used to fill "new" data
|
|
||||||
void shift_vertical(int32_t amount, uint32_t fill_color);
|
|
||||||
|
|
||||||
// copy horizontal slice [src_y, src_y + amount[ to [dst_y, dst_y + amount[
|
|
||||||
// fill_color is used when copying data outside of window bounds
|
|
||||||
void copy_horizontal_slice(int32_t dst_y, int32_t src_y, uint32_t amount, uint32_t fill_color);
|
|
||||||
|
|
||||||
// copy rect (src_x, src_y, width, height) to (dst_x, dst_y, width, height)
|
|
||||||
// fill_color is used when copying data outside of window bounds
|
|
||||||
void copy_rect(int32_t dst_x, int32_t dst_y, int32_t src_x, int32_t src_y, uint32_t width, uint32_t height, uint32_t fill_color);
|
|
||||||
|
|
||||||
void invalidate(int32_t x, int32_t y, uint32_t width, uint32_t height);
|
void invalidate(int32_t x, int32_t y, uint32_t width, uint32_t height);
|
||||||
void invalidate() { return invalidate(0, 0, width(), height()); }
|
void invalidate() { return invalidate(0, 0, width(), height()); }
|
||||||
|
@ -85,9 +55,6 @@ namespace LibGUI
|
||||||
uint32_t width() const { return m_width; }
|
uint32_t width() const { return m_width; }
|
||||||
uint32_t height() const { return m_height; }
|
uint32_t height() const { return m_height; }
|
||||||
|
|
||||||
// used on resize to fill empty space
|
|
||||||
void set_bg_color(uint32_t bg_color) { m_bg_color = bg_color; }
|
|
||||||
|
|
||||||
void wait_events();
|
void wait_events();
|
||||||
void poll_events();
|
void poll_events();
|
||||||
|
|
||||||
|
@ -107,8 +74,6 @@ namespace LibGUI
|
||||||
, m_attributes(attributes)
|
, m_attributes(attributes)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool clamp_to_framebuffer(int32_t& x, int32_t& y, uint32_t& width, uint32_t& height) const;
|
|
||||||
|
|
||||||
void on_socket_error(BAN::StringView function);
|
void on_socket_error(BAN::StringView function);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
|
@ -121,12 +86,11 @@ namespace LibGUI
|
||||||
|
|
||||||
Attributes m_attributes;
|
Attributes m_attributes;
|
||||||
|
|
||||||
BAN::Vector<uint32_t> m_framebuffer;
|
|
||||||
uint32_t* m_framebuffer_smo { nullptr };
|
uint32_t* m_framebuffer_smo { nullptr };
|
||||||
uint32_t m_width { 0 };
|
uint32_t m_width { 0 };
|
||||||
uint32_t m_height { 0 };
|
uint32_t m_height { 0 };
|
||||||
|
|
||||||
uint32_t m_bg_color { 0xFFFFFFFF };
|
Texture m_texture;
|
||||||
|
|
||||||
BAN::Function<void()> m_socket_error_callback;
|
BAN::Function<void()> m_socket_error_callback;
|
||||||
BAN::Function<void()> m_close_window_event_callback;
|
BAN::Function<void()> m_close_window_event_callback;
|
||||||
|
|
|
@ -90,7 +90,7 @@ int main()
|
||||||
|
|
||||||
window->set_position(0, 0);
|
window->set_position(0, 0);
|
||||||
|
|
||||||
window->fill(bg_color);
|
window->texture().fill(bg_color);
|
||||||
window->invalidate();
|
window->invalidate();
|
||||||
|
|
||||||
bool is_running = true;
|
bool is_running = true;
|
||||||
|
@ -108,8 +108,9 @@ int main()
|
||||||
const uint32_t text_x = window->width() - text_w - padding;
|
const uint32_t text_x = window->width() - text_w - padding;
|
||||||
const uint32_t text_y = padding;
|
const uint32_t text_y = padding;
|
||||||
|
|
||||||
window->fill_rect(text_x, text_y, text_w, text_h, bg_color);
|
auto& texture = window->texture();
|
||||||
window->draw_text(text, font, text_x, text_y, fg_color);
|
texture.fill_rect(text_x, text_y, text_w, text_h, bg_color);
|
||||||
|
texture.draw_text(text, font, text_x, text_y, fg_color);
|
||||||
window->invalidate(text_x, text_y, text_w, text_h);
|
window->invalidate(text_x, text_y, text_w, text_h);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -119,9 +119,9 @@ void Terminal::run()
|
||||||
attributes.resizable = true;
|
attributes.resizable = true;
|
||||||
|
|
||||||
m_window = MUST(LibGUI::Window::create(600, 400, "Terminal"_sv, attributes));
|
m_window = MUST(LibGUI::Window::create(600, 400, "Terminal"_sv, attributes));
|
||||||
m_window->fill(m_bg_color);
|
m_window->texture().fill(m_bg_color);
|
||||||
|
m_window->texture().set_bg_color(m_bg_color);
|
||||||
m_window->invalidate();
|
m_window->invalidate();
|
||||||
m_window->set_bg_color(m_bg_color);
|
|
||||||
|
|
||||||
m_font = MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"_sv));
|
m_font = MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"_sv));
|
||||||
|
|
||||||
|
@ -149,13 +149,13 @@ void Terminal::run()
|
||||||
m_window->set_resize_window_event_callback([&] {
|
m_window->set_resize_window_event_callback([&] {
|
||||||
if (const auto rem = m_window->height() % m_font.height())
|
if (const auto rem = m_window->height() % m_font.height())
|
||||||
{
|
{
|
||||||
m_window->fill_rect(0, m_window->height() - rem, m_window->width(), rem, m_bg_color);
|
m_window->texture().fill_rect(0, m_window->height() - rem, m_window->width(), rem, m_bg_color);
|
||||||
m_window->invalidate(0, m_window->height() - rem, m_window->width(), rem);
|
m_window->invalidate(0, m_window->height() - rem, m_window->width(), rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto rem = m_window->width() % m_font.width())
|
if (const auto rem = m_window->width() % m_font.width())
|
||||||
{
|
{
|
||||||
m_window->fill_rect(m_window->width() - rem, 0, rem, m_window->height(), m_bg_color);
|
m_window->texture().fill_rect(m_window->width() - rem, 0, rem, m_window->height(), m_bg_color);
|
||||||
m_window->invalidate(m_window->width() - rem, 0, rem, m_window->height());
|
m_window->invalidate(m_window->width() - rem, 0, rem, m_window->height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,11 +235,12 @@ void Terminal::hide_cursor()
|
||||||
{
|
{
|
||||||
if (m_cursor.x == cols())
|
if (m_cursor.x == cols())
|
||||||
return;
|
return;
|
||||||
|
auto& texture = m_window->texture();
|
||||||
const uint32_t cursor_base_x = m_cursor.x * m_font.width();
|
const uint32_t cursor_base_x = m_cursor.x * m_font.width();
|
||||||
const uint32_t cursor_base_y = m_cursor.y * m_font.height();
|
const uint32_t cursor_base_y = m_cursor.y * m_font.height();
|
||||||
for (uint32_t y = 0; y < m_font.height(); y++)
|
for (uint32_t y = 0; y < m_font.height(); y++)
|
||||||
for (uint32_t x = 0; x < m_font.width(); x++)
|
for (uint32_t x = 0; x < m_font.width(); x++)
|
||||||
m_window->set_pixel(cursor_base_x + x, cursor_base_y + y, m_cursor_buffer[y * m_font.width() + x]);
|
texture.set_pixel(cursor_base_x + x, cursor_base_y + y, m_cursor_buffer[y * m_font.width() + x]);
|
||||||
m_window->invalidate(cursor_base_x, cursor_base_y, m_font.width(), m_font.height());
|
m_window->invalidate(cursor_base_x, cursor_base_y, m_font.width(), m_font.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,16 +248,17 @@ void Terminal::show_cursor()
|
||||||
{
|
{
|
||||||
if (m_cursor.x == cols())
|
if (m_cursor.x == cols())
|
||||||
return;
|
return;
|
||||||
|
auto& texture = m_window->texture();
|
||||||
const uint32_t cursor_base_x = m_cursor.x * m_font.width();
|
const uint32_t cursor_base_x = m_cursor.x * m_font.width();
|
||||||
const uint32_t cursor_base_y = m_cursor.y * m_font.height();
|
const uint32_t cursor_base_y = m_cursor.y * m_font.height();
|
||||||
for (uint32_t y = 0; y < m_font.height(); y++)
|
for (uint32_t y = 0; y < m_font.height(); y++)
|
||||||
for (uint32_t x = 0; x < m_font.width(); x++)
|
for (uint32_t x = 0; x < m_font.width(); x++)
|
||||||
m_cursor_buffer[y * m_font.width() + x] = m_window->get_pixel(cursor_base_x + x, cursor_base_y + y);
|
m_cursor_buffer[y * m_font.width() + x] = texture.get_pixel(cursor_base_x + x, cursor_base_y + y);
|
||||||
if (m_cursor_shown && m_cursor_blink_shown)
|
if (m_cursor_shown && m_cursor_blink_shown)
|
||||||
{
|
{
|
||||||
for (uint32_t y = m_font.height() * 13 / 16; y < m_font.height() - 1; y++)
|
for (uint32_t y = m_font.height() * 13 / 16; y < m_font.height() - 1; y++)
|
||||||
for (uint32_t x = 0; x < m_font.width(); x++)
|
for (uint32_t x = 0; x < m_font.width(); x++)
|
||||||
m_window->set_pixel(cursor_base_x + x, cursor_base_y + y, 0xFFFFFFFF);
|
texture.set_pixel(cursor_base_x + x, cursor_base_y + y, 0xFFFFFFFF);
|
||||||
m_window->invalidate(cursor_base_x, cursor_base_y, m_font.width(), m_font.height());
|
m_window->invalidate(cursor_base_x, cursor_base_y, m_font.width(), m_font.height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,7 +308,7 @@ bool Terminal::read_shell()
|
||||||
{
|
{
|
||||||
const uint32_t scroll = m_cursor.y + newline_count - rows() + 1;
|
const uint32_t scroll = m_cursor.y + newline_count - rows() + 1;
|
||||||
m_cursor.y -= scroll;
|
m_cursor.y -= scroll;
|
||||||
m_window->shift_vertical(-scroll * (int32_t)m_font.height(), m_bg_color);
|
m_window->texture().shift_vertical(-scroll * (int32_t)m_font.height(), m_bg_color);
|
||||||
should_invalidate = { 0, 0, m_window->width(), m_window->height() };
|
should_invalidate = { 0, 0, m_window->width(), m_window->height() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,6 +436,8 @@ Rectangle Terminal::handle_csi(char ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle should_invalidate;
|
Rectangle should_invalidate;
|
||||||
|
|
||||||
|
auto& texture = m_window->texture();
|
||||||
switch (ch)
|
switch (ch)
|
||||||
{
|
{
|
||||||
case 'A':
|
case 'A':
|
||||||
|
@ -508,7 +512,7 @@ Rectangle Terminal::handle_csi(char ch)
|
||||||
|
|
||||||
for (size_t i = 0; i < rect_count; i++)
|
for (size_t i = 0; i < rect_count; i++)
|
||||||
{
|
{
|
||||||
m_window->fill_rect(rects[i].x, rects[i].y, rects[i].width, rects[i].height, m_bg_color);
|
texture.fill_rect(rects[i].x, rects[i].y, rects[i].width, rects[i].height, m_bg_color);
|
||||||
should_invalidate = should_invalidate.get_bounding_box(rects[i]);
|
should_invalidate = should_invalidate.get_bounding_box(rects[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,7 +528,7 @@ Rectangle Terminal::handle_csi(char ch)
|
||||||
rect.width = (m_csi_info.fields[0] == 1) ? m_cursor.x * m_font.width() : m_window->width() - rect.x;
|
rect.width = (m_csi_info.fields[0] == 1) ? m_cursor.x * m_font.width() : m_window->width() - rect.x;
|
||||||
rect.height = m_font.height();
|
rect.height = m_font.height();
|
||||||
|
|
||||||
m_window->fill_rect(rect.x, rect.y, rect.width, rect.height, m_bg_color);
|
texture.fill_rect(rect.x, rect.y, rect.width, rect.height, m_bg_color);
|
||||||
should_invalidate = rect;
|
should_invalidate = rect;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -535,8 +539,8 @@ Rectangle Terminal::handle_csi(char ch)
|
||||||
const uint32_t src_y = m_cursor.y * m_font.height();
|
const uint32_t src_y = m_cursor.y * m_font.height();
|
||||||
const uint32_t dst_y = src_y + count * m_font.height();
|
const uint32_t dst_y = src_y + count * m_font.height();
|
||||||
|
|
||||||
m_window->copy_horizontal_slice(dst_y, src_y, m_window->height() - dst_y, m_bg_color);
|
texture.copy_horizontal_slice(dst_y, src_y, m_window->height() - dst_y, m_bg_color);
|
||||||
m_window->fill_rect(0, src_y, m_window->width(), count * m_font.height(), m_bg_color);
|
texture.fill_rect(0, src_y, m_window->width(), count * m_font.height(), m_bg_color);
|
||||||
should_invalidate = {
|
should_invalidate = {
|
||||||
0,
|
0,
|
||||||
src_y,
|
src_y,
|
||||||
|
@ -552,8 +556,8 @@ Rectangle Terminal::handle_csi(char ch)
|
||||||
const uint32_t dst_y = m_cursor.y * m_font.height();
|
const uint32_t dst_y = m_cursor.y * m_font.height();
|
||||||
const uint32_t src_y = dst_y + count * m_font.height();
|
const uint32_t src_y = dst_y + count * m_font.height();
|
||||||
|
|
||||||
m_window->copy_horizontal_slice(dst_y, src_y, m_window->height() - dst_y, m_bg_color);
|
texture.copy_horizontal_slice(dst_y, src_y, m_window->height() - dst_y, m_bg_color);
|
||||||
m_window->fill_rect(0, m_window->height() - count * m_font.height(), m_window->width(), count * m_font.height(), m_bg_color);
|
texture.fill_rect(0, m_window->height() - count * m_font.height(), m_window->width(), count * m_font.height(), m_bg_color);
|
||||||
should_invalidate = {
|
should_invalidate = {
|
||||||
0,
|
0,
|
||||||
src_y,
|
src_y,
|
||||||
|
@ -570,8 +574,8 @@ Rectangle Terminal::handle_csi(char ch)
|
||||||
const uint32_t src_x = m_cursor.x * m_font.width();
|
const uint32_t src_x = m_cursor.x * m_font.width();
|
||||||
const uint32_t y = m_cursor.y * m_font.height();
|
const uint32_t y = m_cursor.y * m_font.height();
|
||||||
|
|
||||||
m_window->copy_rect(dst_x, y, src_x, y, m_window->width() - dst_x, m_font.height(), m_bg_color);
|
texture.copy_rect(dst_x, y, src_x, y, m_window->width() - dst_x, m_font.height(), m_bg_color);
|
||||||
m_window->fill_rect(src_x, y, count * m_font.width(), m_font.height(), m_bg_color);
|
texture.fill_rect(src_x, y, count * m_font.width(), m_font.height(), m_bg_color);
|
||||||
should_invalidate = {
|
should_invalidate = {
|
||||||
src_x,
|
src_x,
|
||||||
y,
|
y,
|
||||||
|
@ -647,6 +651,7 @@ Rectangle Terminal::putcodepoint(uint32_t codepoint)
|
||||||
{
|
{
|
||||||
Rectangle should_invalidate;
|
Rectangle should_invalidate;
|
||||||
|
|
||||||
|
auto& texture = m_window->texture();
|
||||||
switch (codepoint)
|
switch (codepoint)
|
||||||
{
|
{
|
||||||
case '\e':
|
case '\e':
|
||||||
|
@ -675,7 +680,7 @@ Rectangle Terminal::putcodepoint(uint32_t codepoint)
|
||||||
{
|
{
|
||||||
const uint32_t scroll = m_cursor.y - rows() + 1;
|
const uint32_t scroll = m_cursor.y - rows() + 1;
|
||||||
m_cursor.y -= scroll;
|
m_cursor.y -= scroll;
|
||||||
m_window->shift_vertical(-scroll * (int32_t)m_font.height(), m_bg_color);
|
texture.shift_vertical(-scroll * (int32_t)m_font.height(), m_bg_color);
|
||||||
should_invalidate = { 0, 0, m_window->width(), m_window->height() };
|
should_invalidate = { 0, 0, m_window->width(), m_window->height() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -687,8 +692,8 @@ Rectangle Terminal::putcodepoint(uint32_t codepoint)
|
||||||
const auto fg_color = m_colors_inverted ? m_bg_color : m_fg_color;
|
const auto fg_color = m_colors_inverted ? m_bg_color : m_fg_color;
|
||||||
const auto bg_color = m_colors_inverted ? m_fg_color : m_bg_color;
|
const auto bg_color = m_colors_inverted ? m_fg_color : m_bg_color;
|
||||||
|
|
||||||
m_window->fill_rect(cell_x, cell_y, cell_w, cell_h, bg_color);
|
texture.fill_rect(cell_x, cell_y, cell_w, cell_h, bg_color);
|
||||||
m_window->draw_character(codepoint, m_font, cell_x, cell_y, fg_color);
|
texture.draw_character(codepoint, m_font, cell_x, cell_y, fg_color);
|
||||||
m_last_graphic_char = codepoint;
|
m_last_graphic_char = codepoint;
|
||||||
should_invalidate = { cell_x, cell_y, cell_w, cell_h };
|
should_invalidate = { cell_x, cell_y, cell_w, cell_h };
|
||||||
m_cursor.x++;
|
m_cursor.x++;
|
||||||
|
@ -700,7 +705,7 @@ Rectangle Terminal::putcodepoint(uint32_t codepoint)
|
||||||
{
|
{
|
||||||
const uint32_t scroll = m_cursor.y - rows() + 1;
|
const uint32_t scroll = m_cursor.y - rows() + 1;
|
||||||
m_cursor.y -= scroll;
|
m_cursor.y -= scroll;
|
||||||
m_window->shift_vertical(-scroll * (int32_t)m_font.height(), m_bg_color);
|
texture.shift_vertical(-scroll * (int32_t)m_font.height(), m_bg_color);
|
||||||
should_invalidate = { 0, 0, m_window->width(), m_window->height() };
|
should_invalidate = { 0, 0, m_window->width(), m_window->height() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
|
|
||||||
void randomize_color(BAN::UniqPtr<LibGUI::Window>& window)
|
void randomize_color(BAN::UniqPtr<LibGUI::Window>& window)
|
||||||
{
|
{
|
||||||
|
auto& texture = window->texture();
|
||||||
uint32_t color = ((rand() % 255) << 16) | ((rand() % 255) << 8) | ((rand() % 255) << 0);
|
uint32_t color = ((rand() % 255) << 16) | ((rand() % 255) << 8) | ((rand() % 255) << 0);
|
||||||
for (uint32_t y = 0; y < window->height(); y++)
|
for (uint32_t y = 0; y < window->height(); y++)
|
||||||
for (uint32_t x = 0; x < window->width(); x++)
|
for (uint32_t x = 0; x < window->width(); x++)
|
||||||
window->set_pixel(x, y, 0xFF000000 | color);
|
texture.set_pixel(x, y, 0xFF000000 | color);
|
||||||
window->invalidate();
|
window->invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue