Skip to content

Commit

Permalink
centered backgrounds are now an option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexispurslane authored and awesomekling committed May 27, 2019
1 parent aa50e5b commit da9c705
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Base/home/anon/WindowManager.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Screen]
Width=2560
Height=1440
Width=1920
Height=1080

[Cursor]
Arrow=/res/cursors/arrow.png
Expand Down Expand Up @@ -36,4 +36,4 @@ MenuSelectionColor=132,53,26
DoubleClickSpeed=250

[Background]
Mode=tile
Mode=center
6 changes: 4 additions & 2 deletions Servers/WindowServer/WSCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ void WSCompositor::compose()
m_wallpaper_mode == WallpaperMode::Unchecked) {
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
} else if (m_wallpaper_mode == WallpaperMode::Center) {
// TODO: Implement centered wallpaper
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
Point offset{ ws.size().width() / 2 - m_wallpaper->size().width() / 2,
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) {
m_back_painter->blit_tiled(dirty_rect.location(), *m_wallpaper, dirty_rect);
}
Expand Down
37 changes: 37 additions & 0 deletions SharedGraphics/Painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,43 @@ void Painter::blit_tiled(const Point& position, const GraphicsBitmap& source, co
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)
{
ASSERT(source.has_alpha_channel());
Expand Down
1 change: 1 addition & 0 deletions SharedGraphics/Painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Painter {
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_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, 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);
Expand Down

0 comments on commit da9c705

Please sign in to comment.