Added ability to draw a non-filled rectangle
This commit is contained in:
1 parent
c1659dcf88
commit
a87eba8db7
7 files changed
+45
-12
No files matched your search
+17
-9
@@ -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
|
||||
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);
|
||||
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