initial commit

This commit is contained in:
Ysm-04
2025-09-07 00:22:33 +08:00
parent d62d8a90d6
commit a29b4371fb
16 changed files with 481 additions and 461 deletions

View File

@@ -12,7 +12,7 @@
#pragma once #pragma once
#include "Control.h" #include "Control.h"
class button : public Control class Button : public Control
{ {
std::string text; // 按钮上的文字 std::string text; // 按钮上的文字
@@ -25,27 +25,26 @@ class button : public Control
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; // 按钮形状
int buttonFillMode = BS_SOLID; //按钮填充模式 int buttonFillMode = BS_SOLID; //按钮填充模式
StellarX::fillStyle buttonFillIma = StellarX::fillStyle::BDiagonal; //按钮填充图案 StellarX::FillStyle buttonFillIma = StellarX::FillStyle::BDiagonal; //按钮填充图案
IMAGE* buttonFileIMAGE = nullptr; //按钮填充图像 IMAGE* buttonFileIMAGE = nullptr; //按钮填充图像
int ROUND_RECTANGLEwidth = 20; //构成圆角矩形的圆角的椭圆的宽度。
int ROUND_RECTANGLEheight = 20; //构成圆角矩形的圆角的椭圆的高度。
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模式下的回调函数
StellarX::controlText oldStyle = textStyle; // 按钮文字样式 StellarX::ControlText oldStyle = textStyle; // 按钮文字样式
int oldtext_width = -1; int oldtext_width = -1;
int oldtext_height = -1; int oldtext_height = -1;
int text_width = 0; int text_width = 0;
int text_height = 0; int text_height = 0;
public: public:
StellarX::controlText textStyle; // 按钮文字样式 StellarX::ControlText textStyle; // 按钮文字样式
public: public:
/*************************************************************************/ /*************************************************************************/
@@ -53,18 +52,18 @@ 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); 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, Button(int x, int y, int width, int height, const std::string text,
COLORREF ct, COLORREF cf, StellarX::buttonMode mode = StellarX::buttonMode::NORMAL, COLORREF ct, COLORREF cf, StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL,
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();
/*************************************************************************/ /*************************************************************************/
/********************************Set方法**********************************/ /********************************Set方法**********************************/
@@ -78,7 +77,7 @@ public:
//设置回调函数 //设置回调函数
//************************************ //************************************
// 名称: setOnClickListener | setOnToggleOnListener | setOnToggleOffListener // 名称: setOnClickListener | setOnToggleOnListener | setOnToggleOffListener
// 全名: button::setOnClickListener // 全名: Button::setOnClickListener
// 访问: public // 访问: public
// 返回类型: void // 返回类型: void
// Parameter: const std::function<> & & callback 设置回调函数 传入回调函数名即可,不需要传入(),不需要传入参数,不需要传入返回值 // Parameter: const std::function<> & & callback 设置回调函数 传入回调函数名即可,不需要传入(),不需要传入参数,不需要传入返回值
@@ -90,7 +89,7 @@ public:
//设置TOGGLE模式下取消点击的回调函数 //设置TOGGLE模式下取消点击的回调函数
void setOnToggleOffListener(const std::function<void()>&& callback); void setOnToggleOffListener(const std::function<void()>&& callback);
//设置按钮模式 //设置按钮模式
void setbuttonMode(StellarX::buttonMode mode); void setbuttonMode(StellarX::ButtonMode mode);
//设置圆角矩形椭圆宽度 //设置圆角矩形椭圆宽度
int setROUND_RECTANGLEwidth(int width); int setROUND_RECTANGLEwidth(int width);
//设置圆角矩形椭圆高度 //设置圆角矩形椭圆高度
@@ -98,16 +97,16 @@ public:
//设置按钮填充模式 //设置按钮填充模式
void setFillMode(int mode); void setFillMode(int mode);
//设置按钮填充图案 //设置按钮填充图案
void setFillIma(StellarX::fillStyle ima); void setFillIma(StellarX::FillStyle ima);
//设置按钮填充图像 //设置按钮填充图像
void setFillIma(std::string imaName); void setFillIma(std::string imaName);
//设置按钮边框颜色 //设置按钮边框颜色
void setbuttonBorder(COLORREF Border); void setButtonBorder(COLORREF Border);
//设置按钮文本 //设置按钮文本
void setbuttonText(const char* text); void setButtonText(const char* text);
void setbuttonText(std::string text); void setButtonText(std::string text);
//设置按钮形状 //设置按钮形状
void setbuttonShape(StellarX::controlShape shape); void setButtonShape(StellarX::ControlShape shape);
//判断按钮是否被点击 //判断按钮是否被点击
bool isClicked() const; bool isClicked() const;
@@ -117,28 +116,28 @@ public:
/*************************************************************************/ /*************************************************************************/
//获取按钮文字 //获取按钮文字
std::string getbuttonText() const; std::string getButtonText() const;
const char* getbuttonText_c() const; const char* getButtonText_c() const;
//获取按钮模式 //获取按钮模式
StellarX::buttonMode getbuttonMode() const; StellarX::ButtonMode getButtonMode() const;
//获取按钮形状 //获取按钮形状
StellarX::controlShape getbuttonShape() const; StellarX::ControlShape getButtonShape() const;
//获取按钮填充模式 //获取按钮填充模式
int getFillMode() const; int getFillMode() const;
//获取按钮填充图案 //获取按钮填充图案
StellarX::fillStyle getFillIma() const; StellarX::FillStyle getFillIma() const;
//获取按钮填充图像 //获取按钮填充图像
IMAGE* getFillImaImage() const; IMAGE* getFillImaImage() const;
//获取按钮边框颜色 //获取按钮边框颜色
COLORREF getbuttonBorder() const; COLORREF getButtonBorder() const;
//获取按钮文字颜色 //获取按钮文字颜色
COLORREF getbuttonTxtColor() const; COLORREF getButtonTextColor() const;
//获取按钮文字样式 //获取按钮文字样式
StellarX::controlText getbuttonTextStyle() const; StellarX::ControlText getButtonTextStyle() const;
private: private:
//初始化按钮 //初始化按钮
void initButton(const std::string text, StellarX::buttonMode mode, StellarX::controlShape shape, COLORREF ct, COLORREF cf, COLORREF ch); void initButton(const std::string text, StellarX::ButtonMode mode, StellarX::ControlShape shape, COLORREF ct, COLORREF cf, COLORREF ch);
//判断鼠标是否在圆形按钮内 //判断鼠标是否在圆形按钮内
bool isMouseInCircle(int mouseX, int mouseY, int x, int y, int radius); bool isMouseInCircle(int mouseX, int mouseY, int x, int y, int radius);
//判断鼠标是否在椭圆按钮内 //判断鼠标是否在椭圆按钮内

View File

@@ -6,15 +6,16 @@
// - 将事件传递给子控件 // - 将事件传递给子控件
// - 提供统一的背景和边框 // - 提供统一的背景和边框
// 使用场景: 用于分组相关控件或实现复杂布局 // 使用场景: 用于分组相关控件或实现复杂布局
class Canvas : public Control class Canvas : public Control
{ {
private: private:
std::vector<std::unique_ptr<Control>> controls; std::vector<std::unique_ptr<Control>> controls;
StellarX::controlShape shape = StellarX::controlShape::RECTANGLE; //容器形状 StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE; //容器形状
StellarX::fillMode canvasFillMode = StellarX::fillMode::Solid; //容器填充模式 StellarX::FillMode canvasFillMode = StellarX::FillMode::Solid; //容器填充模式
StellarX::lineStyle canvasLineStyle = StellarX::lineStyle::Solid; //线型 StellarX::LineStyle canvasLineStyle = StellarX::LineStyle::Solid; //线型
int canvaslinewidth = 1; //线宽 int canvaslinewidth = 1; //线宽
COLORREF canvasBorderClor = RGB(0, 0, 0);//边框颜色 COLORREF canvasBorderClor = RGB(0, 0, 0);//边框颜色
@@ -30,17 +31,17 @@ public:
void addControl(std::unique_ptr<Control> control); void addControl(std::unique_ptr<Control> control);
//设置容器样式 //设置容器样式
void setShape(StellarX::controlShape shape); void setShape(StellarX::ControlShape shape);
//设置容器填充模式 //设置容器填充模式
void setcanvasfillMode(StellarX::fillMode mode); void setCanvasfillMode(StellarX::FillMode mode);
//设置容器边框颜色 //设置容器边框颜色
void setBorderColor(COLORREF color); void setBorderColor(COLORREF color);
//设置填充颜色 //设置填充颜色
void setCanvasBkColor(COLORREF color); void setCanvasBkColor(COLORREF color);
//设置线形 //设置线形
void setcanvasLineStyle(StellarX::lineStyle style); void setCanvasLineStyle(StellarX::LineStyle style);
//设置线段宽度 //设置线段宽度
void setlinewidth(int width); void setLinewidth(int width);
}; };

View File

@@ -3,8 +3,8 @@
* \文件: Control.h * \文件: Control.h
* \描述: 控件基类,所有控件都继承自此类。 * \描述: 控件基类,所有控件都继承自此类。
* 提供了控件的一些基本属性和方法。 * 提供了控件的一些基本属性和方法。
* *
* \作者: 我在人间做废物 * \作者: 我在人间做废物
* \日期: September 2025 * \日期: September 2025
*********************************************************************/ *********************************************************************/
#include <vector> #include <vector>
@@ -15,66 +15,49 @@
#include <functional> #include <functional>
#include <initializer_list> #include <initializer_list>
#include "CoreTypes.h" #include "CoreTypes.h"
/**
* @类名称: Control class 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
{ {
protected: 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: public:
Control(const Control&) = delete; // 禁用拷贝构造 Control(const Control&) = delete;
Control& operator=(const Control&) = delete; // 禁用拷贝赋值 Control& operator=(const Control&) = delete;
Control(Control&&) = default; // 允许移动构造 Control(Control&&) = default;
Control& operator=(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){} Control() : x(0), y(0), width(100), height(100) {}
Control(int x, int y, int width, int height)
virtual void draw() = 0; // 绘制控件 : x(x), y(y), width(width), height(height) {
virtual void handleEvent(const ExMessage& msg) = 0; // 处理事件 }
virtual ~Control() {
delete currentLineStyle; currentLineStyle = nullptr; } 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: protected:
//保存当前样式和颜色
void saveStyle(); void saveStyle();
//恢复默认样式和颜色
void restoreStyle(); void restoreStyle();
}; };

View File

@@ -38,7 +38,7 @@ namespace StellarX
* 此枚举类仅支持图案填充模式 * 此枚举类仅支持图案填充模式
* 枚举类在使用时,需要使用::进行调用,还要注意大小写 * 枚举类在使用时,需要使用::进行调用,还要注意大小写
*/ */
enum class fillStyle { enum class FillStyle {
Horizontal = HS_HORIZONTAL, // 水平线 Horizontal = HS_HORIZONTAL, // 水平线
Vertical = HS_VERTICAL, // 垂直线 Vertical = HS_VERTICAL, // 垂直线
FDiagonal = HS_FDIAGONAL, // 反斜线 FDiagonal = HS_FDIAGONAL, // 反斜线
@@ -47,7 +47,7 @@ namespace StellarX
DiagCross = HS_DIAGCROSS // 网格 DiagCross = HS_DIAGCROSS // 网格
}; };
/** /**
* @枚举类名称: fillMode * @枚举类名称: FillMode
* @功能描述: 用来定义控件填充模式的枚举类 * @功能描述: 用来定义控件填充模式的枚举类
* *
* @详细说明: * @详细说明:
@@ -65,12 +65,12 @@ namespace StellarX
* *
* @使用示例: * @使用示例:
* // 示例代码展示如何使用此枚举类 * // 示例代码展示如何使用此枚举类
* fillMode var = fillMode::Solid; * FillMode var = FillMode::Solid;
* *
* @备注: * @备注:
* 枚举类在使用时,需要使用::进行调用,还要注意大小写 * 枚举类在使用时,需要使用::进行调用,还要注意大小写
*/ */
enum class fillMode enum class FillMode
{ {
Solid = BS_SOLID, //固实填充 Solid = BS_SOLID, //固实填充
Null = BS_NULL, // 不填充 Null = BS_NULL, // 不填充
@@ -98,12 +98,12 @@ namespace StellarX
* *
* @使用示例: * @使用示例:
* // 示例代码展示如何使用此枚举类 * // 示例代码展示如何使用此枚举类
* lineStyle var = lineStyle::Solid; * LineStyle var = LineStyle::Solid;
* *
* @备注: * @备注:
* 枚举类在使用时,需要使用::进行调用,还要注意大小写 * 枚举类在使用时,需要使用::进行调用,还要注意大小写
*/ */
enum class lineStyle { enum class LineStyle {
Solid = PS_SOLID, // 实线 Solid = PS_SOLID, // 实线
Dash = PS_DASH, // 虚线 Dash = PS_DASH, // 虚线
Dot = PS_DOT, // 点线 Dot = PS_DOT, // 点线
@@ -113,7 +113,7 @@ namespace StellarX
}; };
/** /**
* @结构体名称: controlText * @结构体名称: ControlText
* @功能描述: 控件字体样式 可以自定义不同的样式 * @功能描述: 控件字体样式 可以自定义不同的样式
* *
* @详细说明: * @详细说明:
@@ -131,10 +131,10 @@ namespace StellarX
* bool bUnderline = false; - 是否下划线 * bool bUnderline = false; - 是否下划线
* bool bStrikeOut = false; - 是否删除线 * bool bStrikeOut = false; - 是否删除线
* bool operator!=(const controlText& text); * bool operator!=(const ControlText& text);
* controlText& operator=(const controlText& text * ControlText& operator=(const ControlText& text
*/ */
struct controlText struct ControlText
{ {
int nHeight = 0; //- 字体高度 int nHeight = 0; //- 字体高度
int nWidth = 0; //- 字体宽度 如果为0则自适应 int nWidth = 0; //- 字体宽度 如果为0则自适应
@@ -147,13 +147,13 @@ namespace StellarX
bool bUnderline = false; //- 是否下划线 bool bUnderline = false; //- 是否下划线
bool bStrikeOut = false; //- 是否删除线 bool bStrikeOut = false; //- 是否删除线
bool operator!=(const controlText& text); bool operator!=(const ControlText& text);
controlText& operator=(const controlText& text); ControlText& operator=(const ControlText& text);
}; };
/** /**
* @枚举名称: controlShape * @枚举名称: ControlShape
* @功能描述: 枚举控件的不同几何样式 * @功能描述: 枚举控件的不同几何样式
* *
* @详细说明: * @详细说明:
@@ -174,12 +174,12 @@ namespace StellarX
* B_ELLIPSE //无边框椭圆 * B_ELLIPSE //无边框椭圆
* *
* @使用示例: * @使用示例:
* controlShape shape = ELLIPSE; * ControlShape shape = ELLIPSE;
* *
* @备注: * @备注:
* 按钮类支持所有形状,部分控件只支持部分形状,具体请参考控件类。 * 按钮类支持所有形状,部分控件只支持部分形状,具体请参考控件类。
*/ */
enum class controlShape enum class ControlShape
{ {
RECTANGLE = 1, //有边框矩形 RECTANGLE = 1, //有边框矩形
B_RECTANGLE, //无边框矩形 B_RECTANGLE, //无边框矩形
@@ -194,7 +194,7 @@ namespace StellarX
B_ELLIPSE //无边框椭圆 B_ELLIPSE //无边框椭圆
}; };
/** /**
* @枚举类名称: textBoxmode * @枚举类名称: TextBoxmode
* @功能描述: 定义了文本框的两种模式 * @功能描述: 定义了文本框的两种模式
* *
* @详细说明: * @详细说明:
@@ -206,19 +206,19 @@ namespace StellarX
* *
* @使用示例: * @使用示例:
* // 示例代码展示如何使用此枚举类 * // 示例代码展示如何使用此枚举类
* StellarX::textBoxmode var = EnumClassName::VALUE1; * StellarX::TextBoxmode var = EnumClassName::VALUE1;
* *
* @备注: * @备注:
* 枚举类的特性、与普通枚举的区别 * 枚举类的特性、与普通枚举的区别
*/ */
enum class textBoxmode enum class TextBoxmode
{ {
INPUT_MODE, // 用户可输入模式 INPUT_MODE, // 用户可输入模式
READONLY_MODE // 只读模式 READONLY_MODE // 只读模式
}; };
/** /**
* @枚举名称: buttonMode * @枚举名称: ButtonMode
* @功能描述: brief * @功能描述: brief
* *
* @详细说明: * @详细说明:
@@ -231,13 +231,18 @@ namespace StellarX
* DISABLED - 禁用模式,按钮不可点击,显示为灰色,文本显示删除线。 * DISABLED - 禁用模式,按钮不可点击,显示为灰色,文本显示删除线。
* *
* @使用示例: * @使用示例:
* button b1(100, 100, 120, 120, "测试按钮", RGB(128, 0, 0), RGB(255, 9, 9)); * Button b1(100, 100, 120, 120, "测试按钮", RGB(128, 0, 0), RGB(255, 9, 9));
* *
*/ */
enum class buttonMode enum class ButtonMode
{ {
NORMAL = 1, NORMAL = 1, //普通模式,点击后触发回调,但不会保持状态。
TOGGLE, TOGGLE, //切换模式,点击后会在选中和未选中之间切换,触发不同的回调函数。
DISABLED DISABLED //禁用模式,按钮不可点击,显示为灰色,文本显示删除线。
};
struct RouRectangle
{
int ROUND_RECTANGLEwidth = 20; //构成圆角矩形的圆角的椭圆的宽度。
int ROUND_RECTANGLEheight = 20; //构成圆角矩形的圆角的椭圆的高度。
}; };
}; };

View File

@@ -10,7 +10,7 @@
* 内部包含顺序经过精心设计,确保所有依赖关系正确解析。 * 内部包含顺序经过精心设计,确保所有依赖关系正确解析。
* *
* @作者: 我在人间做废物 * @作者: 我在人间做废物
* @邮箱: [您的邮箱或联系方式] * @邮箱: [3150131407@qq.com][]
* @仓库: https://github.com/yourusername/stellarx * @仓库: https://github.com/yourusername/stellarx
* *
* @许可证: MIT License * @许可证: MIT License
@@ -30,8 +30,8 @@
#include "CoreTypes.h" #include "CoreTypes.h"
#include "Control.h" #include "Control.h"
#include"Button.h" #include"Button.h"
#include"window.h" #include"Window.h"
#include"label.h" #include"Label.h"
#include"textBox.h" #include"TextBox.h"
#include"Canvas.h" #include"Canvas.h"
#include"table.h" #include"Table.h"

View File

@@ -6,7 +6,7 @@
// - 不支持用户交互(无事件处理) // - 不支持用户交互(无事件处理)
// - 自动适应文本内容大小 // - 自动适应文本内容大小
class label : public Control class Label : public Control
{ {
std::string text; //标签文本 std::string text; //标签文本
COLORREF textColor; //标签文本颜色 COLORREF textColor; //标签文本颜色
@@ -16,18 +16,18 @@ class label : public Control
//标签事件处理(标签无事件)不实现具体代码 //标签事件处理(标签无事件)不实现具体代码
void handleEvent(const ExMessage& msg) override {} void handleEvent(const ExMessage& msg) override {}
public: 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 setTxtdisap(bool key); void setTextdisap(bool key);
//设置标签文本颜色 //设置标签文本颜色
void setTxtColor(COLORREF color); void setTextColor(COLORREF color);
//设置标签背景颜色 //设置标签背景颜色
void setTxtBkColor(COLORREF color); void setTextBkColor(COLORREF color);
//设置标签文本 //设置标签文本
void setText(std::string text); void setText(std::string text);

View File

@@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* @文件: table.h * @文件: Table.h
* @摘要: 高级表格控件,支持分页显示 * @摘要: 高级表格控件,支持分页显示
* @描述: * @描述:
* 提供完整的数据表格功能,包括表头、数据行、分页和导航按钮。 * 提供完整的数据表格功能,包括表头、数据行、分页和导航按钮。
@@ -19,9 +19,9 @@
#pragma once #pragma once
#include "Control.h" #include "Control.h"
#include "Button.h" #include "Button.h"
#include "label.h" #include "Label.h"
class table :public Control class Table :public Control
{ {
private: private:
std::vector<std::vector<std::string>> data; // 表格数据 std::vector<std::vector<std::string>> data; // 表格数据
@@ -44,9 +44,9 @@ private:
bool isNeedDrawHeaders = true; // 是否需要绘制表头 bool isNeedDrawHeaders = true; // 是否需要绘制表头
bool isNeedCellSize = true; // 是否需要计算单元格尺寸 bool isNeedCellSize = true; // 是否需要计算单元格尺寸
button* prevButton = nullptr; // 上一页按钮 Button* prevButton = nullptr; // 上一页按钮
button* nextButton = nullptr; // 下一页按钮 Button* nextButton = nullptr; // 下一页按钮
label* pageNum = nullptr; //页码文本 Label* pageNum = nullptr; //页码文本
int dX = x, dY = y; // 单元格的开始坐标 int dX = x, dY = y; // 单元格的开始坐标
int uX = x, uY = y; // 单元格的结束坐标 int uX = x, uY = y; // 单元格的结束坐标
@@ -54,8 +54,8 @@ private:
int pX = 0; //标签左上角坐标 int pX = 0; //标签左上角坐标
int pY = 0; //标签左上角坐标 int pY = 0; //标签左上角坐标
StellarX::fillMode tableFillMode = StellarX::fillMode::Solid; //填充模式 StellarX::FillMode tableFillMode = StellarX::FillMode::Solid; //填充模式
StellarX::lineStyle tableLineStyle = StellarX::lineStyle::Solid; // 线型 StellarX::LineStyle tableLineStyle = StellarX::LineStyle::Solid; // 线型
COLORREF tableBorderClor = RGB(0, 0, 0); // 表格边框颜色 COLORREF tableBorderClor = RGB(0, 0, 0); // 表格边框颜色
COLORREF tableBkClor = RGB(255, 255, 255); // 表格背景颜色 COLORREF tableBkClor = RGB(255, 255, 255); // 表格背景颜色
@@ -68,11 +68,11 @@ private:
void drawPageNum(); //绘制页码信息 void drawPageNum(); //绘制页码信息
void drawButton(); //绘制翻页按钮 void drawButton(); //绘制翻页按钮
public: public:
StellarX::controlText textStyle; // 文本样式 StellarX::ControlText textStyle; // 文本样式
public: public:
table(int x, int y); Table(int x, int y);
~table(); ~Table();
// 绘制表格 // 绘制表格
void draw() override; void draw() override;
@@ -91,15 +91,15 @@ public:
//设置是否显示翻页按钮 //设置是否显示翻页按钮
void showPageButton(bool isShow); void showPageButton(bool isShow);
//设置表格边框颜色 //设置表格边框颜色
void settableBorder(COLORREF color); void setTableBorder(COLORREF color);
//设置表格背景颜色 //设置表格背景颜色
void settableBk(COLORREF color); void setTableBk(COLORREF color);
//设置填充模式 //设置填充模式
void settableFillMode(StellarX::fillMode mode); void setTableFillMode(StellarX::FillMode mode);
//设置线型 //设置线型
void settableLineStyle(StellarX::lineStyle style); void setTableLineStyle(StellarX::LineStyle style);
//设置边框宽度 //设置边框宽度
void settableBorderWidth(int width); void setTableBorderWidth(int width);
//************************** 获取属性 *****************************/ //************************** 获取属性 *****************************/
@@ -112,19 +112,19 @@ public:
//获取是否显示翻页按钮 //获取是否显示翻页按钮
bool getShowPageButton() const; bool getShowPageButton() const;
//获取表格边框颜色 //获取表格边框颜色
COLORREF gettableBorder() const; COLORREF getTableBorder() const;
//获取表格背景颜色 //获取表格背景颜色
COLORREF gettableBk() const; COLORREF getTableBk() const;
//获取填充模式 //获取填充模式
StellarX::fillMode gettableFillMode() const; StellarX::FillMode getTableFillMode() const;
//获取线型 //获取线型
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;
}; };

View File

@@ -6,11 +6,12 @@
// - 在INPUT_MODE下点击会调用EasyX的InputBox // - 在INPUT_MODE下点击会调用EasyX的InputBox
// - 在READONLY_MODE下点击会显示信息对话框 // - 在READONLY_MODE下点击会显示信息对话框
// - 最大字符长度受maxCharLen限制 // - 最大字符长度受maxCharLen限制
class textBox : public Control
class TextBox : public Control
{ {
std::string text; //文本 std::string text; //文本
StellarX::textBoxmode mode; //模式 StellarX::TextBoxmode mode; //模式
StellarX::controlShape shape; //形状 StellarX::ControlShape shape; //形状
bool dirty = true; //是否重绘 bool dirty = true; //是否重绘
bool click = false; //是否点击 bool click = false; //是否点击
int maxCharLen = 10;//最大字符长度 int maxCharLen = 10;//最大字符长度
@@ -18,25 +19,25 @@ class textBox : public Control
COLORREF textBoxBorderClor = RGB(0,0,0); //边框颜色 COLORREF textBoxBorderClor = RGB(0,0,0); //边框颜色
public: public:
StellarX::controlText textStyle; //文本样式 StellarX::ControlText textStyle; //文本样式
textBox(int x, int y, int width, int height, std::string text = "", StellarX::textBoxmode mode = StellarX::textBoxmode::INPUT_MODE, StellarX::controlShape shape = StellarX::controlShape::RECTANGLE); TextBox(int x, int y, int width, int height, std::string text = "", StellarX::TextBoxmode mode = StellarX::TextBoxmode::INPUT_MODE, StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE);
void draw() override; void draw() override;
void handleEvent(const ExMessage& msg) override; void handleEvent(const ExMessage& msg) override;
//设置模式 //设置模式
void setMode(StellarX::textBoxmode mode); void setMode(StellarX::TextBoxmode mode);
//设置可输入最大字符长度 //设置可输入最大字符长度
void setmaxCharLen(int len); void setMaxCharLen(int len);
//设置形状 //设置形状
void settextBoxshape(StellarX::controlShape shape); void setTextBoxshape(StellarX::ControlShape shape);
//设置边框颜色 //设置边框颜色
void settextBoxBorder(COLORREF color); void setTextBoxBorder(COLORREF color);
//设置背景颜色 //设置背景颜色
void settextBoxBk(COLORREF color); void setTextBoxBk(COLORREF color);
//获取文本 //获取文本
std::string gettext(); std::string getText() const;
}; };

View File

@@ -6,7 +6,7 @@
//#define EX_NOMINIMIZE 3 - 禁用绘图窗口的最小化按钮。 //#define EX_NOMINIMIZE 3 - 禁用绘图窗口的最小化按钮。
//#define EX_SHOWCONSOLE 4 - 显示控制台窗口。 //#define EX_SHOWCONSOLE 4 - 显示控制台窗口。
/******************************************************************************* /*******************************************************************************
* @类: window * @类: Window
* @摘要: 应用程序主窗口类 * @摘要: 应用程序主窗口类
* @描述: * @描述:
* 负责创建和管理应用程序的主窗口,是所有控件的根容器。 * 负责创建和管理应用程序的主窗口,是所有控件的根容器。
@@ -17,7 +17,7 @@
* - 使用 BeginBatchDraw()/EndBatchDraw() 实现双缓冲 * - 使用 BeginBatchDraw()/EndBatchDraw() 实现双缓冲
* - 使用 getmessage() 处理消息循环 * - 使用 getmessage() 处理消息循环
******************************************************************************/ ******************************************************************************/
class window class Window
{ {
int width; //窗口宽度 int width; //窗口宽度
int height; //窗口高度 int height; //窗口高度
@@ -29,10 +29,10 @@ class window
std::vector<std::unique_ptr<Control>> controls; //控件管理 std::vector<std::unique_ptr<Control>> controls; //控件管理
public: public:
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(); void draw();
void draw(std::string pImgFile); void draw(std::string pImgFile);

View File

@@ -1,24 +1,24 @@
#include "button.h" #include "Button.h"
button::button(int x, int y, int width, int height, const std::string text, StellarX::buttonMode mode, StellarX::controlShape shape) Button::Button(int x, int y, int width, int height, const std::string text, StellarX::ButtonMode mode, StellarX::ControlShape shape)
: Control(x, y, width, height) : Control(x, y, width, height)
{ {
initButton(text, mode, shape, RGB(202, 255, 255), RGB(171, 196, 220), RGB(255, 255, 0)); initButton(text, mode, shape, RGB(202, 255, 255), RGB(171, 196, 220), RGB(255, 255, 0));
} }
button::button(int x, int y, int width, int height, const std::string text, COLORREF ct, COLORREF cf, StellarX::buttonMode mode, StellarX::controlShape shape) Button::Button(int x, int y, int width, int height, const std::string text, COLORREF ct, COLORREF cf, StellarX::ButtonMode mode, StellarX::ControlShape shape)
: Control(x, y, width, height) : Control(x, y, width, height)
{ {
initButton(text, mode, shape, ct, cf, RGB(255, 255, 0)); initButton(text, mode, shape, ct, cf, RGB(255, 255, 0));
} }
button::button(int x, int y, int width, int height, const std::string text, COLORREF ct, COLORREF cf, COLORREF ch, StellarX::buttonMode mode, StellarX::controlShape shape) Button::Button(int x, int y, int width, int height, const std::string text, COLORREF ct, COLORREF cf, COLORREF ch, StellarX::ButtonMode mode, StellarX::ControlShape shape)
: Control(x, y, width, height) : Control(x, y, width, height)
{ {
initButton(text, mode, shape, ct, cf, ch); initButton(text, mode, shape, ct, cf, ch);
} }
void button::initButton(const std::string text, StellarX::buttonMode mode, StellarX::controlShape shape, COLORREF ct, COLORREF cf, COLORREF ch) void Button::initButton(const std::string text, StellarX::ButtonMode mode, StellarX::ControlShape shape, COLORREF ct, COLORREF cf, COLORREF ch)
{ {
this->text = text; this->text = text;
this->mode = mode; this->mode = mode;
@@ -31,226 +31,257 @@ void button::initButton(const std::string text, StellarX::buttonMode mode, Stell
} }
button::~button() Button::~Button()
{ {
if (buttonFileIMAGE) if (buttonFileIMAGE)
delete buttonFileIMAGE; delete buttonFileIMAGE;
buttonFileIMAGE = nullptr; buttonFileIMAGE = nullptr;
} }
void button::draw() void Button::draw()
{ {
if (dirty) if (dirty)
{ {
//保存当前样式和颜色 //保存当前样式和颜色
saveStyle(); saveStyle();
if (StellarX::buttonMode::DISABLED == mode) //设置禁用按钮色 if (StellarX::ButtonMode::DISABLED == mode) //设置禁用按钮色
{ {
setfillcolor(RGB(96, 96, 96)); setfillcolor(RGB(96, 96, 96));
textStyle.bStrikeOut = 1; textStyle.bStrikeOut = 1;
} }
else else
{ {
if (hover) // 修改这里:确保点击状态的颜色正确显示
setfillcolor(buttonHoverColor); // 点击状态优先级最高,然后是悬停状态,最后是默认状态
else if (click)
setfillcolor(click ? buttonTrueColor : buttonFalseColor); setfillcolor(buttonTrueColor);
} else if (hover)
setfillcolor(buttonHoverColor);
else
//设置字体背景色透明 setfillcolor(buttonFalseColor);
setbkmode(TRANSPARENT);
//边框颜色
setlinecolor(buttonBorderColor);
if(this->textStyle !=oldStyle)
{
//设置字体颜色
settextcolor(textStyle.color);
//设置字体样式
settextstyle(textStyle.nHeight, textStyle.nWidth, textStyle.lpszFace,
textStyle.nEscapement, textStyle.nOrientation, textStyle.nWeight,
textStyle.bItalic, textStyle.bUnderline, textStyle.bStrikeOut); //设置字体样式
}
//设置按钮填充模式
setfillstyle(buttonFillMode, (int)buttonFillIma, buttonFileIMAGE);
//获取字符串像素高度和宽度
if((this->oldtext_width!= this->text_width|| this->oldtext_height!= this->text_height)
||(-1 == oldtext_width &&oldtext_height == -1))
{
this->oldtext_width = this->text_width = textwidth(LPCTSTR(this->text.c_str()));;
this->oldtext_height = this->text_height = textheight(LPCTSTR(this->text.c_str()));;
} }
//设置字体背景色透明
//根据按钮形状绘制 setbkmode(TRANSPARENT);
switch (shape) //边框颜色
{ setlinecolor(buttonBorderColor);
case StellarX::controlShape::RECTANGLE: if (this->textStyle != oldStyle)
fillrectangle(x, y, width, height);//有边框填充矩形 {
outtextxy((x + (width - x - text_width) / 2), (y + (height - y - text_height) / 2), LPCTSTR(text.c_str())); //设置字体颜色
break; settextcolor(textStyle.color);
case StellarX::controlShape::B_RECTANGLE:
solidrectangle(x, y, width, height);//无边框填充矩形
outtextxy((x + (width - x - text_width) / 2), (y + (height - y - text_height) / 2), LPCTSTR(text.c_str()));
break;
case StellarX::controlShape::ROUND_RECTANGLE:
fillroundrect(x, y, width, height, ROUND_RECTANGLEwidth, ROUND_RECTANGLEheight);//有边框填充圆角矩形
outtextxy((x + (width - x - text_width) / 2), (y + (height - y - text_height) / 2), LPCTSTR(text.c_str()));
break;
case StellarX::controlShape::B_ROUND_RECTANGLE:
solidroundrect(x, y, width, height, ROUND_RECTANGLEwidth, ROUND_RECTANGLEheight);//无边框填充圆角矩形
outtextxy((x + (width - x - text_width) / 2), (y + (height - y - text_height) / 2), LPCTSTR(text.c_str()));
break;
case StellarX::controlShape::CIRCLE:
fillcircle(x, y, (width - x) / 2);//有边框填充圆形
outtextxy(x - text_width / 2, y - text_height / 2, LPCTSTR(text.c_str()));
break;
case StellarX::controlShape::B_CIRCLE:
solidcircle(x, y, (width - x) / 2);//无边框填充圆形
outtextxy(x - text_width / 2, y - text_height / 2, LPCTSTR(text.c_str()));
break;
case StellarX::controlShape::ELLIPSE:
fillellipse(x, y, width, height);//有边框填充椭圆
outtextxy((x + (width - x - text_width) / 2), (y + (height - y - text_height) / 2), LPCTSTR(text.c_str()));
break;
case StellarX::controlShape::B_ELLIPSE:
solidellipse(x, y, width, height);//无边框填充椭圆
outtextxy((x + (width - x - text_width) / 2), (y + (height - y - text_height) / 2), LPCTSTR(text.c_str()));
break;
}
//设置字体样式
settextstyle(textStyle.nHeight, textStyle.nWidth, textStyle.lpszFace,
textStyle.nEscapement, textStyle.nOrientation, textStyle.nWeight,
textStyle.bItalic, textStyle.bUnderline, textStyle.bStrikeOut); //设置字体样式
}
//设置按钮填充模式
setfillstyle(buttonFillMode, (int)buttonFillIma, buttonFileIMAGE);
restoreStyle();//恢复默认字体样式和颜色 //获取字符串像素高度和宽度
if ((this->oldtext_width != this->text_width || this->oldtext_height != this->text_height)
|| (-1 == oldtext_width && oldtext_height == -1))
{
this->oldtext_width = this->text_width = textwidth(LPCTSTR(this->text.c_str()));
this->oldtext_height = this->text_height = textheight(LPCTSTR(this->text.c_str()));
}
dirty = false; //标记按钮不需要重绘
} //根据按钮形状绘制
switch (shape)
{
case StellarX::ControlShape::RECTANGLE:
fillrectangle(x, y, x + width, y + height);//有边框填充矩形
outtextxy((x + (width - text_width) / 2), (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
break;
case StellarX::ControlShape::B_RECTANGLE:
solidrectangle(x, y, x + width, y + height);//无边框填充矩形
outtextxy((x + (width - text_width) / 2), (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
break;
case StellarX::ControlShape::ROUND_RECTANGLE:
fillroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//有边框填充圆角矩形
outtextxy((x + (width - text_width) / 2), (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
break;
case StellarX::ControlShape::B_ROUND_RECTANGLE:
solidroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//无边框填充圆角矩形
outtextxy((x + (width - text_width) / 2), (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
break;
case StellarX::ControlShape::CIRCLE:
fillcircle(x + width / 2, y + height / 2, min(width, height) / 2);//有边框填充圆形
outtextxy(x + width / 2 - text_width / 2, y + height / 2 - text_height / 2, LPCTSTR(text.c_str()));
break;
case StellarX::ControlShape::B_CIRCLE:
solidcircle(x + width / 2, y + height / 2, min(width, height) / 2);//无边框填充圆形
outtextxy(x + width / 2 - text_width / 2, y + height / 2 - text_height / 2, LPCTSTR(text.c_str()));
break;
case StellarX::ControlShape::ELLIPSE:
fillellipse(x, y, x + width, y + height);//有边框填充椭圆
outtextxy((x + (width - text_width) / 2), (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
break;
case StellarX::ControlShape::B_ELLIPSE:
solidellipse(x, y, x + width, y + height);//无边框填充椭圆
outtextxy((x + (width - text_width) / 2), (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
break;
}
restoreStyle();//恢复默认字体样式和颜色
dirty = false; //标记按钮不需要重绘
}
} }
// 处理鼠标事件,检测点击和悬停状态 // 处理鼠标事件,检测点击和悬停状态
// 根据按钮模式和形状进行不同的处理 // 根据按钮模式和形状进行不同的处理
void button::handleEvent(const ExMessage& msg) void Button::handleEvent(const ExMessage& msg)
{ {
bool oldHover = hover; bool oldHover = hover;
bool oldClick = click; bool oldClick = click;
// 检测悬停状态(根据不同形状)
switch (shape)
{
case StellarX::controlShape::RECTANGLE:
case StellarX::controlShape::B_RECTANGLE:
case StellarX::controlShape::ROUND_RECTANGLE:
case StellarX::controlShape::B_ROUND_RECTANGLE:
hover = (msg.x > x && msg.x < width && msg.y > y && msg.y < height);//判断鼠标是否在矩形按钮内
break;
case StellarX::controlShape::CIRCLE:
case StellarX::controlShape::B_CIRCLE:
hover = isMouseInCircle(msg.x, msg.y, x, y, (width - x) / 2);//判断鼠标是否在圆形按钮内
break;
case StellarX::controlShape::ELLIPSE:
case StellarX::controlShape::B_ELLIPSE:
hover = isMouseInEllipse(msg.x, msg.y, x, y, width, height);//判断鼠标是否在椭圆按钮内
break;
} // 检测悬停状态(根据不同形状)
switch (shape)
{
case StellarX::ControlShape::RECTANGLE:
case StellarX::ControlShape::B_RECTANGLE:
case StellarX::ControlShape::ROUND_RECTANGLE:
case StellarX::ControlShape::B_ROUND_RECTANGLE:
hover = (msg.x > x && msg.x < (x + width) && msg.y > y && msg.y < (y + height));
break;
case StellarX::ControlShape::CIRCLE:
case StellarX::ControlShape::B_CIRCLE:
hover = isMouseInCircle(msg.x, msg.y, x + width / 2, y + height / 2, min(width, height) / 2);
break;
case StellarX::ControlShape::ELLIPSE:
case StellarX::ControlShape::B_ELLIPSE:
hover = isMouseInEllipse(msg.x, msg.y, x, y, x + width, y + height);
break;
}
if (hover && msg.message == WM_LBUTTONUP) // 处理鼠标点击事件
{ if (msg.message == WM_LBUTTONDOWN && hover && mode != StellarX::ButtonMode::DISABLED)
if (mode == StellarX::buttonMode::NORMAL) // 普通按钮 NORMAL {
{ if (mode == StellarX::ButtonMode::NORMAL)
click = true; {
if (onClickCallback) onClickCallback(); click = true;
// 刷新消息队列,避免重复处理 dirty = true;
flushmessage(EX_MOUSE | EX_KEY); }
} else if (mode == StellarX::ButtonMode::TOGGLE)
else if (mode == StellarX::buttonMode::TOGGLE) // 切换状态 Toggle {
{ // TOGGLE模式在鼠标释放时处理
click = !click; }
if (click && onToggleOnCallback) onToggleOnCallback(); }
else if (!click && onToggleOffCallback) onToggleOffCallback(); // 处理鼠标释放事件
flushmessage(EX_MOUSE | EX_KEY); else if (msg.message == WM_LBUTTONUP && hover && mode != StellarX::ButtonMode::DISABLED)
} {
else if (mode == StellarX::buttonMode::DISABLED) // 禁用状态 Disabled if (mode == StellarX::ButtonMode::NORMAL && click)
flushmessage(EX_MOUSE | EX_KEY); {
} if (onClickCallback) onClickCallback();
if (hover != oldHover || click != oldClick) click = false;
dirty = true; // 标记按钮需要重绘 dirty = true;
// 使用新的flushmessage函数刷新消息队列:cite[2]:cite[3]
if (dirty) flushmessage(EX_MOUSE | EX_KEY);
draw(); }
else if (mode == StellarX::ButtonMode::TOGGLE)
{
click = !click;
if (click && onToggleOnCallback) onToggleOnCallback();
else if (!click && onToggleOffCallback) onToggleOffCallback();
dirty = true;
// 使用新的flushmessage函数刷新消息队列:cite[2]:cite[3]
flushmessage(EX_MOUSE | EX_KEY);
}
}
// 处理鼠标移出区域的情况
else if (msg.message == WM_MOUSEMOVE)
{
if (!hover && mode == StellarX::ButtonMode::NORMAL && click)
{
click = false;
dirty = true;
}
else if (hover != oldHover)
{
dirty = true;
}
}
if (StellarX::buttonMode::NORMAL == mode) // 如果状态发生变化,标记需要重绘
if (isClicked()) if (hover != oldHover || click != oldClick)
click = false; {
dirty = true;
}
// 如果需要重绘,立即执行
if (dirty)
{
draw();
}
} }
void button::setOnClickListener(const std::function<void()>&& callback) void Button::setOnClickListener(const std::function<void()>&& callback)
{ {
this->onClickCallback = callback; this->onClickCallback = callback;
} }
void button::setOnToggleOnListener(const std::function<void()>&& callback) void Button::setOnToggleOnListener(const std::function<void()>&& callback)
{ {
this->onToggleOnCallback = callback; this->onToggleOnCallback = callback;
} }
void button::setOnToggleOffListener(const std::function<void()>&& callback) void Button::setOnToggleOffListener(const std::function<void()>&& callback)
{ {
this->onToggleOffCallback = callback; this->onToggleOffCallback = callback;
} }
void button::setbuttonMode(StellarX::buttonMode mode) void Button::setbuttonMode(StellarX::ButtonMode mode)
{ {
//取值范围参考 buttMode的枚举注释 //取值范围参考 buttMode的枚举注释
this->mode = mode; this->mode = mode;
} }
int button::setROUND_RECTANGLEwidth(int width) int Button::setROUND_RECTANGLEwidth(int width)
{ {
return ROUND_RECTANGLEwidth = width; return rouRectangleSize.ROUND_RECTANGLEwidth = width;
} }
int button::setROUND_RECTANGLEheight(int height) int Button::setROUND_RECTANGLEheight(int height)
{ {
return ROUND_RECTANGLEheight = height; return rouRectangleSize.ROUND_RECTANGLEheight = height;
} }
bool button::isClicked() const bool Button::isClicked() const
{ {
return this->click; return this->click;
} }
void button::setFillMode(int mode) void Button::setFillMode(int mode)
{ {
buttonFillMode = mode; buttonFillMode = mode;
} }
void button::setFillIma(StellarX::fillStyle ima) void Button::setFillIma(StellarX::FillStyle ima)
{ {
buttonFillIma = ima; buttonFillIma = ima;
} }
void button::setFillIma(std::string imaNAme) void Button::setFillIma(std::string imaNAme)
{ {
buttonFileIMAGE = new IMAGE; buttonFileIMAGE = new IMAGE;
loadimage(buttonFileIMAGE, imaNAme.c_str(),width-x,height-y); loadimage(buttonFileIMAGE, imaNAme.c_str(),width-x,height-y);
} }
void button::setbuttonBorder(COLORREF Border) void Button::setButtonBorder(COLORREF Border)
{ {
buttonBorderColor = Border; buttonBorderColor = Border;
} }
void button::setbuttonText(const char* text) void Button::setButtonText(const char* text)
{ {
this->text = std::string(text); this->text = std::string(text);
this->text_width = textwidth(LPCTSTR(this->text.c_str())); this->text_width = textwidth(LPCTSTR(this->text.c_str()));
this->text_height = textheight(LPCTSTR(this->text.c_str())); this->text_height = textheight(LPCTSTR(this->text.c_str()));
} }
void button::setbuttonText(std::string text) void Button::setButtonText(std::string text)
{ {
this->text = text; this->text = text;
this->text_width = textwidth(LPCTSTR(this->text.c_str())); this->text_width = textwidth(LPCTSTR(this->text.c_str()));
@@ -258,64 +289,64 @@ void button::setbuttonText(std::string text)
this->dirty = true; // 标记需要重绘 this->dirty = true; // 标记需要重绘
} }
void button::setbuttonShape(StellarX::controlShape shape) void Button::setButtonShape(StellarX::ControlShape shape)
{ {
this->shape = shape; this->shape = shape;
} }
std::string button::getbuttonText() const std::string Button::getButtonText() const
{ {
return this->text; return this->text;
} }
const char* button::getbuttonText_c() const const char* Button::getButtonText_c() const
{ {
return this->text.c_str(); return this->text.c_str();
} }
StellarX::buttonMode button::getbuttonMode() const StellarX::ButtonMode Button::getButtonMode() const
{ {
return this->mode; return this->mode;
} }
StellarX::controlShape button::getbuttonShape() const StellarX::ControlShape Button::getButtonShape() const
{ {
return this->shape; return this->shape;
} }
int button::getFillMode() const int Button::getFillMode() const
{ {
return this->buttonFillMode; return this->buttonFillMode;
} }
StellarX::fillStyle button::getFillIma() const StellarX::FillStyle Button::getFillIma() const
{ {
return this->buttonFillIma; return this->buttonFillIma;
} }
IMAGE* button::getFillImaImage() const IMAGE* Button::getFillImaImage() const
{ {
return this->buttonFileIMAGE; return this->buttonFileIMAGE;
} }
COLORREF button::getbuttonBorder() const COLORREF Button::getButtonBorder() const
{ {
return this->buttonBorderColor; return this->buttonBorderColor;
} }
COLORREF button::getbuttonTxtColor() const COLORREF Button::getButtonTextColor() const
{ {
return this->textStyle.color; return this->textStyle.color;
} }
StellarX::controlText button::getbuttonTextStyle() const StellarX::ControlText Button::getButtonTextStyle() const
{ {
return this->textStyle; return this->textStyle;
} }
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));
if (dis <= radius) if (dis <= radius)
@@ -324,7 +355,7 @@ bool button::isMouseInCircle(int mouseX, int mouseY, int x, int y, int radius)
return false; return false;
} }
bool button::isMouseInEllipse(int mouseX, int mouseY, int x, int y, int width, int height) bool Button::isMouseInEllipse(int mouseX, int mouseY, int x, int y, int width, int height)
{ {
int centerX = (x + width) / 2; int centerX = (x + width) / 2;
int centerY = (y + height) / 2; int centerY = (y + height) / 2;

View File

@@ -15,17 +15,17 @@ void Canvas::draw()
//根据画布形状绘制 //根据画布形状绘制
switch (shape) switch (shape)
{ {
case StellarX::controlShape::RECTANGLE: case StellarX::ControlShape::RECTANGLE:
fillrectangle(x, y, width, height);//有边框填充矩形 fillrectangle(x,y,x+width,y+height);//有边框填充矩形
break; break;
case StellarX::controlShape::B_RECTANGLE: case StellarX::ControlShape::B_RECTANGLE:
solidrectangle(x, y, width, height);//无边框填充矩形 solidrectangle(x, y, x + width, y + height);//无边框填充矩形
break; break;
case StellarX::controlShape::ROUND_RECTANGLE: case StellarX::ControlShape::ROUND_RECTANGLE:
fillroundrect(x, y, width, height, 20, 20);//有边框填充圆角矩形 fillroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//有边框填充圆角矩形
break; break;
case StellarX::controlShape::B_ROUND_RECTANGLE: case StellarX::ControlShape::B_ROUND_RECTANGLE:
solidroundrect(x, y, width, height, 20, 20);//无边框填充圆角矩形 solidroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//无边框填充圆角矩形
break; break;
} }
// 绘制所有子控件 // 绘制所有子控件
@@ -48,26 +48,26 @@ void Canvas::addControl(std::unique_ptr<Control> control)
controls.push_back(std::move(control)); controls.push_back(std::move(control));
} }
void Canvas::setShape(StellarX::controlShape shape) void Canvas::setShape(StellarX::ControlShape shape)
{ {
switch (shape) switch (shape)
{ {
case StellarX::controlShape::RECTANGLE: case StellarX::ControlShape::RECTANGLE:
case StellarX::controlShape::B_RECTANGLE: case StellarX::ControlShape::B_RECTANGLE:
case StellarX::controlShape::ROUND_RECTANGLE: case StellarX::ControlShape::ROUND_RECTANGLE:
case StellarX::controlShape::B_ROUND_RECTANGLE: case StellarX::ControlShape::B_ROUND_RECTANGLE:
this->shape = shape; this->shape = shape;
break; break;
case StellarX::controlShape::CIRCLE: case StellarX::ControlShape::CIRCLE:
case StellarX::controlShape::B_CIRCLE: case StellarX::ControlShape::B_CIRCLE:
case StellarX::controlShape::ELLIPSE: case StellarX::ControlShape::ELLIPSE:
case StellarX::controlShape::B_ELLIPSE: case StellarX::ControlShape::B_ELLIPSE:
this->shape = StellarX::controlShape::RECTANGLE; this->shape = StellarX::ControlShape::RECTANGLE;
break; break;
} }
} }
void Canvas::setcanvasfillMode(StellarX::fillMode mode) void Canvas::setCanvasfillMode(StellarX::FillMode mode)
{ {
this->canvasFillMode = mode; this->canvasFillMode = mode;
} }
@@ -82,13 +82,13 @@ void Canvas::setCanvasBkColor(COLORREF color)
this->canvasBkClor = color; this->canvasBkClor = color;
} }
void Canvas::setcanvasLineStyle(StellarX::lineStyle style) void Canvas::setCanvasLineStyle(StellarX::LineStyle style)
{ {
this->canvasLineStyle = style; this->canvasLineStyle = style;
} }
void Canvas::setlinewidth(int width) void Canvas::setLinewidth(int width)
{ {
this->canvaslinewidth = width; this->canvaslinewidth = width;
} }

View File

@@ -1,6 +1,6 @@
#include "Control.h" #include "Control.h"
StellarX::controlText& StellarX::controlText::operator=(const controlText& text) StellarX::ControlText& StellarX::ControlText::operator=(const ControlText& text)
{ {
{ {
nHeight = text.nHeight; nHeight = text.nHeight;
@@ -17,7 +17,7 @@ StellarX::controlText& StellarX::controlText::operator=(const controlText& text)
} }
} }
bool StellarX::controlText::operator!=(const controlText& text) bool StellarX::ControlText::operator!=(const ControlText& text)
{ {
if(nHeight != text.nHeight) if(nHeight != text.nHeight)
return true; return true;

View File

@@ -1,6 +1,6 @@
#include "label.h" #include "Label.h"
label::label() Label::Label()
:Control(0, 0, 0, 0) :Control(0, 0, 0, 0)
{ {
this->text = "默认标签"; this->text = "默认标签";
@@ -8,7 +8,7 @@ label::label()
textBkColor = RGB(255, 255, 255);; //默认白色背景 textBkColor = RGB(255, 255, 255);; //默认白色背景
} }
label::label(int x, int y, std::string text, COLORREF textcolor, COLORREF bkColor) Label::Label(int x, int y, std::string text, COLORREF textcolor, COLORREF bkColor)
:Control(x, y, 0, 0) :Control(x, y, 0, 0)
{ {
this->text = text; this->text = text;
@@ -16,7 +16,7 @@ label::label(int x, int y, std::string text, COLORREF textcolor, COLORREF bkColo
textBkColor = bkColor; //默认白色背景 textBkColor = bkColor; //默认白色背景
} }
void label::draw() void Label::draw()
{ {
saveStyle(); saveStyle();
if (textBkDisap) if (textBkDisap)
@@ -34,22 +34,22 @@ void label::draw()
restoreStyle(); restoreStyle();
} }
void label::setTxtdisap(bool key) void Label::setTextdisap(bool key)
{ {
textBkDisap = key; textBkDisap = key;
} }
void label::setTxtColor(COLORREF color) void Label::setTextColor(COLORREF color)
{ {
textColor = color; textColor = color;
} }
void label::setTxtBkColor(COLORREF color) void Label::setTextBkColor(COLORREF color)
{ {
textBkColor = color; textBkColor = color;
} }
void label::setText(std::string text) void Label::setText(std::string text)
{ {
this->text = text; this->text = text;
} }

View File

@@ -1,7 +1,7 @@
#include "table.h" #include "Table.h"
// 绘制表格的当前页 // 绘制表格的当前页
// 使用双循环绘制行和列,考虑分页偏移 // 使用双循环绘制行和列,考虑分页偏移
void table::drawTable() void Table::drawTable()
{ {
dX = x; dX = x;
dY = uY; dY = uY;
@@ -24,7 +24,7 @@ void table::drawTable()
uY = y + lineHeights.at(0) + 10; uY = y + lineHeights.at(0) + 10;
} }
void table::drawHeader() void Table::drawHeader()
{ {
uY = dY + lineHeights.at(0) + 10; uY = dY + lineHeights.at(0) + 10;
@@ -41,7 +41,7 @@ void table::drawHeader()
// 初始化文本宽度和高度计算 // 初始化文本宽度和高度计算
// 遍历所有数据和表头,计算每列的最大宽度和行高 // 遍历所有数据和表头,计算每列的最大宽度和行高
// 此方法在数据变更时自动调用 // 此方法在数据变更时自动调用
void table::initTextWaH() void Table::initTextWaH()
{ {
this->colWidths.resize(this->headers.size()); this->colWidths.resize(this->headers.size());
this->lineHeights.resize(this->headers.size()); this->lineHeights.resize(this->headers.size());
@@ -91,15 +91,15 @@ void table::initTextWaH()
} }
} }
void table::initButton() void Table::initButton()
{ {
int x1, x2; int x1, x2;
int y1, y2; int y1, y2;
x1 = pX - 70; x1 = pX - 70;
x2 = pX + textwidth(LPCTSTR(pageNumtext.c_str())) + 10; x2 = pX + textwidth(LPCTSTR(pageNumtext.c_str())) + 10;
y1 = y2 = pY; y1 = y2 = pY;
this->prevButton = new button(x1, y1, 60, textheight(LPCTSTR(pageNumtext.c_str())), "上一页", RGB(0, 0, 0), RGB(255, 255, 255)); this->prevButton = new Button(x1, y1, 60, textheight(LPCTSTR(pageNumtext.c_str())), "上一页", RGB(0, 0, 0), RGB(255, 255, 255));
this->nextButton = new button(x2, y2, 60, textheight(LPCTSTR(pageNumtext.c_str())), "下一页", RGB(0, 0, 0), RGB(255, 255, 255)); this->nextButton = new Button(x2, y2, 60, textheight(LPCTSTR(pageNumtext.c_str())), "下一页", RGB(0, 0, 0), RGB(255, 255, 255));
prevButton->setOnClickListener([this]() prevButton->setOnClickListener([this]()
{if (this->currentPage > 1) {if (this->currentPage > 1)
{ {
@@ -117,7 +117,7 @@ void table::initButton()
}}); }});
} }
void table::initPageNum() void Table::initPageNum()
{ {
if (0 == pY) if (0 == pY)
pY = uY + lineHeights.at(0) * rowsPerPage + rowsPerPage * 10+10; pY = uY + lineHeights.at(0) * rowsPerPage + rowsPerPage * 10+10;
@@ -126,12 +126,12 @@ void table::initPageNum()
this->pX -= textwidth(LPCTSTR(pageNumtext.c_str())); this->pX -= textwidth(LPCTSTR(pageNumtext.c_str()));
this->pX /= 2; this->pX /= 2;
this->pX += x; this->pX += x;
this->pageNum = new label(this->pX, pY, pageNumtext); this->pageNum = new Label(this->pX, pY, pageNumtext);
//pageNum->setTxtdisap(true); //pageNum->setTextdisap(true);
pageNum->textStyle = this->textStyle; pageNum->textStyle = this->textStyle;
} }
void table::drawPageNum() void Table::drawPageNum()
{ {
if (nullptr == pageNum) if (nullptr == pageNum)
initPageNum(); initPageNum();
@@ -144,7 +144,7 @@ void table::drawPageNum()
} }
void table::drawButton() void Table::drawButton()
{ {
if (nullptr == prevButton || nullptr == nextButton) if (nullptr == prevButton || nullptr == nextButton)
initButton(); initButton();
@@ -153,13 +153,13 @@ void table::drawButton()
} }
table::table(int x, int y) Table::Table(int x, int y)
:Control(x, y, 0,0) :Control(x, y, 0,0)
{ {
//this->saveBkImage = new IMAGE(this->width,this->height); //this->saveBkImage = new IMAGE(this->width,this->height);
} }
table::~table() Table::~Table()
{ {
if (this->prevButton) if (this->prevButton)
delete this->prevButton; delete this->prevButton;
@@ -175,7 +175,7 @@ table::~table()
this->saveBkImage = nullptr; this->saveBkImage = nullptr;
} }
void table::draw() void Table::draw()
{ {
if (this->dirty) if (this->dirty)
{ {
@@ -260,7 +260,7 @@ void table::draw()
} }
} }
void table::handleEvent(const ExMessage& msg) void Table::handleEvent(const ExMessage& msg)
{ {
if(!this->isShowPageButton) if(!this->isShowPageButton)
return; return;
@@ -271,7 +271,7 @@ void 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)
@@ -281,7 +281,7 @@ void table::setHeaders(std::initializer_list<std::string> headers)
dirty = true; dirty = true;
} }
void table::setData(const std::vector<std::string>& data) void Table::setData(const std::vector<std::string>& data)
{ {
this->data.push_back(data); this->data.push_back(data);
totalPages = (this->data.size() + rowsPerPage - 1) / rowsPerPage; totalPages = (this->data.size() + rowsPerPage - 1) / rowsPerPage;
@@ -291,7 +291,7 @@ void table::setData(const std::vector<std::string>& data)
dirty = true; dirty = true;
} }
void table::setData(const std::initializer_list<std::vector<std::string>>& data) void Table::setData(const std::initializer_list<std::vector<std::string>>& data)
{ {
for (auto lis : data) for (auto lis : data)
this->data.push_back(lis); this->data.push_back(lis);
@@ -302,7 +302,7 @@ void table::setData(const std::initializer_list<std::vector<std::string>>& data)
dirty = true; dirty = true;
} }
void table::setRowsPerPage(int rows) void Table::setRowsPerPage(int rows)
{ {
this->rowsPerPage = rows; this->rowsPerPage = rows;
totalPages = (data.size() + rowsPerPage - 1) / rowsPerPage; totalPages = (data.size() + rowsPerPage - 1) / rowsPerPage;
@@ -312,90 +312,90 @@ void table::setRowsPerPage(int rows)
dirty = true; dirty = true;
} }
void table::showPageButton(bool isShow) void Table::showPageButton(bool isShow)
{ {
this->isShowPageButton = isShow; this->isShowPageButton = isShow;
} }
void table::settableBorder(COLORREF color) void Table::setTableBorder(COLORREF color)
{ {
this->tableBorderClor = color; this->tableBorderClor = color;
} }
void table::settableBk(COLORREF color) void Table::setTableBk(COLORREF color)
{ {
this->tableBkClor = color; this->tableBkClor = color;
} }
void table::settableFillMode(StellarX::fillMode mode) void Table::setTableFillMode(StellarX::FillMode mode)
{ {
if (StellarX::fillMode::Solid == mode || StellarX::fillMode::Null == mode) if (StellarX::FillMode::Solid == mode || StellarX::FillMode::Null == mode)
this->tableFillMode = mode; this->tableFillMode = mode;
else else
this->tableFillMode = StellarX::fillMode::Solid; this->tableFillMode = StellarX::FillMode::Solid;
} }
void table::settableLineStyle(StellarX::lineStyle style) void Table::setTableLineStyle(StellarX::LineStyle style)
{ {
this->tableLineStyle = style; this->tableLineStyle = style;
} }
void table::settableBorderWidth(int width) void Table::setTableBorderWidth(int width)
{ {
this->tableBorderWidth = width; this->tableBorderWidth = width;
} }
int table::getCurrentPage() const int Table::getCurrentPage() const
{ {
return this->currentPage; return this->currentPage;
} }
int table::getTotalPages() const int Table::getTotalPages() const
{ {
return this->totalPages;; return this->totalPages;;
} }
int table::getRowsPerPage() const int Table::getRowsPerPage() const
{ {
return this->rowsPerPage; return this->rowsPerPage;
} }
bool table::getShowPageButton() const bool Table::getShowPageButton() const
{ {
return this->isShowPageButton; return this->isShowPageButton;
} }
COLORREF table::gettableBorder() const COLORREF Table::getTableBorder() const
{ {
return this->tableBorderClor; return this->tableBorderClor;
} }
COLORREF table::gettableBk() const COLORREF Table::getTableBk() const
{ {
return this->tableBkClor; return this->tableBkClor;
} }
StellarX::fillMode table::gettableFillMode() const StellarX::FillMode Table::getTableFillMode() const
{ {
return this->tableFillMode; return this->tableFillMode;
} }
StellarX::lineStyle table::gettableLineStyle() const StellarX::LineStyle Table::getTableLineStyle() const
{ {
return this->tableLineStyle; return this->tableLineStyle;
} }
std::vector<std::string> table::getHeaders() const std::vector<std::string> Table::getHeaders() const
{ {
return this->headers; return this->headers;
} }
std::vector<std::vector<std::string>> table::getData() const std::vector<std::vector<std::string>> Table::getData() const
{ {
return this->data; return this->data;
} }
int table::gettableBorderWidth() const int Table::getTableBorderWidth() const
{ {
return this->tableBorderWidth; return this->tableBorderWidth;
} }

View File

@@ -1,22 +1,22 @@
// TxtBox.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)
{ {
} }
void textBox::draw() void TextBox::draw()
{ {
if(dirty) if(dirty)
{ {
saveStyle(); saveStyle();
setfillcolor(textBoxBkClor); setfillcolor(textBoxBkClor);
setlinecolor(textBoxBorderClor); setlinecolor(textBoxBorderClor);
if (textStyle.nHeight > height - y) if (textStyle.nHeight > height)
textStyle.nHeight = height; textStyle.nHeight = height;
if (textStyle.nWidth > width - x) if (textStyle.nWidth > width)
textStyle.nWidth = width; textStyle.nWidth = width;
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,
@@ -31,21 +31,21 @@ void textBox::draw()
//根据形状绘制 //根据形状绘制
switch (shape) switch (shape)
{ {
case StellarX::controlShape::RECTANGLE: case StellarX::ControlShape::RECTANGLE:
fillrectangle(x, y, width, height);//有边框填充矩形 fillrectangle(x,y,x+width,y+height);//有边框填充矩形
outtextxy(x + 10, (y + (height - y - text_height) / 2), LPCTSTR(text.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, width, height);//无边框填充矩形 solidrectangle(x, y, x + width, y + height);//无边框填充矩形
outtextxy(x + 10, (y + (height - y - text_height) / 2), LPCTSTR(text.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, width, height, 20, 20);//有边框填充圆角矩形 fillroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//有边框填充圆角矩形
outtextxy(x + 10, (y + (height - y - text_height) / 2), LPCTSTR(text.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, width, height, 20, 20);//无边框填充圆角矩形 solidroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//无边框填充圆角矩形
outtextxy(x + 10, (y + (height - y - text_height) / 2), LPCTSTR(text.c_str())); outtextxy(x + 10, (y + (height - text_height) / 2), LPCTSTR(text.c_str()));
break; break;
} }
@@ -54,26 +54,26 @@ void textBox::draw()
dirty = false; //标记不需要重绘 dirty = false; //标记不需要重绘
} }
void textBox::handleEvent(const ExMessage& msg) void TextBox::handleEvent(const ExMessage& msg)
{ {
bool hover = false; bool hover = false;
bool oldClick = click; bool oldClick = click;
switch (shape) switch (shape)
{ {
case StellarX::controlShape::RECTANGLE: case StellarX::ControlShape::RECTANGLE:
case StellarX::controlShape::B_RECTANGLE: case StellarX::ControlShape::B_RECTANGLE:
case StellarX::controlShape::ROUND_RECTANGLE: case StellarX::ControlShape::ROUND_RECTANGLE:
case StellarX::controlShape::B_ROUND_RECTANGLE: case StellarX::ControlShape::B_ROUND_RECTANGLE:
hover = (msg.x > x && msg.x < width && msg.y > y && msg.y < height);//判断鼠标是否在矩形按钮内 hover = (msg.x > x && msg.x < (x + width) && msg.y > y && msg.y < (y + height));//判断鼠标是否在矩形按钮内
break; break;
} }
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()), maxCharLen,"输入框",NULL,text.c_str(), NULL ,NULL,false); dirty = InputBox(LPTSTR(text.c_str()), maxCharLen,"输入框",NULL,text.c_str(), NULL ,NULL,false);
else if (StellarX::textBoxmode::READONLY_MODE == mode) else if (StellarX::TextBoxmode::READONLY_MODE == mode)
{ {
dirty = false; dirty = false;
InputBox(NULL, maxCharLen, "输出框(输入无效!)", NULL, text.c_str(), NULL, NULL, false); InputBox(NULL, maxCharLen, "输出框(输入无效!)", NULL, text.c_str(), NULL, NULL, false);
@@ -87,47 +87,47 @@ void textBox::handleEvent(const ExMessage& msg)
click = false; click = false;
} }
void textBox::setMode(StellarX::textBoxmode mode) void TextBox::setMode(StellarX::TextBoxmode mode)
{ {
this->mode = mode; this->mode = mode;
} }
void textBox::setmaxCharLen(int len) void TextBox::setMaxCharLen(int len)
{ {
if (len > 0) if (len > 0)
maxCharLen = len; maxCharLen = len;
} }
void textBox::settextBoxshape(StellarX::controlShape shape) void TextBox::setTextBoxshape(StellarX::ControlShape shape)
{ {
switch (shape) switch (shape)
{ {
case StellarX::controlShape::RECTANGLE: case StellarX::ControlShape::RECTANGLE:
case StellarX::controlShape::B_RECTANGLE: case StellarX::ControlShape::B_RECTANGLE:
case StellarX::controlShape::ROUND_RECTANGLE: case StellarX::ControlShape::ROUND_RECTANGLE:
case StellarX::controlShape::B_ROUND_RECTANGLE: case StellarX::ControlShape::B_ROUND_RECTANGLE:
this->shape = shape; this->shape = shape;
break; break;
case StellarX::controlShape::CIRCLE: case StellarX::ControlShape::CIRCLE:
case StellarX::controlShape::B_CIRCLE: case StellarX::ControlShape::B_CIRCLE:
case StellarX::controlShape::ELLIPSE: case StellarX::ControlShape::ELLIPSE:
case StellarX::controlShape::B_ELLIPSE: case StellarX::ControlShape::B_ELLIPSE:
this->shape = StellarX::controlShape::RECTANGLE; this->shape = StellarX::ControlShape::RECTANGLE;
break; break;
} }
} }
void textBox::settextBoxBorder(COLORREF color) void TextBox::setTextBoxBorder(COLORREF color)
{ {
textBoxBorderClor = color; textBoxBorderClor = color;
} }
void textBox::settextBoxBk(COLORREF color) void TextBox::setTextBoxBk(COLORREF color)
{ {
textBoxBkClor = color; textBoxBkClor = color;
} }
std::string textBox::gettext() std::string TextBox::getText() const
{ {
return this->text; return this->text;
} }

View File

@@ -1,13 +1,13 @@
#include "window.h" #include "Window.h"
window::window(int width, int height, int mode) Window::Window(int width, int height, int mode)
{ {
this->width = width; this->width = width;
this->height = height; this->height = height;
this->windowMode = mode; this->windowMode = mode;
} }
window::window(int width, int height, int mode, COLORREF bkcloc) Window::Window(int width, int height, int mode, COLORREF bkcloc)
{ {
this->width = width; this->width = width;
this->height = height; this->height = height;
@@ -15,7 +15,7 @@ window::window(int width, int height, int mode, COLORREF bkcloc)
this->wBkcolor = bkcloc; this->wBkcolor = bkcloc;
} }
window::window(int width, int height, int mode, COLORREF bkcloc, std::string headline) Window::Window(int width, int height, int mode, COLORREF bkcloc, std::string headline)
{ {
this->width = width; this->width = width;
this->height = height; this->height = height;
@@ -24,7 +24,7 @@ window::window(int width, int height, int mode, COLORREF bkcloc, std::string hea
this->headline = headline; this->headline = headline;
} }
window::~window() Window::~Window()
{ {
if (background) if (background)
delete background; delete background;
@@ -32,7 +32,7 @@ window::~window()
closegraph(); // 确保关闭图形上下文 closegraph(); // 确保关闭图形上下文
} }
void window::draw() void Window::draw()
{ {
hWnd = initgraph(width, height, windowMode); hWnd = initgraph(width, height, windowMode);
SetWindowText(hWnd,headline.c_str()); SetWindowText(hWnd,headline.c_str());
@@ -47,9 +47,9 @@ void window::draw()
// 使用背景图片绘制窗口 // 使用背景图片绘制窗口
// @参数 pImgFile: 图片文件路径,支持常见图片格式 // @参数 pImgFile: 图片文件路径,支持常见图片格式
// @备注: 会拉伸图片以适应窗口尺寸 // @备注: 会拉伸图片以适应窗口尺寸
void window::draw(std::string pImgFile) void Window::draw(std::string pImgFile)
{ {
this->background = new IMAGE; this->background = new IMAGE(width, height);
hWnd = initgraph(width, height, windowMode); hWnd = initgraph(width, height, windowMode);
SetWindowText(hWnd, headline.c_str()); SetWindowText(hWnd, headline.c_str());
loadimage(background, pImgFile.c_str(), width, height, true); loadimage(background, pImgFile.c_str(), width, height, true);
@@ -64,7 +64,7 @@ void window::draw(std::string pImgFile)
} }
// 运行主事件循环,处理用户输入和窗口消息 // 运行主事件循环,处理用户输入和窗口消息
// 此方法会阻塞直到窗口关闭 // 此方法会阻塞直到窗口关闭
void window::runEventLoop() void Window::runEventLoop()
{ {
ExMessage msg; ExMessage msg;
bool running = true; bool running = true;
@@ -81,7 +81,7 @@ void window::runEventLoop()
} }
} }
void window::setBkImage(std::string pImgFile) void Window::setBkImage(std::string pImgFile)
{ {
if(nullptr == background) if(nullptr == background)
this->background = new IMAGE; this->background = new IMAGE;
@@ -92,18 +92,18 @@ void window::setBkImage(std::string pImgFile)
putimage(0, 0, background); putimage(0, 0, background);
} }
void window::setBkcolor(COLORREF c) void Window::setBkcolor(COLORREF c)
{ {
wBkcolor = c; wBkcolor = c;
} }
void window::setHeadline(std::string headline) void Window::setHeadline(std::string headline)
{ {
this->headline = headline; this->headline = headline;
SetWindowText(this->hWnd, headline.c_str()); SetWindowText(this->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)); this->controls.push_back(std::move(control));
} }