-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponent.h
More file actions
198 lines (177 loc) · 5.41 KB
/
Component.h
File metadata and controls
198 lines (177 loc) · 5.41 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#ifndef HOMEWORK_COMPONENT_H
#define HOMEWORK_COMPONENT_H
/**
* @file Component.h
* @brief Structures and functions related to components
* @version 0.1
* @date 2019-11-05
*
* @copyright Copyright (c) 2019
*
*/
#include <SDL.h>
#include <stdio.h>
#include <math.h>
#include "Utility.h"
#include "Graphics.h"
#include "Parser.h"
extern const float COMPSIZE; /**< Size of each component */
extern const float COMPTHICKNESS; /**< Thickness of the lines */
/**
* @brief Type of a pin
*
*/
typedef enum PinType {
PIN_IN, /**< Input pin */
PIN_OUT /** < Output pin */
} PinType;
/**
* @brief Type of a component
*
*/
typedef enum ComponentType {
CT_MODULE, /**< Module */
CT_WIRE, /**< Wire */
CT_SWITCH, /**< Switch */
CT_LED /**< Led */
} ComponentType;
/**
* @brief Data about a single pin
*
*/
typedef struct Pin {
char name[17]; /**< Name of pin (display if a module) */
PinType type; /**< Type of the pin */
float angle; /**< Angle of the wire coming out of the pin */
Point pos; /**< Position of the pin relative to the component */
bool occupied; /**< Is the pin (if input) already occupied */
} Pin;
/**
* @brief Data of all pins on a component
*
*/
typedef struct PinData {
Pin *pins; /**< Array of all pins */
int pinCount; /**< Number of pins */
} PinData;
/**
* @brief Component
*
*/
typedef struct ComponentData {
float x, /**< X Position of the component */
y; /**< Y Position of the component */
int w, /**< Width of the component */
h; /**< Height of the component */
SDL_Texture *texture; /**< Texture for the component */
PinData pinData; /**< Pins of the component */
FunctionData funData; /**< Function of the component */
ComponentType type; /**< Type of the component */
char *name; /**< Name of the component */
} ComponentData;
/**
* @brief Load the component's corresponding texture
*
* @param path Path to the .cmp file
* @param size Size to draw the component with
* @param thickness Thickness to draw the lines with
* @param font Font to draw the text with
* @return SDL_Surface* The resulting graphic
*/
SDL_Surface *component_load_graphic(const char *path, float size, float thickness, TTF_Font *font);
/**
* @brief Load the pin information for the component
*
* @param path Path to the .dat file
* @param size Size of the component
* @return PinData The resulting pindata
*/
PinData component_load_pin_data(const char *path, float size);
/**
* @brief Create a generic component
*
* @param x X position of the component
* @param y Y position of the component
* @param name File names for the component
* @param size Size of the component
* @param thickness Thickness of the lines
* @param font Font of the text
* @param renderer Renderer to send the texture to
* @return ComponentData Resulting component
*/
ComponentData component_create(float x, float y, char *name, float size, float thickness,
TTF_Font *font, SDL_Renderer *renderer);
/**
* @brief Free component
*
* @param dat Component to free
*/
void component_free_data(ComponentData *dat);
/**
* @brief Render component
*
* @param dat Component to render
* @param renderer Renderer to render component with
* @param camPos Position of the camera
* @param color Color of the component
*/
void component_render(ComponentData *dat, SDL_Renderer *renderer, Point camPos, Color color);
/**
* @brief Create a texture for a wire between 2 points
*
* @param V1 First position
* @param V2 Second position
* @param ang1 First angle
* @param ang2 Second angle
* @param size Size of the wire
* @param thickness Thickness of the line
* @param pin1Pos After the call, holds the position of the first pin relative to the surface
* @return SDL_Surface* Resulting graphic
*/
SDL_Surface *component_create_wire_texture(Point V1, Point V2, float ang1, float ang2, float size, float thickness, Point *pin1Pos);
/**
* @brief Create a wire component between two pins on the two specified components
*
* @param comp1 First component
* @param comp2 Second component
* @param pin1 First pin
* @param pin2 Second pin
* @param size Size of the wire
* @param thickness Thickness of the wire
* @param renderer Renderer to send the texture to
* @return ComponentData Resulting component
*/
ComponentData component_create_wire_between(ComponentData *comp1, ComponentData *comp2, int pin1, int pin2,
float size, float thickness, SDL_Renderer *renderer);
/**
* @brief Create an LED component
*
* @param x X position
* @param y Y position
* @param size Size of the component
* @param thickness Thickness of the lines
* @param renderer Renderer to send the texture to
* @return ComponentData Resulting component
*/
ComponentData component_create_LED(float x, float y, float size, float thickness, SDL_Renderer *renderer);
/**
* @brief Create a Switch component
*
* @param x X position
* @param y Y position
* @param size Size of the component
* @param thickness Thickness of the lines
* @param renderer Renderer to send the texture to
* @return ComponentData Resulting component
*/
ComponentData component_create_switch(float x, float y, float size, float thickness, SDL_Renderer *renderer);
/**
* @brief Simulate component based on input
*
* @param component Component to simulate
* @param in Input values
* @param out Where to write output
*/
void component_run(ComponentData *component, bool *in, bool *out);
Point component_get_pin_position(ComponentData *componentData, int pin);
#endif //HOMEWORK_COMPONENT_H