| Directory: | source/ |
|---|---|
| File: | source/utils/ecs_graphics.c |
| Date: | 2023-12-18 09:27:49 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 25 | 65 | 38.5% |
| Branches: | 8 | 36 | 22.2% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Filename: ecs_graphics.c | ||
| 3 | * Path: sources/utils | ||
| 4 | * Created Date: Saturday, September 30th 2023, 5:01:43 pm | ||
| 5 | * Author: osvegn | ||
| 6 | * | ||
| 7 | * Copyright (c) 2023 ECS | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include "utils/ecs_graphics.h" | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <string.h> | ||
| 13 | |||
| 14 | 2 | int set_shape_color(shape_t *shape, ecs_color_t *color, shape_color_t type) | |
| 15 | { | ||
| 16 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (!shape || !color) |
| 17 | ✗ | return -1; | |
| 18 | 2 | shape->color[type] = *color; | |
| 19 | 2 | return 0; | |
| 20 | } | ||
| 21 | |||
| 22 | 1 | ecs_color_t *get_shape_color(shape_t *shape, shape_color_t type) | |
| 23 | { | ||
| 24 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!shape) |
| 25 | ✗ | return 0; | |
| 26 | 1 | return &shape->color[type]; | |
| 27 | } | ||
| 28 | |||
| 29 | 2 | int set_shape_thickness(shape_t *shape, float value) | |
| 30 | { | ||
| 31 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!shape) |
| 32 | ✗ | return -1; | |
| 33 | 2 | shape->thickness = value; | |
| 34 | 2 | return 0; | |
| 35 | } | ||
| 36 | |||
| 37 | 1 | float get_shape_thickness(shape_t *shape) | |
| 38 | { | ||
| 39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!shape) |
| 40 | ✗ | return -1; | |
| 41 | 1 | return shape->thickness; | |
| 42 | } | ||
| 43 | |||
| 44 | ✗ | int set_shape_is_filled(shape_t *shape, bool value) | |
| 45 | { | ||
| 46 | ✗ | if (!shape) | |
| 47 | ✗ | return -1; | |
| 48 | ✗ | shape->is_filled = value; | |
| 49 | ✗ | return 0; | |
| 50 | } | ||
| 51 | |||
| 52 | ✗ | bool get_shape_is_filled(shape_t *shape) | |
| 53 | { | ||
| 54 | ✗ | return shape->is_filled; | |
| 55 | } | ||
| 56 | |||
| 57 | 6 | int shape_constructor(shape_t *shape, int point_number) | |
| 58 | { | ||
| 59 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
|
18 | for (unsigned int i = 0; i < MAX; i++) { |
| 60 | 12 | shape->color[i] = (ecs_color_t){0, 0, 0, 0}; | |
| 61 | } | ||
| 62 | 6 | shape->texture_filename = 0; | |
| 63 | 6 | shape->thickness = 1.0f; | |
| 64 | 6 | shape->is_filled = true; | |
| 65 | 6 | return vector_constructor(&shape->points, sizeof(ecs_vector2f_t), point_number); | |
| 66 | } | ||
| 67 | |||
| 68 | 5 | int shape_destructor(shape_t *shape) | |
| 69 | { | ||
| 70 | 5 | shape->points.destructor(&shape->points); | |
| 71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (shape->texture_filename) |
| 72 | ✗ | free(shape->texture_filename); | |
| 73 | 5 | return 0; | |
| 74 | } | ||
| 75 | |||
| 76 | ✗ | int set_shape_points(shape_t *shape, vector_t *points) | |
| 77 | { | ||
| 78 | ✗ | if (!shape || !points) | |
| 79 | ✗ | return -1; | |
| 80 | ✗ | shape->points = *points; | |
| 81 | ✗ | return 0; | |
| 82 | } | ||
| 83 | |||
| 84 | ✗ | int set_shape_point(shape_t *shape, ecs_vector2f_t *point, int index) | |
| 85 | { | ||
| 86 | ✗ | if (!shape || !point) | |
| 87 | ✗ | return -1; | |
| 88 | ✗ | shape->points.emplace(&shape->points, point, index); | |
| 89 | ✗ | return 0; | |
| 90 | } | ||
| 91 | |||
| 92 | ✗ | int set_texture_filename(shape_t *shape, char *filename) | |
| 93 | { | ||
| 94 | ✗ | if (!shape || !filename) | |
| 95 | ✗ | return -1; | |
| 96 | ✗ | shape->texture_filename = strdup(filename); | |
| 97 | ✗ | return 0; | |
| 98 | } | ||
| 99 | |||
| 100 | ✗ | char *get_texture_filename(shape_t *shape) | |
| 101 | { | ||
| 102 | ✗ | if (!shape) | |
| 103 | ✗ | return 0; | |
| 104 | ✗ | return shape->texture_filename; | |
| 105 | } | ||
| 106 | |||
| 107 | ✗ | int set_texture(shape_t *shape, void *texture) | |
| 108 | { | ||
| 109 | ✗ | if (!shape || !texture) | |
| 110 | ✗ | return -1; | |
| 111 | ✗ | shape->texture = texture; | |
| 112 | ✗ | return 0; | |
| 113 | } | ||
| 114 | |||
| 115 | ✗ | void *get_texture(shape_t *shape) | |
| 116 | { | ||
| 117 | ✗ | if (!shape) | |
| 118 | ✗ | return 0; | |
| 119 | ✗ | return shape->texture; | |
| 120 | } | ||
| 121 |