/*!
   Draws the label for a major scale tick

   \param painter Painter
   \param value Value

   \sa drawTick(), drawBackbone()
*/
void QwtRoundScaleDraw::drawLabel( QPainter *painter, double value ) const
{
    const QwtText label = tickLabel( painter->font(), value );
    if ( label.isEmpty() )
        return;

    const double tval = scaleMap().transform( value );
    if ( ( tval > d_data->startAngle + 359 * 16 )
        || ( tval < d_data->startAngle - 359 * 16 ) )
    {
        return;
    }

    double radius = d_data->radius;
    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ||
        hasComponent( QwtAbstractScaleDraw::Backbone ) )
    {
        radius += spacing();
    }

    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) )
        radius += tickLength( QwtScaleDiv::MajorTick );

    const QSizeF sz = label.textSize( painter->font() );
    const double arc = tval / 16.0 / 360.0 * 2 * M_PI;

    const double x = d_data->center.x() +
        ( radius + sz.width() / 2.0 ) * qSin( arc );
    const double y = d_data->center.y() -
        ( radius + sz.height() / 2.0 ) * cos( arc );

    const QRectF r( x - sz.width() / 2, y - sz.height() / 2,
        sz.width(), sz.height() );
    label.draw( painter, r );
}
Exemple #2
0
/*!
   Calculate the minimum length that is needed to draw the scale

   \param font Font used for painting the labels
   \return Minimum length that is needed to draw the scale

   \sa extent()
*/
int QwtScaleDraw::minLength( const QFont &font ) const
{
    int startDist, endDist;
    getBorderDistHint( font, startDist, endDist );

    const QwtScaleDiv &sd = scaleDiv();

    const uint minorCount =
        sd.ticks( QwtScaleDiv::MinorTick ).count() +
        sd.ticks( QwtScaleDiv::MediumTick ).count();
    const uint majorCount =
        sd.ticks( QwtScaleDiv::MajorTick ).count();

    int lengthForLabels = 0;
    if ( hasComponent( QwtAbstractScaleDraw::Labels ) )
        lengthForLabels = minLabelDist( font ) * majorCount;

    int lengthForTicks = 0;
    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) )
    {
        const double pw = qMax( 1, penWidth() );  // penwidth can be zero
        lengthForTicks = qCeil( ( majorCount + minorCount ) * ( pw + 1.0 ) );
    }

    return startDist + endDist + qMax( lengthForLabels, lengthForTicks );
}
Exemple #3
0
/*!
   Calculate the width/height that is needed for a
   vertical/horizontal scale.

   The extent is calculated from the pen width of the backbone,
   the major tick length, the spacing and the maximum width/height
   of the labels.

   \param pen Pen that is used for painting backbone and ticks
   \param font Font used for painting the labels

   \sa minLength()
*/
int QwtScaleDraw::extent(const QPen &pen, const QFont &font) const
{
    int d = 0;

    if ( hasComponent(QwtAbstractScaleDraw::Labels) )
    {
        if ( orientation() == Qt::Vertical )
            d = maxLabelWidth(font);
        else
            d = maxLabelHeight(font);

        if ( d > 0 )
            d += spacing();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
    {
        d += majTickLength();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Backbone) )
    {
        const int pw = qwtMax( 1, pen.width() );  // penwidth can be zero
        d += pw;
    }

    d = qwtMax(d, minimumExtent());
    return d;
}
Exemple #4
0
/*!
   Calculate the minimum length that is needed to draw the scale

   \param pen Pen that is used for painting backbone and ticks
   \param font Font used for painting the labels

   \sa extent()
*/
int QwtScaleDraw::minLength(const QPen &pen, const QFont &font) const
{
    int startDist, endDist;
    getBorderDistHint(font, startDist, endDist);

    const QwtScaleDiv &sd = scaleDiv();

    const uint minorCount =
        sd.ticks(QwtScaleDiv::MinorTick).count() +
        sd.ticks(QwtScaleDiv::MediumTick).count();
    const uint majorCount =
        sd.ticks(QwtScaleDiv::MajorTick).count();

    int lengthForLabels = 0;
    if ( hasComponent(QwtAbstractScaleDraw::Labels) )
    {
        if ( majorCount >= 2 )
            lengthForLabels = minLabelDist(font) * (majorCount - 1);
    }

    int lengthForTicks = 0;
    if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
    {
        const int pw = qwtMax( 1, pen.width() );  // penwidth can be zero
        lengthForTicks = 2 * (majorCount + minorCount) * pw;
    }

    return startDist + endDist + qwtMax(lengthForLabels, lengthForTicks);
}
void ComponentManager<T>::addComponent(id entity)
{
    if (hasComponent(entity)) {
        resetComponent(entity);
    } else {
        reserveComponentIndex(entity);
        deletedComponentsIndex.size() == 0 ? createComponent(entity) : reuseComponent(entity);
        fireEntityAddedSignal(entity);
    }
}
/*!
   Find the position, where to paint a label

   The position has a distance of majTickLength() + spacing() + 1
   from the backbone. The direction depends on the alignment()

   \param value Value
*/
QPointF QwtScaleDraw::labelPosition( double value ) const
{
    const double tval = map().transform( value );
    double dist = spacing();
    if ( hasComponent( QwtAbstractScaleDraw::Backbone ) )
        dist += qMax( 1, penWidth() );

    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) )
        dist += majTickLength();

    double px = 0;
    double py = 0;

    switch ( alignment() )
    {
        case RightScale:
        {
            px = d_data->pos.x() + dist;
            py = tval;
            break;
        }
        case LeftScale:
        {
            px = d_data->pos.x() - dist;
            py = tval;
            break;
        }
        case BottomScale:
        {
            px = tval;
            py = d_data->pos.y() + dist;
            break;
        }
        case TopScale:
        {
            px = tval;
            py = d_data->pos.y() - dist;
            break;
        }
    }

    return QPointF( px, py );
}
Exemple #7
0
void ResourceDock::manageUsedResource(const QHash<size_t, QVector<Kite::KMetaProperty>> *ResComponents) {
	if (ResComponents->empty()) {
		return;
	}

	for (auto it = resMap.begin(); it != resMap.end(); ++it) {
		if (it.value().second == Kite::RTypes::Scene) {
			Kite::KFIStream stream;
			auto scene = (Kite::KScene *)load(&stream, it.key());
			auto eman = scene->getEManager();

			scene->clearResources();

			auto econtiner = eman->getEntityStorage();
			for (auto eit = econtiner->begin(); eit != econtiner->end(); ++eit) {

				// first we collect scripts from logic components
				std::vector<Kite::KHandle> lcomps;
				eit->getScriptComponents(lcomps);
				for (auto sit = lcomps.begin(); sit != lcomps.end(); ++sit) {
					auto script = (Kite::KLogicCom *)eit->getComponentByHandle((*sit));
					if (!script->getScript().str.empty()) {
						scene->addResource(script->getScript().str, Kite::RTypes::Script);
					}
				}

				// then we collect resources from other components
				for (auto cit = ResComponents->begin(); cit != ResComponents->end(); ++cit) {
					if (cit.key() == (size_t)Kite::CTypes::Logic) {
						continue;
					}

					if (eit->hasComponent((Kite::CTypes)cit.key())) {
						for (auto pit = cit->begin(); pit != cit->end(); ++pit) {
							auto com = eit->getComponent((Kite::CTypes)cit.key());
							auto res = com->getProperty(pit->name);
							std::string resName;
							if (pit->typeName == "std::string") {
								resName = res.as<std::string>();
							} else if (pit->typeName == "KStringID") {
								resName = res.as<Kite::KStringID>().str;
							}
							
							if (!resName.empty()) {
								scene->addResource(resName, pit->resType);
							}
						}
					}
				}
			}
		}
	}
}
/*!
   Calculate the extent of the scale

   The extent is the distance between the baseline to the outermost
   pixel of the scale draw. radius() + extent() is an upper limit
   for the radius of the bounding circle.

   \param font Font used for painting the labels

   \sa setMinimumExtent(), minimumExtent()
   \warning The implemented algo is not too smart and
            calculates only an upper limit, that might be a
            few pixels too large
*/
double QwtRoundScaleDraw::extent( const QFont &font ) const
{
    double d = 0.0;

    if ( hasComponent( QwtAbstractScaleDraw::Labels ) )
    {
        const QwtScaleDiv &sd = scaleDiv();
        const QList<double> &ticks = sd.ticks( QwtScaleDiv::MajorTick );
        for ( int i = 0; i < ticks.count(); i++ )
        {
            const double value = ticks[i];
            if ( !sd.contains( value ) )
                continue;

            const QwtText label = tickLabel( font, value );
            if ( label.isEmpty() )
                continue;

            const double tval = scaleMap().transform( value );
            if ( ( tval < d_data->startAngle + 360 * 16 )
                && ( tval > d_data->startAngle - 360 * 16 ) )
            {
                const double arc = tval / 16.0 / 360.0 * 2 * M_PI;

                const QSizeF sz = label.textSize( font );
                const double off = qMax( sz.width(), sz.height() );

                double x = off * qSin( arc );
                double y = off * qCos( arc );

                const double dist = qSqrt( x * x + y * y );
                if ( dist > d )
                    d = dist;
            }
        }
    }

    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) )
    {
        d += maxTickLength();
    }

    if ( hasComponent( QwtAbstractScaleDraw::Backbone ) )
    {
        const double pw = qMax( 1, penWidth() );  // penwidth can be zero
        d += pw;
    }

    if ( hasComponent( QwtAbstractScaleDraw::Labels ) &&
        ( hasComponent( QwtAbstractScaleDraw::Ticks ) ||
            hasComponent( QwtAbstractScaleDraw::Backbone ) ) )
    {
        d += spacing();
    }

    d = qMax( d, minimumExtent() );

    return d;
}
Exemple #9
0
void EntityHandle::setAttributeAsAny(const std::string& componentName, const std::string& attributeName, const boost::any& value)
{
    if(componentsTypeIndex.count(componentName) > 0 && hasComponent(componentName))
    {
        const meta::Metadata& componentMetadata = meta::MetadataStore::getMetadata(componentsTypeIndex.at(componentName));
        const meta::AttributeMetadataBase* attributeMetadata = componentMetadata.getAttribute(attributeName);
        attributeMetadata->setAsAny(getComponentPtr(componentName), value);
    }
    else
    {
        std::cout << "[Lua/Warning] Trying to access a not existing component !" << std::endl;
    }
}
Exemple #10
0
void EntityHandle::saveAttributeToXml(const std::string& componentName, const std::string& attributeName, tinyxml2::XMLElement* xmlElement, const level::SerializedEntityGetter& entityGetter) const
{
    if(componentsTypeIndex.count(componentName) > 0 && hasComponent(componentName))
    {
        const meta::Metadata& componentMetadata = meta::MetadataStore::getMetadata(componentsTypeIndex.at(componentName));
        const meta::AttributeMetadataBase* attributeMetadata = componentMetadata.getAttribute(attributeName);
        attributeMetadata->saveToXml(getComponentPtr(componentName), xmlElement, entityGetter);
    }
    else
    {
        std::cout << "[Lua/Warning] Trying to access a not existing component !" << std::endl;
    }
}
Exemple #11
0
void EntityHandle::getAttributeAsLuaTable(const std::string& componentName, const std::string& attributeName, sol::table result) const
{
    if(componentsTypeIndex.count(componentName) > 0 && hasComponent(componentName))
    {
        const meta::Metadata& componentMetadata = meta::MetadataStore::getMetadata(componentsTypeIndex.at(componentName));
        const meta::AttributeMetadataBase* attributeMetadata = componentMetadata.getAttribute(attributeName);
        attributeMetadata->getAsLuaTable(getComponentPtr(componentName), result);
    }
    else
    {
        std::cout << "[Lua/Warning] Trying to access a not existing component !" << std::endl;
    }
}
Exemple #12
0
bool SceneObject::pointIn(double _x, double _y) 
{
	// Return false if we do not live in the world
	if (!hasComponent("Transform"))
		return false;
	double x = ((TransformComponent*)m_Components["Transform"])->getPositionX();
	double y = ((TransformComponent*)m_Components["Transform"])->getPositionY();
	double width, height;
	
	// Are we visible?
	if (hasComponent("Renderable")) {
		Camera& cam = RenderManager::getCurrentContext()->camera();
		int layer;
		if (((RenderComponent*)m_Components["Renderable"])->hasSprite()) {
			Sprite *spr = ((RenderComponent*)m_Components["Renderable"])->getSprite();
			width = spr->width();
			height = spr->height();
			layer = spr->layer();
		}
		if (((RenderComponent*)m_Components["Renderable"])->hasSpriteSheet()) {
			SpriteSheet *spr = ((RenderComponent*)m_Components["Renderable"])->getSpriteSheet();
			width = spr->width();
			height = spr->height();
			layer = spr->layer();
		}

		CameraTransform ctrans = cam.screenToWorld(width, height, layer);
		CameraTransform ctrans2 = cam.screenToWorld(0.0, 0.0, layer);
		width = ctrans.x - ctrans2.x;
		height = ctrans.y - ctrans2.y;
	}else// If we aren't visible, do we have a shape?
	if (hasComponent("Physics")) {

	}else{
		width = 0.5;
		height = 0.5;
	}
}
Exemple #13
0
std::type_index EntityHandle::getAttributeType(const std::string& componentName, const std::string& attributeName) const
{
    if(componentsTypeIndex.count(componentName) > 0 && hasComponent(componentName))
    {
        const meta::Metadata& componentMetadata = meta::MetadataStore::getMetadata(componentsTypeIndex.at(componentName));
        const meta::AttributeMetadataBase* attributeMetadata = componentMetadata.getAttribute(attributeName);
        return attributeMetadata->getType();
    }
    else
    {
        std::cout << "[Lua/Warning] Trying to access a not existing component !" << std::endl;
        return typeid(void);
    }
}
Exemple #14
0
void SceneNode::addComponent(Component* component)
{
	StringHash type = component->getType();

	if (hasComponent(type))
	{
		Logger::warn("Scene node " + name_ + " has already component of type " + std::to_string(type.getValue()));
		return;
	}

	components_[type] = component;

	component->node_ = this;
	component->onNodeSet();
}
Exemple #15
0
    std::shared_ptr<ComponentType> addComponent(ComponentType* component) {
        const QString cname = component->getName();
        if(!hasComponent(cname)) {
            std::shared_ptr<Component> ptr(component);
            ptr->setNode(this);
            ptr->initialize();
            std::pair<QString, std::shared_ptr<Component> > pair(cname, ptr);
            mComponents.insert(pair);
            
            if(!mIsEnabled)
                component->disable();

            _updateAllComponents(0);
        } else {
            Logger::get().error("Cannot add component " + cname + ": a component with this name already exists.");
        }
        return findComponent<ComponentType>(cname);
    }
