示例#1
0
TextureCache::TextureCache():
        mCache(LruCache<const SkPixelRef*, Texture*>::kUnlimitedCapacity),
        mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)),
        mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE) {
    bool setSizeByProperty = false;
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) {
        INIT_LOGD("  Setting texture cache size to %sMB", property);
        setMaxSize(MB(atof(property)));
        setSizeByProperty = true;
    } else {
        INIT_LOGD("  Using default texture cache size of %.2fMB", DEFAULT_TEXTURE_CACHE_SIZE);
    }

    if (property_get(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, property, NULL) > 0) {
        float flushRate = atof(property);
        INIT_LOGD("  Setting texture cache flush rate to %.2f%%", flushRate * 100.0f);
        setFlushRate(flushRate);
    } else {
        INIT_LOGD("  Using default texture cache flush rate of %.2f%%",
                DEFAULT_TEXTURE_CACHE_FLUSH_RATE * 100.0f);
    }

    /// M: Expand texture cache size for project with large resolution.
    if (!setSizeByProperty) {
        if (DEFAULT_TEXTURE_CACHE_SCREEN_BASED_SIZE > DEFAULT_TEXTURE_CACHE_SIZE) {
            INIT_LOGD("  Setting texture cache size to %.2fMB by screen based size", DEFAULT_TEXTURE_CACHE_SCREEN_BASED_SIZE);
            setMaxSize(MB(DEFAULT_TEXTURE_CACHE_SCREEN_BASED_SIZE));
        }
    }

    init();
}
示例#2
0
/**
 * scales down the image to fit the max _width and _height dimensions and pads the borders with _color
 * image will have _width and _height as its dimensions after calling this method
 */
void Image::scaleFitPad(int _width, int _height, ofColor _color, bool _vcenter, bool _hcenter) {
  ofFbo compose;
  ofPixels pixels;

  setMaxSize(_width, _height);
  updateSize();

  compose.allocate(_width, _height, GL_RGBA);
  pixels.allocate(_width, _height, OF_IMAGE_COLOR_ALPHA);
  compose.begin();

  ofPushStyle();
  ofSetColor(_color);
  ofDrawRectangle(0, 0, _width, _height);

  ofSetColor(255, 255, 255);
  int vpos = 0;
  int hpos = 0;
  if (_vcenter == true)
    vpos = (_width - img->getWidth()) * .5;
  if (_hcenter == true)
    hpos = (_height - img->getHeight()) * .5;
  img->draw(vpos, hpos);
  ofPopStyle();
  compose.end();

  compose.readToPixels(pixels);
  img->setFromPixels(pixels.getPixels(), _width, _height, OF_IMAGE_COLOR_ALPHA, true);
  img->update();
  BasicScreenObject::setSize(_width, _height);
}
TextureCache::TextureCache()
        : mCache(LruCache<uint32_t, Texture*>::kUnlimitedCapacity)
        , mSize(0)
        , mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE))
        , mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE)
        , mAssetAtlas(nullptr) {
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, nullptr) > 0) {
        INIT_LOGD("  Setting texture cache size to %sMB", property);
        setMaxSize(MB(atof(property)));
    } else {
        INIT_LOGD("  Using default texture cache size of %.2fMB", DEFAULT_TEXTURE_CACHE_SIZE);
    }

    if (property_get(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, property, nullptr) > 0) {
        float flushRate = atof(property);
        INIT_LOGD("  Setting texture cache flush rate to %.2f%%", flushRate * 100.0f);
        setFlushRate(flushRate);
    } else {
        INIT_LOGD("  Using default texture cache flush rate of %.2f%%",
                DEFAULT_TEXTURE_CACHE_FLUSH_RATE * 100.0f);
    }

    mCache.setOnEntryRemovedListener(this);

    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
    INIT_LOGD("    Maximum texture dimension is %d pixels", mMaxTextureSize);

    mDebugEnabled = Properties::debugLevel & kDebugCaches;
}
示例#4
0
	void Window::setPropertyOverride(const std::string& _key, const std::string& _value)
	{
		/// @wproperty{Window, AutoAlpha, bool} Режим регулировки прозрачности опираясь на фокус ввода.
		if (_key == "AutoAlpha")
			setAutoAlpha(utility::parseValue<bool>(_value));

		/// @wproperty{Window, Snap, bool} Режим прилипания к краям экрана.
		else if (_key == "Snap")
			setSnap(utility::parseValue<bool>(_value));

		/// @wproperty{Window, MinSize, int int} Минимальный размер окна.
		else if (_key == "MinSize")
			setMinSize(utility::parseValue<IntSize>(_value));

		/// @wproperty{Window, MaxSize, int int} Максимальный размер окна.
		else if (_key == "MaxSize")
			setMaxSize(utility::parseValue<IntSize>(_value));

		/// @wproperty{Window, Movable, bool} Режим движения окна мышью за любой участок.
		else if (_key == "Movable")
			setMovable(utility::parseValue<bool>(_value));

		else
		{
			Base::setPropertyOverride(_key, _value);
			return;
		}

		eventChangeProperty(this, _key, _value);
	}
