Compare commits
8 Commits
v2.2.2
...
0c1cf2938f
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c1cf2938f | |||
| aa0fa8d320 | |||
| 43564ef675 | |||
| 53dc237e46 | |||
| 46febdb973 | |||
| f05962954f | |||
| 58d4e8ab2f | |||
| 5420bfd644 |
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,83 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
[中文文档](CHANGELOG.md)
|
[中文文档](CHANGELOG.md)
|
||||||
|
|
||||||
|
## [v2.3.2] - 2025 - 12 - 20
|
||||||
|
|
||||||
|
### ✨ Added
|
||||||
|
|
||||||
|
- **Table: runtime reset for headers and data:** added `Table::clearHeaders()`, `Table::clearData()`, and `Table::resetTable()`. This allows a single `Table` instance to dynamically update its headers/data at runtime, and triggers the required recalculation (cell sizing / pagination info) and redraw.
|
||||||
|
- **TextBox: password mode:** added `PASSWORD_MODE` to `TextBoxmode`. User input is stored internally, while the render layer displays masked characters (e.g., `*`). The real text can be retrieved via `TextBox::getText()`.
|
||||||
|
|
||||||
|
### ⚙️ Changed
|
||||||
|
|
||||||
|
- **TabControl: clarified default active page semantics:**
|
||||||
|
- Calling `TabControl::setActiveIndex()` **before the first draw** now only records the default active index; it no longer immediately triggers the tab button click callback.
|
||||||
|
- **After the first draw completes**, if a default active index was set, the active state is applied and the active page is drawn (if the index is out of range, the last page is activated by default).
|
||||||
|
- Calling `TabControl::setActiveIndex()` **during runtime (non-first draw)** switches the active page immediately when the index is valid; out-of-range indices are ignored.
|
||||||
|
|
||||||
|
### ✅ Fixed
|
||||||
|
|
||||||
|
- **TabControl::setActiveIndex crash when called before drawing:** fixed a null-pointer access caused by triggering the tab button click callback before initialization. The default activation is now applied after the first draw completes, preventing crashes and ensuring the active page is rendered on first draw.
|
||||||
|
- **TabControl rendering glitches when toggling visibility (hidden -> visible):** fixed multi-page overlap/ghosting caused by non-active pages being incorrectly drawn after `setIsVisible(false) -> setIsVisible(true)`. Now, when TabControl is visible, only the active page is visible/drawable; if there is no active page, nothing is drawn.
|
||||||
|
|
||||||
|
## [v2.3.1] - 2025-11-30
|
||||||
|
|
||||||
|
### 🙏 Acknowledgements
|
||||||
|
|
||||||
|
- Special thanks to user [@To-KongBai](https://github.com/To-KongBai) for providing stable reproduction steps and key phenomenon comparisons (container nested child control coordinate transformation issue), which helped us quickly identify and fix the control coordinate transformation problem in deeply nested containers. ([Issues#6](https://github.com/Ysm-04/StellarX/issues/6))
|
||||||
|
- In the upcoming website (currently undergoing ICP filing), we plan to add a contributors' wall to acknowledge users. We welcome everyone to report bugs or share interfaces created with StellarX, and we will carefully read and include acknowledgements.
|
||||||
|
- Sincere thanks to every user who reports bugs—your feedback makes StellarX more stable and robust.
|
||||||
|
|
||||||
|
### ⚙️ Changes
|
||||||
|
|
||||||
|
- **Dialog Background Snapshot Mechanism:** `Dialog` no longer captures and destroys its own snapshot. The methods for capturing and restoring snapshots have been **removed** from `Dialog`, and the base class `Canvas` now handles all snapshot management. The `draw` method in `Dialog` no longer deals with snapshots.
|
||||||
|
- **Timing Adjustment for Window and Control Redrawing on Size Change:** In the main event loop, when the window size changes, control sizes are processed first. Old snapshots are discarded, followed by the redrawing of the window with the new size, and finally, the controls are redrawn.
|
||||||
|
|
||||||
|
### ✅ Fixes
|
||||||
|
|
||||||
|
- **Child Control Coordinate Transformation in Nested Containers:** `Canvas` overrides the base class's `setX/Y` methods to synchronize the global coordinates of child controls when the parent container's global coordinates change. This prevents child controls in nested containers from incorrectly treating the container's relative coordinates as global coordinates.
|
||||||
|
- **Solid Background Window Title Not Applied:** In the `Window`'s `draw()` method, the window title is forcibly set to ensure that the title passed when creating the window is applied correctly, preventing the issue where the window title doesn't take effect.
|
||||||
|
- **Tab Control Background Residue when Changing Coordinates:** In the overridden `setX/Y` methods of `TabControl`, all tabs and their child controls are forced to discard snapshots when the tab's coordinates change. This prevents background residue caused by incorrect snapshot restoration order after modifying coordinates.
|
||||||
|
- **Table Page Number Label and Pagination Button Misalignment when Changing Coordinates:** In `Table`'s `setX/Y`, the `isNeedButtonAndPageNum` state is reset to `true`, ensuring that the pagination button and page number label are recalculated and remain centered directly beneath the table when redrawn.
|
||||||
|
|
||||||
|
## [v2.3.0] - 2025-11-18
|
||||||
|
|
||||||
|
### ✨ Added
|
||||||
|
|
||||||
|
- Introduced `LayoutMode` adaptive layout mode and `Anchor` anchor points. Controls can now call `setLayoutMode` to set layout mode and `steAnchor` to set anchor points, enabling controls to adapt to window changes during resizing. Dialog controls only recalculate their position during window resizing to maintain center alignment.
|
||||||
|
- Added `adaptiveLayout()` API to `Window`, called by the main event loop to recalculate control positions and sizes based on anchor points during window resizing, enabling dual-anchored controls (left-right or top-bottom) to automatically stretch with window changes.
|
||||||
|
|
||||||
|
### ⚙️ Changed
|
||||||
|
|
||||||
|
- **Optimized Window Resizing Mechanism**: Refactored `WndProcThunk`, `runEventLoop`, and `pumpResizeIfNeeded` to uniformly record window size changes and perform one-time repainting at the end of the event loop, preventing jitter and sequencing issues caused by repeated drawing during resizing.
|
||||||
|
- **Added Dialog Size Scheduling Interface**: Introduced `Window::scheduleResizeFromModal()`, used in conjunction with `pumpResizeIfNeeded()`. During modal dialog display, the parent window can update client area size in real time and relayout child controls during unified finalization, while the dialog maintains its original size.
|
||||||
|
- **Redraw Sequence Optimization**: Replaced `InvalidateRect` with `ValidateRect` during the finalization phase after window size changes, preventing the system from sending additional `WM_PAINT` messages that could cause reentrant drawing.
|
||||||
|
- **Other Improvements**: Fixed delayed background snapshot updates for table pagination buttons and page number labels; improved dialog background capture logic.
|
||||||
|
|
||||||
|
### ✅ Fixed
|
||||||
|
|
||||||
|
- **Modal Dialog Resizing Fix**: Resolved the issue where window resizing during modal dialog display prevented underlying controls from updating their sizes and positions according to anchor points; simultaneously eliminated ghosting artifacts caused by repeated dialog redrawing.
|
||||||
|
- **Drawing Sequence Disorder Fix**: Addressed sporadic drawing sequence disorders, control ghosting, and border flickering during window resizing, ensuring controls are drawn in the order they were added.
|
||||||
|
- **Stability Fixes**: Corrected abnormal frames caused by sudden window size changes in certain scenarios; resolved delayed background snapshot updates for tables and dialogs under edge conditions.
|
||||||
|
|
||||||
|
## [v2.2.2] - 2025 - 11- 08
|
||||||
|
|
||||||
|
### ⚙️ Changes
|
||||||
|
|
||||||
|
- Modified the coordinate transfer method for the Canvas container. Child control coordinates are now passed as relative coordinates (with the origin at the top-left corner of the container, obtainable via the `getX`/`getY` interface), instead of the original global coordinates. Child control coordinates can now be set to negative values.
|
||||||
|
- The example under `examples\register-viewer` has been updated to the latest version, aligning container child controls to use relative coordinates.
|
||||||
|
|
||||||
|
### ✅ Fixes
|
||||||
|
|
||||||
|
- Fixed jittering/bouncing and flickering when resizing the window (left/top edges):
|
||||||
|
- `WM_SIZING` only clamps the minimum size; `WM_GETMINMAXINFO` sets the window-level minimum tracking size.
|
||||||
|
- Freezes redrawing during dragging and handles resizing uniformly upon release; `WM_SIZE` only records the new size without interfering with drawing.
|
||||||
|
- Disabled `WM_ERASEBKGND` background erasing and removed `CS_HREDRAW`/`CS_VREDRAW` to reduce flickering.
|
||||||
|
- Fixed issues related to dialog boxes:
|
||||||
|
- Resolved occasional residual functional buttons after closing a dialog.
|
||||||
|
- Fixed issues where window resizing failed to redraw or displayed a corrupted background when a modal dialog was active.
|
||||||
|
- Fixed delayed updates of background snapshots for the table control's pagination buttons and page number labels during window changes.
|
||||||
|
|
||||||
## [v2.2.1] - 2025-11-04
|
## [v2.2.1] - 2025-11-04
|
||||||
|
|
||||||
==This release is a hotfix for v2.2.0==
|
==This release is a hotfix for v2.2.0==
|
||||||
|
|||||||
82
CHANGELOG.md
82
CHANGELOG.md
@@ -7,6 +7,88 @@ StellarX 项目所有显著的变化都将被记录在这个文件中。
|
|||||||
|
|
||||||
[English document](CHANGELOG.en.md)
|
[English document](CHANGELOG.en.md)
|
||||||
|
|
||||||
|
## [v2.3.2] - 2025 - 12 - 20
|
||||||
|
|
||||||
|
### ✨ 新增
|
||||||
|
|
||||||
|
- **Table 支持运行期重置表头与数据:**新增 `Table::clearHeaders()`、`Table::clearData()`、`Table::resetTable()`,允许同一 `Table` 在运行过程中动态切换表头与数据,并触发必要的单元格尺寸/分页信息重算与重绘。
|
||||||
|
- **TextBox 新增密码模式:**`TextBoxmode` 新增 `PASSWORD_MODE`;输入内容内部保存,绘制层面使用掩码字符(如 `*`)替代显示,真实文本可通过 `TextBox::getText()` 获取。
|
||||||
|
|
||||||
|
### ⚙️ 变更
|
||||||
|
|
||||||
|
- **TabControl 默认激活页语义明确化:**
|
||||||
|
- 首次绘制前调用 `TabControl::setActiveIndex()`:仅记录默认激活索引,不再立即触发页签按钮点击回调;
|
||||||
|
- 首次绘制完成后:若设置了默认激活索引则应用激活状态并绘制激活页(索引越界时默认激活最后一个页);
|
||||||
|
- 程序运行过程中调用 `TabControl::setActiveIndex()`:索引合法则立即切换激活页并绘制;索引越界则不做处理。
|
||||||
|
|
||||||
|
### ✅ 修复
|
||||||
|
|
||||||
|
- **TabControl::setActiveIndex 绘制前调用导致程序中断:**修复绘制前设置默认激活索引时触发空指针访问的问题;现在默认激活逻辑延后到首次绘制完成后再生效,避免崩溃并保证首次绘制即可绘制激活页。
|
||||||
|
- **TabControl 由不可见设置为可见时绘制错乱:**修复 `setIsVisible(false) -> setIsVisible(true)` 后非激活页被错误绘制导致的多页重叠/残影;现在 TabControl 可见时仅激活页可见/可绘制,无激活页则不绘制任何页。
|
||||||
|
|
||||||
|
## [v2.3.1] - 2025 - 11 - 30
|
||||||
|
|
||||||
|
### 🙏 鸣谢
|
||||||
|
|
||||||
|
- 感谢用户 [@To-KongBai](https://github.com/To-KongBai) 提供稳定复现步骤与关键现象对比(容器嵌套孙控件坐标转换问题),帮助我们快速确认多容器嵌套时的控件坐标转换问题并修复。([Issues#6](https://github.com/Ysm-04/StellarX/issues/6))
|
||||||
|
- 在即将上线的官网中(ICP备案中)我们计划加入一个贡献者鸣谢墙,欢迎各位用户反馈BUG或者分享自己用星垣做的界面,我们将认真阅读并收录鸣谢
|
||||||
|
- 真诚的感谢每一位反馈BUG的用户,你们的反馈将使星垣更加稳定和健壮
|
||||||
|
|
||||||
|
### ✨ 新增
|
||||||
|
|
||||||
|
新增一个登录界面Demo在主仓库**examples/**目录下
|
||||||
|
|
||||||
|
### ⚙️ 变更
|
||||||
|
|
||||||
|
- **Dialog背景快照机制:**`Dialog`不在自己抓取和销毁快照,**删除**重载的抓取和恢复快照的方法,完全交由基类`Canvas`处理,`Dialog`的`draw`方法中不在处理快照
|
||||||
|
- **窗口变化重绘时控件和窗口重绘的时机调整:**主事件循环中窗口大小发生变化时先处理控件尺寸,并回贴和释放旧快照,然后再重绘新尺寸窗口,最后绘制控件
|
||||||
|
|
||||||
|
### ✅ 修复
|
||||||
|
|
||||||
|
- **容器嵌套时子控件坐标转化:**`Canvas`重写了基类的`setX/Y`方法,在容器全局坐标发生变化时同步修改子控件的全局坐标,防止在容器嵌套时,容器的相对坐标被子控件当成全局坐标处理
|
||||||
|
- **纯色背景窗口标题不生效:**在`Window`的`draw()`方法中强制设置窗口标题,以防止,创建窗口时传递的窗口标题不生效
|
||||||
|
- **选项卡控件页签打开时动态改变坐标背景残留:**在`TabControl`重写的`setX/Y`方法中,当选项卡的坐标发生变化时强制让所有页签以及页和子控件丢一次快照,防止,在修改坐标后因,快照恢复顺序引起的选项卡激活页残留
|
||||||
|
- **Table动态改变坐标页码标签和翻页按钮错乱:**在`Table`控件的`setX/Y`中重置`isNeedButtonAndPageNum`状态为真,在绘制时重新计算翻页按钮和页码标签的位置以保持在表格正下方居中位置显示
|
||||||
|
|
||||||
|
## [v2.3.0] - 2025 - 11 - 18
|
||||||
|
|
||||||
|
### ✨ 新增
|
||||||
|
|
||||||
|
- 新增`LayoutMode `自适应布局模式和`Anchor`锚点,控件中可以调用 `setLayoutMode`
|
||||||
|
设置布局模式以及`steAnchor`设置锚点,达到窗口拉伸时控件自适应窗口变化。对话框控件在窗口变化时只会重新计算位置,来保证居中显示
|
||||||
|
- `Window`新增`adaptiveLayout()`这个API由主事件循环调用,在窗口拉伸时根据锚点重新计算控件位置和尺寸,使左右/上下双锚定控件随窗口变化自动伸缩。
|
||||||
|
|
||||||
|
### ⚙️ 变更
|
||||||
|
|
||||||
|
- **优化窗口尺寸调整机制**:重构 `WndProcThunk`、`runEventLoop` 和 `pumpResizeIfNeeded`,统一记录窗口尺寸变化并在事件循环尾部一次性重绘,避免拉伸过程中重复绘制引发抖动与顺序错乱。
|
||||||
|
- **新增对话框尺寸调度接口**:引入 `Window::scheduleResizeFromModal()`,配合 `pumpResizeIfNeeded()` 使用。模态对话框显示期间,父窗口可实时更新客户区尺寸并在统一收口时重新布局子控件,对话框自身尺寸保持不变。
|
||||||
|
- **重绘顺序优化**:在窗口尺寸变化后的收口阶段使用 `ValidateRect` 代替 `InvalidateRect`,避免系统再次发送 `WM_PAINT` 导致重入绘制。
|
||||||
|
- **其他改进**:修复表格翻页按钮与页码标签等元素背景快照更新不及时的问题;改进对话框背景捕捉逻辑。
|
||||||
|
|
||||||
|
### ✅ 修复
|
||||||
|
|
||||||
|
- **模态对话框拉伸修复**:解决了模态对话框弹出时,窗口拉伸无法让底层控件按照锚点更新尺寸和位置的问题;同时避免对话框反复重绘导致残影。
|
||||||
|
- **绘制顺序错乱修复**:解决窗口拉伸时偶发的绘制顺序紊乱、控件残影和边框闪烁问题,确保控件按添加顺序依次绘制。
|
||||||
|
- **稳定性修复**:修正某些情况下窗口尺寸突变导致的异常帧;解决表格和对话框背景快照在边界条件下未及时更新的问题。
|
||||||
|
|
||||||
|
## [v2.2.2] - 2025 - 11- 08
|
||||||
|
|
||||||
|
### ⚙️ 变更
|
||||||
|
|
||||||
|
- Canvas容器坐标传递方式改变,子控件坐标由原来的传递全局坐标改为传递相对坐标(坐标原点为容器的左上角坐标可通过getX/Y接口获得)可以设置子控件坐标为负值
|
||||||
|
- examples\register-viewer下的案例已同步修改为最新,同步容器子控件为相对坐标
|
||||||
|
|
||||||
|
### ✅ 修复
|
||||||
|
|
||||||
|
- 修复窗口拉伸(左/上边)时的抖动/弹回与闪烁
|
||||||
|
- `WM_SIZING` 仅做最小尺寸夹紧;`WM_GETMINMAXINFO` 设置窗口级最小轨迹
|
||||||
|
- 拖拽期冻结重绘,松手统一收口;`WM_SIZE` 只记录尺寸不抢绘制
|
||||||
|
- 禁用 `WM_ERASEBKGND` 擦背景并移除 `CS_HREDRAW/CS_VREDRAW`,减少闪烁
|
||||||
|
- 对话框的相关问题
|
||||||
|
- 对话框关闭后概率出现功能按钮残留
|
||||||
|
- 模态对话框触发时,窗口拉伸无法重绘或背景错乱
|
||||||
|
- 表格控件在窗口变化时其翻页按钮和页码标签背景快照更新不及时的问题
|
||||||
|
|
||||||
## [v2.2.1] - 2025 - 11 - 4
|
## [v2.2.1] - 2025 - 11 - 4
|
||||||
|
|
||||||
==此版本为v2.2.0的修复版本==
|
==此版本为v2.2.0的修复版本==
|
||||||
|
|||||||
27
README.en.md
27
README.en.md
@@ -7,8 +7,8 @@
|
|||||||

|

|
||||||
[](https://github.com/Ysm-04/StellarX)
|
[](https://github.com/Ysm-04/StellarX)
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
@@ -25,24 +25,6 @@ This is a **teaching-grade and tooling-grade** framework that helps developers u
|
|||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
## **🆕 v2.2.1 (Hotfix for v2.2.0)**
|
|
||||||
|
|
||||||
- Addressed a flickering issue that occurred when using the Canvas and TabControl containers.
|
|
||||||
- Fixed issues where border remnants and functional buttons could persist after closing a Dialog.
|
|
||||||
|
|
||||||
For details, please refer to the [CHANGELOG.en](CHANGELOG.en.md).
|
|
||||||
|
|
||||||
## What’s new in v2.2.0
|
|
||||||
|
|
||||||
- **New TabControl for multi-page tabbed UIs:** With `TabControl`, it’s easy to create a tabbed layout. Tabs can be arranged on the top, bottom, left, or right, and clicking switches the displayed page. Suitable for settings panels and multi-view switching.
|
|
||||||
- **Enhanced control show/hide and resize responsiveness:** All controls now share a unified interface (`setIsVisible`) to toggle visibility. When a container control is hidden, its child controls automatically hide/show with it. Meanwhile, we introduce `onWindowResize` for controls to respond to window size changes so elements update in sync after resizing, eliminating artifacts or misalignment.
|
|
||||||
- **Refined text-style mechanism:** The Label control now uses a unified `ControlText` style structure. Developers can easily customize font, color, size, etc. (replacing older interfaces, and more flexible). Button Tooltips also support richer customization and different texts for toggle states.
|
|
||||||
- **Other improvements:** Dialog management gains de-duplication to prevent identical prompts from popping up repeatedly. Several bug fixes and refresh optimizations further improve stability.
|
|
||||||
|
|
||||||
See `CHANGELOG.md / CHANGELOG.en.md` for the full list.
|
|
||||||
|
|
||||||
------
|
|
||||||
|
|
||||||
## 📦 Project Structure & Design Philosophy
|
## 📦 Project Structure & Design Philosophy
|
||||||
|
|
||||||
StellarX adopts classic **OOP** and **modular** design with a clear structure:
|
StellarX adopts classic **OOP** and **modular** design with a clear structure:
|
||||||
@@ -181,6 +163,11 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
|||||||
| `MessageBoxResult` | Result | `OK`, `Cancel`, `Yes`, `No`, `Abort`, `Retry`, `Ignore` |
|
| `MessageBoxResult` | Result | `OK`, `Cancel`, `Yes`, `No`, `Abort`, `Retry`, `Ignore` |
|
||||||
| `TabPlacement` | Tab position | `Top`, `Bottom`, `Left`, `Right` |
|
| `TabPlacement` | Tab position | `Top`, `Bottom`, `Left`, `Right` |
|
||||||
|
|
||||||
|
| Enum | Description | Common values |
|
||||||
|
| ------------ | ---------------------- | -------------------------------------------- |
|
||||||
|
| `LayoutMode` | 窗口布局模式 | `Fixed`, `AnchorToEdges` |
|
||||||
|
| `Anchor` | 控件相对于父容器的锚点 | `NoAnchor` ,`Left` , `Right`, `Top`,`Bottom` |
|
||||||
|
|
||||||
### Structs
|
### Structs
|
||||||
|
|
||||||
| Struct | Description |
|
| Struct | Description |
|
||||||
|
|||||||
41
README.md
41
README.md
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
[English document](README.en.md)
|
[English document](README.en.md)
|
||||||
|
|
||||||
|
官网地址:https://stellarx-gui.top
|
||||||
|
|
||||||
> 本仓库为 **StellarX** 主仓:开发与 Issue/PR 均在 GitHub 进行。
|
> 本仓库为 **StellarX** 主仓:开发与 Issue/PR 均在 GitHub 进行。
|
||||||
> GitCode 仅为只读镜像:如需反馈请到 GitHub:https://github.com/Ysm-04/StellarX
|
> GitCode 仅为只读镜像:如需反馈请到 GitHub:https://github.com/Ysm-04/StellarX
|
||||||
|
|
||||||
@@ -12,8 +14,8 @@
|
|||||||

|

|
||||||
[](https://github.com/Ysm-04/StellarX)
|
[](https://github.com/Ysm-04/StellarX)
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
@@ -30,24 +32,26 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🆕v2.2.1(v2.2.0修复版)
|
|
||||||
|
|
||||||
- 解决了使用Canvas和TabControl容器时,出现频闪问题
|
|
||||||
|
|
||||||
- 修复了Dialog对话框关闭时概率出边边框残留和功能按钮残留问题
|
|
||||||
|
|
||||||
详情参考[更新日志](CHANGELOG.md)
|
|
||||||
|
|
||||||
|
|
||||||
|
## 🆕V2.3.2——重要更新
|
||||||
|
|
||||||
## V2.2.0 有何变化
|
### 新增
|
||||||
|
|
||||||
- **新增 TabControl 控件,实现多页面选项卡界面:** 通过 `TabControl` 可以轻松创建选项卡式布局,支持页签在上下左右排列、点击切换显示不同内容页面。适用于设置面板、多视图切换等场景。
|
- **Table 支持运行期重置表头与数据:**新增 `Table::clearHeaders()`、`Table::clearData()`、`Table::resetTable()`,允许同一 `Table` 在运行过程中动态切换表头与数据,并触发必要的单元格尺寸/分页信息重算与重绘。
|
||||||
- **控件显隐与布局响应能力增强:** 现在所有控件都可以使用统一接口动态隐藏或显示(`setIsVisible`),容器控件隐藏时其内部子控件会自动随之隐藏/显示。与此同时,引入控件对窗口尺寸变化的响应机制(`onWindowResize`),窗口拉伸后界面各元素可协调更新,杜绝拉伸过程中出现残影或错位。
|
- **TextBox 新增密码模式:**`TextBoxmode` 新增 `PASSWORD_MODE`;输入内容内部保存,绘制层面使用掩码字符(如 `*`)替代显示,真实文本可通过 `TextBox::getText()` 获取。
|
||||||
- **文本样式机制完善:** Label 控件改用统一的文本样式结构 `ControlText`,开发者可方便地设置字体、颜色、大小等属性来定制 Label 的外观(替代旧接口,更加灵活)。Button 的 Tooltip 提示也支持更丰富的定制和针对切换状态的不同提示文本。
|
|
||||||
- **其他改进:** 框架底层的对话框管理增加了防重复弹出相同提示的机制,修复了一些细节 Bug 并优化了刷新效率,进一步提升了稳定性。
|
|
||||||
|
|
||||||
详见 `CHANGELOG.md / CHANGELOG.en.md` 获取完整更新列表。
|
### ⚙️ 变更
|
||||||
|
|
||||||
|
- **TabControl 默认激活页语义明确化:**
|
||||||
|
- 首次绘制前调用 `TabControl::setActiveIndex()`:仅记录默认激活索引,不再立即触发页签按钮点击回调;
|
||||||
|
- 首次绘制完成后:若设置了默认激活索引则应用激活状态并绘制激活页(索引越界时默认激活最后一个页);
|
||||||
|
- 程序运行过程中调用 `TabControl::setActiveIndex()`:索引合法则立即切换激活页并绘制;索引越界则不做处理。
|
||||||
|
|
||||||
|
### ✅ 修复
|
||||||
|
|
||||||
|
- **TabControl::setActiveIndex 绘制前调用导致程序中断:**修复绘制前设置默认激活索引时触发空指针访问的问题;现在默认激活逻辑延后到首次绘制完成后再生效,避免崩溃并保证首次绘制即可绘制激活页。
|
||||||
|
- **TabControl 由不可见设置为可见时绘制错乱:**修复 `setIsVisible(false) -> setIsVisible(true)` 后非激活页被错误绘制导致的多页重叠/残影;现在 TabControl 可见时仅激活页可见/可绘制,无激活页则不绘制任何页。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -189,6 +193,13 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
|||||||
| `MessageBoxResult` | 结果 | `OK`, `Cancel`, `Yes`, `No`, `Abort`, `Retry`, `Ignore` |
|
| `MessageBoxResult` | 结果 | `OK`, `Cancel`, `Yes`, `No`, `Abort`, `Retry`, `Ignore` |
|
||||||
| `TabPlacement` | 页签位置 | `Top`,`Bottom`,`Left`,`Right` |
|
| `TabPlacement` | 页签位置 | `Top`,`Bottom`,`Left`,`Right` |
|
||||||
|
|
||||||
|
| 枚举 | 描述 | 常用值 |
|
||||||
|
| ------------ | ---------------------- | -------------------------------------------- |
|
||||||
|
| `LayoutMode` | 窗口布局模式 | `Fixed`, `AnchorToEdges` |
|
||||||
|
| Anchor | 控件相对于父容器的锚点 | `NoAnchor` ,`Left` , `Right`, `Top`,`Bottom` |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 结构体
|
### 结构体
|
||||||
|
|
||||||
| 结构体 | 描述 |
|
| 结构体 | 描述 |
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
|
|||||||
// 3. 为按钮设置点击事件(使用Lambda表达式)
|
// 3. 为按钮设置点击事件(使用Lambda表达式)
|
||||||
myButton->setOnClickListener([&mainWindow]() {
|
myButton->setOnClickListener([&mainWindow]() {
|
||||||
// 使用消息框工厂创建模态对话框
|
// 使用消息框工厂创建模态对话框
|
||||||
auto result = StellarX::MessageBox::ShowModal(
|
auto result = StellarX::MessageBox::showModal(
|
||||||
mainWindow,
|
mainWindow,
|
||||||
"欢迎使用星垣GUI\r\n作者:我在人间做废物",
|
"欢迎使用星垣GUI\r\n作者:我在人间做废物",
|
||||||
"问候",
|
"问候",
|
||||||
|
|||||||
@@ -7,12 +7,12 @@
|
|||||||
auto blackColor = RGB(202, 255, 255);
|
auto blackColor = RGB(202, 255, 255);
|
||||||
char initData[33] = "00000000000000000000000000000000";//初始数据
|
char initData[33] = "00000000000000000000000000000000";//初始数据
|
||||||
bool gSigned = false; //是否为有符号数
|
bool gSigned = false; //是否为有符号数
|
||||||
void main()
|
int main()
|
||||||
{
|
{
|
||||||
Window mainWindow(700,500,NULL,RGB(255,255,255), "寄存器查看工具 V1.0——我在人间做废物 (同类工具定制:3150131407(Q / V))");
|
Window mainWindow(700, 510, NULL, RGB(255, 255, 255), "寄存器查看工具 V1.0——我在人间做废物 (同类工具定制:3150131407(Q / V))");
|
||||||
|
|
||||||
//选择区控件
|
//选择区控件
|
||||||
auto selectionAreaLabel = std::make_unique<Label>(18, 0,"32位选择区");
|
auto selectionAreaLabel = std::make_unique<Label>(18, 0, "32位选择区");
|
||||||
selectionAreaLabel->setTextdisap(true);
|
selectionAreaLabel->setTextdisap(true);
|
||||||
std::vector<std::unique_ptr<Label>>selectionAreaButtonLabel;
|
std::vector<std::unique_ptr<Label>>selectionAreaButtonLabel;
|
||||||
std::vector<std::unique_ptr<Button>>selectionAreaButton;
|
std::vector<std::unique_ptr<Button>>selectionAreaButton;
|
||||||
@@ -22,21 +22,21 @@ void main()
|
|||||||
selectionArea->setCanvasBkColor(blackColor);
|
selectionArea->setCanvasBkColor(blackColor);
|
||||||
selectionArea->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
selectionArea->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||||||
|
|
||||||
for (int y = 0; y < 2; y ++)
|
for (int y = 0; y < 2; y++)
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
for (int x = 0; x <16; x++)
|
for (int x = 0; x < 16; x++)
|
||||||
{
|
{
|
||||||
if (0 == y)
|
if (0 == y)
|
||||||
{
|
{
|
||||||
selectionAreaButtonLabel.push_back(std::make_unique<Label>(x * 35 + 40 + 28 * (x / 4), 26, "", RGB(208, 208, 208)));
|
selectionAreaButtonLabel.push_back(std::make_unique<Label>(x * 35 + 25 + 28 * (x / 4), 26, "", RGB(208, 208, 208)));
|
||||||
os << std::setw(2) << std::setfill('0') << 31 - x;
|
os << std::setw(2) << std::setfill('0') << 31 - x;
|
||||||
selectionAreaButtonLabel.back()->setText(os.str());
|
selectionAreaButtonLabel.back()->setText(os.str());
|
||||||
selectionAreaButtonLabel.back()->setTextdisap(true);
|
selectionAreaButtonLabel.back()->setTextdisap(true);
|
||||||
|
|
||||||
selectionAreaButton.push_back(
|
selectionAreaButton.push_back(
|
||||||
std::make_unique<Button>(x * 35 + 42 + 28 * (x / 4), 58,20,32,"0",
|
std::make_unique<Button>(x * 35 + 27 + 28 * (x / 4), 58, 25, 30, "0",
|
||||||
blackColor,RGB(171, 196, 220),StellarX::ButtonMode::TOGGLE));
|
blackColor, RGB(171, 196, 220), StellarX::ButtonMode::TOGGLE));
|
||||||
selectionAreaButton.back()->textStyle.color = RGB(226, 116, 152);
|
selectionAreaButton.back()->textStyle.color = RGB(226, 116, 152);
|
||||||
selectionAreaButton.back()->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
selectionAreaButton.back()->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
selectionAreaButton_ptr.push_back(selectionAreaButton.back().get());
|
selectionAreaButton_ptr.push_back(selectionAreaButton.back().get());
|
||||||
@@ -55,19 +55,19 @@ void main()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
selectionAreaButtonLabel.push_back(std::make_unique<Label>(x * 35 + 40 + 28 * (x / 4), 90, "", RGB(208, 208, 208)));
|
selectionAreaButtonLabel.push_back(std::make_unique<Label>(x * 35 + 25 + 28 * (x / 4), 90, "", RGB(208, 208, 208)));
|
||||||
os << std::setw(2) << std::setfill('0') << 15-x;
|
os << std::setw(2) << std::setfill('0') << 15 - x;
|
||||||
selectionAreaButtonLabel.back()->setText(os.str());
|
selectionAreaButtonLabel.back()->setText(os.str());
|
||||||
selectionAreaButtonLabel.back()->setTextdisap(true);
|
selectionAreaButtonLabel.back()->setTextdisap(true);
|
||||||
|
|
||||||
selectionAreaButton.push_back(
|
selectionAreaButton.push_back(
|
||||||
std::make_unique<Button>(x * 35 + 42 + 28 * (x / 4), 120, 20, 32, "0",
|
std::make_unique<Button>(x * 35 + 27 + 28 * (x / 4), 120, 25, 30, "0",
|
||||||
blackColor, RGB(171, 196, 220), StellarX::ButtonMode::TOGGLE));
|
blackColor, RGB(171, 196, 220), StellarX::ButtonMode::TOGGLE));
|
||||||
selectionAreaButton.back()->textStyle.color = RGB(226, 116, 152);
|
selectionAreaButton.back()->textStyle.color = RGB(226, 116, 152);
|
||||||
selectionAreaButton.back()->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
selectionAreaButton.back()->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
selectionAreaButton_ptr.push_back(selectionAreaButton.back().get());
|
selectionAreaButton_ptr.push_back(selectionAreaButton.back().get());
|
||||||
int k =15 - x;
|
int k = 15 - x;
|
||||||
selectionAreaButton.back()->setOnToggleOnListener([k,btn = selectionAreaButton_ptr.back()]()
|
selectionAreaButton.back()->setOnToggleOnListener([k, btn = selectionAreaButton_ptr.back()]()
|
||||||
{
|
{
|
||||||
btn->setButtonText("1");
|
btn->setButtonText("1");
|
||||||
initData[k] = '1';
|
initData[k] = '1';
|
||||||
@@ -90,12 +90,18 @@ void main()
|
|||||||
selectionArea->addControl(std::move(s));
|
selectionArea->addControl(std::move(s));
|
||||||
//功能区控件
|
//功能区控件
|
||||||
//功能区总容器
|
//功能区总容器
|
||||||
auto function = std::make_unique<Canvas>(0, 0, 0, 0);
|
auto function = std::make_unique<Canvas>(10, 170, 680, 70);
|
||||||
function->setCanvasfillMode(StellarX::FillMode::Null);
|
function->setCanvasfillMode(StellarX::FillMode::Null);
|
||||||
|
function->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||||||
|
function->setCanvasBkColor(blackColor);
|
||||||
|
auto bitInvert_que = std::make_unique<Canvas>(0, 0, 220, 70);
|
||||||
|
auto leftShift_que = std::make_unique<Canvas>(230, 0, 220, 70);
|
||||||
|
auto rightShift_que = std::make_unique<Canvas>(460, 0, 220, 70);
|
||||||
|
|
||||||
|
auto bitInvert = bitInvert_que.get();
|
||||||
|
auto leftShift = leftShift_que.get();
|
||||||
|
auto rightShift = rightShift_que.get();
|
||||||
|
|
||||||
auto bitInvert = std::make_unique<Canvas>(10,170,220,70);
|
|
||||||
auto leftShift = std::make_unique<Canvas>(240, 170, 220, 70);
|
|
||||||
auto rightShift = std::make_unique<Canvas>(470, 170, 220, 70);
|
|
||||||
bitInvert->setCanvasBkColor(blackColor);
|
bitInvert->setCanvasBkColor(blackColor);
|
||||||
bitInvert->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
bitInvert->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||||||
leftShift->setCanvasBkColor(blackColor);
|
leftShift->setCanvasBkColor(blackColor);
|
||||||
@@ -103,12 +109,15 @@ void main()
|
|||||||
rightShift->setCanvasBkColor(blackColor);
|
rightShift->setCanvasBkColor(blackColor);
|
||||||
rightShift->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
rightShift->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||||||
|
|
||||||
|
function->addControl(std::move(bitInvert_que));
|
||||||
|
function->addControl(std::move(leftShift_que));
|
||||||
|
function->addControl(std::move(rightShift_que));
|
||||||
|
|
||||||
auto bitInvertLabel = std::make_unique<Label>(18,160,"位取反");
|
auto bitInvertLabel = std::make_unique<Label>(13, -10, "位取反");
|
||||||
bitInvertLabel->setTextdisap(true);
|
bitInvertLabel->setTextdisap(true);
|
||||||
auto leftShiftLabel = std::make_unique<Label>(248, 160, "左移位");
|
auto leftShiftLabel = std::make_unique<Label>(13, -10, "左移位");
|
||||||
leftShiftLabel->setTextdisap(true);
|
leftShiftLabel->setTextdisap(true);
|
||||||
auto rightShiftLabel = std::make_unique<Label>(478, 160, "右移位");
|
auto rightShiftLabel = std::make_unique<Label>(13, -10, "右移位");
|
||||||
rightShiftLabel->setTextdisap(true);
|
rightShiftLabel->setTextdisap(true);
|
||||||
|
|
||||||
// ====== 公用小工具======
|
// ====== 公用小工具======
|
||||||
@@ -139,17 +148,17 @@ void main()
|
|||||||
|
|
||||||
//取反区控件
|
//取反区控件
|
||||||
std::array<std::unique_ptr<Label>, 4> bitInvertFunctionLabel;
|
std::array<std::unique_ptr<Label>, 4> bitInvertFunctionLabel;
|
||||||
bitInvertFunctionLabel[0] = std::make_unique<Label>(35, 180, "低位");
|
bitInvertFunctionLabel[0] = std::make_unique<Label>(30, 10, "低位");
|
||||||
bitInvertFunctionLabel[1] = std::make_unique<Label>(90, 180, "高位");
|
bitInvertFunctionLabel[1] = std::make_unique<Label>(90, 10, "高位");
|
||||||
bitInvertFunctionLabel[2] = std::make_unique<Label>(15, 198, "从");
|
bitInvertFunctionLabel[2] = std::make_unique<Label>(15, 38, "从");
|
||||||
bitInvertFunctionLabel[3] = std::make_unique<Label>(75, 198, "到");
|
bitInvertFunctionLabel[3] = std::make_unique<Label>(75, 38, "到");
|
||||||
|
|
||||||
std::array<std::unique_ptr<TextBox>, 2> bitInvertFunctionTextBox;
|
std::array<std::unique_ptr<TextBox>, 2> bitInvertFunctionTextBox;
|
||||||
bitInvertFunctionTextBox[0] = std::make_unique<TextBox>(35, 203, 35, 30, "0");
|
bitInvertFunctionTextBox[0] = std::make_unique<TextBox>(35, 35, 35, 30, "0");
|
||||||
bitInvertFunctionTextBox[1] = std::make_unique<TextBox>(95, 203, 35, 30, "0");
|
bitInvertFunctionTextBox[1] = std::make_unique<TextBox>(95, 35, 35, 30, "0");
|
||||||
auto invL = bitInvertFunctionTextBox[0].get();
|
auto invL = bitInvertFunctionTextBox[0].get();
|
||||||
auto invH = bitInvertFunctionTextBox[1].get();
|
auto invH = bitInvertFunctionTextBox[1].get();
|
||||||
auto bitInvertFunctionButton = std::make_unique<Button>(150,195, 70, 35, "位取反",
|
auto bitInvertFunctionButton = std::make_unique<Button>(135, 35, 80, 30, "位取反",
|
||||||
blackColor, RGB(171, 196, 220));
|
blackColor, RGB(171, 196, 220));
|
||||||
bitInvertFunctionButton->textStyle.color = RGB(226, 116, 152);
|
bitInvertFunctionButton->textStyle.color = RGB(226, 116, 152);
|
||||||
bitInvertFunctionButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
bitInvertFunctionButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
@@ -171,16 +180,16 @@ void main()
|
|||||||
bitInvert->addControl(std::move(b));
|
bitInvert->addControl(std::move(b));
|
||||||
}
|
}
|
||||||
//左移控件
|
//左移控件
|
||||||
auto leftShiftFunctionLabel = std::make_unique<Label>(435, 198, "位");
|
auto leftShiftFunctionLabel = std::make_unique<Label>(198, 30, "位");
|
||||||
leftShiftFunctionLabel->setTextdisap(true);
|
leftShiftFunctionLabel->setTextdisap(true);
|
||||||
|
|
||||||
auto leftShiftFunctionTextBox = std::make_unique<TextBox>(325, 195, 100, 30, "0");
|
auto leftShiftFunctionTextBox = std::make_unique<TextBox>(90, 30, 100, 30, "0");
|
||||||
leftShiftFunctionTextBox->setMaxCharLen(3);
|
leftShiftFunctionTextBox->setMaxCharLen(3);
|
||||||
leftShiftFunctionTextBox->textStyle.color = RGB(226, 116, 152);
|
leftShiftFunctionTextBox->textStyle.color = RGB(226, 116, 152);
|
||||||
leftShiftFunctionTextBox->setTextBoxBk(RGB(244, 234, 142));
|
leftShiftFunctionTextBox->setTextBoxBk(RGB(244, 234, 142));
|
||||||
leftShiftFunctionTextBox->setTextBoxshape(StellarX::ControlShape::B_RECTANGLE);
|
leftShiftFunctionTextBox->setTextBoxshape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
auto shlBox = leftShiftFunctionTextBox.get();
|
auto shlBox = leftShiftFunctionTextBox.get();
|
||||||
auto leftShiftFunctionButton = std::make_unique<Button>(250, 195, 60, 30, "左移",
|
auto leftShiftFunctionButton = std::make_unique<Button>(15, 30, 60, 30, "左移",
|
||||||
blackColor, RGB(171, 196, 220));
|
blackColor, RGB(171, 196, 220));
|
||||||
leftShiftFunctionButton->textStyle.color = RGB(226, 116, 152);
|
leftShiftFunctionButton->textStyle.color = RGB(226, 116, 152);
|
||||||
leftShiftFunctionButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
leftShiftFunctionButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
@@ -194,16 +203,16 @@ void main()
|
|||||||
leftShift->addControl(std::move(leftShiftFunctionLabel));
|
leftShift->addControl(std::move(leftShiftFunctionLabel));
|
||||||
|
|
||||||
//右移控件
|
//右移控件
|
||||||
auto rightShiftFunctionLabel = std::make_unique<Label>(665, 198, "位");
|
auto rightShiftFunctionLabel = std::make_unique<Label>(198, 30, "位");
|
||||||
rightShiftFunctionLabel->setTextdisap(true);
|
rightShiftFunctionLabel->setTextdisap(true);
|
||||||
auto rightShiftFunctionTextBox = std::make_unique<TextBox>(555, 195, 100, 30, "0");
|
auto rightShiftFunctionTextBox = std::make_unique<TextBox>(90, 30, 100, 30, "0");
|
||||||
rightShiftFunctionTextBox->setMaxCharLen(3);
|
rightShiftFunctionTextBox->setMaxCharLen(3);
|
||||||
rightShiftFunctionTextBox->textStyle.color = RGB(226, 116, 152);
|
rightShiftFunctionTextBox->textStyle.color = RGB(226, 116, 152);
|
||||||
rightShiftFunctionTextBox->setTextBoxBk(RGB(244, 234, 142));
|
rightShiftFunctionTextBox->setTextBoxBk(RGB(244, 234, 142));
|
||||||
rightShiftFunctionTextBox->setTextBoxshape(StellarX::ControlShape::B_RECTANGLE);
|
rightShiftFunctionTextBox->setTextBoxshape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
auto shrBox = rightShiftFunctionTextBox.get();
|
auto shrBox = rightShiftFunctionTextBox.get();
|
||||||
|
|
||||||
auto rightShiftFunctionButton = std::make_unique<Button>(480, 195, 60, 30, "右移",
|
auto rightShiftFunctionButton = std::make_unique<Button>(15, 30, 60, 30, "右移",
|
||||||
blackColor, RGB(171, 196, 220));
|
blackColor, RGB(171, 196, 220));
|
||||||
rightShiftFunctionButton->textStyle.color = RGB(226, 116, 152);
|
rightShiftFunctionButton->textStyle.color = RGB(226, 116, 152);
|
||||||
rightShiftFunctionButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
rightShiftFunctionButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
@@ -217,9 +226,6 @@ void main()
|
|||||||
rightShift->addControl(std::move(rightShiftLabel));
|
rightShift->addControl(std::move(rightShiftLabel));
|
||||||
rightShift->addControl(std::move(rightShiftFunctionLabel));
|
rightShift->addControl(std::move(rightShiftFunctionLabel));
|
||||||
|
|
||||||
function->addControl(std::move(bitInvert));
|
|
||||||
function->addControl(std::move(leftShift));
|
|
||||||
function->addControl(std::move(rightShift));
|
|
||||||
|
|
||||||
//显示区控件
|
//显示区控件
|
||||||
//数值显示
|
//数值显示
|
||||||
@@ -228,13 +234,13 @@ void main()
|
|||||||
NumericalDisplayArea->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
NumericalDisplayArea->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||||||
|
|
||||||
std::array<std::unique_ptr<Label>, 3> NumericalDisplayAreaLabel;
|
std::array<std::unique_ptr<Label>, 3> NumericalDisplayAreaLabel;
|
||||||
NumericalDisplayAreaLabel[0] = std::make_unique<Label>(18, 245, "数值显示区");
|
NumericalDisplayAreaLabel[0] = std::make_unique<Label>(18, -10, "数值显示区");
|
||||||
NumericalDisplayAreaLabel[1] = std::make_unique<Label>(20, 278, "十六进制");
|
NumericalDisplayAreaLabel[1] = std::make_unique<Label>(20, 25, "十六进制");
|
||||||
NumericalDisplayAreaLabel[2] = std::make_unique<Label>(330, 278, "十进制");
|
NumericalDisplayAreaLabel[2] = std::make_unique<Label>(330, 25, "十进制");
|
||||||
|
|
||||||
std::array<std::unique_ptr<TextBox>, 2> NumericalDisplayAreaTextBox;
|
std::array<std::unique_ptr<TextBox>, 2> NumericalDisplayAreaTextBox;
|
||||||
NumericalDisplayAreaTextBox[0] = std::make_unique<TextBox>(110, 275, 200, 30, "0");
|
NumericalDisplayAreaTextBox[0] = std::make_unique<TextBox>(110, 25, 200, 30, "0");
|
||||||
NumericalDisplayAreaTextBox[1] = std::make_unique<TextBox>(400, 275, 200, 30, "0");
|
NumericalDisplayAreaTextBox[1] = std::make_unique<TextBox>(400, 25, 200, 30, "0");
|
||||||
auto hex = NumericalDisplayAreaTextBox[0].get();
|
auto hex = NumericalDisplayAreaTextBox[0].get();
|
||||||
auto dec = NumericalDisplayAreaTextBox[1].get();
|
auto dec = NumericalDisplayAreaTextBox[1].get();
|
||||||
|
|
||||||
@@ -259,13 +265,13 @@ void main()
|
|||||||
BinaryDisplayArea->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
BinaryDisplayArea->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||||||
|
|
||||||
std::array<std::unique_ptr<Label>, 3> BinaryDisplayAreaLabel;
|
std::array<std::unique_ptr<Label>, 3> BinaryDisplayAreaLabel;
|
||||||
BinaryDisplayAreaLabel[0] = std::make_unique<Label>(18, 325, "二进制显示区");
|
BinaryDisplayAreaLabel[0] = std::make_unique<Label>(18, -10, "二进制显示区");
|
||||||
BinaryDisplayAreaLabel[1] = std::make_unique<Label>(35, 353, "上次值");
|
BinaryDisplayAreaLabel[1] = std::make_unique<Label>(35, 20, "上次值");
|
||||||
BinaryDisplayAreaLabel[2] = std::make_unique<Label>(35, 400, "本次值");
|
BinaryDisplayAreaLabel[2] = std::make_unique<Label>(35, 67, "本次值");
|
||||||
|
|
||||||
std::array<std::unique_ptr<TextBox>, 2> BinaryDisplayAreaTextBox;
|
std::array<std::unique_ptr<TextBox>, 2> BinaryDisplayAreaTextBox;
|
||||||
BinaryDisplayAreaTextBox[0] = std::make_unique<TextBox>(110, 350, 520, 30, "0000_0000_0000_0000_0000_0000_0000_0000");
|
BinaryDisplayAreaTextBox[0] = std::make_unique<TextBox>(110, 20, 520, 30, "0000_0000_0000_0000_0000_0000_0000_0000");
|
||||||
BinaryDisplayAreaTextBox[1] = std::make_unique<TextBox>(110, 400, 520, 30, "0000_0000_0000_0000_0000_0000_0000_0000");
|
BinaryDisplayAreaTextBox[1] = std::make_unique<TextBox>(110, 67, 520, 30, "0000_0000_0000_0000_0000_0000_0000_0000");
|
||||||
auto Last = BinaryDisplayAreaTextBox[0].get();
|
auto Last = BinaryDisplayAreaTextBox[0].get();
|
||||||
auto This = BinaryDisplayAreaTextBox[1].get();
|
auto This = BinaryDisplayAreaTextBox[1].get();
|
||||||
|
|
||||||
@@ -367,16 +373,16 @@ void main()
|
|||||||
configuration->setCanvasBkColor(blackColor);
|
configuration->setCanvasBkColor(blackColor);
|
||||||
configuration->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
configuration->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||||||
|
|
||||||
auto configurationLabel = std::make_unique<Label>(20, 445, "配置区");
|
auto configurationLabel = std::make_unique<Label>(20, -10, "配置区");
|
||||||
configurationLabel->setTextdisap(true);
|
configurationLabel->setTextdisap(true);
|
||||||
|
|
||||||
std::array<std::unique_ptr<Button>,2> configurationButton;
|
std::array<std::unique_ptr<Button>, 2> configurationButton;
|
||||||
configurationButton[0] = std::make_unique<Button>(450, 465, 80, 20, "一键置0",
|
configurationButton[0] = std::make_unique<Button>(420, 10, 90, 20, "一键置0",
|
||||||
blackColor, RGB(171, 196, 220));
|
blackColor, RGB(171, 196, 220));
|
||||||
configurationButton[0]->textStyle.color = RGB(226, 116, 152);
|
configurationButton[0]->textStyle.color = RGB(226, 116, 152);
|
||||||
configurationButton[0]->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
configurationButton[0]->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
|
|
||||||
configurationButton[1] = std::make_unique<Button>(550, 465, 80, 20, "一键置1",
|
configurationButton[1] = std::make_unique<Button>(530, 10, 90, 20, "一键置1",
|
||||||
blackColor, RGB(171, 196, 220));
|
blackColor, RGB(171, 196, 220));
|
||||||
configurationButton[1]->textStyle.color = RGB(226, 116, 152);
|
configurationButton[1]->textStyle.color = RGB(226, 116, 152);
|
||||||
configurationButton[1]->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
configurationButton[1]->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
@@ -419,7 +425,7 @@ void main()
|
|||||||
|
|
||||||
|
|
||||||
auto signedToggle = std::make_unique<Button>(
|
auto signedToggle = std::make_unique<Button>(
|
||||||
350, 465, 80, 20, "无符号",
|
330, 10, 80, 20, "无符号",
|
||||||
blackColor, RGB(171, 196, 220), StellarX::ButtonMode::TOGGLE);
|
blackColor, RGB(171, 196, 220), StellarX::ButtonMode::TOGGLE);
|
||||||
signedToggle->textStyle.color = RGB(226, 116, 152);
|
signedToggle->textStyle.color = RGB(226, 116, 152);
|
||||||
signedToggle->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
signedToggle->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
@@ -428,7 +434,7 @@ void main()
|
|||||||
signedTogglePtr->setOnToggleOnListener([&]() {
|
signedTogglePtr->setOnToggleOnListener([&]() {
|
||||||
gSigned = true;
|
gSigned = true;
|
||||||
signedTogglePtr->setButtonText("有符号");
|
signedTogglePtr->setButtonText("有符号");
|
||||||
|
StellarX::MessageBox::showModal(mainWindow, "有符号模式下,\n最高位为符号位,\n其余位为数值位。", "有符号模式");
|
||||||
// 立即刷新十进制显示:用当前位图算出新值,仅改 dec
|
// 立即刷新十进制显示:用当前位图算出新值,仅改 dec
|
||||||
auto cur = snapshotBits();
|
auto cur = snapshotBits();
|
||||||
const uint32_t u = [&] { uint32_t v = 0; for (int b = 0; b < 32; ++b) if (cur[b]) v |= (1u << b); return v; }();
|
const uint32_t u = [&] { uint32_t v = 0; for (int b = 0; b < 32; ++b) if (cur[b]) v |= (1u << b); return v; }();
|
||||||
@@ -438,19 +444,20 @@ void main()
|
|||||||
signedTogglePtr->setOnToggleOffListener([&]() {
|
signedTogglePtr->setOnToggleOffListener([&]() {
|
||||||
gSigned = false;
|
gSigned = false;
|
||||||
signedTogglePtr->setButtonText("无符号");
|
signedTogglePtr->setButtonText("无符号");
|
||||||
|
StellarX::MessageBox::showAsync(mainWindow, "无符号模式下,\n所有位均为数值位。", "无符号模式");
|
||||||
auto cur = snapshotBits();
|
auto cur = snapshotBits();
|
||||||
const uint32_t u = [&] { uint32_t v = 0; for (int b = 0; b < 32; ++b) if (cur[b]) v |= (1u << b); return v; }();
|
const uint32_t u = [&] { uint32_t v = 0; for (int b = 0; b < 32; ++b) if (cur[b]) v |= (1u << b); return v; }();
|
||||||
dec->setText(std::to_string(u));
|
dec->setText(std::to_string(u));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
signedTogglePtr->enableTooltip(true);
|
||||||
|
signedTogglePtr->setTooltipTextsForToggle("切换无符号模式", "切换有符号模式");
|
||||||
|
|
||||||
configuration->addControl(std::move(configurationButton[0]));
|
configuration->addControl(std::move(configurationButton[0]));
|
||||||
configuration->addControl(std::move(configurationButton[1]));
|
configuration->addControl(std::move(configurationButton[1]));
|
||||||
configuration->addControl(std::move(signedToggle));
|
configuration->addControl(std::move(signedToggle));
|
||||||
configuration->addControl(std::move(configurationLabel));
|
configuration->addControl(std::move(configurationLabel));
|
||||||
|
|
||||||
|
|
||||||
mainWindow.addControl(std::move(selectionArea));
|
mainWindow.addControl(std::move(selectionArea));
|
||||||
mainWindow.addControl(std::move(function));
|
mainWindow.addControl(std::move(function));
|
||||||
mainWindow.addControl(std::move(NumericalDisplayArea));
|
mainWindow.addControl(std::move(NumericalDisplayArea));
|
||||||
|
|||||||
127
examples/登录界面/LoginInterface.cpp
Normal file
127
examples/登录界面/LoginInterface.cpp
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
// 本Demo基于 StellarX 构建,轻量级的 Windows GUI 框架。
|
||||||
|
#include"StellarX.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Window win(1300, 800, NULL, RGB(255, 255, 0), "记账管理系统");
|
||||||
|
|
||||||
|
/*********登录界面***********/
|
||||||
|
//标签
|
||||||
|
std::unique_ptr<Label> logIn_label[3];
|
||||||
|
Label* p[3];
|
||||||
|
logIn_label[0] = std::make_unique<Label>(90, 150, "欢迎使用餐馆记账管理系统");
|
||||||
|
logIn_label[1] = std::make_unique<Label>(400, 300, "账号");
|
||||||
|
logIn_label[2] = std::make_unique<Label>(400, 400, "密码");
|
||||||
|
p[0] = logIn_label[0].get();
|
||||||
|
for (auto& log : logIn_label)
|
||||||
|
{
|
||||||
|
log->setTextdisap(true);
|
||||||
|
log->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||||||
|
log->textStyle.lpszFace = "华文行楷";
|
||||||
|
}
|
||||||
|
logIn_label[0]->textStyle.nHeight = 100;
|
||||||
|
logIn_label[0]->setAnchor(StellarX::Anchor::Top, StellarX::Anchor::NoAnchor);
|
||||||
|
logIn_label[1]->textStyle.nHeight = 50;
|
||||||
|
logIn_label[1]->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||||||
|
logIn_label[2]->textStyle.nHeight = 50;
|
||||||
|
logIn_label[2]->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||||||
|
|
||||||
|
//输入框
|
||||||
|
std::unique_ptr<TextBox> logIn_textBox[2];
|
||||||
|
TextBox* logIn_textBox_ptr[2];
|
||||||
|
logIn_textBox[0] = std::make_unique<TextBox>(500, 295, 450, 50);
|
||||||
|
logIn_textBox[1] = std::make_unique<TextBox>(500, 395, 450, 50);
|
||||||
|
logIn_textBox_ptr[0] = logIn_textBox[0].get();
|
||||||
|
logIn_textBox_ptr[1] = logIn_textBox[1].get();
|
||||||
|
for (auto& tb : logIn_textBox)
|
||||||
|
{
|
||||||
|
tb->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||||||
|
tb->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||||||
|
tb->setMaxCharLen(15);
|
||||||
|
}
|
||||||
|
//按钮
|
||||||
|
std::unique_ptr<Button> logIn_Button[2];
|
||||||
|
Button* logIn_Button_ptr[2];
|
||||||
|
logIn_Button[0] = std::make_unique<Button>(350, 500, 300, 50, "管理员登录");
|
||||||
|
logIn_Button[1] = std::make_unique<Button>(750, 500, 300, 50, "操作员登录");
|
||||||
|
logIn_Button_ptr[0] = logIn_Button[0].get();
|
||||||
|
logIn_Button_ptr[1] = logIn_Button[1].get();
|
||||||
|
for (auto& b : logIn_Button)
|
||||||
|
{
|
||||||
|
b->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||||||
|
b->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||||||
|
}
|
||||||
|
//log画布
|
||||||
|
auto log_Canvas = std::make_unique<Canvas>(0, 0, 1300, 800);
|
||||||
|
Canvas* log_Canvas_ptr = log_Canvas.get();
|
||||||
|
log_Canvas_ptr->setCanvasfillMode(StellarX::FillMode::Null);
|
||||||
|
log_Canvas_ptr->setShape(StellarX::ControlShape::B_RECTANGLE);
|
||||||
|
log_Canvas_ptr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||||||
|
log_Canvas_ptr->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::Top);
|
||||||
|
|
||||||
|
//将log界面控价加入logCanvas统一管理
|
||||||
|
for (auto& b : logIn_Button)
|
||||||
|
log_Canvas_ptr->addControl(std::move(b));
|
||||||
|
for (auto& tb : logIn_textBox)
|
||||||
|
log_Canvas_ptr->addControl(std::move(tb));
|
||||||
|
for (auto& la : logIn_label)
|
||||||
|
log_Canvas_ptr->addControl(std::move(la));
|
||||||
|
|
||||||
|
/**************业务UI****************/
|
||||||
|
|
||||||
|
auto tabControl = std::make_unique<TabControl>(10, 10, 1280, 780);
|
||||||
|
auto tabControl_ptr = tabControl.get();
|
||||||
|
tabControl_ptr->setIsVisible(false);
|
||||||
|
tabControl_ptr->setCanvasfillMode(StellarX::FillMode::Null);
|
||||||
|
tabControl_ptr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||||||
|
tabControl_ptr->setTabPlacement(StellarX::TabPlacement::Left);
|
||||||
|
tabControl_ptr->setTabBarHeight(100);
|
||||||
|
//添加页签及页
|
||||||
|
auto tabP = std::make_pair(std::make_unique<Button>(0, 0, 100, 100, "点餐"), std::make_unique<Canvas>(0, 0, 1290, 790));
|
||||||
|
tabP.second->setCanvasfillMode(StellarX::FillMode::Null);
|
||||||
|
tabP.second->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||||||
|
|
||||||
|
tabControl_ptr->add(std::move(tabP));
|
||||||
|
|
||||||
|
/*------------login事件-------------*/
|
||||||
|
//管理员登录按钮事件
|
||||||
|
logIn_Button_ptr[0]->setOnClickListener([&p, &tabControl_ptr, &log_Canvas_ptr, &logIn_textBox_ptr, &win]()
|
||||||
|
{
|
||||||
|
if ("\0" == logIn_textBox_ptr[0]->getText() || "\0" == logIn_textBox_ptr[1]->getText())
|
||||||
|
{
|
||||||
|
if ("\0" == logIn_textBox_ptr[0]->getText())logIn_textBox_ptr[0]->setTextBoxBk(RGB(255, 0, 0));
|
||||||
|
if ("\0" == logIn_textBox_ptr[1]->getText())logIn_textBox_ptr[1]->setTextBoxBk(RGB(255, 0, 0));
|
||||||
|
std::cout << "\a";
|
||||||
|
StellarX::MessageBox::showModal(win, "账号或密码不能为空!", "提示");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log_Canvas_ptr->setIsVisible(false);
|
||||||
|
tabControl_ptr->setIsVisible(true);
|
||||||
|
win.draw("image\\bk1.jpg");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//操作员登录按钮事件
|
||||||
|
logIn_Button_ptr[1]->setOnClickListener([&tabControl_ptr, &log_Canvas_ptr, &logIn_textBox_ptr, &win]()
|
||||||
|
{
|
||||||
|
if ("\0" == logIn_textBox_ptr[0]->getText() || "\0" == logIn_textBox_ptr[1]->getText())
|
||||||
|
{
|
||||||
|
if ("\0" == logIn_textBox_ptr[0]->getText())logIn_textBox_ptr[0]->setTextBoxBk(RGB(255, 0, 0));
|
||||||
|
if ("\0" == logIn_textBox_ptr[1]->getText())logIn_textBox_ptr[1]->setTextBoxBk(RGB(255, 0, 0));
|
||||||
|
std::cout << "\a";
|
||||||
|
StellarX::MessageBox::showModal(win, "账号或密码不能为空!", "提示");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log_Canvas_ptr->setIsVisible(false);
|
||||||
|
tabControl_ptr->setIsVisible(true);
|
||||||
|
win.draw("image\\bk1.jpg");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
win.addControl(std::move(log_Canvas));
|
||||||
|
win.addControl(std::move(tabControl));
|
||||||
|
win.draw("image\\bk1.jpg");
|
||||||
|
|
||||||
|
return win.runEventLoop();
|
||||||
|
}
|
||||||
BIN
examples/登录界面/image/bk1.jpg
Normal file
BIN
examples/登录界面/image/bk1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 MiB |
BIN
examples/登录界面/image/lo_bk2.jpg
Normal file
BIN
examples/登录界面/image/lo_bk2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
BIN
examples/登录界面/image/星垣logo.png
Normal file
BIN
examples/登录界面/image/星垣logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
BIN
image/1.png
Normal file
BIN
image/1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
BIN
image/2.png
Normal file
BIN
image/2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 87 KiB |
@@ -21,14 +21,14 @@
|
|||||||
#include "Control.h"
|
#include "Control.h"
|
||||||
#include"label.h"
|
#include"label.h"
|
||||||
|
|
||||||
|
|
||||||
#define DISABLEDCOLOUR RGB(96, 96, 96) //禁用状态颜色
|
#define DISABLEDCOLOUR RGB(96, 96, 96) //禁用状态颜色
|
||||||
#define TEXTMARGINS_X 6
|
#define TEXTMARGINS_X 6
|
||||||
#define TEXTMARGINS_Y 4
|
#define TEXTMARGINS_Y 4
|
||||||
|
constexpr int bordWith = 1; //边框宽度,用于快照恢复时的偏移计算
|
||||||
|
constexpr int bordHeight = 1; //边框高度,用于快照恢复时的偏移计算
|
||||||
|
|
||||||
class Button : public Control
|
class Button : public Control
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string text; // 按钮上的文字
|
std::string text; // 按钮上的文字
|
||||||
bool click; // 是否被点击
|
bool click; // 是否被点击
|
||||||
bool hover; // 是否被悬停
|
bool hover; // 是否被悬停
|
||||||
@@ -42,7 +42,7 @@ class Button : public Control
|
|||||||
COLORREF buttonTrueColor; // 按钮被点击后的颜色
|
COLORREF buttonTrueColor; // 按钮被点击后的颜色
|
||||||
COLORREF buttonFalseColor; // 按钮未被点击的颜色
|
COLORREF buttonFalseColor; // 按钮未被点击的颜色
|
||||||
COLORREF buttonHoverColor; // 按钮被鼠标悬停的颜色
|
COLORREF buttonHoverColor; // 按钮被鼠标悬停的颜色
|
||||||
COLORREF buttonBorderColor = RGB(0,0,0);// 按钮边框颜色
|
COLORREF buttonBorderColor = RGB(0, 0, 0);// 按钮边框颜色
|
||||||
|
|
||||||
StellarX::ButtonMode mode; // 按钮模式
|
StellarX::ButtonMode mode; // 按钮模式
|
||||||
StellarX::ControlShape shape; // 按钮形状
|
StellarX::ControlShape shape; // 按钮形状
|
||||||
@@ -51,8 +51,6 @@ class Button : public Control
|
|||||||
StellarX::FillStyle buttonFillIma = StellarX::FillStyle::BDiagonal; //按钮填充图案
|
StellarX::FillStyle buttonFillIma = StellarX::FillStyle::BDiagonal; //按钮填充图案
|
||||||
IMAGE* buttonFileIMAGE = nullptr; //按钮填充图像
|
IMAGE* buttonFileIMAGE = nullptr; //按钮填充图像
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::function<void()> onClickCallback; //回调函数
|
std::function<void()> onClickCallback; //回调函数
|
||||||
std::function<void()> onToggleOnCallback; //TOGGLE模式下的回调函数
|
std::function<void()> onToggleOnCallback; //TOGGLE模式下的回调函数
|
||||||
std::function<void()> onToggleOffCallback; //TOGGLE模式下的回调函数
|
std::function<void()> onToggleOffCallback; //TOGGLE模式下的回调函数
|
||||||
@@ -94,7 +92,7 @@ public:
|
|||||||
StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE);
|
StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE);
|
||||||
//自定义按钮颜色和悬停颜色
|
//自定义按钮颜色和悬停颜色
|
||||||
Button(int x, int y, int width, int height, const std::string text,
|
Button(int x, int y, int width, int height, const std::string text,
|
||||||
COLORREF ct, COLORREF cf,COLORREF ch,
|
COLORREF ct, COLORREF cf, COLORREF ch,
|
||||||
StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL, StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE);
|
StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL, StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE);
|
||||||
//析构函数 释放图形指针内存
|
//析构函数 释放图形指针内存
|
||||||
~Button();
|
~Button();
|
||||||
@@ -173,7 +171,7 @@ public:
|
|||||||
//设置提示框样式
|
//设置提示框样式
|
||||||
void setTooltipStyle(COLORREF text, COLORREF bk, bool transparent);
|
void setTooltipStyle(COLORREF text, COLORREF bk, bool transparent);
|
||||||
//设置提示框文本
|
//设置提示框文本
|
||||||
void setTooltipText(const std::string& s){ tipTextClick = s; tipUserOverride = true; }
|
void setTooltipText(const std::string& s) { tipTextClick = s; tipUserOverride = true; }
|
||||||
void setTooltipTextsForToggle(const std::string& onText, const std::string& offText);
|
void setTooltipTextsForToggle(const std::string& onText, const std::string& offText);
|
||||||
private:
|
private:
|
||||||
//初始化按钮
|
//初始化按钮
|
||||||
@@ -189,6 +187,4 @@ private:
|
|||||||
void hideTooltip();
|
void hideTooltip();
|
||||||
// 根据当前 click 状态选择文案
|
// 根据当前 click 状态选择文案
|
||||||
void refreshTooltipTextForState();
|
void refreshTooltipTextForState();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Control.h"
|
#include "Control.h"
|
||||||
|
#include"Table.h"
|
||||||
|
|
||||||
class Canvas : public Control
|
class Canvas : public Control
|
||||||
{
|
{
|
||||||
@@ -30,8 +31,7 @@ protected:
|
|||||||
int canvaslinewidth = 1; //线宽
|
int canvaslinewidth = 1; //线宽
|
||||||
|
|
||||||
COLORREF canvasBorderClor = RGB(0, 0, 0); //边框颜色
|
COLORREF canvasBorderClor = RGB(0, 0, 0); //边框颜色
|
||||||
COLORREF canvasBkClor = RGB(255,255,255); //背景颜色
|
COLORREF canvasBkClor = RGB(255, 255, 255); //背景颜色
|
||||||
|
|
||||||
|
|
||||||
// 清除所有子控件
|
// 清除所有子控件
|
||||||
void clearAllControls();
|
void clearAllControls();
|
||||||
@@ -39,6 +39,10 @@ public:
|
|||||||
Canvas();
|
Canvas();
|
||||||
Canvas(int x, int y, int width, int height);
|
Canvas(int x, int y, int width, int height);
|
||||||
~Canvas() {}
|
~Canvas() {}
|
||||||
|
|
||||||
|
void setX(int x)override;
|
||||||
|
void setY(int y)override;
|
||||||
|
|
||||||
//绘制容器及其子控件
|
//绘制容器及其子控件
|
||||||
void draw() override;
|
void draw() override;
|
||||||
bool handleEvent(const ExMessage& msg) override;
|
bool handleEvent(const ExMessage& msg) override;
|
||||||
@@ -67,4 +71,3 @@ private:
|
|||||||
//用来检查对话框是否模态,此控件不做实现
|
//用来检查对话框是否模态,此控件不做实现
|
||||||
bool model() const override { return false; };
|
bool model() const override { return false; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,23 +9,20 @@
|
|||||||
* - 定义控件基本属性(坐标、尺寸、脏标记)
|
* - 定义控件基本属性(坐标、尺寸、脏标记)
|
||||||
* - 提供绘图状态管理(saveStyle/restoreStyle)
|
* - 提供绘图状态管理(saveStyle/restoreStyle)
|
||||||
* - 声明纯虚接口(draw、handleEvent等)
|
* - 声明纯虚接口(draw、handleEvent等)
|
||||||
* - 支持移动语义,禁止拷贝语义
|
* - 禁止移动语义,禁止拷贝语义
|
||||||
*
|
*
|
||||||
* @使用场景: 作为所有具体控件类的基类,不直接实例化
|
* @使用场景: 作为所有具体控件类的基类,不直接实例化
|
||||||
* @所属框架: 星垣(StellarX) GUI框架
|
* @所属框架: 星垣(StellarX) GUI框架
|
||||||
* @作者: 我在人间做废物
|
* @作者: 我在人间做废物
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef _WIN32_WINNT
|
#ifndef _WIN32_WINNT
|
||||||
#define _WIN32_WINNT 0x0600
|
#define _WIN32_WINNT 0x0600
|
||||||
#endif
|
#endif
|
||||||
#ifndef WINVER
|
#ifndef WINVER
|
||||||
#define WINVER _WIN32_WINNT
|
#define WINVER _WIN32_WINNT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <easyx.h>
|
#include <easyx.h>
|
||||||
@@ -39,12 +36,17 @@ class Control
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::string id; // 控件ID
|
std::string id; // 控件ID
|
||||||
int localx,x, localy,y; // 左上角坐标
|
int localx, x, localy, y; // 左上角坐标
|
||||||
int localWidth,width, localHeight,height; // 控件尺寸
|
int localWidth, width, localHeight, height; // 控件尺寸
|
||||||
Control* parent = nullptr; // 父控件
|
Control* parent = nullptr; // 父控件
|
||||||
bool dirty = true; // 是否重绘
|
bool dirty = true; // 是否重绘
|
||||||
bool show = true; // 是否显示
|
bool show = true; // 是否显示
|
||||||
|
|
||||||
|
/* == 布局模式 == */
|
||||||
|
StellarX::LayoutMode layoutMode = StellarX::LayoutMode::Fixed; // 布局模式
|
||||||
|
StellarX::Anchor anchor_1 = StellarX::Anchor::Top; // 锚点
|
||||||
|
StellarX::Anchor anchor_2 = StellarX::Anchor::Right; // 锚点
|
||||||
|
|
||||||
/* == 背景快照 == */
|
/* == 背景快照 == */
|
||||||
IMAGE* saveBkImage = nullptr;
|
IMAGE* saveBkImage = nullptr;
|
||||||
int saveBkX = 0, saveBkY = 0; // 快照保存起始坐标
|
int saveBkX = 0, saveBkY = 0; // 快照保存起始坐标
|
||||||
@@ -64,9 +66,10 @@ protected:
|
|||||||
Control(Control&&) = delete;
|
Control(Control&&) = delete;
|
||||||
Control& operator=(Control&&) = delete;
|
Control& operator=(Control&&) = delete;
|
||||||
|
|
||||||
Control() : localx(0),x(0), localy(0),y(0), localWidth(100),width(100),height(100), localHeight(100) {}
|
Control() : localx(0), x(0), localy(0), y(0), localWidth(100), width(100), height(100), localHeight(100) {}
|
||||||
Control(int x, int y, int width, int height)
|
Control(int x, int y, int width, int height)
|
||||||
: localx(x), x(x), localy(y), y(y), localWidth(width), width(width), height(height), localHeight(height){}
|
: localx(x), x(x), localy(y), y(y), localWidth(width), width(width), height(height), localHeight(height) {
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~Control()
|
virtual ~Control()
|
||||||
@@ -116,10 +119,10 @@ public:
|
|||||||
int getLocalRight() const { return localx + localWidth; }
|
int getLocalRight() const { return localx + localWidth; }
|
||||||
int getLocalBottom() const { return localy + localHeight; }
|
int getLocalBottom() const { return localy + localHeight; }
|
||||||
|
|
||||||
void setX(int x) { this->x = x; dirty = true; }
|
virtual void setX(int x) { this->x = x; dirty = true; }
|
||||||
void setY(int y) { this->y = y; dirty = true; }
|
virtual void setY(int y) { this->y = y; dirty = true; }
|
||||||
void setWidth(int width) { this->width = width; dirty = true; }
|
virtual void setWidth(int width) { this->width = width; dirty = true; }
|
||||||
void setHeight(int height) { this->height = height; dirty = true; }
|
virtual void setHeight(int height) { this->height = height; dirty = true; }
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void draw() = 0;
|
virtual void draw() = 0;
|
||||||
@@ -130,7 +133,6 @@ public:
|
|||||||
void setParent(Control* parent) { this->parent = parent; }
|
void setParent(Control* parent) { this->parent = parent; }
|
||||||
//设置是否重绘
|
//设置是否重绘
|
||||||
virtual void setDirty(bool dirty) { this->dirty = dirty; }
|
virtual void setDirty(bool dirty) { this->dirty = dirty; }
|
||||||
|
|
||||||
//检查控件是否可见
|
//检查控件是否可见
|
||||||
bool IsVisible() const { return show; };
|
bool IsVisible() const { return show; };
|
||||||
//获取控件id
|
//获取控件id
|
||||||
@@ -139,6 +141,12 @@ public:
|
|||||||
bool isDirty() { return dirty; }
|
bool isDirty() { return dirty; }
|
||||||
//用来检查对话框是否模态,其他控件不用实现
|
//用来检查对话框是否模态,其他控件不用实现
|
||||||
virtual bool model()const = 0;
|
virtual bool model()const = 0;
|
||||||
|
//布局
|
||||||
|
void setLayoutMode(StellarX::LayoutMode layoutMode_);
|
||||||
|
void setAnchor(StellarX::Anchor anchor_1, StellarX::Anchor anchor_2);
|
||||||
|
StellarX::Anchor getAnchor_1() const;
|
||||||
|
StellarX::Anchor getAnchor_2() const;
|
||||||
|
StellarX::LayoutMode getLayoutMode() const;
|
||||||
protected:
|
protected:
|
||||||
void saveStyle();
|
void saveStyle();
|
||||||
void restoreStyle();
|
void restoreStyle();
|
||||||
|
|||||||
@@ -207,7 +207,8 @@ namespace StellarX
|
|||||||
enum class TextBoxmode
|
enum class TextBoxmode
|
||||||
{
|
{
|
||||||
INPUT_MODE, // 用户可输入模式
|
INPUT_MODE, // 用户可输入模式
|
||||||
READONLY_MODE // 只读模式
|
READONLY_MODE, // 只读模式
|
||||||
|
PASSWORD_MODE// 密码模式
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -343,4 +344,47 @@ namespace StellarX
|
|||||||
Left,
|
Left,
|
||||||
Right
|
Right
|
||||||
};
|
};
|
||||||
|
/*
|
||||||
|
* @枚举名称: LayoutMode
|
||||||
|
* @功能描述: 定义了两种布局模式
|
||||||
|
*
|
||||||
|
* @详细说明:
|
||||||
|
* 根据不同模式,在窗口拉伸时采用不同的布局策略
|
||||||
|
*
|
||||||
|
* @成员说明:
|
||||||
|
* Fixed, - 固定布局
|
||||||
|
* AnchorToEdges - 锚定布局
|
||||||
|
*
|
||||||
|
* @使用示例:
|
||||||
|
* LayoutMode mode = LayoutMode::Fixed;
|
||||||
|
*/
|
||||||
|
enum class LayoutMode
|
||||||
|
{
|
||||||
|
Fixed,
|
||||||
|
AnchorToEdges
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
* @枚举名称: Anchor
|
||||||
|
* @功能描述: 定义了控件相对于窗口锚定的位置
|
||||||
|
*
|
||||||
|
* @详细说明:
|
||||||
|
* 根据不同的锚定位置,有不同的拉伸策略
|
||||||
|
*
|
||||||
|
* @成员说明:
|
||||||
|
* Top, - 锚定上边,控件上边与窗口上侧距离保持不变
|
||||||
|
* Bottom, - 锚定底边,控件底边与窗口底边距离保持不变
|
||||||
|
* Left, - 锚定左边,控件左边与窗口左侧距离保持不变
|
||||||
|
* Right - 锚定右边,控件上边与窗口右侧距离保持不变
|
||||||
|
*
|
||||||
|
* @使用示例:
|
||||||
|
* Anchor a = Anchor::Top;
|
||||||
|
*/
|
||||||
|
enum class Anchor
|
||||||
|
{
|
||||||
|
NoAnchor = 0,
|
||||||
|
Left = 1,
|
||||||
|
Right,
|
||||||
|
Top,
|
||||||
|
Bottom
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,6 @@ class Dialog : public Canvas
|
|||||||
std::string message; //提示信息
|
std::string message; //提示信息
|
||||||
std::vector<std::string> lines; //消息内容按行分割
|
std::vector<std::string> lines; //消息内容按行分割
|
||||||
|
|
||||||
|
|
||||||
bool needsInitialization = true; //是否需要初始化
|
bool needsInitialization = true; //是否需要初始化
|
||||||
bool close = false; //是否关闭
|
bool close = false; //是否关闭
|
||||||
bool modal = true; //是否模态
|
bool modal = true; //是否模态
|
||||||
@@ -57,7 +56,6 @@ class Dialog : public Canvas
|
|||||||
COLORREF buttonFalseColor = RGB(215, 215, 215); //按钮未被点击颜色
|
COLORREF buttonFalseColor = RGB(215, 215, 215); //按钮未被点击颜色
|
||||||
COLORREF buttonHoverColor = RGB(224, 224, 224); //按钮悬浮颜色
|
COLORREF buttonHoverColor = RGB(224, 224, 224); //按钮悬浮颜色
|
||||||
|
|
||||||
|
|
||||||
Button* closeButton = nullptr; //关闭按钮
|
Button* closeButton = nullptr; //关闭按钮
|
||||||
|
|
||||||
StellarX::MessageBoxResult result = StellarX::MessageBoxResult::Cancel; // 对话框结果
|
StellarX::MessageBoxResult result = StellarX::MessageBoxResult::Cancel; // 对话框结果
|
||||||
@@ -78,7 +76,6 @@ public:
|
|||||||
//获取对话框消息,用以去重
|
//获取对话框消息,用以去重
|
||||||
std::string GetText() const;
|
std::string GetText() const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Dialog(Window& hWnd, std::string text, std::string message = "对话框", StellarX::MessageBoxType type = StellarX::MessageBoxType::OK, bool modal = true);
|
Dialog(Window& hWnd, std::string text, std::string message = "对话框", StellarX::MessageBoxType type = StellarX::MessageBoxType::OK, bool modal = true);
|
||||||
~Dialog();
|
~Dialog();
|
||||||
@@ -109,7 +106,6 @@ public:
|
|||||||
//初始化
|
//初始化
|
||||||
void setInitialization(bool init);
|
void setInitialization(bool init);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 初始化按钮
|
// 初始化按钮
|
||||||
void initButtons();
|
void initButtons();
|
||||||
@@ -123,10 +119,7 @@ private:
|
|||||||
void getTextSize();
|
void getTextSize();
|
||||||
//初始化对话框尺寸
|
//初始化对话框尺寸
|
||||||
void initDialogSize();
|
void initDialogSize();
|
||||||
void saveBackground(int x, int y, int w, int h)override;
|
void addControl(std::unique_ptr<Control> control);
|
||||||
|
|
||||||
void restBackground()override;
|
|
||||||
|
|
||||||
|
|
||||||
// 清除所有控件
|
// 清除所有控件
|
||||||
void clearControls();
|
void clearControls();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* @文件: StellarX.h
|
* @文件: StellarX.h
|
||||||
* @摘要: 星垣(StellarX) GUI框架 - 主包含头文件
|
* @摘要: 星垣(StellarX) GUI框架 - 主包含头文件
|
||||||
* @版本: v2.2.1
|
* @版本: v2.3.2
|
||||||
* @描述:
|
* @描述:
|
||||||
* 一个为Windows平台打造的轻量级、模块化C++ GUI框架。
|
* 一个为Windows平台打造的轻量级、模块化C++ GUI框架。
|
||||||
* 基于EasyX图形库,提供简洁易用的API和丰富的控件。
|
* 基于EasyX图形库,提供简洁易用的API和丰富的控件。
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
*
|
*
|
||||||
* @作者: 我在人间做废物
|
* @作者: 我在人间做废物
|
||||||
* @邮箱: [3150131407@qq.com] | [ysm3150131407@gmail.com]
|
* @邮箱: [3150131407@qq.com] | [ysm3150131407@gmail.com]
|
||||||
|
* @官网:https://stellarx-gui.top/
|
||||||
* @仓库: [https://github.com/Ysm-04/StellarX]
|
* @仓库: [https://github.com/Ysm-04/StellarX]
|
||||||
*
|
*
|
||||||
* @许可证: MIT License
|
* @许可证: MIT License
|
||||||
|
|||||||
@@ -26,8 +26,10 @@
|
|||||||
class TabControl :public Canvas
|
class TabControl :public Canvas
|
||||||
{
|
{
|
||||||
int tabBarHeight = BUTMINWIDTH; //页签栏高度
|
int tabBarHeight = BUTMINWIDTH; //页签栏高度
|
||||||
StellarX::TabPlacement tabPlacement = StellarX::TabPlacement::Top ; //页签排列方式
|
bool IsFirstDraw = true; //首次绘制标记
|
||||||
std::vector<std::pair<std::unique_ptr<Button>,std::unique_ptr<Canvas>>> controls; //页签/页列表
|
int defaultActivation = -1; //默认激活页签索引
|
||||||
|
StellarX::TabPlacement tabPlacement = StellarX::TabPlacement::Top; //页签排列方式
|
||||||
|
std::vector<std::pair<std::unique_ptr<Button>, std::unique_ptr<Canvas>>> controls; //页签/页列表
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Canvas::addControl; // 禁止外部误用
|
using Canvas::addControl; // 禁止外部误用
|
||||||
@@ -37,16 +39,19 @@ private:
|
|||||||
inline void initTabPage();
|
inline void initTabPage();
|
||||||
public:
|
public:
|
||||||
TabControl();
|
TabControl();
|
||||||
TabControl(int x,int y,int width,int height);
|
TabControl(int x, int y, int width, int height);
|
||||||
~TabControl();
|
~TabControl();
|
||||||
|
|
||||||
|
void setX(int x)override;
|
||||||
|
void setY(int y)override;
|
||||||
|
|
||||||
void draw() override;
|
void draw() override;
|
||||||
bool handleEvent(const ExMessage& msg) override;
|
bool handleEvent(const ExMessage& msg) override;
|
||||||
|
|
||||||
//添加页签+页
|
//添加页签+页
|
||||||
void add(std::pair<std::unique_ptr<Button> ,std::unique_ptr<Canvas>>&& control);
|
void add(std::pair<std::unique_ptr<Button>, std::unique_ptr<Canvas>>&& control);
|
||||||
//添加为某个页添加控件
|
//添加为某个页添加控件
|
||||||
void add(std::string tabText,std::unique_ptr<Control> control);
|
void add(std::string tabText, std::unique_ptr<Control> control);
|
||||||
//设置页签位置
|
//设置页签位置
|
||||||
void setTabPlacement(StellarX::TabPlacement placement);
|
void setTabPlacement(StellarX::TabPlacement placement);
|
||||||
//设置页签栏高度 两侧排列时为宽度
|
//设置页签栏高度 两侧排列时为宽度
|
||||||
@@ -65,4 +70,3 @@ public:
|
|||||||
void setDirty(bool dirty) override;
|
void setDirty(bool dirty) override;
|
||||||
void requestRepaint(Control* parent)override;
|
void requestRepaint(Control* parent)override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public:
|
|||||||
StellarX::ControlText textStyle; //标签文本样式
|
StellarX::ControlText textStyle; //标签文本样式
|
||||||
public:
|
public:
|
||||||
Label();
|
Label();
|
||||||
Label(int x, int y, std::string text = "标签",COLORREF textcolor = BLACK, COLORREF bkColor= RGB(255,255,255));
|
Label(int x, int y, std::string text = "标签", COLORREF textcolor = BLACK, COLORREF bkColor = RGB(255, 255, 255));
|
||||||
|
|
||||||
void draw() override;
|
void draw() override;
|
||||||
void hide();
|
void hide();
|
||||||
@@ -43,6 +43,4 @@ public:
|
|||||||
void setTextBkColor(COLORREF color);
|
void setTextBkColor(COLORREF color);
|
||||||
//设置标签文本
|
//设置标签文本
|
||||||
void setText(std::string text);
|
void setText(std::string text);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
#define TABLE_STR_PAGE_MID "页/共"
|
#define TABLE_STR_PAGE_MID "页/共"
|
||||||
#define TABLE_STR_PAGE_SUFFIX "页"
|
#define TABLE_STR_PAGE_SUFFIX "页"
|
||||||
|
|
||||||
|
|
||||||
class Table :public Control
|
class Table :public Control
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -69,6 +68,7 @@ private:
|
|||||||
bool isShowPageButton = true; // 是否显示翻页按钮
|
bool isShowPageButton = true; // 是否显示翻页按钮
|
||||||
bool isNeedDrawHeaders = true; // 是否需要绘制表头
|
bool isNeedDrawHeaders = true; // 是否需要绘制表头
|
||||||
bool isNeedCellSize = true; // 是否需要计算单元格尺寸
|
bool isNeedCellSize = true; // 是否需要计算单元格尺寸
|
||||||
|
bool isNeedButtonAndPageNum = true; // 是否需要计算翻页按钮和页码信息
|
||||||
|
|
||||||
Button* prevButton = nullptr; // 上一页按钮
|
Button* prevButton = nullptr; // 上一页按钮
|
||||||
Button* nextButton = nullptr; // 下一页按钮
|
Button* nextButton = nullptr; // 下一页按钮
|
||||||
@@ -98,7 +98,10 @@ private:
|
|||||||
bool model() const override { return false; };
|
bool model() const override { return false; };
|
||||||
public:
|
public:
|
||||||
StellarX::ControlText textStyle; // 文本样式
|
StellarX::ControlText textStyle; // 文本样式
|
||||||
|
void setX(int x) override;
|
||||||
|
void setY(int y) override;
|
||||||
|
void setWidth(int width) override;
|
||||||
|
void setHeight(int height) override;
|
||||||
public:
|
public:
|
||||||
Table(int x, int y);
|
Table(int x, int y);
|
||||||
~Table();
|
~Table();
|
||||||
@@ -127,6 +130,14 @@ public:
|
|||||||
void setTableLineStyle(StellarX::LineStyle style);
|
void setTableLineStyle(StellarX::LineStyle style);
|
||||||
//设置边框宽度
|
//设置边框宽度
|
||||||
void setTableBorderWidth(int width);
|
void setTableBorderWidth(int width);
|
||||||
|
//清空表头
|
||||||
|
void clearHeaders();
|
||||||
|
//清空表格数据
|
||||||
|
void clearData();
|
||||||
|
//清空表头和数据
|
||||||
|
void resetTable();
|
||||||
|
//窗口变化丢快照+标脏
|
||||||
|
void onWindowResize() override;
|
||||||
|
|
||||||
//************************** 获取属性 *****************************/
|
//************************** 获取属性 *****************************/
|
||||||
|
|
||||||
@@ -147,12 +158,12 @@ public:
|
|||||||
//获取线型
|
//获取线型
|
||||||
StellarX::LineStyle getTableLineStyle() const;
|
StellarX::LineStyle getTableLineStyle() const;
|
||||||
//获取表头
|
//获取表头
|
||||||
std::vector<std::string> getHeaders () const;
|
std::vector<std::string> getHeaders() const;
|
||||||
//获取表格数据
|
//获取表格数据
|
||||||
std::vector<std::vector<std::string>> getData() const;
|
std::vector<std::vector<std::string>> getData() const;
|
||||||
//获取表格边框宽度
|
//获取表格边框宽度
|
||||||
int getTableBorderWidth() const;
|
int getTableBorderWidth() const;
|
||||||
|
//获取表格尺寸
|
||||||
|
int getTableWidth() const;
|
||||||
|
int getTableHeight() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Control.h"
|
#include "Control.h"
|
||||||
|
|
||||||
|
|
||||||
class TextBox : public Control
|
class TextBox : public Control
|
||||||
{
|
{
|
||||||
std::string text; //文本
|
std::string text; //文本
|
||||||
@@ -27,7 +26,7 @@ class TextBox : public Control
|
|||||||
bool click = false; //是否点击
|
bool click = false; //是否点击
|
||||||
size_t maxCharLen = 10;//最大字符长度
|
size_t maxCharLen = 10;//最大字符长度
|
||||||
COLORREF textBoxBkClor = RGB(255, 255, 255); //背景颜色
|
COLORREF textBoxBkClor = RGB(255, 255, 255); //背景颜色
|
||||||
COLORREF textBoxBorderClor = RGB(0,0,0); //边框颜色
|
COLORREF textBoxBorderClor = RGB(0, 0, 0); //边框颜色
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StellarX::ControlText textStyle; //文本样式
|
StellarX::ControlText textStyle; //文本样式
|
||||||
@@ -55,5 +54,3 @@ private:
|
|||||||
//用来检查对话框是否模态,此控件不做实现
|
//用来检查对话框是否模态,此控件不做实现
|
||||||
bool model() const override { return false; };
|
bool model() const override { return false; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,86 +1,108 @@
|
|||||||
|
/**
|
||||||
|
* Window(头文件)
|
||||||
|
*
|
||||||
|
* 设计目标:
|
||||||
|
* - 提供一个基于 Win32 + EasyX 的“可拉伸且稳定不抖”的窗口容器。
|
||||||
|
* - 通过消息过程子类化(WndProcThunk)接管关键消息(WM_SIZING/WM_SIZE/...)。
|
||||||
|
* - 将“几何变化记录(pendingW/H)”与“统一收口重绘(needResizeDirty)”解耦。
|
||||||
|
*
|
||||||
|
* 关键点(与 .cpp 中实现对应):
|
||||||
|
* - isSizing:处于交互拉伸阶段时,冻结重绘;松手后统一重绘,防止抖动。
|
||||||
|
* - WM_SIZING:只做“最小尺寸夹紧”,不回滚矩形、不做对齐;把其余交给系统。
|
||||||
|
* - WM_GETMINMAXINFO:按最小“客户区”换算到“窗口矩形”,提供系统层最小轨迹值。
|
||||||
|
* - runEventLoop:只记录 WM_SIZE 的新尺寸;真正绘制放在 needResizeDirty 时集中处理。
|
||||||
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include"Control.h"
|
|
||||||
/*******************************************************************************
|
#include "Control.h"
|
||||||
* @类: Window
|
#include <string>
|
||||||
* @摘要: 应用程序主窗口类,管理窗口生命周期和消息循环
|
#include <vector>
|
||||||
* @描述:
|
#include <memory>
|
||||||
* 创建和管理应用程序主窗口,作为所有控件的根容器。
|
#include <windows.h>
|
||||||
* 处理消息分发、事件循环和渲染调度。
|
|
||||||
*
|
|
||||||
* @特性:
|
|
||||||
* - 多种窗口模式配置(双缓冲、控制台等)
|
|
||||||
* - 背景图片和颜色支持
|
|
||||||
* - 集成的对话框管理系统
|
|
||||||
* - 完整的消息处理循环
|
|
||||||
* - 控件和对话框的生命周期管理
|
|
||||||
*
|
|
||||||
* @使用场景: 应用程序主窗口,GUI程序的入口和核心
|
|
||||||
* @所属框架: 星垣(StellarX) GUI框架
|
|
||||||
* @作者: 我在人间做废物
|
|
||||||
******************************************************************************/
|
|
||||||
class Window
|
class Window
|
||||||
{
|
{
|
||||||
int width; //窗口宽度
|
// —— 尺寸状态 ——(绘制尺寸与待应用尺寸分离;收口时一次性更新)
|
||||||
int height; //窗口高度
|
int width; // 当前有效宽(已应用到画布/控件的客户区宽)
|
||||||
int windowMode = NULL; //窗口模式
|
int height; // 当前有效高(已应用到画布/控件的客户区高)
|
||||||
|
int localwidth; // 基准宽(创建时的宽度)
|
||||||
|
int localheight; // 基准高(创建是的高度)
|
||||||
|
int pendingW; // 待应用宽(WM_SIZE/拉伸中记录用)
|
||||||
|
int pendingH; // 待应用高
|
||||||
|
int minClientW; // 业务设定的最小客户区宽(用于 GETMINMAXINFO 与 SIZING 夹紧)
|
||||||
|
int minClientH; // 业务设定的最小客户区高
|
||||||
|
int windowMode = NULL; // EasyX 初始化模式(EX_SHOWCONSOLE/EX_TOPMOST/...)
|
||||||
|
bool needResizeDirty = false; // 统一收口重绘标志(置位后在事件环末尾处理)
|
||||||
|
bool isSizing = false; // 是否处于拖拽阶段(ENTER/EXIT SIZEMOVE 切换)
|
||||||
|
|
||||||
// --- 尺寸变化去抖用 ---
|
// —— 原生窗口句柄与子类化钩子 ——(子类化 EasyX 的窗口过程以拦截关键消息)
|
||||||
int pendingW;
|
HWND hWnd = NULL; // EasyX 初始化后的窗口句柄
|
||||||
int pendingH;
|
WNDPROC oldWndProc = nullptr; // 保存旧过程(CallWindowProc 回落)
|
||||||
bool needResizeDirty = false;
|
bool procHooked = false; // 避免重复子类化
|
||||||
|
static LRESULT CALLBACK WndProcThunk(HWND h, UINT m, WPARAM w, LPARAM l); // 静态过程分发到 this
|
||||||
|
|
||||||
HWND hWnd = NULL; //窗口句柄
|
// —— 绘制相关 ——(是否使用合成双缓冲、窗口标题、背景等)
|
||||||
std::string headline; //窗口标题
|
bool useComposited = true; // 是否启用 WS_EX_COMPOSITED(部分机器可能增加一帧观感延迟)
|
||||||
COLORREF wBkcolor = BLACK; //窗口背景
|
std::string headline; // 窗口标题文本
|
||||||
IMAGE* background = nullptr; //窗口背景图片
|
COLORREF wBkcolor = BLACK; // 纯色背景(无背景图时使用)
|
||||||
std::string bkImageFile; //窗口背景图片文件名
|
IMAGE* background = nullptr; // 背景图对象指针(存在时优先绘制)
|
||||||
std::vector<std::unique_ptr<Control>> controls; //控件管理
|
std::string bkImageFile; // 背景图文件路径(loadimage 用)
|
||||||
std::vector<std::unique_ptr<Control>> dialogs; //对话框管理
|
|
||||||
|
|
||||||
|
// —— 控件/对话框 ——(容器内的普通控件与非模态对话框)
|
||||||
|
std::vector<std::unique_ptr<Control>> controls;
|
||||||
|
std::vector<std::unique_ptr<Control>> dialogs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool dialogClose = false; //是否有对话框关闭
|
bool dialogClose = false; // 项目内使用的状态位
|
||||||
|
|
||||||
|
// —— 构造/析构 ——(仅初始化成员;实际样式与子类化在 draw() 中完成)
|
||||||
Window(int width, int height, int mode);
|
Window(int width, int height, int mode);
|
||||||
Window(int width, int height, int mode, COLORREF bkcloc);
|
Window(int width, int height, int mode, COLORREF bkcloc);
|
||||||
Window(int width, int height, int mode , COLORREF bkcloc, std::string headline = "窗口");
|
Window(int width, int height, int mode, COLORREF bkcloc, std::string headline);
|
||||||
~Window();
|
~Window();
|
||||||
//绘制窗口
|
|
||||||
void draw();
|
// —— 绘制与事件循环 ——(draw* 完成一次全量绘制;runEventLoop 驱动事件与统一收口)
|
||||||
void draw(std::string pImgFile);
|
void draw(); // 纯色背景版本
|
||||||
//事件循环
|
void draw(std::string pImgFile); // 背景图版本
|
||||||
int runEventLoop();
|
int runEventLoop(); // 主事件循环(PeekMessage + 统一收口重绘)
|
||||||
//设置窗口背景图片
|
|
||||||
|
// —— 背景/标题设置 ——(更换背景、背景色与标题;立即触发一次批量绘制)
|
||||||
void setBkImage(std::string pImgFile);
|
void setBkImage(std::string pImgFile);
|
||||||
//设置窗口背景颜色
|
|
||||||
void setBkcolor(COLORREF c);
|
void setBkcolor(COLORREF c);
|
||||||
//设置窗口标题
|
|
||||||
void setHeadline(std::string headline);
|
void setHeadline(std::string headline);
|
||||||
//添加控件
|
|
||||||
|
// —— 控件/对话框管理 ——(添加到容器,或做存在性判断)
|
||||||
void addControl(std::unique_ptr<Control> control);
|
void addControl(std::unique_ptr<Control> control);
|
||||||
//添加对话框
|
|
||||||
void addDialog(std::unique_ptr<Control> dialogs);
|
void addDialog(std::unique_ptr<Control> dialogs);
|
||||||
//检查是否已有对话框显示用于去重,防止工厂模式调用非模态对话框,多次打开污染对话框背景快照
|
|
||||||
bool hasNonModalDialogWithCaption(const std::string& caption, const std::string& message) const;
|
bool hasNonModalDialogWithCaption(const std::string& caption, const std::string& message) const;
|
||||||
|
|
||||||
//获取窗口句柄
|
// —— 访问器 ——(只读接口,供外部查询当前窗口/标题/背景等)
|
||||||
HWND getHwnd() const;
|
HWND getHwnd() const;
|
||||||
//获取窗口宽度
|
|
||||||
int getWidth() const;
|
int getWidth() const;
|
||||||
//获取窗口高度
|
|
||||||
int getHeight() const;
|
int getHeight() const;
|
||||||
//获取窗口标题
|
|
||||||
std::string getHeadline() const;
|
std::string getHeadline() const;
|
||||||
//获取窗口背景颜色
|
|
||||||
COLORREF getBkcolor() const;
|
COLORREF getBkcolor() const;
|
||||||
//获取窗口背景图片
|
|
||||||
IMAGE* getBkImage() const;
|
IMAGE* getBkImage() const;
|
||||||
//获取窗口背景图片文件名
|
|
||||||
std::string getBkImageFile() const;
|
std::string getBkImageFile() const;
|
||||||
//获取控件管理
|
|
||||||
std::vector<std::unique_ptr<Control>>& getControls();
|
std::vector<std::unique_ptr<Control>>& getControls();
|
||||||
|
|
||||||
|
// —— 配置开关 ——(动态调整最小客户区、合成双缓冲)
|
||||||
|
inline void setMinClientSize(int w, int h)
|
||||||
|
{
|
||||||
|
// 仅更新阈值;实际约束在 WM_GETMINMAXINFO/WM_SIZING 中生效
|
||||||
|
minClientW = w;
|
||||||
|
minClientH = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setComposited(bool on)
|
||||||
|
{
|
||||||
|
// 更新标志;真正应用在 draw()/样式 SetWindowLongEx + SWP_FRAMECHANGED
|
||||||
|
useComposited = on;
|
||||||
|
}
|
||||||
|
|
||||||
|
void processWindowMessage(const ExMessage& msg); // 处理 EX_WINDOW 中的 WM_SIZE 等
|
||||||
|
void pumpResizeIfNeeded(); // 执行一次统一收口重绘
|
||||||
|
void scheduleResizeFromModal(int w, int h);
|
||||||
|
private:
|
||||||
|
void adaptiveLayout(std::unique_ptr<Control>& c, const int finalH, const int finalW);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -163,7 +163,6 @@ void Button::initButton(const std::string text, StellarX::ButtonMode mode, Stell
|
|||||||
tipLabel.textStyle = this->textStyle; // 复用按钮字体样式
|
tipLabel.textStyle = this->textStyle; // 复用按钮字体样式
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Button::~Button()
|
Button::~Button()
|
||||||
{
|
{
|
||||||
if (buttonFileIMAGE)
|
if (buttonFileIMAGE)
|
||||||
@@ -224,7 +223,7 @@ void Button::draw()
|
|||||||
//设置按钮填充模式
|
//设置按钮填充模式
|
||||||
setfillstyle((int)buttonFillMode, (int)buttonFillIma, buttonFileIMAGE);
|
setfillstyle((int)buttonFillMode, (int)buttonFillIma, buttonFileIMAGE);
|
||||||
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
|
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
|
||||||
saveBackground(this->x, this->y, this->width, this->height);
|
saveBackground(this->x, this->y, (this->width + bordWith), (this->height + bordHeight));
|
||||||
// 恢复背景(清除旧内容)
|
// 恢复背景(清除旧内容)
|
||||||
restBackground();
|
restBackground();
|
||||||
//根据按钮形状绘制
|
//根据按钮形状绘制
|
||||||
@@ -274,7 +273,6 @@ void Button::draw()
|
|||||||
|
|
||||||
restoreStyle();//恢复默认字体样式和颜色
|
restoreStyle();//恢复默认字体样式和颜色
|
||||||
dirty = false; //标记按钮不需要重绘
|
dirty = false; //标记按钮不需要重绘
|
||||||
|
|
||||||
}
|
}
|
||||||
// 处理鼠标事件,检测点击和悬停状态
|
// 处理鼠标事件,检测点击和悬停状态
|
||||||
// 根据按钮模式和形状进行不同的处理
|
// 根据按钮模式和形状进行不同的处理
|
||||||
@@ -314,7 +312,6 @@ bool Button::handleEvent(const ExMessage& msg)
|
|||||||
// 处理鼠标点击事件
|
// 处理鼠标点击事件
|
||||||
if (msg.message == WM_LBUTTONDOWN && hover && mode != StellarX::ButtonMode::DISABLED)
|
if (msg.message == WM_LBUTTONDOWN && hover && mode != StellarX::ButtonMode::DISABLED)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (mode == StellarX::ButtonMode::NORMAL)
|
if (mode == StellarX::ButtonMode::NORMAL)
|
||||||
{
|
{
|
||||||
click = true;
|
click = true;
|
||||||
@@ -451,7 +448,6 @@ void Button::setROUND_RECTANGLEwidth(int width)
|
|||||||
{
|
{
|
||||||
rouRectangleSize.ROUND_RECTANGLEwidth = width;
|
rouRectangleSize.ROUND_RECTANGLEwidth = width;
|
||||||
this->dirty = true; // 标记需要重绘
|
this->dirty = true; // 标记需要重绘
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::setROUND_RECTANGLEheight(int height)
|
void Button::setROUND_RECTANGLEheight(int height)
|
||||||
@@ -485,11 +481,10 @@ void Button::setFillIma(std::string imaNAme)
|
|||||||
buttonFileIMAGE = nullptr;
|
buttonFileIMAGE = nullptr;
|
||||||
}
|
}
|
||||||
buttonFileIMAGE = new IMAGE;
|
buttonFileIMAGE = new IMAGE;
|
||||||
loadimage(buttonFileIMAGE, imaNAme.c_str(),width,height);
|
loadimage(buttonFileIMAGE, imaNAme.c_str(), width, height);
|
||||||
this->dirty = true;
|
this->dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Button::setButtonBorder(COLORREF Border)
|
void Button::setButtonBorder(COLORREF Border)
|
||||||
{
|
{
|
||||||
buttonBorderColor = Border;
|
buttonBorderColor = Border;
|
||||||
@@ -558,7 +553,6 @@ void Button::setButtonClick(BOOL click)
|
|||||||
requestRepaint(parent);
|
requestRepaint(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string Button::getButtonText() const
|
std::string Button::getButtonText() const
|
||||||
{
|
{
|
||||||
return this->text;
|
return this->text;
|
||||||
@@ -619,8 +613,6 @@ int Button::getButtonHeight() const
|
|||||||
return this->height;
|
return this->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Button::isMouseInCircle(int mouseX, int mouseY, int x, int y, int radius)
|
bool Button::isMouseInCircle(int mouseX, int mouseY, int x, int y, int radius)
|
||||||
{
|
{
|
||||||
double dis = sqrt(pow(mouseX - x, 2) + pow(mouseY - y, 2));
|
double dis = sqrt(pow(mouseX - x, 2) + pow(mouseY - y, 2));
|
||||||
@@ -666,11 +658,9 @@ void Button::cutButtonText()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
cutText = ellipsize_cjk_pref(this->text, contentW, "…"); // 全角省略号
|
cutText = ellipsize_cjk_pref(this->text, contentW, "…"); // 全角省略号
|
||||||
|
|
||||||
}
|
}
|
||||||
isUseCutText = true;
|
isUseCutText = true;
|
||||||
needCutText = false;
|
needCutText = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::hideTooltip()
|
void Button::hideTooltip()
|
||||||
@@ -686,11 +676,8 @@ void Button::hideTooltip()
|
|||||||
void Button::refreshTooltipTextForState()
|
void Button::refreshTooltipTextForState()
|
||||||
{
|
{
|
||||||
if (tipUserOverride) return; // 用户显式设置过 tipText,保持不变
|
if (tipUserOverride) return; // 用户显式设置过 tipText,保持不变
|
||||||
if(mode==StellarX::ButtonMode::NORMAL)
|
if (mode == StellarX::ButtonMode::NORMAL)
|
||||||
tipLabel.setText(tipTextClick);
|
tipLabel.setText(tipTextClick);
|
||||||
else if(mode==StellarX::ButtonMode::TOGGLE)
|
else if (mode == StellarX::ButtonMode::TOGGLE)
|
||||||
tipLabel.setText(click ? tipTextOn : tipTextOff);
|
tipLabel.setText(click ? tipTextOn : tipTextOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
239
src/Canvas.cpp
239
src/Canvas.cpp
@@ -12,31 +12,76 @@ Canvas::Canvas(int x, int y, int width, int height)
|
|||||||
this->id = "Canvas";
|
this->id = "Canvas";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Canvas::setX(int x)
|
||||||
|
{
|
||||||
|
this->x = x;
|
||||||
|
for (auto& c : controls)
|
||||||
|
{
|
||||||
|
c->onWindowResize();
|
||||||
|
c->setX(c->getLocalX() + this->x);
|
||||||
|
}
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::setY(int y)
|
||||||
|
{
|
||||||
|
this->y = y;
|
||||||
|
for (auto& c : controls)
|
||||||
|
{
|
||||||
|
c->onWindowResize();
|
||||||
|
c->setY(c->getLocalY() + this->y);
|
||||||
|
}
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Canvas::clearAllControls()
|
void Canvas::clearAllControls()
|
||||||
{
|
{
|
||||||
controls.clear();
|
controls.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Canvas::draw()
|
void Canvas::draw()
|
||||||
{
|
{
|
||||||
if (!dirty||!show)return;
|
if (!dirty || !show)
|
||||||
|
{
|
||||||
|
for (auto& control : controls)
|
||||||
|
if (auto c = dynamic_cast<Table*>(control.get()))
|
||||||
|
c->draw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
saveStyle();
|
saveStyle();
|
||||||
|
|
||||||
setlinecolor(canvasBorderClor);//设置线色
|
setlinecolor(canvasBorderClor);//设置线色
|
||||||
|
if (StellarX::FillMode::Null != canvasFillMode)
|
||||||
setfillcolor(canvasBkClor);//设置填充色
|
setfillcolor(canvasBkClor);//设置填充色
|
||||||
setfillstyle((int)canvasFillMode);//设置填充模式
|
setfillstyle((int)canvasFillMode);//设置填充模式
|
||||||
setlinestyle((int)canvasLineStyle, canvaslinewidth);
|
setlinestyle((int)canvasLineStyle, canvaslinewidth);
|
||||||
|
|
||||||
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
|
// 在绘制画布之前,先恢复并更新背景快照:
|
||||||
saveBackground(x, y, width, height);
|
// 1. 如果已有快照,则先回贴旧快照以清除之前的内容。
|
||||||
// 恢复背景(清除旧内容)
|
// 2. 当坐标或尺寸变化,或缓存图像无效时,丢弃旧快照并重新抓取新的背景。
|
||||||
|
int margin = canvaslinewidth > 1 ? canvaslinewidth : 1;
|
||||||
|
if (hasSnap)
|
||||||
|
{
|
||||||
|
// 恢复旧快照,清除上一次绘制
|
||||||
|
restBackground();
|
||||||
|
// 如果位置或尺寸变了,或没有有效缓存,则重新抓取
|
||||||
|
if (!saveBkImage || saveBkX != this->x - margin || saveBkY != this->y - margin || saveWidth != this->width + margin * 2 || saveHeight != this->height + margin * 2)
|
||||||
|
{
|
||||||
|
discardBackground();
|
||||||
|
saveBackground(this->x - margin, this->y - margin, this->width + margin * 2, this->height + margin * 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 首次绘制或没有快照时直接抓取背景
|
||||||
|
saveBackground(this->x - margin, this->y - margin, this->width + margin * 2, this->height + margin * 2);
|
||||||
|
}
|
||||||
|
// 再次恢复最新快照,确保绘制区域干净
|
||||||
restBackground();
|
restBackground();
|
||||||
//根据画布形状绘制
|
//根据画布形状绘制
|
||||||
switch (shape)
|
switch (shape)
|
||||||
{
|
{
|
||||||
case StellarX::ControlShape::RECTANGLE:
|
case StellarX::ControlShape::RECTANGLE:
|
||||||
fillrectangle(x,y,x+width,y+height);//有边框填充矩形
|
fillrectangle(x, y, x + width, y + height);//有边框填充矩形
|
||||||
break;
|
break;
|
||||||
case StellarX::ControlShape::B_RECTANGLE:
|
case StellarX::ControlShape::B_RECTANGLE:
|
||||||
solidrectangle(x, y, x + width, y + height);//无边框填充矩形
|
solidrectangle(x, y, x + width, y + height);//无边框填充矩形
|
||||||
@@ -76,6 +121,9 @@ bool Canvas::handleEvent(const ExMessage& msg)
|
|||||||
|
|
||||||
void Canvas::addControl(std::unique_ptr<Control> control)
|
void Canvas::addControl(std::unique_ptr<Control> control)
|
||||||
{
|
{
|
||||||
|
//坐标转化
|
||||||
|
control->setX(control->getLocalX() + this->x);
|
||||||
|
control->setY(control->getLocalY() + this->y);
|
||||||
control->setParent(this);
|
control->setParent(this);
|
||||||
controls.push_back(std::move(control));
|
controls.push_back(std::move(control));
|
||||||
dirty = true;
|
dirty = true;
|
||||||
@@ -126,7 +174,6 @@ void Canvas::setCanvasLineStyle(StellarX::LineStyle style)
|
|||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Canvas::setLinewidth(int width)
|
void Canvas::setLinewidth(int width)
|
||||||
{
|
{
|
||||||
this->canvaslinewidth = width;
|
this->canvaslinewidth = width;
|
||||||
@@ -149,15 +196,179 @@ void Canvas::setIsVisible(bool visible)
|
|||||||
void Canvas::setDirty(bool dirty)
|
void Canvas::setDirty(bool dirty)
|
||||||
{
|
{
|
||||||
this->dirty = dirty;
|
this->dirty = dirty;
|
||||||
for(auto& control : controls)
|
for (auto& control : controls)
|
||||||
control->setDirty(dirty);
|
control->setDirty(dirty);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::onWindowResize()
|
void Canvas::onWindowResize()
|
||||||
{
|
{
|
||||||
Control::onWindowResize(); // 先处理自己
|
// 首先处理自身的快照等逻辑
|
||||||
for (auto& ch : controls) // 再转发给所有子控件
|
Control::onWindowResize();
|
||||||
|
|
||||||
|
// 记录父容器原始尺寸(用于计算子控件的右/下边距)
|
||||||
|
int origParentW = this->localWidth;
|
||||||
|
int origParentH = this->localHeight;
|
||||||
|
|
||||||
|
// 当前容器的新尺寸
|
||||||
|
int finalW = this->width;
|
||||||
|
int finalH = this->height;
|
||||||
|
|
||||||
|
// 当前容器的新坐标(全局坐标)
|
||||||
|
int parentX = this->x;
|
||||||
|
int parentY = this->y;
|
||||||
|
|
||||||
|
// 调整每个子控件在 AnchorToEdges 模式下的位置与尺寸
|
||||||
|
for (auto& ch : controls)
|
||||||
|
{
|
||||||
|
// Only adjust when using anchor-to-edges layout
|
||||||
|
if (ch->getLayoutMode() == StellarX::LayoutMode::AnchorToEdges)
|
||||||
|
{
|
||||||
|
// Determine whether this child is a Table; tables keep their height constant
|
||||||
|
bool isTable = (dynamic_cast<Table*>(ch.get()) != nullptr);
|
||||||
|
|
||||||
|
// Unpack anchors
|
||||||
|
auto a1 = ch->getAnchor_1();
|
||||||
|
auto a2 = ch->getAnchor_2();
|
||||||
|
|
||||||
|
bool anchorLeft = (a1 == StellarX::Anchor::Left || a2 == StellarX::Anchor::Left);
|
||||||
|
bool anchorRight = (a1 == StellarX::Anchor::Right || a2 == StellarX::Anchor::Right);
|
||||||
|
bool anchorTop = (a1 == StellarX::Anchor::Top || a2 == StellarX::Anchor::Top);
|
||||||
|
bool anchorBottom = (a1 == StellarX::Anchor::Bottom || a2 == StellarX::Anchor::Bottom);
|
||||||
|
|
||||||
|
// If it's a table, treat as anchored left and right horizontally and anchored top vertically by default.
|
||||||
|
if (isTable)
|
||||||
|
{
|
||||||
|
anchorLeft = true;
|
||||||
|
anchorRight = true;
|
||||||
|
// If no explicit vertical anchor was provided, default to top.
|
||||||
|
if (!(anchorTop || anchorBottom))
|
||||||
|
{
|
||||||
|
anchorTop = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute new X and width
|
||||||
|
int newX = ch->getX();
|
||||||
|
int newWidth = ch->getWidth();
|
||||||
|
if (anchorLeft && anchorRight)
|
||||||
|
{
|
||||||
|
// Scale horizontally relative to parent's size.
|
||||||
|
if (origParentW > 0)
|
||||||
|
{
|
||||||
|
// Maintain proportional position and size based on original local values.
|
||||||
|
double scaleW = static_cast<double>(finalW) / static_cast<double>(origParentW);
|
||||||
|
newX = parentX + static_cast<int>(ch->getLocalX() * scaleW + 0.5);
|
||||||
|
newWidth = static_cast<int>(ch->getLocalWidth() * scaleW + 0.5);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fallback: keep original
|
||||||
|
newX = parentX + ch->getLocalX();
|
||||||
|
newWidth = ch->getLocalWidth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (anchorLeft && !anchorRight)
|
||||||
|
{
|
||||||
|
// Only left anchored: keep original width and left margin.
|
||||||
|
newWidth = ch->getLocalWidth();
|
||||||
|
newX = parentX + ch->getLocalX();
|
||||||
|
}
|
||||||
|
else if (!anchorLeft && anchorRight)
|
||||||
|
{
|
||||||
|
// Only right anchored: keep original width and right margin.
|
||||||
|
newWidth = ch->getLocalWidth();
|
||||||
|
int origRightDist = origParentW - (ch->getLocalX() + ch->getLocalWidth());
|
||||||
|
newX = parentX + finalW - origRightDist - newWidth;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No horizontal anchor: position relative to parent's left and width unchanged.
|
||||||
|
newWidth = ch->getLocalWidth();
|
||||||
|
newX = parentX + ch->getLocalX();
|
||||||
|
}
|
||||||
|
ch->setX(newX);
|
||||||
|
ch->setWidth(newWidth);
|
||||||
|
|
||||||
|
// Compute new Y and height
|
||||||
|
int newY = ch->getY();
|
||||||
|
int newHeight = ch->getHeight();
|
||||||
|
if (isTable)
|
||||||
|
{
|
||||||
|
// Table: Height remains constant; adjust Y based on anchors.
|
||||||
|
newHeight = ch->getLocalHeight();
|
||||||
|
if (anchorTop && anchorBottom)
|
||||||
|
{
|
||||||
|
// If both top and bottom anchored, scale Y but keep height.
|
||||||
|
if (origParentH > 0)
|
||||||
|
{
|
||||||
|
double scaleH = static_cast<double>(finalH) / static_cast<double>(origParentH);
|
||||||
|
newY = parentY + static_cast<int>(ch->getLocalY() * scaleH + 0.5);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newY = parentY + ch->getLocalY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (anchorTop && !anchorBottom)
|
||||||
|
{
|
||||||
|
// Top anchored only
|
||||||
|
newY = parentY + ch->getLocalY();
|
||||||
|
}
|
||||||
|
else if (!anchorTop && anchorBottom)
|
||||||
|
{
|
||||||
|
// Bottom anchored only
|
||||||
|
int origBottomDist = origParentH - (ch->getLocalY() + ch->getLocalHeight());
|
||||||
|
newY = parentY + finalH - origBottomDist - newHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No vertical anchor: default to top
|
||||||
|
newY = parentY + ch->getLocalY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (anchorTop && anchorBottom)
|
||||||
|
{
|
||||||
|
// Scale vertically relative to parent's size.
|
||||||
|
if (origParentH > 0)
|
||||||
|
{
|
||||||
|
double scaleH = static_cast<double>(finalH) / static_cast<double>(origParentH);
|
||||||
|
newY = parentY + static_cast<int>(ch->getLocalY() * scaleH + 0.5);
|
||||||
|
newHeight = static_cast<int>(ch->getLocalHeight() * scaleH + 0.5);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newY = parentY + ch->getLocalY();
|
||||||
|
newHeight = ch->getLocalHeight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (anchorTop && !anchorBottom)
|
||||||
|
{
|
||||||
|
// Top anchored only: keep height constant
|
||||||
|
newHeight = ch->getLocalHeight();
|
||||||
|
newY = parentY + ch->getLocalY();
|
||||||
|
}
|
||||||
|
else if (!anchorTop && anchorBottom)
|
||||||
|
{
|
||||||
|
// Bottom anchored only: keep height and adjust Y relative to bottom
|
||||||
|
newHeight = ch->getLocalHeight();
|
||||||
|
int origBottomDist = origParentH - (ch->getLocalY() + ch->getLocalHeight());
|
||||||
|
newY = parentY + finalH - origBottomDist - newHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No vertical anchor: position relative to parent's top, height constant.
|
||||||
|
newHeight = ch->getLocalHeight();
|
||||||
|
newY = parentY + ch->getLocalY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ch->setY(newY);
|
||||||
|
ch->setHeight(newHeight);
|
||||||
|
}
|
||||||
|
// Always forward the window resize event to the child (recursively).
|
||||||
ch->onWindowResize();
|
ch->onWindowResize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::requestRepaint(Control* parent)
|
void Canvas::requestRepaint(Control* parent)
|
||||||
@@ -166,14 +377,8 @@ void Canvas::requestRepaint(Control* parent)
|
|||||||
{
|
{
|
||||||
for (auto& control : controls)
|
for (auto& control : controls)
|
||||||
if (control->isDirty() && control->IsVisible())
|
if (control->isDirty() && control->IsVisible())
|
||||||
{
|
|
||||||
control->draw();
|
control->draw();
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
onRequestRepaintAsRoot();
|
onRequestRepaintAsRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,14 @@ bool StellarX::ControlText::operator!=(const ControlText& text)
|
|||||||
}
|
}
|
||||||
void Control::setIsVisible(bool show)
|
void Control::setIsVisible(bool show)
|
||||||
{
|
{
|
||||||
|
this->show = show;
|
||||||
|
dirty = true;
|
||||||
|
|
||||||
if (!show)
|
if (!show)
|
||||||
this->updateBackground();
|
this->updateBackground();
|
||||||
this->show = show;
|
else
|
||||||
|
requestRepaint(parent);
|
||||||
|
|
||||||
}
|
}
|
||||||
void Control::onWindowResize()
|
void Control::onWindowResize()
|
||||||
{
|
{
|
||||||
@@ -54,6 +59,27 @@ void Control::onWindowResize()
|
|||||||
discardBackground();
|
discardBackground();
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
}
|
}
|
||||||
|
void Control::setLayoutMode(StellarX::LayoutMode layoutMode_)
|
||||||
|
{
|
||||||
|
this->layoutMode = layoutMode_;
|
||||||
|
}
|
||||||
|
void Control::setAnchor(StellarX::Anchor anchor_1, StellarX::Anchor anchor_2)
|
||||||
|
{
|
||||||
|
this->anchor_1 = anchor_1;
|
||||||
|
this->anchor_2 = anchor_2;
|
||||||
|
}
|
||||||
|
StellarX::Anchor Control::getAnchor_1() const
|
||||||
|
{
|
||||||
|
return this->anchor_1;
|
||||||
|
}
|
||||||
|
StellarX::Anchor Control::getAnchor_2() const
|
||||||
|
{
|
||||||
|
return this->anchor_2;
|
||||||
|
}
|
||||||
|
StellarX::LayoutMode Control::getLayoutMode() const
|
||||||
|
{
|
||||||
|
return this->layoutMode;
|
||||||
|
}
|
||||||
// 保存当前的绘图状态(字体、颜色、线型等)
|
// 保存当前的绘图状态(字体、颜色、线型等)
|
||||||
// 在控件绘制前调用,确保不会影响全局绘图状态
|
// 在控件绘制前调用,确保不会影响全局绘图状态
|
||||||
void Control::saveStyle()
|
void Control::saveStyle()
|
||||||
@@ -123,6 +149,7 @@ void Control::discardBackground()
|
|||||||
{
|
{
|
||||||
if (saveBkImage)
|
if (saveBkImage)
|
||||||
{
|
{
|
||||||
|
restBackground();
|
||||||
delete saveBkImage;
|
delete saveBkImage;
|
||||||
saveBkImage = nullptr;
|
saveBkImage = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
148
src/Dialog.cpp
148
src/Dialog.cpp
@@ -1,21 +1,19 @@
|
|||||||
#include "Dialog.h"
|
#include "Dialog.h"
|
||||||
|
|
||||||
Dialog::Dialog(Window& h,std::string text,std::string message, StellarX::MessageBoxType type, bool modal)
|
Dialog::Dialog(Window& h, std::string text, std::string message, StellarX::MessageBoxType type, bool modal)
|
||||||
: Canvas(),message(message), type(type), modal(modal), hWnd(h), titleText(text)
|
: Canvas(), message(message), type(type), modal(modal), hWnd(h), titleText(text)
|
||||||
{
|
{
|
||||||
this->id = "Dialog";
|
this->id = "Dialog";
|
||||||
show = false;
|
show = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Dialog::~Dialog()
|
Dialog::~Dialog()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::draw()
|
void Dialog::draw()
|
||||||
{
|
{
|
||||||
if(!show)
|
if (!show)
|
||||||
{
|
{
|
||||||
// 如果对话框不可见且需要清理,执行清理
|
// 如果对话框不可见且需要清理,执行清理
|
||||||
if (pendingCleanup && !isCleaning)
|
if (pendingCleanup && !isCleaning)
|
||||||
@@ -41,12 +39,6 @@ void Dialog::draw()
|
|||||||
Canvas::setCanvasBkColor(this->backgroundColor);
|
Canvas::setCanvasBkColor(this->backgroundColor);
|
||||||
Canvas::setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
Canvas::setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||||||
|
|
||||||
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
|
|
||||||
saveBackground(this->x, this->y, this->width, this->height);
|
|
||||||
//设置所有控件为脏状态
|
|
||||||
/*for(auto& c :this->controls)
|
|
||||||
c->setDirty(true);*/
|
|
||||||
restBackground();
|
|
||||||
Canvas::draw();
|
Canvas::draw();
|
||||||
|
|
||||||
//绘制消息文本
|
//绘制消息文本
|
||||||
@@ -57,9 +49,8 @@ void Dialog::draw()
|
|||||||
textStyle.nEscapement, textStyle.nOrientation, textStyle.nWeight,
|
textStyle.nEscapement, textStyle.nOrientation, textStyle.nWeight,
|
||||||
textStyle.bItalic, textStyle.bUnderline, textStyle.bStrikeOut);
|
textStyle.bItalic, textStyle.bUnderline, textStyle.bStrikeOut);
|
||||||
|
|
||||||
|
|
||||||
int ty = y + closeButtonHeight + titleToTextMargin; // 文本起始Y坐标
|
int ty = y + closeButtonHeight + titleToTextMargin; // 文本起始Y坐标
|
||||||
for (auto line:lines)
|
for (auto& line : lines)
|
||||||
{
|
{
|
||||||
int tx = this->x + ((this->width - textwidth(line.c_str())) / 2); // 文本起始X坐标
|
int tx = this->x + ((this->width - textwidth(line.c_str())) / 2); // 文本起始X坐标
|
||||||
outtextxy(tx, ty, LPCTSTR(line.c_str()));
|
outtextxy(tx, ty, LPCTSTR(line.c_str()));
|
||||||
@@ -73,8 +64,6 @@ void Dialog::draw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Dialog::handleEvent(const ExMessage& msg)
|
bool Dialog::handleEvent(const ExMessage& msg)
|
||||||
{
|
{
|
||||||
bool consume = false;
|
bool consume = false;
|
||||||
@@ -140,7 +129,6 @@ void Dialog::SetModal(bool modal)
|
|||||||
this->modal = modal;
|
this->modal = modal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Dialog::SetResult(StellarX::MessageBoxResult result)
|
void Dialog::SetResult(StellarX::MessageBoxResult result)
|
||||||
{
|
{
|
||||||
this->result = result;
|
this->result = result;
|
||||||
@@ -170,16 +158,43 @@ void Dialog::Show()
|
|||||||
if (modal)
|
if (modal)
|
||||||
{
|
{
|
||||||
// 模态对话框需要阻塞当前线程直到对话框关闭
|
// 模态对话框需要阻塞当前线程直到对话框关闭
|
||||||
|
if (modal)
|
||||||
|
{
|
||||||
|
// 记录当前窗口客户区尺寸,供轮询对比
|
||||||
|
RECT rc0;
|
||||||
|
GetClientRect(hWnd.getHwnd(), &rc0);
|
||||||
|
int lastW = rc0.right - rc0.left;
|
||||||
|
int lastH = rc0.bottom - rc0.top;
|
||||||
|
|
||||||
while (show && !close)
|
while (show && !close)
|
||||||
{
|
{
|
||||||
|
// ① 轮询窗口尺寸(不依赖 WM_SIZE)
|
||||||
|
RECT rc;
|
||||||
|
GetClientRect(hWnd.getHwnd(), &rc);
|
||||||
|
const int cw = rc.right - rc.left;
|
||||||
|
const int ch = rc.bottom - rc.top;
|
||||||
|
|
||||||
// 处理消息
|
if (cw != lastW || ch != lastH)
|
||||||
|
{
|
||||||
|
lastW = cw;
|
||||||
|
lastH = ch;
|
||||||
|
|
||||||
|
// 通知父窗口:有新尺寸 → 标记 needResizeDirty
|
||||||
|
hWnd.scheduleResizeFromModal(cw, ch);
|
||||||
|
|
||||||
|
// 立即统一收口:父窗重绘 背景+普通控件(不会画到这只模态)
|
||||||
|
hWnd.pumpResizeIfNeeded();
|
||||||
|
|
||||||
|
// 这只模态在新尺寸下重建布局 / 重抓背景 → 本帧要画自己
|
||||||
|
setInitialization(true);
|
||||||
|
setDirty(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ② 处理这只对话框的鼠标/键盘(沿用你原来 EX_MOUSE | EX_KEY)
|
||||||
ExMessage msg;
|
ExMessage msg;
|
||||||
if (peekmessage(&msg, EX_MOUSE | EX_KEY))
|
if (peekmessage(&msg, EX_MOUSE | EX_KEY))
|
||||||
{
|
{
|
||||||
handleEvent(msg);
|
handleEvent(msg);
|
||||||
|
|
||||||
// 检查是否需要关闭
|
|
||||||
if (shouldClose)
|
if (shouldClose)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
@@ -187,16 +202,27 @@ void Dialog::Show()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重绘
|
// ③ 最后一笔:只画这只模态,保证永远在最上层
|
||||||
if (dirty)
|
if (dirty)
|
||||||
{
|
{
|
||||||
requestRepaint(parent);
|
BeginBatchDraw();
|
||||||
FlushBatchDraw();
|
this->draw(); // 注意:不要 requestRepaint(parent),只画自己
|
||||||
|
EndBatchDraw();
|
||||||
|
dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 避免CPU占用过高
|
|
||||||
Sleep(10);
|
Sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pendingCleanup && !isCleaning)
|
||||||
|
performDelayedCleanup();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 非模态仍由主循环托管
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
// 模态对话框关闭后执行清理
|
// 模态对话框关闭后执行清理
|
||||||
if (pendingCleanup && !isCleaning)
|
if (pendingCleanup && !isCleaning)
|
||||||
performDelayedCleanup();
|
performDelayedCleanup();
|
||||||
@@ -206,8 +232,6 @@ void Dialog::Show()
|
|||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Dialog::Close()
|
void Dialog::Close()
|
||||||
{
|
{
|
||||||
if (!show) return;
|
if (!show) return;
|
||||||
@@ -217,12 +241,9 @@ void Dialog::Close()
|
|||||||
dirty = true;
|
dirty = true;
|
||||||
pendingCleanup = true; // 只标记需要清理,不立即执行
|
pendingCleanup = true; // 只标记需要清理,不立即执行
|
||||||
|
|
||||||
|
|
||||||
// 工厂模式下非模态触发回调 返回结果
|
// 工厂模式下非模态触发回调 返回结果
|
||||||
if (resultCallback&& !modal)
|
if (resultCallback && !modal)
|
||||||
resultCallback(this->result);
|
resultCallback(this->result);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::setInitialization(bool init)
|
void Dialog::setInitialization(bool init)
|
||||||
@@ -231,10 +252,10 @@ void Dialog::setInitialization(bool init)
|
|||||||
{
|
{
|
||||||
initDialogSize();
|
initDialogSize();
|
||||||
saveBackground((x - BorderWidth), (y - BorderWidth), (width + 2 * BorderWidth), (height + 2 * BorderWidth));
|
saveBackground((x - BorderWidth), (y - BorderWidth), (width + 2 * BorderWidth), (height + 2 * BorderWidth));
|
||||||
|
this->dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Dialog::initButtons()
|
void Dialog::initButtons()
|
||||||
{
|
{
|
||||||
controls.clear();
|
controls.clear();
|
||||||
@@ -358,7 +379,6 @@ void Dialog::initButtons()
|
|||||||
noButton->textStyle = this->textStyle;
|
noButton->textStyle = this->textStyle;
|
||||||
cancelButton->textStyle = this->textStyle;
|
cancelButton->textStyle = this->textStyle;
|
||||||
|
|
||||||
|
|
||||||
this->addControl(std::move(yesButton));
|
this->addControl(std::move(yesButton));
|
||||||
this->addControl(std::move(noButton));
|
this->addControl(std::move(noButton));
|
||||||
this->addControl(std::move(cancelButton));
|
this->addControl(std::move(cancelButton));
|
||||||
@@ -398,7 +418,7 @@ void Dialog::initButtons()
|
|||||||
case StellarX::MessageBoxType::AbortRetryIgnore: // 中止、重试和忽略按钮
|
case StellarX::MessageBoxType::AbortRetryIgnore: // 中止、重试和忽略按钮
|
||||||
{
|
{
|
||||||
auto abortButton = createDialogButton(
|
auto abortButton = createDialogButton(
|
||||||
(this->x + (this->width - (functionButtonWidth * buttonNum + buttonMargin* (buttonNum-1))) / 2),
|
(this->x + (this->width - (functionButtonWidth * buttonNum + buttonMargin * (buttonNum - 1))) / 2),
|
||||||
((this->y + (this->height - buttonAreaHeight)) + (buttonAreaHeight - functionButtonHeight) / 2),
|
((this->y + (this->height - buttonAreaHeight)) + (buttonAreaHeight - functionButtonHeight) / 2),
|
||||||
"中止"
|
"中止"
|
||||||
);
|
);
|
||||||
@@ -448,7 +468,7 @@ void Dialog::initCloseButton()
|
|||||||
//初始化关闭按钮
|
//初始化关闭按钮
|
||||||
auto but = std::make_unique<Button>
|
auto but = std::make_unique<Button>
|
||||||
(
|
(
|
||||||
(this->x + this->width - closeButtonWidth) - 3, (this->y+3), closeButtonWidth-1, closeButtonHeight,
|
(this->x + this->width - closeButtonWidth) - 3, (this->y + 3), closeButtonWidth - 1, closeButtonHeight,
|
||||||
"X", // 按钮文本
|
"X", // 按钮文本
|
||||||
RGB(255, 0, 0), // 按钮被点击颜色
|
RGB(255, 0, 0), // 按钮被点击颜色
|
||||||
this->canvasBkClor, // 按钮背景颜色
|
this->canvasBkClor, // 按钮背景颜色
|
||||||
@@ -469,7 +489,7 @@ void Dialog::initCloseButton()
|
|||||||
|
|
||||||
void Dialog::initTitle()
|
void Dialog::initTitle()
|
||||||
{
|
{
|
||||||
this->title = std::make_unique<Label>(this->x+5,this->y+5,titleText,textStyle.color);
|
this->title = std::make_unique<Label>(this->x + 5, this->y + 5, titleText, textStyle.color);
|
||||||
title->setTextdisap(true);
|
title->setTextdisap(true);
|
||||||
title->textStyle = this->textStyle;
|
title->textStyle = this->textStyle;
|
||||||
|
|
||||||
@@ -483,7 +503,7 @@ void Dialog::splitMessageLines()
|
|||||||
std::string currentLine;
|
std::string currentLine;
|
||||||
for (size_t i = 0; i < message.length(); i++) {
|
for (size_t i = 0; i < message.length(); i++) {
|
||||||
// 处理 换行符 \r\n \n \r
|
// 处理 换行符 \r\n \n \r
|
||||||
if (i + 1 < message.length() && (message[i] == '\r' || message[i] == '\n')||(message[i] == '\r' && message[i+1] == '\n'))
|
if (i + 1 < message.length() && (message[i] == '\r' || message[i] == '\n') || (message[i] == '\r' && message[i + 1] == '\n'))
|
||||||
{
|
{
|
||||||
if (!currentLine.empty()) {
|
if (!currentLine.empty()) {
|
||||||
lines.push_back(currentLine);
|
lines.push_back(currentLine);
|
||||||
@@ -517,7 +537,7 @@ void Dialog::getTextSize()
|
|||||||
settextstyle(textStyle.nHeight, textStyle.nWidth, textStyle.lpszFace,
|
settextstyle(textStyle.nHeight, textStyle.nWidth, textStyle.lpszFace,
|
||||||
textStyle.nEscapement, textStyle.nOrientation, textStyle.nWeight,
|
textStyle.nEscapement, textStyle.nOrientation, textStyle.nWeight,
|
||||||
textStyle.bItalic, textStyle.bUnderline, textStyle.bStrikeOut);
|
textStyle.bItalic, textStyle.bUnderline, textStyle.bStrikeOut);
|
||||||
for (auto text : lines)
|
for (auto& text : lines)
|
||||||
{
|
{
|
||||||
int w = textwidth(LPCTSTR(text.c_str()));
|
int w = textwidth(LPCTSTR(text.c_str()));
|
||||||
int h = textheight(LPCTSTR(text.c_str()));
|
int h = textheight(LPCTSTR(text.c_str()));
|
||||||
@@ -554,10 +574,10 @@ void Dialog::initDialogSize()
|
|||||||
|
|
||||||
// 计算按钮区域宽度
|
// 计算按钮区域宽度
|
||||||
int buttonAreaWidth = buttonNum * functionButtonWidth +
|
int buttonAreaWidth = buttonNum * functionButtonWidth +
|
||||||
(buttonNum > 0 ? (buttonNum +1) * buttonMargin : 0);
|
(buttonNum > 0 ? (buttonNum + 1) * buttonMargin : 0);
|
||||||
|
|
||||||
// 计算文本区域宽度(包括边距)
|
// 计算文本区域宽度(包括边距)
|
||||||
int textAreaWidth = textWidth + textToBorderMargin * 2 ;
|
int textAreaWidth = textWidth + textToBorderMargin * 2;
|
||||||
|
|
||||||
// 对话框宽度取两者中的较大值,并确保最小宽度
|
// 对话框宽度取两者中的较大值,并确保最小宽度
|
||||||
this->width = buttonAreaWidth > textAreaWidth ? buttonAreaWidth : textAreaWidth;
|
this->width = buttonAreaWidth > textAreaWidth ? buttonAreaWidth : textAreaWidth;
|
||||||
@@ -565,7 +585,7 @@ void Dialog::initDialogSize()
|
|||||||
|
|
||||||
// 计算对话框高度
|
// 计算对话框高度
|
||||||
// 高度 = 标题栏高度 + 文本区域高度 + 按钮区域高度 + 间距
|
// 高度 = 标题栏高度 + 文本区域高度 + 按钮区域高度 + 间距
|
||||||
int textAreaHeight = textHeight * (int)lines.size() + 5*((int)lines.size()-1); // 文本行高+行间距
|
int textAreaHeight = textHeight * (int)lines.size() + 5 * ((int)lines.size() - 1); // 文本行高+行间距
|
||||||
this->height = closeButtonHeight + // 标题栏高度
|
this->height = closeButtonHeight + // 标题栏高度
|
||||||
titleToTextMargin + // 标题到文本的间距
|
titleToTextMargin + // 标题到文本的间距
|
||||||
textAreaHeight + // 文本区域高度
|
textAreaHeight + // 文本区域高度
|
||||||
@@ -583,30 +603,11 @@ void Dialog::initDialogSize()
|
|||||||
initCloseButton(); // 初始化关闭按钮
|
initCloseButton(); // 初始化关闭按钮
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::saveBackground(int x, int y, int w, int h)
|
void Dialog::addControl(std::unique_ptr<Control> control)
|
||||||
{
|
{
|
||||||
if (w <= 0 || h <= 0) return;
|
control->setParent(this);
|
||||||
saveBkX = x; saveBkY = y; saveWidth = w; saveHeight = h;
|
controls.push_back(std::move(control));
|
||||||
if (saveBkImage)
|
dirty = true;
|
||||||
{
|
|
||||||
//尺寸变了才重建,避免反复 new/delete
|
|
||||||
if (saveBkImage->getwidth() != w || saveBkImage->getheight() != h)
|
|
||||||
{
|
|
||||||
delete saveBkImage; saveBkImage = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!saveBkImage) saveBkImage = new IMAGE(w + BorderWidth*2, h + BorderWidth*2);
|
|
||||||
|
|
||||||
SetWorkingImage(nullptr); // ★抓屏幕
|
|
||||||
getimage(saveBkImage, x - BorderWidth, y - BorderWidth, w + BorderWidth*2, h+ BorderWidth*2);
|
|
||||||
hasSnap = true;
|
|
||||||
}
|
|
||||||
void Dialog::restBackground()
|
|
||||||
{
|
|
||||||
if (!hasSnap || !saveBkImage) return;
|
|
||||||
// 直接回贴屏幕(与抓取一致)
|
|
||||||
SetWorkingImage(nullptr);
|
|
||||||
putimage(saveBkX - BorderWidth, saveBkY - BorderWidth,saveBkImage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 延迟清理策略:由于对话框绘制时保存了背景快照,必须在对话框隐藏后、
|
// 延迟清理策略:由于对话框绘制时保存了背景快照,必须在对话框隐藏后、
|
||||||
@@ -634,6 +635,23 @@ void Dialog::performDelayedCleanup()
|
|||||||
FlushBatchDraw();
|
FlushBatchDraw();
|
||||||
discardBackground();
|
discardBackground();
|
||||||
}
|
}
|
||||||
|
if (!(saveBkImage && hasSnap))
|
||||||
|
{
|
||||||
|
// 没有背景快照:强制一次完整重绘,立即擦掉残影
|
||||||
|
hWnd.pumpResizeIfNeeded(); // 如果正好有尺寸标志,顺便统一收口
|
||||||
|
// 即使没有尺寸变化,也重绘一帧
|
||||||
|
BeginBatchDraw();
|
||||||
|
// 背景
|
||||||
|
if (hWnd.getBkImage() && !hWnd.getBkImageFile().empty())
|
||||||
|
putimage(0, 0, hWnd.getBkImage());
|
||||||
|
else { setbkcolor(hWnd.getBkcolor()); cleardevice(); }
|
||||||
|
// 所有普通控件
|
||||||
|
for (auto& c : hWnd.getControls()) c->draw();
|
||||||
|
// 其他对话框(this 已经 show=false,会早退不绘)
|
||||||
|
// 注意:此处若有容器管理,需要按你的现状遍历 dialogs 再 draw
|
||||||
|
EndBatchDraw();
|
||||||
|
FlushBatchDraw();
|
||||||
|
}
|
||||||
// 重置状态
|
// 重置状态
|
||||||
needsInitialization = true;
|
needsInitialization = true;
|
||||||
pendingCleanup = false;
|
pendingCleanup = false;
|
||||||
@@ -684,12 +702,8 @@ void Dialog::requestRepaint(Control* parent)
|
|||||||
if (this == parent)
|
if (this == parent)
|
||||||
{
|
{
|
||||||
for (auto& control : controls)
|
for (auto& control : controls)
|
||||||
if (control->isDirty()&&control->IsVisible())
|
if (control->isDirty() && control->IsVisible())
|
||||||
{
|
|
||||||
control->draw();
|
control->draw();
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
onRequestRepaintAsRoot();
|
onRequestRepaintAsRoot();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace StellarX
|
namespace StellarX
|
||||||
{
|
{
|
||||||
MessageBoxResult MessageBox::showModal(Window& wnd,const std::string& text,const std::string& caption,
|
MessageBoxResult MessageBox::showModal(Window& wnd, const std::string& text, const std::string& caption,
|
||||||
MessageBoxType type)
|
MessageBoxType type)
|
||||||
{
|
{
|
||||||
Dialog dlg(wnd, caption, text, type, true); // 模态
|
Dialog dlg(wnd, caption, text, type, true); // 模态
|
||||||
@@ -11,7 +11,7 @@ namespace StellarX
|
|||||||
return dlg.GetResult();
|
return dlg.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageBox::showAsync(Window& wnd,const std::string& text,const std::string& caption,MessageBoxType type,
|
void MessageBox::showAsync(Window& wnd, const std::string& text, const std::string& caption, MessageBoxType type,
|
||||||
std::function<void(MessageBoxResult)> onResult)
|
std::function<void(MessageBoxResult)> onResult)
|
||||||
{
|
{
|
||||||
//去重,如果窗口内已有相同的对话框被触发,则不再创建
|
//去重,如果窗口内已有相同的对话框被触发,则不再创建
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ inline void TabControl::initTabBar()
|
|||||||
for (auto& c : controls)
|
for (auto& c : controls)
|
||||||
{
|
{
|
||||||
c.first->setX(this->x + i * butW);
|
c.first->setX(this->x + i * butW);
|
||||||
c.first->setY(this->y+this->height - tabBarHeight);
|
c.first->setY(this->y + this->height - tabBarHeight);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -41,14 +41,14 @@ inline void TabControl::initTabBar()
|
|||||||
for (auto& c : controls)
|
for (auto& c : controls)
|
||||||
{
|
{
|
||||||
c.first->setX(this->x);
|
c.first->setX(this->x);
|
||||||
c.first->setY(this->y+i* butH);
|
c.first->setY(this->y + i * butH);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case StellarX::TabPlacement::Right:
|
case StellarX::TabPlacement::Right:
|
||||||
for (auto& c : controls)
|
for (auto& c : controls)
|
||||||
{
|
{
|
||||||
c.first->setX(this->x+this->width - tabBarHeight);
|
c.first->setX(this->x + this->width - tabBarHeight);
|
||||||
c.first->setY(this->y + i * butH);
|
c.first->setY(this->y + i * butH);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ inline void TabControl::initTabPage()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TabControl::TabControl():Canvas()
|
TabControl::TabControl() :Canvas()
|
||||||
{
|
{
|
||||||
this->id = "TabControl";
|
this->id = "TabControl";
|
||||||
}
|
}
|
||||||
@@ -162,13 +162,36 @@ TabControl::~TabControl()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabControl::setX(int x)
|
||||||
|
{
|
||||||
|
this->x = x;
|
||||||
|
initTabBar();
|
||||||
|
initTabPage();
|
||||||
|
dirty = true;
|
||||||
|
for (auto& c : controls)
|
||||||
|
{
|
||||||
|
c.first->onWindowResize();
|
||||||
|
c.second->onWindowResize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabControl::setY(int y)
|
||||||
|
{
|
||||||
|
this->y = y;
|
||||||
|
initTabBar();
|
||||||
|
initTabPage();
|
||||||
|
dirty = true;
|
||||||
|
for (auto& c : controls)
|
||||||
|
{
|
||||||
|
c.first->onWindowResize();
|
||||||
|
c.second->onWindowResize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TabControl::draw()
|
void TabControl::draw()
|
||||||
{
|
{
|
||||||
if (!dirty || !show)return;
|
if (!dirty || !show)return;
|
||||||
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
|
// 绘制画布背景和基本形状及其子画布控件
|
||||||
saveBackground(this->x, this->y, this->width, this->height);
|
|
||||||
// 恢复背景(清除旧内容)
|
|
||||||
restBackground();
|
|
||||||
Canvas::draw();
|
Canvas::draw();
|
||||||
for (auto& c : controls)
|
for (auto& c : controls)
|
||||||
{
|
{
|
||||||
@@ -176,13 +199,21 @@ void TabControl::draw()
|
|||||||
c.first->draw();
|
c.first->draw();
|
||||||
}
|
}
|
||||||
for (auto& c : controls)
|
for (auto& c : controls)
|
||||||
if(c.second->IsVisible())
|
|
||||||
{
|
{
|
||||||
c.second->setDirty(true);
|
c.second->setDirty(true);
|
||||||
c.second->draw();
|
c.second->draw();
|
||||||
}
|
}
|
||||||
dirty = false;
|
|
||||||
|
|
||||||
|
// 首次绘制时处理默认激活页签
|
||||||
|
if (IsFirstDraw)
|
||||||
|
{
|
||||||
|
if (defaultActivation >= 0 && defaultActivation < (int)controls.size())
|
||||||
|
controls[defaultActivation].first->setButtonClick(true);
|
||||||
|
else if (defaultActivation >= (int)controls.size())//索引越界则激活最后一个
|
||||||
|
controls[controls.size() - 1].first->setButtonClick(true);
|
||||||
|
IsFirstDraw = false;//避免重复处理
|
||||||
|
}
|
||||||
|
dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TabControl::handleEvent(const ExMessage& msg)
|
bool TabControl::handleEvent(const ExMessage& msg)
|
||||||
@@ -196,7 +227,7 @@ bool TabControl::handleEvent(const ExMessage& msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (auto& c : controls)
|
for (auto& c : controls)
|
||||||
if(c.second->IsVisible())
|
if (c.second->IsVisible())
|
||||||
if (c.second->handleEvent(msg))
|
if (c.second->handleEvent(msg))
|
||||||
{
|
{
|
||||||
consume = true;
|
consume = true;
|
||||||
@@ -216,7 +247,8 @@ void TabControl::add(std::pair<std::unique_ptr<Button>, std::unique_ptr<Canvas>>
|
|||||||
controls[idx].first->setParent(this);
|
controls[idx].first->setParent(this);
|
||||||
controls[idx].first->enableTooltip(true);
|
controls[idx].first->enableTooltip(true);
|
||||||
controls[idx].first->setbuttonMode(StellarX::ButtonMode::TOGGLE);
|
controls[idx].first->setbuttonMode(StellarX::ButtonMode::TOGGLE);
|
||||||
controls[idx].first->setOnToggleOnListener([this,idx]()
|
|
||||||
|
controls[idx].first->setOnToggleOnListener([this, idx]()
|
||||||
{
|
{
|
||||||
controls[idx].second->setIsVisible(true);
|
controls[idx].second->setIsVisible(true);
|
||||||
controls[idx].second->onWindowResize();
|
controls[idx].second->onWindowResize();
|
||||||
@@ -230,7 +262,7 @@ void TabControl::add(std::pair<std::unique_ptr<Button>, std::unique_ptr<Canvas>>
|
|||||||
}
|
}
|
||||||
dirty = true;
|
dirty = true;
|
||||||
});
|
});
|
||||||
controls[idx].first->setOnToggleOffListener([this,idx]()
|
controls[idx].first->setOnToggleOffListener([this, idx]()
|
||||||
{
|
{
|
||||||
controls[idx].second->setIsVisible(false);
|
controls[idx].second->setIsVisible(false);
|
||||||
|
|
||||||
@@ -249,12 +281,11 @@ void TabControl::add(std::string tabText, std::unique_ptr<Control> control)
|
|||||||
if (tab.first->getButtonText() == tabText)
|
if (tab.first->getButtonText() == tabText)
|
||||||
{
|
{
|
||||||
control->setParent(tab.second.get());
|
control->setParent(tab.second.get());
|
||||||
control->setIsVisible( tab.second->IsVisible());
|
control->setIsVisible(tab.second->IsVisible());
|
||||||
tab.second->addControl(std::move(control));
|
tab.second->addControl(std::move(control));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabControl::setTabPlacement(StellarX::TabPlacement placement)
|
void TabControl::setTabPlacement(StellarX::TabPlacement placement)
|
||||||
@@ -263,7 +294,6 @@ void TabControl::setTabPlacement(StellarX::TabPlacement placement)
|
|||||||
setDirty(true);
|
setDirty(true);
|
||||||
initTabBar();
|
initTabBar();
|
||||||
initTabPage();
|
initTabPage();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabControl::setTabBarHeight(int height)
|
void TabControl::setTabBarHeight(int height)
|
||||||
@@ -277,26 +307,42 @@ void TabControl::setTabBarHeight(int height)
|
|||||||
void TabControl::setIsVisible(bool visible)
|
void TabControl::setIsVisible(bool visible)
|
||||||
{
|
{
|
||||||
// 先让基类 Canvas 处理自己的回贴/丢快照逻辑
|
// 先让基类 Canvas 处理自己的回贴/丢快照逻辑
|
||||||
Canvas::setIsVisible(visible); // <--- 新增
|
Canvas::setIsVisible(visible);
|
||||||
|
|
||||||
this->show = visible;
|
|
||||||
for (auto& tab : controls)
|
for (auto& tab : controls)
|
||||||
|
{
|
||||||
|
if(true == visible)
|
||||||
{
|
{
|
||||||
tab.first->setIsVisible(visible);
|
tab.first->setIsVisible(visible);
|
||||||
//页也要跟着关/开,否则它们会保留旧的 saveBkImage
|
//页也要跟着关/开,否则它们会保留旧的 saveBkImage
|
||||||
tab.second->setIsVisible(visible);
|
if (tab.first->isClicked())
|
||||||
|
tab.second->setIsVisible(true);
|
||||||
|
else
|
||||||
|
tab.second->setIsVisible(false);
|
||||||
tab.second->setDirty(true);
|
tab.second->setDirty(true);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tab.first->setIsVisible(visible);
|
||||||
|
tab.second->setIsVisible(visible);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabControl::onWindowResize()
|
void TabControl::onWindowResize()
|
||||||
{
|
{
|
||||||
|
// 调用基类的窗口变化处理,丢弃快照并标记脏
|
||||||
Control::onWindowResize();
|
Control::onWindowResize();
|
||||||
|
// 根据当前 TabControl 的新尺寸重新计算页签栏和页面区域
|
||||||
|
initTabBar();
|
||||||
|
initTabPage();
|
||||||
|
// 转发窗口尺寸变化给所有页签按钮和页面
|
||||||
for (auto& c : controls)
|
for (auto& c : controls)
|
||||||
{
|
{
|
||||||
c.first->onWindowResize();
|
c.first->onWindowResize();
|
||||||
c.second->onWindowResize();
|
c.second->onWindowResize();
|
||||||
}
|
}
|
||||||
|
// 尺寸变化后需要重绘自身
|
||||||
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TabControl::getActiveIndex() const
|
int TabControl::getActiveIndex() const
|
||||||
@@ -313,20 +359,13 @@ int TabControl::getActiveIndex() const
|
|||||||
|
|
||||||
void TabControl::setActiveIndex(int idx)
|
void TabControl::setActiveIndex(int idx)
|
||||||
{
|
{
|
||||||
if (idx < 0 || idx > controls.size() - 1) return;
|
if (IsFirstDraw)
|
||||||
if (controls[idx].first->getButtonMode() == StellarX::ButtonMode::DISABLED)return;
|
defaultActivation = idx;
|
||||||
if (controls[idx].first->isClicked())
|
|
||||||
{
|
|
||||||
if (controls[idx].second->IsVisible())
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
controls[idx].second->setIsVisible(true);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (idx >= 0 && idx < controls.size())
|
||||||
controls[idx].first->setButtonClick(true);
|
controls[idx].first->setButtonClick(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TabControl::count() const
|
int TabControl::count() const
|
||||||
@@ -337,7 +376,7 @@ int TabControl::count() const
|
|||||||
int TabControl::indexOf(const std::string& tabText) const
|
int TabControl::indexOf(const std::string& tabText) const
|
||||||
{
|
{
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
for(auto& c : controls)
|
for (auto& c : controls)
|
||||||
{
|
{
|
||||||
idx++;
|
idx++;
|
||||||
if (c.first->getButtonText() == tabText)
|
if (c.first->getButtonText() == tabText)
|
||||||
@@ -364,15 +403,9 @@ void TabControl::requestRepaint(Control* parent)
|
|||||||
for (auto& control : controls)
|
for (auto& control : controls)
|
||||||
{
|
{
|
||||||
if (control.first->isDirty() && control.first->IsVisible())
|
if (control.first->isDirty() && control.first->IsVisible())
|
||||||
{
|
|
||||||
control.first->draw();
|
control.first->draw();
|
||||||
break;
|
else if (control.second->isDirty() && control.second->IsVisible())
|
||||||
}
|
|
||||||
else if (control.second->isDirty()&&control.second->IsVisible())
|
|
||||||
{
|
|
||||||
control.second->draw();
|
control.second->draw();
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Label::Label()
|
|||||||
{
|
{
|
||||||
this->id = "Label";
|
this->id = "Label";
|
||||||
this->text = "默认标签";
|
this->text = "默认标签";
|
||||||
textStyle.color = RGB(0,0,0);
|
textStyle.color = RGB(0, 0, 0);
|
||||||
textBkColor = RGB(255, 255, 255);; //默认白色背景
|
textBkColor = RGB(255, 255, 255);; //默认白色背景
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ void Label::draw()
|
|||||||
this->height = textheight(text.c_str());
|
this->height = textheight(text.c_str());
|
||||||
}
|
}
|
||||||
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
|
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
|
||||||
saveBackground(this->x, this->y,this->width,this->height);
|
saveBackground(this->x, this->y, this->width, this->height);
|
||||||
// 恢复背景(清除旧内容)
|
// 恢复背景(清除旧内容)
|
||||||
restBackground();
|
restBackground();
|
||||||
outtextxy(x, y, LPCTSTR(text.c_str()));
|
outtextxy(x, y, LPCTSTR(text.c_str()));
|
||||||
@@ -71,5 +71,4 @@ void Label::setText(std::string text)
|
|||||||
{
|
{
|
||||||
this->text = text;
|
this->text = text;
|
||||||
this->dirty = true;
|
this->dirty = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
170
src/table.cpp
170
src/table.cpp
@@ -26,12 +26,10 @@ void Table::drawTable()
|
|||||||
dY = uY;
|
dY = uY;
|
||||||
uY = dY + lineHeights.at(0) + TABLE_ROW_EXTRA;
|
uY = dY + lineHeights.at(0) + TABLE_ROW_EXTRA;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Table::drawHeader()
|
void Table::drawHeader()
|
||||||
{
|
{
|
||||||
|
|
||||||
const int border = tableBorderWidth > 0 ? tableBorderWidth : 0;
|
const int border = tableBorderWidth > 0 ? tableBorderWidth : 0;
|
||||||
// 内容区原点 = x+border, y+border
|
// 内容区原点 = x+border, y+border
|
||||||
dX = x + border;
|
dX = x + border;
|
||||||
@@ -87,11 +85,15 @@ void Table::initTextWaH()
|
|||||||
if (h > maxLineH)
|
if (h > maxLineH)
|
||||||
maxLineH = h;
|
maxLineH = h;
|
||||||
|
|
||||||
// 列的像素宽 = 内容宽 + 左右 padding
|
// 列宽包含左右 padding:在计算完最大文本宽度后,加上 2*padX 作为单元格内边距
|
||||||
|
for (size_t j = 0; j < colWidths.size(); ++j) {
|
||||||
|
colWidths[j] += 2 * padX;
|
||||||
|
}
|
||||||
|
|
||||||
// 表内容总宽 = Σ(列宽 + 列间距)
|
// 表内容总宽 = Σ(列宽 + 列间距)
|
||||||
int contentW = 0;
|
int contentW = 0;
|
||||||
for (size_t j = 0; j < colWidths.size(); ++j)
|
for (size_t j = 0; j < colWidths.size(); ++j)
|
||||||
contentW += (colWidths[j] + 2 * padX) + colGap;
|
contentW += colWidths[j] + colGap;
|
||||||
|
|
||||||
// 表头高 & 行高(与 drawHeader/drawTable 内部一致:+上下 padding)
|
// 表头高 & 行高(与 drawHeader/drawTable 内部一致:+上下 padding)
|
||||||
const int headerH = maxLineH + 2 * padY;
|
const int headerH = maxLineH + 2 * padY;
|
||||||
@@ -109,6 +111,9 @@ void Table::initTextWaH()
|
|||||||
// 最终表宽/高:内容 + 对称边框
|
// 最终表宽/高:内容 + 对称边框
|
||||||
this->width = contentW + (border << 1);
|
this->width = contentW + (border << 1);
|
||||||
this->height = headerH + rowsH + footerH + (border << 1);
|
this->height = headerH + rowsH + footerH + (border << 1);
|
||||||
|
// 记录原始宽高用于锚点布局的参考;此处仅在初始化单元尺寸时重置
|
||||||
|
this->localWidth = this->width;
|
||||||
|
this->localHeight = this->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Table::initButton()
|
void Table::initButton()
|
||||||
@@ -125,7 +130,6 @@ void Table::initButton()
|
|||||||
int nextW = textwidth(LPCTSTR(TABLE_STR_NEXT)) + padH * 2;
|
int nextW = textwidth(LPCTSTR(TABLE_STR_NEXT)) + padH * 2;
|
||||||
int btnH = lblH + padV * 2;
|
int btnH = lblH + padV * 2;
|
||||||
|
|
||||||
|
|
||||||
// 基于“页码标签”的矩形来摆放:
|
// 基于“页码标签”的矩形来摆放:
|
||||||
// prev 在页码左侧 gap 处;next 在右侧 gap 处;Y 对齐 pY
|
// prev 在页码左侧 gap 处;next 在右侧 gap 处;Y 对齐 pY
|
||||||
int prevX = pX - gap - prevW;
|
int prevX = pX - gap - prevW;
|
||||||
@@ -171,6 +175,7 @@ void Table::initButton()
|
|||||||
if (pageNum) pageNum->setDirty(true);
|
if (pageNum) pageNum->setDirty(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
isNeedButtonAndPageNum = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Table::initPageNum()
|
void Table::initPageNum()
|
||||||
@@ -191,7 +196,7 @@ void Table::initPageNum()
|
|||||||
// 按理来说 x + (this->width - textW) / 2;就可以
|
// 按理来说 x + (this->width - textW) / 2;就可以
|
||||||
// 但是在绘制时,发现控件偏右,因此减去40
|
// 但是在绘制时,发现控件偏右,因此减去40
|
||||||
int textW = textwidth(LPCTSTR(pageNumtext.c_str()));
|
int textW = textwidth(LPCTSTR(pageNumtext.c_str()));
|
||||||
pX = x + TABLE_PAGE_TEXT_OFFSET_X +(this->width - textW) / 2;
|
pX = x + TABLE_PAGE_TEXT_OFFSET_X + (this->width - textW) / 2;
|
||||||
|
|
||||||
if (!pageNum)
|
if (!pageNum)
|
||||||
pageNum = new Label(pX, pY, pageNumtext);
|
pageNum = new Label(pX, pY, pageNumtext);
|
||||||
@@ -208,25 +213,23 @@ void Table::initPageNum()
|
|||||||
|
|
||||||
void Table::drawPageNum()
|
void Table::drawPageNum()
|
||||||
{
|
{
|
||||||
|
|
||||||
pageNumtext = "第";
|
pageNumtext = "第";
|
||||||
pageNumtext+= std::to_string(currentPage);
|
pageNumtext += std::to_string(currentPage);
|
||||||
pageNumtext += "页/共";
|
pageNumtext += "页/共";
|
||||||
pageNumtext += std::to_string(totalPages);
|
pageNumtext += std::to_string(totalPages);
|
||||||
pageNumtext += "页";
|
pageNumtext += "页";
|
||||||
if (nullptr == pageNum)
|
if (nullptr == pageNum || isNeedButtonAndPageNum)
|
||||||
initPageNum();
|
initPageNum();
|
||||||
pageNum->setText(pageNumtext);
|
pageNum->setText(pageNumtext);
|
||||||
pageNum->textStyle = this->textStyle;
|
pageNum->textStyle = this->textStyle;
|
||||||
if (StellarX::FillMode::Null == tableFillMode)
|
if (StellarX::FillMode::Null == tableFillMode)
|
||||||
pageNum->setTextdisap(true);
|
pageNum->setTextdisap(true);
|
||||||
pageNum->draw();
|
pageNum->draw();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Table::drawButton()
|
void Table::drawButton()
|
||||||
{
|
{
|
||||||
if (nullptr == prevButton || nullptr == nextButton)
|
if ((nullptr == prevButton || nullptr == nextButton) || isNeedButtonAndPageNum)
|
||||||
initButton();
|
initButton();
|
||||||
|
|
||||||
this->prevButton->textStyle = this->textStyle;
|
this->prevButton->textStyle = this->textStyle;
|
||||||
@@ -239,7 +242,59 @@ void Table::drawButton()
|
|||||||
this->nextButton->setDirty(true);
|
this->nextButton->setDirty(true);
|
||||||
prevButton->draw();
|
prevButton->draw();
|
||||||
nextButton->draw();
|
nextButton->draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Table::setX(int x)
|
||||||
|
{
|
||||||
|
this->x = x;
|
||||||
|
isNeedButtonAndPageNum = true;
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Table::setY(int y)
|
||||||
|
{
|
||||||
|
this->y = y;
|
||||||
|
isNeedButtonAndPageNum = true;
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Table::setWidth(int width)
|
||||||
|
{
|
||||||
|
// 调整列宽以匹配新的表格总宽度。不修改 localWidth,避免累计误差。
|
||||||
|
// 当 width 与当前 width 不同时,根据差值平均分配到各列,余数依次累加/扣减。
|
||||||
|
const int ncols = static_cast<int>(colWidths.size());
|
||||||
|
if (ncols <= 0) {
|
||||||
|
this->width = width;
|
||||||
|
isNeedButtonAndPageNum = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int diff = width - this->width;
|
||||||
|
// 基础增量:整除部分
|
||||||
|
int baseChange = diff / ncols;
|
||||||
|
int remainder = diff % ncols;
|
||||||
|
for (int i = 0; i < ncols; ++i) {
|
||||||
|
int change = baseChange;
|
||||||
|
if (remainder > 0) {
|
||||||
|
change += 1;
|
||||||
|
remainder -= 1;
|
||||||
|
}
|
||||||
|
else if (remainder < 0) {
|
||||||
|
change -= 1;
|
||||||
|
remainder += 1;
|
||||||
|
}
|
||||||
|
int newWidth = colWidths[i] + change;
|
||||||
|
// 限制最小宽度为 1,防止出现负值
|
||||||
|
if (newWidth < 1) newWidth = 1;
|
||||||
|
colWidths[i] = newWidth;
|
||||||
|
}
|
||||||
|
this->width = width;
|
||||||
|
// 需要重新布局页脚元素
|
||||||
|
isNeedButtonAndPageNum = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Table::setHeight(int height)
|
||||||
|
{
|
||||||
|
//高度不变
|
||||||
}
|
}
|
||||||
|
|
||||||
Table::Table(int x, int y)
|
Table::Table(int x, int y)
|
||||||
@@ -317,18 +372,35 @@ void Table::draw()
|
|||||||
setfillstyle((int)tableFillMode);
|
setfillstyle((int)tableFillMode);
|
||||||
setbkmode(TRANSPARENT);
|
setbkmode(TRANSPARENT);
|
||||||
}
|
}
|
||||||
//确保在绘制任何表格内容之前捕获背景
|
// 在绘制前先恢复并更新背景快照:
|
||||||
// 临时恢复样式,确保捕获正确的背景
|
// 如果已有快照且尺寸发生变化,先恢复旧快照以清除上一次绘制,然后丢弃旧快照再重新抓取新的区域。
|
||||||
if ((!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height)||!saveBkImage)
|
if (hasSnap)
|
||||||
|
{
|
||||||
|
// 始终先恢复旧背景,清除上一帧内容
|
||||||
|
restBackground();
|
||||||
|
// 当尺寸变化或缓存图像无效时,需要重新截图
|
||||||
|
if (!saveBkImage || saveWidth != this->width || saveHeight != this->height)
|
||||||
|
{
|
||||||
|
discardBackground();
|
||||||
saveBackground(this->x, this->y, this->width, this->height);
|
saveBackground(this->x, this->y, this->width, this->height);
|
||||||
// 恢复背景(清除旧内容)
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 首次绘制时无背景缓存,直接抓取
|
||||||
|
saveBackground(this->x, this->y, this->width, this->height);
|
||||||
|
}
|
||||||
|
// 恢复最新的背景,保证绘制区域干净
|
||||||
restBackground();
|
restBackground();
|
||||||
// 绘制表头
|
// 绘制表头
|
||||||
|
|
||||||
dX = x;
|
//dX = x;
|
||||||
dY = y;
|
//dY = y;
|
||||||
|
if(isNeedDrawHeaders)
|
||||||
|
{
|
||||||
drawHeader();
|
drawHeader();
|
||||||
this->isNeedDrawHeaders = false;
|
this->isNeedDrawHeaders = false;
|
||||||
|
}
|
||||||
// 绘制当前页
|
// 绘制当前页
|
||||||
drawTable();
|
drawTable();
|
||||||
// 绘制页码标签
|
// 绘制页码标签
|
||||||
@@ -338,7 +410,6 @@ void Table::draw()
|
|||||||
if (this->isShowPageButton)
|
if (this->isShowPageButton)
|
||||||
drawButton();
|
drawButton();
|
||||||
|
|
||||||
|
|
||||||
// 恢复绘图状态
|
// 恢复绘图状态
|
||||||
restoreStyle();
|
restoreStyle();
|
||||||
dirty = false; // 标记不需要重绘
|
dirty = false; // 标记不需要重绘
|
||||||
@@ -347,14 +418,14 @@ void Table::draw()
|
|||||||
|
|
||||||
bool Table::handleEvent(const ExMessage& msg)
|
bool Table::handleEvent(const ExMessage& msg)
|
||||||
{
|
{
|
||||||
if(!show)return false;
|
if (!show)return false;
|
||||||
bool consume = false;
|
bool consume = false;
|
||||||
if(!this->isShowPageButton)
|
if (!this->isShowPageButton)
|
||||||
return consume;
|
return consume;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(prevButton)consume = prevButton->handleEvent(msg);
|
if (prevButton)consume = prevButton->handleEvent(msg);
|
||||||
if (nextButton&&!consume)
|
if (nextButton && !consume)
|
||||||
consume = nextButton->handleEvent(msg);
|
consume = nextButton->handleEvent(msg);
|
||||||
}
|
}
|
||||||
if (dirty)
|
if (dirty)
|
||||||
@@ -365,14 +436,14 @@ bool Table::handleEvent(const ExMessage& msg)
|
|||||||
void Table::setHeaders(std::initializer_list<std::string> headers)
|
void Table::setHeaders(std::initializer_list<std::string> headers)
|
||||||
{
|
{
|
||||||
this->headers.clear();
|
this->headers.clear();
|
||||||
for (auto lis : headers)
|
for (auto& lis : headers)
|
||||||
this->headers.push_back(lis);
|
this->headers.push_back(lis);
|
||||||
isNeedCellSize = true; // 标记需要重新计算单元格尺寸
|
isNeedCellSize = true; // 标记需要重新计算单元格尺寸
|
||||||
isNeedDrawHeaders = true; // 标记需要重新绘制表头
|
isNeedDrawHeaders = true; // 标记需要重新绘制表头
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Table::setData( std::vector<std::string> data)
|
void Table::setData(std::vector<std::string> data)
|
||||||
{
|
{
|
||||||
if (data.size() < headers.size())
|
if (data.size() < headers.size())
|
||||||
for (int i = 0; data.size() <= headers.size(); i++)
|
for (int i = 0; data.size() <= headers.size(); i++)
|
||||||
@@ -385,12 +456,12 @@ void Table::setData( std::vector<std::string> data)
|
|||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Table::setData( std::initializer_list<std::vector<std::string>> data)
|
void Table::setData(std::initializer_list<std::vector<std::string>> data)
|
||||||
{
|
{
|
||||||
for (auto lis : data)
|
for (auto lis : data)
|
||||||
if (lis.size() < headers.size())
|
if (lis.size() < headers.size())
|
||||||
{
|
{
|
||||||
for (size_t i = lis.size(); i< headers.size(); i++)
|
for (size_t i = lis.size(); i < headers.size(); i++)
|
||||||
lis.push_back("");
|
lis.push_back("");
|
||||||
this->data.push_back(lis);
|
this->data.push_back(lis);
|
||||||
}
|
}
|
||||||
@@ -464,6 +535,42 @@ void Table::setTableBorderWidth(int width)
|
|||||||
this->dirty = true;
|
this->dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Table::clearHeaders()
|
||||||
|
{
|
||||||
|
this->headers.clear();
|
||||||
|
isNeedCellSize = true; // 标记需要重新计算单元格尺寸
|
||||||
|
isNeedDrawHeaders = true; // 标记需要重新绘制表头
|
||||||
|
isNeedButtonAndPageNum = true;// 标记需要重新计算翻页按钮和页码信息
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Table::clearData()
|
||||||
|
{
|
||||||
|
this->data.clear();
|
||||||
|
this->currentPage = 1;
|
||||||
|
this->totalPages = 1;
|
||||||
|
isNeedCellSize = true; // 标记需要重新计算单元格尺寸
|
||||||
|
isNeedButtonAndPageNum = true;// 标记需要重新计算翻页按钮和页码信息
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Table::resetTable()
|
||||||
|
{
|
||||||
|
clearHeaders();
|
||||||
|
clearData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Table::onWindowResize()
|
||||||
|
{
|
||||||
|
Control::onWindowResize(); // 先处理自己
|
||||||
|
if (this->prevButton && this->nextButton && this->pageNum)
|
||||||
|
{
|
||||||
|
prevButton->onWindowResize();
|
||||||
|
nextButton->onWindowResize();
|
||||||
|
pageNum->onWindowResize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Table::getCurrentPage() const
|
int Table::getCurrentPage() const
|
||||||
{
|
{
|
||||||
return this->currentPage;
|
return this->currentPage;
|
||||||
@@ -519,4 +626,15 @@ int Table::getTableBorderWidth() const
|
|||||||
return this->tableBorderWidth;
|
return this->tableBorderWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Table::getTableWidth() const
|
||||||
|
{
|
||||||
|
int temp = 0;
|
||||||
|
for (auto& w : colWidths)
|
||||||
|
temp += w;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Table::getTableHeight() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
// TextBox.cpp
|
// TextBox.cpp
|
||||||
#include "TextBox.h"
|
#include "TextBox.h"
|
||||||
|
|
||||||
|
|
||||||
TextBox::TextBox(int x, int y, int width, int height, std::string text, StellarX::TextBoxmode mode, StellarX::ControlShape shape)
|
TextBox::TextBox(int x, int y, int width, int height, std::string text, StellarX::TextBoxmode mode, StellarX::ControlShape shape)
|
||||||
:Control(x,y,width,height),text(text), mode(mode), shape(shape)
|
:Control(x, y, width, height), text(text), mode(mode), shape(shape)
|
||||||
{
|
{
|
||||||
this->id = "TextBox";
|
this->id = "TextBox";
|
||||||
}
|
}
|
||||||
@@ -25,8 +24,22 @@ void TextBox::draw()
|
|||||||
|
|
||||||
settextcolor(textStyle.color);
|
settextcolor(textStyle.color);
|
||||||
setbkmode(TRANSPARENT);
|
setbkmode(TRANSPARENT);
|
||||||
int text_width = textwidth(LPCTSTR(text.c_str()));
|
|
||||||
int text_height = textheight(LPCTSTR(text.c_str()));
|
int text_width = 0;
|
||||||
|
int text_height = 0;
|
||||||
|
std::string pwdText;
|
||||||
|
if (StellarX::TextBoxmode::PASSWORD_MODE == mode)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < text.size(); ++i)
|
||||||
|
pwdText += '*';
|
||||||
|
text_width = textwidth(LPCTSTR(pwdText.c_str()));
|
||||||
|
text_height = textheight(LPCTSTR(pwdText.c_str()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
text_width = textwidth(LPCTSTR(text.c_str()));
|
||||||
|
text_height = textheight(LPCTSTR(text.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
|
if ((saveBkX != this->x) || (saveBkY != this->y) || (!hasSnap) || (saveWidth != this->width) || (saveHeight != this->height) || !saveBkImage)
|
||||||
saveBackground(this->x, this->y, this->width, this->height);
|
saveBackground(this->x, this->y, this->width, this->height);
|
||||||
@@ -36,26 +49,29 @@ void TextBox::draw()
|
|||||||
switch (shape)
|
switch (shape)
|
||||||
{
|
{
|
||||||
case StellarX::ControlShape::RECTANGLE:
|
case StellarX::ControlShape::RECTANGLE:
|
||||||
fillrectangle(x,y,x+width,y+height);//有边框填充矩形
|
fillrectangle(x, y, x + width, y + height);//有边框填充矩形
|
||||||
outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
|
StellarX::TextBoxmode::PASSWORD_MODE == mode ? outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(pwdText.c_str()))
|
||||||
|
: outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
|
||||||
break;
|
break;
|
||||||
case StellarX::ControlShape::B_RECTANGLE:
|
case StellarX::ControlShape::B_RECTANGLE:
|
||||||
solidrectangle(x, y, x + width, y + height);//无边框填充矩形
|
solidrectangle(x, y, x + width, y + height);//无边框填充矩形
|
||||||
outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
|
StellarX::TextBoxmode::PASSWORD_MODE == mode ? outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(pwdText.c_str()))
|
||||||
|
: outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
|
||||||
break;
|
break;
|
||||||
case StellarX::ControlShape::ROUND_RECTANGLE:
|
case StellarX::ControlShape::ROUND_RECTANGLE:
|
||||||
fillroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//有边框填充圆角矩形
|
fillroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//有边框填充圆角矩形
|
||||||
outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
|
StellarX::TextBoxmode::PASSWORD_MODE == mode ? outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(pwdText.c_str()))
|
||||||
|
:outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
|
||||||
break;
|
break;
|
||||||
case StellarX::ControlShape::B_ROUND_RECTANGLE:
|
case StellarX::ControlShape::B_ROUND_RECTANGLE:
|
||||||
solidroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//无边框填充圆角矩形
|
solidroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//无边框填充圆角矩形
|
||||||
outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
|
StellarX::TextBoxmode::PASSWORD_MODE == mode ? outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(pwdText.c_str()))
|
||||||
|
:outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
restoreStyle();
|
restoreStyle();
|
||||||
dirty = false; //标记不需要重绘
|
dirty = false; //标记不需要重绘
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextBox::handleEvent(const ExMessage& msg)
|
bool TextBox::handleEvent(const ExMessage& msg)
|
||||||
@@ -77,9 +93,13 @@ bool TextBox::handleEvent(const ExMessage& msg)
|
|||||||
if (hover && msg.message == WM_LBUTTONUP)
|
if (hover && msg.message == WM_LBUTTONUP)
|
||||||
{
|
{
|
||||||
click = true;
|
click = true;
|
||||||
if(StellarX::TextBoxmode::INPUT_MODE == mode)
|
if (StellarX::TextBoxmode::INPUT_MODE == mode)
|
||||||
{
|
{
|
||||||
dirty = InputBox(LPTSTR(text.c_str()), (int)maxCharLen, "输入框", NULL, text.c_str(), NULL, NULL, false);
|
char* temp = new char[maxCharLen + 1];
|
||||||
|
dirty = InputBox(temp, (int)maxCharLen+1, "输入框", NULL, text.c_str(), NULL, NULL, false);
|
||||||
|
if (dirty)text = temp;
|
||||||
|
delete[] temp;
|
||||||
|
temp = nullptr;
|
||||||
consume = true;
|
consume = true;
|
||||||
}
|
}
|
||||||
else if (StellarX::TextBoxmode::READONLY_MODE == mode)
|
else if (StellarX::TextBoxmode::READONLY_MODE == mode)
|
||||||
@@ -88,6 +108,15 @@ bool TextBox::handleEvent(const ExMessage& msg)
|
|||||||
InputBox(NULL, (int)maxCharLen, "输出框(输入无效!)", NULL, text.c_str(), NULL, NULL, false);
|
InputBox(NULL, (int)maxCharLen, "输出框(输入无效!)", NULL, text.c_str(), NULL, NULL, false);
|
||||||
consume = true;
|
consume = true;
|
||||||
}
|
}
|
||||||
|
else if (StellarX::TextBoxmode::PASSWORD_MODE == mode)
|
||||||
|
{
|
||||||
|
char* temp = new char[maxCharLen + 1];
|
||||||
|
dirty = InputBox(temp, (int)maxCharLen+1, "输入框\n不可见输入,覆盖即可", NULL, NULL, NULL, NULL, false);
|
||||||
|
if (dirty)text = temp;
|
||||||
|
delete[] temp;
|
||||||
|
temp = nullptr;
|
||||||
|
consume = true;
|
||||||
|
}
|
||||||
flushmessage(EX_MOUSE | EX_KEY);
|
flushmessage(EX_MOUSE | EX_KEY);
|
||||||
}
|
}
|
||||||
if (dirty)
|
if (dirty)
|
||||||
@@ -146,7 +175,7 @@ void TextBox::setTextBoxBk(COLORREF color)
|
|||||||
|
|
||||||
void TextBox::setText(std::string text)
|
void TextBox::setText(std::string text)
|
||||||
{
|
{
|
||||||
if(text.size() > maxCharLen)
|
if (text.size() > maxCharLen)
|
||||||
text = text.substr(0, maxCharLen);
|
text = text.substr(0, maxCharLen);
|
||||||
this->text = text;
|
this->text = text;
|
||||||
this->dirty = true;
|
this->dirty = true;
|
||||||
@@ -157,5 +186,3 @@ std::string TextBox::getText() const
|
|||||||
{
|
{
|
||||||
return this->text;
|
return this->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
761
src/window.cpp
761
src/window.cpp
@@ -1,114 +1,348 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Dialog.h"
|
#include "Dialog.h"
|
||||||
#include <windows.h> // 确保包含 Windows API 头文件
|
|
||||||
|
|
||||||
Window::Window(int width, int height, int mode)
|
#include <easyx.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ApplyResizableStyle
|
||||||
|
* 作用:统一设置可拉伸/裁剪样式,并按开关使用 WS_EX_COMPOSITED(合成双缓冲)。
|
||||||
|
* 关键点:
|
||||||
|
* - WS_THICKFRAME:允许从四边/四角拖动改变尺寸。
|
||||||
|
* - WS_CLIPCHILDREN / WS_CLIPSIBLINGS:避免子控件互相覆盖时闪烁。
|
||||||
|
* - WS_EX_COMPOSITED:在一些环境更平滑,但个别显卡/驱动可能带来一帧延迟感。
|
||||||
|
* - SWP_FRAMECHANGED:通知窗口样式已变更,强制系统重算非客户区(标题栏/边框)。
|
||||||
|
*/
|
||||||
|
static void ApplyResizableStyle(HWND h, bool useComposited)
|
||||||
{
|
{
|
||||||
|
LONG style = GetWindowLong(h, GWL_STYLE);
|
||||||
|
style |= WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
|
||||||
|
SetWindowLong(h, GWL_STYLE, style);
|
||||||
|
|
||||||
this->pendingW = this->width = width;
|
LONG ex = GetWindowLong(h, GWL_EXSTYLE);
|
||||||
this->pendingH = this->height = height;
|
if (useComposited)
|
||||||
this->windowMode = mode;
|
{
|
||||||
|
ex |= WS_EX_COMPOSITED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ex &= ~WS_EX_COMPOSITED;
|
||||||
|
}
|
||||||
|
SetWindowLong(h, GWL_EXSTYLE, ex);
|
||||||
|
|
||||||
|
SetWindowPos(h, NULL, 0, 0, 0, 0,
|
||||||
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::Window(int width, int height, int mode, COLORREF bkcloc)
|
/**
|
||||||
|
* ApplyMinSizeOnSizing
|
||||||
|
* 作用:在 WM_SIZING 阶段执行“最小尺寸夹紧”。
|
||||||
|
* 规则:只回推“被拖动的那一侧”,另一侧当锚点(避免几何回弹/位置漂移)。
|
||||||
|
* 步骤:
|
||||||
|
* 1)将“最小客户区尺寸”通过 AdjustWindowRectEx 换算为“最小窗口矩形”(含非客户区)。
|
||||||
|
* 2)若当前矩形比最小还小,则根据 edge(哪条边/角在被拖)调整对应边,另一侧保持不动。
|
||||||
|
* 说明:仅保证不小于最小值;不做对齐/回滚等操作,把其余交给系统尺寸逻辑。
|
||||||
|
*/
|
||||||
|
static void ApplyMinSizeOnSizing(RECT* prc, WPARAM edge, HWND hWnd, int minClientW, int minClientH)
|
||||||
{
|
{
|
||||||
this->pendingW = this->width = width;
|
RECT rcFrame{ 0, 0, minClientW, minClientH };
|
||||||
this->pendingH = this->height = height;
|
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
|
||||||
this->windowMode = mode;
|
DWORD ex = GetWindowLong(hWnd, GWL_EXSTYLE);
|
||||||
this->wBkcolor = bkcloc;
|
AdjustWindowRectEx(&rcFrame, style, FALSE, ex);
|
||||||
|
|
||||||
|
const int minW = rcFrame.right - rcFrame.left;
|
||||||
|
const int minH = rcFrame.bottom - rcFrame.top;
|
||||||
|
|
||||||
|
const int curW = prc->right - prc->left;
|
||||||
|
const int curH = prc->bottom - prc->top;
|
||||||
|
|
||||||
|
if (curW < minW)
|
||||||
|
{
|
||||||
|
switch (edge)
|
||||||
|
{
|
||||||
|
case WMSZ_LEFT:
|
||||||
|
case WMSZ_TOPLEFT:
|
||||||
|
case WMSZ_BOTTOMLEFT:
|
||||||
|
prc->left = prc->right - minW; // 锚定右侧,回推左侧(左边被拖)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
prc->right = prc->left + minW; // 锚定左侧,回推右侧(右边被拖)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curH < minH)
|
||||||
|
{
|
||||||
|
switch (edge)
|
||||||
|
{
|
||||||
|
case WMSZ_TOP:
|
||||||
|
case WMSZ_TOPLEFT:
|
||||||
|
case WMSZ_TOPRIGHT:
|
||||||
|
prc->top = prc->bottom - minH; // 锚定下侧,回推上侧(上边被拖)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
prc->bottom = prc->top + minH; // 锚定上侧,回推下侧(下边被拖)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::Window(int width, int height, int mode, COLORREF bkcloc, std::string headline)
|
// ---------------- 构造 / 析构 ----------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造:初始化当前尺寸、待应用尺寸、最小客户区尺寸与 EasyX 模式。
|
||||||
|
* 注意:样式设置与子类化放在 draw() 内第一次绘制时完成。
|
||||||
|
*/
|
||||||
|
Window::Window(int w, int h, int mode)
|
||||||
{
|
{
|
||||||
this->pendingW = this->width = width;
|
localwidth = minClientW = pendingW = width = w;
|
||||||
this->pendingH = this->height = height;
|
localheight = minClientH = pendingH = height = h;
|
||||||
this->windowMode = mode;
|
windowMode = mode;
|
||||||
this->wBkcolor = bkcloc;
|
}
|
||||||
this->headline = headline;
|
|
||||||
|
Window::Window(int w, int h, int mode, COLORREF bk)
|
||||||
|
{
|
||||||
|
localwidth = minClientW = pendingW = width = w;
|
||||||
|
localheight = minClientH = pendingH = height = h;
|
||||||
|
windowMode = mode;
|
||||||
|
wBkcolor = bk;
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::Window(int w, int h, int mode, COLORREF bk, std::string title)
|
||||||
|
{
|
||||||
|
localwidth = minClientW = pendingW = width = w;
|
||||||
|
localheight = minClientH = pendingH = height = h;
|
||||||
|
windowMode = mode;
|
||||||
|
wBkcolor = bk;
|
||||||
|
headline = std::move(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window()
|
Window::~Window()
|
||||||
{
|
{
|
||||||
if (background)
|
// 析构:释放背景图对象并关闭 EasyX 图形环境
|
||||||
delete background;
|
if (background) delete background;
|
||||||
background = nullptr;
|
background = nullptr;
|
||||||
closegraph(); // 确保关闭图形上下文
|
closegraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------- 原生消息钩子----------------
|
||||||
|
|
||||||
void Window::draw() {
|
/**
|
||||||
// 使用 EasyX 创建基本窗口
|
* WndProcThun
|
||||||
|
* 作用:替换 EasyX 的窗口过程,接管关键消息。
|
||||||
|
* 关键处理:
|
||||||
|
* - WM_ERASEBKGND:返回 1,交由自绘清屏,避免系统擦背景造成闪烁。
|
||||||
|
* - WM_ENTERSIZEMOVE:开始拉伸 → isSizing=true 且 WM_SETREDRAW(FALSE) 冻结重绘。
|
||||||
|
* - WM_SIZING:拉伸中 → 仅做“最小尺寸夹紧”(按被拖边回推),不回滚、不绘制。
|
||||||
|
* - WM_EXITSIZEMOVE:结束拉伸 → 读取最终客户区尺寸 → 标记 needResizeDirty,解冻并刷新。
|
||||||
|
* - WM_GETMINMAXINFO:提供系统最小轨迹限制(四边一致)。
|
||||||
|
*/
|
||||||
|
LRESULT CALLBACK Window::WndProcThunk(HWND h, UINT m, WPARAM w, LPARAM l)
|
||||||
|
{
|
||||||
|
auto* self = reinterpret_cast<Window*>(GetWindowLongPtr(h, GWLP_USERDATA));
|
||||||
|
if (!self)
|
||||||
|
{
|
||||||
|
return DefWindowProc(h, m, w, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关键点①:禁止系统擦背景,避免和我们自己的清屏/双缓冲打架造成闪烁
|
||||||
|
if (m == WM_ERASEBKGND)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关键点②:拉伸开始 → 冻结重绘(系统调整窗口矩形时不触发即时重绘,防止抖)
|
||||||
|
if (m == WM_ENTERSIZEMOVE)
|
||||||
|
{
|
||||||
|
self->isSizing = true;
|
||||||
|
SendMessage(h, WM_SETREDRAW, FALSE, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关键点③:拉伸中 → 仅执行“最小尺寸夹紧”,不做对齐/节流/回滚,保持系统自然流畅
|
||||||
|
if (m == WM_SIZING)
|
||||||
|
{
|
||||||
|
RECT* prc = reinterpret_cast<RECT*>(l);
|
||||||
|
|
||||||
|
// “尺寸异常值”快速过滤:仅保护极端值,不影响正常拖动
|
||||||
|
int currentWidth = prc->right - prc->left;
|
||||||
|
int currentHeight = prc->bottom - prc->top;
|
||||||
|
if (currentWidth < 0 || currentHeight < 0 || currentWidth > 10000 || currentHeight > 10000)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplyMinSizeOnSizing(prc, w, h, self->minClientW, self->minClientH);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关键点④:拉伸结束 → 解冻重绘 + 统一收口(记录最终尺寸 -> 标记 needResizeDirty)
|
||||||
|
if (m == WM_EXITSIZEMOVE)
|
||||||
|
{
|
||||||
|
self->isSizing = false;
|
||||||
|
|
||||||
|
RECT rc; GetClientRect(h, &rc);
|
||||||
|
const int aw = rc.right - rc.left;
|
||||||
|
const int ah = rc.bottom - rc.top;
|
||||||
|
if (aw >= self->minClientW && ah >= self->minClientH && aw <= 10000 && ah <= 10000)
|
||||||
|
{
|
||||||
|
self->pendingW = aw;
|
||||||
|
self->pendingH = ah;
|
||||||
|
self->needResizeDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 结束拉伸后不立即执行重绘,待事件循环统一收口。
|
||||||
|
// 立即解冻重绘标志,同时标记区域为有效,避免触发额外 WM_PAINT。
|
||||||
|
SendMessage(h, WM_SETREDRAW, TRUE, 0);
|
||||||
|
ValidateRect(h, nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关键点⑤:系统级最小轨迹限制(与 WM_SIZING 的夹紧互相配合)
|
||||||
|
if (m == WM_GETMINMAXINFO)
|
||||||
|
{
|
||||||
|
auto* mmi = reinterpret_cast<MINMAXINFO*>(l);
|
||||||
|
RECT rc{ 0, 0, self->minClientW, self->minClientH };
|
||||||
|
DWORD style = GetWindowLong(h, GWL_STYLE);
|
||||||
|
DWORD ex = GetWindowLong(h, GWL_EXSTYLE);
|
||||||
|
// 若后续添加菜单,请把第三个参数改为 HasMenu(h)
|
||||||
|
AdjustWindowRectEx(&rc, style, FALSE, ex);
|
||||||
|
mmi->ptMinTrackSize.x = rc.right - rc.left;
|
||||||
|
mmi->ptMinTrackSize.y = rc.bottom - rc.top;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其它消息:回落到旧过程
|
||||||
|
return self->oldWndProc ? CallWindowProc(self->oldWndProc, h, m, w, l)
|
||||||
|
: DefWindowProc(h, m, w, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- 绘制 ----------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* draw()
|
||||||
|
* 作用:首次初始化 EasyX 窗口与子类化过程;应用可拉伸样式;清屏并批量绘制。
|
||||||
|
* 关键步骤:
|
||||||
|
* 1)initgraph 拿到 hWnd;
|
||||||
|
* 2)SetWindowLongPtr 子类化到 WndProcThunk(只做一次);
|
||||||
|
* 3)ApplyResizableStyle 设置 WS_THICKFRAME/裁剪/(可选)合成双缓冲;
|
||||||
|
* 4)去掉类样式 CS_HREDRAW/CS_VREDRAW,避免全窗无效化引发闪屏;
|
||||||
|
* 5)清屏 + Begin/EndBatchDraw 批量绘制控件&对话框。
|
||||||
|
*/
|
||||||
|
void Window::draw()
|
||||||
|
{
|
||||||
if (!hWnd)
|
if (!hWnd)
|
||||||
|
{
|
||||||
hWnd = initgraph(width, height, windowMode);
|
hWnd = initgraph(width, height, windowMode);
|
||||||
// **启用窗口拉伸支持**:添加厚边框和最大化按钮样式
|
}
|
||||||
LONG style = GetWindowLong(hWnd, GWL_STYLE);
|
|
||||||
style |= WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; // 可调整边框,启用最大化/最小化按钮
|
// 子类化:让我们的 WndProcThunk 接管窗口消息(仅执行一次)
|
||||||
SetWindowLong(hWnd, GWL_STYLE, style);
|
if (!procHooked)
|
||||||
// 通知窗口样式变化生效
|
{
|
||||||
SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
|
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)this);
|
||||||
|
oldWndProc = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)&Window::WndProcThunk);
|
||||||
|
procHooked = (oldWndProc != nullptr);
|
||||||
|
}
|
||||||
|
if (!headline.empty())
|
||||||
|
{
|
||||||
|
SetWindowText(hWnd, headline.c_str());
|
||||||
|
}
|
||||||
|
ApplyResizableStyle(hWnd, useComposited);
|
||||||
|
|
||||||
|
// 关闭类样式的整窗重绘标志(减少尺寸变化时的整窗 redraw)
|
||||||
|
LONG_PTR cls = GetClassLongPtr(hWnd, GCL_STYLE);
|
||||||
|
cls &= ~(CS_HREDRAW | CS_VREDRAW);
|
||||||
|
SetClassLongPtr(hWnd, GCL_STYLE, cls);
|
||||||
|
|
||||||
// 设置背景色并清屏
|
|
||||||
setbkcolor(wBkcolor);
|
setbkcolor(wBkcolor);
|
||||||
cleardevice();
|
cleardevice();
|
||||||
// 初次绘制所有控件(双缓冲)
|
|
||||||
BeginBatchDraw();
|
BeginBatchDraw();
|
||||||
for (auto& control : controls)
|
for (auto& c : controls)
|
||||||
{
|
{
|
||||||
control->draw();
|
c->draw();
|
||||||
|
}
|
||||||
|
for (auto& d : dialogs)
|
||||||
|
{
|
||||||
|
d->draw();
|
||||||
}
|
}
|
||||||
// (如果有初始对话框,也可绘制 dialogs)
|
|
||||||
EndBatchDraw();
|
EndBatchDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* draw(imagePath)
|
||||||
|
* 作用:在 draw() 的基础上加载并绘制背景图;其它流程完全一致。
|
||||||
|
* 注意:这里按当前窗口客户区大小加载背景图(loadimage 的 w/h),保证铺满。
|
||||||
|
*/
|
||||||
void Window::draw(std::string imagePath)
|
void Window::draw(std::string imagePath)
|
||||||
{
|
{
|
||||||
// 使用指定图片绘制窗口背景(铺满窗口)
|
|
||||||
this->background = new IMAGE(width, height);
|
|
||||||
bkImageFile = imagePath;
|
|
||||||
if (!hWnd)
|
if (!hWnd)
|
||||||
|
{
|
||||||
hWnd = initgraph(width, height, windowMode);
|
hWnd = initgraph(width, height, windowMode);
|
||||||
SetWindowText(hWnd, headline.c_str());
|
|
||||||
loadimage(background, imagePath.c_str(), width, height, true);
|
|
||||||
if(background)
|
|
||||||
putimage(0, 0, background);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 设置背景色并清屏
|
|
||||||
setbkcolor(wBkcolor);
|
|
||||||
cleardevice();
|
|
||||||
}
|
}
|
||||||
// 同样应用可拉伸样式
|
|
||||||
LONG style = GetWindowLong(hWnd, GWL_STYLE);
|
|
||||||
style |= WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;
|
|
||||||
SetWindowLong(hWnd, GWL_STYLE, style);
|
|
||||||
SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
|
|
||||||
|
|
||||||
// 绘制控件(含对话框)到窗口
|
if (!procHooked)
|
||||||
BeginBatchDraw();
|
|
||||||
for (auto& control : controls)
|
|
||||||
{
|
{
|
||||||
control->setDirty(true);
|
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)this);
|
||||||
control->draw();
|
oldWndProc = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)&Window::WndProcThunk);
|
||||||
|
procHooked = (oldWndProc != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bkImageFile = std::move(imagePath);
|
||||||
|
if (!headline.empty())
|
||||||
|
{
|
||||||
|
SetWindowText(hWnd, headline.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplyResizableStyle(hWnd, useComposited);
|
||||||
|
|
||||||
|
LONG_PTR cls = GetClassLongPtr(hWnd, GCL_STYLE);
|
||||||
|
cls &= ~(CS_HREDRAW | CS_VREDRAW);
|
||||||
|
SetClassLongPtr(hWnd, GCL_STYLE, cls);
|
||||||
|
|
||||||
|
if (background)
|
||||||
|
{
|
||||||
|
delete background;
|
||||||
|
background = nullptr;
|
||||||
|
}
|
||||||
|
background = new IMAGE;
|
||||||
|
loadimage(background, bkImageFile.c_str(), width, height, true);
|
||||||
|
putimage(0, 0, background);
|
||||||
|
|
||||||
|
BeginBatchDraw();
|
||||||
|
for (auto& c : controls)
|
||||||
|
{
|
||||||
|
c->setDirty(true);
|
||||||
|
c->draw();
|
||||||
|
}
|
||||||
|
for (auto& d : dialogs)
|
||||||
|
{
|
||||||
|
d->draw();
|
||||||
}
|
}
|
||||||
for (auto& dlg : dialogs) dlg->draw();
|
|
||||||
EndBatchDraw();
|
EndBatchDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 运行主事件循环,处理用户输入和窗口消息
|
// ---------------- 事件循环 ----------------
|
||||||
// 此方法会阻塞直到窗口关闭
|
|
||||||
// 主消息循环优先级:对话框 > 普通控件。
|
/**
|
||||||
// 重绘策略:为保证视觉一致性,每次有对话框状态变化(打开/关闭)时,
|
* runEventLoop()
|
||||||
// 会强制重绘所有控件。先绘制普通控件,再绘制对话框(确保对话框在最上层)。
|
* 作用:驱动输入/窗口消息;集中处理“统一收口重绘”。
|
||||||
|
* 关键策略:
|
||||||
|
* - WM_SIZE:始终更新 pendingW/H(即使在拉伸中也只记录不立即绘制);
|
||||||
|
* - needResizeDirty:当尺寸确实变化时置位,随后在循环尾进行一次性重绘;
|
||||||
|
* - 非模态对话框优先消费事件(顶层从后往前);再交给普通控件。
|
||||||
|
*/
|
||||||
int Window::runEventLoop()
|
int Window::runEventLoop()
|
||||||
{
|
{
|
||||||
ExMessage msg;
|
ExMessage msg;
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
|
||||||
|
// 说明:统一使用 needResizeDirty 作为“收口重绘”的唯一标志位
|
||||||
|
// 不再引入额外 pendingResize 等状态,避免分叉导致状态不一致。
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
bool consume = false;// 是否处理了消息
|
bool consume = false;
|
||||||
|
|
||||||
// 处理所有消息
|
|
||||||
if (peekmessage(&msg, EX_MOUSE | EX_KEY | EX_WINDOW, true))
|
if (peekmessage(&msg, EX_MOUSE | EX_KEY | EX_WINDOW, true))
|
||||||
{
|
{
|
||||||
if (msg.message == WM_CLOSE)
|
if (msg.message == WM_CLOSE)
|
||||||
@@ -116,42 +350,58 @@ int Window::runEventLoop()
|
|||||||
running = false;
|
running = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (msg.message == WM_SIZE)
|
|
||||||
|
// 保险:如果 EX_WINDOW 转译了 GETMINMAXINFO,同样按最小客户区折算处理
|
||||||
|
if (msg.message == WM_GETMINMAXINFO)
|
||||||
{
|
{
|
||||||
if (msg.wParam != SIZE_MINIMIZED)
|
auto* mmi = reinterpret_cast<MINMAXINFO*>(msg.lParam);
|
||||||
|
RECT rc{ 0, 0, minClientW, minClientH };
|
||||||
|
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
|
||||||
|
DWORD ex = GetWindowLong(hWnd, GWL_EXSTYLE);
|
||||||
|
AdjustWindowRectEx(&rc, style, FALSE, ex);
|
||||||
|
mmi->ptMinTrackSize.x = rc.right - rc.left;
|
||||||
|
mmi->ptMinTrackSize.y = rc.bottom - rc.top;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关键点⑥:WM_SIZE 只记录新尺寸;若非拉伸阶段则立即置位 needResizeDirty
|
||||||
|
if (msg.message == WM_SIZE && msg.wParam != SIZE_MINIMIZED)
|
||||||
{
|
{
|
||||||
const int nw = LOWORD(msg.lParam);
|
const int nw = LOWORD(msg.lParam);
|
||||||
const int nh = HIWORD(msg.lParam);
|
const int nh = HIWORD(msg.lParam);
|
||||||
|
|
||||||
// 仅在尺寸真的变化时标脏
|
// 基本合法性校验(不小于最小值、不过大)
|
||||||
if (nw > 0 && nh > 0 || (nw != width || nh != height))
|
if (nw >= minClientW && nh >= minClientH && nw <= 10000 && nh <= 10000)
|
||||||
|
{
|
||||||
|
if (nw != width || nh != height)
|
||||||
{
|
{
|
||||||
pendingW = nw;
|
pendingW = nw;
|
||||||
pendingH = nh;
|
pendingH = nh;
|
||||||
|
// 在“非拉伸阶段”的 WM_SIZE(例如最大化/还原/程序化调整)直接触发收口
|
||||||
needResizeDirty = true;
|
needResizeDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;//在末尾重绘制窗口
|
continue;
|
||||||
}
|
}
|
||||||
// 优先处理对话框事件
|
|
||||||
|
// 输入优先:先给顶层“非模态对话框”,再传给普通控件
|
||||||
for (auto it = dialogs.rbegin(); it != dialogs.rend(); ++it)
|
for (auto it = dialogs.rbegin(); it != dialogs.rend(); ++it)
|
||||||
{
|
{
|
||||||
auto& d = *it;
|
auto& d = *it;
|
||||||
if (d->IsVisible() && !d->model())
|
if (d->IsVisible() && !d->model())
|
||||||
consume = d->handleEvent(msg);
|
|
||||||
if (consume)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//普通控件
|
|
||||||
if (!consume)
|
|
||||||
for (auto it = controls.rbegin(); it != controls.rend(); ++it)
|
|
||||||
{
|
{
|
||||||
consume = (*it)->handleEvent(msg);
|
consume = d->handleEvent(msg);
|
||||||
if (consume)
|
}
|
||||||
break;
|
if (consume) break;
|
||||||
|
}
|
||||||
|
if (!consume)
|
||||||
|
{
|
||||||
|
for (auto& c : controls)
|
||||||
|
{
|
||||||
|
consume = c->handleEvent(msg);
|
||||||
|
if (consume) break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//如果有对话框打开或者关闭强制重绘
|
//如果有对话框打开或者关闭强制重绘
|
||||||
bool needredraw = false;
|
bool needredraw = false;
|
||||||
@@ -191,124 +441,183 @@ int Window::runEventLoop()
|
|||||||
}
|
}
|
||||||
EndBatchDraw();
|
EndBatchDraw();
|
||||||
needredraw = false;
|
needredraw = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
//—— 统一“收口”:尺寸变化后的** 一次性** 重绘 ——
|
// —— 统一收口(needResizeDirty 为真时执行一次性重绘)——
|
||||||
if (needResizeDirty)
|
if (needResizeDirty)
|
||||||
{
|
{
|
||||||
//确保窗口不会小于初始尺寸
|
// 以“实际客户区尺寸”为准,防止 pending 与真实尺寸出现偏差
|
||||||
if (pendingW >= width && pendingH >= height)
|
RECT clientRect;
|
||||||
Resize(nullptr, pendingW, pendingH);
|
GetClientRect(hWnd, &clientRect);
|
||||||
else
|
int actualWidth = clientRect.right - clientRect.left;
|
||||||
Resize(nullptr, width, height);
|
int actualHeight = clientRect.bottom - clientRect.top;
|
||||||
if (background)
|
|
||||||
|
const int finalW = (std::max)(minClientW, actualWidth);
|
||||||
|
const int finalH = (std::max)(minClientH, actualHeight);
|
||||||
|
|
||||||
|
// 变化过大/异常场景保护
|
||||||
|
if (finalW != width || finalH != height)
|
||||||
|
{
|
||||||
|
if (abs(finalW - width) > 1000 || abs(finalH - height) > 1000)
|
||||||
|
{
|
||||||
|
// 认为是异常帧,跳过本次(不改变任何状态)
|
||||||
|
needResizeDirty = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 再次冻结窗口更新,保证批量绘制的原子性
|
||||||
|
SendMessage(hWnd, WM_SETREDRAW, FALSE, 0);
|
||||||
|
|
||||||
|
BeginBatchDraw();
|
||||||
|
|
||||||
|
// 调整底层画布尺寸
|
||||||
|
if (finalW != width || finalH != height)
|
||||||
|
{
|
||||||
|
// 批量通知控件“窗口尺寸变化”,并标记重绘
|
||||||
|
for (auto& c : controls)
|
||||||
|
adaptiveLayout(c, finalH, finalW);
|
||||||
|
for (auto& d : dialogs)
|
||||||
|
{
|
||||||
|
if (auto dd = dynamic_cast<Dialog*>(d.get()))
|
||||||
|
{
|
||||||
|
dd->setDirty(true);
|
||||||
|
dd->setInitialization(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//重绘窗口
|
||||||
|
Resize(nullptr, finalW, finalH);
|
||||||
|
|
||||||
|
// 重取一次实际客户区尺寸做确认
|
||||||
|
GetClientRect(hWnd, &clientRect);
|
||||||
|
int confirmedWidth = clientRect.right - clientRect.left;
|
||||||
|
int confirmedHeight = clientRect.bottom - clientRect.top;
|
||||||
|
|
||||||
|
int renderWidth = confirmedWidth;
|
||||||
|
int renderHeight = confirmedHeight;
|
||||||
|
|
||||||
|
// 背景:若设置了背景图则重载并铺满;否则清屏为纯色
|
||||||
|
if (background && !bkImageFile.empty())
|
||||||
{
|
{
|
||||||
delete background;
|
delete background;
|
||||||
background = new IMAGE;
|
background = new IMAGE;
|
||||||
loadimage(background, bkImageFile.c_str(), pendingW, pendingH);
|
loadimage(background, bkImageFile.c_str(), renderWidth, renderHeight, true);
|
||||||
putimage(0, 0, background);
|
putimage(0, 0, background);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setbkcolor(wBkcolor);
|
||||||
|
cleardevice();
|
||||||
|
}
|
||||||
|
|
||||||
// 标记所有控件/对话框为脏,确保都补一次背景/外观
|
// 最终提交“当前已应用尺寸”(用于外部查询/下次比较)
|
||||||
|
width = renderWidth;
|
||||||
|
height = renderHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统一批量绘制
|
||||||
|
for (auto& c : controls) c->draw();
|
||||||
|
for (auto& d : dialogs) d->draw();
|
||||||
|
|
||||||
|
EndBatchDraw();
|
||||||
|
|
||||||
|
// 解冻后标记区域有效,避免系统再次触发 WM_PAINT 覆盖自绘内容。
|
||||||
|
SendMessage(hWnd, WM_SETREDRAW, TRUE, 0);
|
||||||
|
ValidateRect(hWnd, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
needResizeDirty = false; // 收口完成,清标志
|
||||||
|
}
|
||||||
|
|
||||||
|
// 轻微睡眠,削峰填谷(不阻塞拖拽体验)
|
||||||
|
Sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- 其余接口 ----------------
|
||||||
|
|
||||||
|
void Window::setBkImage(std::string pImgFile)
|
||||||
|
{
|
||||||
|
// 更换背景图:立即加载并绘制一次;同时将所有控件标 dirty 并重绘
|
||||||
|
if (background) delete background;
|
||||||
|
background = new IMAGE;
|
||||||
|
bkImageFile = std::move(pImgFile);
|
||||||
|
|
||||||
|
loadimage(background, bkImageFile.c_str(), width, height, true);
|
||||||
|
putimage(0, 0, background);
|
||||||
|
|
||||||
|
BeginBatchDraw();
|
||||||
for (auto& c : controls)
|
for (auto& c : controls)
|
||||||
{
|
{
|
||||||
c->onWindowResize();
|
c->setDirty(true);
|
||||||
c->draw();
|
c->draw();
|
||||||
}
|
}
|
||||||
for (auto& d : dialogs)
|
for (auto& d : dialogs)
|
||||||
{
|
{
|
||||||
auto dd = dynamic_cast<Dialog*>(d.get());
|
d->setDirty(true);
|
||||||
dd->setDirty(true);
|
|
||||||
dd->setInitialization(true);
|
|
||||||
d->draw();
|
d->draw();
|
||||||
}
|
}
|
||||||
needResizeDirty = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 降低占用
|
|
||||||
Sleep(10);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::setBkImage(std::string pImgFile)
|
|
||||||
{
|
|
||||||
if(nullptr == background)
|
|
||||||
this->background = new IMAGE;
|
|
||||||
else
|
|
||||||
delete background;
|
|
||||||
this->background = new IMAGE;
|
|
||||||
this->bkImageFile = pImgFile;
|
|
||||||
loadimage(background, pImgFile.c_str(), width, height, true);
|
|
||||||
putimage(0, 0, background);
|
|
||||||
BeginBatchDraw();
|
|
||||||
for (auto& c : controls)
|
|
||||||
{
|
|
||||||
c->setDirty(true);
|
|
||||||
c->draw();
|
|
||||||
}
|
|
||||||
for (auto& c : dialogs)
|
|
||||||
{
|
|
||||||
c->setDirty(true);
|
|
||||||
c->draw();
|
|
||||||
}
|
|
||||||
EndBatchDraw();
|
EndBatchDraw();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setBkcolor(COLORREF c)
|
void Window::setBkcolor(COLORREF c)
|
||||||
{
|
{
|
||||||
|
// 更换纯色背景:立即清屏并批量重绘控件/对话框
|
||||||
wBkcolor = c;
|
wBkcolor = c;
|
||||||
|
|
||||||
setbkcolor(wBkcolor);
|
setbkcolor(wBkcolor);
|
||||||
cleardevice();
|
cleardevice();
|
||||||
// 初次绘制所有控件(双缓冲)
|
|
||||||
BeginBatchDraw();
|
BeginBatchDraw();
|
||||||
for (auto& c : controls)
|
for (auto& c : controls)
|
||||||
{
|
{
|
||||||
c->setDirty(true);
|
c->setDirty(true);
|
||||||
c->draw();
|
c->draw();
|
||||||
}
|
}
|
||||||
for (auto& c : dialogs)
|
for (auto& d : dialogs)
|
||||||
{
|
{
|
||||||
c->setDirty(true);
|
d->setDirty(true);
|
||||||
c->draw();
|
d->draw();
|
||||||
}
|
}
|
||||||
EndBatchDraw();
|
EndBatchDraw();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setHeadline(std::string headline)
|
void Window::setHeadline(std::string title)
|
||||||
{
|
{
|
||||||
this->headline = headline;
|
// 设置窗口标题(仅改文本,不触发重绘)
|
||||||
SetWindowText(this->hWnd, headline.c_str());
|
headline = std::move(title);
|
||||||
|
if (hWnd)
|
||||||
|
SetWindowText(hWnd, headline.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::addControl(std::unique_ptr<Control> control)
|
void Window::addControl(std::unique_ptr<Control> control)
|
||||||
{
|
{
|
||||||
this->controls.push_back(std::move(control));
|
// 新增控件:仅加入管理容器,具体绘制在 draw()/收口时统一进行
|
||||||
|
controls.push_back(std::move(control));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::addDialog(std::unique_ptr<Control> dialogs)
|
void Window::addDialog(std::unique_ptr<Control> dlg)
|
||||||
{
|
{
|
||||||
this->dialogs.push_back(std::move(dialogs));
|
// 新增非模态对话框:管理顺序决定事件优先级(顶层从后往前)
|
||||||
|
dialogs.push_back(std::move(dlg));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::hasNonModalDialogWithCaption(const std::string& caption, const std::string& message) const
|
bool Window::hasNonModalDialogWithCaption(const std::string& caption, const std::string& message) const
|
||||||
{
|
{
|
||||||
|
// 查询是否存在“可见且非模态”的对话框(用于避免重复弹)
|
||||||
for (const auto& dptr : dialogs)
|
for (const auto& dptr : dialogs)
|
||||||
{
|
{
|
||||||
if (!dptr) continue;
|
if (!dptr) continue;
|
||||||
// 只检查 Dialog 类型的控件
|
if (auto* d = dynamic_cast<Dialog*>(dptr.get()))
|
||||||
Dialog* d = dynamic_cast<Dialog*>(dptr.get());
|
{
|
||||||
//检查是否有非模态对话框可见,并且消息内容一致
|
if (d->IsVisible() && !d->model() && d->GetCaption() == caption && d->GetText() == message)
|
||||||
if (d && d->IsVisible() && !d->model() && d->GetCaption() == caption && d->GetText() == message)
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HWND Window::getHwnd() const
|
HWND Window::getHwnd() const
|
||||||
{
|
{
|
||||||
return hWnd;
|
return hWnd;
|
||||||
@@ -316,40 +625,194 @@ HWND Window::getHwnd() const
|
|||||||
|
|
||||||
int Window::getWidth() const
|
int Window::getWidth() const
|
||||||
{
|
{
|
||||||
return this->pendingW;
|
// 注意:这里返回 pendingW
|
||||||
|
// 表示“最近一次收到的尺寸”(可能尚未应用到画布,最终以收口时的 width 为准)
|
||||||
|
return pendingW;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Window::getHeight() const
|
int Window::getHeight() const
|
||||||
{
|
{
|
||||||
return this->pendingH;
|
// 同上,返回 pendingH(与 getWidth 对应)
|
||||||
|
return pendingH;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Window::getHeadline() const
|
std::string Window::getHeadline() const
|
||||||
{
|
{
|
||||||
return this->headline;
|
return headline;
|
||||||
}
|
}
|
||||||
|
|
||||||
COLORREF Window::getBkcolor() const
|
COLORREF Window::getBkcolor() const
|
||||||
{
|
{
|
||||||
return this->wBkcolor;
|
return wBkcolor;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMAGE* Window::getBkImage() const
|
IMAGE* Window::getBkImage() const
|
||||||
{
|
{
|
||||||
return this->background;
|
return background;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Window::getBkImageFile() const
|
std::string Window::getBkImageFile() const
|
||||||
{
|
{
|
||||||
return this->bkImageFile;
|
return bkImageFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Control>>& Window::getControls()
|
std::vector<std::unique_ptr<Control>>& Window::getControls()
|
||||||
{
|
{
|
||||||
return this->controls;
|
return controls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::processWindowMessage(const ExMessage& msg)
|
||||||
|
{
|
||||||
|
if (msg.message == WM_SIZE && msg.wParam != SIZE_MINIMIZED)
|
||||||
|
{
|
||||||
|
const int nw = LOWORD(msg.lParam);
|
||||||
|
const int nh = HIWORD(msg.lParam);
|
||||||
|
if (nw >= minClientW && nh >= minClientH && nw <= 10000 && nh <= 10000)
|
||||||
|
{
|
||||||
|
if (nw != width || nh != height)
|
||||||
|
{
|
||||||
|
pendingW = nw;
|
||||||
|
pendingH = nh;
|
||||||
|
needResizeDirty = true; // 统一由 pumpResizeIfNeeded 来收口
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::pumpResizeIfNeeded()
|
||||||
|
{
|
||||||
|
if (!needResizeDirty) return;
|
||||||
|
|
||||||
|
RECT rc; GetClientRect(hWnd, &rc);
|
||||||
|
const int finalW = max(minClientW, rc.right - rc.left);
|
||||||
|
const int finalH = max(minClientH, rc.bottom - rc.top);
|
||||||
|
if (finalW == width && finalH == height) { needResizeDirty = false; return; }
|
||||||
|
|
||||||
|
SendMessage(hWnd, WM_SETREDRAW, FALSE, 0);
|
||||||
|
BeginBatchDraw();
|
||||||
|
|
||||||
|
// Resize + 背景
|
||||||
|
Resize(nullptr, finalW, finalH);
|
||||||
|
GetClientRect(hWnd, &rc);
|
||||||
|
if (background && !bkImageFile.empty())
|
||||||
|
{
|
||||||
|
delete background; background = new IMAGE;
|
||||||
|
loadimage(background, bkImageFile.c_str(), rc.right - rc.left, rc.bottom - rc.top, true);
|
||||||
|
putimage(0, 0, background);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setbkcolor(wBkcolor);
|
||||||
|
cleardevice();
|
||||||
|
}
|
||||||
|
width = rc.right - rc.left; height = rc.bottom - rc.top;
|
||||||
|
|
||||||
|
// 通知控件/对话框
|
||||||
|
for (auto& c : controls)
|
||||||
|
{
|
||||||
|
adaptiveLayout(c, finalH, finalW);
|
||||||
|
c->onWindowResize();
|
||||||
|
}
|
||||||
|
for (auto& d : dialogs)
|
||||||
|
if (auto* dd = dynamic_cast<Dialog*>(d.get()))
|
||||||
|
dd->setInitialization(true); // 强制对话框在新尺寸下重建布局/快照
|
||||||
|
|
||||||
|
// 重绘
|
||||||
|
for (auto& c : controls) c->draw();
|
||||||
|
for (auto& d : dialogs) d->draw();
|
||||||
|
|
||||||
|
EndBatchDraw();
|
||||||
|
SendMessage(hWnd, WM_SETREDRAW, TRUE, 0);
|
||||||
|
|
||||||
|
// 原实现在此调用 InvalidateRect 导致系统再次发送 WM_PAINT,从而重复绘制,
|
||||||
|
// 这里改为 ValidateRect:直接标记区域为有效,通知系统我们已完成绘制,不必再触发 WM_PAINT。
|
||||||
|
// 这样可以避免收口阶段的绘制与系统重绘叠加造成顺序错乱。
|
||||||
|
ValidateRect(hWnd, nullptr);
|
||||||
|
|
||||||
|
needResizeDirty = false;
|
||||||
|
}
|
||||||
|
void Window::scheduleResizeFromModal(int w, int h)
|
||||||
|
{
|
||||||
|
if (w < minClientW) w = minClientW;
|
||||||
|
if (h < minClientH) h = minClientH;
|
||||||
|
if (w > 10000) w = 10000;
|
||||||
|
if (h > 10000) h = 10000;
|
||||||
|
|
||||||
|
if (w != width || h != height)
|
||||||
|
{
|
||||||
|
pendingW = w;
|
||||||
|
pendingH = h;
|
||||||
|
needResizeDirty = true; // 交给 pumpResizeIfNeeded 做统一收口+重绘
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::adaptiveLayout(std::unique_ptr<Control>& c, const int finalH, const int finalW)
|
||||||
|
{
|
||||||
|
int origParentW = this->localwidth;
|
||||||
|
int origParentH = this->localheight;
|
||||||
|
if (c->getLayoutMode() == StellarX::LayoutMode::AnchorToEdges)
|
||||||
|
{
|
||||||
|
if ((StellarX::Anchor::Left == c->getAnchor_1() && StellarX::Anchor::Right == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::Right == c->getAnchor_1() && StellarX::Anchor::Left == c->getAnchor_2()))
|
||||||
|
{
|
||||||
|
int origRightDist = origParentW - (c->getLocalX() + c->getLocalWidth());
|
||||||
|
int newWidth = finalW - c->getLocalX() - origRightDist;
|
||||||
|
c->setWidth(newWidth);
|
||||||
|
// 左侧距离固定,ctrl->x 保持为 localx 相对窗口左侧(父容器为窗口,偏移0)
|
||||||
|
c->setX(c->getLocalX());
|
||||||
|
}
|
||||||
|
else if ((StellarX::Anchor::Left == c->getAnchor_1() && StellarX::Anchor::NoAnchor == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::NoAnchor == c->getAnchor_1() && StellarX::Anchor::Left == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::Left == c->getAnchor_1() && StellarX::Anchor::Left == c->getAnchor_2()))
|
||||||
|
{
|
||||||
|
// 仅左锚定:宽度固定不变
|
||||||
|
c->setX(c->getLocalX());
|
||||||
|
c->setWidth(c->getLocalWidth());
|
||||||
|
}
|
||||||
|
else if ((StellarX::Anchor::Right == c->getAnchor_1() && StellarX::Anchor::NoAnchor == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::NoAnchor == c->getAnchor_1() && StellarX::Anchor::Right == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::Right == c->getAnchor_1() && StellarX::Anchor::Right == c->getAnchor_2()))
|
||||||
|
{
|
||||||
|
int origRightDist = origParentW - (c->getLocalX() + c->getLocalWidth());
|
||||||
|
c->setWidth(c->getLocalWidth()); // 宽度不变
|
||||||
|
c->setX(finalW - origRightDist - c->getWidth());
|
||||||
|
}
|
||||||
|
else if (StellarX::Anchor::NoAnchor == c->getAnchor_1() && StellarX::Anchor::NoAnchor == c->getAnchor_2())
|
||||||
|
{
|
||||||
|
c->setX(c->getLocalX());
|
||||||
|
c->setWidth(c->getLocalWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((StellarX::Anchor::Top == c->getAnchor_1() && StellarX::Anchor::Bottom == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::Bottom == c->getAnchor_1() && StellarX::Anchor::Top == c->getAnchor_2()))
|
||||||
|
{
|
||||||
|
// 上下锚定:高度随窗口变化
|
||||||
|
int origBottomDist = origParentH - (c->getLocalY() + c->getLocalHeight());
|
||||||
|
int newHeight = finalH - c->getLocalY() - origBottomDist;
|
||||||
|
c->setHeight(newHeight);
|
||||||
|
c->setY(c->getLocalY());
|
||||||
|
}
|
||||||
|
else if ((StellarX::Anchor::Top == c->getAnchor_1() && StellarX::Anchor::NoAnchor == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::NoAnchor == c->getAnchor_1() && StellarX::Anchor::Top == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::Top == c->getAnchor_1() && StellarX::Anchor::Top == c->getAnchor_2()))
|
||||||
|
{
|
||||||
|
c->setY(c->getLocalY());
|
||||||
|
c->setHeight(c->getLocalHeight());
|
||||||
|
}
|
||||||
|
else if ((StellarX::Anchor::Bottom == c->getAnchor_1() && StellarX::Anchor::NoAnchor == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::NoAnchor == c->getAnchor_1() && StellarX::Anchor::Bottom == c->getAnchor_2())
|
||||||
|
|| (StellarX::Anchor::Bottom == c->getAnchor_1() && StellarX::Anchor::Bottom == c->getAnchor_2()))
|
||||||
|
{
|
||||||
|
int origBottomDist = origParentH - (c->getLocalY() + c->getLocalHeight());
|
||||||
|
c->setHeight(c->getLocalHeight());
|
||||||
|
c->setY(finalH - origBottomDist - c->getHeight());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 垂直无锚点:默认为顶部定位,高度固定
|
||||||
|
c->setY(c->getLocalY());
|
||||||
|
c->setHeight(c->getLocalHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c->onWindowResize();
|
||||||
|
}
|
||||||
2651
控件 API 文档 (StellarX GUI Framework Controls API Documentation).md
Normal file
2651
控件 API 文档 (StellarX GUI Framework Controls API Documentation).md
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user