Exemple #16
0
/*!
  \brief Determine the minimum border distance

  This member function returns the minimum space
  needed to draw the mark labels at the scale's endpoints.

  \param font Font
  \param start Start border distance
  \param end End border distance
*/
void QwtScaleDraw::getBorderDistHint(const QFont &font,
    int &start, int &end ) const
{
    start = 0;
    end = 0;
    
    if ( !hasComponent(QwtAbstractScaleDraw::Labels) )
        return;

    const QwtValueList &ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
    if ( ticks.count() == 0 ) 
        return;

    QRect lr = labelRect(font, ticks[0]);

    // find the distance between tick and border
    int off = qwtAbs(map().transform(ticks[0]) - qRound(map().p1()));

    if ( orientation() == Qt::Vertical )
        end = lr.bottom() + 1 - off;
    else
        start = -lr.left() - off;

    const int lastTick = ticks.count() - 1;
    lr = labelRect(font, ticks[lastTick]);

    // find the distance between tick and border
    off = qwtAbs(map().transform(ticks[lastTick]) - qRound(map().p2()));

    if ( orientation() == Qt::Vertical )
        start = -lr.top() - off;
    else
        end = lr.right() + 1 - off;

    // if the distance between tick and border is larger
    // than half of the label width/height, we set to 0

    if ( start < 0 )
        start = 0;
    if ( end < 0 )
        end = 0;
}
Exemple #17
0
void InputService::setPlayerEntity(EntityID entity)
{
	auto es = Locator::locate<EntityService>();
	if (!es->hasComponent(entity, COMPONENT_INPUT))
		error("Cannot set player entity to %1% as it doesn't have an input component", _str(entity));

	// switch out brain
	auto head = es->getComponent<InputComponent>(entity, COMPONENT_INPUT);
	playersOldBrain = boost::dynamic_pointer_cast<EntityBrain>(head->brain);

	if (!inputBrain)
		inputBrain.reset(new InputBrain(entity)); // lazy init
	else
		inputBrain->setEntity(entity);

	head->brain = inputBrain;

	playerEntity = entity;
	Locator::locate<CameraService>()->setTrackedEntity(entity);
}
Exemple #18
0
		bool
		hasComponent(const char* name)
		{
			return hasComponent(sym(name));
		}
