Files
dl_old/dl/misc/dl_component_use.h
T
2025-07-16 16:23:19 +08:00

128 lines
3.1 KiB
C++

/**
* @file dl_component_use.h
* @brief 组件实例
*
*
* @version 1.0
* @author lveyou
* @date 25-05-12
*
* @note
*/
#pragma once
#include "base/dl_type_def.h"
#include "misc/dl_component.h"
#include "io/dl_input.h"
namespace dl
{
namespace Cpt
{
//! ------------------------------具体组件-------------------------------------
using IsPickup = Function<std::function<bool()>, str_uid("IsPickup")>;//!< 拾取
using IsSelect = Function<std::function<bool()>, str_uid("IsSelect")>;//!< 选择
using IsClick = Function<std::function<bool()>, str_uid("IsClick")>;//!< 点击
using IsDown = Function<std::function<bool()>, str_uid("IsDown")>;//!< 按下状态
using GetCoor = Function<std::function<dl::Coor* ()>, str_uid("GetCoor")>;//!< 返回坐标系
using GetOrder = Function<std::function<float()>, str_uid("GetOrder")>;//!< 返回order
using Update = Function<std::function<void()>, str_uid("Update")>;//!< 逻辑
using Render = Function<std::function<void()>, str_uid("Render")>;//!< 绘制
using SetOrder = Function<std::function<void(float)>, str_uid("SetOrder")>;//!< 设置order
using SetSelect = Function<std::function<void(bool)>, str_uid("SetSelect")>;//!< 设置是否选择
using DeleteThis = Function<std::function<void()>, str_uid("DeleteThis")>;//!< 删除自身
using Clone = Function<std::function<Components* ()>, str_uid("Clone")>;//!< 克隆
using RenderDebug = Function<std::function<void()>, str_uid("RenderD")>;//!< 调试绘图
//! 语言本地化
class Lang
{
public:
std::array<std::string, 2> _str;
std::function<void(std::string_view, std::string_view)> _func;
};
//! 元素通用属性(默认左上对齐,便于理解)
class ElementData
{
public:
ElementData() :
_size{},
_anchor{},
_pos{},
_hv{ Align::LT },
_orderOffset{ 0 },
_bRunAble{true},
_bUpdateAble{true},
_bRenderAble{true}
{}
//! 位置偏移(实际coor位置)
Position GetOffset()
{
return _pos - (Align::Size2Anchor(_size, _hv) + _anchor);
}
//! 自身大小
Position GetSize() const
{
return _size;
}
//! 锚点位置
Position GetAnchor() const
{
return _anchor;
}
//! order偏移
int GetOrderOffset()
{
return _orderOffset;
}
//!
RectF GetRect()
{
return createRectF(GetOffset(), GetSize());
}
public:
Position _size;
Position _anchor;
Position _pos; // 额外偏移
Align::Direction2 _hv;
int _orderOffset;
bool _bRunAble; // 可运行
bool _bUpdateAble; // 可更新
bool _bRenderAble; // 可绘制
};
//! 拖拽组件
class Drag
{
public:
bool _bEnable;
bool _bControlPanel;// 独立使用时无效
RectF _areaPickup; // 拾取范围
RectF _areaRange; // 拖拽范围
MouseCode _key; // 响应按钮
Drag() :
_bEnable{ true },
_bControlPanel{ false },
_areaPickup{},
_areaRange{},
_key{ MouseCode::LEFT },
_state{ 0 },
_xyClick{},
_posOld{}
{}
//! 可独立使用
void Update(Coor* coor, bool is_pickup);
public:
int _state; // 0.未点击 1.拖拽中
Point _xyClick; // 拖拽点击位置(世界)
Position _posOld;
Position _posMove;
};
}
}