mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
centered backgrounds are now an option
This commit is contained in:
parent
aa50e5bb13
commit
da9c70598f
4 changed files with 45 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
[Screen]
|
[Screen]
|
||||||
Width=2560
|
Width=1920
|
||||||
Height=1440
|
Height=1080
|
||||||
|
|
||||||
[Cursor]
|
[Cursor]
|
||||||
Arrow=/res/cursors/arrow.png
|
Arrow=/res/cursors/arrow.png
|
||||||
|
@ -36,4 +36,4 @@ MenuSelectionColor=132,53,26
|
||||||
DoubleClickSpeed=250
|
DoubleClickSpeed=250
|
||||||
|
|
||||||
[Background]
|
[Background]
|
||||||
Mode=tile
|
Mode=center
|
||||||
|
|
|
@ -95,8 +95,10 @@ void WSCompositor::compose()
|
||||||
m_wallpaper_mode == WallpaperMode::Unchecked) {
|
m_wallpaper_mode == WallpaperMode::Unchecked) {
|
||||||
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
|
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
|
||||||
} else if (m_wallpaper_mode == WallpaperMode::Center) {
|
} else if (m_wallpaper_mode == WallpaperMode::Center) {
|
||||||
// TODO: Implement centered wallpaper
|
Point offset{ ws.size().width() / 2 - m_wallpaper->size().width() / 2,
|
||||||
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
|
ws.size().height() / 2 - m_wallpaper->size().height() / 2 };
|
||||||
|
m_back_painter->blit_offset(dirty_rect.location(), *m_wallpaper,
|
||||||
|
dirty_rect, offset);
|
||||||
} else if (m_wallpaper_mode == WallpaperMode::Tile) {
|
} else if (m_wallpaper_mode == WallpaperMode::Tile) {
|
||||||
m_back_painter->blit_tiled(dirty_rect.location(), *m_wallpaper, dirty_rect);
|
m_back_painter->blit_tiled(dirty_rect.location(), *m_wallpaper, dirty_rect);
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,6 +301,43 @@ void Painter::blit_tiled(const Point& position, const GraphicsBitmap& source, co
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Painter::blit_offset(const Point& position,
|
||||||
|
const GraphicsBitmap& source,
|
||||||
|
const Rect& src_rect,
|
||||||
|
const Point& offset)
|
||||||
|
{
|
||||||
|
auto dst_rect = Rect(position, src_rect.size()).translated(translation());
|
||||||
|
auto clipped_rect = dst_rect.intersected(clip_rect());
|
||||||
|
if (clipped_rect.is_empty())
|
||||||
|
return;
|
||||||
|
const int first_row = (clipped_rect.top() - dst_rect.top());
|
||||||
|
const int last_row = (clipped_rect.bottom() - dst_rect.top());
|
||||||
|
const int first_column = (clipped_rect.left() - dst_rect.left());
|
||||||
|
RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x();
|
||||||
|
const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
|
||||||
|
|
||||||
|
if (source.format() == GraphicsBitmap::Format::RGB32 || source.format() == GraphicsBitmap::Format::RGBA32) {
|
||||||
|
int x_start = first_column + src_rect.left();
|
||||||
|
for (int row = first_row; row <= last_row; ++row) {
|
||||||
|
int sr = row - offset.y() + src_rect.top();
|
||||||
|
if (sr >= source.size().height() || sr < 0) {
|
||||||
|
dst += dst_skip;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const RGBA32* sl = source.scanline(sr);
|
||||||
|
for (int x = x_start; x < clipped_rect.width() + x_start; ++x) {
|
||||||
|
int sx = x - offset.x();
|
||||||
|
if (sx < source.size().width() && sx >= 0)
|
||||||
|
dst[x - x_start] = sl[sx];
|
||||||
|
}
|
||||||
|
dst += dst_skip;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
void Painter::blit_with_alpha(const Point& position, const GraphicsBitmap& source, const Rect& src_rect)
|
void Painter::blit_with_alpha(const Point& position, const GraphicsBitmap& source, const Rect& src_rect)
|
||||||
{
|
{
|
||||||
ASSERT(source.has_alpha_channel());
|
ASSERT(source.has_alpha_channel());
|
||||||
|
|
|
@ -28,6 +28,7 @@ public:
|
||||||
void blit(const Point&, const GraphicsBitmap&, const Rect& src_rect, float opacity = 1.0f);
|
void blit(const Point&, const GraphicsBitmap&, const Rect& src_rect, float opacity = 1.0f);
|
||||||
void blit_dimmed(const Point&, const GraphicsBitmap&, const Rect& src_rect);
|
void blit_dimmed(const Point&, const GraphicsBitmap&, const Rect& src_rect);
|
||||||
void blit_tiled(const Point&, const GraphicsBitmap&, const Rect& src_rect);
|
void blit_tiled(const Point&, const GraphicsBitmap&, const Rect& src_rect);
|
||||||
|
void blit_offset(const Point&, const GraphicsBitmap&, const Rect& src_rect, const Point&);
|
||||||
void draw_text(const Rect&, const char* text, int length, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
void draw_text(const Rect&, const char* text, int length, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
||||||
void draw_text(const Rect&, const char* text, int length, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
void draw_text(const Rect&, const char* text, int length, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
||||||
void draw_text(const Rect&, const String&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
void draw_text(const Rect&, const String&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue