summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2017-12-28 21:52:04 +0100
committerOlivier Gayot <duskcoder@gmail.com>2017-12-28 21:52:04 +0100
commit3282ab0cd838ab7e070021cd2a537d78e60d263a (patch)
treea05ead754b3dd1ac8bf2dc9549c77d5ab135d238
Imported sources files into the Git
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--Makefile59
-rw-r--r--include/draw.h54
-rw-r--r--include/sdl_digit.h49
-rw-r--r--src/bar.c252
-rw-r--r--src/digit.c362
-rw-r--r--src/line.c56
-rw-r--r--src/pixel.c69
-rw-r--r--src/rect.c31
-rw-r--r--src/string.c37
9 files changed, 969 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..683aecf
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,59 @@
+##
+## Makefile for in /home/gayot_o/prog/lib/sdl-digit
+##
+## Made by olivier gayot
+## Login <gayot_o@epitech.net>
+##
+## Started on Mon Apr 23 04:13:10 2012 olivier gayot
+## Last update Mon Apr 23 04:13:10 2012 olivier gayot
+##
+
+CC ?= gcc
+CFLAGS += -W -Wall -pedantic -std=c99 -Wextra -O3 `sdl-config --cflags`
+CFLAGS += -I./include
+HEADERS = include/sdl_digit.h
+LDFLAGS += `sdl-config --libs` -lm
+LDFLAGS += -L./lib
+SRC_DIR = src
+
+SRC = line.c \
+ bar.c \
+ rect.c \
+ pixel.c \
+ digit.c \
+ string.c
+SRC := $(addprefix $(SRC_DIR)/, $(SRC))
+OBJ = $(SRC:.c=.o)
+NAME = libsdl-digit.a
+DEBUG = -g
+RENDU = -D PRAG
+
+all: $(NAME)
+
+$(NAME): $(OBJ)
+ @echo 'Creating archive $(NAME)'
+ @$(AR) $(ARFLAGS) $(NAME) $(OBJ)
+ @echo 'done.'
+ @echo 'Generating index for $(NAME)'
+ @ranlib $(NAME)
+ @echo 'done.'
+
+clean:
+ @echo 'Cleaning obj files'
+ @$(RM) $(OBJ)
+ @echo 'done.'
+
+fclean: clean
+ @echo 'Cleaning $(NAME)'
+ @$(RM) $(NAME)
+ @echo 'done'
+
+re: fclean all
+
+install:
+ @echo '######## Installing $(basename $(NAME)) ########'
+ cp $(NAME) /usr/lib/
+ cp $(HEADERS) /usr/include/sdl-digit/
+
+debug: CFLAGS += $(DEBUG)
+debug: re
diff --git a/include/draw.h b/include/draw.h
new file mode 100644
index 0000000..66401fc
--- /dev/null
+++ b/include/draw.h
@@ -0,0 +1,54 @@
+/*
+** draw.h for in /home/gayot_o/prog/lib/sdl-digit/include
+**
+** Made by olivier gayot
+** Login <gayot_o@epitech.net>
+**
+** Started on Wed Apr 25 03:36:16 2012 olivier gayot
+** Last update Wed Apr 25 03:36:16 2012 olivier gayot
+*/
+
+#ifndef DRAW_H_
+# define DRAW_H_
+
+static void draw_0(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_1(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_2(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_3(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_4(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_5(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_6(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_7(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_8(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_9(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_hyphen(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_space(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+
+static void draw_A(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_B(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_C(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_D(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_E(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_F(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_G(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_H(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_I(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_J(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_K(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_L(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_M(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_N(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_O(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_P(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_Q(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_R(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_S(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_T(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_U(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_V(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_W(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_X(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_Y(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+static void draw_Z(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+
+#endif /* !DRAW_H_*/
diff --git a/include/sdl_digit.h b/include/sdl_digit.h
new file mode 100644
index 0000000..d383229
--- /dev/null
+++ b/include/sdl_digit.h
@@ -0,0 +1,49 @@
+/*
+** sdl_digit.h for in /home/gayot_o/prog/lib/sdl-digit
+**
+** Made by olivier gayot
+** Login <gayot_o@epitech.net>
+**
+** Started on Mon Apr 23 08:07:05 2012 olivier gayot
+** Last update Mon Apr 23 08:07:05 2012 olivier gayot
+*/
+
+#ifndef SDL_DIGIT_H_
+# define SDL_DIGIT_H_
+
+# include <math.h>
+# include <SDL/SDL.h>
+
+typedef struct {
+ float x;
+ float y;
+ float z;
+} t_vect;
+
+typedef union {
+ Uint8 *char_;
+ Uint16 *short_;
+ Uint32 *int_;
+} union_;
+
+void draw_horizontal_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+void draw_semi_horizontal_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+void draw_vertical_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+void draw_semi_vertical_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+void draw_slash_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+void draw_backslash_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+void draw_diag_right_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+void draw_diag_left_bar(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color);
+void draw_line(SDL_Surface *surf, SDL_Rect begin, SDL_Rect end, Uint32);
+SDL_Rect get_rect(int x, int y, unsigned int w, unsigned int h);
+Uint32 get_pixel_color(SDL_Surface *surf, int x, int y);
+void set_pixel_color(SDL_Surface *surf, int x, int y, Uint32);
+SDL_Rect *new_rect(int x, int y, unsigned int w, unsigned int h);
+int draw_digit(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color, char d);
+void draw_bar_id(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color, int id);
+void draw_string(SDL_Surface *surf, SDL_Rect *rect, const char *str, Uint32 color, int size);
+SDL_Surface *new_string(const char *str, Uint32 color, int size);
+
+# define ABS(x) (((x) < 0) ? (-(x)) : (x))
+
+#endif /* !SDL_DIGIT_H_*/
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_);
+}
diff --git a/src/digit.c b/src/digit.c
new file mode 100644
index 0000000..e2f675c
--- /dev/null
+++ b/src/digit.c
@@ -0,0 +1,362 @@
+/*
+** digit.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:16:00 2012 olivier gayot
+** Last update Mon Apr 23 08:16:00 2012 olivier gayot
+*/
+
+#include <strings.h>
+#include "sdl_digit.h"
+
+#include "draw.h"
+
+int draw_digit(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color, char d) {
+ void (*f_ptr[256])(SDL_Surface *, SDL_Rect *, int, Uint32);
+
+ memset((void *)f_ptr, 0, sizeof(f_ptr));
+ f_ptr[(int)'0'] = &draw_0;
+ f_ptr[(int)'1'] = &draw_1;
+ f_ptr[(int)'2'] = &draw_2;
+ f_ptr[(int)'3'] = &draw_3;
+ f_ptr[(int)'4'] = &draw_4;
+ f_ptr[(int)'5'] = &draw_5;
+ f_ptr[(int)'6'] = &draw_6;
+ f_ptr[(int)'7'] = &draw_7;
+ f_ptr[(int)'8'] = &draw_8;
+ f_ptr[(int)'9'] = &draw_9;
+ f_ptr[(int)'-'] = &draw_hyphen;
+ f_ptr[(int)' '] = &draw_space;
+ f_ptr[(int)'a'] = &draw_A;
+ f_ptr[(int)'A'] = &draw_A;
+ f_ptr[(int)'b'] = &draw_B;
+ f_ptr[(int)'B'] = &draw_B;
+ f_ptr[(int)'c'] = &draw_C;
+ f_ptr[(int)'C'] = &draw_C;
+ f_ptr[(int)'d'] = &draw_D;
+ f_ptr[(int)'D'] = &draw_D;
+ f_ptr[(int)'e'] = &draw_E;
+ f_ptr[(int)'E'] = &draw_E;
+ f_ptr[(int)'f'] = &draw_F;
+ f_ptr[(int)'F'] = &draw_F;
+ f_ptr[(int)'g'] = &draw_G;
+ f_ptr[(int)'G'] = &draw_G;
+ f_ptr[(int)'h'] = &draw_H;
+ f_ptr[(int)'H'] = &draw_H;
+ f_ptr[(int)'i'] = &draw_I;
+ f_ptr[(int)'I'] = &draw_I;
+ f_ptr[(int)'j'] = &draw_J;
+ f_ptr[(int)'J'] = &draw_J;
+ f_ptr[(int)'K'] = &draw_K;
+ f_ptr[(int)'k'] = &draw_K;
+ f_ptr[(int)'l'] = &draw_L;
+ f_ptr[(int)'L'] = &draw_L;
+ f_ptr[(int)'m'] = &draw_M;
+ f_ptr[(int)'M'] = &draw_M;
+ f_ptr[(int)'n'] = &draw_N;
+ f_ptr[(int)'N'] = &draw_N;
+ f_ptr[(int)'o'] = &draw_O;
+ f_ptr[(int)'O'] = &draw_O;
+ f_ptr[(int)'p'] = &draw_P;
+ f_ptr[(int)'P'] = &draw_P;
+ f_ptr[(int)'q'] = &draw_Q;
+ f_ptr[(int)'Q'] = &draw_Q;
+ f_ptr[(int)'r'] = &draw_R;
+ f_ptr[(int)'R'] = &draw_R;
+ f_ptr[(int)'s'] = &draw_S;
+ f_ptr[(int)'S'] = &draw_S;
+ f_ptr[(int)'t'] = &draw_T;
+ f_ptr[(int)'T'] = &draw_T;
+ f_ptr[(int)'u'] = &draw_U;
+ f_ptr[(int)'U'] = &draw_U;
+ f_ptr[(int)'V'] = &draw_V;
+ f_ptr[(int)'v'] = &draw_V;
+ f_ptr[(int)'w'] = &draw_W;
+ f_ptr[(int)'W'] = &draw_W;
+ f_ptr[(int)'x'] = &draw_X;
+ f_ptr[(int)'X'] = &draw_X;
+ f_ptr[(int)'y'] = &draw_Y;
+ f_ptr[(int)'Y'] = &draw_Y;
+ f_ptr[(int)'z'] = &draw_Z;
+ f_ptr[(int)'Z'] = &draw_Z;
+ if (!f_ptr[(int)d])
+ return 0;
+ f_ptr[(int)d](surf, rect, size, color);
+ return 1;
+}
+
+static void draw_0(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+static void draw_1(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 5);
+}
+static void draw_2(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+static void draw_3(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+static void draw_4(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 5);
+}
+static void draw_5(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+static void draw_6(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+static void draw_7(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 5);
+}
+static void draw_8(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+static void draw_9(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+
+static void draw_hyphen(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 3);
+}
+static void draw_space(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ (void)surf;
+ (void)rect;
+ (void)size;
+ (void)color;
+}
+
+static void draw_A(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+}
+
+static void draw_B(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+ draw_bar_id(surf, rect, size, color, 11);
+ draw_bar_id(surf, rect, size, color, 12);
+ draw_bar_id(surf, rect, size, color, 14);
+}
+
+static void draw_C(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+
+static void draw_D(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+ draw_bar_id(surf, rect, size, color, 11);
+ draw_bar_id(surf, rect, size, color, 12);
+}
+
+static void draw_E(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+
+static void draw_F(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 4);
+}
+
+static void draw_G(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+ draw_bar_id(surf, rect, size, color, 14);
+}
+
+static void draw_H(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+}
+
+static void draw_I(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 11);
+ draw_bar_id(surf, rect, size, color, 12);
+}
+
+static void draw_J(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+
+static void draw_K(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 7);
+ draw_bar_id(surf, rect, size, color, 10);
+}
+
+static void draw_L(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+
+static void draw_M(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 15);
+ draw_bar_id(surf, rect, size, color, 16);
+}
+
+static void draw_N(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 15);
+ draw_bar_id(surf, rect, size, color, 18);
+}
+
+static void draw_O(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_0(surf, rect, size, color);
+}
+
+static void draw_P(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 4);
+}
+
+static void draw_Q(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+ draw_bar_id(surf, rect, size, color, 18);
+}
+
+static void draw_R(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 18);
+}
+
+static void draw_S(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_5(surf, rect, size, color);
+}
+
+static void draw_T(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 11);
+ draw_bar_id(surf, rect, size, color, 12);
+}
+
+static void draw_U(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+}
+static void draw_V(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 19);
+ draw_bar_id(surf, rect, size, color, 20);
+}
+
+static void draw_W(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 4);
+ draw_bar_id(surf, rect, size, color, 5);
+ draw_bar_id(surf, rect, size, color, 6);
+ draw_bar_id(surf, rect, size, color, 12);
+}
+
+static void draw_X(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 15);
+ draw_bar_id(surf, rect, size, color, 16);
+ draw_bar_id(surf, rect, size, color, 17);
+ draw_bar_id(surf, rect, size, color, 18);
+}
+
+static void draw_Y(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 1);
+ draw_bar_id(surf, rect, size, color, 2);
+ draw_bar_id(surf, rect, size, color, 3);
+ draw_bar_id(surf, rect, size, color, 12);
+}
+
+static void draw_Z(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) {
+ draw_bar_id(surf, rect, size, color, 0);
+ draw_bar_id(surf, rect, size, color, 16);
+ draw_bar_id(surf, rect, size, color, 17);
+ draw_bar_id(surf, rect, size, color, 6);
+}
diff --git a/src/line.c b/src/line.c
new file mode 100644
index 0000000..6f0f749
--- /dev/null
+++ b/src/line.c
@@ -0,0 +1,56 @@
+/*
+** line.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:07:45 2012 olivier gayot
+** Last update Mon Apr 23 08:07:45 2012 olivier gayot
+*/
+
+#include "sdl_digit.h"
+
+static void perform_draw_line(SDL_Surface *, SDL_Rect, SDL_Rect, t_vect, Uint32);
+
+void draw_line(SDL_Surface *surf, SDL_Rect r1, SDL_Rect r2, Uint32 color) {
+ t_vect vect;
+ SDL_Rect begin, end;
+
+ if (ABS(r2.x - r1.x) > ABS(r2.y - r1.y)) {
+ if (r1.x < r2.x) {
+ begin = r1;
+ end = r2;
+ }
+ else {
+ begin = r2;
+ end = r1;
+ }
+ vect.x = 1;
+ vect.y = (float)(end.y - begin.y) / (float)(end.x - begin.x);
+ }
+ else {
+ if (r1.y < r2.y) {
+ begin = r1;
+ end = r2;
+ }
+ else {
+ begin = r2;
+ end = r1;
+ }
+ vect.y = 1;
+ vect.x = (float)(end.x - begin.x) / (float)(end.y - begin.y);
+ }
+ perform_draw_line(surf, begin, end, vect, color);
+}
+
+static void perform_draw_line(SDL_Surface *surf, SDL_Rect begin,
+ SDL_Rect end, t_vect vect, Uint32 color) {
+ float x = (float)begin.x;
+ float y = (float)begin.y;
+
+ while (x != (float)end.x || y != (float)end.y) {
+ set_pixel_color(surf, (int)x, (int)y, color);
+ x += vect.x;
+ y += vect.y;
+ }
+}
diff --git a/src/pixel.c b/src/pixel.c
new file mode 100644
index 0000000..abe756e
--- /dev/null
+++ b/src/pixel.c
@@ -0,0 +1,69 @@
+/*
+** pixel.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:13:46 2012 olivier gayot
+** Last update Mon Apr 23 08:13:46 2012 olivier gayot
+*/
+
+#include "sdl_digit.h"
+
+void set_pixel_color(SDL_Surface *surf,
+ int x, int y, Uint32 color) {
+ char *address = surf->pixels;
+ union_ cast_;
+
+ if (x >= surf->w || y >= surf->h || x < 0 || y < 0)
+ return;
+ address += surf->pitch * y;
+ address += x * surf->format->BytesPerPixel;
+ switch (surf->format->BitsPerPixel) {
+ case 32:
+ cast_.int_ = (Uint32 *)address;
+ *cast_.int_ = color;
+ break;
+ case 24:
+ cast_.int_ = (Uint32 *)address;
+ *cast_.int_ = color;
+ break;
+ case 16:
+ cast_.short_ = (Uint16 *)address;
+ *cast_.short_ = color;
+ break;
+ case 8:
+ cast_.char_ = (Uint8 *)address;
+ *cast_.char_ = color;
+ break;
+ default:
+ return;
+ break;
+ }
+}
+
+Uint32 get_pixel_color(SDL_Surface *surf, int x, int y) {
+ char *address = surf->pixels;
+
+ if (x >= surf->w || y >= surf->h || x < 0 || y < 0)
+ return 0;
+ address += surf->pitch * y;
+ address += x * surf->format->BytesPerPixel;
+ switch (surf->format->BitsPerPixel) {
+ case 32:
+ return ((Uint32)*((Uint32 *)address));
+ break;
+ case 24:
+ return ((Uint32)*((Uint32 *)address));
+ break;
+ case 16:
+ return ((Uint32)*((Uint16 *)address));
+ break;
+ case 8:
+ return ((Uint32)*((Uint8 *)address));
+ break;
+ default:
+ return ((Uint32)0);
+ break;
+ }
+}
diff --git a/src/rect.c b/src/rect.c
new file mode 100644
index 0000000..19ed87f
--- /dev/null
+++ b/src/rect.c
@@ -0,0 +1,31 @@
+/*
+** rect.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:12:40 2012 olivier gayot
+** Last update Mon Apr 23 08:12:40 2012 olivier gayot
+*/
+
+#include "sdl_digit.h"
+
+SDL_Rect get_rect(int x, int y, unsigned int w, unsigned int h) {
+ SDL_Rect rect;
+
+ rect.x = x;
+ rect.y = y;
+ rect.w = w;
+ rect.h = h;
+ return rect;
+}
+
+SDL_Rect *new_rect(int x, int y, unsigned int w, unsigned int h) {
+ SDL_Rect *rect = (SDL_Rect *)malloc(sizeof(SDL_Rect));
+
+ rect->x = x;
+ rect->y = y;
+ rect->w = w;
+ rect->h = h;
+ return rect;
+}
diff --git a/src/string.c b/src/string.c
new file mode 100644
index 0000000..ce93e88
--- /dev/null
+++ b/src/string.c
@@ -0,0 +1,37 @@
+/*
+** string.c for in /home/gayot_o/prog/lib/sdl-digit
+**
+** Made by olivier gayot
+** Login <gayot_o@epitech.net>
+**
+** Started on Mon Apr 23 11:08:25 2012 olivier gayot
+** Last update Mon Apr 23 11:08:25 2012 olivier gayot
+*/
+
+#include <string.h>
+#include "sdl_digit.h"
+
+void draw_string(SDL_Surface *surf, SDL_Rect *rect, const char *str, Uint32 color, int size) {
+ SDL_Rect rect_;
+
+ rect_.x = (rect) ? rect->x : 0;
+ rect_.y = (rect) ? rect->y : 0;
+ while (*str) {
+ if (draw_digit(surf, &rect_, size, color, *str))
+ rect_.x += size * 150. / 100.;
+ ++str;
+ }
+}
+
+SDL_Surface *new_string(const char *str, Uint32 color, int size)
+{
+ SDL_Surface *surf;
+ int w;
+ int h;
+
+ w = (size * 150. / 100.) * strlen(str);;
+ h = (size * 2) + (size / 5);
+ surf = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, 32, 0, 0, 0, 0);
+ draw_string(surf, NULL, str, color, size);
+ return (surf);
+}