26-2-20 源码备份

This commit is contained in:
2026-02-20 15:02:30 +08:00
parent c5d109e9be
commit 6aa522f3e2
204 changed files with 2 additions and 20626 deletions

View File

@@ -1,18 +0,0 @@
{
"permissions": {
"allow": [
"Bash(cmd.exe:*)",
"Bash(build_all.bat)",
"Bash(powershell.exe:*)",
"Bash(\"C:/Program Files/CMake/bin/cmake.exe\" -S . -B build_x86 -A Win32)",
"Bash(\"C:/Program Files/CMake/bin/cmake.exe\" --build build_x86 --config Debug --target EzUI)",
"Bash(\"C:/Program Files/CMake/bin/cmake.exe\" --build build_x86 --config Release --target EzUI)",
"Bash(\"C:/Program Files/CMake/bin/cmake.exe\" -S . -B build_x64 -A x64)",
"Bash(\"C:/Program Files/CMake/bin/cmake.exe\":*)",
"Bash(\"C:/Program Files/CMake/bin/cmake.exe\" --build build_x64 --config Release --target EzUI)",
"Bash(file:*)",
"Bash(./test_build.bat)",
"Bash(./verify_scripts.bat:*)"
]
}
}

111
BUILD.md
View File

@@ -1,111 +0,0 @@
# EzUI 构建说明
## 前置要求
### 必需工具
1. **CMake** (版本 3.0 或更高)
- 下载地址https://cmake.org/download/
- 安装后建议将 CMake 添加到系统 PATH 环境变量
- 脚本会自动在以下位置查找 CMake
- 系统 PATH 中的 `cmake`
- `C:\Program Files\CMake\bin\cmake.exe`
2. **Visual Studio 2022** (包含 C++ 构建工具)
- 社区版即可免费使用
- 下载地址https://visualstudio.microsoft.com/downloads/
- 安装时需要选择"使用 C++ 的桌面开发"工作负载
### 可选工具
- **Git** - 用于版本控制(如需从 GitHub 克隆代码)
## 快速构建
### 构建所有配置
```bash
build_all.bat
```
这将自动构建以下所有配置:
- x86 Debug → `lib\EzUI_Debug_Win32.lib`
- x86 Release → `lib\EzUI_Release_Win32.lib`
- x64 Debug → `lib\EzUI_Debug_x64.lib`
- x64 Release → `lib\EzUI_Release_x64.lib`
### 单独构建 x86
```bash
build_x86.bat
```
### 单独构建 x64
```bash
build_x64.bat
```
## Visual Studio 开发
如果需要在 Visual Studio 中开发和调试:
```bash
configure_vs.bat
```
这将生成 CMake 解决方案文件,然后可以打开:
- `build_x86\EzUI.sln` (x86 项目)
- `build_x64\EzUI.sln` (x64 项目)
## 清理构建输出
```bash
clean.bat
```
这将删除以下目录:
- `build_x86/` - x86 构建目录
- `build_x64/` - x64 构建目录
- `lib/` - 静态库输出目录
## 手动 CMake 命令
如果你想使用 CMake 命令行:
```bash
# 配置 x86
cmake -S . -B build_x86 -A Win32
# 配置 x64
cmake -S . -B build_x64 -A x64
# 编译 x86 Debug
cmake --build build_x86 --config Debug --target EzUI
# 编译 x86 Release
cmake --build build_x86 --config Release --target EzUI
# 编译 x64 Debug
cmake --build build_x64 --config Debug --target EzUI
# 编译 x64 Release
cmake --build build_x64 --config Release --target EzUI
```
## 输出文件
所有静态库文件将输出到 `lib/` 目录,命名规则为:
| 配置 | 平台 | 输出文件 |
|------|------|----------|
| Debug | x86 | `lib\EzUI_Debug_Win32.lib` |
| Release | x86 | `lib\EzUI_Release_Win32.lib` |
| Debug | x64 | `lib\EzUI_Debug_x64.lib` |
| Release | x64 | `lib\EzUI_Release_x64.lib` |
## 构建配置说明
- **始终编译为静态库**:不再支持动态库选项
- **输出目录**:所有库文件统一输出到 `lib/` 目录
- **命名规则**`EzUI_$(Configuration)_$(Platform).lib`
- **字符编码**:使用 UTF-8 编译 (`/utf-8`)
- **Unicode**:启用 Unicode 支持
- **预处理器定义**:静态库会自动定义 `EZUI_STATIC`

196
CLAUDE.md
View File

