From 50fb0ac29de925b6e09ec8706c051e4b08591711 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Wed, 8 Jul 2020 15:37:06 +0200 Subject: automated commit --- changes.txt | 9 ++ src/array.h | 2 +- src/linux/platform.c | 18 ++- src/platform.h | 5 + src/project_base.h | 5 + src/render.c | 381 ++++++++++++++++++++++++------------------------- src/ui.c | 13 +- src/ui.h | 2 +- src/windows/platform.c | 28 +++- 9 files changed, 254 insertions(+), 209 deletions(-) create mode 100644 changes.txt diff --git a/changes.txt b/changes.txt new file mode 100644 index 0000000..88a222c --- /dev/null +++ b/changes.txt @@ -0,0 +1,9 @@ +2 +- fix image blending issue with background colors +- triangle rendering on cpu +- refactor submenu for localization +- fix issue where last row of pixels is empty +- cursor change when hovering textbox +- new cursors +1 +- initial release \ No newline at end of file diff --git a/src/array.h b/src/array.h index cf3195c..115559a 100644 --- a/src/array.h +++ b/src/array.h @@ -14,7 +14,7 @@ typedef struct t_array u32 length; u32 reserved_length; u64 entry_size; - u16 reserve_jump; + u32 reserve_jump; void *data; mutex mutex; } array; diff --git a/src/linux/platform.c b/src/linux/platform.c index f849a79..d6fee97 100644 --- a/src/linux/platform.c +++ b/src/linux/platform.c @@ -346,8 +346,6 @@ inline void platform_destroy_file_content(file_content *content) mem_free(content->content); } -// Translate an X11 key code to a GLFW key code. -// static s32 translate_keycode(platform_window *window, s32 scancode) { s32 keySym; @@ -539,10 +537,6 @@ static void create_key_tables(platform_window window) memcpy(name, desc->names->keys[scancode].name, XkbKeyNameLength); name[XkbKeyNameLength] = '\0'; - // Map the key name to a GLFW key code. Note: We only map printable - // keys here, and we use the US keyboard layout. The rest of the - // keys (function keys) are mapped using traditional KeySym - // translations. if (strcmp(name, "TLDE") == 0) key = KEY_GRAVE_ACCENT; else if (strcmp(name, "AE01") == 0) key = KEY_1; else if (strcmp(name, "AE02") == 0) key = KEY_2; @@ -1337,6 +1331,8 @@ inline void platform_window_swap_buffers(platform_window *window) { case CURSOR_DEFAULT: cursor_shape = XC_arrow; break; case CURSOR_POINTER: cursor_shape = XC_hand1; break; + case CURSOR_DRAG: cursor_shape = XC_sb_h_double_arrow; break; + case CURSOR_TEXT: cursor_shape = XC_xterm; break; } Cursor cursor = XCreateFontCursor(window->display, cursor_shape); XDefineCursor(window->display, window->window, cursor); @@ -1669,6 +1665,16 @@ inline s8 string_to_s8(char *str) return (s8)strtol(str, 0, 10); } +inline s8 string_to_f32(char *str) +{ + return (f32)atof(str); +} + +inline s8 string_to_f64(char *str) +{ + return (f64)strtod(str, NULL); +} + inline void platform_open_url(char *url) { char buffer[MAX_INPUT_LENGTH]; diff --git a/src/platform.h b/src/platform.h index dc013e1..22984c9 100644 --- a/src/platform.h +++ b/src/platform.h @@ -160,6 +160,8 @@ typedef enum t_cursor_type { CURSOR_DEFAULT, CURSOR_POINTER, + CURSOR_TEXT, + CURSOR_DRAG, } cursor_type; typedef struct t_vec2 @@ -269,4 +271,7 @@ s32 string_to_s32(char *str); s16 string_to_s16(char *str); s8 string_to_s8(char *str); +s8 string_to_f32(char *str); +s8 string_to_f64(char *str); + #endif \ No newline at end of file diff --git a/src/project_base.h b/src/project_base.h index 6afb938..5d3f684 100644 --- a/src/project_base.h +++ b/src/project_base.h @@ -7,6 +7,8 @@ #ifndef INCLUDE_PROJECT_BASE #define INCLUDE_PROJECT_BASE +#define PROJECT_BASE_VERSION "2" + #ifdef _WIN32 #define OS_WIN #include @@ -46,6 +48,9 @@ #define float32 float #define float64 double +#define f32 float +#define f64 double + #ifdef OS_LINUX #define bool uint8_t #endif diff --git a/src/render.c b/src/render.c index dcff77b..3975f35 100644 --- a/src/render.c +++ b/src/render.c @@ -6,6 +6,79 @@ static platform_window *drawing_window = 0; +static void _copy_image_pixel(s32 x, s32 y, image *image, vec4 rec) +{ + s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; + u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; + + if (buffer_entry[4] > render_depth) return; + buffer_entry[4] = render_depth; + + s32 _x = x - rec.x; + s32 _y = y - rec.y; + s32 image_offset = (_y * (image->width) * 4) + _x * 4; + u8 *color = image->data+image_offset; + + float32 alpha = color[3] / 255.0f; + float32 oneminusalpha = 1 - alpha; + + u8 b = ((color[0] * alpha) + (oneminusalpha * buffer_entry[0])); + u8 g = ((color[1] * alpha) + (oneminusalpha * buffer_entry[1])); + u8 r = ((color[2] * alpha) + (oneminusalpha * buffer_entry[2])); + u8 a = color[3]; + + s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); + + memcpy(buffer_entry, &c, 4); +} + +static void _copy_glyph_pixel(s32 x, s32 y, glyph *gl, vec4 rec, color tint) +{ + s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; + u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; + + if (buffer_entry[4] > render_depth) return; + buffer_entry[4] = render_depth; + + s32 _x = x - rec.x; + s32 _y = y - rec.y; + s32 image_offset = (_y * gl->width) + _x; + u8 *color = gl->bitmap+image_offset; + + float32 alpha = color[0] / 255.0f; + float32 oneminusalpha = 1 - alpha; + + u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); + u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); + u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); + u8 a = color[0]; + + s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); + + memcpy(buffer_entry, &c, 4); +} + +static void _set_pixel(s32 x, s32 y, color tint) +{ + s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; + u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; + + if (buffer_entry[4] > render_depth) return; + buffer_entry[4] = render_depth; + + float32 alpha = tint.a / 255.0f; + float32 oneminusalpha = 1 - alpha; + + u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); + u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); + u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); + u8 a = tint.a; + + s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); + + memcpy(buffer_entry, &c, 4); +} + // returns topleft and bottomright corners. not width + height static vec4 _get_actual_rect(s32 x, s32 y, s32 width, s32 height) { @@ -15,10 +88,6 @@ static vec4 _get_actual_rect(s32 x, s32 y, s32 width, s32 height) s32 start_y = y; s32 end_x = start_x + width; s32 end_y = start_y + height; - if (end_x > drawing_window->backbuffer.width) - end_x = drawing_window->backbuffer.width; - if (end_y > drawing_window->backbuffer.height) - end_y = drawing_window->backbuffer.height; if (start_x < current_scissor.x) start_x = current_scissor.x; if (start_y < current_scissor.y) start_y = current_scissor.y; @@ -27,6 +96,11 @@ static vec4 _get_actual_rect(s32 x, s32 y, s32 width, s32 height) if (end_y > current_scissor.y+current_scissor.h) end_y = current_scissor.y+current_scissor.h; + if (end_x > drawing_window->backbuffer.width) + end_x = drawing_window->backbuffer.width; + if (end_y > drawing_window->backbuffer.height) + end_y = drawing_window->backbuffer.height; + return (vec4){start_x,start_y,end_x,end_y}; } @@ -88,32 +162,11 @@ void render_image(image *image, s32 x, s32 y, s32 width, s32 height) { vec4 rec = _get_actual_rect(x, y, image->width, image->height); - for (s32 x = rec.x; x < rec.w; x++) + for (s32 y = rec.y; y < rec.h; y++) { - for (s32 y = rec.y; y < rec.h; y++) + for (s32 x = rec.x; x < rec.w; x++) { - s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; - u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; - - if (buffer_entry[4] > render_depth) continue; - buffer_entry[4] = render_depth; - - s32 _x = x - rec.x; - s32 _y = y - rec.y; - s32 image_offset = (_y * (image->width) * 4) + _x * 4; - u8 *color = image->data+image_offset; - - float32 alpha = color[3] / 255.0f; - float32 oneminusalpha = 1 - alpha; - - u8 b = ((color[0] * alpha) + (oneminusalpha * buffer_entry[2])); - u8 g = ((color[1] * alpha) + (oneminusalpha * buffer_entry[1])); - u8 r = ((color[2] * alpha) + (oneminusalpha * buffer_entry[0])); - u8 a = color[3]; - - s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); - - memcpy(buffer_entry, &c, 4); + _copy_image_pixel(x, y, image, rec); } } } @@ -200,32 +253,11 @@ s32 render_text_ellipsed(font *font, s32 x, s32 y, s32 maxw, char *text, color t { vec4 rec = _get_actual_rect(x_to_render, y_, g.width, g.height); - for (s32 x = rec.x; x < rec.w; x++) + for (s32 y = rec.y; y < rec.h; y++) { - for (s32 y = rec.y; y < rec.h; y++) + for (s32 x = rec.x; x < rec.w; x++) { - s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; - u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; - - if (buffer_entry[4] > render_depth) continue; - buffer_entry[4] = render_depth; - - s32 _x = x - rec.x; - s32 _y = y - rec.y; - s32 image_offset = (_y * g.width) + _x; - u8 *color = g.bitmap+image_offset; - - float32 alpha = color[0] / 255.0f; - float32 oneminusalpha = 1 - alpha; - - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); - u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); - u8 a = color[0]; - - s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); - - memcpy(buffer_entry, &c, 4); + _copy_glyph_pixel(x, y, &g, rec, tint); } } } @@ -297,32 +329,11 @@ s32 render_text_with_selection(font *font, s32 x, s32 y, char *text, color tint, { vec4 rec = _get_actual_rect(x_to_render, y_, g.width, g.height); - for (s32 x = rec.x; x < rec.w; x++) + for (s32 y = rec.y; y < rec.h; y++) { - for (s32 y = rec.y; y < rec.h; y++) + for (s32 x = rec.x; x < rec.w; x++) { - s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; - u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; - - if (buffer_entry[4] > render_depth) continue; - buffer_entry[4] = render_depth; - - s32 _x = x - rec.x; - s32 _y = y - rec.y; - s32 image_offset = (_y * g.width) + _x; - u8 *color = g.bitmap+image_offset; - - float32 alpha = color[0] / 255.0f; - float32 oneminusalpha = 1 - alpha; - - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); - u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); - u8 a = color[0]; - - s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); - - memcpy(buffer_entry, &c, 4); + _copy_glyph_pixel(x, y, &g, rec, tint); } } } @@ -397,32 +408,11 @@ s32 render_text_with_cursor(font *font, s32 x, s32 y, char *text, color tint, s3 { vec4 rec = _get_actual_rect(x_to_render, y_, g.width, g.height); - for (s32 x = rec.x; x < rec.w; x++) + for (s32 y = rec.y; y < rec.h; y++) { - for (s32 y = rec.y; y < rec.h; y++) + for (s32 x = rec.x; x < rec.w; x++) { - s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; - u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; - - if (buffer_entry[4] > render_depth) continue; - buffer_entry[4] = render_depth; - - s32 _x = x - rec.x; - s32 _y = y - rec.y; - s32 image_offset = (_y * g.width) + _x; - u8 *color = g.bitmap+image_offset; - - float32 alpha = color[0] / 255.0f; - float32 oneminusalpha = 1 - alpha; - - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); - u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); - u8 a = color[0]; - - s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); - - memcpy(buffer_entry, &c, 4); + _copy_glyph_pixel(x, y, &g, rec, tint); } } } @@ -492,34 +482,11 @@ s32 render_text(font *font, s32 x, s32 y, char *text, color tint) { vec4 rec = _get_actual_rect(x_to_render, y_, g.width, g.height); - for (s32 x = rec.x; x < rec.w; x++) + for (s32 y = rec.y; y < rec.h; y++) { - for (s32 y = rec.y; y < rec.h; y++) + for (s32 x = rec.x; x < rec.w; x++) { - s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; - u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; - - if (buffer_entry[4] > render_depth) continue; - buffer_entry[4] = render_depth; - - s32 _x = x - rec.x; - s32 _y = y - rec.y; - s32 image_offset = (_y * g.width) + _x; - u8 *color = g.bitmap+image_offset; - - if (color[0] == 0) continue; - - float32 alpha = color[0] / 255.0f; - float32 oneminusalpha = 1 - alpha; - - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); - u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); - u8 a = color[0]; - - s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); - - memcpy(buffer_entry, &c, 4); + _copy_glyph_pixel(x, y, &g, rec, tint); } } } @@ -600,32 +567,11 @@ s32 render_text_cutoff(font *font, s32 x, s32 y, char *text, color tint, u16 cut { vec4 rec = _get_actual_rect(x_to_render, y__, g.width, g.height); - for (s32 x = rec.x; x < rec.w; x++) + for (s32 y = rec.y; y < rec.h; y++) { - for (s32 y = rec.y; y < rec.h; y++) + for (s32 x = rec.x; x < rec.w; x++) { - s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; - u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; - - if (buffer_entry[4] > render_depth) continue; - buffer_entry[4] = render_depth; - - s32 _x = x - rec.x; - s32 _y = y - rec.y; - s32 image_offset = (_y * g.width) + _x; - u8 *color = g.bitmap+image_offset; - - float32 alpha = color[0] / 255.0f; - float32 oneminusalpha = 1 - alpha; - - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); - u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); - u8 a = color[0]; - - s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); - - memcpy(buffer_entry, &c, 4); + _copy_glyph_pixel(x, y, &g, rec, tint); } } } @@ -790,33 +736,100 @@ s32 calculate_text_width(font *font, char *text) void render_triangle(s32 x, s32 y, s32 w, s32 h, color tint, triangle_direction dir) { - glBegin(GL_TRIANGLES); - glColor4f(tint.r/255.0f, tint.g/255.0f, tint.b/255.0f, tint.a/255.0f); - - if (dir == TRIANGLE_DOWN) - { - glVertex3i(x+(w/2), y+h, render_depth); - glVertex3i(x, y, render_depth); - glVertex3i(x+w, y, render_depth); - } - else if (dir == TRIANGLE_UP) - { - glVertex3i(x+(w/2), y, render_depth); - glVertex3i(x+w, y+h, render_depth); - glVertex3i(x, y+h, render_depth); - } - else if (dir == TRIANGLE_LEFT) + if (global_use_gpu) { - glVertex3i(x, y+(w/2), render_depth); - glVertex3i(x+h, y, render_depth); - glVertex3i(x+h, y+w, render_depth); + glBegin(GL_TRIANGLES); + glColor4f(tint.r/255.0f, tint.g/255.0f, tint.b/255.0f, tint.a/255.0f); + + if (dir == TRIANGLE_DOWN) + { + glVertex3i(x+(w/2), y+h, render_depth); + glVertex3i(x, y, render_depth); + glVertex3i(x+w, y, render_depth); + } + else if (dir == TRIANGLE_UP) + { + glVertex3i(x+(w/2), y, render_depth); + glVertex3i(x+w, y+h, render_depth); + glVertex3i(x, y+h, render_depth); + } + else if (dir == TRIANGLE_LEFT) + { + glVertex3i(x, y+(w/2), render_depth); + glVertex3i(x+h, y, render_depth); + glVertex3i(x+h, y+w, render_depth); + } + else if (dir == TRIANGLE_RIGHT) + { + assert(0 && "not implemented"); // TODO(Aldrik): implement + } + + glEnd(); } - else if (dir == TRIANGLE_RIGHT) + else { - // TODO(Aldrik): implement + vec4 rec = _get_actual_rect(x,y,w,h); + + s32 ac_w = rec.w - rec.x; + + if (dir == TRIANGLE_DOWN) + { + for (s32 y = rec.y; y < rec.h; y++) + { + s32 _y = y-rec.y; + + for (s32 x = rec.x; x < rec.w; x++) + { + s32 _x = x-rec.x; + if (_x < _y / 2 || _x >= ac_w-(_y/2)-1) continue; + + _set_pixel(x, y, tint); + } + } + } + else if (dir == TRIANGLE_UP) + { + s32 ac_h = rec.h - rec.y; + + for (s32 y = rec.y; y < rec.h; y++) + { + s32 _y = (y-rec.y); + _y = ac_h - _y; + + for (s32 x = rec.x; x < rec.w; x++) + { + s32 _x = x-rec.x; + if (_x < _y / 2 || _x >= ac_w-(_y/2)) continue; + + _set_pixel(x, y, tint); + } + } + } + else if (dir == TRIANGLE_LEFT) + { + s32 ac_h = rec.h - rec.y; + + for (s32 y = rec.y; y < rec.h; y++) + { + s32 _y = (y-rec.y); + _y = ac_h - _y; + + for (s32 x = rec.x; x < rec.w; x++) + { + s32 _x = x-rec.x; + _x = ac_w - _x; + if (_x / 2 > _y-1 || _x / 2 >= ac_w-(_y)) continue; + + _set_pixel(x, y, tint); + } + } + } + else if (dir == TRIANGLE_RIGHT) + { + assert(0 && "not implemented"); // TODO(Aldrik): implement + } + } - - glEnd(); } void render_rectangle(s32 x, s32 y, s32 width, s32 height, color tint) @@ -835,27 +848,11 @@ void render_rectangle(s32 x, s32 y, s32 width, s32 height, color tint) { vec4 rec = _get_actual_rect(x,y,width,height); - for (s32 x = rec.x; x < rec.w; x++) + for (s32 y = rec.y; y < rec.h; y++) { - for (s32 y = rec.y; y < rec.h; y++) + for (s32 x = rec.x; x < rec.w; x++) { - s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5; - u8 *buffer_entry = drawing_window->backbuffer.buffer+offset; - - if (buffer_entry[4] > render_depth) continue; - buffer_entry[4] = render_depth; - - float32 alpha = tint.a / 255.0f; - float32 oneminusalpha = 1 - alpha; - - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); - u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); - u8 a = tint.a; - - s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); - - memcpy(buffer_entry, &c, 4); + _set_pixel(x, y, tint); } } } diff --git a/src/ui.c b/src/ui.c index 6b6397a..908a4e9 100644 --- a/src/ui.c +++ b/src/ui.c @@ -626,6 +626,8 @@ bool ui_push_textbox(textbox_state *state, char *placeholder) bool clicked_to_set_cursor = false; if (mouse_x >= x && mouse_x < x + TEXTBOX_WIDTH && mouse_y >= virt_top && mouse_y < virt_bottom) { + platform_set_cursor(global_ui_context.layout.active_window, CURSOR_TEXT); + if (is_left_double_clicked(global_ui_context.mouse) && has_text) { ui_set_active_textbox(state); @@ -1327,7 +1329,7 @@ void ui_begin_menu_submenu(submenu_state *state, char *title) if (result) state->open = false; } -void ui_end_menu_submenu() +void ui_end_menu_submenu(char* empty_placeholder) { set_render_depth(30); @@ -1356,8 +1358,7 @@ void ui_end_menu_submenu() render_rectangle(state->x, state->y, w, total_h, global_ui_context.style.widget_background); render_rectangle_outline(state->x, state->y, w, total_h, 1, global_ui_context.style.border); - // TODO(Aldrik): localize - render_text(global_ui_context.font_small, text_x, text_y, "No recent projects.", global_ui_context.style.foreground); + render_text(global_ui_context.font_small, text_x, text_y, empty_placeholder, global_ui_context.style.foreground); } else { @@ -1961,13 +1962,13 @@ void ui_push_tooltip(char *text) x = global_ui_context.tooltip.x + global_ui_context.tooltip.w + WIDGET_PADDING+3; y = global_ui_context.tooltip.y; - render_triangle(x-6, y+(TEXTBOX_HEIGHT/2)-9,triangle_s,9, rgb(40,40,40), TRIANGLE_LEFT); + render_triangle(x-9, y+(TEXTBOX_HEIGHT/2)-9,triangle_s,triangle_s, rgb(40,40,40), TRIANGLE_LEFT); } // align left else if (global_ui_context.tooltip.x > global_ui_context.layout.active_window->width-(total_w/2)) { - // TODO(Aldrik): implement + assert(0 && "not implemented"); // TODO(Aldrik): implement } // align bottom else @@ -1976,7 +1977,7 @@ void ui_push_tooltip(char *text) y = global_ui_context.tooltip.y + global_ui_context.tooltip.h + WIDGET_PADDING+3; - render_triangle(x+(total_w/2)-(triangle_s/2), y-6,triangle_s,9, rgb(40,40,40), TRIANGLE_UP); + render_triangle(x+(total_w/2)-(triangle_s/2), y-9,triangle_s,triangle_s, rgb(40,40,40), TRIANGLE_UP); } render_rectangle(x, y,total_w,TEXTBOX_HEIGHT, rgb(40,40,40)); diff --git a/src/ui.h b/src/ui.h index a957237..9a654f5 100644 --- a/src/ui.h +++ b/src/ui.h @@ -215,7 +215,7 @@ void ui_begin_menu_bar(); bool ui_push_menu(char *title); bool ui_push_menu_item(char *title, char *shortcut); void ui_begin_menu_submenu(submenu_state *state, char *title); -void ui_end_menu_submenu(); +void ui_end_menu_submenu(char *empty_placeholder); void ui_push_menu_item_separator(); void ui_end_menu_bar(); bool ui_push_dropdown(dropdown_state *state, char *title); diff --git a/src/windows/platform.c b/src/windows/platform.c index 29e8970..ae0c055 100644 --- a/src/windows/platform.c +++ b/src/windows/platform.c @@ -345,7 +345,7 @@ static void _allocate_backbuffer(platform_window *window) window->backbuffer.width = window->width; window->backbuffer.height = window->height; - s32 bufferMemorySize = (window->width*window->height)*5; + s32 bufferMemorySize = (window->backbuffer.width*window->backbuffer.height)*5; window->backbuffer.buffer = mem_alloc(bufferMemorySize); } @@ -887,7 +887,17 @@ void platform_handle_events(platform_window *window, mouse_input *mouse, keyboar } RECT rec; - GetWindowRect(window->window_handle, &rec); + GetClientRect(window->window_handle, &rec); + +#if 0 + if ((window->width != rec.right-rec.left || window->height != rec.bottom-rec.top) + && !global_use_gpu) + { + window->width = rec.right-rec.left; + window->height = rec.bottom-rec.top; + _allocate_backbuffer(current_window_to_handle); + } +#endif POINT p; GetCursorPos(&p); @@ -932,6 +942,8 @@ void platform_window_swap_buffers(platform_window *window) { case CURSOR_DEFAULT: cursor_shape = IDC_ARROW; break; case CURSOR_POINTER: cursor_shape = IDC_HAND; break; + case CURSOR_DRAG: cursor_shape = IDC_SIZEWE; break; + case CURSOR_TEXT: cursor_shape = IDC_IBEAM; break; } HCURSOR cursor = LoadCursorA(NULL, cursor_shape); @@ -949,7 +961,7 @@ void platform_window_swap_buffers(platform_window *window) memcpy(window->backbuffer.buffer + (i*4), buffer_entry, 4); } - StretchDIBits(window->hdc,0,0,window->width,window->height, + StretchDIBits(window->hdc,0,1,window->width,window->height, 0,window->backbuffer.height,window->backbuffer.width, -window->backbuffer.height, window->backbuffer.buffer, &window->backbuffer.bitmapInfo, DIB_RGB_COLORS, SRCCOPY); @@ -1481,6 +1493,16 @@ s8 string_to_s8(char *str) return (s8)strtoul(str, 0, 10); } +s8 string_to_f32(char *str) +{ + return (f32)atof(str); +} + +s8 string_to_f64(char *str) +{ + return (f64)strtod(str, NULL); +} + #if 0 bool platform_send_http_request(char *url, char *params, char *response_buffer) { -- cgit v1.2.3-70-g09d2