initial commit
This commit is contained in:
+41
-58
@@ -3,8 +3,8 @@
|
||||
* \文件: Control.h
|
||||
* \描述: 控件基类,所有控件都继承自此类。
|
||||
* 提供了控件的一些基本属性和方法。
|
||||
*
|
||||
* \作者: 我在人间做废物
|
||||
*
|
||||
* \作者: 我在人间做废物
|
||||
* \日期: September 2025
|
||||
*********************************************************************/
|
||||
#include <vector>
|
||||
@@ -15,66 +15,49 @@
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include "CoreTypes.h"
|
||||
/**
|
||||
* @类名称: Control
|
||||
* @功能描述: 控件基类,所有控件都继承自此类。
|
||||
* 提供了控件的一些基本属性和方法。
|
||||
*
|
||||
* @成员说明:
|
||||
* int x, y, width, height; // 控件的基本属性
|
||||
*
|
||||
* LOGFONT currentFont; //保存当前字体样式和颜色
|
||||
* COLORREF currentColor = 0;
|
||||
* COLORREF currentBkColor = 0; //保存当前填充色
|
||||
* COLORREF currentBorderColor = 0;//边框颜色
|
||||
* LINESTYLE* currentLineStyle = new LINESTYLE; //保存当前线型
|
||||
*
|
||||
* Control():x(0), y(0), width(0), height(0) {}
|
||||
* Control(int x, int y, int width, int height) :x(x),y(y),width(width),height(height){}
|
||||
* virtual void draw() = 0; // 绘制控件
|
||||
* virtual void handleEvent(const ExMessage& msg) = 0; // 处理事件
|
||||
* virtual ~Control() { delete currentLineStyle; }
|
||||
*
|
||||
* //保存当前字体样式和颜色
|
||||
* void saveStyle();
|
||||
* //恢复默认字体样式和颜色
|
||||
* void restoreStyle();
|
||||
*
|
||||
* @使用示例:
|
||||
* Control* ctrl = new Button(10, 10, 100, 50, "Click Me");
|
||||
* ctrl->draw();
|
||||
* delete ctrl;
|
||||
*
|
||||
* @备注:
|
||||
* 这是一个抽象基类,不能直接实例化。
|
||||
* 所有具体的控件类都必须实现draw和handleEvent方法。
|
||||
*/
|
||||
class Control
|
||||
|
||||
class Control
|
||||
{
|
||||
protected:
|
||||
int x, y, width, height; // 控件的基本属性
|
||||
int x, y; // 左上角坐标
|
||||
int width, height; // 控件尺寸
|
||||
|
||||
StellarX::RouRectangle rouRectangleSize; // 圆角矩形椭圆宽度和高度
|
||||
|
||||
LOGFONT currentFont; // 保存当前字体样式和颜色
|
||||
COLORREF currentColor = 0;
|
||||
COLORREF currentBkColor = 0; // 保存当前填充色
|
||||
COLORREF currentBorderColor = 0; // 边框颜色
|
||||
LINESTYLE* currentLineStyle = new LINESTYLE; // 保存当前线型
|
||||
|
||||
LOGFONT currentFont; //保存当前字体样式和颜色
|
||||
COLORREF currentColor = 0;
|
||||
COLORREF currentBkColor = 0; //保存当前填充色
|
||||
COLORREF currentBorderColor = 0;//边框颜色
|
||||
LINESTYLE* currentLineStyle = new LINESTYLE; //保存当前线型
|
||||
public:
|
||||
Control(const Control&) = delete; // 禁用拷贝构造
|
||||
Control& operator=(const Control&) = delete; // 禁用拷贝赋值
|
||||
Control(Control&&) = default; // 允许移动构造
|
||||
Control& operator=(Control&&) = default; // 允许移动赋值
|
||||
Control():x(0), y(0), width(100), height(100) {}
|
||||
Control(int x, int y, int width, int height) :x(x),y(y),width(x + width),height(y + height){}
|
||||
|
||||
virtual void draw() = 0; // 绘制控件
|
||||
virtual void handleEvent(const ExMessage& msg) = 0; // 处理事件
|
||||
virtual ~Control() {
|
||||
delete currentLineStyle; currentLineStyle = nullptr; }
|
||||
|
||||
Control(const Control&) = delete;
|
||||
Control& operator=(const Control&) = delete;
|
||||
Control(Control&&) = default;
|
||||
Control& operator=(Control&&) = default;
|
||||
|
||||
Control() : x(0), y(0), width(100), height(100) {}
|
||||
Control(int x, int y, int width, int height)
|
||||
: x(x), y(y), width(width), height(height) {
|
||||
}
|
||||
|
||||
virtual ~Control() {
|
||||
delete currentLineStyle;
|
||||
currentLineStyle = nullptr;
|
||||
}
|
||||
|
||||
// 获取位置和尺寸
|
||||
int getX() const { return x; }
|
||||
int getY() const { return y; }
|
||||
int getWidth() const { return width; }
|
||||
int getHeight() const { return height; }
|
||||
int getRight() const { return x + width; }
|
||||
int getBottom() const { return y + height; }
|
||||
|
||||
virtual void draw() = 0;
|
||||
virtual void handleEvent(const ExMessage& msg) = 0;
|
||||
|
||||
protected:
|
||||
//保存当前样式和颜色
|
||||
void saveStyle();
|
||||
//恢复默认样式和颜色
|
||||
void restoreStyle();
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user