@@ -1,196 +0,0 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## 项目概述
EzUI 是一个基于原生 Win32 消息机制和 Direct2D 的 C++ 桌面 UI 框架,提供类似 Web 前端的 CSS 样式系统和弹性布局。
**核心特性:**
- 基于 Win32 消息机制,轻量无依赖
- Direct2D 硬件加速渲染,支持高 DPI
- CSS 风格样式系统,支持伪类和选择器
- 弹性布局系统,支持自动尺寸和停靠
- 事件冒泡机制,灵活的事件处理
- 控件组合与继承,一切皆控件
## 快速开始
```cpp
#include "EzUI/UIManager.h"
#include "EzUI/Window.h"
#include "EzUI/Application.h"
using namespace ezui;
class TestForm : public Window {
private:
UIManager umg;
public:
TestForm() : Window(800, 600) {
umg.LoadXmlData("<vbox><label text=\"hello world\"></label></vbox>");
umg.SetupUI(this);
}
};
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
Application app;
TestForm form;
form.SetText(L"窗口标题");
form.Show(nCmdShow);
return app.Exec();
}
```
## 构建命令
**批处理脚本 (快速构建)**
```bash
build_x86.bat # 生成 32 位并构建 Debug/Release
build_x64.bat # 生成 64 位并构建 Debug/Release
build_all.bat # 同时构建 32 位和 64 位
```
**CMake 完整构建流程:**
```bash
# 配置阶段
cmake -S . -B build -A Win32 # 32 位配置
cmake -S . -B build -A x64 # 64 位配置
cmake -S . -B build -DBUILD_SHARED_LIBS=ON # 构建动态库
cmake -S . -B build -DBUILD_DEMO=OFF # 不构建 demo 项目
# 编译阶段
cmake --build build --config Debug # Debug 版本
cmake --build build --config Release # Release 版本
# 单独构建 EzUI 库
cmake --build build --target EzUI --config Debug
cmake --build build --target EzUI --config Release
```
## 核心架构
### 窗口类型 (继承层次)
- `Window` - 经典带边框窗口
- `BorderlessWindow` - 无边框带阴影窗口
- `LayeredWindow` - 分层透明窗口,支持异形
- `PopupWindow` - 失焦自动关闭的弹出窗口
### 控件系统
所有控件继承自 `Control` 基类,核心控件包括:
**基础控件:**
- `Label` - 文本标签
- `Button` - 标准按钮
- `TextBox` - 文本输入框(支持多行)
- `PictureBox` - 图片显示(支持 GIF 动画)
**选择控件:**
- `CheckBox` - 复选框
- `RadioButton` - 单选按钮
- `ComboBox` - 下拉选择框
**数据控件:**
- `TableView` - 表格视图
- `TreeView` - 树形视图
- `ListView` 系列:`HListView`(横向列表)、`VListView`(纵向列表)、`TileListView`(瓦片式)、`PagedListView`(分页列表)
**布局容器:**
- `HLayout` / `HBox` - 水平布局容器
- `VLayout` / `VBox` - 垂直布局容器
- `TabLayout` - 选项卡切换容器
- `Spacer` - 弹性/固定间距占位符
**功能控件:**
- `ScrollBar` / `HScrollBar` / `VScrollBar` - 滚动条
- `Menu` - 菜单系统
- `NotifyIcon` - 系统托盘图标
- `ProgressBar` - 进度条
- `IFrame` - 内嵌框架(类似 HTML iframe
- `ShadowBox` - 阴影容器
**动画系统:**
- `Animation` - 类似 Qt 的属性过渡动画
### 布局系统
- **尺寸优先级**:比例尺寸 (`SetRateWidth/Height`) > 绝对尺寸 (`SetFixedSize`) > 控件内容大小
- **自动布局**`SetAutoWidth/Height` 让控件根据内容自动调整大小
- **停靠布局**`SetDockStyle` 支持 Fill/Vertical/Horizontal 停靠
- **布局状态**`TryPendLayout`/`ResumeLayout` 批量添加控件后统一布局
### 样式与渲染
- `UIManager` - UI 样式与资源管理,支持 XML 布局加载
- `UISelector` - CSS 选择器匹配系统支持类选择器、ID 选择器、组合选择器)
- `Direct2DRender` - Direct2D 绘图实现,支持硬件加速
- `RenderTypes` - 颜色、对齐方式等绘图类型定义
- `UIDef` - 框架内使用的宏定义集合
- `EzUI.h` - 框架主接口头文件,定义事件类、枚举、全局资源等核心结构
**CSS 样式特性:**
- 伪类支持:`:hover``:active``:checked``:disabled`
- 样式属性width、height、background-color、border、color、font 等
- 选择器类型标签选择器、类选择器、ID 选择器、组合选择器
### 事件系统
- 支持事件冒泡机制,可实现事件捕获与穿透
- `NotifyFlags` 控制控件哪些事件需要通知窗口
- `Event` 枚举定义所有事件类型(鼠标、键盘、绘制等),支持位运算组合
- 事件穿透控制:通过 `m_hitTestEnabled` 控制命中测试
- Debug 模式下按 F11 可查看布局信息和控件边界
### 线程模型
- UI 线程:`Application::Run` 启动消息循环
- 跨线程调用:`BeginInvoke`(异步)/ `Invoke`(同步)
- 全局隐藏窗口 `__EzUI_MessageWnd` 用于线程通讯
### 资源管理
- 控件树内存由父控件自动管理:`Attach`/`Detach`
- 图片资源通过 `PtrManager` 自动释放
- XML 布局加载后由 `UIManager` 管理生命周期
- 资源打包系统:通过 `add_resource_package` CMake 函数将资源打包为 `.res` 文件
**资源打包流程:**
1. 在 demo 的 CMakeLists.txt 中调用 `add_resource_package(target source_dir output_file)`
2. 构建时会自动运行 `ResPackage.exe` 工具
3. 生成的 `.res` 文件可以在运行时通过 `Resource.h` 中的函数加载
4. 支持本地文件和资源文件的自动加载(通过 `add_resource_package` 函数)
### 调试技巧
- 在 Debug 模式下运行时,按下 `F11` 可实时查看布局信息,高亮显示控件边界
## Demo 项目
- `helloWorld` - 基础示例,演示最简单的窗口创建
- `ResPackage` - 资源打包工具,用于将资源文件打包为 `.res` 格式
- `QQ` - 仿 QQ 登录界面,展示资源打包和 XML 布局加载
- `kugou` - 酷狗音乐播放器,演示 VLC 集成和复杂 UI 交互(需要额外依赖)
- `TableViewDemo` - 表格控件演示,展示 LayeredWindow + VLayout + TableView + 右键菜单的组合使用
**CMake Demo 目标:**
- 所有 demo 都使用 `add_executable(... WIN32 ...)` 创建
- 通过 `add_resource_package(target source_dir output_file)` 自动打包资源
- 资源文件通过 `source_group` 组织到 VS 的 "res" 筛选项下
## 开发约定
**目录结构:**
- 头文件:`include/EzUI/` 目录
- 源文件:`sources/` 目录
- Demo 项目:`demo/` 目录
**核心理念:**
- 一切皆控件,纯代码组合 UI
- 使用 CSS 驱动视觉,结构与样式分离
- XML 布局通过 `UIManager::LoadXmlFile()``LoadXmlData()` 加载
**CMake 自定义命令:**
- `add_resource_package(target source_dir output_file)` - 打包资源文件为 `.res` 格式
- `target` 需要与 `add_executable` 的项目名匹配
- 资源会在构建时自动打包,程序通过 `Resource.h` 提供的函数访问
- 需要先构建 `ResPackage` 工具(位于 `demo/ResPackage`
**窗口绘制机制:**
- `Window` / `BorderlessWindow`Windows 自动发送 `WM_PAINT` 消息
- `LayeredWindow`:需手动发送 `WM_PAINT` 消息进行绘制(支持实时重绘)
- `PopupWindow`:失焦自动关闭,适用于菜单等临时窗口

View File

@@ -1,62 +0,0 @@
cmake_minimum_required(VERSION 3.0...9.0)
if(UNIX)
add_compile_options(-finput-charset=UTF-8)
add_compile_options(-fexec-charset=UTF-8)
elseif(WIN32)
add_compile_options(/utf-8)
endif()
set(tag $<IF:$<CONFIG:Debug>,Debug,Release>)
#让所有项目都使用UNICODE
add_definitions(-D_UNICODE -DUNICODE)
project(EzUI)
file(GLOB src ./include/EzUI/*.* ./sources/*.* )
# 始终编译为静态库
add_library(EzUI STATIC ${src})
target_compile_definitions(EzUI PUBLIC EZUI_STATIC)
target_include_directories(EzUI PRIVATE ./include/EzUI)
set_target_properties(EzUI PROPERTIES LINKER_LANGUAGE CXX)
# 设置库文件输出目录和命名规则
# 平台标识:根据架构判断 Win32 或 x64
set(PLATFORM_TAG $<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,Win32>)
# 设置输出目录为 lib
set_target_properties(EzUI PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/lib"
)
# 设置库文件命名规则为 EzUI_$(Configuration)_$(Platform).lib
set_target_properties(EzUI PROPERTIES
OUTPUT_NAME "EzUI_$<CONFIG>_${PLATFORM_TAG}"
)
# 定义函数: 添加资源打包任务并关联到指定项目
function(add_resource_package TARGET_NAME INPUT_DIR OUTPUT_FILE)
set (ProjectName ${TARGET_NAME}_EzUI_ResourcePackager)
# 定义始终运行的伪目标
add_custom_target(
${ProjectName} # 更简洁的目标命名
COMMAND ${CMAKE_SOURCE_DIR}/ResPackage.exe -package ${CMAKE_CURRENT_SOURCE_DIR}/${INPUT_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${OUTPUT_FILE}
COMMENT "Packaging resources for ${TARGET_NAME}..."
)
# 将目标归类到专用文件夹
set_target_properties(${ProjectName} PROPERTIES
FOLDER "CMakePredefinedTargets" # 在VS中归类到指定文件夹
)
# 主目标依赖伪目标
add_dependencies(${TARGET_NAME} ${ProjectName})
endfunction()
#添加子项目
option(BUILD_DEMO "Build demo projects" ON)
if(BUILD_DEMO)
add_subdirectory(./demo)
endif()

186
README.md
View File

@@ -1,186 +0,0 @@
# EzUI
**EzUI** 是一个基于原生 Win32 消息机制和 Direct2D 的高性能桌面 UI 框架,具备强大的弹性布局、伪类样式支持和控件系统,目标是提供如 Web 前端般灵活、直观的界面开发体验。
> 🚀 支持高 DPI、分层窗口、响应式布局、CSS 风格皮肤、GIF 动画、控件组合与继承机制。未来将支持跨平台 2D 图形库扩展。
---
## ✨ 框架特色
- 🪱 **基于 Win32 消息机制**:轻量、无依赖,逻辑控件系统拦截并下发鼠标键盘消息
- 🎨 **2D 图形绘制**:当前基于 Direct2D 绘图,具备高性能、高分辨率适配能力。
- 🧹 **弹性布局系统**:支持自动宽高、自适应布局,开发体验类比前端 Flex 设计。
- 🎭 **伪类 CSS 支持**:支持 `hover``active``checked` 等状态样式类选择器、ID 选择器、组合选择器等完整选择器系统。
- 🌟 **控件组合系统**Label、Button、TextBox、CheckBox、RadioButton 等丰富控件可自由组合构建 UI。
- 💡 **事件系统**:支持事件冒泡机制,可实现事件捕获与穿透。
- 🧩 **高 DPI 适配**:框架自动处理 DPI 缩放与坐标换算,支持多显示器高分屏。
- 🪪 **多种窗口类型支持**
- `Window`:经典边框窗口 windows自动发送`WM_PAINT`消息绘制
- `BorderlessWindow`:无边框、带阴影 windows自动发送`WM_PAINT`消息绘制
- `LayeredWindow`:分层透明窗口,支持异形与实时重绘 手动发送 `WM_PAINT`消息进行绘制
- `PopupWindow`:失焦自动关闭的弹出窗口,适用于菜单等
---
## 📆 快速开始
### 1. 下载源码
```bash
git clone https://github.com/NewYoungCode/EzUI.git
```
### 2. 安装 CMake
请前往 [CMake 官网](https://cmake.org/download/) 下载安装。
### 3. 构建与运行
- 构建 32 位项目:
```bash
build.bat
```
- 构建 64 位项目:
```bash
build64.bat
```
---
## 📀 使用说明
### 🏁 程序入口
请在 `WinMain` 函数中创建 `Application` 实例并调用 `app.Exec()` 以启动消息循环:
```cpp
#include <Windows.h>
#include "EzUI/UIManager.h"
#include "Ezui/Window.h"
#include "Ezui/Application.h"
using namespace ezui;
class TestForm :public Window {
private:
UIManager umg;//ui管理器
public:
TestForm() :Window(800, 600) {
//umg.LoadXmlFile("res/form.htm");//从文件中加载xml界面
umg.LoadXmlData("<vbox> <label text=\"hello world\"></label> </vbox>");//从内存中加载布局
umg.SetupUI(this);//设置ui
}
virtual ~TestForm() {
}
virtual void OnClose(bool& bClose) override {
int result = ::MessageBoxW(frm.Hwnd(), L"要退出程序吗?", L"提示", MB_YESNO | MB_ICONQUESTION);
if (result == IDYES) {
Application::Exit(0);//当窗口关闭时 整个程序退出
} else {
bClose=false; // 用户点击了“否” 此标志设置为false将不会关闭
}
}
};
//程序入口;
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
Application app;
TestForm testForm;
testForm.SetText(L"我是测试窗口");
testForm.Show(nCmdShow);
return app.Exec();
};
```
### 🧱 控件与组件列表(部分)
- `Application`EzUI 应用入口与消息循环控制器
- `Window`:经典 Win32 边框窗口
- `BorderlessWindow`:无边框带阴影窗口
- `LayeredWindow`:支持透明和异形的分层窗口
- `PopupWindow`:失焦自动关闭的弹出窗口
- `Control`:所有控件基础类,封装鼠标命中、事件分发和重绘逻辑
- `Label`:文字标签控件
- `Button`:标准按钮控件
- `TextBox`:文本输入框
- `CheckBox` / `RadioButton`:复选框 / 单选框控件
- `PictureBox`:图片显示控件,支持 GIF
- `ComboBox`:下拉框控件
- `Menu`:菜单支持
- `NotifyIcon`:托盘图标支持
- `ScrollBar` / `HScrollBar` / `VScrollBar`:滚动条组件
- `HLayout` / `VLayout`:水平/垂直布局容器
- `HListView` / `VListView`:横向/纵向列表视图容器
- `TileListView`:瓦片式列表视图
- `TabLayout`:选项卡切换容器
- `Spacer`:空隙组件,占位用
- `ShadowBox`:为无边框窗口提供窗口阴影
- `IFrame`:内嵌页面控件,功能类似 Web 前端中的 `<iframe>`
- `UIDef`:框架内使用的宏定义集合
- `UIManager`UI 样式与资源统一管理
- `UISelector`:选择器匹配系统,实现类选择器、链式查询控件
- `UIString` / `tinystr.h` / `tinyxml.h`:字符串处理与 XML 配置解析支持
- `RenderTypes`:绘图相关类型定义(颜色、对齐方式等)
- `Direct2DRender`Direct2D 绘图实现类
- `Bitmap`:图像资源封装
- `Resource.h`:自定义资源管理类(非 VS rc 文件),用于手动加载与管理框架资源
- `Timer` / `Task`:定时与异步任务处理辅助类
- `EzUI.h`:框架主接口头文件,定义事件类、枚举、全局资源等核心结构
- `Animation.h`类似于QT的那种过渡动画
### 🎨 样式示例
```css
#submitBtn {
width: 100px; /*静态样式时支持调整大小*/
height: 30px; /*静态样式时支持调整大小*/
background-color: #0078d7;
}
#submitBtn:hover {
background-color: #005a9e;
}
.classA .classB { /*多选择器*/
color:#ffffff;
}
label{ /*标签选择器*/
color:#ffffff;
}
.check:checked {
border:1px;
border-radius:10px;
border-color: #005a9e;
}
```
---
## 🔧 调试技巧
- 在 Debug 模式下运行时,按下 `F11` 可实时查看布局信息,高亮显示控件边界。
---
## 🧬 开发理念
- **“一切皆控件”**:无 UI 描述文件,纯代码式组件组合;
- **“CSS 驱动视觉”**:结构和样式分离;
- **“面向前端思维”**:布局、交互风格向 Web 靠拟;
- **“跨平台可拟扩”**:绘图模块可替换(未来可能会使用跨平台图形库);
---

View File

@@ -1,71 +0,0 @@
@echo off
setlocal
set "CMAKE_EXE="
where cmake >nul 2>&1
if %errorlevel% equ 0 (
set "CMAKE_EXE=cmake"
echo Found CMake in PATH
) else if exist "C:\Program Files\CMake\bin\cmake.exe" (
set "CMAKE_EXE=C:\Program Files\CMake\bin\cmake.exe"
echo Found CMake at C:\Program Files\CMake\bin\cmake.exe
) else (
echo Error: CMake not found!
echo Please install CMake or add it to PATH.
echo Download: https://cmake.org/download/
pause
exit /b 1
)
echo.
echo ======================================
echo EzUI Build Script
echo Building: x86/x64 Debug/Release
echo ======================================
echo.
echo [1/6] Configuring x86...
"%CMAKE_EXE%" -S . -B build_x86 -A Win32
if %errorlevel% neq 0 goto error
echo [2/6] Building x86 Debug...
"%CMAKE_EXE%" --build build_x86 --config Debug --target EzUI
if %errorlevel% neq 0 goto error
echo [3/6] Building x86 Release...
"%CMAKE_EXE%" --build build_x86 --config Release --target EzUI
if %errorlevel% neq 0 goto error
echo [4/6] Configuring x64...
"%CMAKE_EXE%" -S . -B build_x64 -A x64
if %errorlevel% neq 0 goto error
echo [5/6] Building x64 Debug...
"%CMAKE_EXE%" --build build_x64 --config Debug --target EzUI
if %errorlevel% neq 0 goto error
echo [6/6] Building x64 Release...
"%CMAKE_EXE%" --build build_x64 --config Release --target EzUI
if %errorlevel% neq 0 goto error
echo.
echo ======================================
echo Build completed successfully!
echo ======================================
echo.
echo Output files:
echo lib\EzUI_Debug_Win32.lib
echo lib\EzUI_Release_Win32.lib
echo lib\EzUI_Debug_x64.lib
echo lib\EzUI_Release_x64.lib
echo.
pause
exit /b 0
:error
echo.
echo ======================================
echo Build failed!
echo ======================================
pause
exit /b 1

View File

@@ -1,50 +0,0 @@
@echo off
setlocal
set "CMAKE_EXE="
where cmake >nul 2>&1
if %errorlevel% equ 0 (
set "CMAKE_EXE=cmake"
) else if exist "C:\Program Files\CMake\bin\cmake.exe" (
set "CMAKE_EXE=C:\Program Files\CMake\bin\cmake.exe"
) else (
echo Error: CMake not found!
echo Please install CMake or add it to PATH.
pause
exit /b 1
)
echo ======================================
echo Building EzUI x64
echo ======================================
echo.
echo [1/3] Configuring x64...
"%CMAKE_EXE%" -S . -B build_x64 -A x64
if %errorlevel% neq 0 goto error
echo [2/3] Building x64 Debug...
"%CMAKE_EXE%" --build build_x64 --config Debug --target EzUI
if %errorlevel% neq 0 goto error
echo [3/3] Building x64 Release...
"%CMAKE_EXE%" --build build_x64 --config Release --target EzUI
if %errorlevel% neq 0 goto error
echo.
echo ======================================
echo x64 build completed!
echo Output:
echo lib\EzUI_Debug_x64.lib
echo lib\EzUI_Release_x64.lib
echo ======================================
pause
exit /b 0
:error
echo.
echo ======================================
echo Build failed!
echo ======================================
pause
exit /b 1

View File

@@ -1,50 +0,0 @@
@echo off
setlocal
set "CMAKE_EXE="
where cmake >nul 2>&1
if %errorlevel% equ 0 (
set "CMAKE_EXE=cmake"
) else if exist "C:\Program Files\CMake\bin\cmake.exe" (
set "CMAKE_EXE=C:\Program Files\CMake\bin\cmake.exe"
) else (
echo Error: CMake not found!
echo Please install CMake or add it to PATH.
pause
exit /b 1
)
echo ======================================
echo Building EzUI x86
echo ======================================
echo.
echo [1/3] Configuring x86...
"%CMAKE_EXE%" -S . -B build_x86 -A Win32
if %errorlevel% neq 0 goto error
echo [2/3] Building x86 Debug...
"%CMAKE_EXE%" --build build_x86 --config Debug --target EzUI
if %errorlevel% neq 0 goto error
echo [3/3] Building x86 Release...
"%CMAKE_EXE%" --build build_x86 --config Release --target EzUI
if %errorlevel% neq 0 goto error
echo.
echo ======================================
echo x86 build completed!
echo Output:
echo lib\EzUI_Debug_Win32.lib
echo lib\EzUI_Release_Win32.lib
echo ======================================
pause
exit /b 0
:error
echo.
echo ======================================
echo Build failed!
echo ======================================
pause
exit /b 1

View File

@@ -1,26 +0,0 @@
@echo off
echo ======================================
echo Cleaning build output...
echo ======================================
echo.
if exist build_x86 (
echo Removing build_x86...
rmdir /s /q build_x86
)
if exist build_x64 (
echo Removing build_x64...
rmdir /s /q build_x64
)
if exist lib (
echo Removing lib...
rmdir /s /q lib
)
echo.
echo ======================================
echo Clean completed!
echo ======================================
pause

View File

@@ -1,48 +0,0 @@
@echo off
setlocal
set "CMAKE_EXE="
where cmake >nul 2>&1
if %errorlevel% equ 0 (
set "CMAKE_EXE=cmake"
) else if exist "C:\Program Files\CMake\bin\cmake.exe" (
set "CMAKE_EXE=C:\Program Files\CMake\bin\cmake.exe"
) else (
echo Error: CMake not found!
echo Please install CMake or add it to PATH.
pause
exit /b 1
)
echo ======================================
echo Configuring for Visual Studio
echo ======================================
echo.
echo [1/2] Configuring x86...
"%CMAKE_EXE%" -S . -B build_x86 -A Win32
if %errorlevel% neq 0 goto error
echo [2/2] Configuring x64...
"%CMAKE_EXE%" -S . -B build_x64 -A x64
if %errorlevel% neq 0 goto error
echo.
echo ======================================
echo Configuration completed!
echo ======================================
echo.
echo You can now open:
echo - build_x86\EzUI.sln (x86)
echo - build_x64\EzUI.sln (x64)
echo.
pause
exit /b 0
:error
echo.
echo ======================================
echo Configuration failed!
echo ======================================
pause
exit /b 1

View File

@@ -1,31 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36811.4 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Adminstor", "Adminstor\Adminstor.vcxproj", "{EE06DEDC-52B5-4B5D-8B52-7FEB02D77E6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE06DEDC-52B5-4B5D-8B52-7FEB02D77E6B}.Debug|x64.ActiveCfg = Debug|x64
{EE06DEDC-52B5-4B5D-8B52-7FEB02D77E6B}.Debug|x64.Build.0 = Debug|x64
{EE06DEDC-52B5-4B5D-8B52-7FEB02D77E6B}.Debug|x86.ActiveCfg = Debug|Win32
{EE06DEDC-52B5-4B5D-8B52-7FEB02D77E6B}.Debug|x86.Build.0 = Debug|Win32
{EE06DEDC-52B5-4B5D-8B52-7FEB02D77E6B}.Release|x64.ActiveCfg = Release|x64
{EE06DEDC-52B5-4B5D-8B52-7FEB02D77E6B}.Release|x64.Build.0 = Release|x64
{EE06DEDC-52B5-4B5D-8B52-7FEB02D77E6B}.Release|x86.ActiveCfg = Release|Win32
{EE06DEDC-52B5-4B5D-8B52-7FEB02D77E6B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AC1EAB6C-7DC1-484D-92AE-6736232936CA}
EndGlobalSection
EndGlobal

View File

@@ -1,205 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{ee06dedc-52b5-4b5d-8b52-7feb02d77e6b}</ProjectGuid>
<RootNamespace>Adminstor</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>..\_bin\</OutDir>
<IntDir>..\_temp\$(Platform)$(Configuration)$(ProjectName)\</IntDir>
<IncludePath>..\ThirdParty\EzUI\include;$(IncludePath)</IncludePath>
<LibraryPath>..\ThirdParty\EzUI\lib;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)_$(Configuration)_$(Platform)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>..\_bin\</OutDir>
<IntDir>..\_temp\$(Platform)$(Configuration)$(ProjectName)\</IntDir>
<IncludePath>..\ThirdParty\EzUI\include;$(IncludePath)</IncludePath>
<LibraryPath>..\ThirdParty\EzUI\lib;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)_$(Configuration)_$(Platform)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>..\_bin\</OutDir>
<IntDir>..\_temp\$(Platform)$(Configuration)$(ProjectName)\</IntDir>
<IncludePath>..\ThirdParty\EzUI\include;$(IncludePath)</IncludePath>
<LibraryPath>..\ThirdParty\EzUI\lib;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)_$(Configuration)_$(Platform)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>..\_bin\</OutDir>
<IntDir>..\_temp\$(Platform)$(Configuration)$(ProjectName)\</IntDir>
<IncludePath>..\ThirdParty\EzUI\include;$(IncludePath)</IncludePath>
<LibraryPath>..\ThirdParty\EzUI\lib;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)_$(Configuration)_$(Platform)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>EzUI_$(Configuration)_$(Platform).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>EzUI_$(Configuration)_$(Platform).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>EzUI_$(Configuration)_$(Platform).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>EzUI_$(Configuration)_$(Platform).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="loginForm.h" />
<ClInclude Include="mainForm.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DemoUi.cpp" />
<ClCompile Include="loginForm.cpp" />
<ClCompile Include="mainForm.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="DemoUi.ico" />
<Image Include="small.ico" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DemoUi.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -1,61 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="loginForm.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="mainForm.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DemoUi.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="loginForm.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="mainForm.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="small.ico">
<Filter>资源文件</Filter>
</Image>
<Image Include="DemoUi.ico">
<Filter>资源文件</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DemoUi.rc">
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

Binary file not shown.

View File

@@ -1,15 +0,0 @@
#include "pch.h"
#include "loginForm.h"
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
//app类
Application app(hInstance);
app.EnableHighDpi();//启用高DPI
//创建登录创建
loginForm loginFrm;
loginFrm.Show();
return app.Exec();//进行消息循环
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

View File

@@ -1,7 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 DemoUi.rc 使用
//
#define IDI_SMALL 101
#define IDD_INPUT 102
#define IDC_EDIT1 1000

View File

@@ -1,24 +0,0 @@
#pragma once
#include "resource.h"
#include <windows.h>
#include "ezui/Application.h" //app类
#include "EzUI/Window.h" //基础窗口类
#include "EzUI/Button.h" //按钮
#include "EzUI/TextBox.h" //文本框
#include "EzUI/CheckBox.h" //复选框
#include "EzUI/PictureBox.h" //图片控件
#include "EzUI/TabLayout.h" //选项卡控件
#include "EzUI/VLayout.h" //垂直布局
#include "EzUI/HLayout.h"//水平布局
#include "EzUI/VListView.h"//垂直带滚动条列表
#include "EzUI/HListView.h"//水平带滚动条列表
#include "EzUI/TileListView.h"//瓦片列表
#include "EzUI/LayeredWindow.h"//分层窗口类-可以异型透明窗口
#include "ezui/UIManager.h"//ui管理类(使用xml生成控件)
#include "EzUI/Animation.h"
#include "EzUI/TableView.h"

View File

@@ -1,61 +0,0 @@
#include "pch.h"
#include "loginForm.h"
#include "mainForm.h"
void loginForm::OnNotify(Control* sender, EventArgs& args)
{
if (args.EventType == Event::OnMouseDown) {
if (sender->Name == "btnLogin") {
TextBox* editUser = (TextBox*)FindControl("user");
TextBox* editpwd = (TextBox*)FindControl("pwd");
CheckBox* ckbox = (CheckBox*)FindControl("ckbox");
/*if (!ckbox->GetCheck()) {
::MessageBoxW(Hwnd(), L"请阅读协议并勾选!", L"提示", MB_OK);
return;
}*/
UIString user = editUser->GetText();
UIString pwd = editpwd->GetText();
Hide(); // 隐藏登录窗口
static mainForm mainForm;
mainForm.Show(); // 显示主界面
//if (user == "ad" && pwd == "123") {
// ::MessageBoxW(Hwnd(), L"登录成功!", L"提示", MB_OK);
// Hide(); // 隐藏登录窗口
// static mainForm mainForm;
// mainForm.Show(); // 显示主界面
//}
//else {
// ::MessageBoxW(Hwnd(), L"用户名或密码错误!", L"提示", MB_OK);
//}
}
if (sender->Name == "btnExit") {
Application::Exit();
}
// 打开链接
if (!sender->GetAttribute("url").empty()) {
::ShellExecuteA(0, "open", sender->GetAttribute("url").c_str(), "", "", SW_SHOW);
}
}
__super::OnNotify(sender, args);
}
void loginForm::OnClose(bool& close)
{
Application::Exit();
}
loginForm::loginForm() :LayeredWindow(320, 448)
{
umg.LoadXml("res/loginForm.htm");//加载xml里面的控件与样式
umg.SetupUI(this);
// 通过资源ID加载图标 (在 app.rc 中定义 IDI_SMALL=101)
HICON hIco = (HICON)::LoadImageW(GetModuleHandleW(nullptr), MAKEINTRESOURCEW(IDI_SMALL), IMAGE_ICON, 32, 32, 0);
if (hIco) SetIcon(hIco);
}
loginForm::~loginForm()
{
}

View File

@@ -1,23 +0,0 @@
#pragma once
#include "pch.h"
using namespace ezui;
//using Form = LayeredWindow; //支持异形透明窗口(带阴影)
//using Form = BorderlessWindow; //常规无边框窗口(带阴影)
//using Form = Window; //标准窗口(带系统标题栏)
// 登陆窗口
class loginForm :public LayeredWindow
{
private:
//ui管理类
UIManager umg;
protected:
virtual void OnNotify(Control* sender, EventArgs& args)override;//重载事件通知
virtual void OnClose(bool& close)override;//当窗口关闭的时候
public:
loginForm();
virtual ~loginForm();
};

View File

@@ -1,183 +0,0 @@
#include "pch.h"
#include "mainForm.h"
void mainForm::OnNotify(Control* sender, EventArgs& args)
{
UIString btnName = sender->Name; // 控件id
Event eventType = args.EventType; // 事件类型
// 针对管理界面的表格控件
//if (btnName == "tableViewAdmin") {
// switch (eventType)
// {
// case 8: break;
// case Event::OnMouseUp://鼠标抬起
// {
// TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
// }
// break;
// default:
// std::cout << "表格事件:" << (long long)eventType << std::endl;
// break;
// }
//}
switch (eventType)
{
case ezui::OnMouseDown: //鼠标按下
{
if (btnName == "btnExitMain") { //退出
int result = ::MessageBoxW(Hwnd(), L"要退出程序吗?", L"提示", MB_YESNO | MB_ICONQUESTION);
if (result == IDYES)
exit(0);
}
else if (btnName == "btnMinMain") { //最小化
this->ShowMinimized();
}
else if (btnName == "btnMaxMain") { //最大化|还原
if (this->IsMaximized()) {
this->ShowNormal();
// 修改控件文字
Button* btnMax = (Button*)FindControl("btnMaxMain");
btnMax->SetText(L"🗖");
}
else {
this->ShowMaximized();
// 修改控件文字
Button* btnMax = (Button*)FindControl("btnMaxMain");
btnMax->SetText(L"🗗");
}
}
else if (btnName == "btnAdmin") { //到管理页面 获取 mainTab 设置页面为0
TabLayout* mainTab = (TabLayout*)FindControl("mainTab");
mainTab->SetPageIndex(0);
mainTab->Invalidate();
}
else if (btnName == "btnTools") { //到工具页面 获取 mainTab 设置页面为1
TabLayout* mainTab = (TabLayout*)FindControl("mainTab");
mainTab->SetPageIndex(1);
mainTab->Invalidate();
}
else if (btnName == "btnAdminConnect") { //管理页面的连接按钮按下,先获取 btnAdminConnect 按钮,设置为不可用,修改文字为“连接中...”
Button* btnAdminConnect = (Button*)FindControl("btnAdminConnect");
btnAdminConnect->SetText(L"🔄");
btnAdminConnect->Style.BackColor = Color(0, 185, 107);
}
else if (btnName == "btnAdminTemp") { //管理页面的测试按钮
TextBox* textAdmin = (TextBox*)FindControl("textAdminOutput"); //获取输出框
if (textAdmin) {
textAdmin->Insert(L"\n测试成功!",true);
textAdmin->GetScrollBar()->ScrollTo(1.0);
}
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
if (tableView){
int rowCount = tableView->GetRowCount(); //总行数
// 表格增加一行数据
tableView->InsertRow(rowCount);
tableView->SetRowData(rowCount, { L"uid" + std::to_wstring(rowCount), L"192.168.200.131\n127.0.0" , L"", L"2026-02-25"});
tableView->SetCellChecked(rowCount, 5, true);
tableView->SetCellComboIndex(rowCount, 2, 0);
// 改变单元格颜色
/*CellStyle style = tableView->GetCellStyle(1, 1);
style.SetBackColor(Color(200, 230, 155));
tableView->SetCellStyle(1, 1, style);*/
}
}
}
break;
case ezui::OnMouseDoubleClick: //鼠标双击
{
//if (btnName == "titleMain") { //标题布局
// if (this->IsMaximized()) {
// this->ShowNormal();
// }
// else {
// this->ShowMaximized();
// }
//}
}
break;
default:
break;
}
__super::OnNotify(sender, args);
}
void mainForm::OnClose(bool& close)
{
Application::Exit();
}
void mainForm::OnMouseUp(ezui::MouseButton mbtn, const ezui::Point& point)
{
if (mbtn == ezui::MouseButton::Right) {
// 右键弹起处理(可实现右键单击)
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
if (tableView) {
//表格
int pRow = tableView->GetHoverRow(); //当前行号
int pCol = tableView->GetHoverCol(); //当前列号
if (pRow < 0 || pCol < 0) return; // 说明不在表格区域内
UIString celContent = tableView->GetData(pRow, pCol);
//std::cout << "单元格内容: " << celContent.ansi() << std::endl;
std::cout << "行列号为 (" << pRow << ", " << pCol << ") 当前列宽: " << tableView->GetColumnWidth(pCol) << std::endl;
}
}
ezui::Window::OnMouseUp(mbtn, point);
}
// UI初始化
mainForm::mainForm() :LayeredWindow(1500, 750)
{
SetResizable(true); // 启用窗口大小调整
SetMiniSize(Size(600, 450)); // 设置最小尺寸
umg.LoadXml("res/mainForm.htm");//加载xml里面的控件与样式
umg.SetupUI(this);
// 通过资源ID加载图标 (在 app.rc 中定义 IDI_SMALL=101)
HICON hIco = (HICON)::LoadImageW(GetModuleHandleW(nullptr), MAKEINTRESOURCEW(IDI_SMALL), IMAGE_ICON, 32, 32, 0);
if (hIco) SetIcon(hIco);
// 如果是debug模式则创建控制台窗口用于输出调试信息
#ifdef _DEBUG
AllocConsole();
FILE* fp = nullptr;
freopen_s(&fp, "CONOUT$", "w", stdout);
freopen_s(&fp, "CONOUT$", "w", stderr);
std::cout << "调试模式控制台已启动!" << std::endl;
#endif
// 初始化设置表格各项属性
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
if (tableView) {
tableView->SelectedRowBackColor = Color(200, 230, 255); // 设置选中行背景色
//tableView->SetColumnType(5, ezui::CellType::CheckBox);
tableView->SetColumnType(2, ezui::CellType::ComboBox); //设置第3列为下拉列表类型
tableView->SetColumnComboItems(2, { L"默认", L"禁止" , L"验机" }); //设置第3列下拉列表内容
tableView->SetDefaultTextAlign(Align::MiddleCenter); //设置默认对齐方式
//设置列宽
std::vector<int> withs = {60, 130, 55, 95, 85, 85, 105, 70, 75, 80, 80, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95 };
for(int i = 0; i < withs.size(); i++)
tableView->SetColumnWidth(i, withs[i]);
// 单元格编辑完成(编辑结束时触发,提供旧值与新值)
tableView->CellEditFinished = [](int row, int col, const UIString& oldValue, const UIString& newValue) {
//std::cout << "完成编辑单元格内容: " << newValue.ansi() << ", " << oldValue.ansi() << std::endl;
};
}
}
mainForm::~mainForm()
{
}

View File

@@ -1,23 +0,0 @@
#pragma once
#include "pch.h"
using namespace ezui;
// 主窗口
class mainForm :public LayeredWindow
{
private:
protected:
virtual void OnNotify(Control* sender, EventArgs& args)override;//重载事件通知
virtual void OnClose(bool& close)override;//当窗口关闭的时候
virtual void OnMouseUp(ezui::MouseButton mbtn, const ezui::Point& point) override; // 鼠标抬起
public:
//ui管理类
UIManager umg;
mainForm();
virtual ~mainForm();
};

View File

@@ -1 +0,0 @@
#include "pch.h"

View File

@@ -1,2 +0,0 @@
#pragma once
#include "framework.h"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

View File

@@ -1,29 +0,0 @@
#pragma once
#include "EzUI.h"
#include "Timer.h"
namespace ezui {
class UI_EXPORT Animation : public Object {
private:
Timer *m_timer;
float m_startValue = 0;
float m_endValue = 0;
float m_currValue = 0;
float m_speedPerMs = 0;
std::chrono::steady_clock::time_point m_lastTime;
public:
//当值更改的时候发生的事件(请绑定此函数进行回调,请自行线程同步)
std::function<void(float)> ValueChanged;
Animation(Object* parentObject = NULL);
virtual ~Animation();
void SetStartValue(float value);
void SetEndValue(float value);
//开始动画
void Start(int durationMs, int fps = 90);
//动画是否已经停止
bool IsStopped();
void Stop();
};
};

View File

@@ -1,24 +0,0 @@
#pragma once
#include "Window.h"
#include "Resource.h"
namespace ezui {
class UI_EXPORT Application
{
public:
//退出消息循环
static void Exit(int exitCode = 0);
//获取程序启动路径
static UIString StartPath();
public:
Application(HINSTANCE hInstance = NULL);
//使用本地文件名称或者资源中的名称加载资源包
//填入vs中的资源ID名称 或者 本地文件名 一个Application只允许有一个资源文件
bool SetResource(const UIString& localOrResName);
//启用高DPI适配
void EnableHighDpi();
virtual ~Application();
//执行消息循环
int Exec();
};
};

View File

@@ -1,34 +0,0 @@
#pragma once
#include "EzUI.h"
namespace ezui {
//BGRA 32位图
class UI_EXPORT Bitmap {
private:
int m_width = 0;
int m_height = 0;
HBITMAP m_bmp = NULL;
HDC m_hdc = NULL;
byte* m_point = NULL;
BITMAPINFO m_bmpInfo;
Bitmap(const Bitmap& hBitmap) = delete;
void operator=(const Bitmap& hBitmap) = delete;
protected:
void Create(int width, int height);
public:
int Width()const;
int Height()const;
//BGRA 32位图
Bitmap(int width, int height);
Bitmap(HDC dc, const Rect& rect);
void SetPixel(int x, int y, const Color& color);
Color GetPixel(int x, int y)const;
byte* GetPixel();
void Earse(const Rect& rect);//抹除矩形内容
HBITMAP GetHBITMAP();
HDC GetDC();
bool Save(const UIString& fileName);
Bitmap* Clone()const;
virtual ~Bitmap();
};
};

View File

@@ -1,38 +0,0 @@
#pragma once
#include "Window.h"
#include "ShadowBox.h"
namespace ezui {
/// <summary>
/// BorderlessWindow //无边框 带阴影
/// </summary>
class UI_EXPORT BorderlessWindow :public Window {
private:
int m_shadowWeight = 20;
ShadowBox* m_shadowBox = NULL;
float m_shadowScale = 1.0f;
//是否支持缩放
bool m_bResize = false;
protected:
virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)override;
virtual void OnMove(const Point& location) override;
virtual void OnSize(const Size& sz) override;
virtual void OnDpiChange(float systemScale, const Rect& newRect);//当dpi发生更改时
virtual HWND GetShadowHwnd()override;//获取阴影窗口句柄
public:
//设置阴影宽度
void SetShadow(int weight);
BorderlessWindow(int width, int height, HWND owner = NULL, DWORD dwStyle = NULL, DWORD dwExStyle = NULL);
virtual ~BorderlessWindow();
//更新窗口阴影
void UpdateShadowBox();
//获取阴影窗口
ShadowBox* GetShadowBox();
//关闭窗口阴影 关掉阴影窗口 已有的边框也会随之消失
void CloseShadowBox();
//设置窗口缩放支持
void SetResizable(bool resize);
//是否支持调整大小
bool IsResizable();
};
};

View File

@@ -1,14 +0,0 @@
#pragma once
#include "Label.h"
namespace ezui {
class UI_EXPORT Button :
public Label
{
private:
void Init();
public:
Button(Object* parentObject = NULL);
virtual ~Button();
};
};

View File

@@ -1,33 +0,0 @@
#pragma once
#include "Label.h"
namespace ezui {
class UI_EXPORT CheckBox :
public Label
{
private:
bool m_checked = false;
public:
//选中样式
ControlStyle CheckedStyle;
//选中状态发送变化的回调函数
std::function<void(CheckBox* sender, bool checked)> CheckedChanged = NULL;
protected:
virtual ControlStyle& GetStyle(const ControlState& _state)override;
virtual void OnMouseDown(const MouseEventArgs& arg)override;
virtual void OnDpiChange(const DpiChangeEventArgs& args)override;
virtual void OnMouseEnter(const MouseEventArgs& args)override;
virtual void OnMouseUp(const MouseEventArgs& args)override;
virtual void OnMouseLeave(const MouseEventArgs& args)override;
public:
CheckBox(Object* parentObject = NULL);
virtual void SetAttribute(const UIString& key, const UIString& value)override;
//设置选中状态
virtual void SetCheck(bool checked);
//获取选中状态
virtual bool GetCheck();
virtual ~CheckBox();
};
};

View File

@@ -1,54 +0,0 @@
#pragma once
#include "TextBox.h"
#include "Label.h"
#include "VListView.h"
#include "PopupWindow.h"
#include "HLayout.h"
namespace ezui {
//简易的下拉列表框
class UI_EXPORT ComboBox :public HLayout {
private:
//添加选项请使用AddItem
virtual Control* Add(Control* childCtl)override;
//移除选项请使用RemoveItem
virtual void Remove(Control* childCtl, bool freeCtrl)override;
private:
//下拉菜单选项
class MenuContent :public PopupWindow {
public:
Control* m_hittestCtl;
MenuContent(Control* ownerCtl, Control* hittestCtl);
virtual void OnKillFocus(HWND wnd) override;
virtual ~MenuContent();
};
private:
//下拉菜单窗口
MenuContent* m_menuWnd = NULL;
//选择之后显示的文本框
TextBox m_textBox;
//展开菜单的按钮
Label m_UpDown;
VListView m_list;
int m_index = -1;
int m_pendingIndex = -1; // 延迟设置的索引用于XML属性解析
void Init();
protected:
virtual void OnLayout()override;
public:
ComboBox(Object* parentObject = NULL);
//获取选中的文字
UIString GetText();
//获取选中的下标
int GetCheck();
//选中某个下标
bool SetCheck(int pos);
virtual ~ComboBox();
//添加一个item并返回新item的下标
int AddItem(const UIString& text);
void RemoveItem(int index);
//设置属性
virtual void SetAttribute(const UIString& key, const UIString& value)override;
};
};

View File

@@ -1,527 +0,0 @@
#pragma once
#include "EzUI.h"
namespace ezui {
class UI_EXPORT Control :public Object
{
private:
//顶层窗口句柄
HWND m_hWnd = NULL;
// 控件是否已经被移除或释放
bool* m_bRemove = NULL;
//控件是否被为按住状态
bool m_pressed = false;
// 控件是否启用,禁止状态下鼠标键盘消息将不可用
bool m_enabled = true;
// 控件是否可见。此标志为 true 时,控件为显示状态
bool m_bVisible = true;
// 当前控件的 DPI 缩放比例
float m_scale = 1.0f;
// 子控件集合
Controls m_controls;
// 管理图片的释放
PtrManager<Image*> m_imgs;
// 布局状态
// AddControl、InsertControl、RemoveControl、OnSize 时此标志为挂起状态
// 调用 ResumeLayout 标志为布局中
// 调用 OnLayout() 之后标志为 None
ezui::LayoutState m_layoutState = ezui::LayoutState::None;
// 鼠标悬浮提示文字
UIString m_tipsText;
// 上一次位置
Point m_lastLocation;
// 上一次大小
Size m_lastSize;
// 是否根据内容自动宽度
bool m_bAutoWidth = false;
// 根据内容自动高度变化
bool m_bAutoHeight = false;
// 控件内容宽高
Size m_contentSize;
// 绝对尺寸
Size m_fixedSize;
//比例尺寸(优先级最高)
SizeF m_rateSize;
// 控件矩形区域(基于父控件)
Rect m_rect;
// 控件在窗口中的可见区域
Rect m_viewRect;
// dock 样式
DockStyle m_dock = DockStyle::None;
// 控件是否可以被命中(值为false情况下就是穿透效果)
bool m_hitTestEnabled = true;
protected:
// 基于控件中的可见控件集合
Controls ViewControls;
// 控件当前状态
ControlState State = ControlState::Static;
public:
// 外边距
// 让容器独占一行或一列时,设置边距会使控件变小,不可设置为负数
Distance Margin;
// 控件的 ObjectName ID
UIString Name;
// 控件行为
ControlAction Action = ControlAction::None;
// 静态默认样式
ControlStyle Style;
//禁用状态样式
ControlStyle DisabledStyle;
// 鼠标悬浮样式
ControlStyle HoverStyle;
// 鼠标按下样式
ControlStyle ActiveStyle;
// 父控件指针
Control* Parent = NULL;
//是否添加到所在窗口/IFrame中的OnNotify函数中
Event NotifyFlags = Event::OnMouseEvent | Event::OnKeyBoardEvent;
// 事件处理器
std::function<void(Control*, EventArgs&)> EventHandler = NULL;
private:
// 禁止拷贝构造
Control(const Control&) = delete;
// 禁止赋值
Control& operator=(const Control&) = delete;
// 计算基于父控件的裁剪区域
void ComputeClipRect();
// 所有事件优先进入此函数(内部处理)
void OnEvent(EventArgs& arg);
protected:
//属性或者css样式都适用(css样式和属性都可以设置这些,只对静态样式生效)
virtual bool ApplyStyleProperty(const UIString& key, const UIString& value);
// 设置内容宽度,仅限子类使用
virtual void SetContentWidth(int width);
// 设置内容高度,仅限子类使用
virtual void SetContentHeight(int height);
// 设置内容尺寸,仅限子类使用
virtual void SetContentSize(const Size& size);
// 绘制之前
virtual void OnPaintBefore(PaintEventArgs& args);
// 控件绘制
virtual void OnPaint(PaintEventArgs& args);
// 子控件绘制,可重载此函数优化鼠标操作性能
virtual void OnChildPaint(PaintEventArgs& args);
// 背景绘制
virtual void OnBackgroundPaint(PaintEventArgs& painter);
// 前景绘制
virtual void OnForePaint(PaintEventArgs& e);
// 边框绘制
virtual void OnBorderPaint(PaintEventArgs& painter, const Border& border);
// 坐标发生改变
virtual void OnMove(const MoveEventArgs& arg);
// 大小发生改变
virtual void OnSize(const SizeEventArgs& arg);
// DPI 发生改变
virtual void OnDpiChange(const DpiChangeEventArgs& arg);
// 控件布局逻辑,需重写布局请重写此函数
virtual void OnLayout();
// 鼠标在控件上移动
virtual void OnMouseMove(const MouseEventArgs& arg);
// 鼠标离开控件
virtual void OnMouseLeave(const MouseEventArgs& args);
// 鼠标滚轮事件
virtual void OnMouseWheel(const MouseEventArgs& arg);
// 鼠标按下事件
virtual void OnMouseDown(const MouseEventArgs& arg);
// 鼠标弹起事件
virtual void OnMouseUp(const MouseEventArgs& arg);
// 鼠标双击事件
virtual void OnMouseDoubleClick(const MouseEventArgs& arg);
// 鼠标移入控件
virtual void OnMouseEnter(const MouseEventArgs& arg);
// 鼠标事件统一入口
virtual void OnMouseEvent(const MouseEventArgs& args);
// 键盘事件统一入口
virtual void OnKeyBoardEvent(const KeyboardEventArgs& _args);
// 字符输入事件WM_CHAR
virtual void OnKeyChar(const KeyboardEventArgs& _args);
// 键盘按下事件WM_KEYDOWN
virtual void OnKeyDown(const KeyboardEventArgs& _args);
// 键盘弹起事件WM_KEYUP
virtual void OnKeyUp(const KeyboardEventArgs& _args);
// 获得焦点事件
virtual void OnFocus(const FocusEventArgs& _args);
// 失去焦点事件
virtual void OnKillFocus(const KillFocusEventArgs& _args);
// 被移除时执行的逻辑
virtual void OnRemove();
public:
// 获取当前控件状态下的样式信息
virtual ControlStyle& GetStyle(const ControlState& _state);
// 获取左上圆角半径
int GetBorderTopLeftRadius(ControlState _state = ControlState::None);
// 获取右上圆角半径
int GetBorderTopRightRadius(ControlState _state = ControlState::None);
// 获取右下圆角半径
int GetBorderBottomRightRadius(ControlState _state = ControlState::None);
// 获取左下圆角半径
int GetBorderBottomLeftRadius(ControlState _state = ControlState::None);
// 获取左边框宽度
int GetBorderLeft(ControlState _state = ControlState::None);
// 获取上边框宽度
int GetBorderTop(ControlState _state = ControlState::None);
// 获取右边框宽度
int GetBorderRight(ControlState _state = ControlState::None);
// 获取下边框宽度
int GetBorderBottom(ControlState _state = ControlState::None);
// 获取边框颜色
Color GetBorderColor(ControlState _state = ControlState::None);
//获取边框样式
StrokeStyle GetBorderStyle(ControlState _state = ControlState::None);
// 获取前景图片
Image* GetForeImage(ControlState _state = ControlState::None);
// 获取背景图片
Image* GetBackImage(ControlState _state = ControlState::None);
// 获取背景颜色
Color GetBackColor(ControlState _state = ControlState::None);
// 获取旋转角度
float GetAngle(ControlState _state = ControlState::None);
//获取当前控件的鼠标光标
virtual HCURSOR GetCursor(ControlState _state = ControlState::None);
// 获取前景颜色
Color GetForeColor(ControlState _state = ControlState::None);
// 获取字体 Family
std::wstring GetFontFamily(ControlState _state = ControlState::None);
// 获取字体大小
int GetFontSize(ControlState _state = ControlState::None);
//获取公共数据
WindowData* GetPublicData();
//获取上层Frame容器
IFrame* GetFrame();
public:
// 构造函数 可传入父对象(由父对象自动管理内存)
Control(Object* parentObject = NULL);
// 析构函数
virtual ~Control();
//绑定对象(跟随释放)
using Object::Attach;
//分离对象(解除跟随释放)
using Object::Detach;
//绑定图片(跟随释放)
Image* Attach(Image* img);
//分离图片(解除跟随释放)
void Detach(Image* img);
//窗口句柄
HWND Hwnd();
//设置窗口句柄
void SetHwnd(HWND hWnd);
// 以下函数请保证在父控件布局已完成的情况下使用,使用 ResumeLayout() 执行布局
// 获取 X 坐标
int X();
// 获取 Y 坐标
int Y();
// 获取宽度
int Width();
// 获取高度
int Height();
// 设置 X 坐标
void SetX(int X);
// 设置 Y 坐标
void SetY(int Y);
// 移动相对于父控件的位置
void SetLocation(const Point& pt);
// 设置控件大小(当重绘控件时不建议多次使用,影响性能,会调用 SetRect 函数)
void SetSize(const Size& size);
// 设置绝对宽高
void SetFixedSize(const Size& size);
// 设置宽度(当重绘控件时不建议多次使用,影响性能,会调用 SetRect 函数)
void SetWidth(int width);
// 设置高度(当重绘控件时不建议多次使用,影响性能,会调用 SetRect 函数)
void SetHeight(int height);
// 设置绝对宽度
void SetFixedWidth(int fixedWidth);
// 设置绝对高度
void SetFixedHeight(int fixedHeight);
//设置宽度比例(优先级最高)
void SetRateWidth(float rateWidth);
//设置高度比例(优先级最高)
void SetRateHeight(float rateHeight);
// 设置相对父控件矩形,返回实际的 rect
const Rect& SetRect(const Rect& rect);
// 获取绝对宽度
int GetFixedWidth();
// 获取绝对高度
int GetFixedHeight();
// 获取光标位置
virtual Rect GetCareRect();
// 是否自动宽度
virtual bool IsAutoWidth();
// 是否自动高度
virtual bool IsAutoHeight();
// 设置自动宽度
virtual void SetAutoWidth(bool flag);
// 设置自动高度
virtual void SetAutoHeight(bool flag);
// 设置自动大小
virtual void SetAutoSize(bool flag);
// 获取控件内容大小
virtual const Size& GetContentSize();
// 获取控件大小
Size GetSize();
// 获取控件位置
Point GetLocation();
// 获取相对于父控件的矩形(布局计算后)
virtual const Rect& GetRect();
// 获取基于客户端区域的矩形
Rect GetClientRect();
//获取控件基于屏幕的矩形位置
Rect GetScreenRect();
// 获取控件的 DockStyle停靠方式
DockStyle GetDockStyle();
// 设置控件的 DockStyle
void SetDockStyle(const DockStyle& dockStyle);
// 获取控件的缩放系数
float GetScale();
// 是否存在挂起的布局
bool IsPendLayout();
// 尝试挂起布局,返回当前布局状态
const LayoutState TryPendLayout();
// 获取当前布局状态
const LayoutState GetLayoutState();
// 结束当前布局(使其立即生效)
void EndLayout();
// 立即强制刷新布局
virtual void RefreshLayout();
// 设置提示文字(类似 tooltip
void SetTips(const UIString& text);
// 获取提示文字
const UIString& GetTips();
// 获取控件的滚动条对象
virtual ScrollBar* GetScrollBar();
// 派发事件(如鼠标单击事件等...返回true则事件成功派发 返回false代表派发途中当前控件已被释放
void SendEvent(const EventArgs& arg);
// 设置控件属性
virtual void SetAttribute(const UIString& attrName, const UIString& attrValue);
// 获取当前可见的子控件集合
const Controls& GetViewControls();
// 获取所有子控件(不建议直接修改)
const Controls& GetControls();
// 使用下标获取控件,自动跳过 spacer 类控件
Control* GetControl(int pos);
// 是否包含指定控件(递归遍历所有子控件)
bool Contains(Control* ctl);
// 获取指定子控件的索引
int IndexOf(Control* childCtl);
// 根据 name 查找控件(包括自身)
Control* FindControl(const UIString& ctlName);
// 根据属性查找所有匹配控件(包括自身)
Controls FindControl(const UIString& attrName, const UIString& attrValue);
// 根据属性查找第一个匹配控件(包括自身)
Control* FindSingleControl(const UIString& attrName, const UIString& attrValue);
// 根据 name 查找子控件(仅限直接子集)
Control* FindChild(const UIString& ctlName);
// 根据属性查找所有匹配的子控件(仅限直接子集)
Controls FindChild(const UIString& attrName, const UIString& attrValue);
// 根据属性查找第一个匹配的子控件(仅限直接子集)
Control* FindSingleChild(const UIString& attrName, const UIString& attrValue);
// 交换两个子控件的位置
virtual bool SwapChild(Control* childCtl, Control* childCt2);
//是否启用控件
void SetEnabled(bool flag);
//是否禁用控件
void SetDisabled(bool flag);
//控件是否已启用
bool IsEnabled();
// 在指定位置插入子控件
virtual void Insert(int pos, Control* childCtl);
// 添加控件到末尾(如果是弹簧控件,在释放时将自动销毁)
virtual Control* Add(Control* childCtl);
// 移除控件freeCtrl 标志是否释放控件内存
virtual void Remove(Control* childCtl, bool freeCtrl = false);
// 设置控件的父控件
virtual void SetParent(Control* parentCtl);
// 清空所有子控件
virtual void Clear();
// 清空所有子控件freeChilds 决定是否释放子控件内存
virtual void Clear(bool freeChilds);
// 设置控件可见性
virtual void SetVisible(bool flag);
// 获取控件可见性状态
virtual bool IsVisible();
//设置控件是否可以被鼠标命中(false则是鼠标穿透效果)
void SetHitTestVisible(bool bEnable);
//控件是否可以被命中
bool IsHitTestVisible();
//隐藏控件
void Hide();
//显示控件
void Show();
// 标记控件区域为无效将会延迟刷新UI
virtual bool Invalidate();
// 立即强制刷新控件区域并更新无效区域(且立即触发布局)
virtual void Refresh();
//传入Style的引用 处理key value
virtual void SetStyle(ControlStyle& style, const UIString& key, const UIString& value);
//传入状态并分析样式字符串
virtual void SetStyleSheet(ControlState state, const UIString& styleStr);
//控件是否被按住
bool IsPressed();
};
};

View File

@@ -1,268 +0,0 @@
#pragma once
#include "UIDef.h"
#if USED_DIRECT2D
#ifndef UI_EXPORT
#define UI_EXPORT
#endif
#include <d2d1.h>
#include <d2d1helper.h>
#include <dwrite.h>
#include <wincodec.h>
#include "RenderTypes.h"
namespace ezui {
UI_EXPORT void RenderInitialize();//全局初始化direct2d
UI_EXPORT void RenderUnInitialize();//释放direct2d
UI_EXPORT float GetMaxRadius(float width, float height, float _radius);//获取最大半径 用于自动适应border-radius属性
class UI_EXPORT Font {
private:
Font() = delete;
std::wstring m_fontFamily;
float m_fontSize = 0;
IDWriteTextFormat* m_value = NULL;
bool m_ref = false;
void Copy(const Font& _copy);
public:
Font(const Font& _copy);
Font(const std::wstring& fontFamily, float fontSize);
float GetFontSize()const;
const std::wstring& GetFontFamily()const;
IDWriteTextFormat* Get() const;
bool operator==(const Font& _right);
virtual ~Font();
};
//文本命中测试数据
class UI_EXPORT HitTestMetrics {
public:
int Length;
int TextPos;//命中的下标
RectF FontBox;//文字的矩形位置
bool IsTrailingHit;//命中位置是否在尾部
public:
Rect GetCare() {
float x = FontBox.X;
if (IsTrailingHit) {
x += FontBox.Width;
}
float y = FontBox.Y;
return Rect((int)x, (int)y, 1, (int)(FontBox.Height + 0.5));
}
int GetFontHeight() {
return int(FontBox.Height + 0.5);
}
};
class UI_EXPORT TextLayout {
private:
TextLayout(const TextLayout& rightValue) = delete;
IDWriteTextLayout* m_textLayout = NULL;
std::wstring m_fontFamily;
DWRITE_TEXT_METRICS m_textMetrics = {};
std::vector<RectF> m_lineRects;
int m_unicodeSize = 0;
float m_fontSize = 0;
public:
void GetMetrics();
TextLayout(const std::wstring& text, const Font& font, const SizeF& maxSize = SizeF{ EZUI_FLOAT_MAX,EZUI_FLOAT_MAX }, TextAlign textAlgin = TextAlign::TopLeft);
Point HitTestPoint(const Point& pt, int* outTextPos, BOOL* outIsTrailingHit, int* fontHeight);
void HitTestPoint(const Point& pt, HitTestMetrics* hitTestMetrics);//根据坐标执行命中测试
Point HitTestTextPosition(int textPos, BOOL isTrailingHit);//根据文字下标执行命中测试
const std::wstring& GetFontFamily();
float GetFontSize();
int Width();
int Height();
//获取文本整体的占用空间
Size GetFontBox();
//获取每行文字的矩形位置
const std::vector<RectF>& GetLineRects();
int GetFontHeight();//获取字体高度
int GetLineCount();//获取一共有多少行
IDWriteTextLayout* Get() const;
void SetTextAlign(TextAlign textAlign);
void SetUnderline(int pos = 0, int count = 0);
virtual ~TextLayout();
};
//几何图形基础类(支持自定义路径)
class UI_EXPORT Geometry {
protected:
ID2D1GeometrySink* m_pSink = NULL;
ID2D1Geometry* m_rgn = NULL;
Geometry(const Geometry& rightCopy) = delete;
public:
Geometry();
virtual ~Geometry();
void AddArc(const PointF& endPoint, float radius);
void AddAcr(const D2D1_ARC_SEGMENT& arc);
void AddLine(const PointF& endPoint);
void BeginFigure(const PointF& startPoint, D2D1_FIGURE_BEGIN figureBegin = D2D1_FIGURE_BEGIN_FILLED);
void CloseFigure(D2D1_FIGURE_END figureEnd = D2D1_FIGURE_END_CLOSED);
ID2D1Geometry* Get()const;
public:
/// <summary>
/// 将两个几何图形通过指定的合并模式Union、Intersect、Xor、Exclude合并到一个输出几何中。
/// </summary>
/// <param name="out">合并结果输出到该 Geometry。</param>
/// <param name="a">参与合并的第一个 Geometry。</param>
/// <param name="b">参与合并的第二个 Geometry。</param>
/// <param name="COMBINE_MODE">几何合并模式,取值如 D2D1_COMBINE_MODE_UNION、INTERSECT、XOR、EXCLUDE。</param>
static void Combine(Geometry& out, const Geometry& a, const Geometry& b, D2D1_COMBINE_MODE COMBINE_MODE);
/// <summary>
/// 合并两个区域,取它们的联合部分(即最大边界区域)。
/// </summary>
static void Union(Geometry& out, const Geometry& a, const Geometry& b) {
Combine(out, a, b, D2D1_COMBINE_MODE::D2D1_COMBINE_MODE_UNION);
}
/// <summary>
/// 获取两个区域的交集部分。
/// </summary>
static void Intersect(Geometry& out, const Geometry& a, const Geometry& b) {
Combine(out, a, b, D2D1_COMBINE_MODE::D2D1_COMBINE_MODE_INTERSECT);
}
/// <summary>
/// 合并两个区域,保留不重叠的部分(异或运算)。
/// </summary>
static void Xor(Geometry& out, const Geometry& a, const Geometry& b) {
Combine(out, a, b, D2D1_COMBINE_MODE::D2D1_COMBINE_MODE_XOR);
}
/// <summary>
/// 从第一个区域中排除第二个区域的部分(差集)。
/// </summary>
static void Exclude(Geometry& out, const Geometry& a, const Geometry& b) {
Combine(out, a, b, D2D1_COMBINE_MODE::D2D1_COMBINE_MODE_EXCLUDE);
}
};
//矩形(已经完成闭合)
class UI_EXPORT RectangleGeometry :public Geometry {
private:
void Create(float x, float y, float width, float height, float _radius);
public:
RectangleGeometry(float x, float y, float width, float height, float _radius = 0);
RectangleGeometry(const RectF& _rect, float radius = 0);
RectangleGeometry(const RectF& _rect, float topLeftRadius, float topRightRadius, float bottomRightRadius, float bottomLeftRadius);
virtual ~RectangleGeometry() {};
};
//扇形(已经完成闭合)
class UI_EXPORT PieGeometry :public Geometry {
public:
PieGeometry(const RectF& rectF, float startAngle, float endAngle);
virtual ~PieGeometry() {};
};
//圆形/椭圆(已经完成闭合)
class UI_EXPORT EllipseGeometry :public PieGeometry {
public:
EllipseGeometry(const RectF& rectF) :PieGeometry(rectF, 0, 360) {}
virtual ~EllipseGeometry() {};
};
class UI_EXPORT DXImage : public IImage {
struct GifFrame
{
IWICBitmap* wicBitmap; // 存一份完整帧
UINT delay;
};
protected:
std::vector<GifFrame> m_frames;
IWICBitmapDecoder* m_bitmapdecoder = NULL;
IWICBitmapFrameDecode* m_pframe = NULL;
IWICFormatConverter* m_fmtcovter = NULL;//从文件加载
IWICBitmap* m_bitMap = NULL;//从HBITMAP中加载
int m_width = 0;
int m_height = 0;
ID2D1Bitmap* m_d2dBitmap = NULL;
private:
void CreateFormStream(IStream* istram);
void CreateFromFile(const std::wstring& file);
void Init();
public:
bool Visible = true;
void DecodeOfRender(ID2D1RenderTarget* render);
//如果HBITMAP带有透明通道 确保传入的图像颜色值已经与 Alpha 通道预乘
DXImage(HBITMAP hBitmap);
DXImage(IStream* istram);
DXImage(const std::wstring& file);
//创建带预乘Alpha的BGRA图片
DXImage(int width, int height);
DXImage(const void* data, size_t count);
ID2D1Bitmap* Get();
IWICBitmap* GetIWICBitmap();
int Width();
int Height();
virtual WORD NextFrame()override;
DXImage* Clone();
virtual ~DXImage();
};
class Bezier {
public:
Point point1;
Point point2;
Point point3;
};
};
namespace ezui {
class UI_EXPORT DXRender {
private:
ID2D1DCRenderTarget* m_render = NULL;
ID2D1SolidColorBrush* m_brush = NULL;
Font* m_font = NULL;
ID2D1StrokeStyle* m_pStrokeStyle = NULL;
Point m_offset;
PointF m_rotatePoint;
float m_angle = 0;
private:
DXRender(const DXRender& rightValue) = delete;
public:
ID2D1SolidColorBrush* GetBrush();
ID2D1StrokeStyle* GetStrokeStyle();
public:
DXRender(DXImage* dxImage);
DXRender(HDC dc, int x, int y, int width, int height);//创建dx绘图对象
virtual ~DXRender();
void SetFont(const std::wstring& fontFamily, float fontSize);//必须先调用
void SetFont(const Font& _copy_font);//必须先调用
void SetColor(const __EzUI__Color& color);//会之前必须调用
void SetStrokeStyle(StrokeStyle strokeStyle = StrokeStyle::Solid);//设置样式 虚线/实线
void DrawTextLayout(const TextLayout& textLayout, const PointF & = { 0,0 });//根据已有的布局绘制文字
void DrawString(const std::wstring& text, const RectF& _rect, ezui::TextAlign textAlign);//绘制文字
void DrawLine(const PointF& _A, const PointF& _B, float width = 1);//绘制一条线
void DrawRectangle(const RectF& _rect, float _radius = 0, float width = 1);//绘制矩形
void FillRectangle(const RectF& _rect, float _radius = 0);
//填充矩形
void PushLayer(const Geometry& dxGeometry);
void PopLayer();
void PushAxisAlignedClip(const RectF& rectBounds);
void PopAxisAlignedClip();
void SetTransform(float offsetX, float offsetY);//对画布进行旋转和偏移
void SetTransform(float startX, float startY, float angle);//设置旋转起始点与旋转角度
void SetTransform(float offsetX, float offsetY, float startX, float startY, float angle);
void DrawImage(DXImage* _image, const RectF& tagRect, float opacity = 1);//绘制图像
void DrawBezier(const PointF& startPoint, const Bezier& points, float width = 1);//贝塞尔线
void DrawBezier(const PointF& startPoint, std::list<Bezier>& points, float width = 1);//贝塞尔线
void DrawEllipse(const RectF& rectF, float width = 1);
void FillEllipse(const RectF& rectF);
void DrawPie(const RectF& rectF, float startAngle, float endAngle, float strokeWidth = 1);
void FillPie(const RectF& rectF, float startAngle, float endAngle);
void DrawPoint(const PointF& pt);
void DrawArc(const RectF& rect, float startAngle, float sweepAngle, float width = 1);//未实现
void DrawArc(const PointF& point1, const PointF& point2, const PointF& point3, float width = 1);
void DrawGeometry(ID2D1Geometry* path, float width = 1);
void FillGeometry(ID2D1Geometry* path);
void DrawGeometry(Geometry* path, float width = 1);
void FillGeometry(Geometry* path);
void Flush();
ID2D1DCRenderTarget* Get();//获取原生DX对象
};
};
#endif

View File

@@ -1,530 +0,0 @@
/*/
Author:yang
Email:19980103ly@gmail.com/718987717@qq.com
*/
#pragma once
#include "UIDef.h"
#include "UIString.h"
#include "Resource.h"
#include "RenderTypes.h"
#include "Direct2DRender.h"
#undef LoadCursor
#undef LoadIcon
namespace ezui {
struct MonitorInfo;
class Object;
class EventArgs;
class ControlStyle;
class IFrame;
class Control;
class Window;
class Spacer;
class ScrollBar;
class Bitmap;
enum class Cursor :ULONG_PTR;
#if 1
typedef std::vector<Control*> Controls;
#else
class UI_EXPORT Controls :public std::list<Control*> {
public:
//不要频繁使用此函数
inline Control* operator[](size_t right_pos)const
{
size_t pos = 0;
for (auto& it : *this) {
if (pos == right_pos) {
return it;
}
++pos;
}
return NULL;
}
};
#endif
//全局资源句柄
extern UI_VAR_EXPORT HMODULE __EzUI__HINSTANCE;//全局实例
extern UI_VAR_EXPORT Resource* __EzUI__Resource;//文件中的全局资源句柄
extern UI_VAR_EXPORT DWORD __EzUI__ThreadId;//UI的线程Id
extern UI_VAR_EXPORT HWND __EzUI_MessageWnd;//用于UI通讯的隐形窗口
extern UI_VAR_EXPORT const std::list<ezui::MonitorInfo> __EzUI__MonitorInfos;//所有监视器信息
//判断两个float是相等(两数是否接近)
extern UI_EXPORT bool IsFloatEqual(float num1, float num2);
//加载HICON
extern UI_EXPORT HICON LoadIcon(const UIString& fileName);
//装载字体
extern UI_EXPORT void InstallFont(const UIString& fontFileName);
//卸载字体
extern UI_EXPORT void UnstallFont(const UIString& fontFileName);
//复制内容到剪切板
extern UI_EXPORT bool CopyToClipboard(int uFormat, void* pData, size_t size, HWND hWnd = NULL);
//打开剪切板
extern UI_EXPORT bool GetClipboardData(int uFormat, std::function<void(void*, size_t)> Callback, HWND hWnd = NULL);
//复制unicode文字
extern UI_EXPORT bool CopyToClipboard(const std::wstring& str, HWND hWnd = NULL);
//粘贴unicode文字
extern UI_EXPORT bool GetClipboardData(std::wstring* outStr, HWND hWnd = NULL);
//自动获取文件资源(本地文件/资源文件)
extern UI_EXPORT bool GetResource(const UIString& fileName, std::string* outData);
//获取当前所有监视器的信息
extern UI_EXPORT size_t GetMonitor(std::list<MonitorInfo>* outMonitorInfo);
//获取用户当前所在的显示器
extern UI_EXPORT void GetMontior(MonitorInfo* outInfo, HWND hWnd = NULL);
//使用窗口的矩形位置获取所在的显示器
extern UI_EXPORT void GetMontior(MonitorInfo* outInfo, const Rect& rect);
//加载光标
extern UI_EXPORT HCURSOR LoadCursor(Cursor cursorType);
//加载光标(//需要释放)
extern UI_EXPORT HCURSOR LoadCursor(const UIString& fileName);
//释放光标
extern UI_EXPORT void FreeCursor(HCURSOR hCursor);
//默认处理OnNotify函数(处理一些控件的基础行为)
extern UI_EXPORT void DefaultNotify(Control* sender, EventArgs& args);
class UI_EXPORT Color :public ezui::__EzUI__Color {
public:
Color(const ezui::__EzUI__Color& copy) { this->BGRA = copy.GetValue(); }
Color(const DWORD& rgba = 0) :ezui::__EzUI__Color(rgba) {}
Color(BYTE r, BYTE g, BYTE b, BYTE a = 255) :ezui::__EzUI__Color(r, g, b, a) {}
public:
//构建一个Color
static Color Make(const UIString& colorStr, bool* isGood = NULL);
virtual ~Color() {}
};
#if USED_DIRECT2D
class UI_EXPORT Image :public DXImage {
private:
#ifdef _DEBUG
UIString m_path;
#endif
public:
virtual ~Image() {}
//创建带预乘Alpha的BGRA图片
Image(int width, int height) :DXImage(width, height) {}
Image(HBITMAP hBitmap) :DXImage(hBitmap) {}
Image(Bitmap* bitmap);
Image(IStream* iStream) :DXImage(iStream) {}
Image(const std::wstring& fileName) :DXImage(fileName) {}
Image(const void* data, size_t dataCount) :DXImage(data, dataCount) {}
public:
//从资源或者本地文件自动构建一个Image
static Image* Make(const UIString& fileOrRes);
};
#endif
// 定义用于保存显示器信息的结构体
struct MonitorInfo {
HMONITOR Monitor = NULL;
//显示器的位置 多显示器下Y轴可能出现负数或者大于0的时候代表显示器在设置里面显示器是错位的(多显示器没有平行);
//逻辑宽高
ezui::Rect Rect;
//工作区域
ezui::Rect WorkRect;
//显示器物理宽高
Size Physical;
//显示器缩放比例 1.0 1.25 1.5 1.75 2.0
float Scale = 1.0f;
//显示器帧率
float FPS = 60;
//是否为主显示器
bool Primary = false;
};
struct WindowData {
//缩放率
float Scale = 1.0f;
//单次绘图数量
int PaintCount = 0;
#ifdef _DEBUG
//是否开启debug模式
bool Debug = false;
//调试模式下的特有字段
int ColorIndex = 0;
Color DebugColor;
std::vector<Color> DebugColors{ Color::Red,Color::Green,Color::Blue,Color::Black,Color::White };
#endif
//主窗类的实例
ezui::Window* Window = NULL;
//使一个区域无效
std::function<void(const Rect&)> InvalidateRect = NULL;
//立即更新全部无效区域
std::function<void()> Refresh = NULL;
//清空控件标记等等...
std::function<void(Control*)> CleanControl = NULL;
//内部移动窗口的函数
std::function<void()> MoveWindow = NULL;
//内部使用标题部分移动窗口的函数
std::function<void()> TitleMoveWindow = NULL;
//处理消息过程的回调函数
std::function<LRESULT(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)> WndProc = NULL;
#ifdef _DEBUG
virtual ~WindowData() {
}
#endif
};
enum class LayoutState {
//无状态 (无需布局)
None,
//挂起中
Pend,
//布局中
Layouting
};
enum Event :long long {
None = 1,
OnMouseWheel = 2,
OnMouseEnter = 4,
OnMouseMove = 8,
OnMouseLeave = 16,
OnMouseDoubleClick = 32,
OnMouseDown = 64,
OnMouseUp = 128,
OnKeyDown = 256,
OnKeyUp = 512,
OnPaint = 1024,
OnFocus = 2048,
OnKillFocus = 4096,
OnKeyChar = 8192,
OnMove = 16384,
OnSize = 32768,
OnRect = 65536,
OnDpiChange = 131072,
OnActive = OnMouseDown | OnMouseUp,
OnHover = OnMouseEnter | OnMouseLeave,
OnMouseDrag = OnMouseDown | OnMouseMove,
OnMouseEvent = OnMouseWheel | OnMouseEnter | OnMouseMove | OnMouseLeave | OnMouseDoubleClick | OnMouseDown | OnMouseUp,
OnKeyBoardEvent = OnKeyDown | OnKeyUp | OnKeyChar
};
//重载枚举的 | 运算符
inline Event operator|(Event left, Event right)
{
return static_cast<Event>(static_cast<long long>(left) | static_cast<long long>(right));
}
//控件行为
enum class ControlAction {
None,
Title,//具有移动窗口 双击最大化窗口的行为
MoveWindow,//移动窗口
Mini,//最小化
Max,//最大化|恢复
Close//关闭
};
enum class ControlState :int {
None = 1,//无状态 则是使用_nowStyle缓存样式
Static = 2,//静态
Disabled = 4,//禁用状态
Checked = 8,//选中状态
Hover = 16,//鼠标悬浮
Active = 32//鼠标按住
};
EZUI_ENUM_OPERATORS(ControlState, int);
enum class DockStyle {
// 摘要:
//未设置
None,
// 摘要:
//在父控件中 左右保持
Horizontal,
// 摘要:
//在父控件中 上下保持
Vertical,
// 摘要:
// 铺满整个父控件
Fill
};
enum class MouseButton {
// 摘要:
// 未曾按下鼠标按钮。
None,
//
// 摘要:
// 鼠标左按钮曾按下。
Left,
//
// 摘要:
// 鼠标右按钮曾按下。
Right,
//
// 摘要:
// 鼠标中按钮曾按下。
Middle,
//
// 摘要:
// 第 1 个 XButton 曾按下。
XButton1,
//
// 摘要:
// 第 2 个 XButton 曾按下。
XButton2
};
enum class Cursor :ULONG_PTR
{
None = 0,//未指定
APPSTARTING = (ULONG_PTR)IDC_APPSTARTING,// 标准的箭头和小沙漏
ARROW = (ULONG_PTR)IDC_ARROW,// 标准的箭头
CROSS = (ULONG_PTR)IDC_CROSS,// 十字光标
HAND = (ULONG_PTR)IDC_HAND,// Windows 98/Me, Windows 2000/XP: Hand
HELP = (ULONG_PTR)IDC_HELP,// 标准的箭头和问号
IBEAM = (ULONG_PTR)IDC_IBEAM,// 工字光标
ICON = (ULONG_PTR)IDC_ICON,// Obsolete for applications marked version 4.0 or later.
NO = (ULONG_PTR)IDC_NO,// 禁止圈
SIZE = (ULONG_PTR)IDC_SIZE,// Obsolete for applications marked version 4.0 or later. Use SIZEALL.
SIZEALL = (ULONG_PTR)IDC_SIZEALL,// 四向箭头指向东、西、南、北
SIZENESW = (ULONG_PTR)IDC_SIZENESW,// 双箭头指向东北和西南
SIZENS = (ULONG_PTR)IDC_SIZENS, // 双箭头指向南北
SIZENWSE = (ULONG_PTR)IDC_SIZENWSE,// 双箭头指向西北和东南
SIZEWE = (ULONG_PTR)IDC_SIZEWE,// 双箭头指向东西
UPARROW = (ULONG_PTR)IDC_UPARROW,// 垂直箭头
WAIT = (ULONG_PTR)IDC_WAIT// 沙漏Windows7下会显示为选择的圆圈表示等待
};
//基础事件
class UI_EXPORT EventArgs {
public:
Event EventType = Event::None;
EventArgs(Event eventType) {
this->EventType = eventType;
}
virtual ~EventArgs() {};
};
//为鼠标事件提供基础数据
class UI_EXPORT MouseEventArgs :public EventArgs {
public:
MouseButton Button = MouseButton::None;
int ZDelta = 0;//方向
Point Location;
public:
MouseEventArgs(Event eventType, const Point& location = Point(0, 0), MouseButton mouseButton = MouseButton::None, int ZDelta = 0) :EventArgs(eventType) {
this->Button = mouseButton;
this->Location = location;
this->ZDelta = ZDelta;
}
virtual ~MouseEventArgs() {}
};
// 摘要:
//为键盘事件提供基础数据
class UI_EXPORT KeyboardEventArgs :public EventArgs {
public:
/// <summary>
/// 一般是指 键盘的ascii值
/// </summary>
WPARAM wParam;
LPARAM lParam;
KeyboardEventArgs(Event eventType, WPARAM wParam, LPARAM lParam) :EventArgs(eventType) {
this->wParam = wParam;
this->lParam = lParam;
}
virtual ~KeyboardEventArgs() {}
};
//获取焦点
class UI_EXPORT FocusEventArgs :public EventArgs {
public:
Control* Control;
FocusEventArgs(ezui::Control* ctl) :EventArgs(Event::OnFocus) {
this->Control = ctl;
}
virtual ~FocusEventArgs() {}
};
//失去焦点
class UI_EXPORT KillFocusEventArgs :public EventArgs {
public:
Control* Control;
KillFocusEventArgs(ezui::Control* ctl) :EventArgs(Event::OnKillFocus) {
this->Control = ctl;
}
virtual ~KillFocusEventArgs() {}
};
//坐标发生改变
class UI_EXPORT MoveEventArgs :public EventArgs {
public:
const ezui::Point Location;
MoveEventArgs(const ezui::Point& location) :EventArgs(Event::OnMove), Location(location) {}
virtual ~MoveEventArgs() {}
};
//大小发生改变
class UI_EXPORT SizeEventArgs :public EventArgs {
public:
const ezui::Size Size;
SizeEventArgs(const ezui::Size& size) :EventArgs(Event::OnSize), Size(size) {}
virtual ~SizeEventArgs() {}
};
//dpi发生变化
class UI_EXPORT DpiChangeEventArgs :public EventArgs {
public:
float Scale = 1.0f;
DpiChangeEventArgs(float scale) :EventArgs(Event::OnDpiChange), Scale(scale) {}
virtual ~DpiChangeEventArgs() {}
};
// 为 OnPaint 事件提供数据。
class UI_EXPORT PaintEventArgs :public EventArgs {
private:
std::list<bool> m_layers;
std::list<Point> m_offsets;
public:
PaintEventArgs(const PaintEventArgs&) = delete;
PaintEventArgs& operator=(const PaintEventArgs&) = delete;
WindowData* PublicData = NULL;
::HWND HWND = NULL;
HDC DC = NULL;
ezui::DXRender& Graphics;//画家
Rect InvalidRectangle;//WM_PAINT里面的无效区域
PaintEventArgs(ezui::DXRender& _painter) : EventArgs(Event::OnPaint), Graphics(_painter) {}
virtual ~PaintEventArgs() {}
//添加裁剪(速度较快)
void PushLayer(const Rect& rectBounds);
//添加异形裁剪 比较耗性能,但是可以异形抗锯齿裁剪
void PushLayer(const Geometry& dxGeometry);
//弹出最后一个裁剪
void PopLayer();
//放入一个偏移
void PushOffset(const Point& offset);
//弹出最后一个偏移
void PopOffset();
};
// 为控件样式提供数据。
class UI_EXPORT ControlStyle {
public:
//边框信息
ezui::Border Border;
//整体不透明度
//UI_Float Opacity;
//背景颜色
Color BackColor = 0;
//背景图片 如果指定的图片被删除 请必须将此置零
Image* BackImage = NULL;
//前景图片 如果指定的图片被删除 请必须将此置零
Image* ForeImage = NULL;
//字体名称 具有继承性
std::wstring FontFamily;
//字体大小 具有继承性
int FontSize = 0;
//前景颜色 具有继承性
Color ForeColor;
//鼠标样式
HCURSOR Cursor = NULL;
//旋转范围 0~360
float Angle = 0;
private:
void operator=(const ControlStyle& right) {} //禁止直接赋值 因为这样会导致 Color执行拷贝使得Color变得不合法的有效
ControlStyle(const ControlStyle& right) {} //禁止拷贝
public:
ControlStyle() {}
virtual ~ControlStyle() {}
void Scale(float scale);
};
//指针管理
template <typename T>
class PtrManager {
private:
std::vector<T> m_ptrs;
public:
PtrManager() {}
virtual ~PtrManager() {
for (auto& obj : m_ptrs) {
delete obj;
}
}
void Add(const T& v) {
if (v) {
m_ptrs.push_back(v);
}
}
void Remove(const T& v/*, bool bFree = false*/) {
auto it = std::find(m_ptrs.begin(), m_ptrs.end(), v);
if (it != m_ptrs.end()) {
/*if (bFree) {
delete(*it);
}*/
m_ptrs.erase(it);
}
}
void Clear() {
for (auto& obj : m_ptrs) {
delete obj;
}
m_ptrs.clear();
}
};
//常用对象基类
class UI_EXPORT Object {
private:
//属性集合
std::map<UIString, UIString> m_attrs;
// 管理子对象的释放
PtrManager<Object*> m_childObjects;
public:
//用户自定义数据
UINT_PTR Tag = NULL;
public:
Object(Object* parentObject = NULL);
virtual ~Object();
public:
//设置属性
virtual void SetAttribute(const UIString& attrName, const UIString& attrValue);
//获取属性
virtual UIString GetAttribute(const UIString& attrName);
//获取全部属性
virtual const std::map<UIString, UIString>& GetAttributes();
//移除某个属性
virtual void RemoveAttribute(const UIString& attrName);
//绑定对象(跟随释放)
virtual Object* Attach(Object* obj);
//分离对象(解除跟随释放)
virtual void Detach(Object* obj);
//延迟删除
void DeleteLater();
};
//原理采用PostMessage
template<class Func, class... Args>
bool BeginInvoke(Func&& f, Args&& ...args) {
HWND hWnd = ezui::__EzUI_MessageWnd;
if (hWnd == NULL || !::IsWindow(hWnd)) {
return false;
}
std::function<void()>* func = new std::function<void()>(std::bind(std::forward<Func>(f), std::forward<Args>(args)...));
if (::PostMessage(hWnd, WM_GUI_SYSTEM, WM_GUI_BEGININVOKE, (LPARAM)func) == LRESULT(0)) {
delete func;
return false;
}
return true;
}
//原理采用SendMessage
template<class Func, class... Args>
bool Invoke(Func&& f, Args&& ...args) {
std::function<void()> func(std::bind(std::forward<Func>(f), std::forward<Args>(args)...));
if (::GetCurrentThreadId() == ezui::__EzUI__ThreadId) {
func();
return true;
}
HWND hWnd = ezui::__EzUI_MessageWnd;
if (hWnd == NULL || !::IsWindow(hWnd)) {
return false;
}
if (::SendMessage(hWnd, WM_GUI_SYSTEM, WM_GUI_INVOKE, (LPARAM)&func) == LRESULT(-1)) {
return false;
}
return true;
}
//统计函数耗时
template<class Func, class... Args>
int64_t StopWatch(Func&& f, Args&& ...args) {
auto beginTime = std::chrono::steady_clock::now();
std::forward<Func>(f)(std::forward<Args>(args)...);
auto delta = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - beginTime).count();
return delta;
}
};

View File

@@ -1,18 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
class UI_EXPORT HLayout :
public Control
{
public:
VAlign ContentAlign = VAlign::Mid;
protected:
virtual void OnLayout()override;
public:
HLayout(Object* parentObject = NULL);
virtual void SetAttribute(const UIString& key, const UIString& value)override;
virtual ~HLayout();
};
using HBox = HLayout;
};

View File

@@ -1,21 +0,0 @@
#pragma once
#include "PagedListView.h"
#include "HScrollBar.h"
namespace ezui {
class UI_EXPORT HListView :
public PagedListView
{
private:
HScrollBar m_hScrollBar;
void Init();
void Offset(int offset);
protected:
virtual void OnLayout()override;
virtual void OnChildPaint(PaintEventArgs& args)override;
public:
HListView(Object* parentObject = NULL);
virtual ~HListView();
virtual ScrollBar* GetScrollBar()override;
};
};

View File

@@ -1,21 +0,0 @@
#pragma once
#include "Control.h"
#include "ScrollBar.h"
namespace ezui {
class UI_EXPORT HScrollBar :
public ScrollBar
{
protected:
virtual void OnMouseDown(const MouseEventArgs& arg)override;
virtual void OnMouseMove(const MouseEventArgs& arg)override;
virtual void GetInfo(int* viewLength, int* contentLength, int* scrollBarLength)override;
public:
HScrollBar(Object* parentObject = NULL);
virtual ~HScrollBar();
virtual void ScrollTo(Control* ctl)override;
virtual void ParentSize(const Size& parentSize)override;
virtual Rect GetSliderRect()override;
};
};

View File

@@ -1,32 +0,0 @@
#pragma once
#include "EzUI.h"
#include "UIManager.h"
namespace ezui {
//内联页面 内部控件与外部隔离
class UI_EXPORT IFrame :public Control {
private:
UIManager m_umg;//内部UI管理器
private:
virtual Control* Add(Control* childCtl)override;
virtual void Remove(Control* childCtl, bool freeCtrl = false)override;
public:
//对外暴露消息通知回调
std::function<void(Control*, EventArgs&)> NotifyHandler = NULL;
IFrame(Object* parentObject = NULL);
virtual ~IFrame();
//从文件中加载xml
void LoadXml(const UIString& fileName);
//从内存中加载xml
void LoadXml(const char* fileData, size_t fileSize);
//设置唯一布局
void SetLayout(Control* ctrl);
//获取布局
Control* GetLayout();
virtual void SetAttribute(const UIString& attrName, const UIString& attrValue)override;
//消息通知
virtual void OnNotify(Control* sender, EventArgs& args);
//获取UI管理器
UIManager* GetUIManager();
};
};

View File

@@ -1,36 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
class UI_EXPORT Label :
public Control
{
private:
std::wstring m_wstr;
int m_underlinePos = 0;//显示下划线起始下标
int m_underlineCount = 0;//显示下划线文字个数
std::wstring m_ellipsisText;//文字溢出将显示的文字
protected:
virtual void OnForePaint(PaintEventArgs& args) override;
virtual void OnDpiChange(const DpiChangeEventArgs& args)override;
virtual void OnLayout()override;
public:
//基于控件的文字的边距
ezui::Distance TextMargin;
//文字对齐方式
TextAlign TextAlign = TextAlign::MiddleCenter;
public:
Label(Object* parentObject = NULL);
virtual ~Label();
virtual void SetAttribute(const UIString& key, const UIString& value)override;
virtual void RefreshLayout() override;
//设置文字
void SetText(const UIString& text);
//获取文字
UIString GetText()const;
//设置文字溢出控件之后的显示文字
void SetElidedText(const UIString& text);
//设置下划线位置
void SetUnderline(int pos, int count);
};
};

View File

@@ -1,30 +0,0 @@
#pragma once
#include "BorderlessWindow.h"
#include "Bitmap.h"
#include "Task.h"
#include "Timer.h"
namespace ezui {
/// <summary>
/// //LayeredWindow //无边框 带阴影 窗口透明异形 窗口大小发生改变重绘
/// </summary>
class UI_EXPORT LayeredWindow :public BorderlessWindow
{
private:
std::list<Rect> m_invalidateRect;
Bitmap* m_winBitmap = NULL;
void UpdateLayeredWindow(HDC hdc);
void BeginPaint(Rect* rect);
void EndPaint();
void Paint();
protected:
virtual void OnSize(const Size& sz)override;
void InvalidateRect(const Rect& rect);
virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)override;
public:
//窗口透明度
float Opacity = 1.0f;
LayeredWindow(int width, int height, HWND owner = NULL, DWORD dwStyle = NULL, DWORD dwExStyle = NULL);
virtual ~LayeredWindow();
};
};

View File

@@ -1,20 +0,0 @@
#pragma once
#include "EzUI.h"
namespace ezui {
//菜单类
class UI_EXPORT Menu :public Object
{
private:
HMENU m_hMenu = NULL;
public:
//菜单子项被选点击的回调事件 UINT:子项ID
std::function<void(UINT_PTR)> MouseClick = NULL;
Menu(Object* parentObj = NULL);
virtual ~Menu();
HMENU HMenu();
UINT_PTR Append(const UIString& text);
void Remove(const UINT_PTR id);
};
};

View File

@@ -1,27 +0,0 @@
#pragma once
#include "Menu.h"
#include <shellapi.h>
namespace ezui {
//系统托盘类
class UI_EXPORT NotifyIcon :public Object
{
private:
HWND m_hWnd = NULL;
Menu* m_menu = NULL;
NOTIFYICONDATAW m_nid = {};
WindowData m_publicData;
protected:
virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
public:
//事件处理 只会返回鼠标事件
std::function<void(const MouseEventArgs&)> EventHandler = NULL;
NotifyIcon(Object* parentObj = NULL);
void SetIcon(HICON icon);
//设置鼠标悬停时显示的提示文本
void SetTips(const UIString& text);
void SetMenu(Menu* menu);
void ShowBalloonTip(const UIString& title, const UIString& msg, int timeOut = 1000);
virtual ~NotifyIcon();
};
};

View File

@@ -1,39 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
/**
* 是一个分页显示控件集合的容器控件
*
* 它支持对一批子控件进行分页管理,例如:
* - 显示每页固定数量的控件;
* - 支持翻页;
* - 当控件到达末页时需要手动调用NextPage进行加载下一页;
*
* 子类:VList/HList/TileList 继承使其具备分页管理的能力
*/
class UI_EXPORT PagedListView :
public Control
{
private:
int m_pageIndex = 0;
int m_pageTotal = 0;
int m_pageSize = 0;
Controls m_items;
public:
PagedListView(Object* parentObject = NULL);
virtual ~PagedListView();
//页面需要加载下一页的时候发生
std::function<bool(PagedListView*, int)> NextPaging = NULL;
void SetPageInfo(const Controls& items, int pageSize);
/// <summary>
/// 获取某页的item集合
/// </summary>
/// <param name="index">1~N</param>
/// <param name="outCtls">输出集合</param>
void GetPage(int index, Controls* outCtls);
virtual void NextPage();
virtual void Clear() override;
virtual void Clear(bool freeChilds) override;
};
};

View File

@@ -1,20 +0,0 @@
#pragma once
#include "Control.h"
#include "Timer.h"
namespace ezui {
class UI_EXPORT PictureBox : public Control {
private:
Timer* m_timer;
private:
void Init();
protected:
virtual void OnForePaint(PaintEventArgs& arg)override;
public:
//图片(支持gif图自动播放)
Image* Image = NULL;
PictureBox(Object* parentObject = NULL);
virtual ~PictureBox();
virtual void SetAttribute(const UIString& key, const UIString& value)override;
};
};

View File

@@ -1,22 +0,0 @@
#pragma once
#include "Window.h"
#include "BorderlessWindow.h"
#include "LayeredWindow.h"
namespace ezui {
/// <summary>
/// 弹出式窗口(失去焦点窗口将会关闭) 一般用于做右键菜单等等
/// </summary>
class UI_EXPORT PopupWindow :public LayeredWindow {
private:
Control* m_ownerCtl = NULL;
protected:
virtual void OnKillFocus(HWND hWnd) override;
public:
PopupWindow(int width, int height, HWND ownerHwnd);
PopupWindow(int width, int height, Control* ownerCtl = NULL);
virtual void Show()override;
virtual int ShowModal(bool disableOnwer = false)override;
virtual ~PopupWindow();
};
};

View File

@@ -1,76 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
/// <summary>
/// 进度条控件
/// </summary>
class UI_EXPORT ProgressBar : public Control {
private:
float m_progress = 0.0f; // 进度值 0.0f - 1.0f
Color m_progressColor = Color::Blue; // 进度条颜色
Color m_backgroundColor = Color::LightGray; // 背景颜色
public:
ProgressBar(Object* parentObject = NULL);
virtual ~ProgressBar();
/// <summary>
/// 设置进度值
/// </summary>
/// <param name="progress">进度值,范围 0.0f - 1.0f</param>
void SetProgress(float progress);
/// <summary>
/// 获取当前进度值
/// </summary>
/// <returns>当前进度值</returns>
float GetProgress() const;
/// <summary>
/// 设置进度条颜色
/// </summary>
/// <param name="color">进度条颜色</param>
void SetProgressColor(const Color& color);
/// <summary>
/// 获取进度条颜色
/// </summary>
/// <returns>进度条颜色</returns>
Color GetProgressColor() const;
/// <summary>
/// 设置背景颜色
/// </summary>
/// <param name="color">背景颜色</param>
void SetBackgroundColor(const Color& color);
/// <summary>
/// 获取背景颜色
/// </summary>
/// <returns>背景颜色</returns>
Color GetBackgroundColor() const;
/// <summary>
/// 设置控件属性
/// </summary>
/// <param name="attrName">属性名</param>
/// <param name="attrValue">属性值</param>
virtual void SetAttribute(const UIString& attrName, const UIString& attrValue) override;
protected:
/// <summary>
/// 绘制控件
/// </summary>
/// <param name="args">绘制参数</param>
virtual void OnPaint(PaintEventArgs& args) override;
/// <summary>
/// 应用样式属性
/// </summary>
/// <param name="key">属性键</param>
/// <param name="value">属性值</param>
/// <returns>是否成功应用</returns>
virtual bool ApplyStyleProperty(const UIString& key, const UIString& value) override;
};
}

View File

@@ -1,14 +0,0 @@
#pragma once
#include "CheckBox.h"
namespace ezui {
class UI_EXPORT RadioButton :
public CheckBox
{
protected:
virtual void OnMouseDown(const MouseEventArgs& arg)override;
public:
RadioButton(Object* parentObject = NULL);
virtual~RadioButton();
};
};

View File

@@ -1,813 +0,0 @@
#pragma once
#include <Windows.h>
namespace ezui {
//size模式
enum class SizeMode {
//图片强行拉伸完全填充控件
//不裁剪,图片变形
Stretch,
//图片缩放后完全填充控件
//图片会裁剪, 保持比例裁剪和控件同大小
Cover,
//图片缩放后完整居中显示在控件上
//控件会留白
Fit,
//图片保持原尺寸,
//如果图片小于控件: 控件留白,
//如果图片大于控件: 控件边界外的部分被裁剪
Original
};
typedef SizeMode ImageSizeMode;
#if 1
#define Align_Top 1
#define Align_Bottom 2
#define Align_Left 4
#define Align_Right 8
#define Align_Mid 16
#define Align_Center 32
#else //GDI
#define Align_Top DT_TOP
#define Align_Bottom DT_BOTTOM
#define Align_Left DT_LEFT
#define Align_Right DT_RIGHT
#define Align_Mid DT_VCENTER
#define Align_Center DT_CENTER
#endif
/// <summary>
/// 水平状态下的对齐方式
/// </summary>
enum class HAlign :int
{
Left = Align_Left,
Center = Align_Center,
Right = Align_Right
};
EZUI_ENUM_OPERATORS(HAlign, int);
/// <summary>
/// 垂直状态下的对齐方式
/// </summary>
enum class VAlign :int
{
Top = Align_Top,
Mid = Align_Mid,
Bottom = Align_Bottom
};
EZUI_ENUM_OPERATORS(VAlign, int);
//包含垂直与水平对齐方式
enum class Align :int {
//
// 摘要:
// 内容在垂直方向上顶部对齐,在水平方向上左边对齐。
TopLeft = (int)VAlign::Top | (int)HAlign::Left,
//
// 摘要:
// 内容在垂直方向上顶部对齐,在水平方向上居中对齐。
TopCenter = (int)VAlign::Top | (int)HAlign::Center,
//
// 摘要:
// 内容在垂直方向上顶部对齐,在水平方向上右边对齐。
TopRight = (int)VAlign::Top | (int)HAlign::Right,
//
// 摘要:
// 内容在垂直方向上中间对齐,在水平方向上左边对齐。
MiddleLeft = (int)VAlign::Mid | (int)HAlign::Left,
//
// 摘要:
// 内容在垂直方向上中间对齐,在水平方向上居中对齐。
MiddleCenter = (int)VAlign::Mid | (int)HAlign::Center,
//
// 摘要:
// 内容在垂直方向上中间对齐,在水平方向上右边对齐。
MiddleRight = (int)VAlign::Mid | (int)HAlign::Right,
//
// 摘要:
// 内容在垂直方向上底边对齐,在水平方向上左边对齐。
BottomLeft = (int)VAlign::Bottom | (int)HAlign::Left,
//
// 摘要:
// 内容在垂直方向上底边对齐,在水平方向上居中对齐。
BottomCenter = (int)VAlign::Bottom | (int)HAlign::Center,
//
// 摘要:
// 内容在垂直方向上底边对齐,在水平方向上右边对齐。
BottomRight = (int)VAlign::Bottom | (int)HAlign::Right
};
EZUI_ENUM_OPERATORS(Align, int);
typedef Align TextAlign;
enum class FontStyle {
NORMAL
/* DWRITE_FONT_STYLE_NORMAL
字体样式 :正常。
DWRITE_FONT_STYLE_OBLIQUE
字体样式 :倾斜。
DWRITE_FONT_STYLE_ITALIC
字体样式 :斜体。 */
};
//描边样式
enum class StrokeStyle
{
None,//无
Solid,//实线
Dash//虚线
};
template<typename T>
class __EzUI__Size
{
public:
T Width;
T Height;
public:
__EzUI__Size()
{
Width = Height = 0;
}
__EzUI__Size(const __EzUI__Size& __Size)
{
Width = __Size.Width;
Height = __Size.Height;
}
__EzUI__Size(T width,
T height)
{
Width = width;
Height = height;
}
bool operator!=(const __EzUI__Size& _right) const
{
return !(Width == _right.Width && Height == _right.Height);
}
void Scale(float scale) {
Width = (Width * scale) + 0.5;
Height = (Height * scale) + 0.5;
}
bool Equals(const __EzUI__Size& sz) const
{
return (Width == sz.Width) && (Height == sz.Height);
}
bool Empty() const
{
return (Width == 0 && Height == 0);
}
__EzUI__Size operator+(const __EzUI__Size& sz) const
{
return __EzUI__Size(Width + sz.Width,
Height + sz.Height);
}
__EzUI__Size operator-(const __EzUI__Size& sz) const
{
return __EzUI__Size(Width - sz.Width,
Height - sz.Height);
}
bool operator==(const __EzUI__Size& _right) const
{
return Equals(_right);
}
};
template<typename T>
class __EzUI__Point
{
public:
T X;
T Y;
public:
__EzUI__Point()
{
X = Y = 0;
}
__EzUI__Point(const __EzUI__Point& __Point)
{
X = __Point.X;
Y = __Point.Y;
}
__EzUI__Point(const __EzUI__Size<T>& __Size)
{
X = __Size.Width;
Y = __Size.Height;
}
__EzUI__Point(T x,
T y)
{
X = x;
Y = y;
}
void Scale(float scale) {
X = (X * scale) + 0.5;
Y = (Y * scale) + 0.5;
}
bool Equals(const __EzUI__Point& __Point)const
{
return (X == __Point.X) && (Y == __Point.Y);
}
__EzUI__Point operator+(const __EzUI__Point& __Point) const
{
return __Point(X + __Point.X,
Y + __Point.Y);
}
__EzUI__Point operator-(const __EzUI__Point& __Point) const
{
return __Point(X - __Point.X,
Y - __Point.Y);
}
bool operator==(const __EzUI__Point& __Point) const
{
return Equals(__Point);
}
};
template<typename T>
class __EzUI__Rect
{
public:
T X;
T Y;
T Width;
T Height;
public:
__EzUI__Rect()
{
X = Y = Width = Height = 0;
}
__EzUI__Rect(T x,
T y,
T width,
T height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
__EzUI__Rect(const RECT& rect) {
X = rect.left;
Y = rect.top;
Width = rect.right - rect.left;
Height = rect.bottom - rect.top;
}
__EzUI__Rect(const __EzUI__Point<T>& location, const __EzUI__Size<T>& size) {
X = location.X;
Y = location.Y;
Width = size.Width;
Height = size.Height;
}
__EzUI__Point<T> GetLocation() const
{
return __EzUI__Point<T>{ X, Y };
}
__EzUI__Size<T> GetSize() const
{
return __EzUI__Size<T>(Width, Height);
}
RECT ToRECT() const {
return RECT{ (LONG)GetLeft(), (LONG)GetTop(), (LONG)GetRight(), (LONG)GetBottom() };
}
T GetLeft() const
{
return X;
}
T GetTop() const
{
return Y;
}
T GetRight() const
{
return X + Width;
}
T GetBottom() const
{
return Y + Height;
}
bool IsEmptyArea() const
{
return (Width <= 0) || (Height <= 0);
}
virtual const __EzUI__Rect& Scale(float scale) {
X = T((X * scale) + 0.5);
Y = T((Y * scale) + 0.5);
Width = T((Width * scale) + 0.5);
Height = T((Height * scale) + 0.5);
return *this;
}
bool Equals(const __EzUI__Rect& __Rect) const
{
return X == __Rect.X &&
Y == __Rect.Y &&
Width == __Rect.Width &&
Height == __Rect.Height;
}
bool operator == (const __EzUI__Rect& right) {
return Equals(right);
}
__EzUI__Rect& operator+=(T value) {
X -= value;
Y -= value;
Width += value * 2;
Height += value * 2;
return *this;
}
__EzUI__Rect& operator-=(T value) {
X += value;
Y += value;
Width -= value * 2;
Height -= value * 2;
return *this;
}
__EzUI__Rect operator+(T value) const {
__EzUI__Rect out = *this;
out += value;
return out;
}
__EzUI__Rect operator-(T value) const {
__EzUI__Rect out = *this;
out -= value;
return out;
}
bool Contains(T x,
T y) const
{
return x >= X && x < X + Width &&
y >= Y && y < Y + Height;
}
bool Contains(const __EzUI__Point<T>& pt) const
{
return Contains(pt.X, pt.Y);
}
bool Contains(const __EzUI__Rect& __Rect) const
{
return (X <= __Rect.X) && (__Rect.GetRight() <= GetRight()) &&
(Y <= __Rect.Y) && (__Rect.GetBottom() <= GetBottom());
}
void Inflate(T dx,
T dy)
{
X -= dx;
Y -= dy;
Width += 2 * dx;
Height += 2 * dy;
}
void Inflate(const __EzUI__Point<T>& point)
{
Inflate(point.X, point.Y);
}
bool Intersect(const __EzUI__Rect& __Rect)
{
return Intersect(*this, *this, __Rect);
}
static bool Intersect(__EzUI__Rect& c,
const __EzUI__Rect& a,
const __EzUI__Rect& b)
{
T right = min(a.GetRight(), b.GetRight());
T bottom = min(a.GetBottom(), b.GetBottom());
T left = max(a.GetLeft(), b.GetLeft());
T top = max(a.GetTop(), b.GetTop());
c.X = left;
c.Y = top;
c.Width = right - left;
c.Height = bottom - top;
return !c.IsEmptyArea();
}
bool IntersectsWith(const __EzUI__Rect& __Rect) const
{
return (GetLeft() < __Rect.GetRight() &&
GetTop() < __Rect.GetBottom() &&
GetRight() > __Rect.GetLeft() &&
GetBottom() > __Rect.GetTop());
}
static bool Union(__EzUI__Rect& c,
const __EzUI__Rect& a,
const __EzUI__Rect& b)
{
if (a.IsEmptyArea()) {
c = b;
return !c.IsEmptyArea();
}
if (b.IsEmptyArea()) {
c = a;
return !c.IsEmptyArea();
}
T right = max(a.GetRight(), b.GetRight());
T bottom = max(a.GetBottom(), b.GetBottom());
T left = min(a.GetLeft(), b.GetLeft());
T top = min(a.GetTop(), b.GetTop());
c.X = left;
c.Y = top;
c.Width = right - left;
c.Height = bottom - top;
return !c.IsEmptyArea();
}
void Offset(const __EzUI__Point<T>& point)
{
Offset(point.X, point.Y);
}
void Offset(T dx,
T dy)
{
X += dx;
Y += dy;
}
virtual ~__EzUI__Rect() {}
};
class __EzUI__Color
{
protected:
DWORD BGRA = 0;
public:
__EzUI__Color() {}
__EzUI__Color(
const BYTE& r,
const BYTE& g,
const BYTE& b,
const BYTE& a = 255)
{
((BYTE*)&BGRA)[0] = b;
((BYTE*)&BGRA)[1] = g;
((BYTE*)&BGRA)[2] = r;
((BYTE*)&BGRA)[3] = a;
}
__EzUI__Color(DWORD bgra)
{
BGRA = bgra;
}
virtual ~__EzUI__Color() {}
BYTE GetR() const
{
return ((BYTE*)&BGRA)[2];
}
BYTE GetG() const
{
return ((BYTE*)&BGRA)[1];
}
BYTE GetB() const
{
return ((BYTE*)&BGRA)[0];
}
BYTE GetA() const
{
return ((BYTE*)&BGRA)[3];
}
DWORD GetValue() const
{
return BGRA;
}
void SetValue(DWORD bgra)
{
BGRA = bgra;
}
void SetR(BYTE value) {
((BYTE*)&BGRA)[2] = value;
}
void SetG(BYTE value) {
((BYTE*)&BGRA)[1] = value;
}
void SetB(BYTE value) {
((BYTE*)&BGRA)[0] = value;
}
void SetA(BYTE value) {
((BYTE*)&BGRA)[3] = value;
}
public:
// Common color constants (BGRA format)
enum : DWORD
{
Transparent = 0x00000000, // 全透明
Black = 0xFF000000, // 黑色
White = 0xFFFFFFFF, // 白色
Gray = 0xFF808080, // 灰色
LightGray = 0xFFD3D3D3, // 浅灰色
DarkGray = 0xFFA9A9A9, // 深灰色
Red = 0xFFFF0000, // 红色
DarkRed = 0xFF8B0000, // 深红色
LightCoral = 0xFFF08080, // 浅珊瑚红
Tomato = 0xFFFF6347, // 番茄色
Crimson = 0xFFDC143C, // 猩红色
Green = 0xFF00FF00, // 绿色
Lime = 0xFF00FF00, // 酸橙绿(亮绿)
DarkGreen = 0xFF006400, // 深绿色
LawnGreen = 0xFF7CFC00, // 草坪绿
PaleGreen = 0xFF98FB98, // 苍绿色
Blue = 0xFF0000FF, // 蓝色
RoyalBlue = 0xFF4169E1, // 皇家蓝
DodgerBlue = 0xFF1E90FF, // 道奇蓝
DeepSkyBlue = 0xFF00BFFF, // 深天蓝
LightBlue = 0xFFADD8E6, // 浅蓝色
Yellow = 0xFF00FFFF, // 黄色
Gold = 0xFFFFD700, // 金色
LightYellow = 0xFFFFFFE0, // 浅黄色
Khaki = 0xFFF0E68C, // 卡其色
Orange = 0xFFFFA500, // 橙色
DarkOrange = 0xFFFF8C00, // 深橙色
Coral = 0xFFFF7F50, // 珊瑚色
Salmon = 0xFFFA8072, // 鲑鱼色
Purple = 0xFF800080, // 紫色
MediumPurple = 0xFF9370DB,// 中紫色
Indigo = 0xFF4B0082, // 靛青色
Violet = 0xFFEE82EE, // 紫罗兰
Plum = 0xFFDDA0DD, // 李子紫
Cyan = 0xFF00FFFF, // 青色
Teal = 0xFF808000, // 水鸭色G+B
Aqua = 0xFF00FFFF, // 浅绿色(水色)
Turquoise = 0xFF40E0D0, // 绿松石色
Brown = 0xFFA52A2A, // 棕色
Maroon = 0xFF800000, // 栗色(褐红)
Tan = 0xFFD2B48C, // 茶色
Beige = 0xFFF5F5DC, // 米色
Navy = 0xFF000080, // 藏青色
Olive = 0xFF808000, // 橄榄色
Silver = 0xFFC0C0C0 // 银色
};
};
template<typename T>
class __EzUI__Line {
public:
__EzUI__Point<T> pointA;
__EzUI__Point<T> pointB;
public:
__EzUI__Line() {
pointA.X = 0;
pointA.Y = 0;
pointB.X = 0;
pointB.Y = 0;
}
__EzUI__Line(const __EzUI__Point<T>& _pointA, const __EzUI__Point<T>& _pointB) {
this->pointA = _pointA;
this->pointB = _pointB;
}
};
typedef __EzUI__Point<int> Point;
typedef __EzUI__Point<float> PointF;
typedef __EzUI__Line<int> Line;
typedef __EzUI__Line<float> LineF;
typedef __EzUI__Size<int> Size;
typedef __EzUI__Rect<int> Rect;
class SizeF :public __EzUI__Size<float> {
public:
SizeF()
{
Width = Height = 0;
}
SizeF(float width,
float height)
{
Width = width;
Height = height;
}
SizeF(const SizeF& __Size)
{
Width = __Size.Width;
Height = __Size.Height;
}
SizeF(const Size& __Size)
{
Width = (float)__Size.Width;
Height = (float)__Size.Height;
}
};
class RectF :public __EzUI__Rect<float> {
public:
RectF() {
this->X = 0;
this->Y = 0;
this->Width = 0;
this->Height = 0;
}
RectF(const Rect& rect) {
this->X = (float)rect.X;
this->Y = (float)rect.Y;
this->Width = (float)rect.Width;
this->Height = (float)rect.Height;
}
RectF(const RectF& rect) {
this->X = rect.X;
this->Y = rect.Y;
this->Width = rect.Width;
this->Height = rect.Height;
}
RectF(float x, float y, float width, float height) {
this->X = x;
this->Y = y;
this->Width = width;
this->Height = height;
}
virtual const RectF& Scale(float scale) {
X = (X * scale);
Y = (Y * scale);
Width = (Width * scale);
Height = (Height * scale);
return *this;
}
//转换
static RectF Transformation(SizeMode sizeMode, const RectF& container, const SizeF& contentSize) {
if (sizeMode == SizeMode::Stretch) {
return container;
}
//容器数据
float containerWidth = container.Width;
float containerHeight = container.Height;
float containerRatio = containerWidth / containerHeight;//宽高比
//内容数据
float contentWidth = contentSize.Width;
float contentHeight = contentSize.Height;
float contentRatio = contentWidth / contentHeight; //宽高比
if (sizeMode == SizeMode::Fit) {
if (containerRatio < contentRatio) {
float zoomHeight = containerWidth / contentWidth * contentHeight;
float y = (containerHeight - zoomHeight) / 2.0f + container.Y;
return RectF(container.X, y, containerWidth, zoomHeight);
}
else {
float zoomWidth = containerHeight / contentHeight * contentWidth;
float x = (containerWidth - zoomWidth) / 2.0f + container.X;
return RectF(x, container.Y, zoomWidth, containerHeight);
}
}
if (sizeMode == SizeMode::Cover) {
if (containerRatio < contentRatio) {
//1000 670 容器大小
//1000 300 内容大小
//2233 670 缩放后的内容大小
float zoomWidth = containerHeight / contentHeight * contentWidth;//内容应该这么宽才对
float x = (zoomWidth - containerWidth) / 2.0f;
return RectF(container.X - x, container.Y, zoomWidth, containerHeight);
}
else {
//1000 600 容器大小
//400 600 内容大小
//1000 1500 缩放后的内容大小
float zoomHeight = containerWidth / contentWidth * contentHeight;//内容应该这么高才对
float y = (zoomHeight - containerHeight) / 2.0f;
return RectF(container.X, container.Y - y, containerWidth, zoomHeight);
}
}
//按照内容原大小居中显示
if (sizeMode == SizeMode::Original) {
float x = (container.Width - contentSize.Width) / 2.0f;
float y = (container.Height - contentSize.Height) / 2.0f;
return RectF(x, y, contentSize.Width, contentSize.Height);
}
return container;
}
virtual ~RectF() {};
};
struct Distance {
public:
WORD Left, Top, Right, Bottom;
Distance() {
Left = Top = Right = Bottom = 0;
}
Distance(WORD distanceAll) {
Left = Top = Right = Bottom = distanceAll;
}
Distance& operator=(WORD distanceAll) {
Left = Top = Right = Bottom = distanceAll;
return *this;
}
void Scale(float scale) {
Top = WORD(Top * scale + 0.5);
Bottom = WORD(Bottom * scale + 0.5);
Left = WORD(Left * scale + 0.5);
Right = WORD(Right * scale + 0.5);
}
//获取垂直所占空间
WORD GetVSpace() {
return Top + Bottom;
}
//获取水平所占空间
WORD GetHSpace() {
return Left + Right;
}
};
/// <summary>
/// 描述边框的一些信息
/// </summary>
class Border {
public:
WORD Left = 0;//左边边框大小
WORD Top = 0;//顶部边框大小
WORD Right = 0;//右边边框大小
WORD Bottom = 0;//底部边框大小
WORD TopLeftRadius = 0;
WORD TopRightRadius = 0;
WORD BottomRightRadius = 0;
WORD BottomLeftRadius = 0;
__EzUI__Color Color;
StrokeStyle Style = StrokeStyle::None;
public:
class Radius {
Border& Border;
public:
Radius(ezui::Border& bd) :Border(bd) {}
//对四个角度同时设置半径大小
Radius& operator=(WORD radius) {
Border.TopLeftRadius = radius;
Border.TopRightRadius = radius;
Border.BottomRightRadius = radius;
Border.BottomLeftRadius = radius;
return *this;
}
};
public:
Border::Radius Radius = (*this);
public:
Border() {}
//对四个边设置大小
Border& operator=(WORD borderWidth) {
Left = borderWidth;
Top = borderWidth;
Right = borderWidth;
Bottom = borderWidth;
return *this;
}
void Scale(float scale) {
Left = WORD(Left * scale + 0.5);
Top = WORD(Top * scale + 0.5);
Right = WORD(Right * scale + 0.5);
Bottom = WORD(Bottom * scale + 0.5);
TopLeftRadius = WORD(TopLeftRadius * scale + 0.5);
TopRightRadius = WORD(TopRightRadius * scale + 0.5);
BottomRightRadius = WORD(BottomRightRadius * scale + 0.5);
BottomLeftRadius = WORD(BottomLeftRadius * scale + 0.5);
}
};
class IImage {
protected:
WORD m_frameCount = 0;//总帧数
WORD m_framePos = 0;//当前帧率索引
public:
Rect Clip;//取出图像部分区域进行绘制
Point DrawPosition;//绘制在owner矩形坐标
ezui::Size DrawSize;//绘制在owner矩形的大小
ImageSizeMode SizeMode = ImageSizeMode::Fit;// 图像显示模式
public:
virtual ~IImage() {}
WORD FrameCount() {
return m_frameCount;
}
//跳转到下一帧 并且获取下一帧的延迟
virtual WORD NextFrame() = 0;
};
};

View File

@@ -1,50 +0,0 @@
#pragma once
#include "UIString.h"
namespace ezui {
/// <summary>
/// 框架中的资源类
/// </summary>
class UI_EXPORT Resource {
public:
struct Entry {
std::streampos Offset = 0;//偏移
std::streamsize Size = 0;//大小
UIString Name;//名称
};
//资源文件读取流
class UI_EXPORT ReadStream {
std::streampos m_pos = 0;
std::streamsize m_count = 0;
const char* m_ptr = NULL;
std::ifstream* m_ifs = NULL;
public:
ReadStream(HRSRC hRsrc);
ReadStream(const UIString& fileName);
void seekg(std::streampos pos);
void read(char* buf, std::streamsize count);
std::streampos tellg();
const std::streamsize size();
virtual ~ReadStream();
};
private:
ReadStream* m_rStream = NULL;
void UnPackage();
bool m_isGood = false;
public:
const std::list<Entry> Items;
bool IsGood();
//对资源目录进行打包
static bool Package(const UIString& dir, const UIString& outFile, const std::function<void(const UIString&, int, int)>& packCallback = NULL);
public:
virtual ~Resource();
//从本地文件创建资源对象
Resource(const UIString& resFile);
//使用windows内置资源文件创建资源对象
Resource(HRSRC hRsrc);
//寻找资源中的文件
bool GetFile(const UIString& fileName, std::string* out);
//传入item直接返回数据
void GetFile(const Entry& item, std::string* out);
};
};

View File

@@ -1,67 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
class UI_EXPORT ScrollBar :public Control {
protected:
//鼠标是否已经按下
bool m_mouseDown = false;
//上一次鼠标命中的坐标
int m_lastPoint = 0;
//滚动条当前的坐标
double m_sliderPos = 0;
//滚动条的长度
int m_sliderLength = 0;
//滚动条每滚动一次的比率
double m_rollRate = 0;
//父容器内的坐标偏移
int m_offset = 0;
//父容器的内容长度
int m_contentLength = 0;
//父容器可见长度(容器自身长度)
int m_viewLength = 0;
//溢出容器的长度
int m_overflowLength = 0;
//int _old_viewLength = 0;
//int _old_contentLength = 0;
//int _old_offset = 0;
private:
void Init();
public:
//滚动条计算出偏移之后的回调函数
std::function<void(int)> OffsetCallback = NULL;
//滚动事件 arg1:发送者 arg2:滚动百分比 arg3:滚动类型
std::function<void(ScrollBar*, float, Event)> Scroll = NULL;
protected:
virtual void OnBackgroundPaint(PaintEventArgs& arg)override;
virtual void OnForePaint(PaintEventArgs& args) override;
virtual void OnMouseDown(const MouseEventArgs& arg)override;
virtual void OnMouseUp(const MouseEventArgs& arg)override;
virtual void OnMouseLeave(const MouseEventArgs& arg) override;
virtual void OnMouseWheel(const MouseEventArgs& arg)override;
virtual void GetInfo(int* viewLength, int* contentLength, int* scrollBarLength) = 0;
void ScrollTo(int offset, const Event& type);
void SyncInfo();
public:
//滚动到指定控件可见位置
virtual void ScrollTo(Control* ctl) = 0;
//按照百分比滚动 0.0f~1.0f
void ScrollTo(float scrollRate);
//获取当前滚动到的位置 进度的百分比
float ScrollPos();
//获取滑块的矩形
virtual Rect GetSliderRect() = 0;//
virtual void ParentSize(const Size& parentSize) = 0;
//滚动条是否已经绘制且显示
bool IsDraw();
//重置滚动条数据到起点(不执行重绘)
void Reset();
//滚动条是否能够滚动
bool Scrollable();
//当父控件发生内容发生改变 请调用刷新滚动条
void RefreshScroll();
ScrollBar(Object* parentObject = NULL);
virtual ~ScrollBar();
};
};

View File

@@ -1,28 +0,0 @@
#pragma once
#include "Window.h"
#include "Bitmap.h"
namespace ezui {
class UI_EXPORT ShadowBox
{
private:
Size m_lastSize;
int m_lastShadowMargin = 0;
Bitmap* m_bufBitmap = NULL;
HWND m_hWnd = NULL;
HWND m_mainHWnd = NULL;
WORD m_radius = 0;
WindowData* m_publicData = NULL;
private:
void SetAplpha(int x, int y, BYTE a, float radius);
bool SetShadow(int m_Width, int m_Height, int iSize, float radius);
protected:
virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
public:
ShadowBox(int width, int height, HWND mainHwnd);//构造函数
virtual ~ShadowBox();
//在父窗口发生改变的时候更新阴影区域
virtual void Update(int shadowMargin, int radius);
HWND Hwnd();
};
};

View File

@@ -1,23 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
//添加弹簧无需用户手动释放(不可在栈上创建弹簧对象)
class UI_EXPORT Spacer :public Control {
public:
Spacer();
virtual ~Spacer();
};
//具有绝对高度的 的弹簧
class UI_EXPORT VSpacer :public Spacer {
public:
virtual ~VSpacer();
VSpacer(int fixedHeight = 0);
};
//具有绝对宽度的 的弹簧
class UI_EXPORT HSpacer :public Spacer {
public:
virtual ~HSpacer();
HSpacer(int fixedWidth = 0);
};
};

View File

@@ -1,43 +0,0 @@
#pragma once
#include "Control.h"
#include "Timer.h"
namespace ezui {
//滑动方向
enum class SlideDirection {
Horizontal, // 横向滑动(比如从左滑到右)
Vertical // 纵向滑动(比如从上滑到底)
};
class UI_EXPORT TabLayout :
public Control
{
private:
int m_pageIndex = 0;
Timer* m_timer;
int m_offset = 0;
int m_nowOffset = 0;
std::vector<int> m_initial;
SlideDirection m_dlideDirection;
float m_stepAcc = 0;
float m_stepPerFrame = 0;
void Sort();
void Init();
protected:
virtual void OnLayout()override;
virtual void SetAttribute(const UIString& key, const UIString& value)override;
virtual void OnChildPaint(PaintEventArgs& args)override;
public:
TabLayout(Object* parentObject = NULL);
virtual ~TabLayout();
virtual void Remove(Control* ctl, bool freeCtl = false)override;
virtual Control* Add(Control* childCtl)override;
//设置当前显示页
void SetPageIndex(int index);
//动画方式滑动到某一页
void SlideToPage(int index, SlideDirection dlideDirection = SlideDirection::Horizontal, int durationMs = 150, int fps = 90);
void SetPage(Control* ctl);
Control* GetPage();
//获取当前页索引
int GetPageIndex();
};
};

View File

@@ -1,495 +0,0 @@
#pragma once
#include "Control.h"
#include "Label.h"
#include "TextBox.h"
#include "CheckBox.h"
#include "ComboBox.h"
#include "VScrollBar.h"
#include "HScrollBar.h"
#include <functional>
#include <algorithm>
namespace ezui {
// 第一列类型枚举
enum class FirstColumnType {
TextBox, // 空白文本框(默认)
Index, // 不可编辑的序号从1开始
CheckBox // 选择框
};
// 单元格类型枚举
enum class CellType {
TextBox, // 文本框(默认)
CheckBox, // 选择框
ComboBox, // 下拉选择框
ReadOnly // 不可编辑(可选中复制但不能修改)
};
// 边框类型(复用框架的 StrokeStyle
// StrokeStyle::None - 无边框
// StrokeStyle::Solid - 实线
// StrokeStyle::Dash - 虚线
// 排序方向
enum class SortOrder {
None, // 未排序
Ascending, // 升序
Descending // 降序
};
// 单元格独立样式(用于单独设置某个单元格的样式)
struct CellStyle {
Color BorderColor;
StrokeStyle BorderStyle = StrokeStyle::None;
Color BackColor;
Color ForeColor;
TextAlign Align = TextAlign::TopLeft;
bool HasBorderColor = false;
bool HasBorderStyle = false;
bool HasBackColor = false;
bool HasForeColor = false;
bool HasTextAlign = false;
void SetBorderColor(const Color& color) {
BorderColor = color;
HasBorderColor = true;
}
void SetBorderStyle(StrokeStyle style) {
BorderStyle = style;
HasBorderStyle = true;
}
void SetBackColor(const Color& color) {
BackColor = color;
HasBackColor = true;
}
void SetForeColor(const Color& color) {
ForeColor = color;
HasForeColor = true;
}
void SetTextAlign(ezui::TextAlign align) {
Align = align;
HasTextAlign = true;
}
void Reset() {
HasBorderColor = false;
HasBorderStyle = false;
HasBackColor = false;
HasForeColor = false;
HasTextAlign = false;
}
};
// 单元格数据
struct CellData {
UIString Text; // 单元格文本内容
bool Checked = false; // 用于 CheckBox 类型
int ComboIndex = -1; // 用于 ComboBox 类型,选中的索引
CellStyle Style; // 单元格独立样式
};
// 列信息
struct ColumnInfo {
UIString HeaderText; // 表头文字
int Width = 100; // 列宽
CellType Type = CellType::TextBox; // 单元格类型
std::vector<UIString> ComboItems; // 下拉选项(仅 ComboBox 类型有效)
SortOrder CurrentSort = SortOrder::None; // 当前排序状态
TextAlign CellTextAlign = TextAlign::TopLeft; // 该列的默认对齐方式
};
class UI_EXPORT TableView : public Control {
private:
// 滚动条
VScrollBar m_vScrollBar;
HScrollBar m_hScrollBar;
// 数据存储
std::vector<ColumnInfo> m_columns; // 列信息
std::vector<std::vector<CellData>> m_data; // 二维数据 [row][col]
std::vector<int> m_rowHeights; // 每行高度
std::vector<bool> m_rowChecked; // 每行的选中状态第一列为CheckBox时使用
// 第一列配置
FirstColumnType m_firstColumnType = FirstColumnType::TextBox;
int m_firstColumnWidth = 50; // 第一列宽度
// 表头配置
int m_headerHeight = 30; // 表头高度
bool m_headerSelectAll = false; // 表头全选状态
// 默认行高
int m_defaultRowHeight = 30;
// 统一单元格样式
int m_cellBorderSize = 1;
StrokeStyle m_cellBorderStyle = StrokeStyle::Solid;
Color m_cellBorderColor = Color::LightGray;
Color m_cellBackColor = Color::White;
Color m_cellForeColor = Color::Black;
int m_cellFontSize = 14;
std::wstring m_cellFontFamily = L"Microsoft YaHei";
TextAlign m_cellTextAlign = TextAlign::TopLeft; // 默认对齐方式
std::vector<TextAlign> m_rowTextAlign; // 每行的对齐方式(未设置时使用默认值)
// 表头样式
Color m_headerBackColor = Color(0xFFE0E0E0);
Color m_headerForeColor = Color::Black;
// 滚动偏移
int m_scrollOffsetX = 0;
int m_scrollOffsetY = 0;
// 内容大小缓存供GetContentSize使用
mutable Size m_contentSize;
// 编辑状态
bool m_editing = false;
int m_editRow = -1;
int m_editCol = -1;
TextBox* m_editBox = nullptr;
ComboBox* m_editCombo = nullptr;
CheckBox* m_editCheck = nullptr;
// 列宽拖动
bool m_draggingColumn = false;
int m_dragColumnIndex = -1;
int m_dragStartX = 0;
int m_dragStartWidth = 0;
// 排序
int m_sortColumnIndex = -1;
// 鼠标悬停
int m_hoverRow = -1;
int m_hoverCol = -1;
// 双击检测
ULONGLONG m_lastClickTime = 0;
int m_lastClickRow = -1;
int m_lastClickCol = -1;
// 选中行非CheckBox模式下通过单击第一列选中的行
int m_selectedRow = -1;
// 编辑前的原始值(用于编辑完成回调)
UIString m_editOriginalValue;
private:
void Init();
// 计算总内容宽度
int GetContentWidth() const;
// 计算总内容高度
int GetContentHeight() const;
// 获取列起始X坐标考虑滚动偏移
int GetColumnX(int colIndex) const;
// 获取行起始Y坐标考虑滚动偏移
int GetRowY(int rowIndex) const;
// 根据坐标获取单元格位置
bool HitTestCell(const Point& pt, int* outRow, int* outCol) const;
// 根据坐标检测是否在列边界上(用于拖动调整列宽)
int HitTestColumnBorder(const Point& pt) const;
// 检测是否点击在垂直滚动条上
bool HitTestVScrollBar(const Point& pt);
// 检测是否点击在水平滚动条上
bool HitTestHScrollBar(const Point& pt);
// 绘制表头
void DrawHeader(PaintEventArgs& args);
// 绘制单元格
void DrawCells(PaintEventArgs& args);
// 绘制单个单元格
void DrawCell(PaintEventArgs& args, int row, int col, const Rect& cellRect);
// 绘制第一列
void DrawFirstColumn(PaintEventArgs& args, int row, const Rect& cellRect);
// 开始编辑单元格
void BeginEdit(int row, int col);
// 结束编辑
void EndEdit(bool save = true);
// 更新行高(根据内容)
void UpdateRowHeight(int row);
// 计算文本需要的行数
int CalculateTextLines(const UIString& text, int width) const;
// 刷新滚动条
void RefreshScrollBars();
// 滚动偏移处理
void OffsetX(int offset);
void OffsetY(int offset);
// 执行排序
void DoSort(int colIndex);
protected:
virtual void OnPaint(PaintEventArgs& args) override;
virtual void OnChildPaint(PaintEventArgs& args) override;
virtual void OnLayout() override;
virtual void OnMouseMove(const MouseEventArgs& args) override;
virtual void OnMouseDown(const MouseEventArgs& args) override;
virtual void OnMouseUp(const MouseEventArgs& args) override;
virtual void OnMouseDoubleClick(const MouseEventArgs& args) override;
virtual void OnMouseWheel(const MouseEventArgs& args) override;
virtual void OnMouseLeave(const MouseEventArgs& args) override;
virtual void OnSize(const SizeEventArgs& args) override;
virtual void OnKeyDown(const KeyboardEventArgs& args) override;
virtual void OnKeyChar(const KeyboardEventArgs& args) override;
virtual const Size& GetContentSize() override;
public:
// 选中行背景色当第一列为CheckBox且被选中时使用或者单击选中行时使用
Color SelectedRowBackColor = Color(0xFFADD8E6); // 浅蓝色
/*
table->CellValueChanged = [](int row, int col, const UIString& value) {
// 处理内容变化
};
*/
// 单元格内容变化回调(内容变化时立即触发)
// 参数: row, col, newValue
std::function<void(int, int, const UIString&)> CellValueChanged = nullptr;
/*
table->CellEditFinished = [](int row, int col, const UIString& oldValue, const UIString& newValue) {
// 处理内容变化
};
*/
// 单元格编辑完成回调编辑结束时触发比如TextBox失去焦点或按Enter时
// 参数: row, col, oldValue, newValue
std::function<void(int, int, const UIString&, const UIString&)> CellEditFinished = nullptr;
/*
tableView->RightClick= [tableView](int row, int col) {
// 处理内容变化
};
*/
// 鼠标右键单击回调
// 参数: row, col (row=-1 表示点击在表头col=-1 表示点击在第一列)
std::function<void(int, int)> RightClick = nullptr;
public:
TableView(Object* parentObject = nullptr);
virtual ~TableView();
// ============ 表头设置 ============
// 设置表头(传入表头名数组)
void SetHeaders(const std::vector<UIString>& headers);
// 获取表头数量(不包含第一列)
int GetColumnCount() const;
// 设置表头高度
void SetHeaderHeight(int height);
// 获取表头高度
int GetHeaderHeight() const;
// ============ 第一列设置 ============
// 设置第一列类型
void SetFirstColumnType(FirstColumnType type);
// 获取第一列类型
FirstColumnType GetFirstColumnType() const;
// 设置第一列宽度
void SetFirstColumnWidth(int width);
// 获取第一列宽度
int GetFirstColumnWidth() const;
// ============ 列设置 ============
// 设置某列宽度
void SetColumnWidth(int colIndex, int width);
// 获取某列宽度
int GetColumnWidth(int colIndex) const;
// 获取所有列宽
const std::vector<int> GetColumnWidths() const;
// 设置某列单元格类型
void SetColumnType(int colIndex, CellType type);
// 获取某列单元格类型
CellType GetColumnType(int colIndex) const;
// 设置某列的下拉选项(仅对 ComboBox 类型有效)
void SetColumnComboItems(int colIndex, const std::vector<UIString>& items);
// ============ 行设置 ============
// 获取行数
int GetRowCount() const;
// 添加行
void AddRow();
// 插入行
void InsertRow(int rowIndex);
// 删除行
void RemoveRow(int rowIndex);
// 清空所有行
void ClearRows();
// 添加列
void AddColumn(const UIString& headerText = L"", int width = 100);
// 插入列
void InsertColumn(int colIndex, const UIString& headerText = L"", int width = 100);
// 删除列
void RemoveColumn(int colIndex);
// 获取行高
int GetRowHeight(int rowIndex) const;
// 获取所有行高
const std::vector<int> GetRowHeights() const;
// 设置默认行高
void SetDefaultRowHeight(int height);
// ============ 数据操作 ============
// 设置单个单元格数据
void SetData(int row, int col, const UIString& value);
// 获取单个单元格数据
UIString GetData(int row, int col) const;
// 设置整行数据
void SetRowData(int row, const std::vector<UIString>& values);
// 获取整行数据
std::vector<UIString> GetRowData(int row) const;
// 获取整列数据
std::vector<UIString> GetColData(int col) const;
// 设置全部数据(二维数组)
void SetAllData(const std::vector<std::vector<UIString>>& data);
// 获取全部数据
std::vector<std::vector<UIString>> GetAllData() const;
// 设置单元格 CheckBox 状态
void SetCellChecked(int row, int col, bool checked);
// 获取单元格 CheckBox 状态
bool GetCellChecked(int row, int col) const;
// 设置单元格 ComboBox 选中索引
void SetCellComboIndex(int row, int col, int index);
// 获取单元格 ComboBox 选中索引
int GetCellComboIndex(int row, int col) const;
// ============ 行选中第一列为CheckBox时 ============
// 设置某行选中状态
void SetRowChecked(int row, bool checked);
// 获取某行选中状态
bool GetRowChecked(int row) const;
// 获取所有选中的行索引
std::vector<int> GetCheckedRows() const;
// 获取当前选中的行非CheckBox模式通过单击第一列选中
int GetSelectedRow() const;
// 设置当前选中的行非CheckBox模式
void SetSelectedRow(int row);
// 清除选中行非CheckBox模式
void ClearSelection();
// 全选
void SelectAll();
// 取消全选
void DeselectAll();
// ============ 样式设置 ============
// 设置统一单元格样式
void SetCellBorderSize(int size);
void SetCellBorderStyle(StrokeStyle style);
void SetCellBorderColor(const Color& color);
void SetCellBackColor(const Color& color);
void SetCellForeColor(const Color& color);
void SetCellFontSize(int size);
void SetCellFontFamily(const std::wstring& fontFamily);
// 设置单独单元格样式
void SetCellStyle(int row, int col, const CellStyle& style);
// 获取单独单元格样式
CellStyle GetCellStyle(int row, int col) const;
// 重置单独单元格样式(使用统一样式)
void ResetCellStyle(int row, int col);
// 设置表头样式
void SetHeaderBackColor(const Color& color);
void SetHeaderForeColor(const Color& color);
// ============ 对齐方式设置 ============
// 设置默认对齐方式(影响所有未单独设置对齐方式的单元格)
void SetDefaultTextAlign(TextAlign align);
// 设置某列的对齐方式
void SetColumnTextAlign(int colIndex, TextAlign align);
// 设置某行的对齐方式
void SetRowTextAlign(int rowIndex, TextAlign align);
// 设置单个单元格的对齐方式
void SetCellTextAlign(int row, int col, TextAlign align);
// 获取单元格的对齐方式(考虑优先级:单元格 > 行 > 列 > 默认)
TextAlign GetCellTextAlign(int row, int col) const;
// ============ 鼠标悬停信息 ============
// 获取鼠标当前悬停的行号(-1表示表头或未悬停在任何行
int GetHoverRow() const;
// 获取鼠标当前悬停的列号(-1表示第一列或未悬停在任何列
int GetHoverCol() const;
// 获取鼠标当前悬停的行列号(通过指针返回)
void GetHoverCell(int* outRow, int* outCol) const;
// ============ 滚动条 ============
virtual ScrollBar* GetVScrollBar();
virtual ScrollBar* GetHScrollBar();
// ============ 属性设置XML支持 ============
virtual void SetAttribute(const UIString& key, const UIString& value) override;
};
};

View File

@@ -1,98 +0,0 @@
#pragma once
#include "EzUI.h"
namespace ezui {
//互斥锁
class UI_EXPORT Mutex {
private:
CRITICAL_SECTION m_mtx; // 互斥锁
bool m_bLocked;
Mutex(const Mutex&) = delete;
public:
Mutex();
virtual ~Mutex();
// 锁定互斥锁
void Lock();
// 解锁互斥锁
void UnLock();
};
//带互斥锁的条件变量类
class UI_EXPORT ConditionVariable {
private:
HANDLE m_codv = NULL; // 事件对象(模拟条件变量)
Mutex m_mtx; // 锁对象
ConditionVariable(const ConditionVariable&) = delete;
public:
ConditionVariable();
virtual ~ConditionVariable();
// 唤醒等待的线程(唤醒单个线程)
void Notify();
// 可选条件的等待(不可以多个线程使用此函数)
void Wait(const std::function<bool()>& condition_cb = NULL);
// 锁定互斥锁
void Lock();
// 解锁互斥锁
void Unlock();
};
};
namespace ezui {
class UI_EXPORT Task {
bool m_finished = false;
std::thread* m_thread = NULL;
bool m_bJoin = false;
private:
Task(const Task&) = delete;
void DoWork(std::function<void()>* func);
public:
template<class Func, class... Args>
Task(Func&& f, Args&& ...args) {
std::function<void()>* func = new std::function<void()>(std::bind(std::forward<Func>(f), std::forward<Args>(args)...));
m_thread = new std::thread([this, func]() mutable {
DoWork(func);
});
}
void Wait();
//当前任务是否已经停止
bool IsStopped();
virtual ~Task();
};
class UI_EXPORT TaskFactory {
bool m_bStop = false;
std::list<Task*> m_tasks;
std::list<std::function<void()>> m_funcs;
std::mutex m_mtx;
std::condition_variable m_codv;
//用于等待任务清空的锁和条件变量
std::mutex m_mtx2;
std::condition_variable m_codv2;
private:
TaskFactory(const TaskFactory&) = delete;
public:
TaskFactory(int maxTaskCount = 50);
//添加到任务队列中的末尾(先后顺序执行)
template<class Func, class... Args>
void Add(Func&& f, Args&& ...args) {
{
std::unique_lock<std::mutex> autoLock(m_mtx);
m_funcs.emplace_back(std::bind(std::forward<Func>(f), std::forward<Args>(args)...));
}
m_codv.notify_one();
}
//添加至任务队列的第一位(优先执行)
template<class Func, class... Args>
void AddToFrist(Func&& f, Args&& ...args) {
{
std::unique_lock<std::mutex> autoLock(m_mtx);
m_funcs.emplace_front(std::bind(std::forward<Func>(f), std::forward<Args>(args)...));
}
m_codv.notify_one();
}
//等待所有任务被取走
void WaitAll();
virtual ~TaskFactory();
};
};

View File

@@ -1,121 +0,0 @@
#pragma once
#include "Control.h"
#include "VScrollBar.h"
#include "Timer.h"
namespace ezui {
class UI_EXPORT TextBox :
public Control
{
private:
VScrollBar m_vScrollbar;
int m_lastWidth = 0;
int m_lastHeight = 0;
bool m_autoWrap = false; // 是否允许文字超宽时自动换行
bool m_allowManualLineBreak = false; // 是否允许用户按Shift+Enter手动换行
std::wstring m_text;//文字
Size m_fontBox;
bool m_down = false;//是否具有焦点中
bool m_focus = false;//是否具有焦点中
Point m_point_Start;//开始选中的位置
Point m_point_End;//结束位置
std::vector<RectF> m_selectRects;//选中的字符矩形
Rect m_careRect;//光标位置
Font* m_font = NULL;//字体
TextLayout* m_textLayout = NULL;//字体布局
Point m_pointA;//A点
BOOL m_A_isTrailingHit;//如果是1表示是字符的后半边
int m_A_TextPos = 0;//点击了第几个字符
Point m_pointB;//B点
BOOL m_B_isTrailingHit;//如果是1表示是字符的后半边
int m_B_TextPos = 0;//点击了第几个字符
int m_textPos = 0;//当前文字的下标 0~text.size()
int m_scrollX = 0;//用于左右滚动
int m_scrollY = 0;//用于y轴滚动
int m_lastX = 0;//上一个x位置
int m_lastY = 0;//上一个y位置
Timer* m_timer;//用于光标闪烁
bool m_bCareShow = false;//用于光标闪烁
int m_maxLen = -1;//最大文字数量
std::wstring m_placeholder;//placeholder懂得都懂 (在没有文字的情况下显示的文字)
std::wstring m_passwordChar;
bool m_readOnly = false;//是否只读
// 内边距(四边独立)
int m_padLeft = 6;
int m_padTop = 4;
int m_padRight = 6;
int m_padBottom = 4;
public:
//文字对其方式(针对单行输入框有效)
TextAlign TextAlign = TextAlign::MiddleLeft;
private:
void Init();
void InsertUnicode(const std::wstring& str, bool isEnd = false);//插入unicode文字内部使用
bool DeleteRange();//删除选中内容
bool GetSelectedRange(int* outPos, int* outCount);//获取当前被选中的区域 返回下标和个数
bool Copy();//复制到剪切板
bool Paste();//粘贴
bool SelectedAll();//全选
void OnBackspace();//退格键要做的事
void BuildCare();//构建光标
void BuildSelectedRect();
Point ConvertPoint(const Point& pt);//坐标转换
protected:
virtual void OnRemove()override;
virtual void SetAutoWidth(bool flag)override;
virtual void SetAutoHeight(bool flag)override;
virtual void OnForePaint(PaintEventArgs& e) override;
virtual void OnKeyChar(const KeyboardEventArgs& arg) override;
virtual void OnKeyDown(const KeyboardEventArgs& arg)override;
virtual void OnMouseDown(const MouseEventArgs& arg)override;
virtual void OnMouseWheel(const MouseEventArgs& arg)override;
virtual void OnMouseMove(const MouseEventArgs& arg) override;
virtual void OnMouseUp(const MouseEventArgs& arg)override;
virtual void OnFocus(const FocusEventArgs& arg) override;
virtual void OnKillFocus(const KillFocusEventArgs& arg) override;
virtual void OnLayout();
void Offset(int moveY);
// 支持 TextBox 自身扩展样式属性padding 系列)
virtual bool ApplyStyleProperty(const UIString& key, const UIString& value) override;
public:
std::function<void(const UIString&)> TextChanged = NULL;
public:
TextBox(Object* parentObject = NULL);
virtual ~TextBox();
// 设置内边距 (兼容旧接口:水平=px, 垂直=py)
void SetPadding(int px, int py);
// 设置四边
void SetPadding4(int left, int top, int right, int bottom);
virtual void SetAttribute(const UIString& key, const UIString& value)override;
//获取焦点所在光标位置
virtual Rect GetCareRect()override;
//分析字符串
void Analysis();
//在当前光标中插入文字
void Insert(const UIString& str, bool isEnd = false);
//获取输入框文字
const UIString GetText();
//获取滚动条
virtual ScrollBar* GetScrollBar()override;
//设置文字
void SetText(const UIString& text);
//是否多行显示兼容旧版仅调用autoWrap参数
bool IsMultiLine();
//设置是否多行显示
// autoWrap: 文字超宽时是否自动换行
// allowManualLineBreak: 是否允许用户按Shift+Enter手动换行
void SetMultiLine(bool autoWrap, bool allowManualLineBreak = false);
//设置为是否只读
void SetReadOnly(bool bReadOnly);
//是否为只读
bool IsReadOnly();
//设置最大输入字符个数
void SetMaxLength(int maxLen);
// 设置占位符文本
void SetPlaceholderText(const UIString& text);
//设置密码框占位符(建议单字符)
void SetPasswordChar(const UIString& passwordChar);
// 设置焦点并初始化光标到指定位置(-1表示文本末尾
void SetFocusAndCaret(int caretPos = -1);
};
};

View File

@@ -1,22 +0,0 @@
#pragma once
#include "PagedListView.h"
#include "VScrollBar.h"
namespace ezui {
class UI_EXPORT TileListView :
public PagedListView
{
private:
VScrollBar m_vScrollBar;
bool m_autoHeight = false;//根据内容的高度自动变化
void Init();
void Offset(int offset);
protected:
virtual void OnChildPaint(PaintEventArgs& args)override;
virtual void OnLayout()override;
public:
TileListView(Object* parentObject = NULL);
virtual ~TileListView();
virtual ScrollBar* GetScrollBar()override;
};
};

View File

@@ -1,39 +0,0 @@
#pragma once
#include "EzUI.h"
#include "Task.h"
namespace ezui {
//使用线程的计时器 不与主进程同步(启动的时候就直接开始执行回调函数)
class UI_EXPORT Timer :public Object {
bool m_bExit = false;
std::atomic<bool> m_bPause = true;
Task* m_task = NULL;
HANDLE m_event = NULL;
public:
std::function<void(Timer*)> Tick = NULL;
int Interval = 0;
public:
//Timeout干啥的不用我多说什么了吧
template<class Func, class... Args>
static void Timeout(int msec, Func&& f, Args&& ...args) {
std::function<void()>* func = new std::function<void()>(std::bind(f, args...));
Timer* timer = new Timer;
timer->Interval = 0;
timer->Tick = [msec, func](Timer* t) {
t->Stop();
Sleep(msec);
(*func)();
delete func;
t->DeleteLater();
};
timer->Start();
};
public:
Timer(Object* parentObject = NULL);
bool IsStopped();
void Start();
void Stop();
virtual ~Timer();
};
};

View File

@@ -1,14 +0,0 @@
#pragma once
#include "HListView.h"
#include "VListView.h"
namespace ezui {
//树形菜单 还在设计中
class UI_EXPORT TreeView :public HListView {
private:
VListView m_vList;
public:
TreeView(Object* parentObj = NULL);
void AddNode(const UIString& nodeName);
virtual ~TreeView();
};
};

View File

@@ -1,116 +0,0 @@
#pragma once
#include <list>
#include <vector>
#include <map>
#include <exception>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <memory>
#include <functional>
#include <thread>
#include <chrono>
#include <mutex>
#include <algorithm>
#include <atomic>
#include <condition_variable>
#include <windows.h>
#ifndef GET_X_LPARAM
#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
#endif // !GET_X_LPARAM
#ifndef GET_Y_LPARAM
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
#endif // !GET_Y_LPARAM
#ifndef ASSERT
#ifdef _DEBUG
#define ASSERT(expr) _ASSERTE(expr)
#else
#define ASSERT(expr) ((void)0)
#endif
#endif
#ifndef GCL_HCURSOR
#define GCL_HCURSOR -12
#endif
#ifdef _WIN64
#define UI_SET_USERDATA(hWnd,data) SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)data);
#define UI_GET_USERDATA(hwnd) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
#else
#define UI_SET_USERDATA(hWnd,data) SetWindowLongW(hWnd, GWLP_USERDATA, (LONG)data);
#define UI_GET_USERDATA(hwnd) GetWindowLongW(hwnd, GWLP_USERDATA);
#endif
#if defined _M_IX86
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
//框架内保留的消息 用于GUI框架内部通讯
#define WM_GUI_SYSTEM WM_USER
#define WM_GUI_APP WM_APP
//扩展消息 在WM_GUI_SYSTEM消息中的wParam参数中体现
#define WM_GUI_INVOKE 0x01
#define WM_GUI_BEGININVOKE 0x02
#if defined(EZUI_STATIC)
#define UI_EXPORT
#define UI_VAR_EXPORT
#elif defined(_WINDLL)
#define UI_EXPORT __declspec(dllexport)
#define UI_VAR_EXPORT __declspec(dllexport)
#else
#define UI_EXPORT
#define UI_VAR_EXPORT __declspec(dllimport)
#endif // EZUI_STATIC
#define EZUI_WINDOW_CLASS L"EzUI_Window" //基础窗口类名
#define EZUI_INVOKER_WINDOW_CLASS L"EzUI_InvokerWindow" //用于线程同步的窗口类名
#define EZUI_FLOAT_MAX 16777216.0f //最后一个可以精确表示的整数
#define EZUI_FLOAT_EPSILON 1e-6f // 浮点误差阈值
//下面的渲染方式只能选一个
#define USED_DIRECT2D 1 //DX绘制 性能好 内存占用高
//生成枚举类常用操作符
#define EZUI_ENUM_OPERATORS(ENUM_TYPE, BASE_TYPE) \
inline ENUM_TYPE operator|(ENUM_TYPE a, ENUM_TYPE b) { \
return static_cast<ENUM_TYPE>(static_cast<BASE_TYPE>(a) | static_cast<BASE_TYPE>(b)); \
} \
inline ENUM_TYPE operator&(ENUM_TYPE a, ENUM_TYPE b) { \
return static_cast<ENUM_TYPE>(static_cast<BASE_TYPE>(a) & static_cast<BASE_TYPE>(b)); \
} \
inline ENUM_TYPE operator~(ENUM_TYPE a) { \
return static_cast<ENUM_TYPE>(~static_cast<BASE_TYPE>(a)); \
} \
inline ENUM_TYPE operator^(ENUM_TYPE a, ENUM_TYPE b) { \
return static_cast<ENUM_TYPE>(static_cast<BASE_TYPE>(a) ^ static_cast<BASE_TYPE>(b)); \
} \
inline ENUM_TYPE& operator|=(ENUM_TYPE& a, ENUM_TYPE b) { \
a = a | b; \
return a; \
} \
inline ENUM_TYPE& operator&=(ENUM_TYPE& a, ENUM_TYPE b) { \
a = a & b; \
return a; \
} \
inline ENUM_TYPE& operator^=(ENUM_TYPE& a, ENUM_TYPE b) { \
a = a ^ b; \
return a; \
}

View File

@@ -1,78 +0,0 @@
#pragma once
#include "Control.h"
#include "Spacer.h"
#include "HLayout.h"
#include "Label.h"
#include "VLayout.h"
#include "TileListView.h"
#include "Button.h"
#include "VListView.h"
#include "HListView.h"
#include "RadioButton.h"
#include "CheckBox.h"
#include "TextBox.h"
#include "TabLayout.h"
#include "PictureBox.h"
#include "ProgressBar.h"
#include "Window.h"
#include "ComboBox.h"
#include "TableView.h"
namespace ezui {
//主窗口中的内联页面类
class UI_EXPORT UIManager {
public:
struct Style
{
ControlState m_styleType;
UIString m_selectorName;
UIString m_styleStr;
};
struct XmlNode {
Control* m_ctl;
UIString m_tagName;
public:
XmlNode(Control* ctl, const UIString& tagName) :m_ctl(ctl), m_tagName(tagName) {}
};
private:
std::vector<Control*> m_rootNode;//根节点列表
std::list<XmlNode> m_controls;
std::list<UIManager::Style> m_styles;
void LoadControl(void* node, Control* control);
Control* BuildControl(void* node);//内部函数
//记录XML中的控件到管理器 管理器释放的时候 由管理器加载的控件将自动释放
void RegisterControl(Control* ctl, const UIString& tagNamee);
void AnalysisStyle(const UIString& styleStr, std::list<UIManager::Style>* out);//分析样式
void ApplyStyle(Control* ctl, const std::list<UIManager::Style>& selectors, const UIString& tagName);
//应用样式(为控件应用所有样式)
protected:
//当解析到一个节点的时候发生
virtual Control* OnBuildControl(const UIString& nodeName);
//获取根节点控件
Control* GetRoot(int index = 0);
public:
UIManager();
virtual ~UIManager();
void SetupUI(Window* window);
void SetupUI(Control* parentCtl);
//从文件中加载布局(不允许多次加载xml)
void LoadXml(const UIString& fileName);
//从内存加载布局(不允许多次加载xml)
void LoadXml(const char* fileData, size_t fileSize);
//设置样式表
void SetStyleSheet(const UIString& styleContent);
//从文件中加载样式
void LoadStyle(const UIString& fileName);
//释放由本此对象创建的控件
void Free(Control** ctl);
};
//注册基础控件
void InitControls();
//注册自定义控件
void RegisterControl(const UIString& ctrlName, const std::function<Control* ()>& create_cb);
//注册自定义控件
template<typename T>
void RegisterControl(const UIString& ctrlName) {
RegisterControl(ctrlName, []() -> Control* { return new T; });
}
};

View File

@@ -1,28 +0,0 @@
#pragma once
#include "UIManager.h"
namespace ezui {
//控件选择器(多功能选择器暂时未完善)
class UI_EXPORT UISelector
{
private:
Control* m_ctl = NULL;
Control* m_notCtl = NULL;
std::vector<Control*> m_ctls;
UISelector& NextName(const UIString& key) { return *this; };
UISelector& NextId(const UIString& key) { return *this; };
public:
UISelector(const std::vector<Control*>& controls);
UISelector(const std::list<Control*>& controls);
UISelector(Control* control);
UISelector(Control* control, const UIString& mathStr);
virtual ~UISelector();
UISelector& Css(const UIString& styleStr);
UISelector& CssHover(const UIString& styleStr);
UISelector& CssActive(const UIString& styleStr);
UISelector& Attr(const UIString& key, const UIString& value);
UISelector& Refresh();
UISelector& Not(Control* fiterCtl);
};
#define $ UISelector
};

View File

@@ -1,78 +0,0 @@
#pragma once
#include "UIDef.h"
#include <codecvt>
#include <iomanip>
namespace ezui {
namespace ui_text {
//-----------------------------------------------Copy Start-----------------------------------------------
/// <summary>
/// utf8字符串
/// </summary>
class UI_EXPORT String :public std::string {
public:
String();
virtual ~String();
String(const String& _right)noexcept;
String(String&& _right)noexcept;
String& operator=(const String& _right)noexcept;
String& operator=(String&& _right)noexcept;
String(const std::string& str)noexcept;
String(const char* szbuf)noexcept;
String(const wchar_t* szbuf)noexcept;
String(const std::wstring& wstr)noexcept;
//返回utf8字符个数
size_t utf8Length() const;
std::wstring unicode() const;
std::string ansi() const;
void erase(char _ch);
void erase(size_t pos, size_t count);
String replace(char oldChar, char newChar)const;
String replace(const String& oldText, const String& newText, bool allReplace = true)const;
String toLower()const;
String toUpper()const;
//去除前后空格
String trim()const;
//find value count
size_t count(const String& value)const;
std::vector<String> split(const String& ch)const;
bool operator==(const wchar_t* szbuf)const;
bool operator==(const std::wstring& wStr)const;
template<typename ...T>
inline String format(const T &...args) {
auto bufSize = ::snprintf(NULL, 0, this->c_str(), std::forward<const T&>(args)...) + 1; // +1是为了'结束符\0'
char* buf = new char[bufSize] {0};
auto count = ::sprintf_s(buf, bufSize, this->c_str(), std::forward<const T&>(args)...);
String ret(buf);
delete[] buf;
return ret;
}
};
//base convert
UI_EXPORT void AnyToUnicode(const std::string& src_str, UINT codePage, std::wstring* out_wstr);
UI_EXPORT void UnicodeToAny(const std::wstring& unicode_wstr, UINT codePage, std::string* out_str);
//
UI_EXPORT void GBKToUTF8(const std::string& str, std::string* outStr);
UI_EXPORT void UTF8ToGBK(const std::string& str, std::string* outStr);
UI_EXPORT void ANSIToUniCode(const std::string& str, std::wstring* outStr);
UI_EXPORT void ANSIToUTF8(const std::string& str, std::string* outStr);
UI_EXPORT void UnicodeToANSI(const std::wstring& wstr, std::string* outStr);
UI_EXPORT void UnicodeToUTF8(const std::wstring& wstr, std::string* outStr);
UI_EXPORT void UTF8ToANSI(const std::string& str, std::string* outStr);
UI_EXPORT void UTF8ToUnicode(const std::string& str, std::wstring* outStr);
//
UI_EXPORT void Tolower(std::string* str_in_out);
UI_EXPORT void Toupper(std::string* str_in_out);
UI_EXPORT void Erase(std::string* str_in_out, char ch);
UI_EXPORT void Replace(std::string* str_in_out, char oldChar, char newChar);
UI_EXPORT size_t Replace(std::string* str_in_out, const std::string& oldText, const std::string& newText, bool replaceAll = true);
UI_EXPORT void Split(const std::string& str_in, const std::string& ch, std::vector<std::string>* strs_out);
//
UI_EXPORT String ToString(double number, size_t keepBitSize);
//-----------------------------------------------Copy End-----------------------------------------------
};
using UIString = ui_text::String;
};

View File

@@ -1,18 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
class UI_EXPORT VLayout :
public Control
{
public:
HAlign ContentAlign = HAlign::Center;
protected:
virtual void OnLayout() override;
public:
VLayout(Object* parentObject = NULL);
virtual void SetAttribute(const UIString& key, const UIString& value)override;
virtual ~VLayout();
};
using VBox = VLayout;
};

View File

@@ -1,22 +0,0 @@
#pragma once
#include "PagedListView.h"
#include "VScrollBar.h"
namespace ezui {
class UI_EXPORT VListView :
public PagedListView
{
private:
VScrollBar m_vScrollBar;
void Init();
//对控件进行偏移
void Offset(int offset);
protected:
virtual void OnLayout()override;
virtual void OnChildPaint(PaintEventArgs& args)override;
public:
VListView(Object* parentObject = NULL);
virtual ~VListView();
virtual ScrollBar* GetScrollBar() override;
};
};

View File

@@ -1,22 +0,0 @@
#pragma once
#include "Control.h"
#include "ScrollBar.h"
namespace ezui {
class UI_EXPORT VScrollBar :
public ScrollBar
{
protected:
virtual void OnMouseDown(const MouseEventArgs& arg)override;
virtual void OnMouseMove(const MouseEventArgs& arg)override;
virtual void GetInfo(int* viewLength, int* contentLength, int* scrollBarLength)override;
public:
VScrollBar(Object* parentObject = NULL);
virtual ~VScrollBar();
virtual void ScrollTo(Control* ctl)override;
virtual void ParentSize(const Size& size)override;
virtual Rect GetSliderRect()override;
};
};

View File

@@ -1,267 +0,0 @@
#pragma once
#include "Control.h"
#include "ScrollBar.h"
#include "Spacer.h"
#undef IsMinimized
#undef IsMaximized
#undef IsRestored
namespace ezui {
/// <summary>
/// Window //经典带边框带系统菜单WIN32窗口样式
/// </summary>
class UI_EXPORT Window :public Object
{
private:
//具有鼠标焦点的控件
Control* m_focusControl = NULL;
//具有键盘焦点的控件
Control* m_inputControl = NULL;
//窗口公共数据
WindowData* m_publicData = NULL;
//窗口句柄
HWND m_hWnd = NULL;
//鼠标跟踪
bool m_bTracking = false;
//鼠标是否在里面
bool m_mouseIn = false;
//鼠标是否已经按下
bool m_mouseDown = false;
//窗口移动
bool m_moveWindow = false;
//记录鼠标坐标
POINT m_dragPoint;
//记录鼠标按下的坐标
Point m_downPoint;
//上一次鼠标按下的时间
ULONGLONG m_lastDownTime = 0;
//上一次鼠标按下的按钮
MouseButton m_lastBtn = MouseButton::None;
//窗口最小尺寸
Size m_miniSize;
//窗口最大尺寸
Size m_maxSize;
//当窗口关闭的时候退出代码
int m_closeCode = 0;
//基于桌面的坐标
Rect m_rect;
//客户绘图区域
Rect m_rectClient;
//所属窗口句柄
HWND m_ownerWnd = NULL;
//窗口根Frame
IFrame* m_frame = NULL;
// 管理图片的释放
PtrManager<Image*> m_imgs;
public:
//对外暴露消息通知回调
std::function<void(Control*, EventArgs&)> NotifyHandler = NULL;
private:
Window(const Window&) = delete;
Window& operator=(const Window&) = delete;
bool IsInWindow(Control& pControl, Control& it);
void Init(int width, int height, HWND owner, DWORD dStyle, DWORD dwExStyle);//初始窗口
//仅移动窗口
void MoveWindow();
//鼠标按下以标题栏方式移动窗口
void TitleMoveWindow();
//在窗口中使用基于客户区的鼠标位置寻找可命中的控件
Control* HitTestControl(const Point& clientPoint, Point* outPoint);
//派发事件
void SendEvent(Control* ctrl, const EventArgs& args);
protected:
//当dpi发生更改时
virtual void OnDpiChange(float systemScale, const Rect& newRect);
//鼠标移动时发生
virtual void OnMouseMove(const Point& point);
//当鼠标悬停时发生
virtual void OnMouseHover(const Point& point);
//鼠标离开时发生
virtual void OnMouseLeave();
//鼠标滚动发生
virtual void OnMouseWheel(int zDelta, const Point& point);
//鼠标双击是发生
virtual void OnMouseDoubleClick(MouseButton mbtn, const Point& point);
//鼠标按下时发生
virtual void OnMouseDown(MouseButton mbtn, const Point& point);
//鼠标弹起时发生
virtual void OnMouseUp(MouseButton mbtn, const Point& point);
//生成渲染器 渲染参数
virtual void DoPaint(HDC winDC, const Rect& rePaint);
//渲染中
virtual void OnPaint(PaintEventArgs& arg);
//位置发生改变时发生
virtual void OnMove(const Point& point);
//大小发生改变时发生
virtual void OnSize(const Size& sz);
//当窗口收到WM_CLOSE消息时发生
virtual void OnClose(bool& bClose);
//当窗口销毁时发生
virtual void OnDestroy();
//字符消息
virtual void OnKeyChar(WPARAM wParam, LPARAM lParam);
//键盘按下
virtual void OnKeyDown(WPARAM wParam, LPARAM lParam);
//键盘抬起
virtual void OnKeyUp(WPARAM wParam, LPARAM lParam);
//获得输入焦点时发生
virtual void OnFocus(HWND hWnd);
//失去输入焦点时发生
virtual void OnKillFocus(HWND hWnd);
//鼠标 键盘 重绘 会进入此函数,如果返回true则事件将不再交给sender控件处理 将忽略类似OnMouseDown... Notiify事件处理器...
virtual void OnNotify(Control* sender, EventArgs& args);
//处理消息队列的
virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
//获取阴影窗口句柄
virtual HWND GetShadowHwnd();
public:
Window(int width, int height, HWND owner = NULL, DWORD dStyle = WS_OVERLAPPEDWINDOW, DWORD dwExStyle = NULL);
virtual ~Window();
//使用id寻找控件
Control* FindControl(const UIString& objectName);
//获取公共数据
WindowData* GetPublicData();
//窗口句柄
HWND Hwnd();
//获取窗口X坐标
int X();
//获取窗口Y坐标
int Y();
// 获取窗口宽度
int Width();
// 获取窗口高度
int Height();
//获取窗口基于显示器的矩形
const Rect& GetWindowRect();
//获取客户区矩形
const Rect& GetClientRect();
//获取当前窗口dpi缩放系数
float GetScale();
//设置窗口size
void SetSize(const Size& size);
//设置窗口位置
void SetLocation(const Point& pt);
//设置窗口位置大小
void SetRect(const Rect& rect);
//设置窗口最小size
void SetMiniSize(const Size& size);
//设置窗口最大size
void SetMaxSize(const Size& size);
//设置绝对宽高
void SetFixedSize(const Size& size);
//设置窗口icon
void SetIcon(HICON icon);
//设置窗口主布局
void SetLayout(ezui::Control* layout);
//从文件中加载布局
void LoadXml(const UIString& fileName);
//从内存加载布局
void LoadXml(const char* fileData, size_t fileSize);
//获取窗口主布局
Control* GetLayout();
//设置窗口标题
void SetText(const UIString& text);
//获取窗口标题
UIString GetText();
//设置与取消窗口置顶
void SetTopMost(bool top);
//是否全屏
bool IsFullScreen();
//是否最小化
bool IsMinimized();
//窗口是否最大化
bool IsMaximized();
//窗口是否置顶
bool IsTopMost();
//操作窗口的显示
virtual void Show();
//操作窗口的显示 带参数
void Show(int cmdShow);
//隐藏窗口
virtual void Hide();
//正常显示窗口
void ShowNormal();
//关闭窗口 exitCode为退出代码
void Close(int exitCode = 0);
//模态窗口方式显示窗口(会阻塞) 请务必在窗口构造函数中传入owner窗口句柄
virtual int ShowModal(bool disableOnwer = true);
//最小化窗口
void ShowMinimized();
//最大化窗口
void ShowMaximized();
//让窗口占满当前屏幕
void ShowFullScreen();
//窗口是否显示
bool IsVisible();
//设置窗口显示/隐藏
void SetVisible(bool flag);
//使区域无效(延迟刷新)
void Invalidate();
//立即更新所有无效区域(立即刷新)
void Refresh();
//居中到屏幕
void CenterToScreen();
//参考某个窗口进行居中
void CenterToWindow(HWND wnd = NULL);
//给指定控件为焦点控件
void SetFocus(Control* ctl);
//绑定对象(跟随释放)
using Object::Attach;
//分离对象(解除跟随释放)
using Object::Detach;
//绑定图片(跟随释放)
Image* Attach(Image* img);
//分离图片(解除跟随释放)
void Detach(Image* img);
};
};

View File

@@ -1,303 +0,0 @@
/*
www.sourceforge.net/projects/tinyxml
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#pragma once
#ifndef TIXML_USE_STL
#include <assert.h>
#include <string.h>
/* The support for explicit isn't that universal, and it isn't really
required - it is used to check that the TiXmlString class isn't incorrectly
used. Be nice to old compilers and macro it here:
*/
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
// Microsoft visual studio, version 6 and higher.
#define TIXML_EXPLICIT explicit
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
// GCC version 3 and higher.s
#define TIXML_EXPLICIT explicit
#else
#define TIXML_EXPLICIT
#endif
namespace ezui {
/*
TiXmlString is an emulation of a subset of the std::string template.
Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
Only the member functions relevant to the TinyXML project have been implemented.
The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase
a string and there's no more room, we allocate a buffer twice as big as we need.
*/
class TiXmlString
{
public:
// The size type used
typedef size_t size_type;
// Error value for find primitive
static const size_type npos; // = -1;
// TiXmlString empty constructor
TiXmlString() : rep_(&nullrep_)
{
}
// TiXmlString copy constructor
TiXmlString(const TiXmlString& copy) : rep_(0)
{
init(copy.length());
memcpy(start(), copy.data(), length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString(const char* copy) : rep_(0)
{
init(static_cast<size_type>(strlen(copy)));
memcpy(start(), copy, length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString(const char* str, size_type len) : rep_(0)
{
init(len);
memcpy(start(), str, len);
}
// TiXmlString destructor
~TiXmlString()
{
quit();
}
TiXmlString& operator = (const char* copy)
{
return assign(copy, (size_type)strlen(copy));
}
TiXmlString& operator = (const TiXmlString& copy)
{
return assign(copy.start(), copy.length());
}
// += operator. Maps to append
TiXmlString& operator += (const char* suffix)
{
return append(suffix, static_cast<size_type>(strlen(suffix)));
}
// += operator. Maps to append
TiXmlString& operator += (char single)
{
return append(&single, 1);
}
// += operator. Maps to append
TiXmlString& operator += (const TiXmlString& suffix)
{
return append(suffix.data(), suffix.length());
}
// Convert a TiXmlString into a null-terminated char *
const char* c_str() const { return rep_->str; }
// Convert a TiXmlString into a char * (need not be null terminated).
const char* data() const { return rep_->str; }
// Return the length of a TiXmlString
size_type length() const { return rep_->size; }
// Alias for length()
size_type size() const { return rep_->size; }
// Checks if a TiXmlString is empty
bool empty() const { return rep_->size == 0; }
// Return capacity of string
size_type capacity() const { return rep_->capacity; }
// single char extraction
const char& at(size_type index) const
{
assert(index < length());
return rep_->str[index];
}
// [] operator
char& operator [] (size_type index) const
{
assert(index < length());
return rep_->str[index];
}
// find a char in a string. Return TiXmlString::npos if not found
size_type find(char lookup) const
{
return find(lookup, 0);
}
// find a char in a string from an offset. Return TiXmlString::npos if not found
size_type find(char tofind, size_type offset) const
{
if (offset >= length()) return npos;
for (const char* p = c_str() + offset; *p != '\0'; ++p)
{
if (*p == tofind) return static_cast<size_type>(p - c_str());
}
return npos;
}
void clear()
{
//Lee:
//The original was just too strange, though correct:
// TiXmlString().swap(*this);
//Instead use the quit & re-init:
quit();
init(0, 0);
}
/* Function to reserve a big amount of data when we know we'll need it. Be aware that this
function DOES NOT clear the content of the TiXmlString if any exists.
*/
void reserve(size_type cap);
TiXmlString& assign(const char* str, size_type len);
TiXmlString& append(const char* str, size_type len);
void swap(TiXmlString& other)
{
Rep* r = rep_;
rep_ = other.rep_;
other.rep_ = r;
}
private:
void init(size_type sz) { init(sz, sz); }
void set_size(size_type sz) { rep_->str[rep_->size = sz] = '\0'; }
char* start() const { return rep_->str; }
char* finish() const { return rep_->str + rep_->size; }
struct Rep
{
size_type size, capacity;
char str[1];
};
void init(size_type sz, size_type cap)
{
if (cap)
{
// Lee: the original form:
// rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
// doesn't work in some cases of new being overloaded. Switching
// to the normal allocation, although use an 'int' for systems
// that are overly picky about structure alignment.
const size_type bytesNeeded = sizeof(Rep) + cap;
const size_type intsNeeded = (bytesNeeded + sizeof(int) - 1) / sizeof(int);
rep_ = reinterpret_cast<Rep*>(new int[intsNeeded]);
rep_->str[rep_->size = sz] = '\0';
rep_->capacity = cap;
}
else
{
rep_ = &nullrep_;
}
}
void quit()
{
if (rep_ != &nullrep_)
{
// The rep_ is really an array of ints. (see the allocator, above).
// Cast it back before delete, so the compiler won't incorrectly call destructors.
delete[](reinterpret_cast<int*>(rep_));
}
}
Rep* rep_;
static Rep nullrep_;
};
inline bool operator == (const TiXmlString& a, const TiXmlString& b)
{
return (a.length() == b.length()) // optimization on some platforms
&& (strcmp(a.c_str(), b.c_str()) == 0); // actual compare
}
inline bool operator < (const TiXmlString& a, const TiXmlString& b)
{
return strcmp(a.c_str(), b.c_str()) < 0;
}
inline bool operator != (const TiXmlString& a, const TiXmlString& b) { return !(a == b); }
inline bool operator > (const TiXmlString& a, const TiXmlString& b) { return b < a; }
inline bool operator <= (const TiXmlString& a, const TiXmlString& b) { return !(b < a); }
inline bool operator >= (const TiXmlString& a, const TiXmlString& b) { return !(a < b); }
inline bool operator == (const TiXmlString& a, const char* b) { return strcmp(a.c_str(), b) == 0; }
inline bool operator == (const char* a, const TiXmlString& b) { return b == a; }
inline bool operator != (const TiXmlString& a, const char* b) { return !(a == b); }
inline bool operator != (const char* a, const TiXmlString& b) { return !(b == a); }
TiXmlString operator + (const TiXmlString& a, const TiXmlString& b);
TiXmlString operator + (const TiXmlString& a, const char* b);
TiXmlString operator + (const char* a, const TiXmlString& b);
/*
TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString.
Only the operators that we need for TinyXML have been developped.
*/
class TiXmlOutStream : public TiXmlString
{
public:
// TiXmlOutStream << operator.
TiXmlOutStream& operator << (const TiXmlString& in)
{
*this += in;
return *this;
}
// TiXmlOutStream << operator.
TiXmlOutStream& operator << (const char* in)
{
*this += in;
return *this;
}
};
};
#endif // TIXML_USE_STL

File diff suppressed because it is too large Load Diff

View File

@@ -1,33 +0,0 @@
#pragma once
#include "EzUI.h"
#include "Timer.h"
namespace ezui {
class UI_EXPORT Animation : public Object {
private:
TimerClock m_timer;
float m_startValue = 0;
float m_endValue = 0;
float m_currValue = 0;
std::atomic<bool> m_tickPending = false;
std::shared_ptr<std::atomic<bool>> m_alive;
bool m_finished = true;
float m_damping = 1.0f;
public:
//当值更改的时候发生的事件(请绑定此函数进行回调,已处理线程同步)
std::function<void(float)> ValueChanged;
Animation(Object* ownerObject = NULL);
virtual ~Animation();
void SetStartValue(float value);
void SetEndValue(float value);
//开始动画
void Start(int durationMs, int fps = 90);
//动画是否已经停止(判断的是计时器状态)
bool IsStopped()const;
//动画是否已跑完(判断起始值和结束值)
bool IsFinished()const;
void Stop();
};
};

View File

@@ -1,24 +0,0 @@
#pragma once
#include "Window.h"
#include "Resource.h"
namespace ezui {
class UI_EXPORT Application
{
public:
//退出消息循环
static void Exit(int exitCode = 0);
//获取程序启动路径
static UIString StartPath();
public:
Application(HINSTANCE hInstance = NULL);
//使用本地文件名称或者资源中的名称加载资源包
//填入vs中的资源ID名称 或者 本地文件名 一个Application只允许有一个资源文件
bool SetResource(const UIString& localOrResName);
//启用高DPI适配
void EnableHighDpi();
virtual ~Application();
//执行消息循环
int Exec();
};
};

View File

@@ -1,34 +0,0 @@
#pragma once
#include "EzUI.h"
namespace ezui {
//BGRA 32位图
class UI_EXPORT Bitmap {
private:
int m_width = 0;
int m_height = 0;
HBITMAP m_bmp = NULL;
HDC m_hdc = NULL;
uint8_t* m_point = NULL;
BITMAPINFO m_bmpInfo;
Bitmap(const Bitmap& hBitmap) = delete;
void operator=(const Bitmap& hBitmap) = delete;
protected:
void Create(int width, int height);
public:
int Width()const;
int Height()const;
//BGRA 32位图
Bitmap(int width, int height);
Bitmap(HDC dc, const Rect& rect);
void SetPixel(int x, int y, const Color& color);
Color GetPixel(int x, int y)const;
uint8_t* GetPixel();
void Earse(const Rect& rect);//抹除矩形内容
HBITMAP GetHBITMAP();
HDC GetDC();
bool Save(const UIString& fileName);
Bitmap* Clone()const;
virtual ~Bitmap();
};
};

View File

@@ -1,41 +0,0 @@
#pragma once
#include "Window.h"
#include "ShadowBox.h"
namespace ezui {
/// <summary>
/// BorderlessWindow //无边框 带阴影
/// </summary>
class UI_EXPORT BorderlessWindow :public Window {
private:
int m_shadowWeight = 20;
ShadowBox* m_shadowBox = NULL;
float m_shadowScale = 1.0f;
//是否支持缩放
bool m_bResize = false;
//是否第一次已经绘制
bool isFirstPaint = false;
protected:
virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)override;
virtual void DoPaint(HDC winDC, const Rect& rePaint)override;
virtual void OnMove(const Point& location) override;
virtual void OnSize(const Size& sz) override;
virtual void OnDpiChange(float systemScale, const Rect& newRect);//当dpi发生更改时
virtual HWND GetShadowHwnd()override;//获取阴影窗口句柄
public:
//设置阴影宽度
void SetShadow(int weight);
BorderlessWindow(int width, int height, HWND owner = NULL, DWORD dwStyle = NULL, DWORD dwExStyle = NULL);
virtual ~BorderlessWindow();
//更新窗口阴影
void UpdateShadowBox();
//获取阴影窗口
ShadowBox* GetShadowBox();
//关闭窗口阴影 关掉阴影窗口 已有的边框也会随之消失
void CloseShadowBox();
//设置窗口缩放支持
void SetResizable(bool resize);
//是否支持调整大小
bool IsResizable();
};
};

View File

@@ -1,14 +0,0 @@
#pragma once
#include "Label.h"
namespace ezui {
class UI_EXPORT Button :
public Label
{
private:
void Init();
public:
Button(Object* ownerObject = NULL);
virtual ~Button();
};
};

View File

@@ -1,30 +0,0 @@
#pragma once
#include "Label.h"
namespace ezui {
class UI_EXPORT CheckBox :
public Label
{
private:
bool m_checked = false;
public:
//选中样式
ControlStyle CheckedStyle;
//选中状态发送变化的回调函数
std::function<void(CheckBox* sender, bool checked)> CheckedChanged = NULL;
protected:
virtual ControlStyle& GetStyle(const ControlState& _state)override;
virtual void OnMouseDown(const MouseEventArgs& arg)override;
virtual void OnDpiChange(const DpiChangeEventArgs& args)override;
public:
CheckBox(Object* ownerObject = NULL);
virtual void SetAttribute(const UIString& key, const UIString& value)override;
//设置选中状态
virtual void SetCheck(bool checked);
//获取选中状态
virtual bool GetCheck();
virtual ~CheckBox();
};
};

View File

@@ -1,53 +0,0 @@
#pragma once
#include "TextBox.h"
#include "Label.h"
#include "VListView.h"
#include "PopupWindow.h"
#include "HLayout.h"
namespace ezui {
//简易的下拉列表框
class UI_EXPORT ComboBox :public HLayout {
private:
//添加选项请使用AddItem
virtual Control* AddChild(Control* childCtl)override;
//移除选项请使用RemoveItem
virtual void RemoveChild(Control* childCtl, bool freeCtrl)override;
private:
//下拉菜单选项
class MenuContent :public PopupWindow {
public:
Control* m_ownerCtrl;
Control* m_hittestCtl;
MenuContent(Control* ownerCtl, Control* hittestCtl);
virtual void OnKillFocus(HWND wnd) override;
virtual void Show() override;
virtual ~MenuContent();
};
private:
//下拉菜单窗口
MenuContent* m_menuWnd = NULL;
//选择之后显示的文本框
TextBox m_textBox;
//展开菜单的按钮
Label m_UpDown;
VListView m_list;
int m_index = -1;
void Init();
protected:
virtual void OnLayout()override;
public:
ComboBox(Object* ownerObject = NULL);
//获取选中的文字
UIString GetText();
//获取选中的下标
int GetCheck();
//选中某个下标
bool SetCheck(int pos);
virtual ~ComboBox();
//添加一个item并返回新item的下标
int AddItem(const UIString& text);
void RemoveItem(int index);
};
};

View File

@@ -1,659 +0,0 @@
#pragma once
#include "EzUI.h"
namespace ezui {
class UI_EXPORT Control :public Object
{
friend class HListView;
friend class VListView;
friend class TabLayout;
friend class TileListView;
friend class TextBox;
friend class UILoader;
friend class Frame;
friend class CheckBox;
friend class Window;
friend class ScrollBar;
friend class VLayout;
friend class HLayout;
private:
//顶层窗口句柄
HWND m_hWnd = NULL;
// 控件是否已经被移除或释放
bool* m_bRemove = NULL;
//控件是否被为按住状态
bool m_pressed = false;
// 控件是否可见。此标志为 true 时,控件为显示状态
bool m_bVisible = true;
//控件是否浮动
bool m_float = false;
// 当前控件的 DPI 缩放比例
float m_scale = 1.0f;
// 子控件集合
ControlCollection m_controls;
// 管理图片的释放
PtrManager<Image*> m_imgs;
// 布局状态
// AddControl、InsertControl、RemoveControl、OnSize 时此标志为挂起状态
// 调用 ResumeLayout 标志为布局中
// 调用 OnLayout() 之后标志为 None
ezui::LayoutState m_layoutState = ezui::LayoutState::None;
// 鼠标悬浮提示文字
UIString m_tipsText;
// 上一次位置
Point m_lastLocation;
// 上一次大小
Size m_lastSize;
// 是否根据内容自动宽度
bool m_bAutoWidth = false;
// 根据内容自动高度变化
bool m_bAutoHeight = false;
// 控件内容宽高
Size m_contentSize;
// 绝对尺寸
Size m_fixedSize;
//比例尺寸
SizeF m_rateSize;
//最小宽高
Size m_minSize;
//最大宽高
Size m_maxSize;
//基于父控件矩形区域
Rect m_realRect;
//基于客户端的矩形区域
Rect m_rectInClient;
//基于窗口剪裁过的区域
Rect m_viewClipRect;
// 控件是否可以被命中(值为false情况下就是穿透效果)
bool m_hitTestEnabled = true;
//存储的样式集合
std::list<ezui::Style> m_styles;
// 基于控件中的可见控件集合
ControlCollection m_viewControls;
// 父控件指针
Control* m_parent = NULL;
// 控件当前状态
ControlState m_state = ControlState::Static;
// 外边距
// 当父控件为布局控件或列表控件时生效(不可为负数)
Distance m_margin;
public:
// 控件的 ObjectName ID
UIString Name;
// 控件行为
ControlAction Action = ControlAction::None;
// 静态默认样式
ControlStyle Style;
//具有焦点的时候的样式
ControlStyle FocusStyle;
//禁用状态样式
ControlStyle DisabledStyle;
// 鼠标悬浮样式
ControlStyle HoverStyle;
// 鼠标按下样式
ControlStyle ActiveStyle;
//是否添加到所在窗口/IFrame中的OnNotify函数中
Event NotifyFlags = Event::OnMouseEvent | Event::OnKeyBoardEvent;
// 事件处理器
std::function<void(Control*, EventArgs&)> EventHandler = NULL;
private:
// 禁止拷贝构造
Control(const Control&) = delete;
// 禁止赋值
Control& operator=(const Control&) = delete;
// 计算基于父控件的裁剪区域
void ComputeClipRect();
// 所有事件优先进入此函数(内部处理)
void OnEvent(EventArgs& arg);
//递归子控件给匹配成功的样式应用上
void ApplyChildStyles(const std::list<ezui::Style>& styles);
//向上匹配样式(直到所属的Frame层)
void ApplyParentStyles();
protected:
//属性或者css样式都适用(css样式和属性都可以设置这些,只对静态样式生效)
virtual bool ApplyStyleProperty(const UIString& key, const UIString& value);
/// <summary>
/// 为当前控件的指定状态设置单个样式属性
/// </summary>
/// <param name="style">目标状态样式对象,例如 this->HoverStyle</param>
/// <param name="key">样式键名,例如 "font-size"</param>
/// <param name="value">样式值,例如 "13px"</param>
virtual void SetStyle(ControlStyle& style, const UIString& key, const UIString& value);
// 设置内容宽度,仅限子类使用
virtual void SetContentWidth(int width);
// 设置内容高度,仅限子类使用
virtual void SetContentHeight(int height);
// 设置内容尺寸,仅限子类使用
virtual void SetContentSize(const Size& size);
// 绘制之前
virtual void OnPaintBefore(PaintEventArgs& args);
// 控件绘制
virtual void OnPaint(PaintEventArgs& args);
// 子控件绘制,可重载此函数优化鼠标操作性能
virtual void OnChildPaint(PaintEventArgs& args);
// 背景绘制
virtual void OnBackgroundPaint(PaintEventArgs& painter);
// 前景绘制
virtual void OnForePaint(PaintEventArgs& e);
// 边框绘制
virtual void OnBorderPaint(PaintEventArgs& painter, const Border& border);
// 坐标发生改变
virtual void OnMove(const MoveEventArgs& arg);
// 大小发生改变
virtual void OnSize(const SizeEventArgs& arg);
// DPI 发生改变
virtual void OnDpiChange(const DpiChangeEventArgs& arg);
// 控件布局逻辑,需重写布局请重写此函数
virtual void OnLayout();
// 鼠标在控件上移动
virtual void OnMouseMove(const MouseEventArgs& arg);
// 鼠标离开控件
virtual void OnMouseLeave(const MouseEventArgs& args);
// 鼠标滚轮事件
virtual void OnMouseWheel(const MouseEventArgs& arg);
// 鼠标按下事件
virtual void OnMouseDown(const MouseEventArgs& arg);
// 鼠标弹起事件
virtual void OnMouseUp(const MouseEventArgs& arg);
// 鼠标双击事件
virtual void OnMouseDoubleClick(const MouseEventArgs& arg);
// 鼠标移入控件
virtual void OnMouseEnter(const MouseEventArgs& arg);
// 鼠标事件统一入口
virtual void OnMouseEvent(const MouseEventArgs& args);
// 键盘事件统一入口
virtual void OnKeyBoardEvent(const KeyboardEventArgs& _args);
// 字符输入事件WM_CHAR
virtual void OnKeyChar(const KeyboardEventArgs& _args);
// 键盘按下事件WM_KEYDOWN
virtual void OnKeyDown(const KeyboardEventArgs& _args);
// 键盘弹起事件WM_KEYUP
virtual void OnKeyUp(const KeyboardEventArgs& _args);
// 获得焦点事件
virtual void OnFocus(const FocusEventArgs& _args);
// 失去焦点事件
virtual void OnKillFocus(const KillFocusEventArgs& _args);
// 被移除时执行的逻辑
virtual void OnRemove();
public:
// 获取当前控件状态下的样式信息
virtual ControlStyle& GetStyle(const ControlState& _state);
// 获取左上圆角半径
Value<int16_t> GetBorderTopLeftRadius(ControlState _state = ControlState::None);
// 获取右上圆角半径
Value<int16_t> GetBorderTopRightRadius(ControlState _state = ControlState::None);
// 获取右下圆角半径
Value<int16_t> GetBorderBottomRightRadius(ControlState _state = ControlState::None);
// 获取左下圆角半径
Value<int16_t> GetBorderBottomLeftRadius(ControlState _state = ControlState::None);
// 获取左边框宽度
Value<int16_t> GetBorderLeft(ControlState _state = ControlState::None);
// 获取上边框宽度
Value<int16_t> GetBorderTop(ControlState _state = ControlState::None);
// 获取右边框宽度
Value<int16_t> GetBorderRight(ControlState _state = ControlState::None);
// 获取下边框宽度
Value<int16_t> GetBorderBottom(ControlState _state = ControlState::None);
// 获取边框颜色
Value<Color> GetBorderColor(ControlState _state = ControlState::None);
//获取边框样式
Value<StrokeStyle> GetBorderStyle(ControlState _state = ControlState::None);
// 获取前景图片
Value<Image*> GetForeImage(ControlState _state = ControlState::None);
// 获取背景图片
Value<Image*> GetBackImage(ControlState _state = ControlState::None);
// 获取背景颜色
Value<Color> GetBackColor(ControlState _state = ControlState::None);
// 获取旋转角度
Value<float> GetAngle(ControlState _state = ControlState::None);
// 获取透明度
Value<float> GetOpacity(ControlState _state = ControlState::None);
//获取当前控件的鼠标光标
virtual Value<HCURSOR> GetCursor(ControlState _state = ControlState::None);
// 获取前景颜色
Value<Color> GetForeColor(ControlState _state = ControlState::None);
// 获取字体 Family
Value<std::wstring> GetFontFamily(ControlState _state = ControlState::None);
// 获取字体大小
Value<int> GetFontSize(ControlState _state = ControlState::None);
// 获取字体粗度
Value<int> GetFontWeight(ControlState _state = ControlState::None);
//获取公共数据
WindowContext* GetWindowContext();
//获取上层Frame容器
Frame* GetFrame();
public:
// 构造函数 可传入父对象(由父对象自动管理内存)
Control(Object* ownerObject = NULL);
// 析构函数
virtual ~Control();
//绑定对象(跟随释放)
using Object::Attach;
//分离对象(解除跟随释放)
using Object::Detach;
//绑定图片(跟随释放)
Image* Attach(Image* img);
//分离图片(解除跟随释放)
void Detach(Image* img);
//窗口句柄
HWND Hwnd();
//设置窗口句柄
void SetHwnd(HWND hWnd);
// 以下函数请保证在父控件布局已完成的情况下使用,使用 ResumeLayout() 执行布局
// 获取 X 坐标
int X();
// 获取 Y 坐标
int Y();
// 获取宽度
int Width();
// 获取高度
int Height();
//计算带有策略的宽度
int CalcWidth();
//计算带有策略的度
int CalcHeight();
// 设置 X 坐标
void SetX(int X);
// 设置 Y 坐标
void SetY(int Y);
// 移动相对于父控件的位置
void SetLocation(const Point& pt);
// 设置控件大小(当重绘控件时不建议多次使用,影响性能,会调用 SetRect 函数)
void SetSize(const Size& size);
// 设置绝对宽高
void SetFixedSize(const Size& size);
// 设置宽度(当重绘控件时不建议多次使用,影响性能,会调用 SetRect 函数)
void SetWidth(int width);
// 设置高度(当重绘控件时不建议多次使用,影响性能,会调用 SetRect 函数)
void SetHeight(int height);
// 设置绝对宽度
void SetFixedWidth(int fixedWidth);
// 设置绝对高度
void SetFixedHeight(int fixedHeight);
//设置基于父控件百分比宽度(0~1.0f)
void SetRateWidth(float rateWidth);
//设置基于父控件百分比高度(0~1.0f)
void SetRateHeight(float rateHeight);
// 设置基于父控件百分比宽高(0.0f~1.0f)
void SetRateSize(const SizeF& size);
// 设置相对父控件矩形,返回实际的 rect
const Rect& SetRect(const Rect& rect);
// 获取绝对宽度
int GetFixedWidth();
// 获取绝对高度
int GetFixedHeight();
// 获取最小宽度
int GetMinWidth();
// 获取最小高度
int GetMinHeight();
// 获取最大宽度
int GetMaxWidth();
// 获取最大高度
int GetMaxHeight();
// 设置最小宽度
void SetMinWidth(int w);
// 设置最小高度
void SetMinHeight(int h);
// 设置最大宽度
void SetMaxWidth(int w);
// 设置最大高度
void SetMaxHeight(int h);
//设置最小size
void SetMinSize(const Size& sz);
//设置最大size
void SetMaxSize(const Size& sz);
// 获取光标位置
virtual Rect GetCareRect();
// 是否自动宽度
virtual bool IsAutoWidth();
// 是否自动高度
virtual bool IsAutoHeight();
// 设置自动宽度
virtual void SetAutoWidth(bool flag);
// 设置自动高度
virtual void SetAutoHeight(bool flag);
// 设置自动大小
virtual void SetAutoSize(bool flag);
// 获取控件内容大小
virtual const Size& GetContentSize();
// 获取控件大小
Size GetSize();
// 获取控件位置
Point GetLocation();
// 获取相对于父控件的矩形(布局计算后)
virtual const Rect& GetRect();
// 获取基于客户端区域的矩形
Rect GetRectInClient();
//获取控件基于屏幕的矩形位置
Rect GetRectInScreen();
//获取控件基于Frame层的矩形位置
Rect GetRectInFrame();
// 获取控件的缩放系数
float GetScale();
// 是否存在挂起的布局
bool IsPendLayout();
// 尝试挂起布局,返回当前布局状态
const LayoutState TryPendLayout();
// 获取当前布局状态
const LayoutState GetLayoutState();
// 结束当前布局(使其立即生效)
void EndLayout();
// 立即强制刷新布局
virtual void RefreshLayout();
// 设置提示文字(类似 tooltip
void SetTips(const UIString& text);
// 获取提示文字
const UIString& GetTips();
// 获取控件的滚动条对象
virtual ScrollBar* GetScrollBar();
// 派发事件(如鼠标单击事件等...返回true则事件成功派发 返回false代表派发途中当前控件已被释放
void SendEvent(const EventArgs& arg);
// 设置控件属性
virtual void SetAttribute(const UIString& attrName, const UIString& attrValue);
// 获取当前可见的子控件集合
const ControlCollection& GetCachedViewControls();
//获取父控件
Control* GetParent();
// 获取所有子控件集合
const ControlCollection& GetControls();
// 使用下标获取控件,自动跳过 spacer 类控件
Control* GetControl(int pos);
// 是否包含指定控件(递归遍历所有子控件)
bool Contains(Control* ctrl);
// 获取指定子控件的索引
int IndexOf(Control* childCtl);
// 根据 name 查找控件(包括自身)
Control* FindControl(const UIString& ctrlName);
// 根据属性查找所有匹配控件(包括自身)
ControlCollection FindControls(const UIString& attrName, const UIString& attrValue);
// 根据 name 查找子控件(仅限直接子集)
Control* FindChild(const UIString& ctlName);
// 根据属性查找所有匹配的子控件(仅限直接子集)
ControlCollection FindChildren(const UIString& attrName, const UIString& attrValue);
// 交换两个子控件的位置
virtual bool SwapChildren(Control* childCtl, Control* childCt2);
//是否启用控件
void SetEnabled(bool flag);
//是否禁用控件
void SetDisabled(bool flag);
//控件是否已启用
bool IsEnabled();
// 在指定位置插入子控件
virtual Control* InsertChild(int pos, Control* childCtl);
// 添加控件到末尾(如果是弹簧控件,在释放时将自动销毁)
virtual Control* AddChild(Control* childCtrl);
//解析xml字符串并添加到控件集合末尾
virtual Control* Append(const UIString& xmlStr);
//解析xml字符串并添加到控件集合第一位
virtual Control* Prepend(const UIString& xmlStr);
// 移除控件freeCtrl 标志是否释放控件内存
virtual void RemoveChild(Control* childCtl, bool freeCtrl = false);
//移除并且销毁全部弹簧
void DestroySpacers();
// 设置控件的父控件
virtual void SetParent(Control* parentCtl);
// 移除所有子控件
virtual void RemoveAll();
// 移除所有子控件freeChilds 决定是否释放子控件内存
virtual void RemoveAll(bool freeAll);
//是否为弹簧控件
virtual bool IsSpacer();
//是否为Frame
virtual bool IsFrame();
// 设置控件浮动
virtual void SetFloat(bool flag);
// 控件是否浮动
virtual bool IsFloat();
// 设置控件可见性
virtual void SetVisible(bool flag);
// 获取控件可见性状态
virtual bool IsVisible();
//设置控件是否可以被鼠标命中(false则是鼠标穿透效果)
void SetHitTestVisible(bool bEnable);
//控件是否可以被命中
bool IsHitTestVisible();
//隐藏控件
void Hide();
//显示控件
void Show();
// 标记控件区域为无效将会延迟刷新UI
virtual bool Invalidate();
// 立即强制刷新控件区域并更新无效区域(且立即触发布局)
virtual void Refresh();
/// <summary>
/// 为当前控件的指定状态批量设置样式(使用分号分隔)
/// </summary>
/// <param name="state">控件状态,例如 ControlState::Hover</param>
/// <param name="styleStr">样式字符串,例如 "font-size: 13px; color: #ffffff;"</param>
virtual void SetStyleSheet(ControlState state, const UIString& styleStr);
/// <summary>
/// 设置样式集合,并自动匹配应用到符合条件的子控件
/// </summary>
/// <param name="styleStr">样式字符串,例如 "#btn:hover { font-size:13px; }"</param>
virtual void SetStyleSheet(const UIString& styleStr);
//设置基于父控件的边距四周边距
void SetMargin(int allMargin);
//设置基于父控件的边距上下边距
void SetMargin(int topBottom, int leftRight);
//设置基于父控件的上边距
void SetMarginTop(int topMargin);
//设置基于父控件的左边距
void SetMarginLeft(int leftMargin);
//设置基于父控件的右边距
void SetMarginRight(int rightMargin);
//设置基于父控件的下边距
void SetMarginBottom(int bottomMargin);
//设置基于父控件的边距 上 右 下 左
void SetMargin(int top, int right, int bottom, int left);
//获取基于父控件的边距信息;
const Distance& GetMargin();
//控件是否被按住
bool IsPressed();
//给当前控件设置为焦点控件
void SetFocus();
};
};

View File

@@ -1,280 +0,0 @@
#pragma once
#include "UIDef.h"
#if USED_DIRECT2D
#ifndef UI_EXPORT
#define UI_EXPORT
#endif
#include <d2d1.h>
#include <d2d1helper.h>
#include <dwrite.h>
#include <wincodec.h>
#include "RenderTypes.h"
namespace ezui {
UI_EXPORT void RenderInitialize();//全局初始化direct2d
UI_EXPORT void RenderUnInitialize();//释放direct2d
UI_EXPORT float GetMaxRadius(float width, float height, float _radius);//获取最大半径 用于自动适应border-radius属性
class UI_EXPORT Font {
private:
Font() = delete;
std::wstring m_fontFamily;
float m_fontSize = 0;
int m_fontWeight = 0;
IDWriteTextFormat* m_value = NULL;
bool m_ref = false;
void Copy(const Font& _copy);
public:
Font(const Font& _copy);
Font(const std::wstring& fontFamily, float fontSize, int fontweight = 0);
float GetFontSize()const;
float GetFontWeight()const;
const std::wstring& GetFontFamily()const;
IDWriteTextFormat* Get() const;
bool operator==(const Font& _right);
virtual ~Font();
};
//文本命中测试数据
class UI_EXPORT HitTestMetrics {
public:
int Length;
int TextPos;//命中的下标
RectF FontBox;//文字的矩形位置
bool IsTrailingHit;//命中位置是否在尾部
public:
Rect GetCare() {
float x = FontBox.X;
if (IsTrailingHit) {
x += FontBox.Width;
}
float y = FontBox.Y;
return Rect((int)x, (int)y, 1, (int)(FontBox.Height + 0.5));
}
int GetFontHeight() {
return int(FontBox.Height + 0.5);
}
};
class UI_EXPORT TextLayout {
private:
TextLayout(const TextLayout& rightValue) = delete;
IDWriteTextLayout* m_textLayout = NULL;
std::wstring m_fontFamily;
DWRITE_TEXT_METRICS m_textMetrics = {};
std::vector<RectF> m_lineRects;
int m_unicodeSize = 0;
float m_fontSize = 0;
public:
void GetMetrics();
TextLayout(const std::wstring& text, const Font& font, const SizeF& maxSize = SizeF{ EZUI_FLOAT_MAX,EZUI_FLOAT_MAX }, TextAlign textAlgin = TextAlign::TopLeft);
Point HitTestPoint(const Point& pt, int* outTextPos, BOOL* outIsTrailingHit, int* fontHeight);
void HitTestPoint(const Point& pt, HitTestMetrics* hitTestMetrics);//根据坐标执行命中测试
Point HitTestTextPosition(int textPos, BOOL isTrailingHit);//根据文字下标执行命中测试
const std::wstring& GetFontFamily();
float GetFontSize();
int Width();
int Height();
//获取文本整体的占用空间
Size GetFontBox();
//获取每行文字的矩形位置
const std::vector<RectF>& GetLineRects();
int GetFontHeight();//获取字体高度
int GetLineCount();//获取一共有多少行
IDWriteTextLayout* Get() const;
void SetTextAlign(TextAlign textAlign);
void SetUnderline(int pos = 0, int count = 0);
virtual ~TextLayout();
};
//几何图形基础类(支持自定义路径)
class UI_EXPORT Geometry {
protected:
ID2D1GeometrySink* m_pSink = NULL;
ID2D1Geometry* m_rgn = NULL;
Geometry(const Geometry& rightCopy) = delete;
public:
Geometry();
virtual ~Geometry();
void AddArc(const PointF& endPoint, float radius);
void AddAcr(const D2D1_ARC_SEGMENT& arc);
void AddLine(const PointF& endPoint);
void BeginFigure(const PointF& startPoint, D2D1_FIGURE_BEGIN figureBegin = D2D1_FIGURE_BEGIN_FILLED);
void CloseFigure(D2D1_FIGURE_END figureEnd = D2D1_FIGURE_END_CLOSED);
ID2D1Geometry* Get()const;
public:
/// <summary>
/// 将两个几何图形通过指定的合并模式Union、Intersect、Xor、Exclude合并到一个输出几何中。
/// </summary>
/// <param name="out">合并结果输出到该 Geometry。</param>
/// <param name="a">参与合并的第一个 Geometry。</param>
/// <param name="b">参与合并的第二个 Geometry。</param>
/// <param name="COMBINE_MODE">几何合并模式,取值如 D2D1_COMBINE_MODE_UNION、INTERSECT、XOR、EXCLUDE。</param>
static void Combine(Geometry& out, const Geometry& a, const Geometry& b, D2D1_COMBINE_MODE COMBINE_MODE);
/// <summary>
/// 合并两个区域,取它们的联合部分(即最大边界区域)。
/// </summary>
static void Union(Geometry& out, const Geometry& a, const Geometry& b) {
Combine(out, a, b, D2D1_COMBINE_MODE::D2D1_COMBINE_MODE_UNION);
}
/// <summary>
/// 获取两个区域的交集部分。
/// </summary>
static void Intersect(Geometry& out, const Geometry& a, const Geometry& b) {
Combine(out, a, b, D2D1_COMBINE_MODE::D2D1_COMBINE_MODE_INTERSECT);
}
/// <summary>
/// 合并两个区域,保留不重叠的部分(异或运算)。
/// </summary>
static void Xor(Geometry& out, const Geometry& a, const Geometry& b) {
Combine(out, a, b, D2D1_COMBINE_MODE::D2D1_COMBINE_MODE_XOR);
}
/// <summary>
/// 从第一个区域中排除第二个区域的部分(差集)。
/// </summary>
static void Exclude(Geometry& out, const Geometry& a, const Geometry& b) {
Combine(out, a, b, D2D1_COMBINE_MODE::D2D1_COMBINE_MODE_EXCLUDE);
}
};
//矩形(已经完成闭合)
class UI_EXPORT RectangleGeometry :public Geometry {
private:
void Create(float x, float y, float width, float height, float _radius);
public:
RectangleGeometry(float x, float y, float width, float height, float _radius = 0);
RectangleGeometry(const RectF& _rect, float radius = 0);
RectangleGeometry(const RectF& _rect, float topLeftRadius, float topRightRadius, float bottomRightRadius, float bottomLeftRadius);
virtual ~RectangleGeometry() {};
};
//扇形(已经完成闭合)
class UI_EXPORT PieGeometry :public Geometry {
public:
PieGeometry(const RectF& rectF, float startAngle, float endAngle);
virtual ~PieGeometry() {};
};
//圆形/椭圆(已经完成闭合)
class UI_EXPORT EllipseGeometry :public PieGeometry {
public:
EllipseGeometry(const RectF& rectF) :PieGeometry(rectF, 0, 360) {}
virtual ~EllipseGeometry() {};
};
class UI_EXPORT DXImage : public IImage {
struct GifFrame
{
IWICBitmap* wicBitmap; // 存一份完整帧
UINT delay;
};
protected:
std::vector<GifFrame> m_frames;
IWICBitmapDecoder* m_bitmapdecoder = NULL;
IWICBitmapFrameDecode* m_pframe = NULL;
IWICFormatConverter* m_fmtcovter = NULL;//从文件加载
IWICBitmap* m_bitMap = NULL;//从HBITMAP中加载
int m_width = 0;
int m_height = 0;
ID2D1Bitmap* m_d2dBitmap = NULL;
void* m_lastRender = NULL;
private:
void CreateFormStream(IStream* istram);
void CreateFromFile(const std::wstring& file);
void Init();
public:
bool Visible = true;
void CreateD2DBitmap(ID2D1RenderTarget* render);
//如果HBITMAP带有透明通道 确保传入的图像颜色值已经与 Alpha 通道预乘
DXImage(HBITMAP hBitmap);
DXImage(IStream* istram);
DXImage(const std::wstring& file);
//创建带预乘Alpha的BGRA图片
DXImage(int width, int height);
DXImage(const void* data, size_t count);
ID2D1Bitmap* Get();
IWICBitmap* GetIWICBitmap();
int Width();
int Height();
virtual int NextFrame()override;
DXImage* Clone();
virtual ~DXImage();
};
class Bezier {
public:
Point point1;
Point point2;
Point point3;
};
};
namespace ezui {
class UI_EXPORT DXRender {
private:
ID2D1DCRenderTarget* m_render = NULL;
ID2D1SolidColorBrush* m_brush = NULL;
Font* m_font = NULL;
ID2D1StrokeStyle* m_pStrokeStyle = NULL;
Point m_offset;
PointF m_rotatePoint;
float m_angle = std::numeric_limits<float>::quiet_NaN();
Size m_size;
HWND m_hwnd = NULL;
HDC m_hdc = NULL;
bool m_begin = false;
private:
DXRender(const DXRender& rightValue) = delete;
public:
ID2D1SolidColorBrush* GetBrush();
ID2D1StrokeStyle* GetStrokeStyle();
public:
DXRender(DXImage* dxImage);
DXRender(HDC dc, int width, int height);//创建dx绘图对象
DXRender(HWND hWnd, int width, int height);//创建dx绘图对象
void BeginDraw();
void EndDraw();
virtual ~DXRender();
//如果此对象是由HDC创建的则重置大小时需要传入HDC,如果是使用HWND的则无需传入HDC
void ReSize(int width, int height, HDC dc = NULL);
void SetFont(const std::wstring& fontFamily, float fontSize, int fontWeight = 0);//必须先调用
void SetFont(const Font& _copy_font);//必须先调用
void SetColor(const __EzUI__Color& color);//会之前必须调用
void SetStrokeStyle(StrokeStyle strokeStyle = StrokeStyle::Solid);//设置样式 虚线/实线
void DrawTextLayout(const TextLayout& textLayout, const PointF & = { 0,0 });//根据已有的布局绘制文字
void DrawString(const std::wstring& text, const RectF& _rect, ezui::TextAlign textAlign);//绘制文字
void DrawLine(const PointF& _A, const PointF& _B, float width = 1);//绘制一条线
void DrawRectangle(const RectF& _rect, float _radius = 0, float width = 1);//绘制矩形
void FillRectangle(const RectF& _rect, float _radius = 0);
//填充矩形
void PushLayer(const Geometry& dxGeometry, float opacity = 1.0f);
void PopLayer();
void PushAxisAlignedClip(const RectF& rectBounds);
void PopAxisAlignedClip();
void SetTransform(float offsetX, float offsetY);//对画布进行旋转和偏移
void SetTransform(float startX, float startY, float angle);//设置旋转起始点与旋转角度
void SetTransform(float offsetX, float offsetY, float startX, float startY, float angle);
void DrawImage(DXImage* _image, const RectF& tagRect, float opacity = 1);//绘制图像
void DrawBezier(const PointF& startPoint, const Bezier& points, float width = 1);//贝塞尔线
void DrawBezier(const PointF& startPoint, std::list<Bezier>& points, float width = 1);//贝塞尔线
void DrawEllipse(const RectF& rectF, float width = 1);
void FillEllipse(const RectF& rectF);
void DrawPie(const RectF& rectF, float startAngle, float endAngle, float strokeWidth = 1);
void FillPie(const RectF& rectF, float startAngle, float endAngle);
void DrawPoint(const PointF& pt);
void DrawArc(const RectF& rect, float startAngle, float sweepAngle, float width = 1);//未实现
void DrawArc(const PointF& point1, const PointF& point2, const PointF& point3, float width = 1);
void DrawGeometry(ID2D1Geometry* path, float width = 1);
void FillGeometry(ID2D1Geometry* path);
void DrawGeometry(Geometry* path, float width = 1);
void FillGeometry(Geometry* path);
HRESULT Flush();
ID2D1DCRenderTarget* Get();//获取原生DX对象
};
};
#endif

View File

@@ -1,636 +0,0 @@
/*/
Author:yang
Email:19980103ly@gmail.com/718987717@qq.com
*/
#pragma once
#include "UIDef.h"
#include "UIString.h"
#include "Resource.h"
#include "RenderTypes.h"
#include "Direct2DRender.h"
#undef LoadCursor
#undef LoadIcon
namespace ezui {
class Object;
enum class Cursor : ULONG_PTR;
struct MonitorInfo;
struct Style;
class EventArgs;
class ControlStyle;
class Bitmap;
class Window;
class Control;
class Frame;
class Spacer;
class ScrollBar;
class VScrollBar;
class HScrollBar;
class TabLayout;
class TextBox;
class TileListView;
class TreeView;
class VLayout;
class VListView;
class Button;
class CheckBox;
class ComboBox;
class HLayout;
class HListView;
class Label;
class PagedListView;
class PictureBox;
class RadioButton;
#if 1
//控件集合
class UI_EXPORT ControlCollection : public std::vector<Control*> {
public:
ControlCollection() = default;
~ControlCollection() = default;
//返回集合中的第一个控件
Control* First() {
return this->empty() ? NULL : this->front();
}
//返回集合中的最后一个控件
Control* Last() {
return this->empty() ? NULL : this->back();
}
//移除元素
void Remove(Control* ctrl) {
auto itor = std::find(this->begin(), this->end(), ctrl);
if (itor != this->end()) {
this->erase(itor);
}
}
//检查元素是否存在
bool Contains(Control* ctrl) {
auto itor = std::find(this->begin(), this->end(), ctrl);
return itor != this->end();
}
};
#else
// 控件集合
class UI_EXPORT ControlCollection : public std::list<Control*> {
public:
ControlCollection() = default;
~ControlCollection() = default;
// 慎用 链表不适合随机访问,下标越大,遍历越慢 O(n)
Control* operator[](size_t index) const {
if (index >= this->size()) {
return NULL;
}
auto it = this->begin();
std::advance(it, index); // 高效移动迭代器
return *it;
}
//返回集合中的第一个控件
Control* First() const {
return this->empty() ? NULL : this->front();
}
//返回集合中的最后一个控件
Control* Last() const {
return this->empty() ? NULL : this->back();
}
};
#endif
namespace detail {
//全局资源句柄
extern UI_VAR_EXPORT HMODULE __EzUI__HINSTANCE;//全局实例
extern UI_VAR_EXPORT Resource* __EzUI__Resource;//文件中的全局资源句柄
extern UI_VAR_EXPORT DWORD __EzUI__ThreadId;//UI的线程Id
extern UI_VAR_EXPORT HWND __EzUI_MessageWnd;//用于UI通讯的隐形窗口
extern UI_VAR_EXPORT const std::list<ezui::MonitorInfo> __EzUI__MonitorInfos;//所有监视器信息
};
//判断两个float是相等(两数是否接近)
extern UI_EXPORT bool IsFloatEqual(float num1, float num2);
//加载HICON
extern UI_EXPORT HICON LoadIcon(const UIString& fileName);
//装载字体
extern UI_EXPORT void InstallFont(const UIString& fontFileName);
//卸载字体
extern UI_EXPORT void UnstallFont(const UIString& fontFileName);
//复制内容到剪切板
extern UI_EXPORT bool CopyToClipboard(int uFormat, void* pData, size_t size, HWND hWnd = NULL);
//打开剪切板
extern UI_EXPORT bool GetClipboardData(int uFormat, std::function<void(void*, size_t)> Callback, HWND hWnd = NULL);
//复制unicode文字
extern UI_EXPORT bool CopyToClipboard(const std::wstring& str, HWND hWnd = NULL);
//粘贴unicode文字
extern UI_EXPORT bool GetClipboardData(std::wstring* outStr, HWND hWnd = NULL);
//自动获取文件资源(本地文件/资源文件)
extern UI_EXPORT bool GetResource(const UIString& fileName, std::string* outData);
//获取当前所有监视器的信息
extern UI_EXPORT size_t GetMonitor(std::list<MonitorInfo>* outMonitorInfo);
//获取用户当前所在的显示器
extern UI_EXPORT void GetMontior(MonitorInfo* outInfo, HWND hWnd = NULL);
//使用窗口的矩形位置获取所在的显示器
extern UI_EXPORT void GetMontior(MonitorInfo* outInfo, const Rect& rect);
//加载光标
extern UI_EXPORT HCURSOR LoadCursor(Cursor cursorType);
//加载光标(//需要释放)
extern UI_EXPORT HCURSOR LoadCursor(const UIString& fileName);
//释放光标
extern UI_EXPORT void FreeCursor(HCURSOR hCursor);
//默认处理OnNotify函数(处理一些控件的基础行为)
extern UI_EXPORT void DefaultNotify(Control* sender, EventArgs& args);
class UI_EXPORT Color :public ezui::__EzUI__Color {
public:
Color(const ezui::__EzUI__Color& copy) { this->BGRA = copy.GetValue(); }
Color(const uint32_t& bgra = 0) :ezui::__EzUI__Color(bgra) {}
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) :ezui::__EzUI__Color(r, g, b, a) {}
public:
//构建一个Color
static Color Make(const UIString& colorStr, bool* isGood = NULL);
virtual ~Color() {}
};
/// <summary>
/// 描述边框的一些信息
/// </summary>
class Border {
public:
Value<int16_t> Left;//左边边框大小
Value<int16_t> Top;//顶部边框大小
Value<int16_t> Right;//右边边框大小
Value<int16_t> Bottom;//底部边框大小
Value<int16_t> TopLeftRadius;
Value<int16_t> TopRightRadius;
Value<int16_t> BottomRightRadius;
Value<int16_t> BottomLeftRadius;
Value<Color> Color;
Value<StrokeStyle> Style = StrokeStyle::None;
public:
class Radius {
Border& Border;
public:
Radius(ezui::Border& bd) :Border(bd) {}
//对四个角度同时设置半径大小
Radius& operator=(Value<int16_t> radius) {
Border.TopLeftRadius = radius;
Border.TopRightRadius = radius;
Border.BottomRightRadius = radius;
Border.BottomLeftRadius = radius;
return *this;
}
};
public:
Border::Radius Radius = (*this);
public:
Border() {
this->Style.SetEnabled(false);
}
//对四个边设置大小
Border& operator=(Value<int16_t> borderWidth) {
Left = borderWidth;
Top = borderWidth;
Right = borderWidth;
Bottom = borderWidth;
return *this;
}
void Scale(float scale) {
Left.Set(Left * scale + 0.5);
Top.Set(Top * scale + 0.5);
Right.Set(Right * scale + 0.5);
Bottom.Set(Bottom * scale + 0.5);
TopLeftRadius.Set(TopLeftRadius * scale + 0.5);
TopRightRadius.Set(TopRightRadius * scale + 0.5);
BottomRightRadius.Set(BottomRightRadius * scale + 0.5);
BottomLeftRadius.Set(BottomLeftRadius * scale + 0.5);
}
};
#if USED_DIRECT2D
class UI_EXPORT Image :public DXImage {
private:
#ifdef _DEBUG
UIString m_path;
#endif
public:
virtual ~Image() {}
//创建带预乘Alpha的BGRA图片
Image(int width, int height) :DXImage(width, height) {}
Image(HBITMAP hBitmap) :DXImage(hBitmap) {}
Image(Bitmap* bitmap);
Image(IStream* iStream) :DXImage(iStream) {}
Image(const std::wstring& fileName) :DXImage(fileName) {}
Image(const void* data, size_t dataCount) :DXImage(data, dataCount) {}
public:
//从资源或者本地文件自动构建一个Image
static Image* Make(const UIString& fileOrRes);
};
#endif
// 定义用于保存显示器信息的结构体
struct MonitorInfo {
HMONITOR Monitor = NULL;
//显示器的位置 多显示器下Y轴可能出现负数或者大于0的时候代表显示器在设置里面显示器是错位的(多显示器没有平行);
//逻辑宽高
ezui::Rect Rect;
//工作区域
ezui::Rect WorkRect;
//显示器物理宽高
Size Physical;
//显示器缩放比例 1.0 1.25 1.5 1.75 2.0
float Scale = 1.0f;
//显示器帧率
float FPS = 60;
//是否为主显示器
bool Primary = false;
};
//窗口公共数据
struct WindowContext {
//缩放率
float Scale = 1.0f;
//单次绘图数量
int DrawControlCount = 0;
//上一帧绘制时间
unsigned long long LastFrameTime = 0;
//一秒内绘制次数
int DrawFrameCount = 0;
#ifdef _DEBUG
//是否开启debug模式
bool Debug = false;
//调试模式下的特有字段
int ColorIndex = 0;
Color DebugColor;
std::vector<Color> DebugColors{ Color::Red,Color::Green,Color::Blue,Color::Black,Color::White };
#endif
//主窗类的实例
ezui::Window* Window = NULL;
//使一个区域无效
std::function<void(const Rect&)> InvalidateRect = NULL;
//立即更新全部无效区域
std::function<void()> Refresh = NULL;
//清空控件标记等等...
std::function<void(Control*)> CleanControl = NULL;
//内部移动窗口的函数
std::function<void()> MoveWindow = NULL;
//内部使用标题部分移动窗口的函数
std::function<void()> TitleMoveWindow = NULL;
//处理消息过程的回调函数
std::function<LRESULT(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)> WndProc = NULL;
//设置焦点控件
std::function<void(Control*)> SetFocus = NULL;
};
enum class LayoutState {
//无状态 (无需布局)
None,
//挂起中
Pend,
//布局中
Layouting
};
enum class Event :long long {
None = 0,
OnMouseWheel = 1,
OnMouseEnter = 2,
OnMouseMove = 4,
OnMouseLeave = 8,
OnMouseDoubleClick = 16,
OnMouseDown = 32,
OnMouseUp = 64,
OnKeyDown = 128,
OnKeyUp = 256,
OnPaint = 512,
OnFocus = 1024,
OnKillFocus = 2048,
OnKeyChar = 4096,
OnMove = 8192,
OnSize = 16384,
OnRect = 32768,
OnDpiChange = 65536,
OnActive = OnMouseDown | OnMouseUp,
OnHover = OnMouseEnter | OnMouseLeave,
OnMouseDrag = OnMouseDown | OnMouseMove,
OnMouseEvent = OnMouseWheel | OnMouseEnter | OnMouseMove | OnMouseLeave | OnMouseDoubleClick | OnMouseDown | OnMouseUp,
OnKeyBoardEvent = OnKeyDown | OnKeyUp | OnKeyChar
};
EZUI_ENUM_OPERATORS(Event, long long);
//控件行为
enum class ControlAction {
None,
Title,//具有移动窗口 双击最大化窗口的行为
MoveWindow,//移动窗口
Mini,//最小化
Max,//最大化|恢复
Close//关闭
};
enum class ControlState :int {
None = 1,//无状态 则是使用_nowStyle缓存样式
Static = 2,//静态
Disabled = 4,//禁用状态
Checked = 8,//选中状态
Hover = 16,//鼠标悬浮
Active = 32,//鼠标按住
Focus = 64//具有焦点时
};
EZUI_ENUM_OPERATORS(ControlState, int);
enum class MouseButton {
// 摘要:
// 未曾按下鼠标按钮。
None,
//
// 摘要:
// 鼠标左按钮曾按下。
Left,
//
// 摘要:
// 鼠标右按钮曾按下。
Right,
//
// 摘要:
// 鼠标中按钮曾按下。
Middle,
//
// 摘要:
// 第 1 个 XButton 曾按下。
XButton1,
//
// 摘要:
// 第 2 个 XButton 曾按下。
XButton2
};
enum class Cursor :ULONG_PTR
{
None = 0,//未指定
APPSTARTING = (ULONG_PTR)IDC_APPSTARTING,// 标准的箭头和小沙漏
ARROW = (ULONG_PTR)IDC_ARROW,// 标准的箭头
CROSS = (ULONG_PTR)IDC_CROSS,// 十字光标
HAND = (ULONG_PTR)IDC_HAND,// Windows 98/Me, Windows 2000/XP: Hand
HELP = (ULONG_PTR)IDC_HELP,// 标准的箭头和问号
IBEAM = (ULONG_PTR)IDC_IBEAM,// 工字光标
ICON = (ULONG_PTR)IDC_ICON,// Obsolete for applications marked version 4.0 or later.
NO = (ULONG_PTR)IDC_NO,// 禁止圈
SIZE = (ULONG_PTR)IDC_SIZE,// Obsolete for applications marked version 4.0 or later. Use SIZEALL.
SIZEALL = (ULONG_PTR)IDC_SIZEALL,// 四向箭头指向东、西、南、北
SIZENESW = (ULONG_PTR)IDC_SIZENESW,// 双箭头指向东北和西南
SIZENS = (ULONG_PTR)IDC_SIZENS, // 双箭头指向南北
SIZENWSE = (ULONG_PTR)IDC_SIZENWSE,// 双箭头指向西北和东南
SIZEWE = (ULONG_PTR)IDC_SIZEWE,// 双箭头指向东西
UPARROW = (ULONG_PTR)IDC_UPARROW,// 垂直箭头
WAIT = (ULONG_PTR)IDC_WAIT// 沙漏Windows7下会显示为选择的圆圈表示等待
};
//基础事件
class UI_EXPORT EventArgs {
public:
Event EventType = Event::None;
EventArgs(Event eventType) {
this->EventType = eventType;
}
virtual ~EventArgs() {};
};
//为鼠标事件提供基础数据
class UI_EXPORT MouseEventArgs :public EventArgs {
public:
MouseButton Button = MouseButton::None;
int ZDelta = 0;//方向
Point Location;
public:
MouseEventArgs(Event eventType, const Point& location = Point(0, 0), MouseButton mouseButton = MouseButton::None, int ZDelta = 0) :EventArgs(eventType) {
this->Button = mouseButton;
this->Location = location;
this->ZDelta = ZDelta;
}
virtual ~MouseEventArgs() {}
};
// 摘要:
//为键盘事件提供基础数据
class UI_EXPORT KeyboardEventArgs :public EventArgs {
public:
/// <summary>
/// 一般是指 键盘的ascii值
/// </summary>
WPARAM wParam;
LPARAM lParam;
KeyboardEventArgs(Event eventType, WPARAM wParam, LPARAM lParam) :EventArgs(eventType) {
this->wParam = wParam;
this->lParam = lParam;
}
virtual ~KeyboardEventArgs() {}
};
//获取焦点
class UI_EXPORT FocusEventArgs :public EventArgs {
public:
Control* Control;
FocusEventArgs(ezui::Control* ctl) :EventArgs(Event::OnFocus) {
this->Control = ctl;
}
virtual ~FocusEventArgs() {}
};
//失去焦点
class UI_EXPORT KillFocusEventArgs :public EventArgs {
public:
Control* Control;
KillFocusEventArgs(ezui::Control* ctl) :EventArgs(Event::OnKillFocus) {
this->Control = ctl;
}
virtual ~KillFocusEventArgs() {}
};
//坐标发生改变
class UI_EXPORT MoveEventArgs :public EventArgs {
public:
const ezui::Point Location;
MoveEventArgs(const ezui::Point& location) :EventArgs(Event::OnMove), Location(location) {}
virtual ~MoveEventArgs() {}
};
//大小发生改变
class UI_EXPORT SizeEventArgs :public EventArgs {
public:
const ezui::Size Size;
SizeEventArgs(const ezui::Size& size) :EventArgs(Event::OnSize), Size(size) {}
virtual ~SizeEventArgs() {}
};
//dpi发生变化
class UI_EXPORT DpiChangeEventArgs :public EventArgs {
public:
float Scale = 1.0f;
DpiChangeEventArgs(float scale) :EventArgs(Event::OnDpiChange), Scale(scale) {}
virtual ~DpiChangeEventArgs() {}
};
// 为 OnPaint 事件提供数据。
class UI_EXPORT PaintEventArgs :public EventArgs {
private:
std::list<bool> m_layers;
std::list<Point> m_offsets;
public:
PaintEventArgs(const PaintEventArgs&) = delete;
PaintEventArgs& operator=(const PaintEventArgs&) = delete;
WindowContext* PublicData = NULL;
::HWND HWND = NULL;
HDC DC = NULL;
ezui::DXRender& Graphics;//画家
Rect InvalidRectangle;//WM_PAINT里面的无效区域
PaintEventArgs(ezui::DXRender& _painter) : EventArgs(Event::OnPaint), Graphics(_painter) {}
virtual ~PaintEventArgs() {}
//添加裁剪(速度较快)
void PushLayer(const Rect& rectBounds);
//添加异形裁剪 比较耗性能,但是可以异形抗锯齿裁剪
void PushLayer(const Geometry& dxGeometry, float opacity);
//弹出最后一个裁剪
void PopLayer();
//放入一个偏移
void PushOffset(const Point& offset);
//弹出最后一个偏移
void PopOffset();
};
// 为控件样式提供数据。
class UI_EXPORT ControlStyle {
public:
//边框信息
ezui::Border Border;
//背景颜色
Value<Color> BackColor;
//背景图片 如果指定的图片被删除 请必须将此置零
Value<Image*> BackImage;
//前景图片 如果指定的图片被删除 请必须将此置零
Value<Image*> ForeImage;
//字体名称 具有继承性
Value<std::wstring> FontFamily;
//字体大小 具有继承性
Value<int> FontSize;
//字体粗度 值范围1~999 如需加粗一般为700即可 具有继承性值
Value<int> FontWeight;
//前景颜色 具有继承性
Value<Color> ForeColor;
//鼠标样式
Value<HCURSOR> Cursor;
//正数角度(0~ 360) -> 逆时针旋转
//负数角度(0~ -360) -> 顺时针旋转
Value<float> Angle;
//透明度(0~1.0)
Value<float> Opacity;
private:
void operator=(const ControlStyle& right) {} //禁止直接赋值 因为这样会导致 Color执行拷贝使得Color变得不合法的有效
ControlStyle(const ControlStyle& right) {} //禁止拷贝
public:
ControlStyle() {
Angle.Set(std::numeric_limits<float>::quiet_NaN());
Opacity.Set(std::numeric_limits<float>::quiet_NaN());
}
virtual ~ControlStyle() {}
void Scale(float scale);
};
//指针管理
template <typename T>
class PtrManager {
private:
std::vector<T> m_ptrs;
public:
PtrManager() {}
virtual ~PtrManager() {
this->Clear();
}
void Add(const T& v) {
if (v) {
m_ptrs.push_back(v);
}
}
void Remove(const T& v) {
auto it = std::find(m_ptrs.begin(), m_ptrs.end(), v);
if (it != m_ptrs.end()) {
m_ptrs.erase(it);
}
}
void Clear() {
auto itor = m_ptrs.begin();
while (itor != m_ptrs.end())
{
T item = *itor;
itor = m_ptrs.erase(itor); // erase 返回下一个有效迭代器
delete item;
}
}
};
//常用对象基类
class UI_EXPORT Object {
private:
//属性集合
std::map<UIString, UIString> m_attrs;
// 管理子对象的释放
PtrManager<Object*> m_childObjects;
//是否正在被销毁
bool m_bIsDestroying = false;
public:
//用户自定义数据
UINT_PTR Tag = NULL;
public:
Object(Object* ownerObject = NULL);
virtual ~Object();
public:
//设置属性
virtual void SetAttribute(const UIString& attrName, const UIString& attrValue);
//获取属性
virtual UIString GetAttribute(const UIString& attrName);
//获取全部属性
virtual const std::map<UIString, UIString>& GetAttributes();
//移除某个属性
virtual void RemoveAttribute(const UIString& attrName);
//绑定对象(跟随释放)
virtual Object* Attach(Object* obj);
//分离对象(解除跟随释放)
virtual void Detach(Object* obj);
//对象是否正在被销毁(预防析构降级导致控件访问报错)
bool IsDestroying();
//延迟删除
void DeleteLater();
};
//原理采用PostMessage
template<class Func, class... Args>
bool BeginInvoke(Func&& f, Args&& ...args) {
HWND hWnd = ezui::detail::__EzUI_MessageWnd;
if (hWnd == NULL || !::IsWindow(hWnd)) {
return false;
}
std::function<void()>* func = new std::function<void()>(std::bind(std::forward<Func>(f), std::forward<Args>(args)...));
if (::PostMessage(hWnd, WM_GUI_SYSTEM, WM_GUI_BEGININVOKE, (LPARAM)func) == LRESULT(0)) {
delete func;
return false;
}
return true;
}
//原理采用SendMessage
template<class Func, class... Args>
bool Invoke(Func&& f, Args&& ...args) {
std::function<void()> func(std::bind(std::forward<Func>(f), std::forward<Args>(args)...));
if (::GetCurrentThreadId() == ezui::detail::__EzUI__ThreadId) {
func();
return true;
}
HWND hWnd = ezui::detail::__EzUI_MessageWnd;
if (hWnd == NULL || !::IsWindow(hWnd)) {
return false;
}
if (::SendMessage(hWnd, WM_GUI_SYSTEM, WM_GUI_INVOKE, (LPARAM)&func) == LRESULT(-1)) {
return false;
}
return true;
}
//统计函数耗时
template<class Func, class... Args>
int64_t StopWatch(Func&& f, Args&& ...args) {
auto beginTime = std::chrono::steady_clock::now();
std::forward<Func>(f)(std::forward<Args>(args)...);
auto delta = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - beginTime).count();
return delta;
}
};

View File

@@ -1,29 +0,0 @@
#pragma once
#include "EzUI.h"
#include "UILoader.h"
namespace ezui {
//内联页面 内部控件与外部隔离
class UI_EXPORT Frame :public Control {
private:
UILoader m_loader;//内部UI管理器
public:
//对外暴露消息通知回调
std::function<void(Control*, EventArgs&)> NotifyHandler = NULL;
Frame(Object* ownerObject = NULL);
virtual ~Frame();
//是否为Frame
virtual bool IsFrame()override final;
//从文件中加载xml
void LoadXml(const UIString& fileName);
//设置唯一布局
void SetLayout(Control* ctrl);
//获取布局
Control* GetLayout();
virtual void SetAttribute(const UIString& attrName, const UIString& attrValue)override;
//消息通知
virtual void OnNotify(Control* sender, EventArgs& args);
//获取UI管理器
UILoader* GetUILoader();
};
};

View File

@@ -1,24 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
class UI_EXPORT HLayout :
public Control
{
private:
VAlign m_contentAlign = VAlign::Mid;
protected:
void DistributeAutoWidths(std::vector<Control*> const& autoSizeCtrls, int availableWidth);
virtual void OnLayout()override;
public:
HLayout(Object* ownerObject = NULL);
// 添加一个弹簧控件:
// - 传入 fixedWidth > 0,则作为固定高度的空白,位不可伸缩
// - 传入 fixedWidth == 0,则作为可拉伸的弹簧,占据剩余空间
void AddSpacer(int fixedWidth = 0);
virtual void SetAttribute(const UIString& key, const UIString& value)override;
void SetContentAlign(VAlign contentAlign);
virtual ~HLayout();
};
using HBox = HLayout;
};

View File

@@ -1,24 +0,0 @@
#pragma once
#include "PagedListView.h"
#include "HScrollBar.h"
namespace ezui {
class UI_EXPORT HListView :
public PagedListView
{
private:
VAlign m_contentAlign = VAlign::Mid;
HScrollBar m_hScrollBar;
void Init();
void Offset(int offset);
protected:
virtual void OnLayout()override;
virtual void OnChildPaint(PaintEventArgs& args)override;
public:
HListView(Object* ownerObject = NULL);
virtual ~HListView();
void SetContentAlign(VAlign contentAlign);
virtual void SetAttribute(const UIString& key, const UIString& value)override;
virtual ScrollBar* GetScrollBar()override;
};
};

View File

@@ -1,21 +0,0 @@
#pragma once
#include "Control.h"
#include "ScrollBar.h"
namespace ezui {
class UI_EXPORT HScrollBar :
public ScrollBar
{
protected:
virtual void OnMouseDown(const MouseEventArgs& arg)override;
virtual void OnMouseMove(const MouseEventArgs& arg)override;
virtual void GetInfo(int* viewLength, int* contentLength, int* scrollBarLength)override;
virtual void OnParentSize(const Size& parentSize)override;
public:
HScrollBar(Object* ownerObject = NULL);
virtual ~HScrollBar();
virtual void ScrollTo(Control* ctl)override;
virtual Rect GetSliderRect()override;
};
};

View File

@@ -1,36 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
class UI_EXPORT Label :
public Control
{
private:
std::wstring m_wstr;
int m_underlinePos = 0;//显示下划线起始下标
int m_underlineCount = 0;//显示下划线文字个数
std::wstring m_ellipsisText;//文字溢出将显示的文字
protected:
virtual void OnForePaint(PaintEventArgs& args) override;
virtual void OnDpiChange(const DpiChangeEventArgs& args)override;
virtual void OnLayout()override;
public:
//基于控件的文字的边距
ezui::Distance TextMargin;
//文字对齐方式
TextAlign TextAlign = TextAlign::MiddleCenter;
public:
Label(Object* ownerObject = NULL);
virtual ~Label();
virtual void SetAttribute(const UIString& key, const UIString& value)override;
virtual void RefreshLayout() override;
//设置文字
void SetText(const UIString& text);
//获取文字
UIString GetText()const;
//设置文字溢出控件之后的显示文字
void SetElidedText(const UIString& text);
//设置下划线位置
void SetUnderline(int pos, int count);
};
};

View File

@@ -1,30 +0,0 @@
#pragma once
#include "BorderlessWindow.h"
#include "Bitmap.h"
#include "Task.h"
#include "Timer.h"
namespace ezui {
/// <summary>
/// //LayeredWindow //无边框 带阴影 窗口透明异形 窗口大小发生改变重绘
/// </summary>
class UI_EXPORT LayeredWindow :public BorderlessWindow
{
private:
std::list<Rect> m_invalidateRect;
Bitmap* m_winBitmap = NULL;
void UpdateLayeredWindow(HDC hdc, const Rect& rePaintRect);
void BeginPaint(std::vector<Rect>* outRect);
void EndPaint();
bool Paint();
protected:
virtual void OnSize(const Size& sz)override;
void InvalidateRect(const Rect& rect);
virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)override;
public:
//窗口透明度
float Opacity = 1.0f;
LayeredWindow(int width, int height, HWND owner = NULL, DWORD dwStyle = NULL, DWORD dwExStyle = NULL);
virtual ~LayeredWindow();
};
};

View File

@@ -1,20 +0,0 @@
#pragma once
#include "EzUI.h"
namespace ezui {
//菜单类
class UI_EXPORT Menu :public Object
{
private:
HMENU m_hMenu = NULL;
public:
//菜单子项被选点击的回调事件 UINT:子项ID
std::function<void(UINT_PTR)> MouseClick = NULL;
Menu(Object* ownerObject = NULL);
virtual ~Menu();
HMENU HMenu();
UINT_PTR Append(const UIString& text);
void Remove(const UINT_PTR id);
};
};

View File

@@ -1,27 +0,0 @@
#pragma once
#include "Menu.h"
#include <shellapi.h>
namespace ezui {
//系统托盘类
class UI_EXPORT NotifyIcon :public Object
{
private:
HWND m_hWnd = NULL;
Menu* m_menu = NULL;
NOTIFYICONDATAW m_nid = {};
WindowContext m_publicData;
protected:
virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
public:
//事件处理 只会返回鼠标事件
std::function<void(const MouseEventArgs&)> EventHandler = NULL;
NotifyIcon(Object* ownerObject = NULL);
void SetIcon(HICON icon);
//设置鼠标悬停时显示的提示文本
void SetTips(const UIString& text);
void SetMenu(Menu* menu);
void ShowBalloonTip(const UIString& title, const UIString& msg, int timeOut = 1000);
virtual ~NotifyIcon();
};
};

View File

@@ -1,39 +0,0 @@
#pragma once
#include "Control.h"
namespace ezui {
/**
* 是一个分页显示控件集合的容器控件
*
* 它支持对一批子控件进行分页管理,例如:
* - 显示每页固定数量的控件;
* - 支持翻页;
* - 当控件到达末页时需要手动调用NextPage进行加载下一页;
*
* 子类:VList/HList/TileList 继承使其具备分页管理的能力
*/
class UI_EXPORT PagedListView :
public Control
{
private:
int m_pageIndex = 0;
int m_pageTotal = 0;
int m_pageSize = 0;
ControlCollection m_items;
public:
PagedListView(Object* ownerObject = NULL);
virtual ~PagedListView();
//页面需要加载下一页的时候发生
std::function<bool(PagedListView*, int)> NextPaging = NULL;
void SetPageInfo(const ControlCollection& items, int pageSize);
/// <summary>
/// 获取某页的item集合
/// </summary>
/// <param name="index">1~N</param>
/// <param name="outCtls">输出集合</param>
void GetPage(int index, ControlCollection* outCtls);
virtual void NextPage();
virtual void RemoveAll() override;
virtual void RemoveAll(bool freeChilds) override;
};
};

View File

@@ -1,21 +0,0 @@
#pragma once
#include "Control.h"
#include "Timer.h"
namespace ezui {
class UI_EXPORT PictureBox : public Control {
private:
Timer m_timer;
std::shared_ptr<std::atomic<bool>> m_alive;
private:
void Init();
protected:
virtual void OnForePaint(PaintEventArgs& arg)override;
public:
//图片(支持gif图自动播放)
Image* Image = NULL;
PictureBox(Object* ownerObject = NULL);
virtual ~PictureBox();
virtual void SetAttribute(const UIString& key, const UIString& value)override;
};
};

View File

@@ -1,22 +0,0 @@
#pragma once
#include "Window.h"
#include "BorderlessWindow.h"
#include "LayeredWindow.h"
namespace ezui {
/// <summary>
/// 弹出式窗口(失去焦点窗口将会关闭) 一般用于做右键菜单等等
/// </summary>
class UI_EXPORT PopupWindow :public LayeredWindow {
private:
bool isShowModal = false;
protected:
virtual void OnKillFocus(HWND hWnd) override;
public:
//弹出的窗口在拥有窗口前面 ownerHwnd为NULL则置顶窗口
PopupWindow(int width, int height, HWND ownerHwnd = NULL);
virtual void Show()override;
virtual int ShowModal(bool disableOnwer = false)override;
virtual ~PopupWindow();
};
};

View File

@@ -1,14 +0,0 @@
#pragma once
#include "CheckBox.h"
namespace ezui {
class UI_EXPORT RadioButton :
public CheckBox
{
protected:
virtual void OnMouseDown(const MouseEventArgs& arg)override;
public:
RadioButton(Object* ownerObject = NULL);
virtual~RadioButton();
};
};

Some files were not shown because too many files have changed in this diff Show More