From 1a153d0c8f78318b83024d87b6d12911f18e5984 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sat, 18 Jan 2025 10:24:53 +0100 Subject: [PATCH] Add g2_draw_line_aa --- armorcore/sources/iron.h | 4 ++++ armorcore/sources/iron_ui_nodes.c | 7 +----- armorcore/sources/kinc/graphics2/g2.c | 31 +++++++++++++++++++++++++++ armorcore/sources/kinc/graphics2/g2.h | 1 + armorcore/sources/ts/g2.ts | 4 ++++ armorcore/sources/ts/iron.ts | 1 + 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/armorcore/sources/iron.h b/armorcore/sources/iron.h index f54403c4..c374f55a 100644 --- a/armorcore/sources/iron.h +++ b/armorcore/sources/iron.h @@ -2289,6 +2289,10 @@ void iron_g2_draw_line(f32 x0, f32 y0, f32 x1, f32 y1, f32 strength) { arm_g2_draw_line(x0, y0, x1, y1, strength); } +void iron_g2_draw_line_aa(f32 x0, f32 y0, f32 x1, f32 y1, f32 strength) { + arm_g2_draw_line_aa(x0, y0, x1, y1, strength); +} + void iron_g2_draw_string(string_t *text, f32 x, f32 y) { arm_g2_draw_string(text, x, y); } diff --git a/armorcore/sources/iron_ui_nodes.c b/armorcore/sources/iron_ui_nodes.c index eabd07ba..ed10497d 100644 --- a/armorcore/sources/iron_ui_nodes.c +++ b/armorcore/sources/iron_ui_nodes.c @@ -266,12 +266,7 @@ void ui_draw_link(float x1, float y1, float x2, float y2, bool highlight) { int c = highlight ? c1 : c2; arm_g2_set_color(ui_color(ui_color_r(c), ui_color_g(c), ui_color_b(c), 210)); if (current->ops->theme->LINK_STYLE == UI_LINK_STYLE_LINE) { - arm_g2_draw_line(x1, y1, x2, y2, 1.0); - arm_g2_set_color(ui_color(ui_color_r(c), ui_color_g(c), ui_color_b(c), 150)); // AA - arm_g2_draw_line(x1 + 0.5, y1, x2 + 0.5, y2, 1.0); - arm_g2_draw_line(x1 - 0.5, y1, x2 - 0.5, y2, 1.0); - arm_g2_draw_line(x1, y1 + 0.5, x2, y2 + 0.5, 1.0); - arm_g2_draw_line(x1, y1 - 0.5, x2, y2 - 0.5, 1.0); + arm_g2_draw_line_aa(x1, y1, x2, y2, 1.0); } else if (current->ops->theme->LINK_STYLE == UI_LINK_STYLE_CUBIC_BEZIER) { float x[] = { x1, x1 + fabs(x1 - x2) / 2.0, x2 - fabs(x1 - x2) / 2.0, x2 }; diff --git a/armorcore/sources/kinc/graphics2/g2.c b/armorcore/sources/kinc/graphics2/g2.c index 30bc4faf..a5bad17a 100644 --- a/armorcore/sources/kinc/graphics2/g2.c +++ b/armorcore/sources/kinc/graphics2/g2.c @@ -596,6 +596,37 @@ void arm_g2_draw_line(float x0, float y0, float x1, float y1, float strength) { arm_g2_fill_triangle(p2.x, p2.y, p1.x, p1.y, p3.x, p3.y); } +static uint8_t _g2_color_r(uint32_t color) { + return (color & 0x00ff0000) >> 16; +} + +static uint8_t _g2_color_g(uint32_t color) { + return (color & 0x0000ff00) >> 8; +} + +static uint8_t _g2_color_b(uint32_t color) { + return (color & 0x000000ff); +} + +static uint8_t _g2_color_a(uint32_t color) { + return (color) >> 24; +} + +static uint32_t _g2_color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + return (a << 24) | (r << 16) | (g << 8) | b; +} + +void arm_g2_draw_line_aa(float x0, float y0, float x1, float y1, float strength) { + arm_g2_draw_line(x0, y0, x1, y1, strength); + uint32_t _color = g2_color; + arm_g2_set_color(_g2_color(_g2_color_r(g2_color), _g2_color_g(g2_color), _g2_color_b(g2_color), 150)); + arm_g2_draw_line(x0 + 0.5, y0, x1 + 0.5, y1, strength); + arm_g2_draw_line(x0 - 0.5, y0, x1 - 0.5, y1, strength); + arm_g2_draw_line(x0, y0 + 0.5, x1, y1 + 0.5, strength); + arm_g2_draw_line(x0, y0 - 0.5, x1, y1 - 0.5, strength); + arm_g2_set_color(_color); +} + void arm_g2_text_set_rect_verts(float btlx, float btly, float tplx, float tply, float tprx, float tpry, float btrx, float btry) { int base_idx = (text_buffer_index - text_buffer_start) * 6 * 4; text_rect_verts[base_idx + 0] = btlx; diff --git a/armorcore/sources/kinc/graphics2/g2.h b/armorcore/sources/kinc/graphics2/g2.h index 20c03612..33308a85 100644 --- a/armorcore/sources/kinc/graphics2/g2.h +++ b/armorcore/sources/kinc/graphics2/g2.h @@ -43,6 +43,7 @@ void arm_g2_fill_triangle(float x0, float y0, float x1, float y1, float x2, floa void arm_g2_fill_rect(float x, float y, float width, float height); void arm_g2_draw_rect(float x, float y, float width, float height, float strength); void arm_g2_draw_line(float x0, float y0, float x1, float y1, float strength); +void arm_g2_draw_line_aa(float x0, float y0, float x1, float y1, float strength); void arm_g2_draw_string(const char *text, float x, float y); void arm_g2_end(void); void arm_g2_set_color(uint32_t color); diff --git a/armorcore/sources/ts/g2.ts b/armorcore/sources/ts/g2.ts index a5815727..9a4692ec 100644 --- a/armorcore/sources/ts/g2.ts +++ b/armorcore/sources/ts/g2.ts @@ -119,6 +119,10 @@ function g2_draw_line(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32 = 1.0) { iron_g2_draw_line(x0, y0, x1, y1, strength); } +function g2_draw_line_aa(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32 = 1.0) { + iron_g2_draw_line_aa(x0, y0, x1, y1, strength); +} + function g2_fill_triangle(x0: f32, y0: f32, x1: f32, y1: f32, x2: f32, y2: f32) { iron_g2_fill_triangle(x0, y0, x1, y1, x2, y2); } diff --git a/armorcore/sources/ts/iron.ts b/armorcore/sources/ts/iron.ts index 5121b4b9..e3b373b0 100644 --- a/armorcore/sources/ts/iron.ts +++ b/armorcore/sources/ts/iron.ts @@ -320,6 +320,7 @@ declare function iron_g2_fill_triangle(x0: f32, y0: f32, x1: f32, y1: f32, x2: f declare function iron_g2_fill_rect(x: f32, y: f32, width: f32, height: f32): void; declare function iron_g2_draw_rect(x: f32, y: f32, width: f32, height: f32, strength: f32): void; declare function iron_g2_draw_line(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32): void; +declare function iron_g2_draw_line_aa(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32): void; declare function iron_g2_draw_string(text: string, x: f32, y: f32): void; declare function iron_g2_set_font(font: any, size: i32): void; declare function iron_g2_font_init(blob: buffer_t, font_index: i32): any;