bool SystemTree::hasComponent(JausComponent cmpt)
{
	JausAddress address = cmpt->address;
	return hasComponent(address->subsystem, address->node, address->component, address->instance);
}
bool SystemTree::hasComponent(JausAddress address)
{
	return hasComponent(address->subsystem, address->node, address->component, address->instance);
}
/*!
  \brief Draw the scale

  \param painter    The painter

  \param palette    Palette, text color is used for the labels,
                    foreground color for ticks and backbone
*/
void QwtAbstractScaleDraw::draw( QPainter *painter,
    const QPalette& palette ) const
{
    painter->save();

    QPen pen = painter->pen();
    pen.setWidth( d_data->penWidth );
    pen.setCosmetic( false );
    painter->setPen( pen );

    if ( hasComponent( QwtAbstractScaleDraw::Labels ) )
    {
        painter->save();
        painter->setPen( palette.color( QPalette::Text ) ); // ignore pen style

        const QList<double> &majorTicks =
            d_data->scaleDiv.ticks( QwtScaleDiv::MajorTick );

        for ( int i = 0; i < majorTicks.count(); i++ )
        {
            const double v = majorTicks[i];
            if ( d_data->scaleDiv.contains( v ) )
                drawLabel( painter, v );
        }

        painter->restore();
    }

    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) )
    {
        painter->save();

        QPen pen = painter->pen();
        pen.setColor( palette.color( QPalette::WindowText ) );
        pen.setCapStyle( Qt::FlatCap );

        painter->setPen( pen );

        for ( int tickType = QwtScaleDiv::MinorTick;
            tickType < QwtScaleDiv::NTickTypes; tickType++ )
        {
            const QList<double> &ticks = d_data->scaleDiv.ticks( tickType );
            for ( int i = 0; i < ticks.count(); i++ )
            {
                const double v = ticks[i];
                if ( d_data->scaleDiv.contains( v ) )
                    drawTick( painter, v, d_data->tickLength[tickType] );
            }
        }

        painter->restore();
    }

    if ( hasComponent( QwtAbstractScaleDraw::Backbone ) )
    {
        painter->save();

        QPen pen = painter->pen();
        pen.setColor( palette.color( QPalette::WindowText ) );
        pen.setCapStyle( Qt::FlatCap );

        painter->setPen( pen );

        drawBackbone( painter );

        painter->restore();
    }

    painter->restore();
}
    const QColorGroup& colorGroup) const

