⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trpage_label.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        return NULL;    SupportStyleMapType::const_iterator itr = supportStyleMap.find(id);    if(itr == supportStyleMap.end())        return NULL;    return &itr->second;}bool trpgSupportStyleTable::Write(trpgWriteBuffer &buf){    if (!isValid())        return false;    buf.Begin(TRPG_SUPPORT_STYLE_TABLE);    // Number of styles    int numStyle = supportStyleMap.size();    buf.Add((int32)numStyle);    // Write the styles    SupportStyleMapType::iterator itr = supportStyleMap.begin();    for (  ; itr != supportStyleMap.end( ); itr++)         itr->second.Write(buf);    buf.End();    return true;}bool trpgSupportStyleTable::Read(trpgReadBuffer &buf){    trpgSupportStyle style;    trpgToken styleTok;    int32 len;    bool status;    int numStyle;	int i;    Reset();    try    {        buf.Get(numStyle);        if (numStyle < 0)            throw 1;        //styles.resize(numStyle);		for (i=0;i<numStyle;i++) {            buf.GetToken(styleTok,len);            if (styleTok != TRPG_SUPPORT_STYLE) throw 1;            buf.PushLimit(len);            style.Reset();            status = style.Read(buf);            buf.PopLimit();            if (!status) throw 1;            AddStyle(style);        }    }    catch (...)    {        return false;    }    return isValid();}// *************** Label ppoperty implementationtrpgLabelProperty::trpgLabelProperty(void){    Reset();}trpgLabelProperty::~trpgLabelProperty(void){}void trpgLabelProperty::Reset(void){    fontId = -1;    supportId = -1;    type = VertBillboard;    handle = -1;    writeHandle = false;}void trpgLabelProperty::SetType(LabelType inType){    type = inType;}trpgLabelProperty::LabelType trpgLabelProperty::GetType() const{    return type;}void trpgLabelProperty::SetFontStyle(int id){    fontId = id;}int trpgLabelProperty::GetFontStyle() const{    return fontId;}void trpgLabelProperty::SetSupport(int id){    supportId = id;}int trpgLabelProperty::GetSupport(void) const{    return supportId;}// Write methodbool trpgLabelProperty::Write(trpgWriteBuffer &buf){    buf.Begin(TRPG_LABEL_PROPERTY);    buf.Begin(TRPG_LABEL_PROPERTY_BASIC);    buf.Add(fontId);    buf.Add(supportId);    buf.Add(type);    buf.End();    buf.End();    return true;}// LabelProperty CB// Used to parse tokens from the label property structure.// If we do it this way it's easier to expand later.class labelPropertyCB : public trpgr_Callback{public:    void * Parse(trpgToken,trpgReadBuffer &);    trpgLabelProperty *property;};void * labelPropertyCB::Parse(trpgToken tok,trpgReadBuffer &buf){    int iVal;    try    {        int ival;        switch (tok)        {        case TRPG_LABEL_PROPERTY_BASIC:            buf.Get(iVal);            property->SetFontStyle(iVal);            buf.Get(iVal);            property->SetSupport(iVal);            buf.Get(ival);            property->SetType(trpgLabelProperty::LabelType(ival));            break;        default:            break;        }    }    catch (...)    {        return NULL;    }    return property;}// Read from a bufferbool trpgLabelProperty::Read(trpgReadBuffer &buf){    Reset();    trpgr_Parser parse;    labelPropertyCB labelPropertyCb;    labelPropertyCb.property = this;    parse.AddCallback(TRPG_LABEL_PROPERTY_BASIC,&labelPropertyCb,false);    parse.Parse(buf);    return isValid();}bool trpgLabelProperty::isValid(void) const{    return supportId != -1 && fontId != -1 && type >=0  && type < MaxLabelType;}bool trpgLabelProperty::operator == (const trpgLabelProperty& in)const{    if (fontId != in.fontId || supportId != in.supportId || type != in.type)        return false;    return true;}// ******************* Label Property Table implementationtrpgLabelPropertyTable::trpgLabelPropertyTable(){    Reset();}trpgLabelPropertyTable::~trpgLabelPropertyTable(){}void trpgLabelPropertyTable::Reset(){    labelPropertyMap.clear();}bool trpgLabelPropertyTable::isValid() const{    LabelPropertyMapType::const_iterator itr = labelPropertyMap.begin();    for (  ; itr != labelPropertyMap.end( ); itr++)    {        if (!itr->second.isValid())            return false;    }    return true;}int trpgLabelPropertyTable::AddProperty(const trpgLabelProperty &property){    int handle = property.GetHandle();    if(handle==-1)    {        handle = labelPropertyMap.size();    }    labelPropertyMap[handle] = property;    return handle;}int trpgLabelPropertyTable::FindAddProperty(const trpgLabelProperty& property){    LabelPropertyMapType::const_iterator itr = labelPropertyMap.begin();    for (  ; itr != labelPropertyMap.end( ); itr++)    {        if (itr->second == property)            return itr->first;    }    return AddProperty(property);}int trpgLabelPropertyTable::GetNumProperty() const{    return labelPropertyMap.size();}const trpgLabelProperty *trpgLabelPropertyTable::GetPropertyRef(int id) const{    if (id < 0)        return NULL;    LabelPropertyMapType::const_iterator itr = labelPropertyMap.find(id);    if(itr == labelPropertyMap.end())        return NULL;    return &itr->second;}bool trpgLabelPropertyTable::Write(trpgWriteBuffer &buf){    if (!isValid())        return false;    buf.Begin(TRPG_LABEL_PROPERTY_TABLE);    // Number of styles    int numProperty = labelPropertyMap.size();    buf.Add((int32)numProperty);    // Write the properties    LabelPropertyMapType::iterator itr = labelPropertyMap.begin();    for (  ; itr != labelPropertyMap.end( ); itr++)    {        itr->second.Write(buf);    }    buf.End();    return true;}bool trpgLabelPropertyTable::Read(trpgReadBuffer &buf){    trpgLabelProperty property;    trpgToken propertyTok;    int32 len;    bool status;    int numProperty;	int i;    Reset();    try    {        buf.Get(numProperty);        if (numProperty < 0)            throw 1;        //properties.resize(numProperty);		for (i=0;i<numProperty;i++) {            buf.GetToken(propertyTok,len);            if (propertyTok != TRPG_LABEL_PROPERTY) throw 1;            buf.PushLimit(len);            property.Reset();            status = property.Read(buf);            buf.PopLimit();            if (!status) throw 1;            //properties[i] = property;            AddProperty(property);        }    }    catch (...)    {        return false;    }    return isValid();}// ****************** Label implementationtrpgLabel::trpgLabel(){    Reset();}trpgLabel::~trpgLabel(){}void trpgLabel::Reset(){    propertyId = -1;    text = "";    alignment = Left;    tabSize = 8;    scale = 1.0;    thickness = 0.0;    desc = "";    url = "";    location.x = 0;    location.y = 0;    location.z = 0;    supports.resize(0);}bool trpgLabel::isValid() const{    if (text.empty() || propertyId == -1)        return false;    return true;}void trpgLabel::SetProperty(int id){    propertyId = id;}int trpgLabel::GetProperty() const{    return propertyId;}void trpgLabel::SetText(const std::string &inText){    text = inText;}const std::string *trpgLabel::GetText() const{    return &text;}void trpgLabel::SetAlignment(AlignmentType inType){    alignment = inType;}trpgLabel::AlignmentType trpgLabel::GetAlignment() const{    return alignment;}void trpgLabel::SetTab(int size){    tabSize = size;}int trpgLabel::GetTab(void) const{    return tabSize;}void trpgLabel::SetScale(float32 inScale){    scale = inScale;}float32 trpgLabel::GetScale(void) const{    return scale;}void trpgLabel::SetThickness(float32 inThickness){    thickness = inThickness;}float32 trpgLabel::GetThickness(void) const{    return thickness;}void trpgLabel::SetDesc(const std::string &inText){    desc = inText;}const std::string *trpgLabel::GetDesc() const{    return &desc;}void trpgLabel::SetURL(const std::string &inText){    url = inText;}const std::string *trpgLabel::GetURL() const{    return &url;}void trpgLabel::SetLocation(const trpg3dPoint &pt){    location = pt;}const trpg3dPoint& trpgLabel::GetLocation() const{    return location;}void trpgLabel::AddSupport(const trpg3dPoint &pt){    supports.push_back(pt);}const std::vector<trpg3dPoint> *trpgLabel::GetSupports() const{    return &supports;}bool trpgLabel::Write(trpgWriteBuffer &buf){	unsigned int i;    buf.Begin(TRPG_LABEL);    buf.Add(propertyId);    buf.Add(text);    buf.Add(alignment);    buf.Add(tabSize);    buf.Add(scale);    buf.Add(thickness);    buf.Add(desc);    buf.Add(url);    buf.Add(location);    buf.Add((int)supports.size());	for (i=0;i<supports.size();i++)        buf.Add(supports[i]);    buf.End();    return true;}bool trpgLabel::Read(trpgReadBuffer &buf){	int numSupport,i;    trpg3dPoint support;    int iVal;    try    {        buf.Get(iVal);        propertyId = iVal;        buf.Get(text);        buf.Get(iVal);        alignment = (AlignmentType)iVal;        buf.Get(tabSize);        buf.Get(scale);        buf.Get(thickness);        buf.Get(desc);        buf.Get(url);        buf.Get(location);        buf.Get(numSupport);        if (numSupport < 0) throw 1;		for (i=0;i<numSupport;i++) {            buf.Get(support);            supports.push_back(support);        }    }    catch (...)    {        return false;    }    return isValid();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -