Пример #1
0
bool Font::deserialize(const ConfigParserPtr& config) {
    mGlyphs.clear();

    if(config && config->toNode(L"font")) {
        UknString font_name = config->getString(L"name");

        if(!font_name.empty()) {
            UknString fullFontPath = Path::CheckAndGetFontPath(font_name);

            if(fullFontPath.empty()) {
                log_error(L"ukn::Font::deserialize: error finding font name " + font_name);
                return false;
            }
            ResourcePtr fontResource = ResourceLoader::Instance().loadResource(fullFontPath);
            if(fontResource && fontResource->getResourceStream()) {
                bool result = mFace->load(fontResource);

                if(result) {
                    mGlyphs.resize(mFace->face->num_glyphs);

                    for(int i = 0; i < mFace->face->num_glyphs; ++i) {
                        mGlyphs[i].size = mFontSize;
                        mGlyphs[i].face = &mFace->face;
                    }
                }
            }
        }

        mEnableShadow = config->getBool(L"shadow", false);
        mEnableStroke = config->getBool(L"stroke", false);

        if(config->getBool(L"bold", false)) {
            this->setFTStyle(FT_STYLE_FLAG_BOLD);
        }
        if(config->getBool(L"italic", false)) {
            this->setFTStyle(FT_STYLE_FLAG_ITALIC);
        }
        mShadowXOffset = config->getInt(L"shadow_offset_x", 0);
        mShadowYOffset = config->getInt(L"shadow_offset_y", 0);

        mStrokeWidth = config->getInt(L"stroke_width", 0);

        mFontSize = config->getInt(L"size", 14);
        mFontName = font_name;

        config->toParent();

        return true;
    }
    return false;
}
Пример #2
0
 inline void create_linear_animation(const MistString& type, void* prop, const ConfigParserPtr& parser, StoryBoard* storyboard) {
     if(type == L"int") {
         SharedPtr<LinearAnimation<int> > anim = MakeSharedPtr<LinearAnimation<int> >();
         anim->setFrom(parser->getInt(L"from", 0));
         anim->setTo(parser->getInt(L"to", 0));
         anim->setDuration(parser->getInt(L"duration", 0));
         storyboard->children().push_back(StoryBoard::AnimationInfo(parser->getInt(L"time", 0), 
                                                                    anim,
                                                                    prop));
         return;
     }
     
     if(type == L"float") {
         SharedPtr<LinearAnimation<float> > anim =  MakeSharedPtr<LinearAnimation<float> >();
         anim->setFrom(parser->getFloat(L"from", 0));
         anim->setTo(parser->getFloat(L"to", 0));
         anim->setDuration(parser->getInt(L"duration", 0));
         storyboard->children().push_back(StoryBoard::AnimationInfo(parser->getInt(L"time", 0), 
                                                                    anim,
                                                                    prop));
         return;
     }
     
     if(type == L"uint") {
         SharedPtr<LinearAnimation<uint32> > anim =  MakeSharedPtr<LinearAnimation<uint32> >();
         anim->setFrom(parser->getInt(L"from", 0));
         anim->setTo(parser->getInt(L"to", 0));
         anim->setDuration(parser->getInt(L"duration", 0));
         storyboard->children().push_back(StoryBoard::AnimationInfo(parser->getInt(L"time", 0), 
                                                                    anim,
                                                                    prop));
         return;
     }
     
     if(type == L"double") {
         SharedPtr<LinearAnimation<double> > anim = MakeSharedPtr<LinearAnimation<double> >();
         anim->setFrom(parser->getFloat(L"from", 0));
         anim->setTo(parser->getFloat(L"to", 0));
         anim->setDuration(parser->getInt(L"duration", 0));
         storyboard->children().push_back(StoryBoard::AnimationInfo(parser->getInt(L"time", 0), 
                                                                    anim,
                                                                    prop));
         return;
     }
     
     if(type == L"color") {
         // to do
         return;
     }
 }