void NativeEditBox::setCaption(const String& caption) {
	if(caption.length() > mMaxSize) {
		setMaxSize(caption.length()+1);
	}
	//Label::setCaption(caption);
	EditBox::setText("");
	EditBox::setText(caption);
	EditBox::moveCursorHorizontal(caption.length(), false);
}
LayerCache::LayerCache(): mSize(0), mMaxSize(MB(DEFAULT_LAYER_CACHE_SIZE)) {
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_LAYER_CACHE_SIZE, property, NULL) > 0) {
        INIT_LOGD("  Setting layer cache size to %sMB", property);
        setMaxSize(MB(atof(property)));
    } else {
        INIT_LOGD("  Using default layer cache size of %.2fMB", DEFAULT_LAYER_CACHE_SIZE);
    }
}
RenderBufferCache::RenderBufferCache(): mSize(0), mMaxSize(MB(DEFAULT_RENDER_BUFFER_CACHE_SIZE)) {
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_RENDER_BUFFER_CACHE_SIZE, property, NULL) > 0) {
        INIT_LOGD("  Setting render buffer cache size to %sMB", property);
        setMaxSize(MB(atof(property)));
    } else {
        INIT_LOGD("  Using default render buffer cache size of %.2fMB",
                DEFAULT_RENDER_BUFFER_CACHE_SIZE);
    }
}
bool
FileLogHandler::setParam(const BaseString &param, const BaseString &value){
  if(param == "filename")
    return setFilename(value);
  if(param == "maxsize")
    return setMaxSize(value);
  if(param == "maxfiles")
    return setMaxFiles(value);
  setErrorStr("Invalid parameter");
  return false;
}
示例#9
0
/*************************************************************************
    Constructor
*************************************************************************/
Timer::Timer(const CEGUI::String& type, const CEGUI::String& name) :
    Window(type, name),
    d_delay(0),
    d_currentValue(0),
    d_started(false)
{
    CEGUI::USize sz(CEGUI::UDim(1.0, 0.0), CEGUI::UDim(1.0, 0.0));
    setMaxSize(sz);
    setSize(sz);
    addTimerProperties();
}
TextDropShadowCache::TextDropShadowCache():
        mCache(GenerationCache<ShadowText, ShadowTexture*>::kUnlimitedCapacity),
        mSize(0), mMaxSize(MB(DEFAULT_DROP_SHADOW_CACHE_SIZE)) {
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_DROP_SHADOW_CACHE_SIZE, property, NULL) > 0) {
        INIT_LOGD("  Setting drop shadow cache size to %sMB", property);
        setMaxSize(MB(atof(property)));
    } else {
        INIT_LOGD("  Using default drop shadow cache size of %.2fMB",
                DEFAULT_DROP_SHADOW_CACHE_SIZE);
    }

    init();
}
示例#11
0
NativeEditBox::NativeEditBox(int x, int y, int width, int height, int maxSize, int options, Widget *parent,
	const String& initialText, const WString& titleString, bool fresh) :
	EditBox(x, y, width, height, parent),
