summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/project_base.h4
-rw-r--r--src/render.c45
-rw-r--r--src/render.h11
3 files changed, 39 insertions, 21 deletions
diff --git a/src/project_base.h b/src/project_base.h
index 9d2ca5f..6447204 100644
--- a/src/project_base.h
+++ b/src/project_base.h
@@ -7,9 +7,7 @@
#ifndef INCLUDE_PROJECT_BASE
#define INCLUDE_PROJECT_BASE
-// TODO(Aldrik): scrolling images and text cuts off top because of scissor rec in cpu render mode
-
-#define PROJECT_BASE_VERSION "2"
+#define PROJECT_BASE_VERSION "3"
#ifdef _WIN32
#define OS_WIN
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++)
{
diff --git a/src/render.h b/src/render.h
index 92b58e2..dcb3af6 100644
--- a/src/render.h
+++ b/src/render.h
@@ -22,6 +22,17 @@ typedef struct t_vec4
s32 h;
} vec4;
+typedef struct t_render_target
+{
+ s32 x;
+ s32 y;
+ s32 w;
+ s32 h;
+
+ s32 offset_x;
+ s32 offset_y;
+} render_target;
+
typedef enum t_triangle_direction
{
TRIANGLE_DOWN,