Files
StellarX-kaifa/src/Canvas.cpp
T
2025-09-07 22:26:23 +08:00

96 lines
2.3 KiB
C++

#include "StellarX/Canvas.h"
Canvas::Canvas(int x, int y, int width, int height)
:Control(x, y, width, height) {}
void Canvas::draw()
{
saveStyle();
setlinecolor(canvasBorderClor);//设置线色
setfillcolor(canvasBkClor);//设置填充色
setfillstyle((int)canvasFillMode);//设置填充模式
setlinestyle((int)canvasLineStyle, canvaslinewidth);
//根据画布形状绘制
switch (shape)
{
case StellarX::ControlShape::RECTANGLE:
fillrectangle(x,y,x+width,y+height);//有边框填充矩形
break;
case StellarX::ControlShape::B_RECTANGLE:
solidrectangle(x, y, x + width, y + height);//无边框填充矩形
break;
case StellarX::ControlShape::ROUND_RECTANGLE:
fillroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//有边框填充圆角矩形
break;
case StellarX::ControlShape::B_ROUND_RECTANGLE:
solidroundrect(x, y, x + width, y + height, rouRectangleSize.ROUND_RECTANGLEwidth, rouRectangleSize.ROUND_RECTANGLEheight);//无边框填充圆角矩形
break;
}
// 绘制所有子控件
for (auto& control : controls)
control->draw();
restoreStyle();
}
void Canvas::handleEvent(const ExMessage& msg)
{
for (auto& control : controls) {
control->handleEvent(msg);
}
}
void Canvas::addControl(std::unique_ptr<Control> control)
{
controls.push_back(std::move(control));
}
void Canvas::setShape(StellarX::ControlShape shape)
{
switch (shape)
{
case StellarX::ControlShape::RECTANGLE:
case StellarX::ControlShape::B_RECTANGLE:
case StellarX::ControlShape::ROUND_RECTANGLE:
case StellarX::ControlShape::B_ROUND_RECTANGLE:
this->shape = shape;
break;
case StellarX::ControlShape::CIRCLE:
case StellarX::ControlShape::B_CIRCLE:
case StellarX::ControlShape::ELLIPSE:
case StellarX::ControlShape::B_ELLIPSE:
this->shape = StellarX::ControlShape::RECTANGLE;
break;
}
}
void Canvas::setCanvasfillMode(StellarX::FillMode mode)
{
this->canvasFillMode = mode;
}
void Canvas::setBorderColor(COLORREF color)
{
this->canvasBorderClor = color;
}
void Canvas::setCanvasBkColor(COLORREF color)
{
this->canvasBkClor = color;
}
void Canvas::setCanvasLineStyle(StellarX::LineStyle style)
{
this->canvasLineStyle = style;
}
void Canvas::setLinewidth(int width)
{
this->canvaslinewidth = width;
}