diff options
| author | Aldrik Ramaekers <aldrik.ramaekers@protonmail.com> | 2020-08-21 23:08:04 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik.ramaekers@protonmail.com> | 2020-08-21 23:08:04 +0200 |
| commit | dc171d3310a6acacc8d5f512475a79700f0e616d (patch) | |
| tree | 83d3502d8a236c98e44332413761f7f9da15c7af /src/render.c | |
| parent | cdc771255cfab5385b3dae5740db90727efa16ec (diff) | |
automated commit
Diffstat (limited to 'src/render.c')
| -rw-r--r-- | src/render.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/src/render.c b/src/render.c index 3975f35..30f5cca 100644 --- a/src/render.c +++ b/src/render.c @@ -6,7 +6,7 @@ static platform_window *drawing_window = 0;
-static void _copy_image_pixel(s32 x, s32 y, image *image, vec4 rec)
+static void _copy_image_pixel(s32 x, s32 y, image *image, render_target rec)
{
s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5;
u8 *buffer_entry = drawing_window->backbuffer.buffer+offset;
@@ -14,8 +14,8 @@ static void _copy_image_pixel(s32 x, s32 y, image *image, vec4 rec) if (buffer_entry[4] > render_depth) return;
buffer_entry[4] = render_depth;
- s32 _x = x - rec.x;
- s32 _y = y - rec.y;
+ s32 _x = x - rec.x + rec.offset_x;
+ s32 _y = y - rec.y + rec.offset_y;
s32 image_offset = (_y * (image->width) * 4) + _x * 4;
u8 *color = image->data+image_offset;
@@ -32,7 +32,7 @@ static void _copy_image_pixel(s32 x, s32 y, image *image, vec4 rec) memcpy(buffer_entry, &c, 4);
}
-static void _copy_glyph_pixel(s32 x, s32 y, glyph *gl, vec4 rec, color tint)
+static void _copy_glyph_pixel(s32 x, s32 y, glyph *gl, render_target rec, color tint)
{
s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5;
u8 *buffer_entry = drawing_window->backbuffer.buffer+offset;
@@ -40,8 +40,8 @@ static void _copy_glyph_pixel(s32 x, s32 y, glyph *gl, vec4 rec, color tint) if (buffer_entry[4] > render_depth) return;
buffer_entry[4] = render_depth;
- s32 _x = x - rec.x;
- s32 _y = y - rec.y;
+ s32 _x = x - rec.x + rec.offset_x;
+ s32 _y = y - rec.y + rec.offset_y;
s32 image_offset = (_y * gl->width) + _x;
u8 *color = gl->bitmap+image_offset;
@@ -80,7 +80,7 @@ static void _set_pixel(s32 x, s32 y, color tint) }
// returns topleft and bottomright corners. not width + height
-static vec4 _get_actual_rect(s32 x, s32 y, s32 width, s32 height)
+static render_target _get_actual_rect(s32 x, s32 y, s32 width, s32 height)
{
if (x < 0) x = 0;
if (y < 0) y = 0;
@@ -88,9 +88,18 @@ static vec4 _get_actual_rect(s32 x, s32 y, s32 width, s32 height) s32 start_y = y;
s32 end_x = start_x + width;
s32 end_y = start_y + height;
+ s32 offset_x = 0;
+ s32 offset_y = 0;
+
+ if (start_x < current_scissor.x) {
+ offset_x = current_scissor.x - start_x;
+ start_x = current_scissor.x;
+ }
+ if (start_y < current_scissor.y) {
+ offset_y = current_scissor.y - start_y;
+ start_y = current_scissor.y;
+ }
- if (start_x < current_scissor.x) start_x = current_scissor.x;
- if (start_y < current_scissor.y) start_y = current_scissor.y;
if (end_x > current_scissor.x+current_scissor.w)
end_x = current_scissor.x+current_scissor.w;
if (end_y > current_scissor.y+current_scissor.h)
@@ -101,7 +110,7 @@ static vec4 _get_actual_rect(s32 x, s32 y, s32 width, s32 height) if (end_y > drawing_window->backbuffer.height)
end_y = drawing_window->backbuffer.height;
- return (vec4){start_x,start_y,end_x,end_y};
+ return (render_target){start_x,start_y,end_x,end_y,offset_x,offset_y};
}
inline void render_clear(platform_window *window)
@@ -160,7 +169,7 @@ void render_image(image *image, s32 x, s32 y, s32 width, s32 height) {
if (image->loaded)
{
- vec4 rec = _get_actual_rect(x, y, image->width, image->height);
+ render_target rec = _get_actual_rect(x, y, image->width, image->height);
for (s32 y = rec.y; y < rec.h; y++)
{
@@ -251,7 +260,7 @@ s32 render_text_ellipsed(font *font, s32 x, s32 y, s32 maxw, char *text, color t }
else
{
- vec4 rec = _get_actual_rect(x_to_render, y_, g.width, g.height);
+ render_target rec = _get_actual_rect(x_to_render, y_, g.width, g.height);
for (s32 y = rec.y; y < rec.h; y++)
{
@@ -327,7 +336,7 @@ s32 render_text_with_selection(font *font, s32 x, s32 y, char *text, color tint, }
else
{
- vec4 rec = _get_actual_rect(x_to_render, y_, g.width, g.height);
+ render_target rec = _get_actual_rect(x_to_render, y_, g.width, g.height);
for (s32 y = rec.y; y < rec.h; y++)
{
@@ -406,7 +415,7 @@ s32 render_text_with_cursor(font *font, s32 x, s32 y, char *text, color tint, s3 }
else
{
- vec4 rec = _get_actual_rect(x_to_render, y_, g.width, g.height);
+ render_target rec = _get_actual_rect(x_to_render, y_, g.width, g.height);
for (s32 y = rec.y; y < rec.h; y++)
{
@@ -480,7 +489,7 @@ s32 render_text(font *font, s32 x, s32 y, char *text, color tint) }
else
{
- vec4 rec = _get_actual_rect(x_to_render, y_, g.width, g.height);
+ render_target rec = _get_actual_rect(x_to_render, y_, g.width, g.height);
for (s32 y = rec.y; y < rec.h; y++)
{
@@ -565,7 +574,7 @@ s32 render_text_cutoff(font *font, s32 x, s32 y, char *text, color tint, u16 cut }
else
{
- vec4 rec = _get_actual_rect(x_to_render, y__, g.width, g.height);
+ render_target rec = _get_actual_rect(x_to_render, y__, g.width, g.height);
for (s32 y = rec.y; y < rec.h; y++)
{
@@ -768,7 +777,7 @@ void render_triangle(s32 x, s32 y, s32 w, s32 h, color tint, triangle_direction }
else
{
- vec4 rec = _get_actual_rect(x,y,w,h);
+ render_target rec = _get_actual_rect(x,y,w,h);
s32 ac_w = rec.w - rec.x;
@@ -846,7 +855,7 @@ void render_rectangle(s32 x, s32 y, s32 width, s32 height, color tint) }
else
{
- vec4 rec = _get_actual_rect(x,y,width,height);
+ render_target rec = _get_actual_rect(x,y,width,height);
for (s32 y = rec.y; y < rec.h; y++)
{
|
