#ifndef EDITOR_H #define EDITOR_H #include "engine.h" typedef enum EditorModeEnum { MODE_NONE, MODE_VERTEX, MODE_NEIGHBOR, MODE_HEX, MODE_REGION, MODE_MAX_ENUM, } EditorMode; typedef struct EditorDataStruct EditorData; typedef struct ModeKeyStruct ModeKey; typedef void(*ModeKeyCallback)(EditorData* data, ClientContext* context, ModeKey* binding, int action, int mods); struct ModeKeyStruct { int key; ModeKeyCallback logic; int axis; float amount; }; struct EditorDataStruct { ModeKey* mode_keys[MODE_MAX_ENUM]; uint32_t mode_key_counts[MODE_MAX_ENUM]; // The full-window container hosting context->camera (see editor_startup/ // container_set_camera) - kept around so editor_frame_callback's resize // check can update its size without a lookup every frame. Container* main_container; uint32_t selected_max; uint32_t selected_count; // selected_vertices[i] (and hover_vertex below) is mode-dependent: a real // vertex index (1-6) in Vertex mode, a wedge/triangle index (0-5) in Hex // mode - same "hex mode used to just hardcode this to a placeholder" // shape as before (that placeholder was always 0, now it's whichever // wedge was actually picked). Always homogeneous within a frame, since // on_mode_changed clears the selection on every mode switch. uint32_t* selected_regions; uint32_t* selected_hexes; uint32_t* selected_vertices; bool hover_valid; uint32_t hover_region; uint32_t hover_hex; uint32_t hover_vertex; // Drag-to-multi-select: set on left-button press (Vertex/Hex mode), // cleared on release. While true, editor_cursor_callback applies the same // add/remove toggle a click would to whatever becomes newly hovered. // drag_remove captures the initiating click's Ctrl state, since // editor_cursor_callback (GLFW's cursor-pos callback) doesn't receive // modifier keys itself. bool dragging; bool drag_remove; // Camera control scheme: WASD/scroll accumulate into these, which // editor_frame_callback integrates into context->camera each frame. The // camera itself (position/rotation/distance/view) is engine-owned // (ClientContext.camera) - this is app policy for how input drives it, // not camera state, so a different app (or a scripted sequence) can drive // the same camera without this accumulator scheme at all. vec3 velocity; int32_t spin[2]; int32_t zoom; float spin_speed; float zoom_speed; float move_speed; }; EditorData* create_editor_data(void); void destroy_editor_data(EditorData* data); void editor_startup(ClientContext* context); void editor_frame_callback(ClientContext* context, double delta_time); void editor_key_callback(ClientContext* context, int key, int action, int mods); void editor_scroll_callback(ClientContext* context, double x, double y); void editor_button_callback(ClientContext* context, float x, float y, int button, int action, int mods); void editor_cursor_callback(ClientContext* context, float x, float y); EditorMode current_mode(ClientContext* context); void editor_set_mode(ClientContext* context, EditorMode mode); void resize_selected(EditorData* data, unsigned int size); int32_t find_selected_vertex(EditorData* data, uint32_t region, uint32_t hex, uint32_t vertex); void add_selected(EditorData* data, uint32_t region, uint32_t hex, uint32_t vertex); void remove_selected_at(EditorData* data, uint32_t index); // triangle (0-5) is always populated on a hit, independent of edge_only - // it's the wedge the ray landed in, used by Hex-mode selection. bool editor_pick(ClientContext* context, double cursor[2], uint32_t* rid, uint32_t* hid, uint32_t* vertex, uint32_t* triangle, bool edge_only); // Declared here since set_vertex_color/set_vertex_height are defined in // editor.c but need to be callable from editor_lua.c's Lua bindings. VkResult set_vertex_height(float height, uint32_t region, uint32_t hex, uint32_t vertex, ClientContext* context); VkResult set_vertex_color(vec4 color, uint32_t region, uint32_t hex, uint32_t vertex, ClientContext* context); VkResult set_hex_triangle_color(vec4 color, uint32_t region, uint32_t hex, uint32_t triangle, ClientContext* context); VkResult set_hex_flat(bool flat, uint32_t region, uint32_t hex, uint32_t triangle, ClientContext* context); void editor_selection_set_color(ClientContext* context, vec4 color); void editor_selection_nudge_height(ClientContext* context, float delta); void editor_selection_toggle_flat(ClientContext* context); #endif