|
|
|
|
@ -442,7 +442,9 @@ bool editor_pick(ClientContext* context, double cursor[2], uint32_t* rid, uint32
|
|
|
|
|
// reserved for the hover preview (see refresh_hover_visuals).
|
|
|
|
|
void sync_hex_highlights(EditorData* data, ClientContext* context) {
|
|
|
|
|
EditorMode mode = current_mode(context);
|
|
|
|
|
for(uint32_t i = 0; i < MAX_HIGHLIGHTS - 1; i++) {
|
|
|
|
|
// +1 for the reserved hover slot (see refresh_hover_visuals).
|
|
|
|
|
ensure_highlight_capacity(&context->hex, &context->render, data->selected_count + 1);
|
|
|
|
|
for(uint32_t i = 0; i < context->hex.cap_highlights - 1; i++) {
|
|
|
|
|
if(i < data->selected_count) {
|
|
|
|
|
GPUHighlight temp = {
|
|
|
|
|
// 0.25 alpha (was 1.0) so a color applied under the selection
|
|
|
|
|
@ -466,7 +468,13 @@ void sync_hex_highlights(EditorData* data, ClientContext* context) {
|
|
|
|
|
|
|
|
|
|
void sync_vertex_points(EditorData* data, ClientContext* context) {
|
|
|
|
|
EditorMode mode = current_mode(context);
|
|
|
|
|
for(uint32_t i = 0; i < MAX_POINTS - 1; i++) {
|
|
|
|
|
// Only grow for demand that will actually be drawn (Hex-mode selections
|
|
|
|
|
// never populate points - see below), so switching to Hex mode with a
|
|
|
|
|
// huge selection doesn't grow a buffer nothing will read.
|
|
|
|
|
if(mode == MODE_VERTEX) {
|
|
|
|
|
ensure_point_capacity(&context->hex, &context->render, data->selected_count + 1);
|
|
|
|
|
}
|
|
|
|
|
for(uint32_t i = 0; i < context->hex.cap_points - 1; i++) {
|
|
|
|
|
// Hex-mode selections are wedges, not vertices - selected_vertices[i]
|
|
|
|
|
// isn't a real vertex index there, so there's nothing for a point
|
|
|
|
|
// marker to draw (the wedge highlight above is the only visual).
|
|
|
|
|
@ -492,7 +500,14 @@ void sync_vertex_points(EditorData* data, ClientContext* context) {
|
|
|
|
|
// remove) is visible before the user commits to it.
|
|
|
|
|
void refresh_hover_visuals(EditorData* data, ClientContext* context) {
|
|
|
|
|
EditorMode mode = current_mode(context);
|
|
|
|
|
uint32_t highlight_slot = MAX_HIGHLIGHTS - 1;
|
|
|
|
|
// No capacity check needed here: cap_highlights/cap_points start at
|
|
|
|
|
// MIN_HIGHLIGHTS/MIN_POINTS (create_hex_context) and only grow when
|
|
|
|
|
// selection does, via sync_hex_highlights/sync_vertex_points - so by the
|
|
|
|
|
// time this runs (whether after those, via refresh_selection_visuals, or
|
|
|
|
|
// on its own for a hover-only update) capacity already covers whatever
|
|
|
|
|
// the selection currently needs, and the hover slot just rides along at
|
|
|
|
|
// whatever the last index of that capacity is.
|
|
|
|
|
uint32_t highlight_slot = context->hex.cap_highlights - 1;
|
|
|
|
|
// would_remove and the hover highlight's shape (whole hex vs. one wedge)
|
|
|
|
|
// both key off the same mode-dependent hover_vertex meaning that
|
|
|
|
|
// find_selected_vertex/sync_hex_highlights use.
|
|
|
|
|
@ -511,7 +526,7 @@ void refresh_hover_visuals(EditorData* data, ClientContext* context) {
|
|
|
|
|
add_transfers(&disabled, context->hex.highlights, sizeof(GPUHighlight)*highlight_slot + offsetof(GPUHighlight, hex), sizeof(uint32_t), &context->render);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t point_slot = MAX_POINTS - 1;
|
|
|
|
|
uint32_t point_slot = context->hex.cap_points - 1;
|
|
|
|
|
if(mode == MODE_VERTEX && data->hover_valid) {
|
|
|
|
|
bool would_remove = find_selected_vertex(data, data->hover_region, data->hover_hex, data->hover_vertex) != -1;
|
|
|
|
|
GPUPoint temp;
|
|
|
|
|
@ -566,14 +581,24 @@ static void on_mode_changed(void* userdata, const char* event, uint32_t source,
|
|
|
|
|
EditorData* data = context->app_data;
|
|
|
|
|
data->selected_count = 0;
|
|
|
|
|
data->hover_valid = false;
|
|
|
|
|
data->dragging = false;
|
|
|
|
|
refresh_selection_visuals(data, context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void editor_button_callback(ClientContext* context, float x, float y, int button, int action, int mods) {
|
|
|
|
|
EditorData* data = context->app_data;
|
|
|
|
|
EditorMode mode = current_mode(context);
|
|
|
|
|
|
|
|
|
|
if(button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS) return;
|
|
|
|
|
if(button != GLFW_MOUSE_BUTTON_LEFT) return;
|
|
|
|
|
|
|
|
|
|
// Checked ahead of the mode gate below so a release always clears the
|
|
|
|
|
// drag, even if the mode somehow changed while the button was still held.
|
|
|
|
|
if(action == GLFW_RELEASE) {
|
|
|
|
|
data->dragging = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(action != GLFW_PRESS) return;
|
|
|
|
|
|
|
|
|
|
EditorMode mode = current_mode(context);
|
|
|
|
|
if(mode != MODE_VERTEX && mode != MODE_HEX) return;
|
|
|
|
|
|
|
|
|
|
uint32_t rid, hid, v;
|
|
|
|
|
@ -599,6 +624,12 @@ void editor_button_callback(ClientContext* context, float x, float y, int button
|
|
|
|
|
// different wedges of the same hex are distinct selections.
|
|
|
|
|
int32_t idx = find_selected_vertex(data, rid, hid, v);
|
|
|
|
|
|
|
|
|
|
// Starts a drag-select session: editor_cursor_callback extends this same
|
|
|
|
|
// add/remove toggle to whatever becomes newly hovered while the button
|
|
|
|
|
// stays down (see the "dragging" field's comment in editor.h).
|
|
|
|
|
data->dragging = true;
|
|
|
|
|
data->drag_remove = (mods & GLFW_MOD_CONTROL) != 0;
|
|
|
|
|
|
|
|
|
|
// Left click adds to the selection; Shift is reserved for camera movement
|
|
|
|
|
// (GLFW_KEY_LEFT_SHIFT) so it carries no selection meaning here. Ctrl
|
|
|
|
|
// removes. Mode changes remain the only way to reset the selection.
|
|
|
|
|
@ -643,7 +674,22 @@ void editor_cursor_callback(ClientContext* context, float x, float y) {
|
|
|
|
|
data->hover_hex = hid;
|
|
|
|
|
data->hover_vertex = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Drag-select: extend the initiating click's add/remove toggle to
|
|
|
|
|
// whatever just became hovered, same idx check as editor_button_callback
|
|
|
|
|
// uses for a plain click - so gliding back over an already-selected item
|
|
|
|
|
// during a plain (non-Ctrl) drag is a no-op, not a re-toggle.
|
|
|
|
|
if(data->dragging && hit) {
|
|
|
|
|
int32_t idx = find_selected_vertex(data, rid, hid, v);
|
|
|
|
|
if(data->drag_remove) {
|
|
|
|
|
if(idx != -1) remove_selected_at(data, (uint32_t)idx);
|
|
|
|
|
} else if(idx == -1) {
|
|
|
|
|
add_selected(data, rid, hid, v);
|
|
|
|
|
}
|
|
|
|
|
refresh_selection_visuals(data, context);
|
|
|
|
|
} else {
|
|
|
|
|
refresh_hover_visuals(data, context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void editor_startup(ClientContext* context) {
|
|
|
|
|
|