bool ctrlImage::Msg_MouseMove(const MouseCoords& mc)
{
    // gültiges Bild?
    if(GetImage())
    {
        // Jeweils Tooltip ein- und ausblenden, wenn die Maus über dem Bild ist
        if(IsPointInRect(mc.GetPos(), Rect::move(GetImageRect(), GetDrawPos())))
            ShowTooltip();
        else
            HideTooltip();
    }

    return false;
}
bool ctrlIngameMinimap::Msg_MouseMove(const MouseCoords& mc)
{
    if(mc.ldown)
    {
        // Mauszeiger auf der Karte?
        if(IsPointInRect(mc.GetPos(), GetMapDrawArea()))
        {
            // Koordinate feststellen
            DrawPoint mapCoord =
              (mc.GetPos() - DrawPoint(GetMapDrawArea().getOrigin())) * DrawPoint(minimap.GetMapSize()) / DrawPoint(GetCurMapSize());

            gwv.MoveToMapPt(MapPoint(mapCoord));

            return true;
        }
    }

    return false;
}
TBool CCommonUtils::IsPointInRect(TPoint aPoint,TRect rect)
	{
	return IsPointInRect(aPoint.iX, aPoint.iY, rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);
	}
Beispiel #4
0
// 鼠标事件
bool LongUI::UISlider::DoMouseEvent(const MouseEventArgument& arg) noexcept {
    // 禁用状态禁用鼠标消息
    if (!this->GetEnabled()) return true;
    // 坐标转换
    D2D1_POINT_2F pt4self = LongUI::TransformPointInverse(this->world, arg.pt);
    bool nocontinued = false;
    // 分类
    switch (arg.event)
    {
    case LongUI::MouseEvent::Event_MouseLeave:
        // 鼠标移出: 设置UI元素状态
        this->SetControlState(LongUI::State_Normal);
        m_bMouseClickIn = false;
        m_bMouseMoveIn = false;
        nocontinued = true;
        break;
    case  LongUI::MouseEvent::Event_MouseMove:
        // 点中并且移动
        if (arg.sys.wParam & MK_LBUTTON) {
            if (m_bMouseClickIn) {
                // 获取基本值
                if (this->IsVerticalSlider()) {
                    auto slider_height = this->view_size.height - this->thumb_size.height;
                    m_fValue = (pt4self.y - m_fClickPosition) / slider_height;
                }
                else {
                    auto slider_width = this->view_size.width - this->thumb_size.width;
                    m_fValue = (pt4self.x - m_fClickPosition) / slider_width;
                }
                // 阈值检查
                if (m_fValue > 1.f) m_fValue = 1.f;
                else if (m_fValue < 0.f) m_fValue = 0.f;
            }
        }
        // 移动
        else {
            if (IsPointInRect(m_rcThumb, pt4self)){
                // 鼠标移进:
                if (!m_bMouseMoveIn) {
                    // 设置UI元素状态
                    this->SetControlState(LongUI::State_Hover);
                    m_bMouseMoveIn = true;
                }
            }
            else {
                // 鼠标移出:
                if (m_bMouseMoveIn) {
                    // 设置UI元素状态
                    this->SetControlState(LongUI::State_Normal);
                    m_bMouseMoveIn = false;
                }
            }
        }
        nocontinued = true;
        break;
    case  LongUI::MouseEvent::Event_LButtonDown:
        // 左键按下
        m_pWindow->SetCapture(this);
        if (IsPointInRect(m_rcThumb, pt4self)){
            m_bMouseClickIn = true;
            m_fClickPosition = this->IsVerticalSlider() ?
                (pt4self.y - m_rcThumb.top) : (pt4self.x - m_rcThumb.left);
            this->SetControlState(LongUI::State_Pushed);
        }
        nocontinued = true;
        break;
    case LongUI::MouseEvent::Event_LButtonUp:
        // 右键按下
        m_bMouseClickIn = false;
        m_pWindow->ReleaseCapture();
        this->SetControlState(LongUI::State_Hover);
        nocontinued = true;
        break;
    }
    // 检查事件
    if (m_fValueOld != m_fValue) {
        m_fValueOld = m_fValue;
        // 调用
        this->call_uievent(m_event, SubEvent::Event_ValueChanged);
        // 刷新
        m_pWindow->Invalidate(this);
    }
    return nocontinued;
}
TBool CCommonUtils::IsPointInRect(TInt x,TInt y,TRect rect)
{
	return IsPointInRect(x, y, rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);
}