#else

/*!
  \brief Draw the scale

  \param painter    The painter

  \param palette    Palette, text color is used for the labels,
                    foreground color for ticks and backbone
*/
void QwtAbstractScaleDraw::draw(QPainter *painter,
    const QPalette& palette) const
#endif
{
    if ( hasComponent(QwtAbstractScaleDraw::Labels) )
    {
        painter->save();

#if QT_VERSION < 0x040000
        painter->setPen(colorGroup.text()); // ignore pen style
#else
        painter->setPen(palette.color(QPalette::Text)); // ignore pen style
#endif

        const QwtValueList &majorTicks =
            d_data->scldiv.ticks(QwtScaleDiv::MajorTick);

        for (int i = 0; i < (int)majorTicks.count(); i++)
        {
            const double v = majorTicks[i];
            if ( d_data->scldiv.contains(v) )
                drawLabel(painter, majorTicks[i]);
        }

        painter->restore();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
    {
        painter->save();

        QPen pen = painter->pen();
#if QT_VERSION < 0x040000
        pen.setColor(colorGroup.foreground());
#else
        pen.setColor(palette.color(QPalette::Foreground));
#endif
        painter->setPen(pen);

        for ( int tickType = QwtScaleDiv::MinorTick;
            tickType < QwtScaleDiv::NTickTypes; tickType++ )
        {
            const QwtValueList &ticks = d_data->scldiv.ticks(tickType);
            for (int i = 0; i < (int)ticks.count(); i++)
            {
                const double v = ticks[i];
                if ( d_data->scldiv.contains(v) )
                    drawTick(painter, v, d_data->tickLength[tickType]);
            }
        }

        painter->restore();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Backbone) )
    {
        painter->save();

        QPen pen = painter->pen();
#if QT_VERSION < 0x040000
        pen.setColor(colorGroup.foreground());
#else
        pen.setColor(palette.color(QPalette::Foreground));
#endif
        painter->setPen(pen);

        drawBackbone(painter);

        painter->restore();
    }
}
Exemple #23
0
void Node::removeComponent(const QString name) {
    if(hasComponent(name)) {
        mComponents[name]->deinitialize();
        mComponents.erase(name);
    }
}
Exemple #24
0
 std::shared_ptr<ComponentType> findComponent(const QString name) {
     if(!hasComponent(name))
         return std::shared_ptr<ComponentType>();
     return std::dynamic_pointer_cast<ComponentType>(mComponents[name]);
 }
