Files
lity3d/Engine/UI/ui.h
T
shuiyu1123 0669d102ce feat: major engine overhaul - scene demo with lighting, sphere, ground
- Scene Demo: cube + sphere + ground plane with proper lighting
- Audio: XAudio2 dynamic loading + WAV playback
- Physics: expanded collision system
- Renderer: improved pipeline with materials
- UI: extended widget system
- VisualScript: enhanced serializer + block interactions
- ASM: optimized math/memory/profiling routines
- Window: mouse input + scroll support
2026-07-12 08:21:07 +08:00

75 lines
2.1 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;
ID3D11ShaderResourceView* font_srv;
ID3D11SamplerState* font_sampler;
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;
float char_uvs[128][4];
} 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);
void ui_draw_text(UI* ui, float x, float y, const char* text, uint32_t color);
// 控件
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);