Skip to content

Commit acd4179

Browse files
authored
Clean up rectangle code (#135)
* Move variable declarations to top * Remove unneeded semicolons * Apply astyle styling
1 parent 225afc5 commit acd4179

2 files changed

Lines changed: 23 additions & 33 deletions

File tree

include/hagl/rectangle.h

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
MIT License
55
6-
Copyright (c) 2018-2023 Mika Tuupola
6+
Copyright (c) 2018-2026 Mika Tuupola
77
88
Permission is hereby granted, free of charge, to any person obtaining a copy
99
of this software and associated documentation files (the "Software"), to deal
@@ -72,8 +72,7 @@ hagl_draw_rectangle_xyxy(void const *surface, int16_t x0, int16_t y0, int16_t x1
7272
* @param color
7373
*/
7474
static void inline
75-
hagl_draw_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, hagl_color_t color)
76-
{
75+
hagl_draw_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, hagl_color_t color) {
7776
hagl_draw_rectangle_xyxy(surface, x0, y0, x1, y1, color);
7877
}
7978

@@ -90,8 +89,7 @@ hagl_draw_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int
9089
* @param color
9190
*/
9291
static void inline
93-
hagl_draw_rectangle_xywh(void const *surface, int16_t x0, int16_t y0, uint16_t width, uint16_t height, hagl_color_t color)
94-
{
92+
hagl_draw_rectangle_xywh(void const *surface, int16_t x0, int16_t y0, uint16_t width, uint16_t height, hagl_color_t color) {
9593
hagl_draw_rectangle_xyxy(surface, x0, y0, x0 + width - 1, y0 + height - 1, color);
9694
};
9795

@@ -123,8 +121,7 @@ hagl_fill_rectangle_xyxy(void const *surface, int16_t x0, int16_t y0, int16_t x1
123121
* @param color
124122
*/
125123
static void inline
126-
hagl_fill_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, hagl_color_t color)
127-
{
124+
hagl_fill_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, hagl_color_t color) {
128125
hagl_fill_rectangle_xyxy(surface, x0, y0, x1, y1, color);
129126
}
130127

@@ -141,8 +138,7 @@ hagl_fill_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int
141138
* @param color
142139
*/
143140
static void inline
144-
hagl_fill_rectangle_xywh(void const *surface, int16_t x0, int16_t y0, uint16_t width, uint16_t height, hagl_color_t color)
145-
{
141+
hagl_fill_rectangle_xywh(void const *surface, int16_t x0, int16_t y0, uint16_t width, uint16_t height, hagl_color_t color) {
146142
hagl_fill_rectangle_xyxy(surface, x0, y0, x0 + width - 1, y0 + height - 1, color);
147143
};
148144

@@ -176,8 +172,7 @@ hagl_draw_rounded_rectangle_xyxy(void const *surface, int16_t x0, int16_t y0, in
176172
* @param color
177173
*/
178174
static void inline
179-
hagl_draw_rounded_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, hagl_color_t color)
180-
{
175+
hagl_draw_rounded_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, hagl_color_t color) {
181176
hagl_draw_rounded_rectangle_xyxy(surface, x0, y0, x1, y1, r, color);
182177
}
183178

@@ -195,8 +190,7 @@ hagl_draw_rounded_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t
195190
* @param color
196191
*/
197192
static void inline
198-
hagl_draw_rounded_rectangle_xywh(void const *surface, int16_t x0, int16_t y0, uint16_t width, uint16_t height, int16_t r, hagl_color_t color)
199-
{
193+
hagl_draw_rounded_rectangle_xywh(void const *surface, int16_t x0, int16_t y0, uint16_t width, uint16_t height, int16_t r, hagl_color_t color) {
200194
hagl_draw_rounded_rectangle_xyxy(surface, x0, y0, x0 + width - 1, y0 + height - 1, r, color);
201195
}
202196

@@ -230,8 +224,7 @@ hagl_fill_rounded_rectangle_xyxy(void const *surface, int16_t x0, int16_t y0, in
230224
* @param color
231225
*/
232226
static void inline
233-
hagl_fill_rounded_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, hagl_color_t color)
234-
{
227+
hagl_fill_rounded_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, hagl_color_t color) {
235228
hagl_fill_rounded_rectangle_xyxy(surface, x0, y0, x1, y1, r, color);
236229
}
237230

@@ -249,8 +242,7 @@ hagl_fill_rounded_rectangle(void const *surface, int16_t x0, int16_t y0, int16_t
249242
* @param color
250243
*/
251244
static void inline
252-
hagl_fill_rounded_rectangle_xywh(void const *surface, int16_t x0, int16_t y0, uint16_t width, uint16_t height, int16_t r, hagl_color_t color)
253-
{
245+
hagl_fill_rounded_rectangle_xywh(void const *surface, int16_t x0, int16_t y0, uint16_t width, uint16_t height, int16_t r, hagl_color_t color) {
254246
hagl_fill_rounded_rectangle_xyxy(surface, x0, y0, x0 + width - 1, y0 + height - 1, r, color);
255247
}
256248

@@ -259,4 +251,4 @@ hagl_fill_rounded_rectangle_xywh(void const *surface, int16_t x0, int16_t y0, ui
259251
}
260252
#endif /* __cplusplus */
261253

262-
#endif /* _HAGL_RECTANGLE_H */
254+
#endif /* _HAGL_RECTANGLE_H */

src/hagl_rectangle.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
MIT License
44
5-
Copyright (c) 2018-2023 Mika Tuupola
5+
Copyright (c) 2018-2026 Mika Tuupola
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
@@ -44,9 +44,9 @@ SPDX-License-Identifier: MIT
4444
#define MAX(a,b) (((a)>(b))?(a):(b))
4545

4646
void
47-
hagl_draw_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, hagl_color_t color)
48-
{
47+
hagl_draw_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, hagl_color_t color) {
4948
const hagl_surface_t *surface = _surface;
49+
uint16_t width, height;
5050

5151
/* Make sure x0 is smaller than x1. */
5252
if (x0 > x1) {
@@ -72,8 +72,8 @@ hagl_draw_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x
7272
return;
7373
}
7474

75-
uint16_t width = x1 - x0 + 1;
76-
uint16_t height = y1 - y0 + 1;
75+
width = x1 - x0 + 1;
76+
height = y1 - y0 + 1;
7777

7878
hagl_draw_hline(surface, x0, y0, width, color);
7979
hagl_draw_hline(surface, x0, y1, width, color);
@@ -82,9 +82,9 @@ hagl_draw_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x
8282
}
8383

8484
void
85-
hagl_fill_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, hagl_color_t color)
86-
{
85+
hagl_fill_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, hagl_color_t color) {
8786
const hagl_surface_t *surface = _surface;
87+
uint16_t width, height;
8888

8989
/* Make sure x0 is smaller than x1. */
9090
if (x0 > x1) {
@@ -115,8 +115,8 @@ hagl_fill_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x
115115
x1 = MIN(x1, surface->clip.x1);
116116
y1 = MIN(y1, surface->clip.y1);
117117

118-
uint16_t width = x1 - x0 + 1;
119-
uint16_t height = y1 - y0 + 1;
118+
width = x1 - x0 + 1;
119+
height = y1 - y0 + 1;
120120

121121
for (uint16_t i = 0; i < height; i++) {
122122
if (surface->hline) {
@@ -129,8 +129,7 @@ hagl_fill_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x
129129
}
130130

131131
void
132-
hagl_draw_rounded_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, hagl_color_t color)
133-
{
132+
hagl_draw_rounded_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, hagl_color_t color) {
134133
const hagl_surface_t *surface = _surface;
135134

136135
uint16_t width, height;
@@ -200,11 +199,10 @@ hagl_draw_rounded_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, i
200199
hagl_put_pixel(surface, x0 + r - x, y1 - r + y, color);
201200
hagl_put_pixel(surface, x0 + r - y, y1 - r + x, color);
202201
}
203-
};
202+
}
204203

205204
void
206-
hagl_fill_rounded_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, hagl_color_t color)
207-
{
205+
hagl_fill_rounded_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, hagl_color_t color) {
208206
const hagl_surface_t *surface = _surface;
209207

210208
uint16_t width, height;
@@ -282,4 +280,4 @@ hagl_fill_rounded_rectangle_xyxy(void const *_surface, int16_t x0, int16_t y0, i
282280

283281
/* Center */
284282
hagl_fill_rectangle_xyxy(surface, x0, y0 + r, x1, y1 - r, color);
285-
};
283+
}

0 commit comments

Comments
 (0)