From 76b333749899c666dee522fd064234d8b94d9cfd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 7 Jun 2019 11:46:55 +0200 Subject: [PATCH] SharedGraphics: Run clang-format on everything. --- SharedGraphics/CharacterBitmap.cpp | 1 - SharedGraphics/CharacterBitmap.h | 3 +- SharedGraphics/Color.cpp | 76 ++++++++++++++++++++++-------- SharedGraphics/Color.h | 20 ++++++-- SharedGraphics/DisjointRectSet.cpp | 4 +- SharedGraphics/DisjointRectSet.h | 10 ++-- SharedGraphics/Font.cpp | 13 ++--- SharedGraphics/Font.h | 7 +-- SharedGraphics/GraphicsBitmap.cpp | 10 ++-- SharedGraphics/GraphicsBitmap.h | 14 ++++-- SharedGraphics/PNGLoader.cpp | 73 +++++++++++++++------------- SharedGraphics/Point.h | 8 +++- SharedGraphics/Rect.cpp | 4 +- SharedGraphics/Rect.h | 2 +- SharedGraphics/Size.h | 12 +++-- SharedGraphics/StylePainter.cpp | 27 +++++++---- SharedGraphics/StylePainter.h | 23 +++++++-- SharedGraphics/TextAlignment.h | 8 +++- SharedGraphics/TextElision.h | 4 +- SharedGraphics/puff.h | 11 ++--- 20 files changed, 216 insertions(+), 114 deletions(-) diff --git a/SharedGraphics/CharacterBitmap.cpp b/SharedGraphics/CharacterBitmap.cpp index 62f1f26677b..ecfc550d195 100644 --- a/SharedGraphics/CharacterBitmap.cpp +++ b/SharedGraphics/CharacterBitmap.cpp @@ -14,4 +14,3 @@ Retained CharacterBitmap::create_from_ascii(const char* asciiDa { return adopt(*new CharacterBitmap(asciiData, width, height)); } - diff --git a/SharedGraphics/CharacterBitmap.h b/SharedGraphics/CharacterBitmap.h index ef0b0d5c5a2..e86f88fca87 100644 --- a/SharedGraphics/CharacterBitmap.h +++ b/SharedGraphics/CharacterBitmap.h @@ -1,8 +1,8 @@ #pragma once #include "Size.h" -#include #include +#include class CharacterBitmap : public Retainable { public: @@ -22,4 +22,3 @@ private: const char* m_bits { nullptr }; Size m_size; }; - diff --git a/SharedGraphics/Color.cpp b/SharedGraphics/Color.cpp index c982261c7e6..2b86b20f991 100644 --- a/SharedGraphics/Color.cpp +++ b/SharedGraphics/Color.cpp @@ -10,25 +10,63 @@ Color::Color(NamedColor named) } rgb; switch (named) { - case Black: rgb = { 0, 0, 0 }; break; - case White: rgb = { 255, 255, 255 }; break; - case Red: rgb = { 255, 0, 0}; break; - case Green: rgb = { 0, 255, 0}; break; - case Cyan: rgb = { 0, 255, 255 }; break; - case Blue: rgb = { 0, 0, 255}; break; - case Yellow: rgb = { 255, 255, 0 }; break; - case Magenta: rgb = { 255, 0, 255 }; break; - case DarkGray: rgb = { 64, 64, 64 }; break; - case MidGray: rgb = { 127, 127, 127 }; break; - case LightGray: rgb = { 192, 192, 192 }; break; - case MidGreen: rgb = { 0, 192, 0 }; break; - case MidBlue: rgb = { 0, 0, 192 }; break; - case MidRed: rgb = { 192, 0, 0 }; break; - case MidMagenta: rgb = { 192, 0, 192 }; break; - case DarkGreen: rgb = { 0, 128, 0 }; break; - case DarkBlue: rgb = { 0, 0, 128 }; break; - case DarkRed: rgb = { 128, 0, 0 }; break; - default: ASSERT_NOT_REACHED(); break; + case Black: + rgb = { 0, 0, 0 }; + break; + case White: + rgb = { 255, 255, 255 }; + break; + case Red: + rgb = { 255, 0, 0 }; + break; + case Green: + rgb = { 0, 255, 0 }; + break; + case Cyan: + rgb = { 0, 255, 255 }; + break; + case Blue: + rgb = { 0, 0, 255 }; + break; + case Yellow: + rgb = { 255, 255, 0 }; + break; + case Magenta: + rgb = { 255, 0, 255 }; + break; + case DarkGray: + rgb = { 64, 64, 64 }; + break; + case MidGray: + rgb = { 127, 127, 127 }; + break; + case LightGray: + rgb = { 192, 192, 192 }; + break; + case MidGreen: + rgb = { 0, 192, 0 }; + break; + case MidBlue: + rgb = { 0, 0, 192 }; + break; + case MidRed: + rgb = { 192, 0, 0 }; + break; + case MidMagenta: + rgb = { 192, 0, 192 }; + break; + case DarkGreen: + rgb = { 0, 128, 0 }; + break; + case DarkBlue: + rgb = { 0, 0, 128 }; + break; + case DarkRed: + rgb = { 128, 0, 0 }; + break; + default: + ASSERT_NOT_REACHED(); + break; } m_value = 0xff000000 | (rgb.r << 16) | (rgb.g << 8) | rgb.b; diff --git a/SharedGraphics/Color.h b/SharedGraphics/Color.h index 29116790c66..8c3af4cabe0 100644 --- a/SharedGraphics/Color.h +++ b/SharedGraphics/Color.h @@ -12,7 +12,8 @@ inline constexpr dword make_rgb(byte r, byte g, byte b) class Color { public: - enum NamedColor { + enum NamedColor + { Black, White, Red, @@ -33,10 +34,16 @@ public: MidMagenta, }; - Color() { } + Color() {} Color(NamedColor); - Color(byte r, byte g, byte b) : m_value(0xff000000 | (r << 16) | (g << 8) | b) { } - Color(byte r, byte g, byte b, byte a) : m_value((a << 24) | (r << 16) | (g << 8) | b) { } + Color(byte r, byte g, byte b) + : m_value(0xff000000 | (r << 16) | (g << 8) | b) + { + } + Color(byte r, byte g, byte b, byte a) + : m_value((a << 24) | (r << 16) | (g << 8) | b) + { + } static Color from_rgb(unsigned rgb) { return Color(rgb | 0xff000000); } static Color from_rgba(unsigned rgba) { return Color(rgba); } @@ -94,7 +101,10 @@ public: String to_string() const; private: - explicit Color(RGBA32 rgba) : m_value(rgba) { } + explicit Color(RGBA32 rgba) + : m_value(rgba) + { + } RGBA32 m_value { 0 }; }; diff --git a/SharedGraphics/DisjointRectSet.cpp b/SharedGraphics/DisjointRectSet.cpp index 38221fea665..c3eacf275ac 100644 --- a/SharedGraphics/DisjointRectSet.cpp +++ b/SharedGraphics/DisjointRectSet.cpp @@ -39,7 +39,7 @@ void DisjointRectSet::shatter() } output.append(r1); } -next_pass: + next_pass: swap(output, m_rects); - } while(pass_had_intersections); + } while (pass_had_intersections); } diff --git a/SharedGraphics/DisjointRectSet.h b/SharedGraphics/DisjointRectSet.h index 1c15eadbd93..197cb4c81b3 100644 --- a/SharedGraphics/DisjointRectSet.h +++ b/SharedGraphics/DisjointRectSet.h @@ -5,9 +5,12 @@ class DisjointRectSet { public: - DisjointRectSet() { } - ~DisjointRectSet() { } - DisjointRectSet(DisjointRectSet&& other) : m_rects(move(other.m_rects)) { } + DisjointRectSet() {} + ~DisjointRectSet() {} + DisjointRectSet(DisjointRectSet&& other) + : m_rects(move(other.m_rects)) + { + } void add(const Rect&); @@ -23,4 +26,3 @@ private: Vector m_rects; }; - diff --git a/SharedGraphics/Font.cpp b/SharedGraphics/Font.cpp index 98e5e27c0a0..47baaa7163c 100644 --- a/SharedGraphics/Font.cpp +++ b/SharedGraphics/Font.cpp @@ -1,15 +1,16 @@ #include "Font.h" -#include #include -#include #include -#include -#include -#include +#include +#include #include +#include #include +#include +#include -struct [[gnu::packed]] FontFileHeader { +struct [[gnu::packed]] FontFileHeader +{ char magic[4]; byte glyph_width; byte glyph_height; diff --git a/SharedGraphics/Font.h b/SharedGraphics/Font.h index 193c69b31c4..85d91e3bea2 100644 --- a/SharedGraphics/Font.h +++ b/SharedGraphics/Font.h @@ -1,15 +1,16 @@ #pragma once -#include -#include -#include #include #include +#include +#include #include +#include // FIXME: Make a MutableGlyphBitmap buddy class for FontEditor instead? class GlyphBitmap { friend class Font; + public: const unsigned* rows() const { return m_rows; } unsigned row(unsigned index) const { return m_rows[index]; } diff --git a/SharedGraphics/GraphicsBitmap.cpp b/SharedGraphics/GraphicsBitmap.cpp index e4c861d8694..8a7621e4e6d 100644 --- a/SharedGraphics/GraphicsBitmap.cpp +++ b/SharedGraphics/GraphicsBitmap.cpp @@ -1,11 +1,11 @@ +#include #include #include -#include +#include +#include +#include #include #include -#include -#include -#include Retained GraphicsBitmap::create(Format format, const Size& size) { @@ -83,7 +83,7 @@ GraphicsBitmap::~GraphicsBitmap() ASSERT(rc == 0); } m_data = nullptr; - delete [] m_palette; + delete[] m_palette; } void GraphicsBitmap::set_mmap_name(const StringView& name) diff --git a/SharedGraphics/GraphicsBitmap.h b/SharedGraphics/GraphicsBitmap.h index 6f0c78c8f2c..aecad2ed1d7 100644 --- a/SharedGraphics/GraphicsBitmap.h +++ b/SharedGraphics/GraphicsBitmap.h @@ -3,16 +3,22 @@ #include "Color.h" #include "Rect.h" #include "Size.h" -#include -#include #include -#include #include +#include +#include +#include #include class GraphicsBitmap : public Retainable { public: - enum class Format { Invalid, RGB32, RGBA32, Indexed8 }; + enum class Format + { + Invalid, + RGB32, + RGBA32, + Indexed8 + }; static Retained create(Format, const Size&); static Retained create_wrapper(Format, const Size&, RGBA32*); diff --git a/SharedGraphics/PNGLoader.cpp b/SharedGraphics/PNGLoader.cpp index 37952654bbe..5f67149906f 100644 --- a/SharedGraphics/PNGLoader.cpp +++ b/SharedGraphics/PNGLoader.cpp @@ -1,15 +1,15 @@ -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include //#define PNG_STOPWATCH_DEBUG @@ -125,7 +125,8 @@ RetainPtr load_png(const StringView& path) return c; } -union [[gnu::packed]] Pixel { +union [[gnu::packed]] Pixel +{ RGBA32 rgba { 0 }; byte v[4]; struct { @@ -186,7 +187,8 @@ template auto& x = pixels[i]; swap(x.r, x.b); Pixel a; - if (i != 0) a = pixels[i - 1]; + if (i != 0) + a = pixels[i - 1]; const Pixel& b = pixels_y_minus_1[i]; x.v[0] = x.v[0] + ((a.v[0] + b.v[0]) / 2); x.v[1] = x.v[1] + ((a.v[1] + b.v[1]) / 2); @@ -222,32 +224,37 @@ template { { #ifdef PNG_STOPWATCH_DEBUG - Stopwatch sw("load_png_impl: unfilter: unpack"); + Stopwatch sw("load_png_impl: unfilter: unpack"); #endif - // First unpack the scanlines to RGBA: - switch (context.color_type) { - case 2: - for (int y = 0; y < context.height; ++y) { - struct [[gnu::packed]] Triplet { byte r; byte g; byte b; }; - auto* triplets = (Triplet*)context.scanlines[y].data.pointer(); - for (int i = 0; i < context.width; ++i) { - auto& pixel = (Pixel&)context.bitmap->scanline(y)[i]; - pixel.r = triplets[i].r; - pixel.g = triplets[i].g; - pixel.b = triplets[i].b; - pixel.a = 0xff; + // First unpack the scanlines to RGBA: + switch (context.color_type) { + case 2: + for (int y = 0; y < context.height; ++y) { + struct [[gnu::packed]] Triplet + { + byte r; + byte g; + byte b; + }; + auto* triplets = (Triplet*)context.scanlines[y].data.pointer(); + for (int i = 0; i < context.width; ++i) { + auto& pixel = (Pixel&)context.bitmap->scanline(y)[i]; + pixel.r = triplets[i].r; + pixel.g = triplets[i].g; + pixel.b = triplets[i].b; + pixel.a = 0xff; + } } + break; + case 6: + for (int y = 0; y < context.height; ++y) { + memcpy(context.bitmap->scanline(y), context.scanlines[y].data.pointer(), context.scanlines[y].data.size()); + } + break; + default: + ASSERT_NOT_REACHED(); + break; } - break; - case 6: - for (int y = 0; y < context.height; ++y) { - memcpy(context.bitmap->scanline(y), context.scanlines[y].data.pointer(), context.scanlines[y].data.size()); - } - break; - default: - ASSERT_NOT_REACHED(); - break; - } } auto dummy_scanline = ByteBuffer::create_zeroed(context.width * sizeof(RGBA32)); diff --git a/SharedGraphics/Point.h b/SharedGraphics/Point.h index b9fa85d994c..0530da9adb2 100644 --- a/SharedGraphics/Point.h +++ b/SharedGraphics/Point.h @@ -7,8 +7,12 @@ struct WSAPI_Point; class Point { public: - Point() { } - Point(int x, int y) : m_x(x) , m_y(y) { } + Point() {} + Point(int x, int y) + : m_x(x) + , m_y(y) + { + } Point(const WSAPI_Point&); int x() const { return m_x; } diff --git a/SharedGraphics/Rect.cpp b/SharedGraphics/Rect.cpp index 1f14918cd1b..213d18ead96 100644 --- a/SharedGraphics/Rect.cpp +++ b/SharedGraphics/Rect.cpp @@ -9,8 +9,8 @@ void Rect::intersect(const Rect& other) int b = min(bottom(), other.bottom()); if (l > r || t > b) { - m_location = { }; - m_size = { }; + m_location = {}; + m_size = {}; return; } diff --git a/SharedGraphics/Rect.h b/SharedGraphics/Rect.h index de600a4e77b..3fcc8649a1a 100644 --- a/SharedGraphics/Rect.h +++ b/SharedGraphics/Rect.h @@ -9,7 +9,7 @@ struct WSAPI_Rect; class Rect { public: - Rect() { } + Rect() {} Rect(int x, int y, int width, int height) : m_location(x, y) , m_size(width, height) diff --git a/SharedGraphics/Size.h b/SharedGraphics/Size.h index 77638cca2f6..e38c47e66d2 100644 --- a/SharedGraphics/Size.h +++ b/SharedGraphics/Size.h @@ -6,8 +6,12 @@ struct WSAPI_Size; class Size { public: - Size() { } - Size(int w, int h) : m_width(w), m_height(h) { } + Size() {} + Size(int w, int h) + : m_width(w) + , m_height(h) + { + } Size(const WSAPI_Size&); bool is_null() const { return !m_width && !m_height; } @@ -23,8 +27,7 @@ public: bool operator==(const Size& other) const { - return m_width == other.m_width && - m_height == other.m_height; + return m_width == other.m_width && m_height == other.m_height; } bool operator!=(const Size& other) const @@ -54,4 +57,3 @@ private: int m_width { 0 }; int m_height { 0 }; }; - diff --git a/SharedGraphics/StylePainter.cpp b/SharedGraphics/StylePainter.cpp index bf08fbdb57a..9b152821753 100644 --- a/SharedGraphics/StylePainter.cpp +++ b/SharedGraphics/StylePainter.cpp @@ -1,5 +1,5 @@ -#include #include +#include void StylePainter::paint_tab_button(Painter& painter, const Rect& rect, bool active, bool hovered, bool enabled) { @@ -25,9 +25,21 @@ void StylePainter::paint_tab_button(Painter& painter, const Rect& rect, bool act painter.set_pixel({ 1, 1 }, highlight_color2); // Right side - painter.draw_line({ rect.width() - 1, 2, }, { rect.width() - 1, rect.height() - 1 }, shadow_color2); - painter.draw_line({ rect.width() - 2, 2, }, { rect.width() - 2, rect.height() - 1 }, shadow_color1); - painter.set_pixel({ rect.width() - 2, 1, }, shadow_color2); + painter.draw_line({ + rect.width() - 1, + 2, + }, + { rect.width() - 1, rect.height() - 1 }, shadow_color2); + painter.draw_line({ + rect.width() - 2, + 2, + }, + { rect.width() - 2, rect.height() - 1 }, shadow_color1); + painter.set_pixel({ + rect.width() - 2, + 1, + }, + shadow_color2); } static void paint_button_new(Painter& painter, const Rect& rect, bool pressed, bool checked, bool hovered, bool enabled) @@ -52,11 +64,11 @@ static void paint_button_new(Painter& painter, const Rect& rect, bool pressed, b // Base painter.fill_rect({ 1, 1, rect.width() - 2, rect.height() - 2 }, button_color); - painter.draw_rect({ { }, rect.size() }, shadow_color2); + painter.draw_rect({ {}, rect.size() }, shadow_color2); // Sunken shadow painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, shadow_color1); - painter.draw_line({ 1, 2 }, {1, rect.height() - 2 }, shadow_color1); + painter.draw_line({ 1, 2 }, { 1, rect.height() - 2 }, shadow_color1); } else { // Base painter.fill_rect({ 1, 1, rect.width() - 3, rect.height() - 3 }, button_color); @@ -96,7 +108,7 @@ void StylePainter::paint_button(Painter& painter, const Rect& rect, ButtonStyle // Sunken shadow painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, shadow_color); - painter.draw_line({ 1, 2 }, {1, rect.height() - 2 }, shadow_color); + painter.draw_line({ 1, 2 }, { 1, rect.height() - 2 }, shadow_color); // Bottom highlight painter.draw_line({ rect.width() - 2, 1 }, { rect.width() - 2, rect.height() - 3 }, highlight_color); @@ -214,4 +226,3 @@ void StylePainter::paint_window_frame(Painter& painter, const Rect& rect) painter.draw_line(rect.bottom_left().translated(1, -1), rect.bottom_right().translated(-1, -1), mid_shade); painter.draw_line(rect.bottom_left().translated(2, -2), rect.bottom_right().translated(-2, -2), base_color); } - diff --git a/SharedGraphics/StylePainter.h b/SharedGraphics/StylePainter.h index 12aab479324..b6432f564c2 100644 --- a/SharedGraphics/StylePainter.h +++ b/SharedGraphics/StylePainter.h @@ -3,9 +3,26 @@ class Painter; class Rect; -enum class ButtonStyle { Normal, CoolBar }; -enum class FrameShadow { Plain, Raised, Sunken }; -enum class FrameShape { NoFrame, Box, Container, Panel, VerticalLine, HorizontalLine }; +enum class ButtonStyle +{ + Normal, + CoolBar +}; +enum class FrameShadow +{ + Plain, + Raised, + Sunken +}; +enum class FrameShape +{ + NoFrame, + Box, + Container, + Panel, + VerticalLine, + HorizontalLine +}; class StylePainter { public: diff --git a/SharedGraphics/TextAlignment.h b/SharedGraphics/TextAlignment.h index 9f77c671797..4327077baa9 100644 --- a/SharedGraphics/TextAlignment.h +++ b/SharedGraphics/TextAlignment.h @@ -1,6 +1,12 @@ #pragma once -enum class TextAlignment { TopLeft, CenterLeft, Center, CenterRight }; +enum class TextAlignment +{ + TopLeft, + CenterLeft, + Center, + CenterRight +}; inline bool is_right_text_alignment(TextAlignment alignment) { diff --git a/SharedGraphics/TextElision.h b/SharedGraphics/TextElision.h index ecd97cd4525..054d514e8cf 100644 --- a/SharedGraphics/TextElision.h +++ b/SharedGraphics/TextElision.h @@ -1,7 +1,7 @@ #pragma once -enum class TextElision { +enum class TextElision +{ None, Right, }; - diff --git a/SharedGraphics/puff.h b/SharedGraphics/puff.h index e23a2454316..50beef92a1f 100644 --- a/SharedGraphics/puff.h +++ b/SharedGraphics/puff.h @@ -21,15 +21,14 @@ Mark Adler madler@alumni.caltech.edu */ - /* * See puff.c for purpose and usage. */ #ifndef NIL -# define NIL ((unsigned char *)0) /* for no output option */ +# define NIL ((unsigned char*)0) /* for no output option */ #endif -int puff(unsigned char *dest, /* pointer to destination pointer */ - unsigned long *destlen, /* amount of output space */ - const unsigned char *source, /* pointer to source data pointer */ - unsigned long *sourcelen); /* amount of input available */ +int puff(unsigned char* dest, /* pointer to destination pointer */ + unsigned long* destlen, /* amount of output space */ + const unsigned char* source, /* pointer to source data pointer */ + unsigned long* sourcelen); /* amount of input available */