Пример #3
0
 inline void create_key_frame_animation(const MistString& type, void* prop, const ConfigParserPtr& parser, StoryBoard* storyboard) {
     
     if(type == L"int") {
         SharedPtr<KeyFrameAnimation<int> > anim = MakeSharedPtr<KeyFrameAnimation<int> >();
         
         int32 time = parser->getInt(L"time", 0);
         int32 duration = parser->getInt(L"duration", 0);
         
         if(duration == 0)
             return;
         anim->setDuration(duration);
         
         if(parser->toFirstChild()) {
             do {
                 if(parser->hasAttribute(L"val")) {
                     
                     int32 val = parser->getInt(L"val", 0);
                     int32 dur = parser->getInt(L"duration", 0);
                     int32 type = parser->getInt(L"type", 0);
                 
                     anim->getKeyFrames().push_back(KeyFrameAnimation<int>::KeyFrame(val, 
                                                                                   dur, 
                                                                                   type == 0 ? KFT_Linear : KFT_Discrete));
                 }
                 
             } while(parser->toNextChild());
             
             storyboard->children().push_back(StoryBoard::AnimationInfo(time, 
                                                                        anim,
                                                                        prop));
         }
         return;
     } 
     
     if(type == L"float") {
         SharedPtr<KeyFrameAnimation<float> > anim = MakeSharedPtr<KeyFrameAnimation<float> >();
         
         int32 time = parser->getInt(L"time", 0);
         int32 duration = parser->getInt(L"duration", 0);
         
         if(duration == 0)
             return;
         anim->setDuration(duration);
         
         if(parser->toFirstChild()) {
             do {
                 if(parser->hasAttribute(L"val")) {
                     
                     float val = parser->getFloat(L"val", 0);
                     int32 dur = parser->getInt(L"duration", 0);
                     int32 type = parser->getInt(L"type", 0);
                     
                     anim->getKeyFrames().push_back(KeyFrameAnimation<float>::KeyFrame(val, 
                                                                                     dur, 
                                                                                     type == 0 ? KFT_Linear : KFT_Discrete));
                 }
                 
             } while(parser->toNextChild());
             
             storyboard->children().push_back(StoryBoard::AnimationInfo(time, 
                                                                        anim,
                                                                        prop));
         }
         return;
     } 
     
     if(type == L"double") {
         SharedPtr<KeyFrameAnimation<double> > anim = MakeSharedPtr<KeyFrameAnimation<double> >();
         
         int32 time = parser->getInt(L"time", 0);
         int32 duration = parser->getInt(L"duration", 0);
         
         if(duration == 0)
             return;
         anim->setDuration(duration);
         
         if(parser->toFirstChild()) {
             do {
                 if(parser->hasAttribute(L"val")) {
                     int32 val = parser->getInt(L"val", 0);
                     int32 dur = parser->getInt(L"duration", 0);
                     int32 type = parser->getInt(L"type", 0);
                     
                     anim->getKeyFrames().push_back(KeyFrameAnimation<double>::KeyFrame(val, 
                                                                                      dur, 
                                                                                      type == 0 ? KFT_Linear : KFT_Discrete));
                 }
                 
             } while(parser->toNextChild());
             
             storyboard->children().push_back(StoryBoard::AnimationInfo(time, 
                                                                        anim,
                                                                        prop));
         }
         return;
     } 
     
     if(type == L"uint") {
         SharedPtr<KeyFrameAnimation<uint32> > anim = MakeSharedPtr<KeyFrameAnimation<uint32> >();
         
         int32 time = parser->getInt(L"time", 0);
         int32 duration = parser->getInt(L"duration", 0);
         
         if(duration == 0)
             return;
         anim->setDuration(duration);
         
         if(parser->toFirstChild()) {
             do {
                 if(parser->hasAttribute(L"val")) {
                     
                     int32 val = parser->getInt(L"val", 0);
                     int32 dur = parser->getInt(L"duration", 0);
                     int32 type = parser->getInt(L"type", 0);
                 
                     anim->getKeyFrames().push_back(KeyFrameAnimation<uint32>::KeyFrame(val, 
                                                                                    dur, 
                                                                                    type == 0 ? KFT_Linear : KFT_Discrete));
                     
                 }
                 
             } while(parser->toNextChild());
             
             storyboard->children().push_back(StoryBoard::AnimationInfo(time, 
                                                                        anim,
                                                                        prop));
         }
         return;
     } 
     
     
     if(type == L"color") {
         // to do
     } 
 }