Exemple #25
0
void Object::attachComponent(Component *com) {
    apx_assert(!hasComponent(com->getType()), "Duplicate component.");
    _component[com->getType()] = com;
}
Exemple #26
0
int QwtScaleDraw::minLabelDist(const QFont &font) const
{
    if ( !hasComponent(QwtAbstractScaleDraw::Labels) )
        return 0;

    const QwtValueList &ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
    if (ticks.count() == 0)
        return 0;

    const QFontMetrics fm(font);

    const bool vertical = (orientation() == Qt::Vertical);

    QRect bRect1;
    QRect bRect2 = labelRect(font, ticks[0]);
    if ( vertical )
    {
        bRect2.setRect(-bRect2.bottom(), 0, bRect2.height(), bRect2.width());
    }
    int maxDist = 0;

    for (uint i = 1; i < (uint)ticks.count(); i++ )
    {
        bRect1 = bRect2;
        bRect2 = labelRect(font, ticks[i]);
        if ( vertical )
        {
            bRect2.setRect(-bRect2.bottom(), 0,
                bRect2.height(), bRect2.width());
        }

        int dist = fm.leading(); // space between the labels
        if ( bRect1.right() > 0 )
            dist += bRect1.right();
        if ( bRect2.left() < 0 )
            dist += -bRect2.left();

        if ( dist > maxDist )
            maxDist = dist;
    }

    double angle = labelRotation() / 180.0 * M_PI;
    if ( vertical )
        angle += M_PI / 2;

    if ( sin(angle) == 0.0 )
        return maxDist;

    const int fmHeight = fm.ascent() - 2; 

    // The distance we need until there is
    // the height of the label font. This height is needed
    // for the neighbour labal.

    int labelDist = (int)(fmHeight / sin(angle) * cos(angle));
    if ( labelDist < 0 )
        labelDist = -labelDist;

    // The cast above floored labelDist. We want to ceil.
    labelDist++; 

    // For text orientations close to the scale orientation 

    if ( labelDist > maxDist )
        labelDist = maxDist;

    // For text orientations close to the opposite of the 
    // scale orientation

    if ( labelDist < fmHeight )
        labelDist = fmHeight;

    return labelDist;
}
/*!
  \brief Determine the minimum border distance

  This member function returns the minimum space
  needed to draw the mark labels at the scale's endpoints.

  \param font Font
  \param start Start border distance
  \param end End border distance
*/
void QwtScaleDraw::getBorderDistHint( const QFont &font,
                                      int &start, int &end ) const
{
    start = 0;
    end = 0;

    if ( !hasComponent( QwtAbstractScaleDraw::Labels ) )
        return;

    const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
    if ( ticks.count() == 0 )
        return;

    // Find the ticks, that are mapped to the borders.
    // minTick is the tick, that is mapped to the top/left-most position
    // in widget coordinates.

    double minTick = ticks[0];
    double minPos = map().transform( minTick );
    double maxTick = minTick;
    double maxPos = minPos;

    for ( uint i = 1; i < ( uint )ticks.count(); i++ )
    {
        const double tickPos = map().transform( ticks[i] );
        if ( tickPos < minPos )
        {
            minTick = ticks[i];
            minPos = tickPos;
        }
        if ( tickPos > map().transform( maxTick ) )
        {
            maxTick = ticks[i];
            maxPos = tickPos;
        }
    }

    double e = 0.0;
    double s = 0.0;
    if ( orientation() == Qt::Vertical )
    {
        s = -labelRect( font, minTick ).top();
        s -= qAbs( minPos - qRound( map().p2() ) );

        e = labelRect( font, maxTick ).bottom();
        e -= qAbs( maxPos - map().p1() );
    }
    else
    {
        s = -labelRect( font, minTick ).left();
        s -= qAbs( minPos - map().p1() );

        e = labelRect( font, maxTick ).right();
        e -= qAbs( maxPos - map().p2() );
    }

    if ( s < 0.0 )
        s = 0.0;
    if ( e < 0.0 )
        e = 0.0;

    start = qCeil( s );
    end = qCeil( e );
}
Exemple #28
0
		// Returns whether or not the specified component exists within the entity
		template<typename TType> bool hasSystem()
		{
			return hasComponent(TypeIdGrabber::getUniqueTypeID<TType>());
		}
