#include "editor.h" #include "../Core/logger.h" #include #include #include static const float BG_DARK[] = {0.12f, 0.12f, 0.14f}; static const float BG_PANEL[] = {0.16f, 0.16f, 0.18f}; static const float BG_TITLE[] = {0.20f, 0.20f, 0.24f}; static const float BG_INPUT[] = {0.10f, 0.10f, 0.12f}; int editor_init(Editor* ed, GraphicsDevice* dev) { memset(ed, 0, sizeof(*ed)); ed->device = dev; if (!uilayer_init(&ed->ui, dev->device, (float)dev->width, (float)dev->height)) return 0; int sw = dev->width, sh = dev->height; int menu_h = 28; ed->panels[0] = (EditorPanel){PANEL_VIEWPORT, "Viewport", 220, menu_h, sw-440, sh-menu_h-200, 1, 0, 0}; ed->panels[1] = (EditorPanel){PANEL_SCENE, "Scene", 0, menu_h, 220, sh-menu_h-200, 1, 0, 0}; ed->panels[2] = (EditorPanel){PANEL_INSPECTOR, "Inspector", sw-220, menu_h, 220, sh-menu_h-200, 1, 0, 0}; ed->panels[3] = (EditorPanel){PANEL_CONSOLE, "Console", 0, sh-200, sw, 200, 1, 0, 0}; ed->panel_count = 4; ed->scene_entities_count = 8; strcpy(ed->selected_entity, "Cube"); LOG_INFO("Editor initialized"); return 1; } void editor_shutdown(Editor* ed) { uilayer_destroy(&ed->ui); } void editor_update(Editor* ed, float dt) { ed->time += dt; ed->viewport_rotation += dt * 0.5f; } void editor_render(Editor* ed) { ID3D11DeviceContext* ctx = ed->device->context; float sw = (float)ed->device->width; float sh = (float)ed->device->height; graphics_device_clear(ed->device, BG_DARK[0], BG_DARK[1], BG_DARK[2], 1.0f); uilayer_begin(&ed->ui); uilayer_rect(&ed->ui, 0, 0, sw, 28, 1.0f, 0.0f, 0.0f, 1.0f); uilayer_rect(&ed->ui, 0, 28, sw, 28, 0.0f, 1.0f, 0.0f, 1.0f); uilayer_rect(&ed->ui, 0, 56, sw/3, sh-256, 0.0f, 0.0f, 1.0f, 1.0f); uilayer_rect(&ed->ui, sw/3, 56, sw/3, sh-256, 1.0f, 1.0f, 0.0f, 1.0f); uilayer_rect(&ed->ui, 2*sw/3, 56, sw/3, sh-256, 1.0f, 0.0f, 1.0f, 1.0f); uilayer_rect(&ed->ui, 0, sh-200, sw, 200, 0.0f, 1.0f, 1.0f, 1.0f); uilayer_rect(&ed->ui, 0, sh-22, sw, 22, 1.0f, 0.5f, 0.0f, 1.0f); uilayer_flush(&ed->ui, ctx); float sw2 = sw, sh2 = sh; bitmap_font_draw(&ed->font, ctx, "MiMo Engine Editor", 10, 6, 0.4f, 0.75f, 1.0f, 1.0f, sw2, sh2); const char* menu[] = {"File", "Edit", "View", "Build", "Help"}; int mx = 180; for (int i = 0; i < 5; i++) { bitmap_font_draw(&ed->font, ctx, menu[i], mx + 8, 6, 0.9f, 0.9f, 0.92f, 1.0f, sw2, sh2); mx += (int)strlen(menu[i]) * 8 + 16; } const char* tools[] = {"Select", "Move", "Rotate", "Scale"}; int tx = 6; for (int i = 0; i < 4; i++) { bitmap_font_draw(&ed->font, ctx, tools[i], tx + 4, 34, 0.9f, 0.9f, 0.92f, 1.0f, sw2, sh2); tx += (int)strlen(tools[i]) * 8 + 16; } for (int i = 0; i < ed->panel_count; i++) { EditorPanel* p = &ed->panels[i]; if (!p->visible) continue; bitmap_font_draw(&ed->font, ctx, p->title, p->x + 6, p->y + 6, 0.9f, 0.9f, 0.92f, 1.0f, sw2, sh2); } bitmap_font_draw(&ed->font, ctx, ed->selected_entity, 226, 56, 0.4f, 0.75f, 1.0f, 1.0f, sw2, sh2); const char* entities[] = {"Light", "Camera", "Cube", "Plane", "Sphere", "Particles", "Audio", "Skybox"}; for (int i = 0; i < 8; i++) { bitmap_font_draw(&ed->font, ctx, entities[i], 226, 78 + i * 22, 0.9f, 0.9f, 0.92f, 1.0f, sw2, sh2); } const char* sections[] = {"Transform", "Mesh Filter", "Material", "Collider"}; int sy = 56; for (int s = 0; s < 4; s++) { bitmap_font_draw(&ed->font, ctx, sections[s], (int)sw - 214, sy, 0.9f, 0.9f, 0.92f, 1.0f, sw2, sh2); sy += 26; } char status[128]; snprintf(status, sizeof(status), "Entities: %d | Time: %.1fs", ed->scene_entities_count, ed->time); bitmap_font_draw(&ed->font, ctx, status, 10, (int)sh - 18, 0.55f, 0.55f, 0.6f, 1.0f, sw2, sh2); } void editor_handle_input(Editor* ed, int msg, int wp, int lp) { (void)lp; switch (msg) { case 0x0200: ed->input.mouse_x = wp & 0xFFFF; ed->input.mouse_y = (wp >> 16) & 0x7FFF; break; case 0x0201: ed->input.mouse_lbtn = 1; break; case 0x0202: ed->input.mouse_lbtn = 0; break; case 0x0204: ed->input.mouse_rbtn = 1; break; case 0x0205: ed->input.mouse_rbtn = 0; break; case 0x0100: if (wp < 256) ed->input.key_down[wp] = 1; break; case 0x0101: if (wp < 256) ed->input.key_down[wp] = 0; break; } }