Пример #4
0
    void Context::loadCfgFile(const UknString& name) {
        ContextCfg cfg;
        cfg.render_cfg.width = 800;
        cfg.render_cfg.height = 600;
        cfg.render_cfg.top = 0;
        cfg.render_cfg.left = 0;
        cfg.render_cfg.color_fmt = EF_RGBA8;
        cfg.render_cfg.depth_stencil_fmt = EF_D16;
        cfg.render_cfg.resizable = false;
        cfg.render_cfg.full_screen = false;
        cfg.render_cfg.show_mouse = true;
        cfg.render_cfg.sample_count = 0;
        cfg.render_cfg.sample_quality = 0;
        
        ConfigParserPtr configParser = AssetManager::Instance().load<ConfigParser>(name);
        if(configParser) {            
            if(configParser->toNode(L"/cfg/graphics")) {
                cfg.render_cfg.width        = configParser->getInt(L"width", cfg.render_cfg.width);
                cfg.render_cfg.height       = configParser->getInt(L"height", cfg.render_cfg.height);
                cfg.render_cfg.top          = configParser->getInt(L"top", cfg.render_cfg.top);
                cfg.render_cfg.left         = configParser->getInt(L"left", cfg.render_cfg.left);
                
                cfg.render_cfg.resizable    = configParser->getBool(L"resizable", cfg.render_cfg.resizable);
                cfg.render_cfg.show_mouse   = configParser->getBool(L"show_mouse", cfg.render_cfg.show_mouse);
                cfg.render_cfg.full_screen  = configParser->getBool(L"full_screen", cfg.render_cfg.full_screen);
                
                cfg.render_cfg.sample_count     = configParser->getInt(L"sample_count", cfg.render_cfg.sample_count);
                cfg.render_cfg.sample_quality   = configParser->getInt(L"sample_quality", cfg.render_cfg.sample_quality);
                
                UknString fmt_string;
                int fmt_id;
                
                fmt_string = configParser->getString(L"color_fmt", L"EF_ARGB8");
                fmt_id = fmt_string_to_element_format(fmt_string);
                if(fmt_id == -1) {
                    log_warning(format_string("ukn::Context::loadCfgFile: unknown color format %s, using EF_ARGB8", fmt_string.c_str()));
                    
                    cfg.render_cfg.color_fmt = (ElementFormat)fmt_id;
                }
                
                fmt_string = configParser->getString(L"depth_stencil_fmt", L"EF_D16");
                fmt_id = fmt_string_to_element_format(fmt_string);
                if(fmt_id == -1) {
                    log_warning(format_string("ukn::Context::loadCfgFile: unknown depth stencil format %s, using EF_D16", fmt_string.c_str()));
                    
                    cfg.render_cfg.depth_stencil_fmt = (ElementFormat)fmt_id;
                }
            }
            
            if(configParser->toNode(L"/cfg/plugins")) {
                cfg.graphic_factory_name = configParser->getString(L"graphic_factory", L"");
            }
        } else {
            log_warning(L"ukn::Context::loadCfgFile: unable to open config file " + name);
        }
        
        setCfg(cfg);

		
		if(!configParser) {
			saveCfgFile(L"config.xml");
		}
    }