-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphics.h
155 lines (138 loc) · 3.59 KB
/
Graphics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef HOMEWORK_GRAPHICS_H
#define HOMEWORK_GRAPHICS_H
/**
* @file Graphics.h
* @brief Structures and functions related to drawing shapes
* @version 0.1
* @date 2019-11-05
*
* @copyright Copyright (c) 2019
*
*/
#include "debugmalloc.h"
#include <stddef.h>
#include <stdbool.h>
#include <math.h>
#include <SDL.h>
#include <SDL_ttf.h>
#include <assert.h>
/**
* @brief Represents a point
*
*/
typedef struct Point {
float x, /**< X Position */
y; /**< Y Position */
} Point;
/**
* @brief Represents a vector
*
*/
typedef Point Vec;
/**
* @brief Represents a color
*
*/
typedef uint32_t Color;
/**
* @brief Draw one pixel line between two points
*
* @param dest Surface to draw to
* @param V1 First point
* @param V2 Second point
* @param color Color to use
*/
void gfx_draw_line(SDL_Surface *dest, Point V1, Point V2, Color color);
/**
* @brief Draw a one pixel outline around the given triangle
*
* @param dest Surface to draw to
* @param V1 First point
* @param V2 Second point
* @param V3 Third point
* @param color Color to use
*/
void gfx_draw_triangle(SDL_Surface *dest, Point V1, Point V2, Point V3, Color color);
/**
* @brief Fill the given triangle
*
* @param dest Surface to draw to
* @param V1 First point
* @param V2 Second point
* @param V3 Third point
* @param color Color to use
*/
void gfx_fill_triangle(SDL_Surface *dest, Point V1, Point V2, Point V3, Color color);
/**
* @brief Draw a line with thickness
*
* @param dest Surface to draw to
* @param V1 First point
* @param V2 Second point
* @param thickness Thickness of the line
* @param color Color to use
*/
void gfx_draw_thick_line(SDL_Surface *dest, Point V1, Point V2, float thickness, Color color);
/**
* @brief Draw one pixel circle around point with radius
*
* @param dest Surface to draw to
* @param C Center position
* @param r Radius
* @param color Color to use
*/
void gfx_draw_circle(SDL_Surface *dest, Point C, float r, Color color);
/**
* @brief Fill circle with center and radius
*
* @param dest Surface to draw to
* @param C Center position
* @param r Radius
* @param color Color to use
*/
void gfx_fill_circle(SDL_Surface *dest, Point C, float r, Color color);
/**
* @brief Draw quadratic bezier curve with given information
*
* @param dest Surface to draw to
* @param V1 First endpoint
* @param V2 Second endpoint
* @param C Control point
* @param thickness Thickness of curve
* @param color Color to use
*/
void gfx_draw_bezier(SDL_Surface *dest, Point V1, Point V2, Point C, float thickness, Color color);
/**
* @brief Draw a cubic bezier curve with given information
*
* @param dest Surface to draw to
* @param V1 First endpoint
* @param V2 Second enpoint
* @param C1 First control point
* @param C2 Second control point
* @param thickness Thickness of the curve
* @param color Color to use
*/
void gfx_draw_bezier_cubic(SDL_Surface *dest, Point V1, Point V2, Point C1, Point C2, float thickness, Color color);
/**
* @brief Draw text at given position
*
* @param dest Surface to draw to
* @param font Font to use
* @param x Top left X
* @param y Top left Y
* @param str String to draw
* @param color Color to use
*/
void gfx_draw_text(SDL_Surface *dest, TTF_Font *font, int x, int y, const char *str, Color color);
/**
* @brief Fill ring around given point with radius and thickness
*
* @param dest Surface to draw to
* @param C Center position
* @param r Radius
* @param thickness Thickness of the curve
* @param color Color to use
*/
void gfx_fill_ring(SDL_Surface *dest, Point C, float r, float thickness, Color color);
#endif //HOMEWORK_GRAPHICS_H