feat: add a new awesome feature
This commit is contained in:
+45
-18
@@ -1,19 +1,28 @@
|
||||
#pragma once
|
||||
/*********************************************************************
|
||||
* \文件: Control.h
|
||||
* \描述: 控件基类,所有控件都继承自此类。
|
||||
* 提供了控件的一些基本属性和方法。
|
||||
/*******************************************************************************
|
||||
* @类: Control
|
||||
* @摘要: 所有控件的抽象基类,定义通用接口和基础功能
|
||||
* @描述:
|
||||
* 提供控件的基本属性和方法,包括位置、尺寸、重绘标记等。
|
||||
* 实现绘图状态保存和恢复机制,确保控件绘制不影响全局状态。
|
||||
*
|
||||
* \作者: 我在人间做废物
|
||||
* \日期: September 2025
|
||||
*********************************************************************/
|
||||
* @特性:
|
||||
* - 定义控件基本属性(坐标、尺寸、脏标记)
|
||||
* - 提供绘图状态管理(saveStyle/restoreStyle)
|
||||
* - 声明纯虚接口(draw、handleEvent等)
|
||||
* - 支持移动语义,禁止拷贝语义
|
||||
*
|
||||
* @使用场景: 作为所有具体控件类的基类,不直接实例化
|
||||
* @所属框架: 星垣(StellarX) GUI框架
|
||||
* @作者: 我在人间做废物
|
||||
******************************************************************************/
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <easyx.h>
|
||||
#undef MessageBox
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include "CoreTypes.h"
|
||||
|
||||
class Control
|
||||
@@ -21,14 +30,15 @@ class Control
|
||||
protected:
|
||||
int x, y; // 左上角坐标
|
||||
int width, height; // 控件尺寸
|
||||
bool dirty = true; // 是否重绘
|
||||
|
||||
StellarX::RouRectangle rouRectangleSize; // 圆角矩形椭圆宽度和高度
|
||||
|
||||
LOGFONT currentFont; // 保存当前字体样式和颜色
|
||||
COLORREF currentColor = 0;
|
||||
COLORREF currentBkColor = 0; // 保存当前填充色
|
||||
COLORREF currentBorderColor = 0; // 边框颜色
|
||||
LINESTYLE* currentLineStyle = new LINESTYLE; // 保存当前线型
|
||||
LOGFONT* currentFont = new LOGFONT(); // 保存当前字体样式和颜色
|
||||
COLORREF* currentColor = new COLORREF();
|
||||
COLORREF* currentBkColor = new COLORREF(); // 保存当前填充色
|
||||
COLORREF* currentBorderColor = new COLORREF(); // 边框颜色
|
||||
LINESTYLE* currentLineStyle = new LINESTYLE(); // 保存当前线型
|
||||
|
||||
public:
|
||||
Control(const Control&) = delete;
|
||||
@@ -42,10 +52,21 @@ public:
|
||||
}
|
||||
|
||||
virtual ~Control() {
|
||||
delete currentFont;
|
||||
delete currentColor;
|
||||
delete currentBkColor;
|
||||
delete currentBorderColor;
|
||||
delete currentLineStyle;
|
||||
currentLineStyle = nullptr;
|
||||
}
|
||||
|
||||
currentFont = nullptr;
|
||||
currentColor = nullptr;
|
||||
currentBkColor = nullptr;
|
||||
currentBorderColor = nullptr;
|
||||
currentLineStyle = nullptr;
|
||||
|
||||
|
||||
}
|
||||
protected:
|
||||
// 获取位置和尺寸
|
||||
int getX() const { return x; }
|
||||
int getY() const { return y; }
|
||||
@@ -53,9 +74,15 @@ public:
|
||||
int getHeight() const { return height; }
|
||||
int getRight() const { return x + width; }
|
||||
int getBottom() const { return y + height; }
|
||||
|
||||
public:
|
||||
//设置是否重绘
|
||||
void setDirty(bool dirty) { this->dirty = dirty; }
|
||||
virtual void draw() = 0;
|
||||
virtual void handleEvent(const ExMessage& msg) = 0;
|
||||
virtual bool handleEvent(const ExMessage& msg) = 0;//返回true代表事件已消费
|
||||
//用来检查非模态对话框是否可见,其他控件不用实现
|
||||
virtual bool IsVisible() const = 0;
|
||||
//用来检查对话框是否模态,其他控件不用实现
|
||||
virtual bool model()const = 0;
|
||||
|
||||
protected:
|
||||
void saveStyle();
|
||||
|
||||
Reference in New Issue
Block a user