Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nightly #2

Merged
merged 14 commits into from
Nov 5, 2019
Prev Previous commit
Added doxygen documentation to every function
  • Loading branch information
gorbit99 committed Nov 5, 2019
commit 5c77954138d7c1deee4a487050ea1e05ac76efb0
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ find_package(SDL2_image REQUIRED)

add_executable(${PROJECT_NAME} main.c Graphics.c Graphics.h debugmalloc.h debugmalloc-impl.h Component.c Component.h
Utility.c Utility.h Window.c Window.h Input.c Input.h Node.c Node.h Parser.c Parser.h
NodeVector.c NodeVector.h Camera.c Camera.h GUIGraphics.c GUIGraphics.h NodeEvent.c
NodeEvent.h Wire.c Wire.h)
NodeVector.c NodeVector.h Camera.c Camera.h GUIGraphics.c GUIGraphics.h Wire.c Wire.h)

set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99)

Expand Down
39 changes: 37 additions & 2 deletions Camera.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
#ifndef HOMEWORK_CAMERA_H
#define HOMEWORK_CAMERA_H

/**
* @file Camera.h
* @brief Structures and information related to the camera system
* @version 0.1
* @date 2019-11-05
*
* @copyright Copyright (c) 2019
*
*/

#include "Graphics.h"

/**
* @brief Stores camera data
*
*/
typedef struct Camera {
Point position;
float zoom;
Point position; /**< Position */
float zoom; /**< Zoom amount (0 - 1) */
} Camera;

/**
* @brief Zooms in camera to the zoom position
*
* @param camera The camera struct to zoom with
* @param zoomLevels Relatively how much to zoom
* @param zoomPos Position to zoom in to
*/
void camera_zoom(Camera *camera, float zoomLevels, Point zoomPos);

/**
* @brief Moves camera taking the zoom into account
*
* @param camera The camera struct to move with
* @param movement Amount to move
*/
void camera_move(Camera *camera, Vec movement);

/**
* @brief Get screen position relative to the world
*
* @param camera The camera struct to do the calculations with
* @param p The point to transform
* @return Point The resulting point in world space
*/
Point camera_screen_to_view(Camera *camera, Point p);

#endif //HOMEWORK_CAMERA_H
164 changes: 144 additions & 20 deletions Component.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#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>
Expand All @@ -9,62 +19,176 @@
#include "Graphics.h"
#include "Parser.h"

extern const float COMPSIZE;
extern const float COMPTHICKNESS;
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,
PIN_OUT
PIN_IN, /**< Input pin */
PIN_OUT /** < Output pin */
} PinType;

/**
* @brief Type of a component
*
*/
typedef enum ComponentType {
CT_MODULE,
CT_WIRE,
CT_SWITCH,
CT_LED
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];
PinType type;
float angle;
Point pos;
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 */
} Pin;

/**
* @brief Data of all pins on a component
*
*/
typedef struct PinData {
Pin *pins;
int pinCount;
Pin *pins; /**< Array of all pins */
int pinCount; /**< Number of pins */
} PinData;

/**
* @brief Component
*
*/
typedef struct ComponentData {
float x, y;
int w, h;
SDL_Texture *texture;
PinData pinData;
FunctionData funData;
ComponentType type;
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 */
} 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);

#endif //HOMEWORK_COMPONENT_H
61 changes: 53 additions & 8 deletions GUIGraphics.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,72 @@
#ifndef HOMEWORK_GUIGRAPHICS_H
#define HOMEWORK_GUIGRAPHICS_H

/**
* @file GUIGraphics.h
* @brief Structures and functions related to GUI Graphics
* @version 0.1
* @date 2019-11-05
*
* @copyright Copyright (c) 2019
*
*/

#include <SDL.h>
#include <SDL_image.h>
#include <stdbool.h>
#include "Utility.h"

/**
* @brief Type of a 9-slice texture
*
*/
typedef enum SliceType {
ST_CLAMP,
ST_REPEAT
ST_CLAMP, /**< Clamp the texture to the edges */
ST_REPEAT /**< Repeat texture over the given area */
} SliceType;

/**
* @brief Data for a 9-slice texture
*
*/
typedef struct NSliceTexture {
SDL_Texture *texture;
int w, h;
SliceType type;
int x1, y1, x2, y2;
int w1, w2, w3;
int h1, h2, h3;
SDL_Texture *texture; /**< Texture */
int w, /**< Width */
h; /**< Height */
SliceType type; /**< Type of the texture */
int x1, /**< Relative position of the first vertical slice */
y1, /**< Relative position of the first horizontal slice */
x2, /**< Relative position of the second vertical slice */
y2; /**< Relative position of the second horizontal slice */
int w1, /**< Width of the first inner slice */
w2, /**< Width of the second inner slice */
w3; /**< Width of the third inner slice */
int h1, /**< Height of the first inner slice */
h2, /**< Height of the second inner slice */
h3; /**< Height of the third inner slice */
} NSliceTexture;

/**
* @brief Create 9-slice texture
*
* @param path Path to load image from
* @param type Type of the texture
* @param x1 First vertical slice x position
* @param y1 First horizontal slice y position
* @param x2 Second vertical slice x position
* @param y2 Second horizontal slice y position
* @param renderer Renderer to send texture to
* @return NSliceTexture Resulting 9-slice texture
*/
NSliceTexture guigfx_create_nslice(char *path, SliceType type, int x1, int y1, int x2, int y2, SDL_Renderer *renderer);

/**
* @brief Render 9-slice texture into given area
*
* @param data Texture to render
* @param rect Rect to render to
* @param renderer Renderer to render with
*/
void guigfx_render_9slice(NSliceTexture *data, SDL_Rect rect, SDL_Renderer *renderer);

#endif //HOMEWORK_GUIGRAPHICS_H
Loading