mTitleString(titleString),
mString(NULL),
mOptions(options), x(x), y(y), width(width), height(height), fresh(fresh)
{
	setFont(Util::getFontWhite());
	setMaxSize(maxSize);
	setCaption(initialText);
	Environment::getEnvironment().addPointerListener(this);
#if defined(MA_PROF_QWERTY)
	setInputMode(EditBox::IM_QWERTY);
#endif
}
TessellationCache::TessellationCache()
        : mSize(0)
        , mMaxSize(MB(DEFAULT_VERTEX_CACHE_SIZE))
        , mCache(LruCache<Description, Buffer*>::kUnlimitedCapacity)
        , mShadowCache(LruCache<ShadowDescription, Task<vertexBuffer_pair_t*>*>::kUnlimitedCapacity) {
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_VERTEX_CACHE_SIZE, property, NULL) > 0) {
        INIT_LOGD("  Setting %s cache size to %sMB", name, property);
        setMaxSize(MB(atof(property)));
    } else {
        INIT_LOGD("  Using default %s cache size of %.2fMB", name, DEFAULT_VERTEX_CACHE_SIZE);
    }

    mCache.setOnEntryRemovedListener(&mBufferRemovedListener);
    mShadowCache.setOnEntryRemovedListener(&mBufferPairRemovedListener);
    mDebugEnabled = readDebugLevel() & kDebugCaches;
}
示例#13
0
NativeEditBox::NativeEditBox(
	int x, 
	int y, 
	int width, 
	int height, 
	int maxSize, 
	int options,
	const String& initialText, 
	const WString& titleString)
		: Label(x, y, width, height, initialText),
		mTitleString(titleString),
		mString(NULL),
		mOptions(options),
		mEditBoxListeners(false)
{
	setMaxSize(maxSize);
	setCaption(initialText);
}
PathCache::PathCache():
        mCache(LruCache<PathDescription, PathTexture*>::kUnlimitedCapacity),
        mSize(0), mMaxSize(MB(DEFAULT_PATH_CACHE_SIZE)) {
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_PATH_CACHE_SIZE, property, NULL) > 0) {
        INIT_LOGD("  Setting %s cache size to %sMB", name, property);
        setMaxSize(MB(atof(property)));
    } else {
        INIT_LOGD("  Using default %s cache size of %.2fMB", name, DEFAULT_PATH_CACHE_SIZE);
    }

    mCache.setOnEntryRemovedListener(this);

    GLint maxTextureSize;
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
    mMaxTextureSize = maxTextureSize;

    mDebugEnabled = readDebugLevel() & kDebugCaches;
}
示例#15
0
 void Window::setPropertyOverride(const std::string& _key, const std::string& _value)
 {
     if (_key == "AutoAlpha")
         setAutoAlpha(utility::parseValue<bool>(_value));
     else if (_key == "Snap")
         setSnap(utility::parseValue<bool>(_value));
     else if (_key == "MinSize")
         setMinSize(utility::parseValue<IntSize>(_value));
     else if (_key == "MaxSize")
         setMaxSize(utility::parseValue<IntSize>(_value));
     else if (_key == "Movable")
         setMovable(utility::parseValue<bool>(_value));
     else
     {
         Base::setPropertyOverride(_key, _value);
         return;
     }
     eventChangeProperty(this, _key, _value);
 }
示例#16
0
文件: messages.cpp 项目: dganic/qutim
Tlv2711::Tlv2711(quint8 msgType, quint8 msgFlags, quint16 X1, quint16 X2, const Cookie &cookie):
	m_cookie(cookie)
{
	setMaxSize(0x1f18);
	append<quint16>(0x1B, LittleEndian);
	append<quint16>(protocol_version, LittleEndian);
	append(ICQ_CAPABILITY_PSIG_MESSAGE);
	append<quint8>(0); // not sure
	append<quint16>(client_features);
	append<quint32>(dc_type);
	append<quint16>(m_cookie.id(), LittleEndian);
	append<quint16>(0x0E, LittleEndian);
	append<quint16>(m_cookie.id(), LittleEndian);
	append<quint64>(0); // Unknown 12 bytes
	append<quint32>(0);
	append<quint8>(msgType);
	append<quint8>(msgFlags);
	append<quint16>(X1, LittleEndian);
	append<quint16>(X2, LittleEndian);
}
TextureCache::TextureCache():
        mCache(GenerationCache<SkBitmap*, Texture*>::kUnlimitedCapacity),
        mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)),
        mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE) {
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) {
        INIT_LOGD("  Setting texture cache size to %sMB", property);
        setMaxSize(MB(atof(property)));
    } else {
        INIT_LOGD("  Using default texture cache size of %.2fMB", DEFAULT_TEXTURE_CACHE_SIZE);
    }

    if (property_get(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, property, NULL) > 0) {
        float flushRate = atof(property);
        INIT_LOGD("  Setting texture cache flush rate to %.2f%%", flushRate * 100.0f);
        setFlushRate(flushRate);
    } else {
        INIT_LOGD("  Using default texture cache flush rate of %.2f%%",
                DEFAULT_TEXTURE_CACHE_FLUSH_RATE * 100.0f);
    }

    init();
}
示例#18
0
void TwWindow::setMaxSize(int w, int h)
{
    setMaxSize(TwSize<int>(w, h));
}
示例#19
0
	void Window::setMaxSize(int _width, int _height)
	{
		setMaxSize(IntSize(_width, _height));
	}
