最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Mygui中文換行問(wèn)題解決方案

 更新時(shí)間:2012年11月28日 10:11:24   作者:  
相信大家解決了中文輸入后一定會(huì)遇到如何解決中文輸入的問(wèn)題,中文輸入換行問(wèn)題是很多gui框架都存在的一個(gè)問(wèn)題,需要的朋友可以了解下
相信大家解決了中文輸入后一定會(huì)遇到如何解決中文輸入的問(wèn)題,中文輸入換行問(wèn)題是很多gui框架都存在的一個(gè)問(wèn)題,這里不廢話了,大家打開(kāi)mygui的引擎層中的widget的textview 的頭文件和源文件將其替換為:
復(fù)制代碼 代碼如下:

/*!
@file
@author Albert Semenov
@date 09/2009
*/
#ifndef __MYGUI_TEXT_VIEW_DATA_H__
#define __MYGUI_TEXT_VIEW_DATA_H__
#include "MyGUI_Prerequest.h"
namespace MyGUI
{
class CharInfo
{
public:
CharInfo() :
mIsColour(false)
{
mMetrics.mWidth = 0.0f;
mMetrics.mHeight = 0.0f;
mMetrics.mAdvance = 0.0f;
mMetrics.mBearingX = 0.0f;
mMetrics.mBearingY = 0.0f;
}
CharInfo(
const FloatRect& _rect,
float _width,
float _height,
float _advance,
float _bearingX,
float _bearingY) :
mIsColour(false),
mUVRect(_rect)
{
mMetrics.mWidth = _width;
mMetrics.mHeight = _height;
mMetrics.mAdvance = _advance;
mMetrics.mBearingX = _bearingX;
mMetrics.mBearingY = _bearingY;
}
CharInfo(uint32 _colour) :
mIsColour(true),
mColour(_colour)
{ }
bool isColour() const
{
return mIsColour;
}
float getWidth() const
{
return mMetrics.mWidth;
}
float getHeight() const
{
return mMetrics.mHeight;
}
float getAdvance() const
{
return mMetrics.mAdvance;
}
float getBearingX() const
{
return mMetrics.mBearingX;
}
float getBearingY() const
{
return mMetrics.mBearingY;
}
const FloatRect& getUVRect() const
{
return mUVRect;
}
uint32 getColour() const
{
return mColour;
}
private:
bool mIsColour;
FloatRect mUVRect;
struct Metrics
{
float mWidth;
float mHeight;
float mAdvance;
float mBearingX;
float mBearingY;
};
union
{
Metrics mMetrics;
uint32 mColour;
};
};
typedef std::vector<CharInfo> VectorCharInfo;
//struct LineInfo
//{
// LineInfo() :
// width(0),
// offset(0),
// count(0)
// {
// }
// void clear()
// {
// width = 0;
// count = 0;
// simbols.clear();
// offset = 0;
// }
// int width;
// int offset;
// size_t count;
// VectorCharInfo simbols;
//};
struct LineInfo
{
LineInfo() :
width(0),
offset(0),
count(0),
offcount(0)
{
}
void clear()
{
offcount = 0;
width = 0;
count = 0;
simbols.clear();
offset = 0;
}
int offcount;
int width;
int offset;
size_t count;
VectorCharInfo simbols;
};
typedef std::vector<LineInfo> VectorLineInfo;
} // namespace MyGUI
#endif // __MYGUI_TEXT_VIEW_DATA_H__

上面是頭文件,下面是源文件:
復(fù)制代碼 代碼如下:

/*!
@file
@author Albert Semenov
@date 09/2010
*/
/*
This file is part of MyGUI.
MyGUI is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MyGUI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_TextView.h"
namespace MyGUI
{
namespace
{
template<typename T>
void setMin(T& _var, const T& _newValue)
{
if (_newValue < _var)
_var = _newValue;
}
template<typename T>
void setMax(T& _var, const T& _newValue)
{
if (_var < _newValue)
_var = _newValue;
}
}
class RollBackPoint
{
public:
RollBackPoint() :
position(0),
count(0),
width(0),
rollback(false)
{
}
void set(size_t _position, UString::const_iterator& _space_point, size_t _count, float _width)
{
position = _position;
space_point = _space_point;
count = _count;
width = _width;
rollback = true;
}
void clear()
{
rollback = false;
}
bool empty() const
{
return !rollback;
}
float getWidth() const
{
MYGUI_DEBUG_ASSERT(rollback, "rollback point not valid");
return width;
}
size_t getCount() const
{
MYGUI_DEBUG_ASSERT(rollback, "rollback point not valid");
return count;
}
size_t getPosition() const
{
MYGUI_DEBUG_ASSERT(rollback, "rollback point not valid");
return position;
}
UString::const_iterator getTextIter() const
{
MYGUI_DEBUG_ASSERT(rollback, "rollback point not valid");
return space_point;
}
private:
size_t position;
UString::const_iterator space_point;
size_t count;
float width;
bool rollback;
};
TextView::TextView() :
mLength(0),
mFontHeight(0)
{
}
void TextView::update(const UString& _text, IFont* _font, int _height, Align _align, VertexColourType _format, int _maxWidth)
{
mFontHeight = _height;
// массив для быстрой конвертации цветов
static const char convert_colour[64] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
mViewSize.clear();
RollBackPoint roll_back;
IntSize result;
float width = 0.0f;
size_t count = 0;
mLength = 0;
mLineInfo.clear();
LineInfo line_info;
int font_height = _font->getDefaultHeight();
UString::const_iterator end = _text.end();
UString::const_iterator index = _text.begin();
/*if (index == end)
return;*/
result.height += _height;
for (; index != end; ++index)
{
Char character = *index;
// новая строка
if (character == FontCodeType::CR
|| character == FontCodeType::NEL
|| character == FontCodeType::LF)
{
if (character == FontCodeType::CR)
{
UString::const_iterator peeki = index;
++peeki;
if ((peeki != end) && (*peeki == FontCodeType::LF))
index = peeki; // skip both as one newline
}
line_info.width = (int)ceil(width);
line_info.count = count;
//mLength += line_info.count + 1;
mLength += line_info.offcount;
result.height += _height;
setMax(result.width, line_info.width);
width = 0;
count = 0;
mLineInfo.push_back(line_info);
line_info.clear();
// отменяем откат
roll_back.clear();
continue;
}
// тег
else if (character == L'#')
{
// берем следующий символ
++ index;
if (index == end)
{
--index; // это защита
continue;
}
character = *index;
// если два подряд, то рисуем один шарп, если нет то меняем цвет
if (character != L'#')
{
// парсим первый символ
uint32 colour = convert_colour[(character - 48) & 0x3F];
// и еще пять символов после шарпа
for (char i = 0; i < 5; i++)
{
++ index;
if (index == end)
{
--index; // это защита
continue;
}
colour <<= 4;
colour += convert_colour[ ((*index) - 48) & 0x3F ];
}
// если нужно, то меняем красный и синий компоненты
texture_utility::convertColour(colour, _format);
line_info.simbols.push_back( CharInfo(colour) );
continue;
}
}
GlyphInfo* info = _font->getGlyphInfo(character);
if (info == nullptr)
continue;
if (FontCodeType::Space == character)
{
roll_back.set(line_info.simbols.size(), index, count, width);
}
else if (FontCodeType::Tab == character)
{
roll_back.set(line_info.simbols.size(), index, count, width);
}
float char_width = info->width;
float char_height = info->height;
float char_advance = info->advance;
float char_bearingX = info->bearingX;
float char_bearingY = info->bearingY;
if (_height != font_height)
{
float scale = (float)_height / font_height;
char_width *= scale;
char_height *= scale;
char_advance *= scale;
char_bearingX *= scale;
char_bearingY *= scale;
}
float char_fullAdvance = char_bearingX + char_advance;
// перенос слов
if (_maxWidth != -1
&& (width + char_fullAdvance) > _maxWidth
/*&& !roll_back.empty()*/)
{
--index;
// откатываем до последнего пробела
/*width = roll_back.getWidth();
count = roll_back.getCount();
index = roll_back.getTextIter();
line_info.simbols.erase(line_info.simbols.begin() + roll_back.getPosition(), line_info.simbols.end());*/

// запоминаем место отката, как полную строку
/*line_info.width = (int)ceil(width);
line_info.count = count;
mLength += line_info.count + 1;
result.height += _height;
setMax(result.width, line_info.width);
width = 0;
count = 0;
mLineInfo.push_back(line_info);
line_info.clear();*/
// запоминаем место отката, как полную строку
line_info.width = (int)ceil(width);
line_info.count = count;
line_info.offcount = 0;
mLength += line_info.count;// + 1;
result.height += _height;
setMax(result.width, line_info.width);
width = 0;
count = 0;
mLineInfo.push_back(line_info);
line_info.clear();
// отменяем откат
roll_back.clear();
continue;
}
line_info.simbols.push_back(CharInfo(info->uvRect, char_width, char_height, char_advance, char_bearingX, char_bearingY));
width += char_fullAdvance;
count ++;
}
line_info.width = (int)ceil(width);
line_info.count = count;
mLength += line_info.count;
mLineInfo.push_back(line_info);
setMax(result.width, line_info.width);
// теперь выравниванием строки
for (VectorLineInfo::iterator line = mLineInfo.begin(); line != mLineInfo.end(); ++line)
{
if (_align.isRight())
line->offset = result.width - line->width;
else if (_align.isHCenter())
line->offset = (result.width - line->width) / 2;
}
mViewSize = result;
}
size_t TextView::getCursorPosition(const IntPoint& _value)
{
const int height = mFontHeight;
size_t result = 0;
int top = 0;
for (VectorLineInfo::const_iterator line = mLineInfo.begin(); line != mLineInfo.end(); ++line)
{
// это последняя строка
bool lastline = !(line + 1 != mLineInfo.end());
// наша строчка
if (top + height > _value.top || lastline)
{
top += height;
float left = (float)line->offset;
int count = 0;
// ищем символ
for (VectorCharInfo::const_iterator sim = line->simbols.begin(); sim != line->simbols.end(); ++sim)
{
if (sim->isColour())
continue;
float fullAdvance = sim->getAdvance() + sim->getBearingX();
if (left + fullAdvance / 2.0f > _value.left)
{
break;
}
left += fullAdvance;
count ++;
}
result += count;
break;
}
if (!lastline)
{
top += height;
result += line->count + line->offcount;

}
}
return result;
}
IntPoint TextView::getCursorPoint(size_t _position)
{
setMin(_position, mLength);
size_t position = 0;
int top = 0;
float left = 0.0f;
for (VectorLineInfo::const_iterator line = mLineInfo.begin(); line != mLineInfo.end(); ++line)
{
left = (float)line->offset;
if (position + line->count >= _position)
{
for (VectorCharInfo::const_iterator sim = line->simbols.begin(); sim != line->simbols.end(); ++sim)
{
if (sim->isColour())
continue;
if (position == _position)
break;
position ++;
left += sim->getBearingX() + sim->getAdvance();
}
break;
}
position += line->count + line->offcount;

top += mFontHeight;
}
return IntPoint((int)left, top);
}
const IntSize& TextView::getViewSize() const
{
return mViewSize;
}
size_t TextView::getTextLength() const
{
return mLength;
}
const VectorLineInfo& TextView::getData() const
{
return mLineInfo;
}
} // namespace MyGUI

