From dc171d3310a6acacc8d5f512475a79700f0e616d Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Fri, 21 Aug 2020 23:08:04 +0200 Subject: automated commit --- changes.txt | 6 +++++- src/project_base.h | 4 +--- src/render.c | 45 +++++++++++++++++++++++++++------------------ src/render.h | 11 +++++++++++ 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/changes.txt b/changes.txt index a4c552e..9b52b01 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,9 @@ -2 +3 +- fix issue where text and images were being cut off on scroll - fix cursor being overwritten by underlying ui element +- refactor ui menu bar +- added shadow to dropdown menu item +2 - fix image blending issue with background colors - triangle rendering on cpu - refactor submenu for localization 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, -- cgit v1.2.3-70-g09d2