Skip to content

Commit

Permalink
Gloom: Editor shows entity types as labels
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 69481e5 commit 93a8969
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
3 changes: 2 additions & 1 deletion doomsday/tests/test_gloom/net.dengine.gloom.pack/images.dei
Expand Up @@ -5,7 +5,8 @@ group world {
image grass.diffuse { path = "images/mat-grass.jpg" }
image dirt.diffuse { path = "images/mat-dirt.jpg" }
group test {
image diffuse { path = "images/mat-stone.png" }
image diffuse { path = "images/mat-stone.png/Color.solid:0,0,0,255" }
image specgloss { path = "images/mat-stone.png/Color.solid:32,40,50,128" }
image normaldisp { path = "images/heights2.png/HeightMap.toNormals" }
}
image test2.diffuse { path = "images/mat-test2.png" }
Expand Down
44 changes: 28 additions & 16 deletions doomsday/tests/test_gloom/src/editor.cpp
Expand Up @@ -38,6 +38,20 @@ using namespace gloom;
static const int DRAG_MIN_DIST = 2;
static const int UNDO_MAX = 50;

struct EntityType {
Entity::Type type;
QString label;
};
static const QHash<Entity::Type, String> entityMetadata {
std::make_pair(Entity::Light, String("Light")),
std::make_pair(Entity::Spotlight, String("Spotlight")),
std::make_pair(Entity::Tree1, String("Tree1")),
std::make_pair(Entity::Tree2, String("Tree2")),
std::make_pair(Entity::Tree3, String("Tree3")),
std::make_pair(Entity::TestSphere, String("Test Sphere")),
std::make_pair(Entity::Buggy, String("Buggy"))
};

enum Direction {
Horizontal = 0x1,
Vertical = 0x2,
Expand Down Expand Up @@ -833,6 +847,11 @@ DENG2_PIMPL(Editor)
return id;
}

String entityLabel(const Entity &ent) const
{
return entityMetadata[ent.type()];
}

void selectOrUnselect(ID id)
{
if (!selection.contains(id))
Expand Down Expand Up @@ -1311,7 +1330,9 @@ void Editor::paintEvent(QPaintEvent *)

// Entities.
{
const QFontMetrics metrics(d->metaFont);
ptr.setPen(Qt::black);
ptr.setFont(d->metaFont);

for (auto i = mapEnts.begin(), end = mapEnts.end(); i != end; ++i)
{
Expand All @@ -1321,11 +1342,15 @@ void Editor::paintEvent(QPaintEvent *)
float radius = 0.5f * d->viewScale;
ptr.setBrush(d->selection.contains(i.key())? selectColor : QColor(Qt::white));
ptr.drawEllipse(pos, radius, radius);

ptr.drawText(pos + QPointF(radius + 5, metrics.ascent() / 2), d->entityLabel(*ent));
}

ptr.setBrush(Qt::NoBrush);
const Point mousePos = d->worldMousePoint();
ptr.drawEllipse(d->worldToView(mousePos), 5, 5);

ptr.setFont(font());
}

// Status bar.
Expand Down Expand Up @@ -1525,24 +1550,11 @@ void Editor::mouseReleaseEvent(QMouseEvent *event)
header->setDisabled(true);

QMenu *eType = pop->addMenu("Type");
struct EntityType {
Entity::Type type;
QString label;
};
const EntityType types[] = {
{ Entity::Light, "Light" },
{ Entity::Spotlight, "Spotlight" },
{ Entity::Tree1, "Tree1" },
{ Entity::Tree2, "Tree2" },
{ Entity::Tree3, "Tree3" },
{ Entity::TestSphere, "Test Sphere" },
{ Entity::Buggy, "Buggy" },
};
const ID entityId = d->hoverEntity;
for (const auto &et : types)
for (auto i = entityMetadata.begin(), end = entityMetadata.end(); i != end; ++i)
{
/*QAction *a = */ eType->addAction(et.label, [this, entityId, et] () {
d->map.entity(entityId).setType(et.type);
/*QAction *a = */ eType->addAction(i.value(), [this, entityId, i] () {
d->map.entity(entityId).setType(i.key());
});
}
pop->popup(mapToGlobal(event->pos()));
Expand Down

0 comments on commit 93a8969

Please sign in to comment.