#pragma once // ============================================================================ // ui.h - 立即模式UI // ============================================================================ #include #include #define UI_MAX_VERTICES 16384 #define UI_MAX_INDICES 32768 #define UI_MAX_WIDGETS 256 typedef struct { float x, y; float u, v; uint32_t color; } UIVertex; typedef struct { float x, y, w, h; uint32_t color; int visible; } UIRect; typedef struct { ID3D11Buffer* vertex_buffer; ID3D11Buffer* index_buffer; ID3D11VertexShader* vertex_shader; ID3D11PixelShader* pixel_shader; ID3D11InputLayout* input_layout; ID3D11BlendState* blend_state; ID3D11RasterizerState* rasterizer; UIVertex vertices[UI_MAX_VERTICES]; uint32_t indices[UI_MAX_INDICES]; uint32_t vertex_count; uint32_t index_count; float mouse_x, mouse_y; int mouse_down; int mouse_pressed; int mouse_released; float font_size; uint32_t text_color; uint32_t bg_color; uint32_t border_color; float padding; } UI; // 创建/销毁 UI* ui_create(ID3D11Device* device); void ui_destroy(UI* ui); // 帧操作 void ui_begin(UI* ui, float mouse_x, float mouse_y, int mouse_down, int mouse_pressed, int mouse_released); void ui_end(UI* ui); void ui_render(UI* ui, ID3D11DeviceContext* ctx); // 基础绘制 void ui_draw_rect(UI* ui, float x, float y, float w, float h, uint32_t color); void ui_draw_rect_border(UI* ui, float x, float y, float w, float h, uint32_t fill, uint32_t border, float thickness); // 控件 int ui_button(UI* ui, float x, float y, float w, float h, const char* text); float ui_slider(UI* ui, float x, float y, float w, float h, float value, float min_val, float max_val); int ui_checkbox(UI* ui, float x, float y, const char* text, int checked); void ui_label(UI* ui, float x, float y, const char* text);