示例#20
0
MusicWindow::MusicWindow(QWidget *parent) : MainWindow(parent)
{
    this->setWindowIcon(QIcon(":/images/icons/app_icon"));

    systemTrayIcon = new MySystemTrayIcon(this);
    connect(systemTrayIcon, SIGNAL(showWindow()), this, SLOT(show()));
    connect(systemTrayIcon, SIGNAL(quit()), this, SLOT(close()));

    player = new MyPlayer();
    connect(player, SIGNAL(playerStateChanged(int)), this, SLOT(playerStateChanged(int)));
    connect(player, SIGNAL(musicChanged(QString,int)), this, SLOT(musicChanged(QString,int)));

    topBar = new TopBar(this);
    connect(topBar, SIGNAL(setMinSize()), this, SLOT(showMinimized()));
    connect(topBar, SIGNAL(setMaxSize()), this, SLOT(setMaxSize()));
    connect(topBar, SIGNAL(closeWindow()), this, SLOT(hide()));
    connect(topBar, SIGNAL(quit()), this, SLOT(close()));
    connect(topBar, SIGNAL(setBackgroud(QString)), this, SLOT(setBackgroud(QString)));
    connect(topBar, SIGNAL(aboutQtMusic()), this, SLOT(aboutQtMusic()));

    fuctionPage = new QStackedWidget;
    fuctionPage->setMinimumWidth(200);

    lyricLabel = new LyricLabel(false, this);
    connect(player, SIGNAL(positionChanged(qint64)), lyricLabel, SLOT(postionChanged(qint64)));
    connect(lyricLabel, SIGNAL(changeTo(qint64)), player, SLOT(setPosition(qint64)));

    networkPage = new NetworkPage();

    QLabel *label2 = new QLabel("Network");
    label2->setAlignment(Qt::AlignCenter);
    QLabel *label3 = new QLabel("Download");
    label3->setAlignment(Qt::AlignCenter);
    fuctionPage->addWidget(lyricLabel);
    fuctionPage->addWidget(networkPage);
    fuctionPage->addWidget(label3);
    fuctionPage->setCurrentIndex(0);
    connect(topBar, SIGNAL(selectFuction(int)), fuctionPage, SLOT(setCurrentIndex(int)));

    musicPage = new MusicPage;
    musicPage->setMaximumWidth(500);
    musicPage->setMinimumWidth(300);
    connect(musicPage, SIGNAL(tryToCreateList(QString)), this, SLOT(tryToCreateList(QString)));
    connect(musicPage, SIGNAL(deleteList(QString)), this, SLOT(deleteList(QString)));
    connect(musicPage, SIGNAL(addMusics()), this, SLOT(addMusics()));
    connect(musicPage, SIGNAL(play(QString,int)), player, SLOT(playTheMusic(QString,int)));
    connect(musicPage, SIGNAL(removeTheMusic(QString,int)), this, SLOT(removeTheMusic(QString,int)));
    connect(musicPage, SIGNAL(removeAllMusics(QString)), this, SLOT(removeAllMusics(QString)));
    connect(musicPage, SIGNAL(moveMusic(QString,int,int)), this, SLOT(moveMusic(QString,int,int)));

    bottomBar = new BottomBar(this);
    connect(bottomBar, SIGNAL(setVoice(int)), player, SLOT(setVoice(int)));
    connect(bottomBar, SIGNAL(setMode(int)), player, SLOT(setPlayMode(int)));
    connect(bottomBar, SIGNAL(setPostion(qint64)), player, SLOT(setPosition(qint64)));
    connect(bottomBar, SIGNAL(setPostion(qint64)), lyricLabel, SLOT(setPostion(qint64)));
    connect(player, SIGNAL(durationChanged(qint64)), bottomBar, SLOT(setMaxDuration(qint64)));
    connect(player, SIGNAL(positionChanged(qint64)), bottomBar, SLOT(changePostionTo(qint64)));
    connect(musicPage, SIGNAL(play(QString,int)), bottomBar, SLOT(setPostionAvailable()));
    connect(bottomBar, SIGNAL(tryplay()), this, SLOT(clickPlay()));
    connect(bottomBar, SIGNAL(playPre()), this, SLOT(playPre()));
    connect(bottomBar, SIGNAL(playNext()), this, SLOT(playNext()));
    connect(systemTrayIcon, SIGNAL(setMode(int)), bottomBar, SLOT(setPlayMode(int)));
    connect(bottomBar, SIGNAL(setMode(int)), systemTrayIcon, SLOT(setPlayMode(int)));
    connect(bottomBar, SIGNAL(showLyric(QString)), topBar, SLOT(changeFuction(QString)));
    //connect(lyricLabel, SIGNAL(changeTo(qint64)), bottomBar, SLOT(changePostionTo(qint64)));
    //connect(lyricLabel, SIGNAL(changeTo(qint64)), bottomBar, SIGNAL(setPostion(qint64)));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(topBar);

    QSplitter *splitter = new QSplitter(Qt::Horizontal, this);
    //设定分割窗口的分割条在拖动时是否为实时更新 true为实时更新 false则在拖动时只显示一条灰色的线条
    //在拖动到位并弹起鼠标后再显示分隔条
    splitter->setOpaqueResize(false);
    splitter->setChildrenCollapsible(false);
    splitter->addWidget(fuctionPage);
    splitter->addWidget(musicPage);
    splitter->setStretchFactor(0, 10);
    splitter->setStretchFactor(1, 1);
    splitter->setStyleSheet("QSplitter::handle { background-color: rgba(0,0,0,0%) }");
    splitter->setHandleWidth(4);
    mainLayout->addWidget(splitter);
    mainLayout->addWidget(bottomBar);
    mainLayout->setMargin(1);
    mainLayout->setSpacing(3);
    this->setLayout(mainLayout);

    dealMouse();
    readData();
}
示例#21
0
void CandidateSet::initTrees(CandidateSet& candSet) {
    int curMaxSize = this->maxSize;
    *this = candSet;
    setMaxSize(curMaxSize);
}
示例#22
0
 explicit TimeCache(size_t size) { setMaxSize(size); }
