summaryrefslogtreecommitdiff
path: root/src/bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bar.c')
-rw-r--r--src/bar.c252
1 files changed, 252 insertions, 0 deletions
diff --git a/src/bar.c b/src/bar.c
new file mode 100644
index 0000000..f498bb8
--- /dev/null
+++ b/src/bar.c
@@ -0,0 +1,252 @@
+/*
+** bar.c for in /home/gayot_o/prog/lib/sdl-digit
+**
+** Made by olivier gayot
+** Login <gayot_o@epitech.net>
+**
+** Started on Mon Apr 23 08:05:18 2012 olivier gayot
+** Last update Mon Apr 23 08:05:18 2012 olivier gayot
+*/
+
+#include "sdl_digit.h"
+
+void draw_horizontal_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ for (int j = 0; j < size / 5; ++j) {
+ int decal = ABS((size / 5) / 2 - j);
+ SDL_Rect begin = get_rect(rect->x + decal, rect->y + j, 0,0);
+ SDL_Rect end = get_rect(rect->x + size - decal, rect->y + j, 0,0);
+ draw_line(surf, begin, end, color);
+ }
+}
+
+void draw_semi_horizontal_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ for (int j = 0; j < size / 5; ++j) {
+ int decal = ABS((size / 5) / 2 - j);
+ SDL_Rect begin = get_rect(rect->x + decal, rect->y + j, 0,0);
+ SDL_Rect end = get_rect(rect->x + size / 2 - decal, rect->y + j, 0,0);
+ draw_line(surf, begin, end, color);
+ }
+}
+
+void draw_vertical_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ int l = size / 5;
+ for (int i = 0; i < l; ++i) {
+ int decal = ABS(l / 2 - i);
+ SDL_Rect begin = get_rect(rect->x + i, rect->y + decal, 0, 0);
+ SDL_Rect end = get_rect(rect->x + i, rect->y + size - decal, 0, 0);
+ draw_line(surf, begin, end, color);
+ }
+}
+
+void draw_semi_vertical_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ int l = size / 5;
+ for (int i = 0; i < l; ++i) {
+ int decal = ABS(l / 2 - i);
+ SDL_Rect begin = get_rect(rect->x + i, rect->y + decal, 0, 0);
+ SDL_Rect end = get_rect(rect->x + i, rect->y + size / 2 - decal, 0, 0);
+ draw_line(surf, begin, end, color);
+ }
+}
+
+void draw_diag_left_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ float l = ((float)size / 5.f);
+ int b = l / 2;
+ int h = size - 2 * b;
+ int a = (int)(l / (sqrtf(2.f)));
+ SDL_Rect begin;
+ SDL_Rect end;
+
+ for (int y = 0; y < h; ++y) {
+ begin.x = 0;
+ begin.y = rect->y + y;
+ end.x = a + y;
+ end.y = rect->y + y;
+ if (y > a)
+ begin.x += y - a;
+ if (y >= h - a)
+ end.x -= y - (h - a);
+ begin.x += rect->x;
+ end.x += rect->x;
+ draw_line(surf, begin, end, color);
+ }
+}
+
+void draw_diag_right_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ float l = ((float)size / 5.f);
+ int b = l / 2;
+ int h = size - 2 * b;
+ int a = (int)(l / (sqrtf(2.f)));
+ SDL_Rect begin;
+ SDL_Rect end;
+
+ for (int y = 0; y < h; ++y) {
+ begin.x = 0;
+ begin.y = rect->y + y;
+ end.x = a + y;
+ end.y = rect->y + y;
+ if (y > a)
+ begin.x += y - a;
+ if (y >= h - a)
+ end.x -= y - (h - a);
+ begin.x = h - begin.x;
+ end.x = h - end.x;
+ begin.x += rect->x;
+ end.x += rect->x;
+ draw_line(surf, begin, end, color);
+ }
+}
+
+void draw_backslash_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ float l = ((float)size / 5.f);
+ int b = l / 2;
+ int h = size - 2 * b;
+ int a = (int)(l / (sqrtf(2.f)));
+ SDL_Rect begin;
+ SDL_Rect end;
+
+ for (int y = 0; y < h; ++y) {
+ begin.y = rect->y + y;
+ end.y = rect->y + y;
+
+ begin.x = 0;
+ end.x = a + y / 2;
+
+ if (y > a)
+ begin.x += (y / 2) - a / 2;
+ if (y >= h - a)
+ end.x -= (y - (h - a)) / 2;
+ begin.x += rect->x;
+ end.x += rect->x;
+ draw_line(surf, begin, end, color);
+ }
+}
+
+void draw_slash_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ float l = ((float)size / 5.f);
+ int b = l / 2;
+ int h = size - 2 * b;
+ int a = (int)(l / (sqrtf(2.f)));
+ SDL_Rect begin;
+ SDL_Rect end;
+
+ for (int y = 0; y < h; ++y) {
+ begin.y = rect->y + y;
+ end.y = rect->y + y;
+
+ begin.x = 0;
+ end.x = a + y / 2;
+
+ if (y > a)
+ begin.x += (y / 2) - a / 2;
+ if (y >= h - a)
+ end.x -= (y - (h - a)) / 2;
+ begin.x = h / 2 - begin.x;
+ begin.x += rect->x;
+ end.x = h / 2 - end.x;
+ end.x += rect->x;
+ draw_line(surf, begin, end, color);
+ }
+}
+
+/* id is :
+ * 0
+ * 1 2
+ * 3
+ * 4 5
+ * 6
+ */
+
+void draw_bar_id(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color, int id) {
+ SDL_Rect *rect_;
+
+ switch (id) {
+ case 0:
+ rect_ = new_rect(rect->x + (size / 5) / 2, rect->y, 0, 0);
+ draw_horizontal_bar(surf, rect_, size, color);
+ break;
+ case 1:
+ rect_ = new_rect(rect->x, rect->y + (size / 5) / 2, 0, 0);
+ draw_vertical_bar(surf, rect_, size, color);
+ break;
+ case 2:
+ rect_ = new_rect(rect->x + size, rect->y + (size / 5) / 2, 0, 0);
+ draw_vertical_bar(surf, rect_, size, color);
+ break;
+ case 3:
+ rect_ = new_rect(rect->x + (size / 5) / 2, rect->y + size, 0, 0);
+ draw_horizontal_bar(surf, rect_, size, color);
+ break;
+ case 4:
+ rect_ = new_rect(rect->x, rect->y + size + (size / 5) / 2, 0, 0);
+ draw_vertical_bar(surf, rect_, size, color);
+ break;
+ case 5:
+ rect_ = new_rect(rect->x + size, rect->y + size + (size / 5) / 2, 0, 0);
+ draw_vertical_bar(surf, rect_, size, color);
+ break;
+ case 6:
+ rect_ = new_rect(rect->x + (size / 5) / 2, rect->y + size * 2, 0, 0);
+ draw_horizontal_bar(surf, rect_, size, color);
+ break;
+ case 7:
+ rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5), 0, 0);
+ draw_diag_right_bar(surf, rect_, size, color);
+ break;
+ case 8:
+ rect_ = new_rect(rect->x + (size / 5) + size, rect->y + (size / 5), 0, 0);
+ draw_diag_left_bar(surf, rect_, size, color);
+ break;
+ case 9:
+ rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5) + size, 0, 0);
+ draw_diag_right_bar(surf, rect_, size, color);
+ break;
+ case 10:
+ rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5) + size, 0, 0);
+ draw_diag_left_bar(surf, rect_, size, color);
+ break;
+ case 11:
+ rect_ = new_rect(rect->x + (size / 2), rect->y + (size / 5) / 2, 0, 0);
+ draw_vertical_bar(surf, rect_, size, color);
+ break;
+ case 12:
+ rect_ = new_rect(rect->x + (size / 2), rect->y + (size / 5) / 2 + size, 0, 0);
+ draw_vertical_bar(surf, rect_, size, color);
+ break;
+ case 13:
+ rect_ = new_rect(rect->x + (size / 5) / 2, rect->y + size, 0, 0);
+ draw_semi_horizontal_bar(surf, rect_, size, color);
+ break;
+ case 14:
+ rect_ = new_rect(rect->x + (size / 5) / 2 + size / 2, rect->y + size, 0, 0);
+ draw_semi_horizontal_bar(surf, rect_, size, color);
+ break;
+ case 15:
+ rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5), 0, 0);
+ draw_backslash_bar(surf, rect_, size, color);
+ break;
+ case 16:
+ rect_ = new_rect(rect->x + (size / 5) + size / 2, rect->y + (size / 5), 0, 0);
+ draw_slash_bar(surf, rect_, size, color);
+ break;
+ case 17:
+ rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5) + size, 0, 0);
+ draw_slash_bar(surf, rect_, size, color);
+ break;
+ case 18:
+ rect_ = new_rect(rect->x + (size / 5) + size / 2, rect->y + (size / 5) + size, 0, 0);
+ draw_backslash_bar(surf, rect_, size, color);
+ break;
+ case 19:
+ rect_ = new_rect(rect->x + (size / 5), rect->y + (size / 5) + size, 0, 0);
+ draw_backslash_bar(surf, rect_, size, color);
+ break;
+ case 20:
+ rect_ = new_rect(rect->x + (size / 5) + size / 2, rect->y + (size / 5) + size, 0, 0);
+ draw_slash_bar(surf, rect_, size, color);
+ break;
+ default:
+ return;
+ break;
+ }
+ free(rect_);
+}