int check_valid_file_ids( struct mhdf_FileDesc* desc ) { const int ngrp = 2 + desc->num_elem_desc; int i, err = 0; struct mhdf_EntDesc** sorted = malloc(ngrp*sizeof(struct mhdf_EntDesc*)); for (i = 0; i < desc->num_elem_desc; ++i) sorted[i] = &desc->elems[i].desc; sorted[i++] = &desc->nodes; sorted[i] = &desc->sets; qsort( sorted, ngrp, sizeof(struct mhdf_EntDesc*), &dcomp ); for (i = 0; i < ngrp; ++i) { if (sorted[i]->count < 0) { printf("Group \"%s\" has negative count!\n", desc_name( desc, sorted[i] )); ++err; } if (sorted[i]->count && sorted[i]->start_id == 0) { printf("Group \"%s\" contains NULL ID!\n", desc_name( desc, sorted[i] )); ++err; } if (i > 0 && sorted[i-1]->start_id + sorted[i-1]->count > sorted[i]->start_id) { printf("Conflicting group IDs for \"%s\" [%ld,%ld] and \"%s\" [%ld,%ld]\n", desc_name(desc,sorted[i-1]), sorted[i-1]->start_id, sorted[i-1]->start_id + sorted[i-1]->count - 1, desc_name(desc,sorted[i ]), sorted[i ]->start_id, sorted[i ]->start_id + sorted[i ]->count - 1 ); ++err; } } free(sorted); return err; }
string PangoFontInfo::DescriptionName() const { if (!desc_) return ""; char* desc_str = pango_font_description_to_string(desc_); string desc_name(desc_str); g_free(desc_str); return desc_name; }
void PropertyGrid::showArrayProperty(Lumix::ComponentUID cmp, Lumix::IArrayDescriptor& desc) { Lumix::StaticString<100> desc_name(desc.getName(), "###", (Lumix::uint64)&desc); if (!ImGui::CollapsingHeader(desc_name, nullptr, true, true)) return; int count = desc.getCount(cmp); if (desc.canAdd() && ImGui::Button("Add")) { m_editor.addArrayPropertyItem(cmp, desc); } count = desc.getCount(cmp); for (int i = 0; i < count; ++i) { char tmp[10]; Lumix::toCString(i, tmp, sizeof(tmp)); ImGui::PushID(i); if (!desc.canRemove() || ImGui::TreeNode(tmp)) { if (desc.canRemove() && ImGui::Button("Remove")) { m_editor.removeArrayPropertyItem(cmp, i, desc); --i; count = desc.getCount(cmp); ImGui::TreePop(); ImGui::PopID(); continue; } for (int j = 0; j < desc.getChildren().size(); ++j) { auto* child = desc.getChildren()[j]; showProperty(*child, i, cmp); } if (desc.canRemove()) ImGui::TreePop(); } ImGui::PopID(); } }
void PropertyGrid::showProperty(Lumix::IPropertyDescriptor& desc, int index, Lumix::ComponentUID cmp) { Lumix::OutputBlob stream(m_editor.getAllocator()); desc.get(cmp, index, stream); Lumix::InputBlob tmp(stream); Lumix::StaticString<100> desc_name(desc.getName(), "###", (Lumix::uint64)&desc); switch (desc.getType()) { case Lumix::IPropertyDescriptor::DECIMAL: { float f; tmp.read(f); auto& d = static_cast<Lumix::IDecimalPropertyDescriptor&>(desc); if ((d.getMax() - d.getMin()) / d.getStep() <= 100) { if (ImGui::SliderFloat(desc_name, &f, d.getMin(), d.getMax())) { m_editor.setProperty(cmp.type, index, desc, &f, sizeof(f)); } } else { if (ImGui::DragFloat(desc_name, &f, d.getStep(), d.getMin(), d.getMax())) { m_editor.setProperty(cmp.type, index, desc, &f, sizeof(f)); } } break; } case Lumix::IPropertyDescriptor::INTEGER: { int i; tmp.read(i); if (ImGui::DragInt(desc_name, &i)) { m_editor.setProperty(cmp.type, index, desc, &i, sizeof(i)); } break; } case Lumix::IPropertyDescriptor::BOOL: { bool b; tmp.read(b); if (ImGui::Checkbox(desc_name, &b)) { m_editor.setProperty(cmp.type, index, desc, &b, sizeof(b)); } break; } case Lumix::IPropertyDescriptor::COLOR: { Lumix::Vec3 v; tmp.read(v); if (ImGui::ColorEdit3(desc_name, &v.x)) { m_editor.setProperty(cmp.type, index, desc, &v, sizeof(v)); } if (ImGui::BeginPopupContextItem(Lumix::StaticString<50>(desc_name, "pu"))) { if (ImGui::ColorPicker(&v.x, false)) { m_editor.setProperty(cmp.type, index, desc, &v, sizeof(v)); } ImGui::EndPopup(); } break; } case Lumix::IPropertyDescriptor::VEC2: { Lumix::Vec2 v; tmp.read(v); if (ImGui::DragFloat2(desc_name, &v.x)) { m_editor.setProperty(cmp.type, index, desc, &v, sizeof(v)); } break; } case Lumix::IPropertyDescriptor::INT2: { Lumix::Int2 v; tmp.read(v); if (ImGui::DragInt2(desc_name, &v.x)) { m_editor.setProperty(cmp.type, index, desc, &v, sizeof(v)); } break; } case Lumix::IPropertyDescriptor::VEC3: { Lumix::Vec3 v; tmp.read(v); if (ImGui::DragFloat3(desc_name, &v.x)) { m_editor.setProperty(cmp.type, index, desc, &v, sizeof(v)); } break; } case Lumix::IPropertyDescriptor::VEC4: { Lumix::Vec4 v; tmp.read(v); if (ImGui::DragFloat4(desc_name, &v.x)) { m_editor.setProperty(cmp.type, index, desc, &v, sizeof(v)); } break; } case Lumix::IPropertyDescriptor::RESOURCE: { char buf[1024]; Lumix::copyString(buf, (const char*)stream.getData()); auto& resource_descriptor = static_cast<Lumix::IResourcePropertyDescriptor&>(desc); auto rm_type = resource_descriptor.getResourceType(); if (m_asset_browser.resourceInput( desc.getName(), Lumix::StaticString<20>("", (Lumix::uint64)&desc), buf, sizeof(buf), rm_type)) { m_editor.setProperty(cmp.type, index, desc, buf, Lumix::stringLength(buf) + 1); } break; } case Lumix::IPropertyDescriptor::STRING: case Lumix::IPropertyDescriptor::FILE: { char buf[1024]; Lumix::copyString(buf, (const char*)stream.getData()); if (ImGui::InputText(desc_name, buf, sizeof(buf))) { m_editor.setProperty(cmp.type, index, desc, buf, Lumix::stringLength(buf) + 1); } break; } case Lumix::IPropertyDescriptor::ARRAY: showArrayProperty(cmp, static_cast<Lumix::IArrayDescriptor&>(desc)); break; case Lumix::IPropertyDescriptor::SAMPLED_FUNCTION: showSampledFunctionProperty(cmp, static_cast<Lumix::ISampledFunctionDescriptor&>(desc)); break; case Lumix::IPropertyDescriptor::ENTITY: showEntityProperty(cmp, index, static_cast<Lumix::IEnumPropertyDescriptor&>(desc)); break; case Lumix::IPropertyDescriptor::ENUM: showEnumProperty(cmp, index, static_cast<Lumix::IEnumPropertyDescriptor&>(desc)); break; default: ASSERT(false); break; } }