Added ability to draw a non-filled rectangle
This commit is contained in:
1 parent
c1659dcf88
commit
a87eba8db7
7 files changed
+41
-8
No files matched your search
@@ -48,6 +48,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/engine_build_config.h
|
||||
include/aliases.h
|
||||
include/constants.h
|
||||
include/GameEngine.h
|
||||
include/Window.h
|
||||
|
||||
@@ -61,13 +61,14 @@ WindowSize get_window_real_size();
|
||||
*/
|
||||
WindowDrawingArea get_window_drawing_area();
|
||||
|
||||
void draw_rectangle(RenderRect rect, SDL_Color color);
|
||||
void fill_rectangle(RenderRect rect, SDL_Color color);
|
||||
|
||||
/**
|
||||
* Ensures that a rendered rectangle is clipped to the drawing area when it is
|
||||
* smaller than the actual size of the window.
|
||||
*/
|
||||
void clip_source_rect_to_drawing_area(RenderRect *src, RenderRect *dest);
|
||||
void clip_render_rects_to_drawing_area(RenderRect *src, RenderRect *dest);
|
||||
|
||||
RenderRect get_texture_asset_rect(AssetID id);
|
||||
void render_texture_asset(AssetID id, RenderRect *src, RenderRect *dest);
|
||||
|
||||
@@ -37,6 +37,8 @@ Renderer *create_renderer(SDL_Window *window);
|
||||
void get_render_output_size(Renderer *renderer, int32_t *w, int32_t *h);
|
||||
|
||||
void render_clear(const Renderer *renderer, SDL_Color color);
|
||||
void draw_rect(const Renderer *renderer, SDL_Color color, float x, float y,
|
||||
float w, float h);
|
||||
void fill_rect(const Renderer *renderer, SDL_Color color, float x, float y,
|
||||
float w, float h);
|
||||
void render_surface(const Renderer *renderer, SDL_Surface *surface,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef ALIASES_H
|
||||
#define ALIASES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // !__cplusplus
|
||||
|
||||
#define INTERNAL static
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !ALIASES_H
|
||||
@@ -5,8 +5,6 @@
|
||||
extern "C" {
|
||||
#endif // !__cplusplus
|
||||
|
||||
#define INTERNAL static
|
||||
|
||||
#define MAX_OBJ_COUNT 10000
|
||||
#define MAX_ASSET_COUNT 1000
|
||||
#define HASH_PRIME_01 1987
|
||||
|
||||
+13
-5
@@ -16,6 +16,7 @@
|
||||
#include "SDL_ttf.h"
|
||||
#include "SDL_video.h"
|
||||
#include "Window.h"
|
||||
#include "aliases.h"
|
||||
#include "constants.h"
|
||||
#include "engine_build_config.h"
|
||||
#include "reusable_ids.h"
|
||||
@@ -213,12 +214,17 @@ WindowDrawingArea get_window_drawing_area() {
|
||||
return GameEngine.window.drawing_area;
|
||||
}
|
||||
|
||||
void draw_rectangle(RenderRect rect, SDL_Color color) {
|
||||
draw_rect(GameEngine.window.renderer, color, rect.x, rect.y, rect.width,
|
||||
rect.height);
|
||||
}
|
||||
|
||||
void fill_rectangle(RenderRect rect, SDL_Color color) {
|
||||
fill_rect(GameEngine.window.renderer, color, rect.x, rect.y, rect.width,
|
||||
rect.height);
|
||||
}
|
||||
|
||||
void clip_source_rect_to_drawing_area(RenderRect *src, RenderRect *dest) {
|
||||
void clip_render_rects_to_drawing_area(RenderRect *src, RenderRect *dest) {
|
||||
WindowDrawingArea area = get_window_drawing_area();
|
||||
|
||||
// If the rectangle is completely out of bounds, set its width and height to 0
|
||||
@@ -256,14 +262,16 @@ void clip_source_rect_to_drawing_area(RenderRect *src, RenderRect *dest) {
|
||||
y_clip = (dest->y + dest->height) - (area.y + area.height);
|
||||
}
|
||||
|
||||
// Offset and clipping of source rectangle needs to be calculated based on the
|
||||
// ratio of the x_clip and y_clip variables to the width and height of the
|
||||
// destination rectangle respectively. This is because the source rectangle's
|
||||
// width and height might be different from the destination's
|
||||
if (src) {
|
||||
// Offset and clipping of source rectangle needs to be calculated based on
|
||||
// the ratio of the x_clip and y_clip variables to the width and height of
|
||||
// the destination rectangle respectively. This is because the source
|
||||
// rectangle's width and height might be different from the destination's
|
||||
src->x += ((x_offset / dest->width) * src->width);
|
||||
src->y += ((y_offset / dest->height) * src->height);
|
||||
src->width *= 1 - (x_clip / dest->width);
|
||||
src->height *= 1 - (y_clip / dest->height);
|
||||
}
|
||||
|
||||
dest->x += x_offset;
|
||||
dest->y += y_offset;
|
||||
|
||||
@@ -49,6 +49,15 @@ void render_clear(const Renderer *renderer, SDL_Color color) {
|
||||
SDL_RenderClear(renderer->SDL_base_renderer);
|
||||
}
|
||||
|
||||
void draw_rect(const Renderer *renderer, SDL_Color color, float x, float y,
|
||||
float w, float h) {
|
||||
SDL_FRect dest = {x, y, w, h};
|
||||
|
||||
SDL_SetRenderDrawColor(renderer->SDL_base_renderer, color.r, color.g, color.b,
|
||||
color.a);
|
||||
SDL_RenderDrawRectF(renderer->SDL_base_renderer, &dest);
|
||||
}
|
||||
|
||||
void fill_rect(const Renderer *renderer, SDL_Color color, float x, float y,
|
||||
float w, float h) {
|
||||
SDL_FRect dest = {x, y, w, h};
|
||||
|
||||
Reference in new issue
Block a user