QWidget* DynamicObjectItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
	if (index.column() == 1)
	{
		auto node = (DynamicObjectModel::Node*)index.internalPointer();
		if (!node)
		{
			return QStyledItemDelegate::createEditor(parent, option, index);
		}
		if (node->onCreateEditor)
		{
			return node->onCreateEditor(parent, option);
		}
		else if (node->m_getter().type() == QMetaType::Bool)
		{
			return nullptr;
		}
		else if (node->m_getter().type() == QMetaType::Float)
		{
			QDoubleSpinBox* input = new QDoubleSpinBox(parent);
			input->setMaximum(FLT_MAX);
			input->setMinimum(-FLT_MAX);
			connect(input, (void (QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged, [node](double value){
				node->m_setter(value);
			});
			input->setSingleStep(0.1);
			return input;
		}
	}
	return QStyledItemDelegate::createEditor(parent, option, index);
}
Ejemplo n.º 2
0
std::array<Type, Size> AccessorArrayValue<Type, Size>::get() const
{
    std::array<Type, Size> array;
    for (size_t i = 0; i < Size; ++i)
        array[i] = m_getter(i);

    return array;
}
Ejemplo n.º 3
0
	UInt32 IndexMapper::Get(unsigned int i) const
	{
		#if NAZARA_UTILITY_SAFE
		if (i >= m_indexCount)
		{
			NazaraError("Index out of range (" + String::Number(i) + " >= " + String::Number(m_indexCount) + ')');
			return 0;
		}
		#endif

		return m_getter(m_mapper.GetPointer(), i);
	}
Ejemplo n.º 4
0
 Variant Global::GetValue(void) const
 {
     return m_getter( );
 }
void ResourceModel::fillMaterialInfo(Lumix::Material* material, Node& node)
{
	auto object = Object<Lumix::Material>(material, &node);
	node.m_getter = [material]() -> QVariant
	{
		return material->getPath().c_str();
	};
	node.m_name = "Material";
	object.getNode().onCreateEditor = [this, material](
		QWidget* parent, const QStyleOptionViewItem&) -> QWidget*
	{
		auto* widget = new QWidget(parent);
		auto* layout = new QHBoxLayout(widget);
		layout->setContentsMargins(0, 0, 0, 0);
		auto* label = new QLabel(material->getPath().c_str(), widget);
		layout->addWidget(label);
		layout->addStretch();

		QPushButton* button = new QPushButton("Save", widget);
		connect(button,
				&QPushButton::clicked,
				[this, material]()
				{
					saveMaterial(material);
				});
		layout->addWidget(button);

		return widget;
	};
	object.getNode().enablePeristentEditor();
	object.property("Alpha cutout",
					&Lumix::Material::isAlphaCutout,
					&Lumix::Material::enableAlphaCutout)
		.property("Backface culling",
				  &Lumix::Material::isBackfaceCulling,
				  &Lumix::Material::enableBackfaceCulling)
		.property("Shadow receiver",
				  &Lumix::Material::isShadowReceiver,
				  &Lumix::Material::enableShadowReceiving)
		.property("Shininess",
				  &Lumix::Material::getShininess,
				  &Lumix::Material::setShininess)
		.propertyColor("Specular",
					   &Lumix::Material::getSpecular,
					   &Lumix::Material::setSpecular)
		.property(
			"Z test", &Lumix::Material::isZTest, &Lumix::Material::enableZTest)
		.property("Shader",
				  [](Lumix::Material* material) -> QVariant
				  {
					  return material->getShader()
								 ? material->getShader()->getPath().c_str()
								 : "";
				  },
				  [this](Lumix::Material* material, QVariant value)
				  {
					  setMaterialShader(material, value.toString());
				  });
	auto shader_node = object.getNode().m_children.back();
	shader_node->enablePeristentEditor();
	shader_node->onCreateEditor = [shader_node](QWidget* parent,
												const QStyleOptionViewItem&)
	{
		auto input = new FileInput(parent);
		input->setValue(shader_node->m_getter().toString());
		input->connect(input,
					   &FileInput::valueChanged,
					   [shader_node, input]()
					   {
						   shader_node->m_setter(input->value());
					   });
		return input;
	};

	for (int i = 0; i < material->getUniformCount(); ++i)
	{
		auto& uniform = material->getUniform(i);
		QString name = uniform.m_name;
		object.property(uniform.m_name,
						[name](Lumix::Material* material) -> QVariant
						{
							Lumix::Material::Uniform* uniform =
								getMaterialUniform(material, name);
							if (uniform)
							{
								switch (uniform->m_type)
								{
									case Lumix::Material::Uniform::FLOAT:
										return uniform->m_float;
								}
							}
							return QVariant();
						},
						[name](Lumix::Material* material, const QVariant& value)
						{
							Lumix::Material::Uniform* uniform =
								getMaterialUniform(material, name);
							if (uniform)
							{
								switch (uniform->m_type)
								{
									case Lumix::Material::Uniform::FLOAT:
										uniform->m_float = value.toFloat();
										break;
								}
							}
						});
	}

	for (int i = 0; material->getShader() &&
					i < material->getShader()->getTextureSlotCount();
		 ++i)
	{
		const auto& slot = material->getShader()->getTextureSlot(i);
		Object<const Lumix::Shader::TextureSlot> slot_object(
			&slot, &object.getNode().addChild(slot.m_name));
		auto& node = slot_object.getNode();
		auto texture = material->getTexture(i);
		if (texture)
		{
			fillTextureInfo(texture, node);
		}
		node.m_name = slot.m_name;
		node.m_getter = [texture]() -> QVariant
		{
			return texture ? texture->getPath().c_str() : "";
		};
		node.onCreateEditor = [&node, i, texture, material](
			QWidget* parent, const QStyleOptionViewItem&) -> QWidget*
		{
			auto input = new FileInput(parent);
			input->setValue(texture ? texture->getPath().c_str() : "");
			input->connect(input,
						   &FileInput::valueChanged,
						   [&node, input]()
						   {
							   node.m_setter(input->value());
						   });
			return input;
		};
		node.m_setter = [material, i](const QVariant& value)
		{
			if (value.isValid())
			{
				material->setTexturePath(
					i, Lumix::Path(value.toString().toLatin1().data()));
			}
		};
		node.enablePeristentEditor();
	}
}
Ejemplo n.º 6
0
Type AccessorArrayValue<Type, Size>::get(size_t i) const
{
    return m_getter(i);
}