SharedGraphics: Run clang-format on everything.

This commit is contained in:
Andreas Kling 2019-06-07 11:46:55 +02:00
parent 7770d6a09d
commit 76b3337498
Notes: sideshowbarker 2024-07-19 13:41:42 +09:00
20 changed files with 216 additions and 114 deletions

View file

@ -14,4 +14,3 @@ Retained<CharacterBitmap> CharacterBitmap::create_from_ascii(const char* asciiDa
{
return adopt(*new CharacterBitmap(asciiData, width, height));
}

View file

@ -1,8 +1,8 @@
#pragma once
#include "Size.h"
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
class CharacterBitmap : public Retainable<CharacterBitmap> {
public:
@ -22,4 +22,3 @@ private:
const char* m_bits { nullptr };
Size m_size;
};

View file

@ -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;

View file

@ -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 };
};

View file

@ -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);
}

View file

@ -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<Rect, 32> m_rects;
};

View file

@ -1,15 +1,16 @@
#include "Font.h"
#include <AK/kmalloc.h>
#include <AK/BufferStream.h>
#include <AK/StdLibExtras.h>
#include <AK/MappedFile.h>
#include <LibC/unistd.h>
#include <LibC/stdio.h>
#include <LibC/fcntl.h>
#include <AK/StdLibExtras.h>
#include <AK/kmalloc.h>
#include <LibC/errno.h>
#include <LibC/fcntl.h>
#include <LibC/mman.h>
#include <LibC/stdio.h>
#include <LibC/unistd.h>
struct [[gnu::packed]] FontFileHeader {
struct [[gnu::packed]] FontFileHeader
{
char magic[4];
byte glyph_width;
byte glyph_height;

View file

@ -1,15 +1,16 @@
#pragma once
#include <SharedGraphics/Rect.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
#include <AK/MappedFile.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/Types.h>
#include <SharedGraphics/Rect.h>
// 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]; }

View file

@ -1,11 +1,11 @@
#include <AK/MappedFile.h>
#include <SharedGraphics/GraphicsBitmap.h>
#include <SharedGraphics/PNGLoader.h>
#include <AK/MappedFile.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
Retained<GraphicsBitmap> 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)

View file

@ -3,16 +3,22 @@
#include "Color.h"
#include "Rect.h"
#include "Size.h"
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
#include <AK/StringView.h>
#include <AK/MappedFile.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/StringView.h>
#include <SharedBuffer.h>
class GraphicsBitmap : public Retainable<GraphicsBitmap> {
public:
enum class Format { Invalid, RGB32, RGBA32, Indexed8 };
enum class Format
{
Invalid,
RGB32,
RGBA32,
Indexed8
};
static Retained<GraphicsBitmap> create(Format, const Size&);
static Retained<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*);

View file

@ -1,15 +1,15 @@
#include <SharedGraphics/PNGLoader.h>
#include <AK/NetworkOrdered.h>
#include <AK/MappedFile.h>
#include <AK/FileSystemPath.h>
#include <AK/MappedFile.h>
#include <AK/NetworkOrdered.h>
#include <SharedGraphics/PNGLoader.h>
#include <SharedGraphics/puff.c>
#include <fcntl.h>
#include <serenity.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <SharedGraphics/puff.c>
#include <serenity.h>
//#define PNG_STOPWATCH_DEBUG
@ -125,7 +125,8 @@ RetainPtr<GraphicsBitmap> 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<bool has_alpha, byte filter_type>
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<bool has_alpha, byte filter_type>
{
{
#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));

View file

@ -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; }

View file

@ -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;
}

View file

@ -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)

View file

@ -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 };
};

View file

@ -1,5 +1,5 @@
#include <SharedGraphics/StylePainter.h>
#include <LibGUI/GPainter.h>
#include <SharedGraphics/StylePainter.h>
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);
}

View file

@ -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:

View file

@ -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)
{

View file

@ -1,7 +1,7 @@
#pragma once
enum class TextElision {
enum class TextElision
{
None,
Right,
};

View file

@ -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 */