Exemple #29
0
int QwtScaleDraw::minLabelDist( const QFont &font ) const
{
    if ( !hasComponent( QwtAbstractScaleDraw::Labels ) )
        return 0;

    const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
    if ( ticks.isEmpty() )
        return 0;

    const QFontMetrics fm( font );

    const bool vertical = ( orientation() == Qt::Vertical );

    QRectF bRect1;
    QRectF bRect2 = labelRect( font, ticks[0] );
    if ( vertical )
    {
        bRect2.setRect( -bRect2.bottom(), 0.0, bRect2.height(), bRect2.width() );
    }

    double maxDist = 0.0;

    for ( int i = 1; i < ticks.count(); i++ )
    {
        bRect1 = bRect2;
        bRect2 = labelRect( font, ticks[i] );
        if ( vertical )
        {
            bRect2.setRect( -bRect2.bottom(), 0.0,
                            bRect2.height(), bRect2.width() );
        }

        double dist = fm.leading(); // space between the labels
        if ( bRect1.right() > 0 )
            dist += bRect1.right();
        if ( bRect2.left() < 0 )
            dist += -bRect2.left();

        if ( dist > maxDist )
            maxDist = dist;
    }

    double angle = qwtRadians( labelRotation() );
    if ( vertical )
        angle += M_PI / 2;

    const double sinA = qFastSin( angle ); // qreal -> double
    if ( qFuzzyCompare( sinA + 1.0, 1.0 ) )
        return qCeil( maxDist );

    const int fmHeight = fm.ascent() - 2;

    // The distance we need until there is
    // the height of the label font. This height is needed
    // for the neighbored label.

    double labelDist = fmHeight / qFastSin( angle ) * qFastCos( angle );
    if ( labelDist < 0 )
        labelDist = -labelDist;

    // For text orientations close to the scale orientation

    if ( labelDist > maxDist )
        labelDist = maxDist;

    // For text orientations close to the opposite of the
    // scale orientation

    if ( labelDist < fmHeight )
        labelDist = fmHeight;

    return qCeil( labelDist );
}