Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5584: Migrate entity name rendering. Everything except the colour is…
… working. Added OriginKey member to EntityNode - all subclasses need to be adjusted now to use the same observer.
- Loading branch information
1 parent
a93973d
commit 3393128
Showing
8 changed files
with
135 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,48 @@ | ||
/* | ||
Copyright (C) 2001-2006, William Joseph. | ||
All Rights Reserved. | ||
This file is part of GtkRadiant. | ||
GtkRadiant is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
GtkRadiant is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with GtkRadiant; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#if !defined(INCLUDED_NAMEDENTITY_H) | ||
#define INCLUDED_NAMEDENTITY_H | ||
|
||
#include "entitylib.h" | ||
#pragma once | ||
|
||
#include "ieclass.h" | ||
#include "ientity.h" | ||
#include "SpawnArgs.h" | ||
|
||
namespace entity { | ||
namespace entity | ||
{ | ||
|
||
class NameKey : | ||
public KeyObserver | ||
{ | ||
// The reference to the spawnarg structure | ||
SpawnArgs& m_entity; | ||
SpawnArgs& _entity; | ||
|
||
// Cached "name" keyvalue | ||
std::string _name; | ||
|
||
sigc::signal<void> _sigNameChanged; | ||
|
||
public: | ||
NameKey(SpawnArgs& entity) : | ||
m_entity(entity) | ||
NameKey(SpawnArgs& entity) : | ||
_entity(entity) | ||
{} | ||
|
||
std::string name() const | ||
std::string getName() const | ||
{ | ||
if (_name.empty()) | ||
{ | ||
return m_entity.getEntityClass()->getName(); | ||
return _entity.getEntityClass()->getName(); | ||
} | ||
return _name; | ||
} | ||
|
||
void onKeyValueChanged(const std::string& value) | ||
{ | ||
_name = value; | ||
} | ||
}; | ||
|
||
class RenderableNameKey : | ||
public OpenGLRenderable | ||
{ | ||
const NameKey& _nameKey; | ||
|
||
// The origin (local entity coordinates) | ||
Vector3 _origin; | ||
|
||
public: | ||
RenderableNameKey(const NameKey& nameKey) : | ||
_nameKey(nameKey), | ||
_origin(0,0,0) | ||
{} | ||
|
||
// We render in local coordinates of the owning entity node | ||
void render(const RenderInfo& info) const | ||
{ | ||
glRasterPos3dv(_origin); | ||
GlobalOpenGL().drawString(_nameKey.name()); | ||
_sigNameChanged.emit(); | ||
} | ||
|
||
void setOrigin(const Vector3& origin) | ||
{ | ||
_origin = origin; | ||
} | ||
sigc::signal<void>& signal_nameChanged() | ||
{ | ||
return _sigNameChanged; | ||
} | ||
}; | ||
|
||
} // namespace entity | ||
|
||
#endif | ||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include <sigc++/trackable.h> | ||
#include <sigc++/functors/mem_fun.h> | ||
#include "math/Matrix4.h" | ||
#include "render/RenderableText.h" | ||
#include "NameKey.h" | ||
|
||
namespace entity | ||
{ | ||
|
||
class RenderableEntityName : | ||
public render::RenderableText, | ||
public sigc::trackable | ||
{ | ||
NameKey& _nameKey; | ||
|
||
// The origin in world coordinates | ||
const Vector3& _entityOrigin; | ||
|
||
bool _needsUpdate; | ||
|
||
public: | ||
RenderableEntityName(NameKey& nameKey, const Vector3& entityOrigin) : | ||
_nameKey(nameKey), | ||
_entityOrigin(entityOrigin), | ||
_needsUpdate(true) | ||
{ | ||
// Queue an update once the name changes | ||
_nameKey.signal_nameChanged().connect( | ||
sigc::mem_fun(*this, &RenderableEntityName::queueUpdate) | ||
); | ||
} | ||
|
||
void queueUpdate() | ||
{ | ||
_needsUpdate = true; | ||
} | ||
|
||
protected: | ||
void onUpdate() override | ||
{ | ||
if (!_needsUpdate) return; | ||
|
||
_needsUpdate = false; | ||
|
||
setText(_nameKey.getName()); | ||
setWorldPosition(_entityOrigin); | ||
} | ||
}; | ||
|
||
} |
Oops, something went wrong.