修改了這兩個(gè)以后,然后將edit控件改為多行支持和自動(dòng)換行,這樣就實(shí)現(xiàn)了mygui的中文自動(dòng)換行問(wèn)題。

相關(guān)文章

  • C/C++模擬實(shí)現(xiàn)煙花效果的示例代碼

    C/C++模擬實(shí)現(xiàn)煙花效果的示例代碼

    這篇文章主要為大家詳細(xì)介紹了C/C++模擬實(shí)現(xiàn)煙花效果的兩種簡(jiǎn)單方法,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解下
    2024-01-01
  • 利用C++實(shí)現(xiàn)?然連接操作算法

    利用C++實(shí)現(xiàn)?然連接操作算法

    這篇文章主要介紹了利用C++實(shí)現(xiàn)?然連接操作算法,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定參考價(jià)值,需要的小伙伴可以參考一下
    2022-08-08
  • 詳解Visual Studio 2019(VS2019) 基本操作

    詳解Visual Studio 2019(VS2019) 基本操作

    這篇文章主要介紹了詳解Visual Studio 2019(VS2019) 基本操作,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • C++實(shí)現(xiàn)LeetCode(138.拷貝帶有隨機(jī)指針的鏈表)

    C++實(shí)現(xiàn)LeetCode(138.拷貝帶有隨機(jī)指針的鏈表)

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(138.拷貝帶有隨機(jī)指針的鏈表),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • C++Zip壓縮解壓縮示例(支持遞歸壓縮)

    C++Zip壓縮解壓縮示例(支持遞歸壓縮)

    C++Zip壓縮解壓縮示例,用第三方函數(shù)封裝而成,支持 UNCODE, ANSCII、支持壓縮文件夾、支持遞歸壓縮
    2013-11-11
  • C++ Cartographer加載配置文件過(guò)程介紹

    C++ Cartographer加載配置文件過(guò)程介紹

    這篇文章主要介紹了Cartographer加載配置文件過(guò)程,谷歌優(yōu)秀的激光SLAM開(kāi)源框架Cartographer算法簡(jiǎn)單,但是程序部分太多需要學(xué)習(xí)的地方了,不論是整體框架的結(jié)構(gòu),還是數(shù)據(jù)的使用,都是非常優(yōu)美的
    2023-03-03
  • C語(yǔ)言實(shí)現(xiàn)單鏈表逆序與逆序輸出實(shí)例

    C語(yǔ)言實(shí)現(xiàn)單鏈表逆序與逆序輸出實(shí)例

    這篇文章主要介紹了C語(yǔ)言實(shí)現(xiàn)單鏈表逆序與逆序輸出,是數(shù)據(jù)結(jié)構(gòu)與算法中比較基礎(chǔ)的重要內(nèi)容,有必要加以牢固掌握,需要的朋友可以參考下
    2014-08-08
  • c++實(shí)現(xiàn)二路歸并排序的示例代碼

    c++實(shí)現(xiàn)二路歸并排序的示例代碼

    這篇文章主要介紹了c++實(shí)現(xiàn)二路歸并排序的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • C++之OpenCV圖像高光調(diào)整具體流程

    C++之OpenCV圖像高光調(diào)整具體流程

    PS中的高光命令是一種校正由于太接近相機(jī)閃光燈而有些發(fā)白的焦點(diǎn)的方法,對(duì)高光區(qū)和非高光區(qū)的邊緣作平滑處理,接下來(lái)通過(guò)本文給大家分享C++之OpenCV圖像高光調(diào)整具體流程,感興趣的朋友一起看看吧
    2021-09-09
  • C語(yǔ)言中初始、增加和刪除進(jìn)程信號(hào)的操作方法簡(jiǎn)介

    C語(yǔ)言中初始、增加和刪除進(jìn)程信號(hào)的操作方法簡(jiǎn)介

    這篇文章主要介紹了C語(yǔ)言中初始、增加和刪除進(jìn)程信號(hào)的操作方法簡(jiǎn)介,分別是sigemptyset函數(shù)、sigaddset函數(shù)和sigdelset函數(shù)的用法,需要的朋友可以參考下
    2015-09-09

最新評(píng)論

临洮县| 永泰县| 集贤县| 新密市| 丹江口市| 古蔺县| 丹寨县| 星子县| 墨脱县| 孟村| 灵宝市| 丹巴县| 安溪县| 邻水| 靖宇县| 西昌市| 旬阳县| 黄陵县| 新民市| 称多县| 乌海市| 龙游县| 宁化县| 宝山区| 鄂托克旗| 瑞丽市| 高密市| 天津市| 垫江县| 正镶白旗| 佛教| 班玛县| 南宁市| 武冈市| 丹巴县| 浑源县| 阆中市| 扶余县| 安福县| 临邑县| 安阳县|