diff options
Diffstat (limited to 'SharedGraphics')
-rw-r--r-- | SharedGraphics/Painter.cpp | 52 | ||||
-rw-r--r-- | SharedGraphics/Painter.h | 14 |
2 files changed, 45 insertions, 21 deletions
diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp index 5061fefb2c..97c58b59a5 100644 --- a/SharedGraphics/Painter.cpp +++ b/SharedGraphics/Painter.cpp @@ -1,13 +1,13 @@ #include "Painter.h" #include "Font.h" #include "GraphicsBitmap.h" -#include <SharedGraphics/CharacterBitmap.h> #include <AK/Assertions.h> #include <AK/StdLibExtras.h> #include <AK/StringBuilder.h> -#include <unistd.h> -#include <stdio.h> +#include <SharedGraphics/CharacterBitmap.h> #include <math.h> +#include <stdio.h> +#include <unistd.h> #pragma GCC optimize("O3") @@ -89,7 +89,7 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start, RGBA32* dst = m_target->scanline(clipped_rect.top()) + clipped_rect.left(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - float increment = (1.0/((rect.width())/255.0)); + float increment = (1.0 / ((rect.width()) / 255.0)); int r2 = gradient_start.red(); int g2 = gradient_start.green(); @@ -104,8 +104,8 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start, dst[j] = Color( r1 / 255.0 * c + r2 / 255.0 * (255 - c), g1 / 255.0 * c + g2 / 255.0 * (255 - c), - b1 / 255.0 * c + b2 / 255.0 * (255 - c) - ).value(); + b1 / 255.0 * c + b2 / 255.0 * (255 - c)) + .value(); c += increment; } dst += dst_skip; @@ -289,7 +289,7 @@ void Painter::blit_tiled(const Point& position, const GraphicsBitmap& source, co int x_start = first_column + src_rect.left(); for (int row = first_row; row <= last_row; ++row) { const RGBA32* sl = source.scanline((row + src_rect.top()) - % source.size().height()); + % source.size().height()); for (int x = x_start; x < clipped_rect.width() + x_start; ++x) { dst[x - x_start] = sl[x % source.size().width()]; } @@ -302,9 +302,9 @@ void Painter::blit_tiled(const Point& position, const GraphicsBitmap& source, co } void Painter::blit_offset(const Point& position, - const GraphicsBitmap& source, - const Rect& src_rect, - const Point& offset) + 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()); @@ -483,17 +483,33 @@ void Painter::draw_scaled_bitmap(const Rect& a_dst_rect, const GraphicsBitmap& s if (source.has_alpha_channel()) { switch (source.format()) { - case GraphicsBitmap::Format::RGB32: do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); break; - case GraphicsBitmap::Format::RGBA32: do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); break; - case GraphicsBitmap::Format::Indexed8: do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>); break; - default: do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>); break; + case GraphicsBitmap::Format::RGB32: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); + break; + case GraphicsBitmap::Format::RGBA32: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); + break; + case GraphicsBitmap::Format::Indexed8: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>); + break; + default: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>); + break; } } else { switch (source.format()) { - case GraphicsBitmap::Format::RGB32: do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); break; - case GraphicsBitmap::Format::RGBA32: do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); break; - case GraphicsBitmap::Format::Indexed8: do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>); break; - default: do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>); break; + case GraphicsBitmap::Format::RGB32: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); + break; + case GraphicsBitmap::Format::RGBA32: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::RGB32>); + break; + case GraphicsBitmap::Format::Indexed8: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Indexed8>); + break; + default: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<GraphicsBitmap::Format::Invalid>); + break; } } } diff --git a/SharedGraphics/Painter.h b/SharedGraphics/Painter.h index 593474e3c3..de0125a4c6 100644 --- a/SharedGraphics/Painter.h +++ b/SharedGraphics/Painter.h @@ -4,9 +4,9 @@ #include "Point.h" #include "Rect.h" #include "Size.h" +#include <AK/AKString.h> #include <SharedGraphics/TextAlignment.h> #include <SharedGraphics/TextElision.h> -#include <AK/AKString.h> class CharacterBitmap; class GlyphBitmap; @@ -38,7 +38,11 @@ public: const Font& font() const { return *state().font; } void set_font(const Font& font) { state().font = &font; } - enum class DrawOp { Copy, Xor }; + enum class DrawOp + { + Copy, + Xor + }; void set_draw_op(DrawOp op) { state().draw_op = op; } DrawOp draw_op() const { return state().draw_op; } @@ -54,7 +58,11 @@ public: GraphicsBitmap* target() { return m_target.ptr(); } void save() { m_state_stack.append(m_state_stack.last()); } - void restore() { ASSERT(m_state_stack.size() > 1); m_state_stack.take_last(); } + void restore() + { + ASSERT(m_state_stack.size() > 1); + m_state_stack.take_last(); + } protected: void set_pixel_with_draw_op(dword& pixel, const Color&); |