feat: add mouse click input - entity selection in scene panel

This commit is contained in:
shuiyu1123 committed 2026-07-11 01:23:55 +08:00
1 parent e6f5e43d85
commit 258f63fcee
1 file changed
+38
+38
View File
@@ -124,6 +124,9 @@ static int g_selected = 2;
static char g_console_lines[32][256];
static int g_console_count = 0;
static char g_file_path[512] = "untitled.ly";
static int g_mouse_x = 0, g_mouse_y = 0;
static int g_mouse_click = 0;
static int g_mouse_click_x = 0, g_mouse_click_y = 0;
static void console_add(const char* msg) {
if (g_console_count >= 32) {
@@ -135,6 +138,38 @@ static void console_add(const char* msg) {
g_console_count++;
}
static void on_mouse_move(int x, int y) {
g_mouse_x = x; g_mouse_y = y;
}
static void on_mouse_button(int button) {
if (button == 0) {
if (g_mouse_click == 0) {
g_mouse_click = 1;
g_mouse_click_x = g_mouse_x;
g_mouse_click_y = g_mouse_y;
}
}
}
static void process_click(void) {
if (!g_mouse_click) return;
g_mouse_click = 0;
int cx = g_mouse_click_x, cy = g_mouse_click_y;
float pw = 220, mh = 28, th = 28, sh2 = 22, ch = 180;
if (cx >= 0 && cx <= (int)pw && cy >= (int)(mh + th)) {
for (int i = 0; i < g_entity_count; i++) {
float ey = 60 + i * 22;
if (cy >= (int)ey - 4 && cy <= (int)ey + 18) {
g_selected = i;
char buf[128]; snprintf(buf, sizeof(buf), "Selected: %s", g_entities[i].name);
console_add(buf);
return;
}
}
}
}
static void save_ly(const char* path) {
FILE* f = fopen(path, "w");
if (!f) { console_add("ERROR: save failed"); return; }
@@ -191,6 +226,7 @@ static void init_default_scene(void) {
static void on_render(Engine* engine) {
if (!g_dev) return;
process_click();
ID3D11DeviceContext* ctx = g_dev->context;
float sw = (float)g_dev->width, sh = (float)g_dev->height;
@@ -321,6 +357,8 @@ int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR cmd, int nS) {
engine_set_render_callback(engine, on_render);
engine_set_key_callback(engine, on_key);
window_set_mouse_move_callback(engine->window, on_mouse_move);
window_set_mouse_button_callback(engine->window, on_mouse_button);
engine_run(engine);
if(g_tex_layout)g_tex_layout->lpVtbl->Release(g_tex_layout);