Files
lity3d/Engine/UI/ui.h
T
shuiyu1123 2d56cb3bc9 MiMoEngine ASM: x86-64 MASM汇编+C混合架构游戏引擎
核心热路径(数学/内存/字符串/性能分析)用MASM汇编(SSE/AVX2)
外围系统(窗口/渲染/ECS/音频/UI/脚本)用C语言
含自研编辑器、VisualScript积木编程、中文渲染(glyph_atlas)
2026-07-10 19:20:40 +08:00

70 lines
1.9 KiB
C

#pragma once
// ============================================================================
// ui.h - 立即模式UI
// ============================================================================
#include <d3d11.h>
#include <stdint.h>
#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);