From 0f2e813cefeb28286cd15596b41496d6fb0e24dc Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sat, 18 Jan 2025 19:28:10 +0100 Subject: [PATCH] Cleanup --- armorcore/sources/iron.h | 129 ------- armorcore/sources/iron_ui.c | 406 ++++++++++----------- armorcore/sources/iron_ui_ext.c | 42 +-- armorcore/sources/iron_ui_nodes.c | 80 ++--- armorcore/sources/kinc/graphics2/g2.c | 411 ++++++++++++---------- armorcore/sources/kinc/graphics2/g2.h | 91 +++-- armorcore/sources/kinc/graphics2/g2_ext.c | 26 +- armorcore/sources/kinc/graphics2/g2_ext.h | 8 +- armorcore/sources/ts/g2.ts | 56 +-- armorcore/sources/ts/iron.ts | 52 +-- base/sources/base.ts | 2 +- base/sources/import_font.ts | 2 +- 12 files changed, 614 insertions(+), 691 deletions(-) diff --git a/armorcore/sources/iron.h b/armorcore/sources/iron.h index 4b9d6ed70..9b0faaab0 100644 --- a/armorcore/sources/iron.h +++ b/armorcore/sources/iron.h @@ -1608,17 +1608,6 @@ kinc_g4_texture_t *iron_load_image(string_t *file, bool readable) { return texture; } -typedef struct image { - any texture_; - any render_target_; - int format; // tex_format_t; - bool readable; - buffer_t *pixels; - int width; - int height; - int depth; -} image_t; - void iron_unload_image(image_t *image) { if (image == NULL) { return; @@ -2247,124 +2236,6 @@ void iron_http_request(string_t *url, i32 size, void (*callback)(char *, buffer_ #endif } -void iron_g2_init(buffer_t *image_vert, buffer_t *image_frag, buffer_t *colored_vert, buffer_t *colored_frag, buffer_t *text_vert, buffer_t *text_frag) { - arm_g2_init(image_vert->buffer, image_vert->length, image_frag->buffer, image_frag->length, colored_vert->buffer, colored_vert->length, colored_frag->buffer, colored_frag->length, text_vert->buffer, text_vert->length, text_frag->buffer, text_frag->length); -} - -void iron_g2_begin() { - arm_g2_begin(); -} - -void iron_g2_end() { - arm_g2_end(); -} - -void iron_g2_draw_scaled_sub_image(image_t *image, f32 sx, f32 sy, f32 sw, f32 sh, f32 dx, f32 dy, f32 dw, f32 dh) { - #ifdef KINC_DIRECT3D12 - waitAfterNextDraw = true; - #endif - if (image->texture_ != NULL) { - kinc_g4_texture_t *texture = (kinc_g4_texture_t *)image->texture_; - arm_g2_draw_scaled_sub_image(texture, sx, sy, sw, sh, dx, dy, dw, dh); - } - else { - kinc_g4_render_target_t *render_target = (kinc_g4_render_target_t *)image->render_target_; - arm_g2_draw_scaled_sub_render_target(render_target, sx, sy, sw, sh, dx, dy, dw, dh); - } -} - -void iron_g2_fill_triangle(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2) { - arm_g2_fill_triangle(x0, y0, x1, y1, x2, y2); -} - -void iron_g2_fill_rect(f32 x, f32 y, f32 width, f32 height) { - arm_g2_fill_rect(x, y, width, height); -} - -void iron_g2_draw_rect(f32 x, f32 y, f32 width, f32 height, f32 strength) { - arm_g2_draw_rect(x, y, width, height, strength); -} - -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); -} - -void iron_g2_set_font(arm_g2_font_t *font, i32 size) { - arm_g2_set_font(font, size); -} - -arm_g2_font_t *iron_g2_font_init(buffer_t *blob, i32 font_index) { - arm_g2_font_t *font = (arm_g2_font_t *)malloc(sizeof(arm_g2_font_t)); - arm_g2_font_init(font, blob->buffer, font_index); - return font; -} - -arm_g2_font_t *iron_g2_font_13(buffer_t *blob) { - arm_g2_font_t *font = (arm_g2_font_t *)malloc(sizeof(arm_g2_font_t)); - arm_g2_font_13(font, blob->buffer); - return font; -} - -void iron_g2_font_set_glyphs(i32_array_t *glyphs) { - arm_g2_font_set_glyphs(glyphs->buffer, glyphs->length); -} - -i32 iron_g2_font_count(arm_g2_font_t *font) { - return arm_g2_font_count(font); -} - -i32 iron_g2_font_height(arm_g2_font_t *font, i32 size) { - return (int)arm_g2_font_height(font, size); -} - -i32 iron_g2_string_width(arm_g2_font_t *font, i32 size, string_t *text) { - return (int)arm_g2_string_width(font, size, text); -} - -void iron_g2_set_bilinear_filter(bool bilinear) { - arm_g2_set_bilinear_filter(bilinear); -} - -void iron_g2_restore_render_target() { - arm_g2_restore_render_target(); -} - -void iron_g2_set_render_target(kinc_g4_render_target_t *render_target) { - arm_g2_set_render_target(render_target); -} - -void iron_g2_set_color(i32 color) { - arm_g2_set_color(color); -} - -void iron_g2_set_pipeline(kinc_g4_pipeline_t *pipeline) { - arm_g2_set_pipeline(pipeline); -} - -void iron_g2_set_transform(buffer_t *matrix) { - arm_g2_set_transform(matrix != NULL ? (kinc_matrix3x3_t *)matrix->buffer : NULL); -} - -void iron_g2_fill_circle(f32 cx, f32 cy, f32 radius, i32 segments) { - arm_g2_fill_circle(cx, cy, radius, segments); -} - -void iron_g2_draw_circle(f32 cx, f32 cy, f32 radius, i32 segments, f32 strength) { - arm_g2_draw_circle(cx, cy, radius, segments, strength); -} - -void iron_g2_draw_cubic_bezier(f32_array_t *x, f32_array_t *y, i32 segments, f32 strength) { - arm_g2_draw_cubic_bezier(x->buffer, y->buffer, segments, strength); -} - bool _window_close_callback(void *data) { #ifdef KINC_WINDOWS bool save = false; diff --git a/armorcore/sources/iron_ui.c b/armorcore/sources/iron_ui.c index 605594234..0f776b741 100644 --- a/armorcore/sources/iron_ui.c +++ b/armorcore/sources/iron_ui.c @@ -140,30 +140,30 @@ ui_handle_t *ui_nest(ui_handle_t *handle, int pos) { } void ui_fade_color(float alpha) { - uint32_t color = arm_g2_get_color(); + uint32_t color = kinc_g2_get_color(); uint8_t r = (color & 0x00ff0000) >> 16; uint8_t g = (color & 0x0000ff00) >> 8; uint8_t b = (color & 0x000000ff); uint8_t a = (uint8_t)(255.0 * alpha); - arm_g2_set_color((a << 24) | (r << 16) | (g << 8) | b); + kinc_g2_set_color((a << 24) | (r << 16) | (g << 8) | b); } void ui_fill(float x, float y, float w, float h, uint32_t color) { - arm_g2_set_color(color); + kinc_g2_set_color(color); if (!current->enabled) { ui_fade_color(0.25); } - arm_g2_fill_rect(current->_x + x * UI_SCALE(), current->_y + y * UI_SCALE() - 1, w * UI_SCALE(), h * UI_SCALE()); - arm_g2_set_color(0xffffffff); + kinc_g2_fill_rect(current->_x + x * UI_SCALE(), current->_y + y * UI_SCALE() - 1, w * UI_SCALE(), h * UI_SCALE()); + kinc_g2_set_color(0xffffffff); } void ui_rect(float x, float y, float w, float h, uint32_t color, float strength) { - arm_g2_set_color(color); + kinc_g2_set_color(color); if (!current->enabled) { ui_fade_color(0.25); } - arm_g2_draw_rect(current->_x + x * UI_SCALE(), current->_y + y * UI_SCALE(), w * UI_SCALE(), h * UI_SCALE(), strength); - arm_g2_set_color(0xffffffff); + kinc_g2_draw_rect(current->_x + x * UI_SCALE(), current->_y + y * UI_SCALE(), w * UI_SCALE(), h * UI_SCALE(), strength); + kinc_g2_set_color(0xffffffff); } void ui_draw_shadow(float x, float y, float w, float h) { @@ -171,14 +171,14 @@ void ui_draw_shadow(float x, float y, float w, float h) { // for (int i = 0; i < 8; i++) { // float offset = i * UI_SCALE(); // float a = (8 - i + 1) * 0.01; - // arm_g2_set_color(((uint8_t)(a * 255) << 24) | (0 << 16) | (0 << 8) | 0); + // kinc_g2_set_color(((uint8_t)(a * 255) << 24) | (0 << 16) | (0 << 8) | 0); // ui_draw_rect(true, x - offset, y - offset, w + offset * 2, h + offset * 2); // } float max_offset = 4.0 * UI_SCALE(); for (int i = 0; i < 4; i++) { float offset = (max_offset / 4) * (i + 1); float a = 0.1 - (0.1 / 4) * i; - arm_g2_set_color(((uint8_t)(a * 255) << 24) | (0 << 16) | (0 << 8) | 0); + kinc_g2_set_color(((uint8_t)(a * 255) << 24) | (0 << 16) | (0 << 8) | 0); ui_draw_rect(true, x + offset, y + offset, w + (max_offset - offset) * 2, h + (max_offset - offset) * 2); } } @@ -199,15 +199,15 @@ void ui_draw_rect(bool fill, float x, float y, float w, float h) { if (theme->ROUND_CORNERS && current->enabled && r > 0 && w >= r * 2.0) { y -= 1; // Make it pixel perfect with non-round draw h += 1; - arm_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x, y, r, r); - arm_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x, y + h, r, -r); - arm_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x + w, y, -r, r); - arm_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x + w, y + h, -r, -r); - arm_g2_fill_rect(x + r, y, w - r * 2.0, h); - arm_g2_fill_rect(x, y + r, w, h - r * 2.0); + kinc_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x, y, r, r); + kinc_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x, y + h, r, -r); + kinc_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x + w, y, -r, r); + kinc_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x + w, y + h, -r, -r); + kinc_g2_fill_rect(x + r, y, w - r * 2.0, h); + kinc_g2_fill_rect(x, y + r, w, h - r * 2.0); } else { - arm_g2_fill_rect(x, y - 1, w, h + 1); + kinc_g2_fill_rect(x, y - 1, w, h + 1); } } else { @@ -217,17 +217,17 @@ void ui_draw_rect(bool fill, float x, float y, float w, float h) { w += 1; y -= 1; h += 1; - arm_g2_draw_scaled_render_target(¤t->round_corner_image, x, y, r, r); - arm_g2_draw_scaled_render_target(¤t->round_corner_image, x, y + h, r, -r); - arm_g2_draw_scaled_render_target(¤t->round_corner_image, x + w, y, -r, r); - arm_g2_draw_scaled_render_target(¤t->round_corner_image, x + w, y + h, -r, -r); - arm_g2_fill_rect(x + r, y, w - r * 2.0, strength); - arm_g2_fill_rect(x + r, y + h - 1, w - r * 2.0, strength); - arm_g2_fill_rect(x, y + r, strength, h - r * 2.0); - arm_g2_fill_rect(x + w - 1, y + r, strength, h - r * 2.0); + kinc_g2_draw_scaled_render_target(¤t->round_corner_image, x, y, r, r); + kinc_g2_draw_scaled_render_target(¤t->round_corner_image, x, y + h, r, -r); + kinc_g2_draw_scaled_render_target(¤t->round_corner_image, x + w, y, -r, r); + kinc_g2_draw_scaled_render_target(¤t->round_corner_image, x + w, y + h, -r, -r); + kinc_g2_fill_rect(x + r, y, w - r * 2.0, strength); + kinc_g2_fill_rect(x + r, y + h - 1, w - r * 2.0, strength); + kinc_g2_fill_rect(x, y + r, strength, h - r * 2.0); + kinc_g2_fill_rect(x + w - 1, y + r, strength, h - r * 2.0); } else { - arm_g2_draw_rect(x, y, w, h, strength); + kinc_g2_draw_rect(x, y, w, h, strength); } } } @@ -238,10 +238,10 @@ void ui_draw_round_bottom(float x, float y, float w) { int h = 4; y -= 1; // Make it pixel perfect with non-round draw h += 1; - arm_g2_set_color(theme->SEPARATOR_COL); - arm_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x, y + h, r, -r); - arm_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x + w, y + h, -r, -r); - arm_g2_fill_rect(x + r, y, w - r * 2.0, h); + kinc_g2_set_color(theme->SEPARATOR_COL); + kinc_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x, y + h, r, -r); + kinc_g2_draw_scaled_render_target(¤t->filled_round_corner_image, x + w, y + h, -r, -r); + kinc_g2_fill_rect(x + r, y, w - r * 2.0, h); } } @@ -317,13 +317,13 @@ void ui_draw_string(char *text, float x_offset, float y_offset, int align, bool char *full_text = text; strcpy(truncated, text); text = &truncated[0]; - while (strlen(text) > 0 && arm_g2_string_width(current->ops->font->font_, current->font_size, text) > current->_w - 6.0 * UI_SCALE()) { + while (strlen(text) > 0 && kinc_g2_string_width(current->ops->font->font_, current->font_size, text) > current->_w - 6.0 * UI_SCALE()) { text[strlen(text) - 1] = 0; } if (strlen(text) < strlen(full_text)) { strcat(text, ".."); // Strip more to fit ".." - while (strlen(text) > 2 && arm_g2_string_width(current->ops->font->font_, current->font_size, text) > current->_w - 10.0 * UI_SCALE()) { + while (strlen(text) > 2 && kinc_g2_string_width(current->ops->font->font_, current->font_size, text) > current->_w - 10.0 * UI_SCALE()) { text[strlen(text) - 3] = 0; strcat(text, ".."); } @@ -336,9 +336,9 @@ void ui_draw_string(char *text, float x_offset, float y_offset, int align, bool if (ui_dynamic_glyph_load) { int len = strlen(text); for (int i = 0; i < len; ++i) { - if (text[i] > 126 && !arm_g2_font_has_glyph((int)text[i])) { + if (text[i] > 126 && !kinc_g2_font_has_glyph((int)text[i])) { int glyph = text[i]; - arm_g2_font_add_glyph(glyph); + kinc_g2_font_add_glyph(glyph); } } } @@ -347,12 +347,12 @@ void ui_draw_string(char *text, float x_offset, float y_offset, int align, bool x_offset = theme->TEXT_OFFSET; } x_offset *= UI_SCALE(); - arm_g2_set_font(current->ops->font->font_, current->font_size); + kinc_g2_set_font(current->ops->font->font_, current->font_size); if (align == UI_ALIGN_CENTER) { - x_offset = current->_w / 2.0 - arm_g2_string_width(current->ops->font->font_, current->font_size, text) / 2.0; + x_offset = current->_w / 2.0 - kinc_g2_string_width(current->ops->font->font_, current->font_size, text) / 2.0; } else if (align == UI_ALIGN_RIGHT) { - x_offset = current->_w - arm_g2_string_width(current->ops->font->font_, current->font_size, text) - UI_TEXT_OFFSET(); + x_offset = current->_w - kinc_g2_string_width(current->ops->font->font_, current->font_size, text) - UI_TEXT_OFFSET(); } if (!current->enabled) { @@ -360,7 +360,7 @@ void ui_draw_string(char *text, float x_offset, float y_offset, int align, bool } if (current->text_coloring == NULL) { - arm_g2_draw_string(text, current->_x + x_offset, current->_y + current->font_offset_y + y_offset); + kinc_g2_draw_string(text, current->_x + x_offset, current->_y + current->font_offset_y + y_offset); } else { // Monospace fonts only for now @@ -369,13 +369,13 @@ void ui_draw_string(char *text, float x_offset, float y_offset, int align, bool ui_coloring_t *coloring = current->text_coloring->colorings->buffer[i]; ui_text_extract_t result = ui_extract_coloring(temp, coloring); if (result.colored[0] != '\0') { - arm_g2_set_color(coloring->color); - arm_g2_draw_string(result.colored, current->_x + x_offset, current->_y + current->font_offset_y + y_offset); + kinc_g2_set_color(coloring->color); + kinc_g2_draw_string(result.colored, current->_x + x_offset, current->_y + current->font_offset_y + y_offset); } strcpy(temp, result.uncolored); } - arm_g2_set_color(current->text_coloring->default_color); - arm_g2_draw_string(temp, current->_x + x_offset, current->_y + current->font_offset_y + y_offset); + kinc_g2_set_color(current->text_coloring->default_color); + kinc_g2_draw_string(temp, current->_x + x_offset, current->_y + current->font_offset_y + y_offset); } } @@ -579,14 +579,14 @@ void ui_draw_tooltip_text(bool bind_global_g) { int line_count = ui_line_count(current->tooltip_text); float tooltip_w = 0.0; for (int i = 0; i < line_count; ++i) { - float line_tooltip_w = arm_g2_string_width(current->ops->font->font_, current->font_size, ui_extract_line(current->tooltip_text, i)); + float line_tooltip_w = kinc_g2_string_width(current->ops->font->font_, current->font_size, ui_extract_line(current->tooltip_text, i)); if (line_tooltip_w > tooltip_w) { tooltip_w = line_tooltip_w; } } current->tooltip_x = fmin(current->tooltip_x, kinc_window_width(0) - tooltip_w - 20); - if (bind_global_g) arm_g2_restore_render_target(); - float font_height = arm_g2_font_height(current->ops->font->font_, current->font_size); + if (bind_global_g) kinc_g2_restore_render_target(); + float font_height = kinc_g2_font_height(current->ops->font->font_, current->font_size); float off = 0; if (current->tooltip_img != NULL) { float w = current->tooltip_img->tex_width; @@ -608,13 +608,13 @@ void ui_draw_tooltip_text(bool bind_global_g) { int w = tooltip_w + 20 + 10; int h = font_height * line_count + 10; ui_draw_shadow(x, y, w, h); - arm_g2_set_color(theme->SEPARATOR_COL); - arm_g2_fill_rect(x, y, w, h); + kinc_g2_set_color(theme->SEPARATOR_COL); + kinc_g2_fill_rect(x, y, w, h); - arm_g2_set_font(current->ops->font->font_, current->font_size); - arm_g2_set_color(theme->TEXT_COL); + kinc_g2_set_font(current->ops->font->font_, current->font_size); + kinc_g2_set_color(theme->TEXT_COL); for (int i = 0; i < line_count; ++i) { - arm_g2_draw_string(ui_extract_line(current->tooltip_text, i), current->tooltip_x + 5, current->tooltip_y + off + i * current->font_size); + kinc_g2_draw_string(ui_extract_line(current->tooltip_text, i), current->tooltip_x + 5, current->tooltip_y + off + i * current->font_size); } } @@ -627,14 +627,14 @@ void ui_draw_tooltip_image(bool bind_global_g) { current->tooltip_x = fmin(current->tooltip_x, kinc_window_width(0) - w - 20); current->tooltip_y = fmin(current->tooltip_y, kinc_window_height(0) - h - 20); if (bind_global_g) { - arm_g2_restore_render_target(); + kinc_g2_restore_render_target(); } - arm_g2_set_color(0xff000000); - arm_g2_fill_rect(current->tooltip_x, current->tooltip_y, w, h); - arm_g2_set_color(0xffffffff); + kinc_g2_set_color(0xff000000); + kinc_g2_fill_rect(current->tooltip_x, current->tooltip_y, w, h); + kinc_g2_set_color(0xffffffff); current->tooltip_invert_y ? - arm_g2_draw_scaled_image(current->tooltip_img, current->tooltip_x, current->tooltip_y + h, w, -h) : - arm_g2_draw_scaled_image(current->tooltip_img, current->tooltip_x, current->tooltip_y, w, h); + kinc_g2_draw_scaled_image(current->tooltip_img, current->tooltip_x, current->tooltip_y + h, w, -h) : + kinc_g2_draw_scaled_image(current->tooltip_img, current->tooltip_x, current->tooltip_y, w, h); } void ui_draw_tooltip_rt(bool bind_global_g) { @@ -646,47 +646,47 @@ void ui_draw_tooltip_rt(bool bind_global_g) { current->tooltip_x = fmin(current->tooltip_x, kinc_window_width(0) - w - 20); current->tooltip_y = fmin(current->tooltip_y, kinc_window_height(0) - h - 20); if (bind_global_g) { - arm_g2_restore_render_target(); + kinc_g2_restore_render_target(); } - arm_g2_set_color(0xff000000); - arm_g2_fill_rect(current->tooltip_x, current->tooltip_y, w, h); - arm_g2_set_color(0xffffffff); + kinc_g2_set_color(0xff000000); + kinc_g2_fill_rect(current->tooltip_x, current->tooltip_y, w, h); + kinc_g2_set_color(0xffffffff); current->tooltip_invert_y ? - arm_g2_draw_scaled_render_target(current->tooltip_rt, current->tooltip_x, current->tooltip_y + h, w, -h) : - arm_g2_draw_scaled_render_target(current->tooltip_rt, current->tooltip_x, current->tooltip_y, w, h); + kinc_g2_draw_scaled_render_target(current->tooltip_rt, current->tooltip_x, current->tooltip_y + h, w, -h) : + kinc_g2_draw_scaled_render_target(current->tooltip_rt, current->tooltip_x, current->tooltip_y, w, h); } void ui_draw_tooltip(bool bind_global_g) { static char temp[1024]; if (current->slider_tooltip) { if (bind_global_g) { - arm_g2_restore_render_target(); + kinc_g2_restore_render_target(); } - arm_g2_set_font(current->ops->font->font_, current->font_size * 2); + kinc_g2_set_font(current->ops->font->font_, current->font_size * 2); sprintf(temp, "%f", round(current->scroll_handle->value * 100.0) / 100.0); string_strip_trailing_zeros(temp); char *text = temp; - float x_off = arm_g2_string_width(current->ops->font->font_, current->font_size * 2.0, text) / 2.0; - float y_off = arm_g2_font_height(current->ops->font->font_, current->font_size * 2.0); + float x_off = kinc_g2_string_width(current->ops->font->font_, current->font_size * 2.0, text) / 2.0; + float y_off = kinc_g2_font_height(current->ops->font->font_, current->font_size * 2.0); float x = fmin(fmax(current->slider_tooltip_x, current->input_x), current->slider_tooltip_x + current->slider_tooltip_w); - arm_g2_set_color(theme->BUTTON_COL); - arm_g2_fill_rect(x - x_off, current->slider_tooltip_y - y_off, x_off * 2.0, y_off); - arm_g2_set_color(theme->TEXT_COL); - arm_g2_draw_string(text, x - x_off, current->slider_tooltip_y - y_off); + kinc_g2_set_color(theme->BUTTON_COL); + kinc_g2_fill_rect(x - x_off, current->slider_tooltip_y - y_off, x_off * 2.0, y_off); + kinc_g2_set_color(theme->TEXT_COL); + kinc_g2_draw_string(text, x - x_off, current->slider_tooltip_y - y_off); } if (ui_touch_tooltip && current->text_selected_handle != NULL) { if (bind_global_g) { - arm_g2_restore_render_target(); + kinc_g2_restore_render_target(); } - arm_g2_set_font(current->ops->font->font_, current->font_size * 2.0); - float x_off = arm_g2_string_width(current->ops->font->font_, current->font_size * 2.0, current->text_selected) / 2.0; - float y_off = arm_g2_font_height(current->ops->font->font_, current->font_size * 2.0) / 2.0; + kinc_g2_set_font(current->ops->font->font_, current->font_size * 2.0); + float x_off = kinc_g2_string_width(current->ops->font->font_, current->font_size * 2.0, current->text_selected) / 2.0; + float y_off = kinc_g2_font_height(current->ops->font->font_, current->font_size * 2.0) / 2.0; float x = kinc_window_width(0) / 2.0; float y = kinc_window_height(0) / 3.0; - arm_g2_set_color(theme->BUTTON_COL); - arm_g2_fill_rect(x - x_off, y - y_off, x_off * 2.0, y_off * 2.0); - arm_g2_set_color(theme->TEXT_COL); - arm_g2_draw_string(current->text_selected, x - x_off, y - y_off); + kinc_g2_set_color(theme->BUTTON_COL); + kinc_g2_fill_rect(x - x_off, y - y_off, x_off * 2.0, y_off * 2.0); + kinc_g2_set_color(theme->TEXT_COL); + kinc_g2_draw_string(current->text_selected, x - x_off, y - y_off); } if (current->tooltip_text[0] != '\0' || current->tooltip_img != NULL || current->tooltip_rt != NULL) { @@ -718,9 +718,9 @@ void ui_draw_combo(bool begin /*= true*/) { if (current->combo_selected_handle == NULL) { return; } - arm_g2_set_color(theme->SEPARATOR_COL); + kinc_g2_set_color(theme->SEPARATOR_COL); if (begin) { - arm_g2_restore_render_target(); + kinc_g2_restore_render_target(); } float combo_h = (current->combo_selected_texts->length + (current->combo_selected_label != NULL ? 1 : 0) + (current->combo_search_bar ? 1 : 0)) * UI_ELEMENT_H(); @@ -867,7 +867,7 @@ void ui_draw_combo(bool begin /*= true*/) { if (unroll_up) { current->_y -= UI_ELEMENT_H() * 2.0; ui_fill(0, 0, current->_w / UI_SCALE(), UI_ELEMENT_H() / UI_SCALE(), theme->SEPARATOR_COL); - arm_g2_set_color(theme->LABEL_COL); + kinc_g2_set_color(theme->LABEL_COL); ui_draw_string(current->combo_selected_label, theme->TEXT_OFFSET, 0, UI_ALIGN_RIGHT, true); current->_y += UI_ELEMENT_H(); ui_fill(0, 0, current->_w / UI_SCALE(), 1.0 * UI_SCALE(), theme->ACCENT_COL); // Separator @@ -875,7 +875,7 @@ void ui_draw_combo(bool begin /*= true*/) { else { ui_fill(0, 0, current->_w / UI_SCALE(), UI_ELEMENT_H() / UI_SCALE(), theme->SEPARATOR_COL); ui_fill(0, 0, current->_w / UI_SCALE(), 1.0 * UI_SCALE(), theme->ACCENT_COL); // Separator - arm_g2_set_color(theme->LABEL_COL); + kinc_g2_set_color(theme->LABEL_COL); ui_draw_string(current->combo_selected_label, theme->TEXT_OFFSET, 0, UI_ALIGN_RIGHT, true); current->_y += UI_ELEMENT_H(); ui_draw_round_bottom(current->_x, current->_y - 1, current->_w); @@ -899,38 +899,38 @@ void ui_bake_elements() { } float r = UI_CHECK_SELECT_SIZE(); kinc_g4_render_target_init(¤t->check_select_image, r, r, KINC_G4_RENDER_TARGET_FORMAT_32BIT, 0, 0); - arm_g2_set_render_target(¤t->check_select_image); + kinc_g2_set_render_target(¤t->check_select_image); kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0x00000000, 0, 0); - arm_g2_set_color(0xffffffff); - arm_g2_draw_line(0, r / 2.0, r / 2.0 - 2.0 * UI_SCALE(), r - 2.0 * UI_SCALE(), 2.0 * UI_SCALE()); - arm_g2_draw_line(r / 2.0 - 3.0 * UI_SCALE(), r - 3.0 * UI_SCALE(), r / 2.0 + 5.0 * UI_SCALE(), r - 11.0 * UI_SCALE(), 2.0 * UI_SCALE()); - arm_g2_end(); + kinc_g2_set_color(0xffffffff); + kinc_g2_draw_line(0, r / 2.0, r / 2.0 - 2.0 * UI_SCALE(), r - 2.0 * UI_SCALE(), 2.0 * UI_SCALE()); + kinc_g2_draw_line(r / 2.0 - 3.0 * UI_SCALE(), r - 3.0 * UI_SCALE(), r / 2.0 + 5.0 * UI_SCALE(), r - 11.0 * UI_SCALE(), 2.0 * UI_SCALE()); + kinc_g2_end(); if (current->radio_image.width != 0) { kinc_g4_render_target_destroy(¤t->radio_image); } r = UI_CHECK_SIZE(); kinc_g4_render_target_init(¤t->radio_image, r, r, KINC_G4_RENDER_TARGET_FORMAT_32BIT, 0, 0); - arm_g2_set_render_target(¤t->radio_image); + kinc_g2_set_render_target(¤t->radio_image); kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0x00000000, 0, 0); - arm_g2_set_color(0xffaaaaaa); - arm_g2_fill_circle(r / 2.0, r / 2.0, r / 2.0, 0); - arm_g2_set_color(0xffffffff); - arm_g2_draw_circle(r / 2.0, r / 2.0, r / 2.0, 0, 1.0 * UI_SCALE()); - arm_g2_end(); + kinc_g2_set_color(0xffaaaaaa); + kinc_g2_fill_circle(r / 2.0, r / 2.0, r / 2.0, 0); + kinc_g2_set_color(0xffffffff); + kinc_g2_draw_circle(r / 2.0, r / 2.0, r / 2.0, 0, 1.0 * UI_SCALE()); + kinc_g2_end(); if (current->radio_select_image.width != 0) { kinc_g4_render_target_destroy(¤t->radio_select_image); } r = UI_CHECK_SELECT_SIZE(); kinc_g4_render_target_init(¤t->radio_select_image, r, r, KINC_G4_RENDER_TARGET_FORMAT_32BIT, 0, 0); - arm_g2_set_render_target(¤t->radio_select_image); + kinc_g2_set_render_target(¤t->radio_select_image); kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0x00000000, 0, 0); - arm_g2_set_color(0xffaaaaaa); - arm_g2_fill_circle(r / 2.0, r / 2.0, 4.5 * UI_SCALE(), 0); - arm_g2_set_color(0xffffffff); - arm_g2_fill_circle(r / 2.0, r / 2.0, 4.0 * UI_SCALE(), 0); - arm_g2_end(); + kinc_g2_set_color(0xffaaaaaa); + kinc_g2_fill_circle(r / 2.0, r / 2.0, 4.5 * UI_SCALE(), 0); + kinc_g2_set_color(0xffffffff); + kinc_g2_fill_circle(r / 2.0, r / 2.0, 4.0 * UI_SCALE(), 0); + kinc_g2_end(); if (theme->ROUND_CORNERS) { if (current->filled_round_corner_image.width != 0) { @@ -938,24 +938,24 @@ void ui_bake_elements() { } r = 4.0 * UI_SCALE(); kinc_g4_render_target_init(¤t->filled_round_corner_image, r, r, KINC_G4_RENDER_TARGET_FORMAT_32BIT, 0, 0); - arm_g2_set_render_target(¤t->filled_round_corner_image); + kinc_g2_set_render_target(¤t->filled_round_corner_image); kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0x00000000, 0, 0); - arm_g2_set_color(0xffffffff); - arm_g2_fill_circle(r, r, r, 0); - arm_g2_end(); + kinc_g2_set_color(0xffffffff); + kinc_g2_fill_circle(r, r, r, 0); + kinc_g2_end(); if (current->round_corner_image.width != 0) { kinc_g4_render_target_destroy(¤t->round_corner_image); } kinc_g4_render_target_init(¤t->round_corner_image, r, r, KINC_G4_RENDER_TARGET_FORMAT_32BIT, 0, 0); - arm_g2_set_render_target(¤t->round_corner_image); + kinc_g2_set_render_target(¤t->round_corner_image); kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0x00000000, 0, 0); - arm_g2_set_color(0xffffffff); - arm_g2_draw_circle(r, r, r, 0, 1); - arm_g2_end(); + kinc_g2_set_color(0xffffffff); + kinc_g2_draw_circle(r, r, r, 0, 1); + kinc_g2_end(); } - arm_g2_restore_render_target(); + kinc_g2_restore_render_target(); current->elements_baked = true; } @@ -988,10 +988,10 @@ void ui_end_region(bool last) { } void ui_set_cursor_to_input(int align) { - float off = align == UI_ALIGN_LEFT ? UI_TEXT_OFFSET() : current->_w - arm_g2_string_width(current->ops->font->font_, current->font_size, current->text_selected); + float off = align == UI_ALIGN_LEFT ? UI_TEXT_OFFSET() : current->_w - kinc_g2_string_width(current->ops->font->font_, current->font_size, current->text_selected); float x = current->input_x - (current->_window_x + current->_x + off); current->cursor_x = 0; - while (current->cursor_x < strlen(current->text_selected) && arm_g2_sub_string_width(current->ops->font->font_, current->font_size, current->text_selected, 0, current->cursor_x) < x) { + while (current->cursor_x < strlen(current->text_selected) && kinc_g2_sub_string_width(current->ops->font->font_, current->font_size, current->text_selected, 0, current->cursor_x) < x) { current->cursor_x++; } current->highlight_anchor = current->cursor_x; @@ -1204,23 +1204,23 @@ void ui_update_text_edit(int align, bool editable, bool live_update) { iend = current->cursor_x; } - float hlstrw = arm_g2_sub_string_width(current->ops->font->font_, current->font_size, text, istart, iend); - float start_off = arm_g2_sub_string_width(current->ops->font->font_, current->font_size, text, 0, istart); + float hlstrw = kinc_g2_sub_string_width(current->ops->font->font_, current->font_size, text, istart, iend); + float start_off = kinc_g2_sub_string_width(current->ops->font->font_, current->font_size, text, 0, istart); float hl_start = align == UI_ALIGN_LEFT ? current->_x + start_off + off : current->_x + current->_w - hlstrw - off; if (align == UI_ALIGN_RIGHT) { - hl_start -= arm_g2_sub_string_width(current->ops->font->font_, current->font_size, text, iend, strlen(text)); + hl_start -= kinc_g2_sub_string_width(current->ops->font->font_, current->font_size, text, iend, strlen(text)); } - arm_g2_set_color(theme->ACCENT_COL); - arm_g2_fill_rect(hl_start, current->_y + current->button_offset_y * 1.5, hlstrw, cursor_height); + kinc_g2_set_color(theme->ACCENT_COL); + kinc_g2_fill_rect(hl_start, current->_y + current->button_offset_y * 1.5, hlstrw, cursor_height); } // Draw cursor int str_start = align == UI_ALIGN_LEFT ? 0 : current->cursor_x; int str_length = align == UI_ALIGN_LEFT ? current->cursor_x : (strlen(text) - current->cursor_x); - float strw = arm_g2_sub_string_width(current->ops->font->font_, current->font_size, text, str_start, str_length); + float strw = kinc_g2_sub_string_width(current->ops->font->font_, current->font_size, text, str_start, str_length); float cursor_x = align == UI_ALIGN_LEFT ? current->_x + strw + off : current->_x + current->_w - strw - off; - arm_g2_set_color(theme->TEXT_COL); // Cursor - arm_g2_fill_rect(cursor_x, current->_y + current->button_offset_y * 1.5, 1.0 * UI_SCALE(), cursor_height); + kinc_g2_set_color(theme->TEXT_COL); // Cursor + kinc_g2_fill_rect(cursor_x, current->_y + current->button_offset_y * 1.5, 1.0 * UI_SCALE(), cursor_height); strcpy(current->text_selected, text); if (live_update && current->text_selected_handle != NULL) { @@ -1267,20 +1267,20 @@ void ui_draw_tabs() { current->tab_handle->position = current->tab_count - 1; } - arm_g2_set_color(theme->SEPARATOR_COL); // Tab background + kinc_g2_set_color(theme->SEPARATOR_COL); // Tab background if (current->tab_vertical) { - arm_g2_fill_rect(0, current->_y, UI_ELEMENT_W(), current->_window_h); + kinc_g2_fill_rect(0, current->_y, UI_ELEMENT_W(), current->_window_h); } else { - arm_g2_fill_rect(0, current->_y, current->_window_w, current->button_offset_y + tab_h + 2); + kinc_g2_fill_rect(0, current->_y, current->_window_w, current->button_offset_y + tab_h + 2); } - arm_g2_set_color(theme->BUTTON_COL); // Underline tab buttons + kinc_g2_set_color(theme->BUTTON_COL); // Underline tab buttons if (current->tab_vertical) { - arm_g2_fill_rect(UI_ELEMENT_W(), current->_y, 1, current->_window_h); + kinc_g2_fill_rect(UI_ELEMENT_W(), current->_y, 1, current->_window_h); } else { - arm_g2_fill_rect(current->button_offset_y, current->_y + current->button_offset_y + tab_h + 2, current->_window_w - current->button_offset_y * 2.0, 1); + kinc_g2_fill_rect(current->button_offset_y, current->_y + current->button_offset_y + tab_h + 2, current->_window_w - current->button_offset_y * 2.0, 1); } float base_y = current->tab_vertical ? current->_y : current->_y + 2; @@ -1292,7 +1292,7 @@ void ui_draw_tabs() { current->_y = base_y + tab_y; current->_w = current->tab_vertical ? (UI_ELEMENT_W() - 1 * UI_SCALE()) : theme->FULL_TABS ? (current->_window_w / current->tab_count) : - (arm_g2_string_width(current->ops->font->font_, current->font_size, current->tab_names[i]) + current->button_offset_y * 2.0 + 18.0 * UI_SCALE()); + (kinc_g2_string_width(current->ops->font->font_, current->font_size, current->tab_names[i]) + current->button_offset_y * 2.0 + 18.0 * UI_SCALE()); bool released = ui_get_released(tab_h); bool started = ui_get_started(tab_h); bool pushed = ui_get_pushed(tab_h); @@ -1318,7 +1318,7 @@ void ui_draw_tabs() { } bool selected = current->tab_handle->position == i; - arm_g2_set_color((pushed || hover) ? theme->HOVER_COL : + kinc_g2_set_color((pushed || hover) ? theme->HOVER_COL : current->tab_colors[i] != -1 ? current->tab_colors[i] : selected ? theme->WINDOW_BG_COL : theme->SEPARATOR_COL); @@ -1329,8 +1329,8 @@ void ui_draw_tabs() { tab_x += current->_w + 1; } // ui_draw_rect(true, current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w, tab_h); // Round corners - arm_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w, tab_h); - arm_g2_set_color(theme->TEXT_COL); + kinc_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w, tab_h); + kinc_g2_set_color(theme->TEXT_COL); if (!selected) { ui_fade_color(0.65); } @@ -1339,19 +1339,19 @@ void ui_draw_tabs() { if (selected) { // Hide underline for active tab if (current->tab_vertical) { // Hide underline - // arm_g2_set_color(theme->WINDOW_BG_COL); - // arm_g2_fill_rect(current->_x + current->button_offset_y + current->_w - 1, current->_y + current->button_offset_y - 1, 2, tab_h + current->button_offset_y); + // kinc_g2_set_color(theme->WINDOW_BG_COL); + // kinc_g2_fill_rect(current->_x + current->button_offset_y + current->_w - 1, current->_y + current->button_offset_y - 1, 2, tab_h + current->button_offset_y); // Highlight - arm_g2_set_color(theme->HIGHLIGHT_COL); - arm_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y - 1, 2, tab_h + current->button_offset_y); + kinc_g2_set_color(theme->HIGHLIGHT_COL); + kinc_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y - 1, 2, tab_h + current->button_offset_y); } else { // Hide underline - arm_g2_set_color(theme->WINDOW_BG_COL); - arm_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y + tab_h, current->_w, 1); + kinc_g2_set_color(theme->WINDOW_BG_COL); + kinc_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y + tab_h, current->_w, 1); // Highlight - arm_g2_set_color(theme->HIGHLIGHT_COL); - arm_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w, 2); + kinc_g2_set_color(theme->HIGHLIGHT_COL); + kinc_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w, 2); } } @@ -1361,12 +1361,12 @@ void ui_draw_tabs() { if (sep_col < 0xff000000) { sep_col = theme->SEPARATOR_COL + 0x00050505; } - arm_g2_set_color(sep_col); + kinc_g2_set_color(sep_col); if (current->tab_vertical) { - arm_g2_fill_rect(current->_x, current->_y + tab_h, current->_w, 1); + kinc_g2_fill_rect(current->_x, current->_y + tab_h, current->_w, 1); } else { - arm_g2_fill_rect(current->_x + current->button_offset_y + current->_w, current->_y, 1, tab_h); + kinc_g2_fill_rect(current->_x + current->button_offset_y + current->_w, current->_y, 1, tab_h); } } } @@ -1382,14 +1382,14 @@ void ui_draw_tabs() { void ui_draw_arrow(bool selected) { float x = current->_x + current->arrow_offset_x; float y = current->_y + current->arrow_offset_y; - arm_g2_set_color(theme->TEXT_COL); + kinc_g2_set_color(theme->TEXT_COL); if (selected) { - arm_g2_fill_triangle(x, y, + kinc_g2_fill_triangle(x, y, x + UI_ARROW_SIZE(), y, x + UI_ARROW_SIZE() / 2.0, y + UI_ARROW_SIZE()); } else { - arm_g2_fill_triangle(x, y, + kinc_g2_fill_triangle(x, y, x, y + UI_ARROW_SIZE(), x + UI_ARROW_SIZE(), y + UI_ARROW_SIZE() / 2.0); } @@ -1399,13 +1399,13 @@ void ui_draw_tree(bool selected) { float SIGN_W = 7.0 * UI_SCALE(); float x = current->_x + current->arrow_offset_x + 1; float y = current->_y + current->arrow_offset_y + 1; - arm_g2_set_color(theme->TEXT_COL); + kinc_g2_set_color(theme->TEXT_COL); if (selected) { - arm_g2_fill_rect(x, y + SIGN_W / 2.0 - 1, SIGN_W, SIGN_W / 8.0); + kinc_g2_fill_rect(x, y + SIGN_W / 2.0 - 1, SIGN_W, SIGN_W / 8.0); } else { - arm_g2_fill_rect(x, y + SIGN_W / 2.0 - 1, SIGN_W, SIGN_W / 8.0); - arm_g2_fill_rect(x + SIGN_W / 2.0 - 1, y, SIGN_W / 8.0, SIGN_W); + kinc_g2_fill_rect(x, y + SIGN_W / 2.0 - 1, SIGN_W, SIGN_W / 8.0); + kinc_g2_fill_rect(x + SIGN_W / 2.0 - 1, y, SIGN_W / 8.0, SIGN_W); } } @@ -1413,34 +1413,34 @@ void ui_draw_check(bool selected, bool hover) { float x = current->_x + current->check_offset_x; float y = current->_y + current->check_offset_y; - arm_g2_set_color(selected ? theme->HIGHLIGHT_COL : theme->PRESSED_COL); + kinc_g2_set_color(selected ? theme->HIGHLIGHT_COL : theme->PRESSED_COL); ui_draw_rect(true, x, y, UI_CHECK_SIZE(), UI_CHECK_SIZE()); // Bg - arm_g2_set_color(hover ? theme->HOVER_COL : theme->BUTTON_COL); + kinc_g2_set_color(hover ? theme->HOVER_COL : theme->BUTTON_COL); ui_draw_rect(false, x, y, UI_CHECK_SIZE(), UI_CHECK_SIZE()); // Bg if (selected) { // Check - arm_g2_set_color(hover ? theme->TEXT_COL : theme->LABEL_COL); + kinc_g2_set_color(hover ? theme->TEXT_COL : theme->LABEL_COL); if (!current->enabled) { ui_fade_color(0.25); } int size = UI_CHECK_SELECT_SIZE(); - arm_g2_draw_scaled_render_target(¤t->check_select_image, x + current->check_select_offset_x, y + current->check_select_offset_y, size, size); + kinc_g2_draw_scaled_render_target(¤t->check_select_image, x + current->check_select_offset_x, y + current->check_select_offset_y, size, size); } } void ui_draw_radio(bool selected, bool hover) { float x = current->_x + current->radio_offset_x; float y = current->_y + current->radio_offset_y; - arm_g2_set_color(selected ? theme->HIGHLIGHT_COL : hover ? theme->HOVER_COL : theme->BUTTON_COL); - arm_g2_draw_render_target(¤t->radio_image, x, y); // Circle bg + kinc_g2_set_color(selected ? theme->HIGHLIGHT_COL : hover ? theme->HOVER_COL : theme->BUTTON_COL); + kinc_g2_draw_render_target(¤t->radio_image, x, y); // Circle bg if (selected) { // Check - arm_g2_set_color(theme->LABEL_COL); + kinc_g2_set_color(theme->LABEL_COL); if (!current->enabled) { ui_fade_color(0.25); } - arm_g2_draw_render_target(¤t->radio_select_image, x + current->radio_select_offset_x, y + current->radio_select_offset_y); // Circle + kinc_g2_draw_render_target(¤t->radio_select_image, x + current->radio_select_offset_x, y + current->radio_select_offset_y); // Circle } } @@ -1449,15 +1449,15 @@ void ui_draw_slider(float value, float from, float to, bool filled, bool hover) float y = current->_y + current->button_offset_y; float w = current->_w - current->button_offset_y * 2.0; - arm_g2_set_color(theme->PRESSED_COL); + kinc_g2_set_color(theme->PRESSED_COL); ui_draw_rect(true, x, y, w, UI_BUTTON_H()); // Bg if (hover) { - arm_g2_set_color(theme->HOVER_COL); + kinc_g2_set_color(theme->HOVER_COL); ui_draw_rect(false, x, y, w, UI_BUTTON_H()); // Bg } - arm_g2_set_color(hover ? theme->HOVER_COL : theme->BUTTON_COL); + kinc_g2_set_color(hover ? theme->HOVER_COL : theme->BUTTON_COL); float offset = (value - from) / (to - from); float bar_w = 8.0 * UI_SCALE(); // Unfilled bar float slider_x = filled ? x : x + (w - bar_w) * offset; @@ -1470,7 +1470,7 @@ void ui_draw_slider(float value, float from, float to, bool filled, bool hover) void ui_set_scale(float factor) { current->ops->scale_factor = factor; current->font_size = UI_FONT_SIZE(); - float font_height = arm_g2_font_height(current->ops->font->font_, current->font_size); + float font_height = kinc_g2_font_height(current->ops->font->font_, current->font_size); current->font_offset_y = (UI_ELEMENT_H() - font_height) / 2.0; // Precalculate offsets current->arrow_offset_y = (UI_ELEMENT_H() - UI_ARROW_SIZE()) / 2.0; current->arrow_offset_x = current->arrow_offset_y; @@ -1532,7 +1532,7 @@ void ui_begin_sticky() { } void ui_end_sticky() { - arm_g2_end(); + kinc_g2_end(); current->sticky = false; current->scissor = true; kinc_g4_scissor(0, current->_y, current->_window_w, current->_window_h - current->_y); @@ -1558,8 +1558,8 @@ void ui_end_window(bool bind_global_g) { } if (handle->drag_enabled) { // Draggable header - arm_g2_set_color(theme->SEPARATOR_COL); - arm_g2_fill_rect(0, 0, current->_window_w, UI_HEADER_DRAG_H()); + kinc_g2_set_color(theme->SEPARATOR_COL); + kinc_g2_fill_rect(0, 0, current->_window_w, UI_HEADER_DRAG_H()); } float window_size = handle->layout == UI_LAYOUT_VERTICAL ? current->_window_h - current->window_header_h : current->_window_w - current->window_header_w; // Exclude header @@ -1616,7 +1616,7 @@ void ui_end_window(bool bind_global_g) { } if (handle->layout == UI_LAYOUT_VERTICAL) { - arm_g2_set_color(theme->BUTTON_COL); // Bar + kinc_g2_set_color(theme->BUTTON_COL); // Bar bool scrollbar_focus = ui_input_in_rect(current->_window_x + current->_window_w - UI_SCROLL_W(), wy, UI_SCROLL_W(), window_size); float bar_w = (scrollbar_focus || handle == current->scroll_handle) ? UI_SCROLL_W() : UI_SCROLL_MINI_W(); ui_draw_rect(true, current->_window_w - bar_w - current->scroll_align, bar_y, bar_w, bar_h); @@ -1639,10 +1639,10 @@ void ui_end_window(bool bind_global_g) { // Draw window texture if (ui_always_redraw_window || handle->redraws > -4) { if (bind_global_g) { - arm_g2_restore_render_target(); + kinc_g2_restore_render_target(); } - arm_g2_set_color(0xffffffff); - arm_g2_draw_render_target(&handle->texture, current->_window_x, current->_window_y); + kinc_g2_set_color(0xffffffff); + kinc_g2_draw_render_target(&handle->texture, current->_window_x, current->_window_y); if (handle->redraws <= 0) { handle->redraws--; } @@ -1666,7 +1666,7 @@ bool _ui_window(ui_handle_t *handle, int x, int y, int w, int h, bool drag) { } current->window_ended = false; - arm_g2_set_render_target(&handle->texture); + kinc_g2_set_render_target(&handle->texture); current->current_window = handle; current->_window_x = x + handle->drag_x; current->_window_y = y + handle->drag_y; @@ -1719,8 +1719,8 @@ bool _ui_window(ui_handle_t *handle, int x, int y, int w, int h, bool drag) { } else { kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0x00000000, 0, 0); - arm_g2_set_color(theme->WINDOW_BG_COL); - arm_g2_fill_rect(current->_x, current->_y - handle->scroll_offset, handle->last_max_x, handle->last_max_y); + kinc_g2_set_color(theme->WINDOW_BG_COL); + kinc_g2_fill_rect(current->_x, current->_y - handle->scroll_offset, handle->last_max_x, handle->last_max_y); } handle->drag_enabled = drag; @@ -1755,7 +1755,7 @@ bool ui_button(char *text, int align, char *label/*, kinc_g4_texture_t *icon, in current->changed = true; } - arm_g2_set_color(pushed ? theme->PRESSED_COL : + kinc_g2_set_color(pushed ? theme->PRESSED_COL : (!theme->FILL_BUTTON_BG && hover) ? theme->HIGHLIGHT_COL : hover ? theme->HOVER_COL : theme->BUTTON_COL); @@ -1765,21 +1765,21 @@ bool ui_button(char *text, int align, char *label/*, kinc_g4_texture_t *icon, in current->_w - current->button_offset_y * 2, UI_BUTTON_H()); } - arm_g2_set_color(theme->TEXT_COL); + kinc_g2_set_color(theme->TEXT_COL); ui_draw_string(text, theme->TEXT_OFFSET, 0, align, true); if (label != NULL) { - arm_g2_set_color(theme->LABEL_COL); + kinc_g2_set_color(theme->LABEL_COL); ui_draw_string(label, theme->TEXT_OFFSET, 0, align == UI_ALIGN_RIGHT ? UI_ALIGN_LEFT : UI_ALIGN_RIGHT, true); } /* if (icon != NULL) { - arm_g2_set_color(0xffffffff); + kinc_g2_set_color(0xffffffff); if (current->image_invert_y) { - arm_g2_draw_scaled_sub_image(icon, sx, sy, sw, sh, _x + current->button_offset_y, _y - 1 + sh, sw, -sh); + kinc_g2_draw_scaled_sub_texture(icon, sx, sy, sw, sh, _x + current->button_offset_y, _y - 1 + sh, sw, -sh); } else { - arm_g2_draw_scaled_sub_image(icon, sx, sy, sw, sh, _x + current->button_offset_y, _y - 1, sw, sh); + kinc_g2_draw_scaled_sub_texture(icon, sx, sy, sw, sh, _x + current->button_offset_y, _y - 1, sw, sh); } } */ @@ -1800,7 +1800,7 @@ int ui_text(char *text, int align, int bg) { ui_split_text(text, align, bg); return UI_STATE_IDLE; } - float h = fmax(UI_ELEMENT_H(), arm_g2_font_height(current->ops->font->font_, current->font_size)); + float h = fmax(UI_ELEMENT_H(), kinc_g2_font_height(current->ops->font->font_, current->font_size)); if (!ui_is_visible(h)) { ui_end_element_of_size(h + UI_ELEMENT_OFFSET()); return UI_STATE_IDLE; @@ -1810,10 +1810,10 @@ int ui_text(char *text, int align, int bg) { bool released = ui_get_released(h); bool hover = ui_get_hover(h); if (bg != 0x0000000) { - arm_g2_set_color(bg); - arm_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w - current->button_offset_y * 2, UI_BUTTON_H()); + kinc_g2_set_color(bg); + kinc_g2_fill_rect(current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w - current->button_offset_y * 2, UI_BUTTON_H()); } - arm_g2_set_color(theme->TEXT_COL); + kinc_g2_set_color(theme->TEXT_COL); ui_draw_string(text, theme->TEXT_OFFSET, 0, align, true); ui_end_element_of_size(h + UI_ELEMENT_OFFSET()); @@ -1869,7 +1869,7 @@ bool ui_panel(ui_handle_t *handle, char *text, bool is_tree, bool filled) { ui_draw_arrow(handle->selected); } - arm_g2_set_color(theme->LABEL_COL); // Title + kinc_g2_set_color(theme->LABEL_COL); // Title ui_draw_string(text, current->title_offset_x, 0, UI_ALIGN_LEFT, true); ui_end_element(); @@ -1896,19 +1896,19 @@ static int image_height(void *image, bool is_rt) { static void draw_scaled_image(void *image, bool is_rt, float dx, float dy, float dw, float dh) { if (is_rt) { - arm_g2_draw_scaled_render_target((kinc_g4_render_target_t *)image, dx, dy, dw, dh); + kinc_g2_draw_scaled_render_target((kinc_g4_render_target_t *)image, dx, dy, dw, dh); } else { - arm_g2_draw_scaled_image((kinc_g4_texture_t *)image, dx, dy, dw, dh); + kinc_g2_draw_scaled_image((kinc_g4_texture_t *)image, dx, dy, dw, dh); } } static void draw_scaled_sub_image(void *image, bool is_rt, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { if (is_rt) { - arm_g2_draw_scaled_sub_render_target((kinc_g4_render_target_t *)image, sx, sy, sw, sh, dx, dy, dw, dh); + kinc_g2_draw_scaled_sub_render_target((kinc_g4_render_target_t *)image, sx, sy, sw, sh, dx, dy, dw, dh); } else { - arm_g2_draw_scaled_sub_image((kinc_g4_texture_t *)image, sx, sy, sw, sh, dx, dy, dw, dh); + kinc_g2_draw_scaled_sub_texture((kinc_g4_texture_t *)image, sx, sy, sw, sh, dx, dy, dw, dh); } } @@ -1958,7 +1958,7 @@ int ui_sub_image(/*kinc_g4_texture_t kinc_g4_render_target_t*/ void *image, bool // } // } - arm_g2_set_color(tint); + kinc_g2_set_color(tint); if (!current->enabled) { ui_fade_color(0.25); } @@ -1997,7 +1997,7 @@ char *ui_text_input(ui_handle_t *handle, char *label, int align, bool editable, if (hover && ui_on_text_hover != NULL) { ui_on_text_hover(); } - arm_g2_set_color(hover ? theme->HOVER_COL : theme->BUTTON_COL); // Text bg + kinc_g2_set_color(hover ? theme->HOVER_COL : theme->BUTTON_COL); // Text bg ui_draw_rect(false, current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w - current->button_offset_y * 2, UI_BUTTON_H()); bool released = ui_get_released(UI_ELEMENT_H()); @@ -2024,12 +2024,12 @@ char *ui_text_input(ui_handle_t *handle, char *label, int align, bool editable, } if (label[0] != '\0') { - arm_g2_set_color(theme->LABEL_COL); // Label + kinc_g2_set_color(theme->LABEL_COL); // Label int label_align = align == UI_ALIGN_RIGHT ? UI_ALIGN_LEFT : UI_ALIGN_RIGHT; ui_draw_string(label, label_align == UI_ALIGN_LEFT ? theme->TEXT_OFFSET : 0, 0, label_align, true); } - arm_g2_set_color(theme->TEXT_COL); // Text + kinc_g2_set_color(theme->TEXT_COL); // Text if (current->text_selected_handle != handle) { ui_draw_string(handle->text, theme->TEXT_OFFSET, 0, align, true); } @@ -2055,11 +2055,11 @@ bool ui_check(ui_handle_t *handle, char *text, char *label) { bool hover = ui_get_hover(UI_ELEMENT_H()); ui_draw_check(handle->selected, hover); // Check - arm_g2_set_color(theme->TEXT_COL); // Text + kinc_g2_set_color(theme->TEXT_COL); // Text ui_draw_string(text, current->title_offset_x, 0, UI_ALIGN_LEFT, true); if (label[0] != '\0') { - arm_g2_set_color(theme->LABEL_COL); + kinc_g2_set_color(theme->LABEL_COL); ui_draw_string(label, theme->TEXT_OFFSET, 0, UI_ALIGN_RIGHT, true); } @@ -2084,11 +2084,11 @@ bool ui_radio(ui_handle_t *handle, int position, char *text, char *label) { bool hover = ui_get_hover(UI_ELEMENT_H()); ui_draw_radio(handle->position == position, hover); // Radio - arm_g2_set_color(theme->TEXT_COL); // Text + kinc_g2_set_color(theme->TEXT_COL); // Text ui_draw_string(text, current->title_offset_x, 0, UI_ALIGN_LEFT, true); if (label[0] != '\0') { - arm_g2_set_color(theme->LABEL_COL); + kinc_g2_set_color(theme->LABEL_COL); ui_draw_string(label, theme->TEXT_OFFSET, 0, UI_ALIGN_RIGHT, true); } @@ -2115,7 +2115,7 @@ int ui_combo(ui_handle_t *handle, char_ptr_array_t *texts, char *label, bool sho current->combo_selected_w = current->_w; current->combo_search_bar = search_bar; for (int i = 0; i < texts->length; ++i) { // Adapt combo list width to combo item width - int w = (int)arm_g2_string_width(current->ops->font->font_, current->font_size, texts->buffer[i]) + 10; + int w = (int)kinc_g2_string_width(current->ops->font->font_, current->font_size, texts->buffer[i]) + 10; if (current->combo_selected_w < w) { current->combo_selected_w = w; } @@ -2144,30 +2144,30 @@ int ui_combo(ui_handle_t *handle, char_ptr_array_t *texts, char *label, bool sho handle->changed = false; } - arm_g2_set_color(theme->PRESSED_COL); // Bg + kinc_g2_set_color(theme->PRESSED_COL); // Bg ui_draw_rect(true, current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w - current->button_offset_y * 2, UI_BUTTON_H()); bool hover = ui_get_hover(UI_ELEMENT_H()); - arm_g2_set_color(hover ? theme->HOVER_COL : theme->BUTTON_COL); + kinc_g2_set_color(hover ? theme->HOVER_COL : theme->BUTTON_COL); ui_draw_rect(false, current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w - current->button_offset_y * 2, UI_BUTTON_H()); int x = current->_x + current->_w - current->arrow_offset_x - 8; int y = current->_y + current->arrow_offset_y + 3; - arm_g2_set_color(theme->HOVER_COL); + kinc_g2_set_color(theme->HOVER_COL); // if (handle == current->combo_selected_handle) { // // Flip arrow when combo is open - // arm_g2_fill_triangle(x, y, x + UI_ARROW_SIZE(), y, x + UI_ARROW_SIZE() / 2.0, y - UI_ARROW_SIZE() / 2.0); + // kinc_g2_fill_triangle(x, y, x + UI_ARROW_SIZE(), y, x + UI_ARROW_SIZE() / 2.0, y - UI_ARROW_SIZE() / 2.0); // } // else { - arm_g2_fill_triangle(x, y, x + UI_ARROW_SIZE(), y, x + UI_ARROW_SIZE() / 2.0, y + UI_ARROW_SIZE() / 2.0); + kinc_g2_fill_triangle(x, y, x + UI_ARROW_SIZE(), y, x + UI_ARROW_SIZE() / 2.0, y + UI_ARROW_SIZE() / 2.0); // } if (show_label && label[0] != '\0') { if (align == UI_ALIGN_LEFT) { current->_x -= 15; } - arm_g2_set_color(theme->LABEL_COL); + kinc_g2_set_color(theme->LABEL_COL); ui_draw_string(label, theme->TEXT_OFFSET, 0, align == UI_ALIGN_LEFT ? UI_ALIGN_RIGHT : UI_ALIGN_LEFT, true); if (align == UI_ALIGN_LEFT) { current->_x += 15; @@ -2177,7 +2177,7 @@ int ui_combo(ui_handle_t *handle, char_ptr_array_t *texts, char *label, bool sho if (align == UI_ALIGN_RIGHT) { current->_x -= 15; } - arm_g2_set_color(theme->TEXT_COL); // Value + kinc_g2_set_color(theme->TEXT_COL); // Value if (handle->position < texts->length) { ui_draw_string(texts->buffer[handle->position], theme->TEXT_OFFSET, 0, align, true); } @@ -2257,11 +2257,11 @@ float ui_slider(ui_handle_t *handle, char *text, float from, float to, bool fill handle->changed = current->changed = true; } - arm_g2_set_color(theme->LABEL_COL); // Text + kinc_g2_set_color(theme->LABEL_COL); // Text ui_draw_string(text, theme->TEXT_OFFSET, 0, align, true); if (display_value) { - arm_g2_set_color(theme->TEXT_COL); // Value + kinc_g2_set_color(theme->TEXT_COL); // Value if (current->text_selected_handle != handle) { sprintf(temp, "%.2f", round(handle->value * precision) / precision); string_strip_trailing_zeros(temp); @@ -2282,8 +2282,8 @@ void ui_separator(int h, bool fill) { return; } if (fill) { - arm_g2_set_color(theme->SEPARATOR_COL); - arm_g2_fill_rect(current->_x, current->_y, current->_w, h * UI_SCALE()); + kinc_g2_set_color(theme->SEPARATOR_COL); + kinc_g2_fill_rect(current->_x, current->_y, current->_w, h * UI_SCALE()); } current->_y += h * UI_SCALE(); } diff --git a/armorcore/sources/iron_ui_ext.c b/armorcore/sources/iron_ui_ext.c index c7f2c6fda..a4e9bad1a 100644 --- a/armorcore/sources/iron_ui_ext.c +++ b/armorcore/sources/iron_ui_ext.c @@ -199,20 +199,20 @@ int ui_inline_radio(ui_handle_t *handle, char_ptr_array_t *texts, int align) { for (int i = 0; i < texts->length; ++i) { if (handle->position == i) { - arm_g2_set_color(current->ops->theme->HIGHLIGHT_COL); + kinc_g2_set_color(current->ops->theme->HIGHLIGHT_COL); if (!current->enabled) { ui_fade_color(0.25); } ui_draw_rect(true, current->_x + step * i, current->_y + current->button_offset_y, step, UI_BUTTON_H()); } else if (hovered == i) { - arm_g2_set_color(current->ops->theme->BUTTON_COL); + kinc_g2_set_color(current->ops->theme->BUTTON_COL); if (!current->enabled) { ui_fade_color(0.25); } ui_draw_rect(false, current->_x + step * i, current->_y + current->button_offset_y, step, UI_BUTTON_H()); } - arm_g2_set_color(current->ops->theme->TEXT_COL); // Text + kinc_g2_set_color(current->ops->theme->TEXT_COL); // Text current->_x += step * i; float _w = current->_w; current->_w = (int)step; @@ -306,15 +306,15 @@ int ui_color_wheel(ui_handle_t *handle, bool alpha, float w, float h, bool color current->_y = py; ui_image(current->ops->black_white_gradient, false, 0xffffffff, -1); - arm_g2_set_color(0xff000000); - arm_g2_fill_rect(cx - 3.0 * UI_SCALE(), cy - 3.0 * UI_SCALE(), 6.0 * UI_SCALE(), 6.0 * UI_SCALE()); - arm_g2_set_color(0xffffffff); - arm_g2_fill_rect(cx - 2.0 * UI_SCALE(), cy - 2.0 * UI_SCALE(), 4.0 * UI_SCALE(), 4.0 * UI_SCALE()); + kinc_g2_set_color(0xff000000); + kinc_g2_fill_rect(cx - 3.0 * UI_SCALE(), cy - 3.0 * UI_SCALE(), 6.0 * UI_SCALE(), 6.0 * UI_SCALE()); + kinc_g2_set_color(0xffffffff); + kinc_g2_fill_rect(cx - 2.0 * UI_SCALE(), cy - 2.0 * UI_SCALE(), 4.0 * UI_SCALE(), 4.0 * UI_SCALE()); - arm_g2_set_color(0xff000000); - arm_g2_fill_rect(grad_tx + grad_w / 2.0 - 3.0 * UI_SCALE(), grad_ty + (1.0 - cval) * grad_h - 3.0 * UI_SCALE(), 6.0 * UI_SCALE(), 6.0 * UI_SCALE()); - arm_g2_set_color(0xffffffff); - arm_g2_fill_rect(grad_tx + grad_w / 2.0 - 2.0 * UI_SCALE(), grad_ty + (1.0 - cval) * grad_h - 2.0 * UI_SCALE(), 4.0 * UI_SCALE(), 4.0 * UI_SCALE()); + kinc_g2_set_color(0xff000000); + kinc_g2_fill_rect(grad_tx + grad_w / 2.0 - 3.0 * UI_SCALE(), grad_ty + (1.0 - cval) * grad_h - 3.0 * UI_SCALE(), 6.0 * UI_SCALE(), 6.0 * UI_SCALE()); + kinc_g2_set_color(0xffffffff); + kinc_g2_fill_rect(grad_tx + grad_w / 2.0 - 2.0 * UI_SCALE(), grad_ty + (1.0 - cval) * grad_h - 2.0 * UI_SCALE(), 4.0 * UI_SCALE(), 4.0 * UI_SCALE()); if (alpha) { ui_handle_t *alpha_handle = ui_nest(handle, 1); @@ -557,9 +557,9 @@ char *ui_text_area(ui_handle_t *handle, int align, bool editable, char *label, b new_lines[0] = '\0'; for (int i = 0; i < word_count; ++i) { char *w = ui_extract_word(lines, i); - float spacew = arm_g2_string_width(current->ops->font->font_, current->font_size, " "); - float wordw = spacew + arm_g2_string_width(current->ops->font->font_, current->font_size, w); - float linew = wordw + arm_g2_string_width(current->ops->font->font_, current->font_size, line); + float spacew = kinc_g2_string_width(current->ops->font->font_, current->font_size, " "); + float wordw = spacew + kinc_g2_string_width(current->ops->font->font_, current->font_size, w); + float linew = wordw + kinc_g2_string_width(current->ops->font->font_, current->font_size, line); if (linew > current->_w - 10 && linew > wordw) { if (new_lines[0] != '\0') { strcat(new_lines, "\n"); @@ -619,7 +619,7 @@ char *ui_text_area(ui_handle_t *handle, int align, bool editable, char *label, b current->_w -= numbers_w - UI_SCROLL_W(); } - arm_g2_set_color(current->ops->theme->SEPARATOR_COL); // Background + kinc_g2_set_color(current->ops->theme->SEPARATOR_COL); // Background ui_draw_rect(true, current->_x + current->button_offset_y, current->_y + current->button_offset_y, current->_w - current->button_offset_y * 2, line_count * UI_ELEMENT_H() - current->button_offset_y * 2); ui_text_coloring_t *_text_coloring = current->text_coloring; @@ -659,9 +659,9 @@ char *ui_text_area(ui_handle_t *handle, int align, bool editable, char *label, b (i <= text_area_selection_start && i > handle->position)) { int line_height = UI_ELEMENT_H(); int cursor_height = line_height - current->button_offset_y * 3.0; - int linew = arm_g2_string_width(current->ops->font->font_, current->font_size, line); - arm_g2_set_color(current->ops->theme->ACCENT_COL); - arm_g2_fill_rect(current->_x + UI_ELEMENT_OFFSET() * 2.0, current->_y + current->button_offset_y * 1.5, linew, cursor_height); + int linew = kinc_g2_string_width(current->ops->font->font_, current->font_size, line); + kinc_g2_set_color(current->ops->theme->ACCENT_COL); + kinc_g2_fill_rect(current->_x + UI_ELEMENT_OFFSET() * 2.0, current->_y + current->button_offset_y * 1.5, linew, cursor_height); } ui_text(line, align, 0x00000000); } @@ -722,8 +722,8 @@ void ui_begin_menu() { _BUTTON_COL = current->ops->theme->BUTTON_COL; current->ops->theme->ELEMENT_OFFSET = 0; current->ops->theme->BUTTON_COL = current->ops->theme->SEPARATOR_COL; - arm_g2_set_color(current->ops->theme->SEPARATOR_COL); - arm_g2_fill_rect(0, 0, current->_window_w, UI_MENUBAR_H()); + kinc_g2_set_color(current->ops->theme->SEPARATOR_COL); + kinc_g2_fill_rect(0, 0, current->_window_w, UI_MENUBAR_H()); } void ui_end_menu() { @@ -734,6 +734,6 @@ void ui_end_menu() { bool _ui_menu_button(char *text) { ui_t *current = ui_get_current(); - current->_w = arm_g2_string_width(current->ops->font->font_, current->font_size, text) + 25.0 * UI_SCALE(); + current->_w = kinc_g2_string_width(current->ops->font->font_, current->font_size, text) + 25.0 * UI_SCALE(); return ui_button(text, UI_ALIGN_CENTER, ""); } diff --git a/armorcore/sources/iron_ui_nodes.c b/armorcore/sources/iron_ui_nodes.c index ed10497d0..781132488 100644 --- a/armorcore/sources/iron_ui_nodes.c +++ b/armorcore/sources/iron_ui_nodes.c @@ -238,15 +238,15 @@ void ui_nodes_bake_elements() { kinc_g4_render_target_destroy(&ui_socket_image); } kinc_g4_render_target_init(&ui_socket_image, 24, 24, KINC_G4_RENDER_TARGET_FORMAT_32BIT, 0, 0); - arm_g2_set_render_target(&ui_socket_image); + kinc_g2_set_render_target(&ui_socket_image); kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0x00000000, 0, 0); - arm_g2_set_color(0xff111111); - arm_g2_fill_circle(12, 12, 11, 0); - arm_g2_set_color(0xffffffff); - arm_g2_fill_circle(12, 12, 9, 0); + kinc_g2_set_color(0xff111111); + kinc_g2_fill_circle(12, 12, 11, 0); + kinc_g2_set_color(0xffffffff); + kinc_g2_fill_circle(12, 12, 9, 0); - arm_g2_restore_render_target(); + kinc_g2_restore_render_target(); ui_nodes_elements_baked = true; } @@ -264,14 +264,14 @@ void ui_draw_link(float x1, float y1, float x2, float y2, bool highlight) { int c1 = current->ops->theme->LABEL_COL; int c2 = current->ops->theme->ACCENT_COL; int c = highlight ? c1 : c2; - arm_g2_set_color(ui_color(ui_color_r(c), ui_color_g(c), ui_color_b(c), 210)); + kinc_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_aa(x1, y1, x2, y2, 1.0); + kinc_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 }; float y[] = { y1, y1, y2, y2 }; - arm_g2_draw_cubic_bezier(x, y, 30, highlight ? 2.0 : 1.0); + kinc_g2_draw_cubic_bezier(x, y, 30, highlight ? 2.0 : 1.0); } } @@ -406,37 +406,37 @@ void ui_draw_node(ui_node_t *node, ui_node_canvas_t *canvas) { ui_draw_shadow(nx, ny, w, h); // Outline - arm_g2_set_color(ui_is_selected(node) ? current->ops->theme->LABEL_COL : current->ops->theme->PRESSED_COL); + kinc_g2_set_color(ui_is_selected(node) ? current->ops->theme->LABEL_COL : current->ops->theme->PRESSED_COL); ui_draw_rect(true, nx - 1, ny - 1, w + 2, h + 2); // Body - arm_g2_set_color(current->ops->theme->WINDOW_BG_COL); + kinc_g2_set_color(current->ops->theme->WINDOW_BG_COL); ui_draw_rect(true, nx, ny, w, h); // Header line - arm_g2_set_color(node->color); - arm_g2_fill_rect(nx, ny + lineh - ui_p(3), w, ui_p(3)); + kinc_g2_set_color(node->color); + kinc_g2_fill_rect(nx, ny + lineh - ui_p(3), w, ui_p(3)); // Title - arm_g2_set_color(current->ops->theme->TEXT_COL); - float textw = arm_g2_string_width(current->ops->font->font_, current->font_size, text); - arm_g2_draw_string(text, nx + ui_p(10), ny + ui_p(6)); + kinc_g2_set_color(current->ops->theme->TEXT_COL); + float textw = kinc_g2_string_width(current->ops->font->font_, current->font_size, text); + kinc_g2_draw_string(text, nx + ui_p(10), ny + ui_p(6)); ny += lineh * 0.5; // Outputs for (int i = 0; i < node->outputs->length; ++i) { ui_node_socket_t *out = node->outputs->buffer[i]; ny += lineh; - arm_g2_set_color(out->color); - arm_g2_draw_scaled_render_target(&ui_socket_image, nx + w - ui_p(6), ny - ui_p(3), ui_p(12), ui_p(12)); + kinc_g2_set_color(out->color); + kinc_g2_draw_scaled_render_target(&ui_socket_image, nx + w - ui_p(6), ny - ui_p(3), ui_p(12), ui_p(12)); } ny -= lineh * node->outputs->length; - arm_g2_set_color(current->ops->theme->LABEL_COL); + kinc_g2_set_color(current->ops->theme->LABEL_COL); for (int i = 0; i < node->outputs->length; ++i) { ui_node_socket_t *out = node->outputs->buffer[i]; ny += lineh; - float strw = arm_g2_string_width(current->ops->font->font_, current->font_size, ui_tr(out->name)); - arm_g2_draw_string(ui_tr(out->name), nx + w - strw - ui_p(12), ny - ui_p(3)); + float strw = kinc_g2_string_width(current->ops->font->font_, current->font_size, ui_tr(out->name)); + kinc_g2_draw_string(ui_tr(out->name), nx + w - strw - ui_p(12), ny - ui_p(3)); if (ui_nodes_on_socket_released != NULL && current->input_enabled && (current->input_released || current->input_released_r)) { if (current->input_x > wx + nx && current->input_x < wx + nx + w && current->input_y > wy + ny && current->input_y < wy + ny + lineh) { @@ -611,8 +611,8 @@ void ui_draw_node(ui_node_t *node, ui_node_canvas_t *canvas) { for (int i = 0; i < node->inputs->length; ++i) { ui_node_socket_t *inp = node->inputs->buffer[i]; ny += lineh; - arm_g2_set_color(inp->color); - arm_g2_draw_scaled_render_target(&ui_socket_image, nx - ui_p(6), ny - ui_p(3), ui_p(12), ui_p(12)); + kinc_g2_set_color(inp->color); + kinc_g2_draw_scaled_render_target(&ui_socket_image, nx - ui_p(6), ny - ui_p(3), ui_p(12), ui_p(12)); bool is_linked = ui_input_linked(canvas, node->id, i); if (!is_linked && strcmp(inp->type, "VALUE") == 0) { current->_x = nx + ui_p(6); @@ -649,18 +649,18 @@ void ui_draw_node(ui_node_t *node, ui_node_canvas_t *canvas) { current->ops->theme->TEXT_OFFSET = text_off; } else if (!is_linked && strcmp(inp->type, "RGBA") == 0) { - arm_g2_set_color(current->ops->theme->LABEL_COL); - arm_g2_draw_string(ui_tr(inp->name), nx + ui_p(12), ny - ui_p(3)); + kinc_g2_set_color(current->ops->theme->LABEL_COL); + kinc_g2_draw_string(ui_tr(inp->name), nx + ui_p(12), ny - ui_p(3)); ui_node_socket_t *soc = inp; - arm_g2_set_color(0xff000000); - arm_g2_fill_rect(nx + w - ui_p(38), ny - ui_p(6), ui_p(36), ui_p(18)); + kinc_g2_set_color(0xff000000); + kinc_g2_fill_rect(nx + w - ui_p(38), ny - ui_p(6), ui_p(36), ui_p(18)); float *val = (float *)soc->default_value->buffer; - arm_g2_set_color(ui_color(val[0] * 255, val[1] * 255, val[2] * 255, 255)); + kinc_g2_set_color(ui_color(val[0] * 255, val[1] * 255, val[2] * 255, 255)); float rx = nx + w - ui_p(37); float ry = ny - ui_p(5); float rw = ui_p(34); float rh = ui_p(16); - arm_g2_fill_rect(rx, ry, rw, rh); + kinc_g2_fill_rect(rx, ry, rw, rh); float ix = current->input_x - wx; float iy = current->input_y - wy; if (current->input_started && ix > rx && iy > ry && ix < rx + rw && iy < ry + rh) { @@ -676,8 +676,8 @@ void ui_draw_node(ui_node_t *node, ui_node_canvas_t *canvas) { } } else if (!is_linked && strcmp(inp->type, "VECTOR") == 0 && inp->display == 1) { - arm_g2_set_color(current->ops->theme->LABEL_COL); - arm_g2_draw_string(ui_tr(inp->name), nx + ui_p(12), ny - ui_p(3)); + kinc_g2_set_color(current->ops->theme->LABEL_COL); + kinc_g2_draw_string(ui_tr(inp->name), nx + ui_p(12), ny - ui_p(3)); ny += lineh / 2; current->_x = nx; current->_y = ny; @@ -708,8 +708,8 @@ void ui_draw_node(ui_node_t *node, ui_node_canvas_t *canvas) { ny += lineh * 2.5; } else { - arm_g2_set_color(current->ops->theme->LABEL_COL); - arm_g2_draw_string(ui_tr(inp->name), nx + ui_p(12), ny - ui_p(3)); + kinc_g2_set_color(current->ops->theme->LABEL_COL); + kinc_g2_draw_string(ui_tr(inp->name), nx + ui_p(12), ny - ui_p(3)); } if (ui_nodes_on_socket_released != NULL && current->input_enabled && (current->input_released || current->input_released_r)) { if (current->input_x > wx + nx && current->input_x < wx + nx + w && current->input_y > wy + ny && current->input_y < wy + ny + lineh) { @@ -780,7 +780,7 @@ void ui_node_canvas(ui_nodes_t *nodes, ui_node_canvas_t *canvas) { current_nodes->ELEMENT_H = current->ops->theme->ELEMENT_H + 2; ui_set_scale(UI_NODES_SCALE()); // Apply zoomed scale current->elements_baked = true; - arm_g2_set_font(current->ops->font->font_, current->font_size); + kinc_g2_set_font(current->ops->font->font_, current->font_size); for (int i = 0; i < canvas->links->length; ++i) { ui_node_link_t *link = canvas->links->buffer[i]; @@ -1016,11 +1016,11 @@ void ui_node_canvas(ui_nodes_t *nodes, ui_node_canvas_t *canvas) { } if (ui_box_select) { - arm_g2_set_color(0x223333dd); - arm_g2_fill_rect(ui_box_select_x, ui_box_select_y, current->input_x - ui_box_select_x - current->_window_x, current->input_y - ui_box_select_y - current->_window_y); - arm_g2_set_color(0x773333dd); - arm_g2_draw_rect(ui_box_select_x, ui_box_select_y, current->input_x - ui_box_select_x - current->_window_x, current->input_y - ui_box_select_y - current->_window_y, 1); - arm_g2_set_color(0xffffffff); + kinc_g2_set_color(0x223333dd); + kinc_g2_fill_rect(ui_box_select_x, ui_box_select_y, current->input_x - ui_box_select_x - current->_window_x, current->input_y - ui_box_select_y - current->_window_y); + kinc_g2_set_color(0x773333dd); + kinc_g2_draw_rect(ui_box_select_x, ui_box_select_y, current->input_x - ui_box_select_x - current->_window_x, current->input_y - ui_box_select_y - current->_window_y, 1); + kinc_g2_set_color(0xffffffff); } if (current->input_enabled && current->input_started && !current->is_alt_down && current_nodes->link_drag_id == -1 && !current_nodes->nodes_drag && !current->changed && @@ -1227,7 +1227,7 @@ void ui_node_canvas(ui_nodes_t *nodes, ui_node_canvas_t *canvas) { current->_w = ui_popup_w; ui_draw_shadow(current->_x - 5, current->_y - 5, current->_w + 10, ui_popup_h * UI_SCALE() + 10); - arm_g2_set_color(current->ops->theme->SEPARATOR_COL); + kinc_g2_set_color(current->ops->theme->SEPARATOR_COL); ui_draw_rect(true, current->_x - 5, current->_y - 5, current->_w + 10, ui_popup_h * UI_SCALE() + 10); (*ui_popup_commands)(current, ui_popup_data, ui_popup_data2); diff --git a/armorcore/sources/kinc/graphics2/g2.c b/armorcore/sources/kinc/graphics2/g2.c index a47dca893..2deb8626f 100644 --- a/armorcore/sources/kinc/graphics2/g2.c +++ b/armorcore/sources/kinc/graphics2/g2.c @@ -18,13 +18,16 @@ #include #include #include +#ifdef KINC_DIRECT3D12 +extern bool waitAfterNextDraw; +#endif #define G2_BUFFER_SIZE 1000 static kinc_matrix4x4_t g2_projection_matrix; static bool g2_bilinear_filter = true; static uint32_t g2_color = 0; -static arm_g2_font_t *g2_font = NULL; +static kinc_g2_font_t *g2_font = NULL; static int g2_font_size; static bool g2_is_render_target = false; static kinc_g4_pipeline_t *g2_last_pipeline = NULL; @@ -77,13 +80,13 @@ static int *g2_font_glyphs = NULL; static int g2_font_num_glyph_blocks = -1; static int g2_font_num_glyphs = -1; -void arm_g2_image_end(void); -void arm_g2_colored_end(void); -void arm_g2_colored_rect_end(bool tris_done); -void arm_g2_colored_tris_end(bool rects_done); -void arm_g2_text_end(void); +void kinc_g2_image_end(void); +void kinc_g2_colored_end(void); +void kinc_g2_colored_rect_end(bool tris_done); +void kinc_g2_colored_tris_end(bool rects_done); +void kinc_g2_text_end(void); -kinc_matrix4x4_t arm_g2_matrix4x4_orthogonal_projection(float left, float right, float bottom, float top, float zn, float zf) { +kinc_matrix4x4_t kinc_g2_matrix4x4_orthogonal_projection(float left, float right, float bottom, float top, float zn, float zf) { float tx = -(right + left) / (right - left); float ty = -(top + bottom) / (top - bottom); float tz = -(zf + zn) / (zf - zn); @@ -95,7 +98,7 @@ kinc_matrix4x4_t arm_g2_matrix4x4_orthogonal_projection(float left, float right, }; } -void arm_g2_matrix3x3_multquad(kinc_matrix3x3_t *m, float qx, float qy, float qw, float qh, kinc_vector2_t *out) { +void kinc_g2_matrix3x3_multquad(kinc_matrix3x3_t *m, float qx, float qy, float qw, float qh, kinc_vector2_t *out) { kinc_float32x4_t xx = kinc_float32x4_load(qx, qx, qx + qw, qx + qw); kinc_float32x4_t yy = kinc_float32x4_load(qy + qh, qy, qy, qy + qh); @@ -119,34 +122,34 @@ void arm_g2_matrix3x3_multquad(kinc_matrix3x3_t *m, float qx, float qy, float qw out[3] = (kinc_vector2_t){kinc_float32x4_get(px, 3), kinc_float32x4_get(py, 3)}; } -kinc_vector2_t arm_g2_matrix3x3_multvec(kinc_matrix3x3_t *m, kinc_vector2_t v) { +kinc_vector2_t kinc_g2_matrix3x3_multvec(kinc_matrix3x3_t *m, kinc_vector2_t v) { float w = m->m[2] * v.x + m->m[5] * v.y + m->m[8] * 1.0f; float x = (m->m[0] * v.x + m->m[3] * v.y + m->m[6] * 1.0f) / w; float y = (m->m[1] * v.x + m->m[4] * v.y + m->m[7] * 1.0f) / w; return (kinc_vector2_t){x, y}; } -void arm_g2_internal_set_projection_matrix(kinc_g4_render_target_t *target) { +void kinc_g2_internal_set_projection_matrix(kinc_g4_render_target_t *target) { if (target != NULL) { if (kinc_g4_render_targets_inverted_y()) { - g2_projection_matrix = arm_g2_matrix4x4_orthogonal_projection(0.0f, (float)target->width, 0.0f, (float)target->height, 0.1f, 1000.0f); + g2_projection_matrix = kinc_g2_matrix4x4_orthogonal_projection(0.0f, (float)target->width, 0.0f, (float)target->height, 0.1f, 1000.0f); } else { - g2_projection_matrix = arm_g2_matrix4x4_orthogonal_projection(0.0f, (float)target->width, (float)target->height, 0.0f, 0.1f, 1000.0f); + g2_projection_matrix = kinc_g2_matrix4x4_orthogonal_projection(0.0f, (float)target->width, (float)target->height, 0.0f, 0.1f, 1000.0f); } } else { - g2_projection_matrix = arm_g2_matrix4x4_orthogonal_projection(0.0f, (float)kinc_window_width(0), (float)kinc_window_height(0), 0.0f, 0.1f, 1000.0f); + g2_projection_matrix = kinc_g2_matrix4x4_orthogonal_projection(0.0f, (float)kinc_window_width(0), (float)kinc_window_height(0), 0.0f, 0.1f, 1000.0f); } } -void arm_g2_init(void *image_vert, int image_vert_size, void *image_frag, int image_frag_size, void *colored_vert, int colored_vert_size, void *colored_frag, int colored_frag_size, void *text_vert, int text_vert_size, void *text_frag, int text_frag_size) { - arm_g2_internal_set_projection_matrix(NULL); +void kinc_g2_init(buffer_t *image_vert, buffer_t *image_frag, buffer_t *colored_vert, buffer_t *colored_frag, buffer_t *text_vert, buffer_t *text_frag) { + kinc_g2_internal_set_projection_matrix(NULL); g2_transform = kinc_matrix3x3_identity(); // Image painter - kinc_g4_shader_init(&image_vert_shader, image_vert, image_vert_size, KINC_G4_SHADER_TYPE_VERTEX); - kinc_g4_shader_init(&image_frag_shader, image_frag, image_frag_size, KINC_G4_SHADER_TYPE_FRAGMENT); + kinc_g4_shader_init(&image_vert_shader, image_vert->buffer, image_vert->length, KINC_G4_SHADER_TYPE_VERTEX); + kinc_g4_shader_init(&image_frag_shader, image_frag->buffer, image_frag->length, KINC_G4_SHADER_TYPE_FRAGMENT); { kinc_g4_vertex_structure_t structure; @@ -185,8 +188,8 @@ void arm_g2_init(void *image_vert, int image_vert_size, void *image_frag, int im } // Colored painter - kinc_g4_shader_init(&colored_vert_shader, colored_vert, colored_vert_size, KINC_G4_SHADER_TYPE_VERTEX); - kinc_g4_shader_init(&colored_frag_shader, colored_frag, colored_frag_size, KINC_G4_SHADER_TYPE_FRAGMENT); + kinc_g4_shader_init(&colored_vert_shader, colored_vert->buffer, colored_vert->length, KINC_G4_SHADER_TYPE_VERTEX); + kinc_g4_shader_init(&colored_frag_shader, colored_frag->buffer, colored_frag->length, KINC_G4_SHADER_TYPE_FRAGMENT); { kinc_g4_vertex_structure_t structure; @@ -236,8 +239,8 @@ void arm_g2_init(void *image_vert, int image_vert_size, void *image_frag, int im } // Text painter - kinc_g4_shader_init(&text_vert_shader, text_vert, text_vert_size, KINC_G4_SHADER_TYPE_VERTEX); - kinc_g4_shader_init(&text_frag_shader, text_frag, text_frag_size, KINC_G4_SHADER_TYPE_FRAGMENT); + kinc_g4_shader_init(&text_vert_shader, text_vert->buffer, text_vert->length, KINC_G4_SHADER_TYPE_VERTEX); + kinc_g4_shader_init(&text_frag_shader, text_frag->buffer, text_frag->length, KINC_G4_SHADER_TYPE_FRAGMENT); { kinc_g4_vertex_structure_t structure; @@ -289,11 +292,11 @@ void arm_g2_init(void *image_vert, int image_vert_size, void *image_frag, int im } } -void arm_g2_begin(void) { - arm_g2_set_color(0xffffffff); +void kinc_g2_begin(void) { + kinc_g2_set_color(0xffffffff); } -void arm_g2_set_image_rect_verts(float btlx, float btly, float tplx, float tply, float tprx, float tpry, float btrx, float btry) { +void kinc_g2_set_image_rect_verts(float btlx, float btly, float tplx, float tply, float tprx, float tpry, float btrx, float btry) { int base_idx = (image_buffer_index - image_buffer_start) * 6 * 4; image_rect_verts[base_idx + 0] = btlx; image_rect_verts[base_idx + 1] = btly; @@ -312,7 +315,7 @@ void arm_g2_set_image_rect_verts(float btlx, float btly, float tplx, float tply, image_rect_verts[base_idx + 20] = -5.0f; } -void arm_g2_set_image_rect_tex_coords(float left, float top, float right, float bottom) { +void kinc_g2_set_image_rect_tex_coords(float left, float top, float right, float bottom) { int base_idx = (image_buffer_index - image_buffer_start) * 6 * 4; image_rect_verts[base_idx + 3] = left; image_rect_verts[base_idx + 4] = bottom; @@ -327,7 +330,7 @@ void arm_g2_set_image_rect_tex_coords(float left, float top, float right, float image_rect_verts[base_idx + 22] = bottom; } -void arm_g2_set_image_rect_colors(uint32_t color) { +void kinc_g2_set_image_rect_colors(uint32_t color) { color = (color & 0xff000000) | ((color & 0x00ff0000) >> 16) | (color & 0x0000ff00) | ((color & 0x000000ff) << 16); int base_idx = (image_buffer_index - image_buffer_start) * 6 * 4; image_rect_verts[base_idx + 5] = *(float *)&color; @@ -336,7 +339,7 @@ void arm_g2_set_image_rect_colors(uint32_t color) { image_rect_verts[base_idx + 23] = *(float *)&color; } -void arm_g2_draw_image_buffer(bool end) { +void kinc_g2_draw_image_buffer(bool end) { if (image_buffer_index - image_buffer_start == 0) return; kinc_g4_vertex_buffer_unlock(&image_vertex_buffer, (image_buffer_index - image_buffer_start) * 4); kinc_g4_set_pipeline(g2_custom_pipeline != NULL ? g2_custom_pipeline : &image_pipeline); @@ -368,63 +371,77 @@ void arm_g2_draw_image_buffer(bool end) { } } -void arm_g2_draw_scaled_sub_image(kinc_g4_texture_t *tex, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { - arm_g2_colored_end(); - arm_g2_text_end(); - if (image_buffer_start + image_buffer_index + 1 >= G2_BUFFER_SIZE || (image_last_texture != NULL && tex != image_last_texture) || image_last_render_target != NULL) arm_g2_draw_image_buffer(false); +void kinc_g2_draw_scaled_sub_texture(kinc_g4_texture_t *tex, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { + kinc_g2_colored_end(); + kinc_g2_text_end(); + if (image_buffer_start + image_buffer_index + 1 >= G2_BUFFER_SIZE || (image_last_texture != NULL && tex != image_last_texture) || image_last_render_target != NULL) kinc_g2_draw_image_buffer(false); - arm_g2_set_image_rect_tex_coords(sx / tex->tex_width, sy / tex->tex_height, (sx + sw) / tex->tex_width, (sy + sh) / tex->tex_height); - arm_g2_set_image_rect_colors(g2_color); + kinc_g2_set_image_rect_tex_coords(sx / tex->tex_width, sy / tex->tex_height, (sx + sw) / tex->tex_width, (sy + sh) / tex->tex_height); + kinc_g2_set_image_rect_colors(g2_color); kinc_vector2_t p[4]; - arm_g2_matrix3x3_multquad(&g2_transform, dx, dy, dw, dh, p); - arm_g2_set_image_rect_verts(p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y); + kinc_g2_matrix3x3_multquad(&g2_transform, dx, dy, dw, dh, p); + kinc_g2_set_image_rect_verts(p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y); ++image_buffer_index; image_last_texture = tex; image_last_render_target = NULL; } -void arm_g2_draw_scaled_image(kinc_g4_texture_t *tex, float dx, float dy, float dw, float dh) { - arm_g2_draw_scaled_sub_image(tex, 0, 0, (float)tex->tex_width, (float)tex->tex_height, dx, dy, dw, dh); +void kinc_g2_draw_scaled_image(kinc_g4_texture_t *tex, float dx, float dy, float dw, float dh) { + kinc_g2_draw_scaled_sub_texture(tex, 0, 0, (float)tex->tex_width, (float)tex->tex_height, dx, dy, dw, dh); } -void arm_g2_draw_sub_image(kinc_g4_texture_t *tex, float sx, float sy, float sw, float sh, float x, float y) { - arm_g2_draw_scaled_sub_image(tex, sx, sy, sw, sh, x, y, sw, sh); +void kinc_g2_draw_sub_image(kinc_g4_texture_t *tex, float sx, float sy, float sw, float sh, float x, float y) { + kinc_g2_draw_scaled_sub_texture(tex, sx, sy, sw, sh, x, y, sw, sh); } -void arm_g2_draw_image(kinc_g4_texture_t *tex, float x, float y) { - arm_g2_draw_scaled_sub_image(tex, 0, 0, (float)tex->tex_width, (float)tex->tex_height, x, y, (float)tex->tex_width, (float)tex->tex_height); +void kinc_g2_draw_image(kinc_g4_texture_t *tex, float x, float y) { + kinc_g2_draw_scaled_sub_texture(tex, 0, 0, (float)tex->tex_width, (float)tex->tex_height, x, y, (float)tex->tex_width, (float)tex->tex_height); } -void arm_g2_draw_scaled_sub_render_target(kinc_g4_render_target_t *rt, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { - arm_g2_colored_end(); - arm_g2_text_end(); - if (image_buffer_start + image_buffer_index + 1 >= G2_BUFFER_SIZE || (image_last_render_target != NULL && rt != image_last_render_target) || image_last_texture != NULL) arm_g2_draw_image_buffer(false); +void kinc_g2_draw_scaled_sub_render_target(kinc_g4_render_target_t *rt, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { + kinc_g2_colored_end(); + kinc_g2_text_end(); + if (image_buffer_start + image_buffer_index + 1 >= G2_BUFFER_SIZE || (image_last_render_target != NULL && rt != image_last_render_target) || image_last_texture != NULL) kinc_g2_draw_image_buffer(false); - arm_g2_set_image_rect_tex_coords(sx / rt->width, sy / rt->height, (sx + sw) / rt->width, (sy + sh) / rt->height); - arm_g2_set_image_rect_colors(g2_color); + kinc_g2_set_image_rect_tex_coords(sx / rt->width, sy / rt->height, (sx + sw) / rt->width, (sy + sh) / rt->height); + kinc_g2_set_image_rect_colors(g2_color); kinc_vector2_t p[4]; - arm_g2_matrix3x3_multquad(&g2_transform, dx, dy, dw, dh, p); - arm_g2_set_image_rect_verts(p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y); + kinc_g2_matrix3x3_multquad(&g2_transform, dx, dy, dw, dh, p); + kinc_g2_set_image_rect_verts(p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y); ++image_buffer_index; image_last_render_target = rt; image_last_texture = NULL; } -void arm_g2_draw_scaled_render_target(kinc_g4_render_target_t *rt, float dx, float dy, float dw, float dh) { - arm_g2_draw_scaled_sub_render_target(rt, 0, 0, (float)rt->width, (float)rt->height, dx, dy, dw, dh); +void kinc_g2_draw_scaled_render_target(kinc_g4_render_target_t *rt, float dx, float dy, float dw, float dh) { + kinc_g2_draw_scaled_sub_render_target(rt, 0, 0, (float)rt->width, (float)rt->height, dx, dy, dw, dh); } -void arm_g2_draw_sub_render_target(kinc_g4_render_target_t *rt, float sx, float sy, float sw, float sh, float x, float y) { - arm_g2_draw_scaled_sub_render_target(rt, sx, sy, sw, sh, x, y, sw, sh); +void kinc_g2_draw_sub_render_target(kinc_g4_render_target_t *rt, float sx, float sy, float sw, float sh, float x, float y) { + kinc_g2_draw_scaled_sub_render_target(rt, sx, sy, sw, sh, x, y, sw, sh); } -void arm_g2_draw_render_target(kinc_g4_render_target_t *rt, float x, float y) { - arm_g2_draw_scaled_sub_render_target(rt, 0, 0, (float)rt->width, (float)rt->height, x, y, (float)rt->width, (float)rt->height); +void kinc_g2_draw_render_target(kinc_g4_render_target_t *rt, float x, float y) { + kinc_g2_draw_scaled_sub_render_target(rt, 0, 0, (float)rt->width, (float)rt->height, x, y, (float)rt->width, (float)rt->height); } -void arm_g2_colored_rect_set_verts(float btlx, float btly, float tplx, float tply, float tprx, float tpry, float btrx, float btry) { +void kinc_g2_draw_scaled_sub_image(image_t *image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { + #ifdef KINC_DIRECT3D12 + waitAfterNextDraw = true; + #endif + if (image->texture_ != NULL) { + kinc_g4_texture_t *texture = (kinc_g4_texture_t *)image->texture_; + kinc_g2_draw_scaled_sub_texture(texture, sx, sy, sw, sh, dx, dy, dw, dh); + } + else { + kinc_g4_render_target_t *render_target = (kinc_g4_render_target_t *)image->render_target_; + kinc_g2_draw_scaled_sub_render_target(render_target, sx, sy, sw, sh, dx, dy, dw, dh); + } +} + +void kinc_g2_colored_rect_set_verts(float btlx, float btly, float tplx, float tply, float tprx, float tpry, float btrx, float btry) { int base_idx = (colored_rect_buffer_index - colored_rect_buffer_start) * 4 * 4; colored_rect_verts[base_idx + 0] = btlx; colored_rect_verts[base_idx + 1] = btly; @@ -443,7 +460,7 @@ void arm_g2_colored_rect_set_verts(float btlx, float btly, float tplx, float tpl colored_rect_verts[base_idx + 14] = -5.0f; } -void arm_g2_colored_rect_set_colors(uint32_t color) { +void kinc_g2_colored_rect_set_colors(uint32_t color) { color = (color & 0xff000000) | ((color & 0x00ff0000) >> 16) | (color & 0x0000ff00) | ((color & 0x000000ff) << 16); int base_idx = (colored_rect_buffer_index - colored_rect_buffer_start) * 4 * 4; colored_rect_verts[base_idx + 3] = *(float *)&color; @@ -452,12 +469,12 @@ void arm_g2_colored_rect_set_colors(uint32_t color) { colored_rect_verts[base_idx + 15] = *(float *)&color; } -void arm_g2_colored_rect_draw_buffer(bool tris_done) { +void kinc_g2_colored_rect_draw_buffer(bool tris_done) { if (colored_rect_buffer_index - colored_rect_buffer_start == 0) { return; } - if (!tris_done) arm_g2_colored_tris_end(true); + if (!tris_done) kinc_g2_colored_tris_end(true); kinc_g4_vertex_buffer_unlock(&colored_rect_vertex_buffer, (colored_rect_buffer_index - colored_rect_buffer_start) * 4); kinc_g4_set_pipeline(g2_custom_pipeline != NULL ? g2_custom_pipeline : &colored_pipeline); @@ -477,7 +494,7 @@ void arm_g2_colored_rect_draw_buffer(bool tris_done) { } } -void arm_g2_colored_tris_set_verts(float x0, float y0, float x1, float y1, float x2, float y2) { +void kinc_g2_colored_tris_set_verts(float x0, float y0, float x1, float y1, float x2, float y2) { int base_idx = (colored_tris_buffer_index - colored_tris_buffer_start) * 4 * 3; colored_tris_verts[base_idx + 0] = x0; colored_tris_verts[base_idx + 1] = y0; @@ -492,7 +509,7 @@ void arm_g2_colored_tris_set_verts(float x0, float y0, float x1, float y1, float colored_tris_verts[base_idx + 10] = -5.0f; } -void arm_g2_colored_tris_set_colors(uint32_t color) { +void kinc_g2_colored_tris_set_colors(uint32_t color) { int base_idx = (colored_tris_buffer_index - colored_tris_buffer_start) * 4 * 3; color = (color & 0xff000000) | ((color & 0x00ff0000) >> 16) | (color & 0x0000ff00) | ((color & 0x000000ff) << 16); colored_tris_verts[base_idx + 3] = *(float *)&color; @@ -500,12 +517,12 @@ void arm_g2_colored_tris_set_colors(uint32_t color) { colored_tris_verts[base_idx + 11] = *(float *)&color; } -void arm_g2_colored_tris_draw_buffer(bool rect_done) { +void kinc_g2_colored_tris_draw_buffer(bool rect_done) { if (colored_tris_buffer_index - colored_tris_buffer_start == 0) { return; } - if (!rect_done) arm_g2_colored_rect_end(true); + if (!rect_done) kinc_g2_colored_rect_end(true); kinc_g4_vertex_buffer_unlock(&colored_tris_vertex_buffer, (colored_tris_buffer_index - colored_tris_buffer_start) * 3); kinc_g4_set_pipeline(g2_custom_pipeline != NULL ? g2_custom_pipeline : &colored_pipeline); @@ -525,54 +542,54 @@ void arm_g2_colored_tris_draw_buffer(bool rect_done) { } } -void arm_g2_colored_rect_end(bool tris_done) { - if (colored_rect_buffer_index - colored_rect_buffer_start > 0) arm_g2_colored_rect_draw_buffer(tris_done); +void kinc_g2_colored_rect_end(bool tris_done) { + if (colored_rect_buffer_index - colored_rect_buffer_start > 0) kinc_g2_colored_rect_draw_buffer(tris_done); } -void arm_g2_colored_tris_end(bool rects_done) { - if (colored_tris_buffer_index - colored_tris_buffer_start > 0) arm_g2_colored_tris_draw_buffer(rects_done); +void kinc_g2_colored_tris_end(bool rects_done) { + if (colored_tris_buffer_index - colored_tris_buffer_start > 0) kinc_g2_colored_tris_draw_buffer(rects_done); } -void arm_g2_fill_triangle(float x0, float y0, float x1, float y1, float x2, float y2) { - arm_g2_image_end(); - arm_g2_text_end(); - if (colored_rect_buffer_index - colored_rect_buffer_start > 0) arm_g2_colored_rect_draw_buffer(true); - if (colored_tris_buffer_index + 1 >= G2_BUFFER_SIZE) arm_g2_colored_tris_draw_buffer(false); +void kinc_g2_fill_triangle(float x0, float y0, float x1, float y1, float x2, float y2) { + kinc_g2_image_end(); + kinc_g2_text_end(); + if (colored_rect_buffer_index - colored_rect_buffer_start > 0) kinc_g2_colored_rect_draw_buffer(true); + if (colored_tris_buffer_index + 1 >= G2_BUFFER_SIZE) kinc_g2_colored_tris_draw_buffer(false); - arm_g2_colored_tris_set_colors(g2_color); + kinc_g2_colored_tris_set_colors(g2_color); - kinc_vector2_t p0 = arm_g2_matrix3x3_multvec(&g2_transform, (kinc_vector2_t){x0, y0}); // Bottom-left - kinc_vector2_t p1 = arm_g2_matrix3x3_multvec(&g2_transform, (kinc_vector2_t){x1, y1}); // Top-left - kinc_vector2_t p2 = arm_g2_matrix3x3_multvec(&g2_transform, (kinc_vector2_t){x2, y2}); // Top-right - arm_g2_colored_tris_set_verts(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y); + kinc_vector2_t p0 = kinc_g2_matrix3x3_multvec(&g2_transform, (kinc_vector2_t){x0, y0}); // Bottom-left + kinc_vector2_t p1 = kinc_g2_matrix3x3_multvec(&g2_transform, (kinc_vector2_t){x1, y1}); // Top-left + kinc_vector2_t p2 = kinc_g2_matrix3x3_multvec(&g2_transform, (kinc_vector2_t){x2, y2}); // Top-right + kinc_g2_colored_tris_set_verts(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y); ++colored_tris_buffer_index; } -void arm_g2_fill_rect(float x, float y, float width, float height) { - arm_g2_image_end(); - arm_g2_text_end(); - if (colored_tris_buffer_index - colored_tris_buffer_start > 0) arm_g2_colored_tris_draw_buffer(true); - if (colored_rect_buffer_index + 1 >= G2_BUFFER_SIZE) arm_g2_colored_rect_draw_buffer(false); +void kinc_g2_fill_rect(float x, float y, float width, float height) { + kinc_g2_image_end(); + kinc_g2_text_end(); + if (colored_tris_buffer_index - colored_tris_buffer_start > 0) kinc_g2_colored_tris_draw_buffer(true); + if (colored_rect_buffer_index + 1 >= G2_BUFFER_SIZE) kinc_g2_colored_rect_draw_buffer(false); - arm_g2_colored_rect_set_colors(g2_color); + kinc_g2_colored_rect_set_colors(g2_color); kinc_vector2_t p[4]; - arm_g2_matrix3x3_multquad(&g2_transform, x, y, width, height, p); - arm_g2_colored_rect_set_verts(p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y); + kinc_g2_matrix3x3_multquad(&g2_transform, x, y, width, height, p); + kinc_g2_colored_rect_set_verts(p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y); ++colored_rect_buffer_index; } -void arm_g2_draw_rect(float x, float y, float width, float height, float strength) { +void kinc_g2_draw_rect(float x, float y, float width, float height, float strength) { float hs = strength / 2.0f; - arm_g2_fill_rect(x - hs, y - hs, width + strength, strength); // Top - arm_g2_fill_rect(x - hs, y + hs, strength, height - strength); // Left - arm_g2_fill_rect(x - hs, y + height - hs, width + strength, strength); // Bottom - arm_g2_fill_rect(x + width - hs, y + hs, strength, height - strength); // Right + kinc_g2_fill_rect(x - hs, y - hs, width + strength, strength); // Top + kinc_g2_fill_rect(x - hs, y + hs, strength, height - strength); // Left + kinc_g2_fill_rect(x - hs, y + height - hs, width + strength, strength); // Bottom + kinc_g2_fill_rect(x + width - hs, y + hs, strength, height - strength); // Right } -void arm_g2_draw_line(float x0, float y0, float x1, float y1, float strength) { +void kinc_g2_draw_line(float x0, float y0, float x1, float y1, float strength) { kinc_vector2_t vec; if (y1 == y0) { vec = (kinc_vector2_t){0.0f, -1.0f}; @@ -592,8 +609,8 @@ void arm_g2_draw_line(float x0, float y0, float x1, float y1, float strength) { kinc_vector2_t p1 = (kinc_vector2_t){x1 + 0.5f * vec.x, y1 + 0.5f * vec.y}; kinc_vector2_t p2 = (kinc_vector2_t){p0.x - vec.x, p0.y - vec.y}; kinc_vector2_t p3 = (kinc_vector2_t){p1.x - vec.x, p1.y - vec.y}; - arm_g2_fill_triangle(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y); - arm_g2_fill_triangle(p2.x, p2.y, p1.x, p1.y, p3.x, p3.y); + kinc_g2_fill_triangle(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y); + kinc_g2_fill_triangle(p2.x, p2.y, p1.x, p1.y, p3.x, p3.y); } static uint8_t _g2_color_r(uint32_t color) { @@ -616,18 +633,18 @@ 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); +void kinc_g2_draw_line_aa(float x0, float y0, float x1, float y1, float strength) { + kinc_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); + kinc_g2_set_color(_g2_color(_g2_color_r(g2_color), _g2_color_g(g2_color), _g2_color_b(g2_color), 150)); + kinc_g2_draw_line(x0 + 0.5, y0, x1 + 0.5, y1, strength); + kinc_g2_draw_line(x0 - 0.5, y0, x1 - 0.5, y1, strength); + kinc_g2_draw_line(x0, y0 + 0.5, x1, y1 + 0.5, strength); + kinc_g2_draw_line(x0, y0 - 0.5, x1, y1 - 0.5, strength); + kinc_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) { +void kinc_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; text_rect_verts[base_idx + 1] = btly; @@ -646,7 +663,7 @@ void arm_g2_text_set_rect_verts(float btlx, float btly, float tplx, float tply, text_rect_verts[base_idx + 20] = -5.0f; } -void arm_g2_text_set_rect_tex_coords(float left, float top, float right, float bottom) { +void kinc_g2_text_set_rect_tex_coords(float left, float top, float right, float bottom) { int base_idx = (text_buffer_index - text_buffer_start) * 6 * 4; text_rect_verts[base_idx + 3] = left; text_rect_verts[base_idx + 4] = bottom; @@ -661,7 +678,7 @@ void arm_g2_text_set_rect_tex_coords(float left, float top, float right, float b text_rect_verts[base_idx + 22] = bottom; } -void arm_g2_text_set_rect_colors(uint32_t color) { +void kinc_g2_text_set_rect_colors(uint32_t color) { color = (color & 0xff000000) | ((color & 0x00ff0000) >> 16) | (color & 0x0000ff00) | ((color & 0x000000ff) << 16); int base_idx = (text_buffer_index - text_buffer_start) * 6 * 4; text_rect_verts[base_idx + 5] = *(float *)&color; @@ -670,7 +687,7 @@ void arm_g2_text_set_rect_colors(uint32_t color) { text_rect_verts[base_idx + 23] = *(float *)&color; } -void arm_g2_text_draw_buffer(bool end) { +void kinc_g2_text_draw_buffer(bool end) { if (text_buffer_index - text_buffer_start == 0) return; kinc_g4_vertex_buffer_unlock(&text_vertex_buffer, text_buffer_index * 4); kinc_g4_set_pipeline(g2_custom_pipeline != NULL ? g2_custom_pipeline : g2_is_render_target ? &text_pipeline_rt : &text_pipeline); @@ -699,21 +716,21 @@ void arm_g2_text_draw_buffer(bool end) { #define STB_TRUETYPE_IMPLEMENTATION #include -typedef struct arm_g2_font_aligned_quad { +typedef struct kinc_g2_font_aligned_quad { float x0, y0, s0, t0; // Top-left float x1, y1, s1, t1; // Bottom-right float xadvance; -} arm_g2_font_aligned_quad_t; +} kinc_g2_font_aligned_quad_t; -typedef struct arm_g2_font_image { +typedef struct kinc_g2_font_image { float m_size; stbtt_bakedchar *chars; kinc_g4_texture_t *tex; int width, height, first_unused_y; float baseline, descent, line_gap; -} arm_g2_font_image_t; +} kinc_g2_font_image_t; -arm_g2_font_image_t *arm_g2_font_get_image_internal(arm_g2_font_t *font, int size) { +kinc_g2_font_image_t *kinc_g2_font_get_image_internal(kinc_g2_font_t *font, int size) { for (int i = 0; i < font->m_images_len; ++i) { if ((int)font->images[i].m_size == size) { return &(font->images[i]); @@ -722,17 +739,17 @@ arm_g2_font_image_t *arm_g2_font_get_image_internal(arm_g2_font_t *font, int siz return NULL; } -static inline bool arm_g2_prepare_font_load_internal(arm_g2_font_t *font, int size) { - if (arm_g2_font_get_image_internal(font, size) != NULL) return false; // Nothing to do +static inline bool kinc_g2_prepare_font_load_internal(kinc_g2_font_t *font, int size) { + if (kinc_g2_font_get_image_internal(font, size) != NULL) return false; // Nothing to do // Resize images array if necessary if (font->m_capacity <= font->m_images_len) { font->m_capacity = font->m_images_len + 1; if (font->images == NULL) { - font->images = (arm_g2_font_image_t *)malloc(font->m_capacity * sizeof(arm_g2_font_image_t)); + font->images = (kinc_g2_font_image_t *)malloc(font->m_capacity * sizeof(kinc_g2_font_image_t)); } else { - font->images = (arm_g2_font_image_t *)realloc(font->images, font->m_capacity * sizeof(arm_g2_font_image_t)); + font->images = (kinc_g2_font_image_t *)realloc(font->images, font->m_capacity * sizeof(kinc_g2_font_image_t)); } } @@ -784,10 +801,10 @@ static int stbtt_BakeFontBitmapArr(unsigned char *data, int offset, // Fo return bottom_y; } -void arm_g2_font_load(arm_g2_font_t *font, int size) { - if (!arm_g2_prepare_font_load_internal(font, size)) return; +void kinc_g2_font_load(kinc_g2_font_t *font, int size) { + if (!kinc_g2_prepare_font_load_internal(font, size)) return; - arm_g2_font_image_t *img = &(font->images[font->m_images_len]); + kinc_g2_font_image_t *img = &(font->images[font->m_images_len]); font->m_images_len += 1; int width = 64; int height = 32; @@ -829,12 +846,12 @@ void arm_g2_font_load(arm_g2_font_t *font, int size) { free(pixels); } -kinc_g4_texture_t *arm_g2_font_get_texture(arm_g2_font_t *font, int size) { - arm_g2_font_image_t *img = arm_g2_font_get_image_internal(font, size); +kinc_g4_texture_t *kinc_g2_font_get_texture(kinc_g2_font_t *font, int size) { + kinc_g2_font_image_t *img = kinc_g2_font_get_image_internal(font, size); return img->tex; } -int arm_g2_font_get_char_index_internal(arm_g2_font_image_t *img, int char_index) { +int kinc_g2_font_get_char_index_internal(kinc_g2_font_image_t *img, int char_index) { if (g2_font_num_glyphs <= 0) { return 0; } @@ -857,9 +874,9 @@ int arm_g2_font_get_char_index_internal(arm_g2_font_image_t *img, int char_index return char_index - offset; } -bool arm_g2_font_get_baked_quad(arm_g2_font_t *font, int size, arm_g2_font_aligned_quad_t *q, int char_code, float xpos, float ypos) { - arm_g2_font_image_t *img = arm_g2_font_get_image_internal(font, size); - int char_index = arm_g2_font_get_char_index_internal(img, char_code); +bool kinc_g2_font_get_baked_quad(kinc_g2_font_t *font, int size, kinc_g2_font_aligned_quad_t *q, int char_code, float xpos, float ypos) { + kinc_g2_font_image_t *img = kinc_g2_font_get_image_internal(font, size); + int char_index = kinc_g2_font_get_char_index_internal(img, char_code); if (char_index >= g2_font_num_glyphs) return false; float ipw = 1.0f / (float)img->width; float iph = 1.0f / (float)img->height; @@ -882,32 +899,32 @@ bool arm_g2_font_get_baked_quad(arm_g2_font_t *font, int size, arm_g2_font_align return true; } -void arm_g2_draw_string(const char *text, float x, float y) { - arm_g2_image_end(); - arm_g2_colored_end(); +void kinc_g2_draw_string(const char *text, float x, float y) { + kinc_g2_image_end(); + kinc_g2_colored_end(); - arm_g2_font_image_t *img = arm_g2_font_get_image_internal(g2_font, g2_font_size); + kinc_g2_font_image_t *img = kinc_g2_font_get_image_internal(g2_font, g2_font_size); kinc_g4_texture_t *tex = img->tex; - if (text_last_texture != NULL && tex != text_last_texture) arm_g2_text_draw_buffer(false); + if (text_last_texture != NULL && tex != text_last_texture) kinc_g2_text_draw_buffer(false); text_last_texture = tex; float xpos = x; float ypos = y + img->baseline; - arm_g2_font_aligned_quad_t q; + kinc_g2_font_aligned_quad_t q; for (int i = 0; text[i] != 0; ) { int l = 0; int codepoint = string_utf8_decode(&text[i], &l); i += l; - if (arm_g2_font_get_baked_quad(g2_font, g2_font_size, &q, codepoint, xpos, ypos)) { - if (text_buffer_index + 1 >= G2_BUFFER_SIZE) arm_g2_text_draw_buffer(false); - arm_g2_text_set_rect_colors(g2_color); - arm_g2_text_set_rect_tex_coords(q.s0, q.t0, q.s1, q.t1); + if (kinc_g2_font_get_baked_quad(g2_font, g2_font_size, &q, codepoint, xpos, ypos)) { + if (text_buffer_index + 1 >= G2_BUFFER_SIZE) kinc_g2_text_draw_buffer(false); + kinc_g2_text_set_rect_colors(g2_color); + kinc_g2_text_set_rect_tex_coords(q.s0, q.t0, q.s1, q.t1); kinc_vector2_t p[4]; - arm_g2_matrix3x3_multquad(&g2_transform, q.x0, q.y0, q.x1 - q.x0, q.y1 - q.y0, p); - arm_g2_text_set_rect_verts(p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y); + kinc_g2_matrix3x3_multquad(&g2_transform, q.x0, q.y0, q.x1 - q.x0, q.y1 - q.y0, p); + kinc_g2_text_set_rect_verts(p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y); xpos += q.xadvance; ++text_buffer_index; @@ -915,7 +932,7 @@ void arm_g2_draw_string(const char *text, float x, float y) { } } -void arm_g2_font_default_glyphs() { +void kinc_g2_font_default_glyphs() { g2_font_num_glyphs = 127 - 32; g2_font_glyphs = (int *)malloc(g2_font_num_glyphs * sizeof(int)); for (int i = 32; i < 127; ++i) g2_font_glyphs[i - 32] = i; @@ -925,9 +942,9 @@ void arm_g2_font_default_glyphs() { g2_font_glyph_blocks[1] = 126; } -void arm_g2_font_init(arm_g2_font_t *font, void *blob, int font_index) { +void _kinc_g2_font_init(kinc_g2_font_t *font, void *blob, int font_index) { if (g2_font_glyphs == NULL) { - arm_g2_font_default_glyphs(); + kinc_g2_font_default_glyphs(); } font->blob = blob; @@ -940,9 +957,15 @@ void arm_g2_font_init(arm_g2_font_t *font, void *blob, int font_index) { } } -void arm_g2_font_13(arm_g2_font_t *font, void *blob) { +kinc_g2_font_t *kinc_g2_font_init(buffer_t *blob, int font_index) { + kinc_g2_font_t *font = (kinc_g2_font_t *)malloc(sizeof(kinc_g2_font_t)); + _kinc_g2_font_init(font, blob->buffer, font_index); + return font; +} + +void _kinc_g2_font_13(kinc_g2_font_t *font, void *blob) { if (g2_font_glyphs == NULL) { - arm_g2_font_default_glyphs(); + kinc_g2_font_default_glyphs(); } font->blob = blob; @@ -950,9 +973,9 @@ void arm_g2_font_13(arm_g2_font_t *font, void *blob) { font->m_images_len = 0; font->m_capacity = 0; font->offset = 0; - arm_g2_prepare_font_load_internal(font, 13); + kinc_g2_prepare_font_load_internal(font, 13); - arm_g2_font_image_t *img = &(font->images[font->m_images_len]); + kinc_g2_font_image_t *img = &(font->images[font->m_images_len]); font->m_images_len += 1; img->m_size = 13; img->baseline = 0; // 10 @@ -978,10 +1001,15 @@ void arm_g2_font_13(arm_g2_font_t *font, void *blob) { baked[i].xadvance = g2_font_13_xadvance[i]; } img->chars = baked; +} +kinc_g2_font_t *kinc_g2_font_13(buffer_t *blob) { + kinc_g2_font_t *font = (kinc_g2_font_t *)malloc(sizeof(kinc_g2_font_t)); + _kinc_g2_font_13(font, blob->buffer); + return font; } -bool arm_g2_font_has_glyph(int glyph) { +bool kinc_g2_font_has_glyph(int glyph) { for (int i = 0; i < g2_font_num_glyphs; ++i) { if (g2_font_glyphs[i] == glyph) { return true; @@ -990,7 +1018,7 @@ bool arm_g2_font_has_glyph(int glyph) { return false; } -void arm_g2_font_set_glyphs(int *glyphs, int count) { +void _kinc_g2_font_set_glyphs(int *glyphs, int count) { free(g2_font_glyphs); g2_font_num_glyphs = count; g2_font_glyphs = (int *)malloc(g2_font_num_glyphs * sizeof(int)); @@ -1030,116 +1058,123 @@ void arm_g2_font_set_glyphs(int *glyphs, int count) { g2_font_glyph_blocks[blocks * 2 - 1] = glyphs[count - 1]; } -void arm_g2_font_add_glyph(int glyph) { +void kinc_g2_font_set_glyphs(i32_array_t *glyphs) { + _kinc_g2_font_set_glyphs(glyphs->buffer, glyphs->length); +} + +void kinc_g2_font_add_glyph(int glyph) { // TODO: slow g2_font_num_glyphs++; int *font_glyphs = (int *)malloc(g2_font_num_glyphs * sizeof(int)); for (int i = 0; i < g2_font_num_glyphs - 1; ++i) font_glyphs[i] = g2_font_glyphs[i]; font_glyphs[g2_font_num_glyphs - 1] = glyph; - arm_g2_font_set_glyphs(font_glyphs, g2_font_num_glyphs); + _kinc_g2_font_set_glyphs(font_glyphs, g2_font_num_glyphs); } -int arm_g2_font_count(arm_g2_font_t *font) { +int kinc_g2_font_count(kinc_g2_font_t *font) { return stbtt_GetNumberOfFonts(font->blob); } -float arm_g2_font_height(arm_g2_font_t *font, int font_size) { - arm_g2_font_load(font, font_size); - return arm_g2_font_get_image_internal(font, font_size)->m_size; +int kinc_g2_font_height(kinc_g2_font_t *font, int font_size) { + kinc_g2_font_load(font, font_size); + return (int)kinc_g2_font_get_image_internal(font, font_size)->m_size; } -float arm_g2_font_get_char_width_internal(arm_g2_font_image_t *img, int char_index) { - int i = arm_g2_font_get_char_index_internal(img, char_index); +float kinc_g2_font_get_char_width_internal(kinc_g2_font_image_t *img, int char_index) { + int i = kinc_g2_font_get_char_index_internal(img, char_index); return img->chars[i].xadvance; } -float arm_g2_sub_string_width(arm_g2_font_t *font, int font_size, const char *text, int start, int end) { - arm_g2_font_load(font, font_size); - arm_g2_font_image_t *img = arm_g2_font_get_image_internal(font, font_size); +float kinc_g2_sub_string_width(kinc_g2_font_t *font, int font_size, const char *text, int start, int end) { + kinc_g2_font_load(font, font_size); + kinc_g2_font_image_t *img = kinc_g2_font_get_image_internal(font, font_size); float width = 0.0; for (int i = start; i < end; ++i) { if (text[i] == '\0') break; - width += arm_g2_font_get_char_width_internal(img, text[i]); + width += kinc_g2_font_get_char_width_internal(img, text[i]); } return width; } -float arm_g2_string_width(arm_g2_font_t *font, int font_size, const char *text) { - return arm_g2_sub_string_width(font, font_size, text, 0, (int)strlen(text)); +int kinc_g2_string_width(kinc_g2_font_t *font, int font_size, const char *text) { + return (int)kinc_g2_sub_string_width(font, font_size, text, 0, (int)strlen(text)); } -void arm_g2_image_end(void) { - if (image_buffer_index > 0) arm_g2_draw_image_buffer(true); +void kinc_g2_image_end(void) { + if (image_buffer_index > 0) kinc_g2_draw_image_buffer(true); image_last_texture = NULL; image_last_render_target = NULL; } -void arm_g2_colored_end(void) { - arm_g2_colored_rect_end(false); - arm_g2_colored_tris_end(false); +void kinc_g2_colored_end(void) { + kinc_g2_colored_rect_end(false); + kinc_g2_colored_tris_end(false); } -void arm_g2_text_end(void) { - if (text_buffer_index > 0) arm_g2_text_draw_buffer(true); +void kinc_g2_text_end(void) { + if (text_buffer_index > 0) kinc_g2_text_draw_buffer(true); text_last_texture = NULL; } -void arm_g2_end(void) { - arm_g2_image_end(); - arm_g2_colored_end(); - arm_g2_text_end(); +void kinc_g2_end(void) { + kinc_g2_image_end(); + kinc_g2_colored_end(); + kinc_g2_text_end(); } -void arm_g2_set_color(uint32_t color) { +void kinc_g2_set_color(uint32_t color) { g2_color = color; } -uint32_t arm_g2_get_color() { +uint32_t kinc_g2_get_color() { return g2_color; } -void arm_g2_set_pipeline(kinc_g4_pipeline_t *pipeline) { +void kinc_g2_set_pipeline(kinc_g4_pipeline_t *pipeline) { if (pipeline == g2_last_pipeline) return; g2_last_pipeline = pipeline; - arm_g2_end(); // flush + kinc_g2_end(); // flush g2_custom_pipeline = pipeline; } -void arm_g2_set_transform(kinc_matrix3x3_t *m) { +void kinc_g2_set_transform(buffer_t *matrix) { + kinc_matrix3x3_t *m = matrix != NULL ? (kinc_matrix3x3_t *)matrix->buffer : NULL; if (m == NULL) { g2_transform = kinc_matrix3x3_identity(); } else { - for (int i = 0; i < 3 * 3; ++i) g2_transform.m[i] = m->m[i]; + for (int i = 0; i < 3 * 3; ++i) { + g2_transform.m[i] = m->m[i]; + } } } -void arm_g2_set_font(arm_g2_font_t *font, int size) { - arm_g2_end(); // flush +void kinc_g2_set_font(kinc_g2_font_t *font, int size) { + kinc_g2_end(); // flush g2_font = font; g2_font_size = size; - arm_g2_font_load(font, size); + kinc_g2_font_load(font, size); } -void arm_g2_set_bilinear_filter(bool bilinear) { +void kinc_g2_set_bilinear_filter(bool bilinear) { if (g2_bilinear_filter == bilinear) return; - arm_g2_end(); // flush + kinc_g2_end(); // flush g2_bilinear_filter = bilinear; } -void arm_g2_restore_render_target(void) { +void kinc_g2_restore_render_target(void) { g2_is_render_target = false; - arm_g2_end(); - arm_g2_begin(); + kinc_g2_end(); + kinc_g2_begin(); kinc_g4_restore_render_target(); - arm_g2_internal_set_projection_matrix(NULL); + kinc_g2_internal_set_projection_matrix(NULL); } -void arm_g2_set_render_target(kinc_g4_render_target_t *target) { +void kinc_g2_set_render_target(kinc_g4_render_target_t *target) { g2_is_render_target = true; - arm_g2_end(); - arm_g2_begin(); + kinc_g2_end(); + kinc_g2_begin(); kinc_g4_render_target_t *render_targets[1] = { target }; kinc_g4_set_render_targets(render_targets, 1); - arm_g2_internal_set_projection_matrix(target); + kinc_g2_internal_set_projection_matrix(target); } diff --git a/armorcore/sources/kinc/graphics2/g2.h b/armorcore/sources/kinc/graphics2/g2.h index 33308a85b..bc7cf5c83 100644 --- a/armorcore/sources/kinc/graphics2/g2.h +++ b/armorcore/sources/kinc/graphics2/g2.h @@ -11,55 +11,68 @@ #include #include #include +#include "iron_array.h" -typedef struct arm_g2_font_image arm_g2_font_image_t; +typedef struct image { + void *texture_; + void *render_target_; + int format; // tex_format_t; + bool readable; + buffer_t *pixels; + int width; + int height; + int depth; +} image_t; -typedef struct arm_g2_font { +typedef struct kinc_g2_font_image kinc_g2_font_image_t; + +typedef struct kinc_g2_font { unsigned char *blob; - arm_g2_font_image_t *images; + kinc_g2_font_image_t *images; size_t m_capacity; size_t m_images_len; int offset; -} arm_g2_font_t; +} kinc_g2_font_t; typedef struct g2_font { - arm_g2_font_t *font_; + kinc_g2_font_t *font_; void *blob; // buffer_t void *glyphs; // i32_array_t int index; } g2_font_t; -void arm_g2_init(void *image_vert, int image_vert_size, void *image_frag, int image_frag_size, void *colored_vert, int colored_vert_size, void *colored_frag, int colored_frag_size, void *text_vert, int text_vert_size, void *text_frag, int text_frag_size); -void arm_g2_begin(void); -void arm_g2_draw_scaled_sub_image(kinc_g4_texture_t *tex, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh); -void arm_g2_draw_scaled_image(kinc_g4_texture_t *tex, float dx, float dy, float dw, float dh); -void arm_g2_draw_sub_image(kinc_g4_texture_t *tex, float sx, float sy, float sw, float sh, float x, float y); -void arm_g2_draw_image(kinc_g4_texture_t *tex, float x, float y); -void arm_g2_draw_scaled_sub_render_target(kinc_g4_render_target_t *rt, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh); -void arm_g2_draw_scaled_render_target(kinc_g4_render_target_t *rt, float dx, float dy, float dw, float dh); -void arm_g2_draw_sub_render_target(kinc_g4_render_target_t *rt, float sx, float sy, float sw, float sh, float x, float y); -void arm_g2_draw_render_target(kinc_g4_render_target_t *rt, float x, float y); -void arm_g2_fill_triangle(float x0, float y0, float x1, float y1, float x2, float y2); -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); -uint32_t arm_g2_get_color(); -void arm_g2_set_pipeline(kinc_g4_pipeline_t *pipeline); -void arm_g2_set_transform(kinc_matrix3x3_t *m); -void arm_g2_set_font(arm_g2_font_t *font, int size); -void arm_g2_font_init(arm_g2_font_t *font, void *blob, int font_index); -void arm_g2_font_13(arm_g2_font_t *font, void *blob); -bool arm_g2_font_has_glyph(int glyph); -void arm_g2_font_set_glyphs(int *glyphs, int count); -void arm_g2_font_add_glyph(int glyph); -int arm_g2_font_count(arm_g2_font_t *font); -float arm_g2_font_height(arm_g2_font_t *font, int font_size); -float arm_g2_sub_string_width(arm_g2_font_t *font, int font_size, const char *text, int start, int end); -float arm_g2_string_width(arm_g2_font_t *font, int font_size, const char *text); -void arm_g2_set_bilinear_filter(bool bilinear); -void arm_g2_restore_render_target(void); -void arm_g2_set_render_target(kinc_g4_render_target_t *target); +void kinc_g2_init(buffer_t *image_vert, buffer_t *image_frag, buffer_t *colored_vert, buffer_t *colored_frag, buffer_t *text_vert, buffer_t *text_frag); +void kinc_g2_begin(void); +void kinc_g2_draw_scaled_sub_image(image_t *img, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh); +void kinc_g2_draw_scaled_sub_texture(kinc_g4_texture_t *tex, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh); +void kinc_g2_draw_scaled_image(kinc_g4_texture_t *tex, float dx, float dy, float dw, float dh); +void kinc_g2_draw_sub_image(kinc_g4_texture_t *tex, float sx, float sy, float sw, float sh, float x, float y); +void kinc_g2_draw_image(kinc_g4_texture_t *tex, float x, float y); +void kinc_g2_draw_scaled_sub_render_target(kinc_g4_render_target_t *rt, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh); +void kinc_g2_draw_scaled_render_target(kinc_g4_render_target_t *rt, float dx, float dy, float dw, float dh); +void kinc_g2_draw_sub_render_target(kinc_g4_render_target_t *rt, float sx, float sy, float sw, float sh, float x, float y); +void kinc_g2_draw_render_target(kinc_g4_render_target_t *rt, float x, float y); +void kinc_g2_fill_triangle(float x0, float y0, float x1, float y1, float x2, float y2); +void kinc_g2_fill_rect(float x, float y, float width, float height); +void kinc_g2_draw_rect(float x, float y, float width, float height, float strength); +void kinc_g2_draw_line(float x0, float y0, float x1, float y1, float strength); +void kinc_g2_draw_line_aa(float x0, float y0, float x1, float y1, float strength); +void kinc_g2_draw_string(const char *text, float x, float y); +void kinc_g2_end(void); +void kinc_g2_set_color(uint32_t color); +uint32_t kinc_g2_get_color(); +void kinc_g2_set_pipeline(kinc_g4_pipeline_t *pipeline); +void kinc_g2_set_transform(buffer_t *matrix); +void kinc_g2_set_font(kinc_g2_font_t *font, int size); +kinc_g2_font_t *kinc_g2_font_init(buffer_t *blob, int font_index); +kinc_g2_font_t *kinc_g2_font_13(buffer_t *blob); +bool kinc_g2_font_has_glyph(int glyph); +void kinc_g2_font_set_glyphs(i32_array_t *glyphs); +void kinc_g2_font_add_glyph(int glyph); +int kinc_g2_font_count(kinc_g2_font_t *font); +int kinc_g2_font_height(kinc_g2_font_t *font, int font_size); +float kinc_g2_sub_string_width(kinc_g2_font_t *font, int font_size, const char *text, int start, int end); +int kinc_g2_string_width(kinc_g2_font_t *font, int font_size, const char *text); +void kinc_g2_set_bilinear_filter(bool bilinear); +void kinc_g2_restore_render_target(void); +void kinc_g2_set_render_target(kinc_g4_render_target_t *target); diff --git a/armorcore/sources/kinc/graphics2/g2_ext.c b/armorcore/sources/kinc/graphics2/g2_ext.c index 6c8f1d160..2db7073ff 100644 --- a/armorcore/sources/kinc/graphics2/g2_ext.c +++ b/armorcore/sources/kinc/graphics2/g2_ext.c @@ -6,7 +6,7 @@ #define MATH_PI 3.14159265358979323846 -void arm_g2_fill_circle(float cx, float cy, float radius, int segments) { +void kinc_g2_fill_circle(float cx, float cy, float radius, int segments) { if (segments <= 0) { segments = (int)floor(10 * sqrtf(radius)); } @@ -26,11 +26,11 @@ void arm_g2_fill_circle(float cx, float cy, float radius, int segments) { x = c * x - s * y; y = c * y + s * t; - arm_g2_fill_triangle(px, py, x + cx, y + cy, cx, cy); + kinc_g2_fill_triangle(px, py, x + cx, y + cy, cx, cy); } } -void arm_g2_draw_inner_line(float x1, float y1, float x2, float y2, float strength) { +void kinc_g2_draw_inner_line(float x1, float y1, float x2, float y2, float strength) { int side = y2 > y1 ? 1 : 0; if (y2 == y1) { side = x2 - x1 > 0 ? 1 : 0; @@ -48,11 +48,11 @@ void arm_g2_draw_inner_line(float x1, float y1, float x2, float y2, float streng kinc_vector2_t p2 = {x2 + side * vec.x, y2 + side * vec.y}; kinc_vector2_t p3 = vec2_sub(p1, vec); kinc_vector2_t p4 = vec2_sub(p2, vec); - arm_g2_fill_triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); - arm_g2_fill_triangle(p3.x, p3.y, p2.x, p2.y, p4.x, p4.y); + kinc_g2_fill_triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); + kinc_g2_fill_triangle(p3.x, p3.y, p2.x, p2.y, p4.x, p4.y); } -void arm_g2_draw_circle(float cx, float cy, float radius, int segments, float strength) { +void kinc_g2_draw_circle(float cx, float cy, float radius, int segments, float strength) { radius += strength / 2; if (segments <= 0) { @@ -74,11 +74,11 @@ void arm_g2_draw_circle(float cx, float cy, float radius, int segments, float st x = c * x - s * y; y = c * y + s * t; - arm_g2_draw_inner_line(x + cx, y + cy, px, py, strength); + kinc_g2_draw_inner_line(x + cx, y + cy, px, py, strength); } } -void arm_g2_calculate_cubic_bezier_point(float t, float *x, float *y, float *out) { +void kinc_g2_calculate_cubic_bezier_point(float t, float *x, float *y, float *out) { float u = 1 - t; float tt = t * t; float uu = u * u; @@ -109,15 +109,17 @@ void arm_g2_calculate_cubic_bezier_point(float t, float *x, float *y, float *out * Provide x and y in the following order: startPoint, controlPoint1, controlPoint2, endPoint * Reference: http://devmag.org.za/2011/04/05/bzier-curves-a-tutorial/ */ -void arm_g2_draw_cubic_bezier(float *x, float *y, int segments, float strength) { +void kinc_g2_draw_cubic_bezier(f32_array_t *xa, f32_array_t *ya, int segments, float strength) { + float *x = xa->buffer; + float *y = ya->buffer; float q0[2]; float q1[2]; - arm_g2_calculate_cubic_bezier_point(0, x, y, q0); + kinc_g2_calculate_cubic_bezier_point(0, x, y, q0); for (int i = 1; i < (segments + 1); ++i) { float t = (float)i / segments; - arm_g2_calculate_cubic_bezier_point(t, x, y, q1); - arm_g2_draw_line(q0[0], q0[1], q1[0], q1[1], strength); + kinc_g2_calculate_cubic_bezier_point(t, x, y, q1); + kinc_g2_draw_line(q0[0], q0[1], q1[0], q1[1], strength); q0[0] = q1[0]; q0[1] = q1[1]; } diff --git a/armorcore/sources/kinc/graphics2/g2_ext.h b/armorcore/sources/kinc/graphics2/g2_ext.h index a436a8eff..b4c032d40 100644 --- a/armorcore/sources/kinc/graphics2/g2_ext.h +++ b/armorcore/sources/kinc/graphics2/g2_ext.h @@ -1,5 +1,7 @@ #pragma once -void arm_g2_fill_circle(float cx, float cy, float radius, int segments); -void arm_g2_draw_circle(float cx, float cy, float radius, int segments, float strength); -void arm_g2_draw_cubic_bezier(float *x, float *y, int segments, float strength); +#include "iron_array.h" + +void kinc_g2_fill_circle(float cx, float cy, float radius, int segments); +void kinc_g2_draw_circle(float cx, float cy, float radius, int segments, float strength); +void kinc_g2_draw_cubic_bezier(f32_array_t *x, f32_array_t *y, int segments, float strength); diff --git a/armorcore/sources/ts/g2.ts b/armorcore/sources/ts/g2.ts index 9a4692ecd..fd88d61d3 100644 --- a/armorcore/sources/ts/g2.ts +++ b/armorcore/sources/ts/g2.ts @@ -15,13 +15,13 @@ let _g2_mat: f32_array_t = f32_array_create(9); let _g2_initialized: bool = false; function g2_set_color(c: color_t) { - iron_g2_set_color(c); + kinc_g2_set_color(c); _g2_color = c; } function g2_set_font_and_size(font: g2_font_t, font_size: i32) { g2_font_init(font); - iron_g2_set_font(font.font_, font_size); + kinc_g2_set_font(font.font_, font_size); } function g2_set_font(f: g2_font_t) { @@ -39,17 +39,17 @@ function g2_set_font_size(i: i32) { } function g2_set_pipeline(p: pipeline_t) { - iron_g2_set_pipeline(p == null ? null : p.pipeline_); + kinc_g2_set_pipeline(p == null ? null : p.pipeline_); _g2_pipeline = p; } function g2_set_bilinear_filter(bilinear: bool) { - iron_g2_set_bilinear_filter(bilinear); + kinc_g2_set_bilinear_filter(bilinear); } function g2_set_transformation(m: mat3_t) { if (mat3_isnan(m)) { - iron_g2_set_transform(null); + kinc_g2_set_transform(null); } else { _g2_mat[0] = m.m00; @@ -61,7 +61,7 @@ function g2_set_transformation(m: mat3_t) { _g2_mat[6] = m.m20; _g2_mat[7] = m.m21; _g2_mat[8] = m.m22; - iron_g2_set_transform(_g2_mat); + kinc_g2_set_transform(_g2_mat); } } @@ -75,7 +75,7 @@ function _g2_make_glyphs(start: i32, end: i32): i32[] { function g2_init() { if (!_g2_initialized) { - iron_g2_init( + kinc_g2_init( iron_load_blob(data_path() + "g2_image.vert" + sys_shader_ext()), iron_load_blob(data_path() + "g2_image.frag" + sys_shader_ext()), iron_load_blob(data_path() + "g2_colored.vert" + sys_shader_ext()), @@ -88,7 +88,7 @@ function g2_init() { } function g2_draw_scaled_sub_image(img: image_t, sx: f32, sy: f32, sw: f32, sh: f32, dx: f32, dy: f32, dw: f32, dh: f32) { - iron_g2_draw_scaled_sub_image(img, sx, sy, sw, sh, dx, dy, dw, dh); + kinc_g2_draw_scaled_sub_image(img, sx, sy, sw, sh, dx, dy, dw, dh); } function g2_draw_sub_image(img: image_t, x: f32, y: f32, sx: f32, sy: f32, sw: f32, sh: f32) { @@ -104,36 +104,36 @@ function g2_draw_image(img: image_t, x: f32, y: f32) { } function g2_draw_rect(x: f32, y: f32, width: f32, height: f32, strength: f32 = 1.0) { - iron_g2_draw_rect(x, y, width, height, strength); + kinc_g2_draw_rect(x, y, width, height, strength); } function g2_fill_rect(x: f32, y: f32, width: f32, height: f32) { - iron_g2_fill_rect(x, y, width, height); + kinc_g2_fill_rect(x, y, width, height); } function g2_draw_string(text: string, x: f32, y: f32) { - iron_g2_draw_string(text, x, y); + kinc_g2_draw_string(text, x, y); } 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); + kinc_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); + kinc_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); + kinc_g2_fill_triangle(x0, y0, x1, y1, x2, y2); } function g2_scissor(x: i32, y: i32, width: i32, height: i32) { - iron_g2_end(); // flush + kinc_g2_end(); // flush g4_scissor(x, y, width, height); } function g2_disable_scissor() { - iron_g2_end(); // flush + kinc_g2_end(); // flush g4_disable_scissor(); } @@ -145,13 +145,13 @@ function g2_begin(render_target: image_t = null) { _g2_in_use = true; _g2_current = render_target; - iron_g2_begin(); + kinc_g2_begin(); if (render_target != null) { - iron_g2_set_render_target(render_target.render_target_); + kinc_g2_set_render_target(render_target.render_target_); } else { - iron_g2_restore_render_target(); + kinc_g2_restore_render_target(); } } @@ -163,7 +163,7 @@ function g2_end() { _g2_in_use = false; _g2_current = null; - iron_g2_end(); + kinc_g2_end(); } function g2_clear(color: color_t = 0x00000000) { @@ -171,25 +171,25 @@ function g2_clear(color: color_t = 0x00000000) { } function g2_fill_circle(cx: f32, cy: f32, radius: f32, segments: i32 = 0) { - iron_g2_fill_circle(cx, cy, radius, segments); + kinc_g2_fill_circle(cx, cy, radius, segments); } function g2_draw_circle(cx: f32, cy: f32, radius: f32, segments: i32 = 0, strength: f32 = 1.0) { - iron_g2_draw_circle(cx, cy, radius, segments, strength); + kinc_g2_draw_circle(cx, cy, radius, segments, strength); } function g2_draw_cubic_bezier(x: f32[], y: f32[], segments: i32 = 20, strength: f32 = 1.0) { - iron_g2_draw_cubic_bezier(x, y, segments, strength); + kinc_g2_draw_cubic_bezier(x, y, segments, strength); } function g2_font_init(raw: g2_font_t) { if (_g2_font_glyphs_last != _g2_font_glyphs) { _g2_font_glyphs_last = _g2_font_glyphs; - iron_g2_font_set_glyphs(_g2_font_glyphs); + kinc_g2_font_set_glyphs(_g2_font_glyphs); } if (raw.glyphs != _g2_font_glyphs) { raw.glyphs = _g2_font_glyphs; - raw.font_ = iron_g2_font_init(raw.blob, raw.index); + raw.font_ = kinc_g2_font_init(raw.blob, raw.index); } } @@ -202,12 +202,12 @@ function g2_font_create(blob: buffer_t, index: i32 = 0): g2_font_t { function g2_font_height(raw: g2_font_t, size: i32): f32 { g2_font_init(raw); - return iron_g2_font_height(raw.font_, size); + return kinc_g2_font_height(raw.font_, size); } function g2_font_width(raw: g2_font_t, size: i32, str: string): f32 { g2_font_init(raw); - return iron_g2_string_width(raw.font_, size, str); + return kinc_g2_string_width(raw.font_, size, str); } function g2_font_unload(raw: g2_font_t) { @@ -224,7 +224,7 @@ function g2_font_clone(raw: g2_font_t): g2_font_t { } declare type g2_font_t = { - font_?: any; // arm_g2_font_t + font_?: any; // kinc_g2_font_t blob?: buffer_t; glyphs?: i32[]; index?: i32; diff --git a/armorcore/sources/ts/iron.ts b/armorcore/sources/ts/iron.ts index e3b373b00..14e78893d 100644 --- a/armorcore/sources/ts/iron.ts +++ b/armorcore/sources/ts/iron.ts @@ -312,32 +312,32 @@ declare function iron_get_arg(index: i32): string; declare function iron_get_files_location(): string; declare function iron_http_request(url: string, size: i32, callback: (url: string, _: buffer_t)=>void): void; -declare function iron_g2_init(image_vert: buffer_t, image_frag: buffer_t, colored_vert: buffer_t, colored_frag: buffer_t, text_vert: buffer_t, text_frag: buffer_t): void; -declare function iron_g2_begin(): void; -declare function iron_g2_end(): void; -declare function iron_g2_draw_scaled_sub_image(image: image_t, sx: f32, sy: f32, sw: f32, sh: f32, dx: f32, dy: f32, dw: f32, dh: f32): void; -declare function iron_g2_fill_triangle(x0: f32, y0: f32, x1: f32, y1: f32, x2: f32, y2: f32): void; -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; -declare function iron_g2_font_13(blob: buffer_t): any; -declare function iron_g2_font_set_glyphs(glyphs: i32[]): void; -declare function iron_g2_font_count(font: any): i32; -declare function iron_g2_font_height(font: any, size: i32): i32; -declare function iron_g2_string_width(font: any, size: i32, text: string): i32; -declare function iron_g2_set_bilinear_filter(bilinear: bool): void; -declare function iron_g2_restore_render_target(): void; -declare function iron_g2_set_render_target(render_target: any): void; -declare function iron_g2_set_color(color: i32): void; -declare function iron_g2_set_pipeline(pipeline: any): void; -declare function iron_g2_set_transform(matrix: buffer_t): void; -declare function iron_g2_fill_circle(cx: f32, cy: f32, radius: f32, segments: i32): void; -declare function iron_g2_draw_circle(cx: f32, cy: f32, radius: f32, segments: i32, strength: f32): void; -declare function iron_g2_draw_cubic_bezier(x: f32[], y: f32[], segments: i32, strength: f32): void; +declare function kinc_g2_init(image_vert: buffer_t, image_frag: buffer_t, colored_vert: buffer_t, colored_frag: buffer_t, text_vert: buffer_t, text_frag: buffer_t): void; +declare function kinc_g2_begin(): void; +declare function kinc_g2_end(): void; +declare function kinc_g2_draw_scaled_sub_image(image: image_t, sx: f32, sy: f32, sw: f32, sh: f32, dx: f32, dy: f32, dw: f32, dh: f32): void; +declare function kinc_g2_fill_triangle(x0: f32, y0: f32, x1: f32, y1: f32, x2: f32, y2: f32): void; +declare function kinc_g2_fill_rect(x: f32, y: f32, width: f32, height: f32): void; +declare function kinc_g2_draw_rect(x: f32, y: f32, width: f32, height: f32, strength: f32): void; +declare function kinc_g2_draw_line(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32): void; +declare function kinc_g2_draw_line_aa(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32): void; +declare function kinc_g2_draw_string(text: string, x: f32, y: f32): void; +declare function kinc_g2_set_font(font: any, size: i32): void; +declare function kinc_g2_font_init(blob: buffer_t, font_index: i32): any; +declare function kinc_g2_font_13(blob: buffer_t): any; +declare function kinc_g2_font_set_glyphs(glyphs: i32[]): void; +declare function kinc_g2_font_count(font: any): i32; +declare function kinc_g2_font_height(font: any, size: i32): i32; +declare function kinc_g2_string_width(font: any, size: i32, text: string): i32; +declare function kinc_g2_set_bilinear_filter(bilinear: bool): void; +declare function kinc_g2_restore_render_target(): void; +declare function kinc_g2_set_render_target(render_target: any): void; +declare function kinc_g2_set_color(color: i32): void; +declare function kinc_g2_set_pipeline(pipeline: any): void; +declare function kinc_g2_set_transform(matrix: buffer_t): void; +declare function kinc_g2_fill_circle(cx: f32, cy: f32, radius: f32, segments: i32): void; +declare function kinc_g2_draw_circle(cx: f32, cy: f32, radius: f32, segments: i32, strength: f32): void; +declare function kinc_g2_draw_cubic_bezier(x: f32[], y: f32[], segments: i32, strength: f32): void; declare function iron_set_save_and_quit_callback(callback: (save: bool)=>void): void; declare function iron_set_mouse_cursor(id: i32): void; diff --git a/base/sources/base.ts b/base/sources/base.ts index 33bacc3ba..4a2de2999 100644 --- a/base/sources/base.ts +++ b/base/sources/base.ts @@ -86,7 +86,7 @@ function base_init() { // Baked font for fast startup if (config_raw.locale == "en") { - base_font.font_ = iron_g2_font_13(base_font.blob); + base_font.font_ = kinc_g2_font_13(base_font.blob); base_font.glyphs = _g2_font_glyphs; } else { diff --git a/base/sources/import_font.ts b/base/sources/import_font.ts index 8ba902548..0de6fe485 100644 --- a/base/sources/import_font.ts +++ b/base/sources/import_font.ts @@ -9,7 +9,7 @@ function import_font_run(path: string) { } let font: g2_font_t = data_get_font(path); g2_font_init(font); // Make sure font_ is ready - let count: i32 = iron_g2_font_count(font.font_); + let count: i32 = kinc_g2_font_count(font.font_); let font_slots: slot_font_t[] = []; for (let i: i32 = 0; i < count; ++i) { let ar: string[] = string_split(path, path_sep);