editor_update :: (dt: f32) {
move_towards(^editor_openness, editor_target_openness, dt * 6);
-
+
if is_key_just_up(GLFW_KEY_1) do clicked_tab = .Create;
if is_key_just_up(GLFW_KEY_2) do clicked_tab = .Edit;
#local handle_entity_selction_and_dragging :: (dt: f32) {
mouse_pos := mouse_get_position_vector();
- if mouse_pos.x < ~~window_width - sidebar_width * 2 && mouse_pos.y > menubar_height {
+ if mouse_pos.x < ~~window_width - sidebar_width && mouse_pos.y > menubar_height {
if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) || is_button_just_down(GLFW_MOUSE_BUTTON_RIGHT) {
if active_tab == .Edit do active_index = -1;
selected_entity_id = Entity_Nothing;
break;
}
}
-
+
dragging = is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) && selected_entity_id != Entity_Nothing;
resizing = is_button_just_down(GLFW_MOUSE_BUTTON_RIGHT) && selected_entity_id != Entity_Nothing;
}
{ // Draw sidebar, if necessary
sidebar_width = editor_openness * 400.0f;
- w := sidebar_width;
+ w := sidebar_width;
x := ~~ window_width - w;
y := 40.0f;
h := ~~ window_height - y;
test << #char "t";
}
- draw_textbox(.{x, y + 72.0f, w, 36.0f}, ^test);
+ draw_textbox(.{x, y + 72.0f, w / 2.0f, 36.0f}, ^test);
#persist dumb := false;
font_print(editor_big_font, x + 2, y + 24, info.name);
+ if active_index >= 0 do sidebar_width += w;
render_struct_fields(any.{~~entity, entity.type}, 0, x, y + 4, w, h);
}
#local render_struct_fields :: (v: any, i: i32, x, y, w, h: f32, depth := 0) -> (new_y: f32, new_i: i32) {
- Field_Height :: 22.0f
+ Field_Height :: 22.0f;
info := cast(^type_info.Type_Info_Struct) type_info.get_type_info(v.type);
for^ info.members {
if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) {
if Rect.contains(.{x, y + 2, w, Field_Height + 2}, mouse_get_position_vector()) {
+ if active_index < 0 do sidebar_width += w;
active_index = i - 1;
}
}
if active_index + 1 == i {
- immediate_set_color(.{.4,.4,.2});
- immediate_rectangle(x, y + 2, w, Field_Height + 2);
+ immediate_set_color(.{.4,.4,.2});
+ immediate_rectangle(x, y + 2, w, Field_Height + 2);
- render_field_editor(member_any, y, it.name);
+ render_field_editor(member_any, y, it.name);
} elseif i % 2 == 0 {
- immediate_set_color(.{.3,.3,.3});
- immediate_rectangle(x, y + 2, w, Field_Height + 2);
+ immediate_set_color(.{.3,.3,.3});
+ immediate_rectangle(x, y + 2, w, Field_Height + 2);
}
font_print(editor_font, x + 2, y + Field_Height, it.name);
}
#local render_field_editor :: (v: any, y: f32, field_name: str) {
- w := sidebar_width;
+ w := sidebar_width / 2;
h := 200.0f;
- x := ~~ window_width - sidebar_width * 2;
+ x := ~~ window_width - sidebar_width;
y = math.min(y, ~~ window_height - h);
immediate_set_color(.{.3,.3,.3});
immediate_rectangle(x, y, w, h);
speed :: 128.0f;
delta: Vector2;
- if is_key_down(controls.left) { delta.x -= speed * dt; facing = .Left; }
- if is_key_down(controls.right) { delta.x += speed * dt; facing = .Right; }
- if is_key_down(controls.up) { delta.y -= speed * dt; facing = .Up; }
- if is_key_down(controls.down) { delta.y += speed * dt; facing = .Down; }
+ if is_key_down(controls.left) { delta.x -= speed * dt; facing = .Left; }
+ if is_key_down(controls.right) { delta.x += speed * dt; facing = .Right; }
+ if is_key_down(controls.up) { delta.y -= speed * dt; facing = .Up; }
+ if is_key_down(controls.down) { delta.y += speed * dt; facing = .Down; }
dist := math.max(size.x, size.y) * 2;
walls := scene->query_by_flags(.{pos.x - dist, pos.y - dist, dist * 2, dist * 2}, .Solid);
if *v < target do *v += diff;
if *v > target do *v -= diff;
}
-
immediate_ellipse :: () {}
+immediate_push_scissor :: (x, y, w, h: f32) {
+ // Assuming that x, y, w, and h are in screen (window) coordinates.
+
+ scissors << .{x, y, w, h};
+ glEnable(GL_SCISSOR_TEST);
+ glScissor(~~x, window_height - ~~(y + h), ~~w, ~~h);
+}
+
+immediate_pop_scissor :: () {
+ if scissors.count > 0 {
+ array.pop(^scissors);
+ }
+
+ if scissors.count > 0 {
+ glEnable(GL_SCISSOR_TEST);
+ s := scissors[scissors.count - 1];
+ glScissor(~~s.x, window_height - ~~(s.y + s.h), ~~s.w, ~~s.h);
+ } else {
+ glDisable(GL_SCISSOR_TEST);
+ }
+}
+
Color :: struct {
r, g, b : f32;
a := 1.0f;
}
rendering_type := Rendering_Type.Plain;
+ Scissor :: struct {
+ x, y, w, h: f32;
+ }
+ scissors: [..] Scissor;
+
set_rendering_type :: (new_type: typeof rendering_type) {
if rendering_type != new_type {
immediate_flush();
border_width := theme.border_width;
text_color := theme.text_color;
text := str.{text_buffer.data, text_buffer.count};
- if text.count == 0 && placeholder.count >0 {
+ if text.count == 0 && placeholder.count > 0 {
text = placeholder;
text_color = theme.placeholder_text_color;
}
}
case GLFW_KEY_DELETE {
- array.delete(text_buffer, 0);
+ array.delete(text_buffer, textbox_editing_state.cursor_position);
}
case #default {
move_towards(^animation_state.hover_time, 0.0f, theme.hover_speed);
}
- // immediate_push_scissor(x, y, w, h);
+ immediate_push_scissor(x, y, w, h);
immediate_set_color(theme.border_color);
immediate_rectangle(x, y, w, h);
move_towards(^animation_state.click_time, 0.0f, theme.click_decay_speed);
- // immediate_pop_scissor();
+ immediate_pop_scissor();
return result;
}
b = c1.b * (1 - t) + c2.b * t,
a = c1.a * (1 - t) + c2.a * t,
};
-}
\ No newline at end of file
+}