CEGUI的ComponentArea::getPixelRect()两个重载函数的参数,Editbox点击偏移错误

本文解决了一个关于Falagard编辑框中点击位置偏移的问题,通过修改获取文本区域的方式,确保用户点击的位置能准确对应到文本的实际位置。


 d_window->getLookNFeel();
 const WidgetLookFeel& wlf = getLookNFeel();
 const Rect textArea(wlf.getNamedArea("TextArea").getArea().getPixelRect(*w)); 

 const Rect textArea(wlf.getNamedArea("TextArea").getArea().getPixelRect(*w), d_window->getOuterRectClipper());

///////////////////////////////////////////


        Rect getPixelRect(const Window& wnd, const Rect& container) const;
        Rect getPixelRect(const Window& wnd) const;

 

第一个函数得到的结果是该nameArea在该window的位置,以Rect参考的基准为基准

第二个函数得到的结果是nameArea在该window的位置,

一般用法就是注释上面的一段,改自FalEditbox,原来的减去的不知道是啥东东~反正改了looknfeel中的TextArea就会点不到真实的位置了,改了就好了。。。也算是输入文本的偏移错误吧。。。希望同问题的人可以搜索到,有点帮助~

 

size_t FalagardEditbox::getTextIndexFromPosition(const Point& pt) const
{
    Editbox* w = static_cast<Editbox*>(d_window);

    // calculate final window position to be checked
    float wndx = CoordConverter::screenToWindowX(*w, pt.d_x);


 //MODIFY:还应该减去namespace:TextArea的左边缘
 d_window->getLookNFeel();
 const WidgetLookFeel& wlf = getLookNFeel();
 const Rect textArea(wlf.getNamedArea("TextArea").getArea().getPixelRect(*w));
 wndx -= textArea.d_left;

 

//原来的
    //wndx -= d_lastTextOffset;

 

    // Return the proper index
    if (w->isTextMasked())
        return w->getFont()->getCharAtPixel(
                String(w->getTextVisual().length(), w->getMaskCodePoint()),
                wndx);
    else
        return w->getFont()->getCharAtPixel(w->getTextVisual(), wndx);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值