void Sprite::SetScale(float scale)
{
    SetScale(Vector2(scale, scale));
}
Example #2
0
void
VectorAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("VectorAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("glyphLocation")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 2)
                SetGlyphLocation(GlyphLocation(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            GlyphLocation value;
            if(GlyphLocation_FromString(node->AsString(), value))
                SetGlyphLocation(value);
        }
    }
    if((node = searchNode->GetNode("useStride")) != 0)
        SetUseStride(node->AsBool());
    if((node = searchNode->GetNode("stride")) != 0)
        SetStride(node->AsInt());
    if((node = searchNode->GetNode("nVectors")) != 0)
        SetNVectors(node->AsInt());
    if((node = searchNode->GetNode("lineStyle")) != 0)
        SetLineStyle(node->AsInt());
    if((node = searchNode->GetNode("lineWidth")) != 0)
        SetLineWidth(node->AsInt());
    if((node = searchNode->GetNode("scale")) != 0)
        SetScale(node->AsDouble());
    if((node = searchNode->GetNode("scaleByMagnitude")) != 0)
        SetScaleByMagnitude(node->AsBool());
    if((node = searchNode->GetNode("autoScale")) != 0)
        SetAutoScale(node->AsBool());
    if((node = searchNode->GetNode("headSize")) != 0)
        SetHeadSize(node->AsDouble());
    if((node = searchNode->GetNode("headOn")) != 0)
        SetHeadOn(node->AsBool());
    if((node = searchNode->GetNode("colorByMag")) != 0)
        SetColorByMag(node->AsBool());
    if((node = searchNode->GetNode("useLegend")) != 0)
        SetUseLegend(node->AsBool());
    if((node = searchNode->GetNode("vectorColor")) != 0)
        vectorColor.SetFromNode(node);
    if((node = searchNode->GetNode("colorTableName")) != 0)
        SetColorTableName(node->AsString());
    if((node = searchNode->GetNode("invertColorTable")) != 0)
        SetInvertColorTable(node->AsBool());
    if((node = searchNode->GetNode("vectorOrigin")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 3)
                SetVectorOrigin(OriginType(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            OriginType value;
            if(OriginType_FromString(node->AsString(), value))
                SetVectorOrigin(value);
        }
    }
    if((node = searchNode->GetNode("minFlag")) != 0)
        SetMinFlag(node->AsBool());
    if((node = searchNode->GetNode("maxFlag")) != 0)
        SetMaxFlag(node->AsBool());
    if((node = searchNode->GetNode("limitsMode")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 2)
                SetLimitsMode(LimitsMode(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            LimitsMode value;
            if(LimitsMode_FromString(node->AsString(), value))
                SetLimitsMode(value);
        }
    }
    if((node = searchNode->GetNode("min")) != 0)
        SetMin(node->AsDouble());
    if((node = searchNode->GetNode("max")) != 0)
        SetMax(node->AsDouble());
    if((node = searchNode->GetNode("lineStem")) != 0)
        SetLineStem(node->AsBool());
    if((node = searchNode->GetNode("geometryQuality")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 2)
                SetGeometryQuality(Quality(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            Quality value;
            if(Quality_FromString(node->AsString(), value))
                SetGeometryQuality(value);
        }
    }
    if((node = searchNode->GetNode("stemWidth")) != 0)
        SetStemWidth(node->AsDouble());
    if((node = searchNode->GetNode("origOnly")) != 0)
        SetOrigOnly(node->AsBool());
    if((node = searchNode->GetNode("glyphType")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 2)
                SetGlyphType(GlyphType(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            GlyphType value;
            if(GlyphType_FromString(node->AsString(), value))
                SetGlyphType(value);
        }
    }
}
void Sprite::SetScale(float x, float y)
{
    SetScale(Vector2(x, y));
}
Example #4
0
void UIScrollView::Input(UIEvent *currentTouch)
{
//	if(currentTouch->tapCount == 2 && currentTouch->phase == UIControlTouch::PHASE_BEGAN)
//	{
//		float32 targetScale;
//		if(zoomScale < maxScale)
//		{
//			//zoom in
//			targetScale = maxScale;
//		}
//		else
//		{
//			targetScale = minScale;
//		}
//		LinearAnimation<float32> * scaleAnimation = new LinearAnimation<float32>(this, &zoomScale, targetScale, 0.5f,
//									Interpolation::EASY_IN_EASY_OUT);
//		scaleAnimation->Start(0);
//		
//		
//		{
//			float32 multScale = targetScale/zoomScale;
//			
//			if(targetScale < zoomScale)
//			{
//				LinearAnimation<float32> * xAnim = new LinearAnimation<float32>(this, &scrollOrigin.x, scrollZero.x, 0.5f, Interpolation::EASY_IN_EASY_OUT);
//				LinearAnimation<float32> * yAnim = new LinearAnimation<float32>(this, &scrollOrigin.y, scrollZero.y, 0.5f, Interpolation::EASY_IN_EASY_OUT);
//				xAnim->Start(1);
//				yAnim->Start(2);
//			}
//			else
//			{
//				Point2f adjPoint = Point2f(currentTouch->point.x*multScale, currentTouch->point.y*multScale);
//				Point2f delta = Point2f(adjPoint.x - currentTouch->point.x, adjPoint.y - currentTouch->point.y);
//				
//				LinearAnimation<float32> * xAnim = new LinearAnimation<float32>(this, &scrollOrigin.x, scrollOrigin.x-delta.x, 0.5f, Interpolation::EASY_IN_EASY_OUT);
//				LinearAnimation<float32> * yAnim = new LinearAnimation<float32>(this, &scrollOrigin.y, scrollOrigin.y-delta.y, 0.5f, Interpolation::EASY_IN_EASY_OUT);
//				
//				xAnim->Start(1);
//				yAnim->Start(2);
//			}
//		}
//	}
//  int32 saveState = state;
	
	Vector<UIEvent> touches = UIControlSystem::Instance()->GetAllInputs();
	if(1 == touches.size())
	{
        bool spaceIsPressed = InputSystem::Instance()->GetKeyboard()->IsKeyPressed(DVKEY_SPACE);
//        bool spaceIsPressed = false;
        if(!spaceIsPressed)
        {
            for(List<UIControl*>::iterator it = childs.begin(); it != childs.end(); ++it)
            {
                (*it)->Input(currentTouch);
            }

            return;
        }
        
        
		switch(currentTouch->phase) 
		{
			case UIEvent::PHASE_BEGAN:
			{
				scrollTouch = *currentTouch;
				
				Vector2 start = currentTouch->point;
				StartScroll(start);

				// init scrolling speed parameters
				scrollPixelsPerSecond = 0.0f;
				scrollStartTime = currentTouch->timestamp;//to avoid cast from uint64 to float64 SystemTimer::Instance()->AbsoluteMS();
				touchStartTime = SystemTimer::Instance()->AbsoluteMS();
				state = STATE_SCROLL;

				clickStartPosition = start;
			}
			break;
			case UIEvent::PHASE_DRAG:
			{
				if(state == STATE_SCROLL) 
				{
					if(currentTouch->tid == scrollTouch.tid)
					{
						// scrolling speed get parameters
						float64 scrollCurrentTime = currentTouch->timestamp;//SystemTimer::Instance()->AbsoluteMS();
						Vector2 scrollPrevPosition = scrollCurrentPosition;
						
						// perform scrolling
						ProcessScroll(currentTouch->point);
						
						// calculate scrolling speed
						float64 tmp = scrollCurrentTime;
						if(fabs(scrollCurrentTime - scrollStartTime) < 1e-9)
						{
							tmp += .1f;
						}
						
						Vector2 lineLength = scrollCurrentPosition - scrollPrevPosition;
						scrollPixelsPerSecond = (float32)((float64)lineLength.Length() / (tmp - scrollStartTime));
						scrollStartTime = scrollCurrentTime;
						
						///NSLog(@"pps:%f\n", scrollPixelsPerSecond);
					}
				}
			}
				break;
			case UIEvent::PHASE_ENDED:
			{
				if(state == STATE_SCROLL)
				{
					if(currentTouch->tid == scrollTouch.tid)
					{
						Vector2 scrollPrevPos = lastMousePositions[(positionIndex - 3) & (MAX_MOUSE_POSITIONS - 1)];
						Vector2 currentTouchPos = currentTouch->point; 
						
						deccelerationSpeed = Vector2(currentTouchPos.x, currentTouchPos.y);
						deccelerationSpeed.x -= scrollPrevPos.x;
						deccelerationSpeed.y -= scrollPrevPos.y;
						
						float32 deccelerationSpeedLen = sqrtf(deccelerationSpeed.x * deccelerationSpeed.x + deccelerationSpeed.y * deccelerationSpeed.y);
						if (deccelerationSpeedLen >= 0.00001f)
						{
							deccelerationSpeed.x /= deccelerationSpeedLen;
							deccelerationSpeed.y /= deccelerationSpeedLen;
						}
						else
						{
							deccelerationSpeed.x = 0.0f;
							deccelerationSpeed.y = 0.0f;
						}
						
						//Logger::Debug("Dcs: %f, %f\n", deccelerationSpeed.x, deccelerationSpeed.y);
						
						EndScroll();
						
						//scrollTouch = 0;
						if(scrollStartMovement)
						{
							state = STATE_DECCELERATION;
						}
						
						clickEndPosition = currentTouchPos;
					}
					
					if(touchStartTime)
					{
						touchStartTime = 0;
						PerformScroll();
					}
					
//					float32 clickLen = LineLength(clickStartPosition, clickEndPosition);
					
//					if (clickLen < SCROLL_BEGIN_PIXELS)
//					{			
//						clickEndPosition.x -= (scrollOrigin.x);
//						clickEndPosition.y -= (scrollOrigin.y);
//						
//						clickEndPosition.x /= zoomScale;
//						clickEndPosition.y /= zoomScale;
//						
//						UIControlTouch modifiedTouch = *currentTouch;
//						modifiedTouch.point = clickEndPosition;
//						
//						ScrollTouch(&modifiedTouch);
//					}	
				}
			}
				break;
		}
	}
	else if(2 == touches.size())
	{
		switch(currentTouch->phase) 
		{
			case UIEvent::PHASE_BEGAN:
			{
				if (state == STATE_SCROLL)
				{
					EndScroll();
					//scrollTouch = 0;
				}
				
				// init zoom parameters
				state = STATE_ZOOM;
				
				zoomTouches[0] = touches[0];
				zoomTouches[1] = touches[1];
				
				zoomStartPositions[0] = zoomTouches[0].point;
				zoomStartPositions[1] = zoomTouches[1].point;
				
				prevZoomScale = zoomScale; // save current scale to perform scaling in zoom mode
			}
			break;
			case UIEvent::PHASE_DRAG:
				if(state == STATE_ZOOM)
				{
					zoomTouches[0] = touches[0];
					zoomTouches[1] = touches[1];
					
					zoomCurrentPositions[0] = zoomTouches[0].point;
					zoomCurrentPositions[1] = zoomTouches[1].point;
					
					float initialDistance = sqrtf(
									  (zoomStartPositions[0].x - zoomStartPositions[1].x) * 
									  (zoomStartPositions[0].x - zoomStartPositions[1].x) + 
									  
									  (zoomStartPositions[0].y - zoomStartPositions[1].y) * 
									  (zoomStartPositions[0].y - zoomStartPositions[1].y));
					
					float currentDistance = sqrtf(
									  (zoomCurrentPositions[0].x - zoomCurrentPositions[1].x) * 
									  (zoomCurrentPositions[0].x - zoomCurrentPositions[1].x) + 
									  
									  (zoomCurrentPositions[0].y - zoomCurrentPositions[1].y) * 
									  (zoomCurrentPositions[0].y - zoomCurrentPositions[1].y));
					
					float32 saveZoomScale = zoomScale;
					float32 changeCoeff = initialDistance/currentDistance;
					float32 newScale = prevZoomScale * ((1.f - changeCoeff)/2.5f + 1.f);
					//float32 changeCoeff = currentDistance/initialDistance;
					//float32 newScale = prevZoomScale * changeCoeff * changeCoeff;
					if(newScale > maxScale)newScale = maxScale;
					if(newScale < minScale)newScale = minScale; 
					
					SetScale(newScale);
					
					Vector2 center = Vector2((zoomStartPositions[0].x + zoomStartPositions[1].x) / 2,
									(zoomStartPositions[0].y + zoomStartPositions[1].y) / 2);
					
					Vector2 scaleVectorOriginal = Vector2(center.x - scrollOrigin.x, center.y - scrollOrigin.y);
					Vector2 scaleVectorNew = scaleVectorOriginal;
					scaleVectorNew.x *= zoomScale / saveZoomScale;
					scaleVectorNew.y *= zoomScale / saveZoomScale;
					
					scaleVectorNew.x -= scaleVectorOriginal.x;
					scaleVectorNew.y -= scaleVectorOriginal.y;
					
					scrollOrigin.x -= scaleVectorNew.x;
					scrollOrigin.y -= scaleVectorNew.y;
				}
			break;
			case UIEvent::PHASE_ENDED:
			{
				Vector<UIEvent>::iterator it = touches.begin();
				bool zoomToScroll = false;
				for(; it != touches.end(); ++it)
				{
					if((*it).phase == UIEvent::PHASE_DRAG)
					{
						zoomToScroll = true;
						scrollTouch = *it;
					}
				}
				
				if(zoomToScroll)
				{
					//scrollTouch = *it;
					Vector2 start = scrollTouch.point;
					StartScroll(start);
					state = STATE_SCROLL;
					
					//zoomTouches[0] = 0;
					//zoomTouches[1] = 0;
				}
				else
				{
					if (state != STATE_DECCELERATION) 
					{
						state = STATE_NONE;
					}
				}
			}
			break;
		}
	}
	
//	if (saveState == state)
//	{
//		Logger::Debug("event: %d prevState: %d resultState: %d - alltouches: %d", currentTouch->phase, saveState, state, touches.size());
//	}else
//		Logger::Debug("CHANGED: event: %d prevState: %d resultState: %d - alltouches: %d", currentTouch->phase, saveState, state, touches.size());
}
Example #5
0
void Object3D::SetScale(float x, float y, float z)
{
	SetScale(Vector3f(x, y, z));
}
Example #6
0
// This is called when the screen gets or loses focus
void CMenuIntel::OnFocus(LTBOOL bFocus)
{
	if (!m_PopupText.IsVisible())
	{
		ClearSelection();
	}

	if (bFocus)
	{
		uint16 nextItem = 0;
		CIntelItemList *pList = g_pPlayerStats->GetIntelList();
		char szTemp[512] = "";
		for (uint16 i = 0; i < pList->GetCount(); i++)
		{
			uint16 nIndex = (pList->GetCount() - i) - 1;
			INTEL_ITEM* pItem = pList->Get(nIndex);
			if (!pItem)
			{
				continue;
			}

			GetIntelName(pItem->nTextId,szTemp,sizeof(szTemp));

			CLTGUITextCtrl* pCtrl = LTNULL;
			if (nextItem < m_List.GetNumControls())
			{
				pCtrl = (CLTGUITextCtrl*)m_List.GetControl(nextItem);
				if (pCtrl)
				{
					pCtrl->SetString(szTemp);
					pCtrl->Show(LTTRUE);
					nextItem++;
				}
			}
			else
			{
				uint16 ndx = AddControl(szTemp,MC_INTEL);
				pCtrl = (CLTGUITextCtrl*)m_List.GetControl(ndx);
				nextItem++;
			}

			if (pCtrl)
			{
				pCtrl->SetParam1(nIndex);
				if (pItem->bIsIntel)
				{
					pCtrl->SetColors(0xFFFF0000,0xFFA00000,m_DisabledColor);
				}
				else
				{
					pCtrl->SetColors(m_SelectedColor,m_NonSelectedColor,m_DisabledColor);
				}
			}
		}

		for (uint16 nIndex = nextItem; nIndex < m_List.GetNumControls(); nIndex++)
		{
					 
			CLTGUITextCtrl* pCtrl = (CLTGUITextCtrl*)m_List.GetControl(nIndex);
			if (pCtrl)
			{
				pCtrl->Show(LTFALSE);
			}
		}

		if (m_fScale != g_pInterfaceResMgr->GetXRatio())
		{
			SetScale(g_pInterfaceResMgr->GetXRatio());
		}

		SetSelection(GetIndex(&m_List));
	}
}
Example #7
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int32_t OTOffer::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
    int32_t nReturnVal = 0;

    // Here we call the parent class first.
    // If the node is found there, or there is some error,
    // then we just return either way.  But if it comes back
    // as '0', then nothing happened, and we'll continue executing.
    //
    // -- Note you can choose not to call the parent if
    // you don't want to use any of those xml tags.
    // As I do below, in the case of OTAccount.
    // if (nReturnVal = OTContract::ProcessXMLNode(xml))
    //    return nReturnVal;

    if (!strcmp("marketOffer", xml->getNodeName())) {
        m_strVersion = xml->getAttributeValue("version");

        String strIsSelling;
        strIsSelling = xml->getAttributeValue("isSelling");
        if (strIsSelling.Compare("true"))
            m_bSelling = true;
        else
            m_bSelling = false;

        m_strContractType.Set((m_bSelling ? "ASK" : "BID"));

        const String strNotaryID(xml->getAttributeValue("notaryID")),
            strInstrumentDefinitionID(
                xml->getAttributeValue("instrumentDefinitionID")),
            strCurrencyTypeID(xml->getAttributeValue("currencyTypeID"));

        const Identifier NOTARY_ID(strNotaryID),
            INSTRUMENT_DEFINITION_ID(strInstrumentDefinitionID),
            CURRENCY_TYPE_ID(strCurrencyTypeID);

        SetNotaryID(NOTARY_ID);
        SetInstrumentDefinitionID(INSTRUMENT_DEFINITION_ID);
        SetCurrencyID(CURRENCY_TYPE_ID);

        const String strScale = xml->getAttributeValue("marketScale");
        const int64_t lScale =
            strScale.Exists() ? strScale.ToLong() : 0; // if it doesn't exist,
                                                       // the 0 here causes the
                                                       // below error to fire.

        if (!isPowerOfTen(lScale)) {
            otOut << "OTOffer::ProcessXMLNode: Failure: marketScale *must* be "
                     "1, or a power of 10. Instead I got: " << lScale << ".\n";
            return (-1);
        }
        else
            SetScale(lScale);

        const String strPriceLimit = xml->getAttributeValue("priceLimit");
        const int64_t lPriceLimit = strPriceLimit.Exists()
                                        ? strPriceLimit.ToLong()
                                        : 0; // if it doesn't exist, the 0 here
                                             // causes the below error to fire.

        // NOTE: Market Orders (new) have a 0 price, so this error condition was
        // changed.
        if (!strPriceLimit.Exists())
        //      if (lPriceLimit < 1)
        {
            otOut << "OTOffer::ProcessXMLNode: Failure: priceLimit *must* be "
                     "provided(" << lPriceLimit << ").\n";
            return (-1);
        }
        else
            SetPriceLimit(lPriceLimit);

        const String strTotal = xml->getAttributeValue("totalAssetsOnOffer");
        const int64_t lTotal =
            strTotal.Exists() ? strTotal.ToLong() : 0; // if it doesn't exist,
                                                       // the 0 here causes the
                                                       // below error to fire.
        if (lTotal < 1) {
            otOut << "OTOffer::ProcessXMLNode: Failure: totalAssetsOnOffer "
                     "*must* be larger than 0. Instead I got: " << lTotal
                  << ".\n";
            return (-1);
        }
        else
            SetTotalAssetsOnOffer(lTotal);

        const String strFinished = xml->getAttributeValue("finishedSoFar");
        const int64_t lFinished = strFinished.Exists()
                                      ? strFinished.ToLong()
                                      : 0; // if it doesn't exist, the 0 here
                                           // causes the below error to fire.
        if (lFinished < 0) {
            otOut << "OTOffer::ProcessXMLNode: Failure: finishedSoFar *must* "
                     "be 0 or larger. Instead I got: " << lFinished << ".\n";
            return (-1);
        }
        else
            SetFinishedSoFar(lFinished);

        const String strMinInc = xml->getAttributeValue("minimumIncrement");
        // if it doesn't exist, the 0 here causes the below error to fire.
        const int64_t lMinInc = strMinInc.Exists() ? strMinInc.ToLong() : 0;

        if ((lMinInc < 1) || (lMinInc > lTotal)) // Minimum increment cannot
                                                 // logically be higher than the
                                                 // total assets on offer...
        {
            otOut << "OTOffer::ProcessXMLNode: Failure: minimumIncrement "
                     "*must* be 1 or larger, \n"
                     "and must also be less than the total assets on offer. "
                     "Instead I got: " << lMinInc << ".\n";
            return (-1);
        }
        else
            SetMinimumIncrement(lMinInc);

        const String strTransNum = xml->getAttributeValue("transactionNum");
        const int64_t lTransNum =
            strTransNum.Exists() ? strTransNum.ToLong() : 0;

        SetTransactionNum(lTransNum);

        const String str_valid_from = xml->getAttributeValue("validFrom");
        const String str_valid_to = xml->getAttributeValue("validTo");

        int64_t tValidFrom =
            str_valid_from.Exists() ? parseTimestamp(str_valid_from.Get()) : 0;
        int64_t tValidTo =
            str_valid_to.Exists() ? parseTimestamp(str_valid_to.Get()) : 0;

        if ((tValidTo < tValidFrom) && (tValidTo != 0)) {
            otOut << "OTOffer::" << __FUNCTION__ << ": Failure: validTo date ("
                  << tValidFrom << ") cannot be earlier than "
                                   "validFrom date (" << tValidTo << ").\n";
            return (-1);
        }

        SetValidFrom(OTTimeGetTimeFromSeconds(tValidFrom));
        SetValidTo(OTTimeGetTimeFromSeconds(tValidTo));

        otLog4 << "\n\nOffer. Transaction Number: " << m_lTransactionNum
               << "\n Valid From: " << tValidFrom << "\n Valid To: " << tValidTo
               << "\n"
                  " InstrumentDefinitionID: " << strInstrumentDefinitionID
               << "\n  CurrencyTypeID: " << strCurrencyTypeID
               << "\n NotaryID: " << strNotaryID
               << "\n"
                  " Price Limit: " << GetPriceLimit()
               << ",  Total Assets on Offer: " << GetTotalAssetsOnOffer()
               << ",  " << (m_bSelling ? "sold" : "bought")
               << " so far: " << GetFinishedSoFar() << "\n "
                                                       " Scale: " << GetScale()
               << ".   Minimum Increment: " << GetMinimumIncrement()
               << ".  This offer is a" << (m_bSelling ? "n ASK" : " BID")
               << ".\n";

        nReturnVal = 1;
    }

    return nReturnVal;
}
Example #8
0
CPLErr VRTRasterBand::XMLInit( CPLXMLNode * psTree, 
                               const char *pszVRTPath )

{
/* -------------------------------------------------------------------- */
/*      Validate a bit.                                                 */
/* -------------------------------------------------------------------- */
    if( psTree == NULL || psTree->eType != CXT_Element
        || !EQUAL(psTree->pszValue,"VRTRasterBand") )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "Invalid node passed to VRTRasterBand::XMLInit()." );
        return CE_Failure;
    }

/* -------------------------------------------------------------------- */
/*      Set the band if provided as an attribute.                       */
/* -------------------------------------------------------------------- */
    const char* pszBand = CPLGetXMLValue( psTree, "band", NULL);
    if( pszBand != NULL )
    {
        nBand = atoi(pszBand);
    }

/* -------------------------------------------------------------------- */
/*      Set the band if provided as an attribute.                       */
/* -------------------------------------------------------------------- */
    const char *pszDataType = CPLGetXMLValue( psTree, "dataType", NULL);
    if( pszDataType != NULL )
    {
        eDataType = GDALGetDataTypeByName(pszDataType);
    }

/* -------------------------------------------------------------------- */
/*      Apply any band level metadata.                                  */
/* -------------------------------------------------------------------- */
    oMDMD.XMLInit( psTree, TRUE );

/* -------------------------------------------------------------------- */
/*      Collect various other items of metadata.                        */
/* -------------------------------------------------------------------- */
    SetDescription( CPLGetXMLValue( psTree, "Description", "" ) );
    
    if( CPLGetXMLValue( psTree, "NoDataValue", NULL ) != NULL )
        SetNoDataValue( CPLAtofM(CPLGetXMLValue( psTree, "NoDataValue", "0" )) );

    if( CPLGetXMLValue( psTree, "HideNoDataValue", NULL ) != NULL )
        bHideNoDataValue = CSLTestBoolean( CPLGetXMLValue( psTree, "HideNoDataValue", "0" ) );

    SetUnitType( CPLGetXMLValue( psTree, "UnitType", NULL ) );

    SetOffset( CPLAtof(CPLGetXMLValue( psTree, "Offset", "0.0" )) );
    SetScale( CPLAtof(CPLGetXMLValue( psTree, "Scale", "1.0" )) );

    if( CPLGetXMLValue( psTree, "ColorInterp", NULL ) != NULL )
    {
        const char *pszInterp = CPLGetXMLValue( psTree, "ColorInterp", NULL );
        SetColorInterpretation(GDALGetColorInterpretationByName(pszInterp));
    }

/* -------------------------------------------------------------------- */
/*      Category names.                                                 */
/* -------------------------------------------------------------------- */
    if( CPLGetXMLNode( psTree, "CategoryNames" ) != NULL )
    {
        CPLXMLNode *psEntry;

        CSLDestroy( papszCategoryNames );
        papszCategoryNames = NULL;

        CPLStringList oCategoryNames;

        for( psEntry = CPLGetXMLNode( psTree, "CategoryNames" )->psChild;
             psEntry != NULL; psEntry = psEntry->psNext )
        {
            if( psEntry->eType != CXT_Element 
                || !EQUAL(psEntry->pszValue,"Category") 
                || (psEntry->psChild != NULL && psEntry->psChild->eType != CXT_Text) )
                continue;
            
            oCategoryNames.AddString(
                                (psEntry->psChild) ? psEntry->psChild->pszValue : "");
        }

        papszCategoryNames = oCategoryNames.StealList();
    }

/* -------------------------------------------------------------------- */
/*      Collect a color table.                                          */
/* -------------------------------------------------------------------- */
    if( CPLGetXMLNode( psTree, "ColorTable" ) != NULL )
    {
        CPLXMLNode *psEntry;
        GDALColorTable oTable;
        int        iEntry = 0;

        for( psEntry = CPLGetXMLNode( psTree, "ColorTable" )->psChild;
             psEntry != NULL; psEntry = psEntry->psNext )
        {
            GDALColorEntry sCEntry;

            sCEntry.c1 = (short) atoi(CPLGetXMLValue( psEntry, "c1", "0" ));
            sCEntry.c2 = (short) atoi(CPLGetXMLValue( psEntry, "c2", "0" ));
            sCEntry.c3 = (short) atoi(CPLGetXMLValue( psEntry, "c3", "0" ));
            sCEntry.c4 = (short) atoi(CPLGetXMLValue( psEntry, "c4", "255" ));

            oTable.SetColorEntry( iEntry++, &sCEntry );
        }
        
        SetColorTable( &oTable );
    }

/* -------------------------------------------------------------------- */
/*      Histograms                                                      */
/* -------------------------------------------------------------------- */
    CPLXMLNode *psHist = CPLGetXMLNode( psTree, "Histograms" );
    if( psHist != NULL )
    {
        CPLXMLNode *psNext = psHist->psNext;
        psHist->psNext = NULL;

        psSavedHistograms = CPLCloneXMLTree( psHist );
        psHist->psNext = psNext;
    }

/* ==================================================================== */
/*      Overviews                                                       */
/* ==================================================================== */
    CPLXMLNode *psNode;

    for( psNode = psTree->psChild; psNode != NULL; psNode = psNode->psNext )
    {
        if( psNode->eType != CXT_Element
            || !EQUAL(psNode->pszValue,"Overview") )
            continue;

/* -------------------------------------------------------------------- */
/*      Prepare filename.                                               */
/* -------------------------------------------------------------------- */
        char *pszSrcDSName = NULL;
        CPLXMLNode* psFileNameNode=CPLGetXMLNode(psNode,"SourceFilename");
        const char *pszFilename = 
            psFileNameNode ? CPLGetXMLValue(psFileNameNode,NULL, NULL) : NULL;

        if( pszFilename == NULL )
        {
            CPLError( CE_Warning, CPLE_AppDefined, 
                      "Missing <SourceFilename> element in Overview." );
            return CE_Failure;
        }

        if (EQUALN(pszFilename, "MEM:::", 6) && pszVRTPath != NULL &&
            !CSLTestBoolean(CPLGetConfigOption("VRT_ALLOW_MEM_DRIVER", "NO")))
        {
            CPLError( CE_Failure, CPLE_AppDefined,
                    "<SourceFilename> points to a MEM dataset, which is rather suspect! "
                    "If you know what you are doing, define the VRT_ALLOW_MEM_DRIVER configuration option to YES" );
            return CE_Failure;
        }

        if( pszVRTPath != NULL
            && atoi(CPLGetXMLValue( psFileNameNode, "relativetoVRT", "0")) )
        {
            pszSrcDSName = CPLStrdup(
                CPLProjectRelativeFilename( pszVRTPath, pszFilename ) );
        }
        else
            pszSrcDSName = CPLStrdup( pszFilename );

/* -------------------------------------------------------------------- */
/*      Get the raster band.                                            */
/* -------------------------------------------------------------------- */
        int nSrcBand = atoi(CPLGetXMLValue(psNode,"SourceBand","1"));

        apoOverviews.resize( apoOverviews.size() + 1 );
        apoOverviews[apoOverviews.size()-1].osFilename = pszSrcDSName;
        apoOverviews[apoOverviews.size()-1].nBand = nSrcBand;
        
        CPLFree( pszSrcDSName );
    }

/* ==================================================================== */
/*      Mask band (specific to that raster band)                        */
/* ==================================================================== */
    CPLXMLNode* psMaskBandNode = CPLGetXMLNode(psTree, "MaskBand");
    if (psMaskBandNode)
        psNode = psMaskBandNode->psChild;
    else
        psNode = NULL;
    for( ; psNode != NULL; psNode = psNode->psNext )
    {
        if( psNode->eType != CXT_Element
            || !EQUAL(psNode->pszValue,"VRTRasterBand") )
            continue;

        if( ((VRTDataset*)poDS)->poMaskBand != NULL)
        {
            CPLError( CE_Warning, CPLE_AppDefined,
                       "Illegal mask band at raster band level when a dataset mask band already exists." );
            break;
        }

        const char *pszSubclass = CPLGetXMLValue( psNode, "subclass",
                                                    "VRTSourcedRasterBand" );
        VRTRasterBand  *poBand = NULL;

        if( EQUAL(pszSubclass,"VRTSourcedRasterBand") )
            poBand = new VRTSourcedRasterBand( GetDataset(), 0 );
        else if( EQUAL(pszSubclass, "VRTDerivedRasterBand") )
            poBand = new VRTDerivedRasterBand( GetDataset(), 0 );
        else if( EQUAL(pszSubclass, "VRTRawRasterBand") )
            poBand = new VRTRawRasterBand( GetDataset(), 0 );
        else if( EQUAL(pszSubclass, "VRTWarpedRasterBand") )
            poBand = new VRTWarpedRasterBand( GetDataset(), 0 );
        else
        {
            CPLError( CE_Failure, CPLE_AppDefined,
                        "VRTRasterBand of unrecognised subclass '%s'.",
                        pszSubclass );
            break;
        }


        if( poBand->XMLInit( psNode, pszVRTPath ) == CE_None )
        {
            SetMaskBand(poBand);
        }

        break;
    }

    return CE_None;
}
Example #9
0
File: paddle.cpp Project: d10p/pong
Paddle::Paddle(float x, float y, float w, float h, float ds, bool vis) :
	Entity(x, y, w, h, vis), defaultSpeed(ds), score(0)
{
	SetPosition(X, Y);
	SetScale(W, H);
}
Example #10
0
void
WindowProjection::SetScaleFromRadius(fixed radius)
{
  SetScale(fixed(GetMinScreenDistance()) / (radius * 2));
}