1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00:00

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
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)); return adopt(*new CharacterBitmap(asciiData, width, height));
} }

View file

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

View file

@ -10,25 +10,63 @@ Color::Color(NamedColor named)
} rgb; } rgb;
switch (named) { switch (named) {
case Black: rgb = { 0, 0, 0 }; break; case Black:
case White: rgb = { 255, 255, 255 }; break; rgb = { 0, 0, 0 };
case Red: rgb = { 255, 0, 0}; break; break;
case Green: rgb = { 0, 255, 0}; break; case White:
case Cyan: rgb = { 0, 255, 255 }; break; rgb = { 255, 255, 255 };
case Blue: rgb = { 0, 0, 255}; break; break;
case Yellow: rgb = { 255, 255, 0 }; break; case Red:
case Magenta: rgb = { 255, 0, 255 }; break; rgb = { 255, 0, 0 };
case DarkGray: rgb = { 64, 64, 64 }; break; break;
case MidGray: rgb = { 127, 127, 127 }; break; case Green:
case LightGray: rgb = { 192, 192, 192 }; break; rgb = { 0, 255, 0 };
case MidGreen: rgb = { 0, 192, 0 }; break; break;
case MidBlue: rgb = { 0, 0, 192 }; break; case Cyan:
case MidRed: rgb = { 192, 0, 0 }; break; rgb = { 0, 255, 255 };
case MidMagenta: rgb = { 192, 0, 192 }; break; break;
case DarkGreen: rgb = { 0, 128, 0 }; break; case Blue:
case DarkBlue: rgb = { 0, 0, 128 }; break; rgb = { 0, 0, 255 };
case DarkRed: rgb = { 128, 0, 0 }; break; break;
default: ASSERT_NOT_REACHED(); 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; 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 { class Color {
public: public:
enum NamedColor { enum NamedColor
{
Black, Black,
White, White,
Red, Red,
@ -35,8 +36,14 @@ public:
Color() {} Color() {}
Color(NamedColor); Color(NamedColor);
Color(byte r, byte g, byte b) : m_value(0xff000000 | (r << 16) | (g << 8) | b) { } Color(byte r, byte g, byte b)
Color(byte r, byte g, byte b, byte a) : m_value((a << 24) | (r << 16) | (g << 8) | 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_rgb(unsigned rgb) { return Color(rgb | 0xff000000); }
static Color from_rgba(unsigned rgba) { return Color(rgba); } static Color from_rgba(unsigned rgba) { return Color(rgba); }
@ -94,7 +101,10 @@ public:
String to_string() const; String to_string() const;
private: private:
explicit Color(RGBA32 rgba) : m_value(rgba) { } explicit Color(RGBA32 rgba)
: m_value(rgba)
{
}
RGBA32 m_value { 0 }; RGBA32 m_value { 0 };
}; };

View file

@ -7,7 +7,10 @@ class DisjointRectSet {
public: public:
DisjointRectSet() {} DisjointRectSet() {}
~DisjointRectSet() {} ~DisjointRectSet() {}
DisjointRectSet(DisjointRectSet&& other) : m_rects(move(other.m_rects)) { } DisjointRectSet(DisjointRectSet&& other)
: m_rects(move(other.m_rects))
{
}
void add(const Rect&); void add(const Rect&);
@ -23,4 +26,3 @@ private:
Vector<Rect, 32> m_rects; Vector<Rect, 32> m_rects;
}; };

View file

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

View file

@ -1,15 +1,16 @@
#pragma once #pragma once
#include <SharedGraphics/Rect.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/MappedFile.h> #include <AK/MappedFile.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <SharedGraphics/Rect.h>
// FIXME: Make a MutableGlyphBitmap buddy class for FontEditor instead? // FIXME: Make a MutableGlyphBitmap buddy class for FontEditor instead?
class GlyphBitmap { class GlyphBitmap {
friend class Font; friend class Font;
public: public:
const unsigned* rows() const { return m_rows; } const unsigned* rows() const { return m_rows; }
unsigned row(unsigned index) const { return m_rows[index]; } 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/GraphicsBitmap.h>
#include <SharedGraphics/PNGLoader.h> #include <SharedGraphics/PNGLoader.h>
#include <AK/MappedFile.h> #include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
Retained<GraphicsBitmap> GraphicsBitmap::create(Format format, const Size& size) Retained<GraphicsBitmap> GraphicsBitmap::create(Format format, const Size& size)
{ {

View file

@ -3,16 +3,22 @@
#include "Color.h" #include "Color.h"
#include "Rect.h" #include "Rect.h"
#include "Size.h" #include "Size.h"
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/StringView.h>
#include <AK/MappedFile.h> #include <AK/MappedFile.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/StringView.h>
#include <SharedBuffer.h> #include <SharedBuffer.h>
class GraphicsBitmap : public Retainable<GraphicsBitmap> { class GraphicsBitmap : public Retainable<GraphicsBitmap> {
public: 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(Format, const Size&);
static Retained<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*); 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/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/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <SharedGraphics/puff.c>
#include <serenity.h>
//#define PNG_STOPWATCH_DEBUG //#define PNG_STOPWATCH_DEBUG
@ -125,7 +125,8 @@ RetainPtr<GraphicsBitmap> load_png(const StringView& path)
return c; return c;
} }
union [[gnu::packed]] Pixel { union [[gnu::packed]] Pixel
{
RGBA32 rgba { 0 }; RGBA32 rgba { 0 };
byte v[4]; byte v[4];
struct { struct {
@ -186,7 +187,8 @@ template<bool has_alpha, byte filter_type>
auto& x = pixels[i]; auto& x = pixels[i];
swap(x.r, x.b); swap(x.r, x.b);
Pixel a; Pixel a;
if (i != 0) a = pixels[i - 1]; if (i != 0)
a = pixels[i - 1];
const Pixel& b = pixels_y_minus_1[i]; const Pixel& b = pixels_y_minus_1[i];
x.v[0] = x.v[0] + ((a.v[0] + b.v[0]) / 2); 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); x.v[1] = x.v[1] + ((a.v[1] + b.v[1]) / 2);
@ -228,7 +230,12 @@ template<bool has_alpha, byte filter_type>
switch (context.color_type) { switch (context.color_type) {
case 2: case 2:
for (int y = 0; y < context.height; ++y) { for (int y = 0; y < context.height; ++y) {
struct [[gnu::packed]] Triplet { byte r; byte g; byte b; }; struct [[gnu::packed]] Triplet
{
byte r;
byte g;
byte b;
};
auto* triplets = (Triplet*)context.scanlines[y].data.pointer(); auto* triplets = (Triplet*)context.scanlines[y].data.pointer();
for (int i = 0; i < context.width; ++i) { for (int i = 0; i < context.width; ++i) {
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i]; auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];

View file

@ -8,7 +8,11 @@ struct WSAPI_Point;
class Point { class Point {
public: public:
Point() {} Point() {}
Point(int x, int y) : m_x(x) , m_y(y) { } Point(int x, int y)
: m_x(x)
, m_y(y)
{
}
Point(const WSAPI_Point&); Point(const WSAPI_Point&);
int x() const { return m_x; } int x() const { return m_x; }

View file

@ -7,7 +7,11 @@ struct WSAPI_Size;
class Size { class Size {
public: public:
Size() {} Size() {}
Size(int w, int h) : m_width(w), m_height(h) { } Size(int w, int h)
: m_width(w)
, m_height(h)
{
}
Size(const WSAPI_Size&); Size(const WSAPI_Size&);
bool is_null() const { return !m_width && !m_height; } bool is_null() const { return !m_width && !m_height; }
@ -23,8 +27,7 @@ public:
bool operator==(const Size& other) const bool operator==(const Size& other) const
{ {
return m_width == other.m_width && return m_width == other.m_width && m_height == other.m_height;
m_height == other.m_height;
} }
bool operator!=(const Size& other) const bool operator!=(const Size& other) const
@ -54,4 +57,3 @@ private:
int m_width { 0 }; int m_width { 0 };
int m_height { 0 }; int m_height { 0 };
}; };

View file

@ -1,5 +1,5 @@
#include <SharedGraphics/StylePainter.h>
#include <LibGUI/GPainter.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) 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); painter.set_pixel({ 1, 1 }, highlight_color2);
// Right side // Right side
painter.draw_line({ rect.width() - 1, 2, }, { rect.width() - 1, rect.height() - 1 }, shadow_color2); painter.draw_line({
painter.draw_line({ rect.width() - 2, 2, }, { rect.width() - 2, rect.height() - 1 }, shadow_color1); rect.width() - 1,
painter.set_pixel({ rect.width() - 2, 1, }, shadow_color2); 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) static void paint_button_new(Painter& painter, const Rect& rect, bool pressed, bool checked, bool hovered, bool enabled)
@ -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(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); 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 Painter;
class Rect; class Rect;
enum class ButtonStyle { Normal, CoolBar }; enum class ButtonStyle
enum class FrameShadow { Plain, Raised, Sunken }; {
enum class FrameShape { NoFrame, Box, Container, Panel, VerticalLine, HorizontalLine }; Normal,
CoolBar
};
enum class FrameShadow
{
Plain,
Raised,
Sunken
};
enum class FrameShape
{
NoFrame,
Box,
Container,
Panel,
VerticalLine,
HorizontalLine
};
class StylePainter { class StylePainter {
public: public:

View file

@ -1,6 +1,12 @@
#pragma once #pragma once
enum class TextAlignment { TopLeft, CenterLeft, Center, CenterRight }; enum class TextAlignment
{
TopLeft,
CenterLeft,
Center,
CenterRight
};
inline bool is_right_text_alignment(TextAlignment alignment) inline bool is_right_text_alignment(TextAlignment alignment)
{ {

View file

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

View file

@ -21,7 +21,6 @@
Mark Adler madler@alumni.caltech.edu Mark Adler madler@alumni.caltech.edu
*/ */
/* /*
* See puff.c for purpose and usage. * See puff.c for purpose and usage.
*/ */