示例#23
0
ChatEventList::ChatEventList() {
	eventListEnd = &eventListRoot;
	setMaxSize(DEFAULT_MAX_SIZE);
	currentSize = 0;
}
示例#24
0
void CJsonRmgTemplateLoader::loadTemplates()
{
	const JsonNode rootNode(ResourceID("config/rmg.json"));
	for(const auto & templatePair : rootNode.Struct())
	{
		auto tpl = new CRmgTemplate();
		try
		{
			tpl->setName(templatePair.first);
			const auto & templateNode = templatePair.second;

			// Parse main template data
			tpl->setMinSize(parseMapTemplateSize(templateNode["minSize"].String()));
			tpl->setMaxSize(parseMapTemplateSize(templateNode["maxSize"].String()));
			tpl->setPlayers(parsePlayers(templateNode["players"].String()));
			tpl->setCpuPlayers(parsePlayers(templateNode["cpu"].String()));

			// Parse zones
			std::map<TRmgTemplateZoneId, CRmgTemplateZone *> zones;
			for (const auto & zonePair : templateNode["zones"].Struct())
			{
				auto zone = new CRmgTemplateZone();
				auto zoneId = boost::lexical_cast<TRmgTemplateZoneId>(zonePair.first);
				zone->setId(zoneId);

				const auto & zoneNode = zonePair.second;
				zone->setType(parseZoneType(zoneNode["type"].String()));
				zone->setSize(zoneNode["size"].Float());
				if (!zoneNode["owner"].isNull()) zone->setOwner(zoneNode["owner"].Float());

				zone->setPlayerTowns(parseTemplateZoneTowns(zoneNode["playerTowns"]));
				zone->setNeutralTowns(parseTemplateZoneTowns(zoneNode["neutralTowns"]));
				if (!zoneNode["matchTerrainToTown"].isNull()) //default : true
					zone->setMatchTerrainToTown(zoneNode["matchTerrainToTown"].Bool());
				zone->setTerrainTypes(parseTerrainTypes(zoneNode["terrainTypes"].Vector(), zone->getDefaultTerrainTypes()));

				if (!zoneNode["townsAreSameType"].isNull()) //default : false
					zone->setTownsAreSameType((zoneNode["townsAreSameType"].Bool()));

				for (int i = 0; i < 2; ++i)
				{
					std::set<TFaction> allowedTownTypes;
					if (i)
					{
						if (zoneNode["allowedTowns"].isNull())
							allowedTownTypes = zone->getDefaultTownTypes();
					}
					else
					{
						if (zoneNode["allowedMonsters"].isNull())
							allowedTownTypes = VLC->townh->getAllowedFactions(false);
					}

					if (allowedTownTypes.empty())
					{
						for (const JsonNode & allowedTown : zoneNode[i ? "allowedTowns" : "allowedMonsters"].Vector())
						{
							//complain if the town type is not present in our game
							if (auto id = VLC->modh->identifiers.getIdentifier("faction", allowedTown, false))
								allowedTownTypes.insert(id.get());
						}
					}

					if (!zoneNode[i ? "bannedTowns" : "bannedMonsters"].isNull())
					{
						for (const JsonNode & bannedTown : zoneNode[i ? "bannedTowns" : "bannedMonsters"].Vector())
						{
							//erase unindentified towns silently
							if (auto id = VLC->modh->identifiers.getIdentifier("faction", bannedTown, true))
								vstd::erase_if_present(allowedTownTypes, id.get());
						}
					}
					if (i)
						zone->setTownTypes(allowedTownTypes);
					else
						zone->setMonsterTypes(allowedTownTypes);
				}

				const std::string monsterStrength = zoneNode["monsters"].String();
				if (monsterStrength == "weak")
					zone->setMonsterStrength(EMonsterStrength::ZONE_WEAK);
				else if (monsterStrength == "normal")
					zone->setMonsterStrength(EMonsterStrength::ZONE_NORMAL);
				else if (monsterStrength == "strong")
					zone->setMonsterStrength(EMonsterStrength::ZONE_STRONG);
				else
					throw (rmgException("incorrect monster power"));

				if (!zoneNode["mines"].isNull())
				{
					auto mines = zoneNode["mines"].Struct();
					//FIXME: maybe there is a smarter way to parse it already?
					zone->setMinesAmount(Res::WOOD, mines["wood"].Float());
					zone->setMinesAmount(Res::ORE, mines["ore"].Float());
					zone->setMinesAmount(Res::GEMS, mines["gems"].Float());
					zone->setMinesAmount(Res::CRYSTAL, mines["crystal"].Float());
					zone->setMinesAmount(Res::SULFUR, mines["sulfur"].Float());
					zone->setMinesAmount(Res::MERCURY, mines["mercury"].Float());
					zone->setMinesAmount(Res::GOLD, mines["gold"].Float());
					//TODO: Mithril
				}

				//treasures
				if (!zoneNode["treasure"].isNull())
				{
					//TODO: parse vector of different treasure settings
					if (zoneNode["treasure"].getType() == JsonNode::DATA_STRUCT)
					{
						auto treasureInfo = zoneNode["treasure"].Struct();
						{
							CTreasureInfo ti;
							ti.min = treasureInfo["min"].Float();
							ti.max = treasureInfo["max"].Float();
							ti.density = treasureInfo["density"].Float(); //TODO: use me
							zone->addTreasureInfo(ti);
						}
					}
					else if (zoneNode["treasure"].getType() == JsonNode::DATA_VECTOR)
					{
						for (auto treasureInfo : zoneNode["treasure"].Vector())
						{
							CTreasureInfo ti;
							ti.min = treasureInfo["min"].Float();
							ti.max = treasureInfo["max"].Float();
							ti.density = treasureInfo["density"].Float();
							zone->addTreasureInfo(ti);
						}
					}
				}

				zones[zone->getId()] = zone;
			}

			//copy settings from already parsed zones
			for (const auto & zonePair : templateNode["zones"].Struct())
			{
				auto zoneId = boost::lexical_cast<TRmgTemplateZoneId>(zonePair.first);
				auto zone = zones[zoneId];

				const auto & zoneNode = zonePair.second;

				if (!zoneNode["terrainTypeLikeZone"].isNull())
				{
					int id = zoneNode["terrainTypeLikeZone"].Float();
					zone->setTerrainTypes(zones[id]->getTerrainTypes());
					zone->setMatchTerrainToTown(zones[id]->getMatchTerrainToTown());
				}

				if (!zoneNode["townTypeLikeZone"].isNull())
					zone->setTownTypes (zones[zoneNode["townTypeLikeZone"].Float()]->getTownTypes());

				if (!zoneNode["treasureLikeZone"].isNull())
				{
					for (auto treasureInfo : zones[zoneNode["treasureLikeZone"].Float()]->getTreasureInfo())
					{
						zone->addTreasureInfo(treasureInfo);
					}
				}

				if (!zoneNode["minesLikeZone"].isNull())
				{
					for (auto mineInfo : zones[zoneNode["minesLikeZone"].Float()]->getMinesInfo())
					{
						zone->setMinesAmount (mineInfo.first, mineInfo.second);
					}
					
				}
			}

			tpl->setZones(zones);

			// Parse connections
			std::list<CRmgTemplateZoneConnection> connections;
			for(const auto & connPair : templateNode["connections"].Vector())
			{
				CRmgTemplateZoneConnection conn;
				conn.setZoneA(zones.find(boost::lexical_cast<TRmgTemplateZoneId>(connPair["a"].String()))->second);
				conn.setZoneB(zones.find(boost::lexical_cast<TRmgTemplateZoneId>(connPair["b"].String()))->second);
				conn.setGuardStrength(connPair["guard"].Float());
				connections.push_back(conn);
			}
			tpl->setConnections(connections);
			{
				auto zones = tpl->getZones();
				for (auto con : tpl->getConnections())
				{
					auto idA = con.getZoneA()->getId();
					auto idB = con.getZoneB()->getId();
					zones[idA]->addConnection(idB);
					zones[idB]->addConnection(idA);
				}
			}
			tpl->validate();
			templates[tpl->getName()] = tpl;
		}
		catch(const std::exception & e)
		{
			logGlobal->errorStream() << boost::format("Template %s has errors. Message: %s.") % tpl->getName() % std::string(e.what());
		}
	}
}
示例#25
0
void CLayoutVertical::computeSize()
{
    // Nombre d'objets enfants
    const int nbr_children = getNumChildren();

    // Dimensions minimales et maximales du layout
    int min_height = 0;
    int max_height = 0;
    int min_width = 0;
    int max_width = 0;

    // Hauteur et largeur de chaque widget
    std::vector<int> widgets_h_min;
    std::vector<int> widgets_w_min;
    std::vector<int> widgets_h_max;
    std::vector<int> widgets_w_max;

    widgets_h_min.reserve(nbr_children);
    widgets_w_min.reserve(nbr_children);
    widgets_h_max.reserve(nbr_children);
    widgets_w_max.reserve(nbr_children);

    int totalStretch = 0;

    // On cherche la taille de chaque objet
    for (std::list<TLayoutItem>::const_iterator it = m_children.begin(); it != m_children.end(); ++it)
    {
        totalStretch += it->stretch;

        // Dimensions minimales
        int tmp_w = it->widget->getMinWidth();
        widgets_w_min.push_back(tmp_w);

        int tmp_h = it->widget->getMinHeight();
        widgets_h_min.push_back(tmp_h);

        tmp_w = SumInt(tmp_w, m_padding.getLeft() + m_padding.getRight());

        if (tmp_w > min_width)
        {
            min_width = tmp_w;
        }

        min_height = SumInt(min_height, SumInt(tmp_h, m_padding.getTop() + m_padding.getBottom()));

        // Dimensions maximales
        tmp_w = it->widget->getMaxWidth();
        widgets_w_max.push_back(tmp_w);

        tmp_h = it->widget->getMaxHeight();
        widgets_h_max.push_back(tmp_h);

        tmp_w = SumInt(tmp_w, m_padding.getLeft() + m_padding.getRight());

        if (tmp_w > max_width)
        {
            max_width = tmp_w;
        }

        max_height = SumInt(max_height, SumInt(tmp_h, m_padding.getTop() + m_padding.getBottom()));
    }

    min_width = SumInt(min_width, m_margin.getLeft() + m_margin.getRight());
    max_width = SumInt(max_width, m_margin.getLeft() + m_margin.getRight());

    min_height = SumInt(min_height, m_margin.getTop() + m_margin.getBottom());
    max_height = SumInt(max_height, m_margin.getTop() + m_margin.getBottom());

    setMinSize(min_width, min_height);
    setMaxSize(max_width, max_height);


    // Espace à répartir
    int residu = 0;

    if (min_height < m_height)
    {
        residu = m_height - min_height;
    }


    // Dimensions de chaque objet enfant
    std::vector<int> widgets_w;
    std::vector<int> widgets_h;

    widgets_w.reserve(nbr_children);
    widgets_h.reserve(nbr_children);

    int growingStretch = totalStretch;
    int growingChildren = nbr_children;

    // Calcul des dimensions de chaque objet enfant
    for (int i = 0; i < nbr_children; ++i)
    {
        if (widgets_w_min[i] < widgets_w_max[i])
        {
            if (widgets_w_max[i] < m_width - m_padding.getLeft() - m_padding.getRight())
                widgets_w[i] = widgets_w_min[i];
            else
                widgets_w[i] = m_width - m_padding.getLeft() - m_padding.getRight();
        }
        else
        {
            widgets_w[i] = widgets_w_min[i];
        }

        widgets_h[i] = widgets_h_min[i];

        if (widgets_h[i] >= widgets_h_max[i])
        {
            --growingChildren;
        }
    }


    while (residu > 0)
    {
        if (growingStretch == 0)
        {
            // Tous les widgets ont leur taille maximale
            if (growingChildren == 0)
            {
                int nbr_first = residu % nbr_children;
                int add_pixel = residu / nbr_children;
                residu = 0;

                int i = 0;

                // On modifie la taille des cases
                for (std::list<TLayoutItem>::iterator it = m_children.begin(); it != m_children.end(); ++it, ++i)
                {
                    it->size = widgets_h[i] + m_padding.getTop() + m_padding.getBottom() + add_pixel;
                    if (i < nbr_first)
                        ++(it->size);
                }
            }
            else
            {
                float pixelPerStretch = static_cast<float>(residu) / static_cast<float>(growingChildren);
                int pixelAdd = pixelPerStretch;

                if (pixelAdd == 0)
                {
                    growingChildren = 0;
                    continue;
                }

                int i = 0;

                // Pour chaque objet enfant
                for (std::list<TLayoutItem>::iterator it = m_children.begin(); it != m_children.end(); ++it, ++i)
                {
                    // On peut agrandir le widget
                    if (widgets_h[i] < widgets_h_max[i])
                    {
                        int pixelCanAdd = widgets_h_max[i] - widgets_h[i];

                        if (pixelCanAdd >= pixelAdd)
                        {
                            widgets_h[i] += pixelAdd;
                            residu -= pixelAdd;

                            if (pixelCanAdd == pixelAdd)
                            {
                                --growingChildren;
                            }
                        }
                        else
                        {
                            widgets_h[i] += pixelCanAdd;
                            residu -= pixelCanAdd;
                            --growingChildren;
                        }

                        it->size = widgets_h[i] + m_padding.getTop() + m_padding.getBottom();
                    }
                }
            }
        }
        else
        {
            float pixelPerStretch = static_cast<float>(residu) / static_cast<float>(growingStretch);

            if (pixelPerStretch < 1.0f)
            {
                growingStretch = 0;
                growingChildren = 0;
                continue;
            }

            bool noChange = true;
            int i = 0;

            // Pour chaque objet enfant
            for (std::list<TLayoutItem>::iterator it = m_children.begin(); it != m_children.end(); ++it, ++i)
            {
                // On peut agrandir le widget
                if (widgets_h[i] < widgets_h_max[i])
                {
                    int pixelAdd = pixelPerStretch * it->stretch;
                    int pixelCanAdd = widgets_h_max[i] - widgets_h[i];

                    if (pixelCanAdd >= pixelAdd)
                    {
                        widgets_h[i] += pixelAdd;
                        residu -= pixelAdd;

                        if (pixelCanAdd == pixelAdd)
                        {
                            --growingChildren;
                            growingStretch -= it->stretch;
                        }
                    }
                    else
                    {
                        widgets_h[i] += pixelCanAdd;
                        residu -= pixelCanAdd;

                        --growingChildren;
                        growingStretch -= it->stretch;
                    }

                    it->size = widgets_h[i] + m_padding.getTop() + m_padding.getBottom();

                    noChange = false;
                }
            }

            // Tous les widgets ont leur taille maximale
            if (noChange)
            {
                i = 0;

                // Pour chaque objet enfant
                for (std::list<TLayoutItem>::iterator it = m_children.begin(); it != m_children.end(); ++it, ++i)
                {
                    int pixelAdd = pixelPerStretch * it->stretch;
                    residu -= pixelAdd;
                    it->size = widgets_h[i] + m_padding.getTop() + m_padding.getBottom() + pixelAdd;
                }

                growingStretch = 0;
                growingChildren = 0;
            }
        }
    }


    int offset = m_margin.getTop();
    int i = 0;

    // On modifie la liste des objets
    for (std::list<TLayoutItem>::iterator it = m_children.begin(); it != m_children.end(); ++it, ++i)
    {
        // Dimensions de l'objet
        it->widget->setSize(widgets_w[i], widgets_h[i]);

        // Position de l'objet
        switch (it->align)
        {
            case AlignTopLeft:
                it->widget->setPosition(m_margin.getLeft() + m_padding.getLeft(), offset + m_padding.getTop());
                break;

            case AlignTopCenter:
                it->widget->setPosition((m_width - widgets_w[i]) / 2, offset + m_padding.getTop());
                break;

            case AlignTopRight:
                it->widget->setPosition(m_width - m_padding.getRight() - widgets_w[i], offset + m_padding.getTop());
                break;

            case AlignMiddleLeft:
                it->widget->setPosition(m_margin.getLeft() + m_padding.getLeft(), offset + (it->size - widgets_h[i]) / 2);
                break;

            default:
            case AlignMiddleCenter:
                it->widget->setPosition((m_width - widgets_w[i] ) / 2 , offset + (it->size - widgets_h[i]) / 2);
                break;

            case AlignMiddleRight:
                it->widget->setPosition(m_width - m_padding.getRight() - widgets_w[i], offset + (it->size - widgets_h[i]) / 2);
                break;

            case AlignBottomLeft:
                it->widget->setPosition(m_margin.getLeft() + m_padding.getLeft(), offset + it->size - widgets_h[i] - m_padding.getBottom());
                break;

            case AlignBottomCenter:
                it->widget->setPosition((m_width - widgets_w[i]) / 2 , offset + it->size - widgets_h[i] - m_padding.getBottom());
                break;

            case AlignBottomRight:
                it->widget->setPosition(m_width - m_padding.getRight() - widgets_w[i], offset + it->size - widgets_h[i] - m_padding.getBottom());
                break;
        }

        offset += it->size;
    }
}
void ZDvidDataSliceHelper::setUnlimitedSize()
{
  setMaxSize(0, 0);
}
示例#27
0
void NativeEditBox::setCaption(const String& caption) {
	if(caption.length() > mMaxSize) {
		setMaxSize(caption.length()+1);
	}
	Label::setCaption(caption);
}