feat: add a new awesome feature
This commit is contained in:
+42
-38
@@ -1,14 +1,22 @@
|
||||
/*******************************************************************************
|
||||
* @文件: Button.h
|
||||
* @摘要: 按钮控件类
|
||||
* @描述:
|
||||
* 提供多种样式和行为的按钮控件,支持点击、悬停、切换等状态。
|
||||
* 继承自Control基类,是框架的核心交互组件之一。
|
||||
*
|
||||
* @所属框架: 星垣(StellarX) GUI框架
|
||||
* @作者: 我在人间做废物
|
||||
* @日期: September 2025
|
||||
******************************************************************************/
|
||||
/*******************************************************************************
|
||||
* @类: Button
|
||||
* @摘要: 多功能按钮控件,支持多种状态和样式
|
||||
* @描述:
|
||||
* 提供完整的按钮功能,包括普通点击、切换模式、禁用状态。
|
||||
* 支持多种形状(矩形、圆形、椭圆等)和丰富的视觉样式。
|
||||
* 通过回调函数机制实现灵活的交互逻辑。
|
||||
*
|
||||
* @特性:
|
||||
* - 支持三种工作模式:普通、切换、禁用
|
||||
* - 八种几何形状,各有边框和无边框版本
|
||||
* - 自定义颜色(默认、悬停、点击状态)
|
||||
* - 多种填充模式(纯色、图案、图像)
|
||||
* - 完整的鼠标事件处理(点击、悬停、移出)
|
||||
*
|
||||
* @使用场景: 作为主要交互控件,用于触发动作或表示状态
|
||||
* @所属框架: 星垣(StellarX) GUI框架
|
||||
* @作者: 我在人间做废物
|
||||
******************************************************************************/
|
||||
#pragma once
|
||||
#include "Control.h"
|
||||
|
||||
@@ -18,7 +26,6 @@ class Button : public Control
|
||||
std::string text; // 按钮上的文字
|
||||
bool click; // 是否被点击
|
||||
bool hover; // 是否被悬停
|
||||
bool dirty = true; // 是否重绘
|
||||
|
||||
COLORREF buttonTrueColor; // 按钮被点击后的颜色
|
||||
COLORREF buttonFalseColor; // 按钮未被点击的颜色
|
||||
@@ -28,7 +35,7 @@ class Button : public Control
|
||||
StellarX::ButtonMode mode; // 按钮模式
|
||||
StellarX::ControlShape shape; // 按钮形状
|
||||
|
||||
int buttonFillMode = BS_SOLID; //按钮填充模式
|
||||
StellarX::FillMode buttonFillMode = StellarX::FillMode::Solid; //按钮填充模式
|
||||
StellarX::FillStyle buttonFillIma = StellarX::FillStyle::BDiagonal; //按钮填充图案
|
||||
IMAGE* buttonFileIMAGE = nullptr; //按钮填充图像
|
||||
|
||||
@@ -47,12 +54,9 @@ public:
|
||||
StellarX::ControlText textStyle; // 按钮文字样式
|
||||
|
||||
public:
|
||||
/*************************************************************************/
|
||||
/********************************构造函数*********************************/
|
||||
/*************************************************************************/
|
||||
|
||||
//默认按钮颜色
|
||||
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,
|
||||
StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL, StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE);
|
||||
//自定义按钮未被点击和被点击颜色
|
||||
Button(int x, int y, int width, int height, const std::string text,
|
||||
@@ -65,24 +69,13 @@ public:
|
||||
//析构函数 释放图形指针内存
|
||||
~Button();
|
||||
|
||||
/*************************************************************************/
|
||||
/********************************Set方法**********************************/
|
||||
/*************************************************************************/
|
||||
//绘制按钮
|
||||
void draw() override;
|
||||
//按钮事件处理
|
||||
|
||||
void handleEvent(const ExMessage& msg) override;
|
||||
bool handleEvent(const ExMessage& msg) override;
|
||||
|
||||
//设置回调函数
|
||||
//************************************
|
||||
// 名称: setOnClickListener | setOnToggleOnListener | setOnToggleOffListener
|
||||
// 全名: Button::setOnClickListener
|
||||
// 访问: public
|
||||
// 返回类型: void
|
||||
// Parameter: const std::function<> & & callback 设置回调函数 传入回调函数名即可,不需要传入(),不需要传入参数,不需要传入返回值
|
||||
// 如果要传入参数,可以使用lambda表达式
|
||||
//************************************
|
||||
void setOnClickListener(const std::function<void()>&& callback);
|
||||
//设置TOGGLE模式下被点击的回调函数
|
||||
void setOnToggleOnListener(const std::function<void()>&& callback);
|
||||
@@ -91,17 +84,19 @@ public:
|
||||
//设置按钮模式
|
||||
void setbuttonMode(StellarX::ButtonMode mode);
|
||||
//设置圆角矩形椭圆宽度
|
||||
int setROUND_RECTANGLEwidth(int width);
|
||||
void setROUND_RECTANGLEwidth(int width);
|
||||
//设置圆角矩形椭圆高度
|
||||
int setROUND_RECTANGLEheight(int height);
|
||||
void setROUND_RECTANGLEheight(int height);
|
||||
//设置按钮填充模式
|
||||
void setFillMode(int mode);
|
||||
void setFillMode(StellarX::FillMode mode);
|
||||
//设置按钮填充图案
|
||||
void setFillIma(StellarX::FillStyle ima);
|
||||
//设置按钮填充图像
|
||||
void setFillIma(std::string imaName);
|
||||
//设置按钮边框颜色
|
||||
void setButtonBorder(COLORREF Border);
|
||||
//设置按钮未被点击颜色
|
||||
void setButtonFalseColor(COLORREF color);
|
||||
//设置按钮文本
|
||||
void setButtonText(const char* text);
|
||||
void setButtonText(std::string text);
|
||||
@@ -110,10 +105,6 @@ public:
|
||||
|
||||
//判断按钮是否被点击
|
||||
bool isClicked() const;
|
||||
|
||||
/*************************************************************************/
|
||||
/********************************Get方法**********************************/
|
||||
/*************************************************************************/
|
||||
|
||||
//获取按钮文字
|
||||
std::string getButtonText() const;
|
||||
@@ -123,7 +114,7 @@ public:
|
||||
//获取按钮形状
|
||||
StellarX::ControlShape getButtonShape() const;
|
||||
//获取按钮填充模式
|
||||
int getFillMode() const;
|
||||
StellarX::FillMode getFillMode() const;
|
||||
//获取按钮填充图案
|
||||
StellarX::FillStyle getFillIma() const;
|
||||
//获取按钮填充图像
|
||||
@@ -134,6 +125,14 @@ public:
|
||||
COLORREF getButtonTextColor() const;
|
||||
//获取按钮文字样式
|
||||
StellarX::ControlText getButtonTextStyle() const;
|
||||
//获取按钮宽度
|
||||
int getButtonWidth() const;
|
||||
//获取按钮高度
|
||||
int getButtonHeight() const;
|
||||
//获取按钮横坐标
|
||||
int getButtonX() const;
|
||||
//获取按钮纵坐标
|
||||
int getButtonY() const;
|
||||
|
||||
private:
|
||||
//初始化按钮
|
||||
@@ -141,6 +140,11 @@ private:
|
||||
//判断鼠标是否在圆形按钮内
|
||||
bool isMouseInCircle(int mouseX, int mouseY, int x, int y, int radius);
|
||||
//判断鼠标是否在椭圆按钮内
|
||||
bool isMouseInEllipse(int mouseX, int mouseY, int x, int y, int width, int height);
|
||||
bool isMouseInEllipse(int mouseX, int mouseY, int x, int y, int width, int height);
|
||||
|
||||
//检查是否对话框是否可见
|
||||
bool IsVisible() const override { return false; }
|
||||
//获取对话框类型
|
||||
bool model() const override { return false; }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user