mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Merge pull request #3764 from highfidelity/revert-3759-20140
Revert "CR for Job #20140 - Add Overlays.getTextWidth"
This commit is contained in:
commit
86eb7a2464
10 changed files with 18 additions and 64 deletions
|
@ -1125,12 +1125,12 @@ var toolBar = (function () {
|
|||
browseModelsButton,
|
||||
loadURLMenuItem,
|
||||
loadFileMenuItem,
|
||||
menuItemWidth,
|
||||
menuItemWidth = 125,
|
||||
menuItemOffset,
|
||||
menuItemHeight,
|
||||
menuItemMargin = 5,
|
||||
menuTextColor = { red: 255, green: 255, blue: 255 },
|
||||
menuBackgroundColor = { red: 18, green: 66, blue: 66 };
|
||||
menuBackgoundColor = { red: 18, green: 66, blue: 66 };
|
||||
|
||||
function initialize() {
|
||||
toolBar = new ToolBar(0, 0, ToolBar.VERTICAL);
|
||||
|
@ -1167,8 +1167,9 @@ var toolBar = (function () {
|
|||
loadURLMenuItem = Overlays.addOverlay("text", {
|
||||
x: newModelButton.x - menuItemWidth,
|
||||
y: newModelButton.y + menuItemOffset,
|
||||
width: menuItemWidth,
|
||||
height: menuItemHeight,
|
||||
backgroundColor: menuBackgroundColor,
|
||||
backgroundColor: menuBackgoundColor,
|
||||
topMargin: menuItemMargin,
|
||||
text: "Model URL",
|
||||
alpha: 0.9,
|
||||
|
@ -1178,19 +1179,15 @@ var toolBar = (function () {
|
|||
loadFileMenuItem = Overlays.addOverlay("text", {
|
||||
x: newModelButton.x - menuItemWidth,
|
||||
y: newModelButton.y + menuItemOffset + menuItemHeight,
|
||||
width: menuItemWidth,
|
||||
height: menuItemHeight,
|
||||
backgroundColor: menuBackgroundColor,
|
||||
backgroundColor: menuBackgoundColor,
|
||||
topMargin: menuItemMargin,
|
||||
text: "Model File",
|
||||
alpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
menuItemWidth = Math.max(Overlays.textWidth(loadURLMenuItem, "Model URL"),
|
||||
Overlays.textWidth(loadFileMenuItem, "Model File")) + 20;
|
||||
Overlays.editOverlay(loadURLMenuItem, { width: menuItemWidth });
|
||||
Overlays.editOverlay(loadFileMenuItem, { width: menuItemWidth });
|
||||
|
||||
newCubeButton = toolBar.addTool({
|
||||
imageURL: toolIconUrl + "add-cube.svg",
|
||||
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
|
|
|
@ -83,12 +83,12 @@ var toolBar = (function () {
|
|||
browseModelsButton,
|
||||
loadURLMenuItem,
|
||||
loadFileMenuItem,
|
||||
menuItemWidth,
|
||||
menuItemWidth = 125,
|
||||
menuItemOffset,
|
||||
menuItemHeight,
|
||||
menuItemMargin = 5,
|
||||
menuTextColor = { red: 255, green: 255, blue: 255 },
|
||||
menuBackgroundColor = { red: 18, green: 66, blue: 66 };
|
||||
menuBackgoundColor = { red: 18, green: 66, blue: 66 };
|
||||
|
||||
function initialize() {
|
||||
toolBar = new ToolBar(0, 0, ToolBar.VERTICAL);
|
||||
|
@ -125,8 +125,9 @@ var toolBar = (function () {
|
|||
loadURLMenuItem = Overlays.addOverlay("text", {
|
||||
x: newModelButton.x - menuItemWidth,
|
||||
y: newModelButton.y + menuItemOffset,
|
||||
width: menuItemWidth,
|
||||
height: menuItemHeight,
|
||||
backgroundColor: menuBackgroundColor,
|
||||
backgroundColor: menuBackgoundColor,
|
||||
topMargin: menuItemMargin,
|
||||
text: "Model URL",
|
||||
alpha: 0.9,
|
||||
|
@ -136,19 +137,15 @@ var toolBar = (function () {
|
|||
loadFileMenuItem = Overlays.addOverlay("text", {
|
||||
x: newModelButton.x - menuItemWidth,
|
||||
y: newModelButton.y + menuItemOffset + menuItemHeight,
|
||||
width: menuItemWidth,
|
||||
height: menuItemHeight,
|
||||
backgroundColor: menuBackgroundColor,
|
||||
backgroundColor: menuBackgoundColor,
|
||||
topMargin: menuItemMargin,
|
||||
text: "Model File",
|
||||
alpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
menuItemWidth = Math.max(Overlays.textWidth(loadURLMenuItem, "Model URL"),
|
||||
Overlays.textWidth(loadFileMenuItem, "Model File")) + 20;
|
||||
Overlays.editOverlay(loadURLMenuItem, { width: menuItemWidth });
|
||||
Overlays.editOverlay(loadFileMenuItem, { width: menuItemWidth });
|
||||
|
||||
newCubeButton = toolBar.addTool({
|
||||
imageURL: toolIconUrl + "add-cube.svg",
|
||||
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
|
|
|
@ -37,13 +37,12 @@ static uint qHash(const TextRenderer::Properties& key, uint seed = 0) {
|
|||
}
|
||||
|
||||
static bool operator==(const TextRenderer::Properties& p1, const TextRenderer::Properties& p2) {
|
||||
return p1.font == p2.font && p1.effect == p2.effect && p1.effectThickness == p2.effectThickness && p1.color == p2.color
|
||||
&& p1.copy == p2.copy;
|
||||
return p1.font == p2.font && p1.effect == p2.effect && p1.effectThickness == p2.effectThickness && p1.color == p2.color;
|
||||
}
|
||||
|
||||
TextRenderer* TextRenderer::getInstance(const char* family, int pointSize, int weight, bool italic,
|
||||
EffectType effect, int effectThickness, const QColor& color, int copy) {
|
||||
Properties properties = { QFont(family, pointSize, weight, italic), effect, effectThickness, color, copy };
|
||||
EffectType effect, int effectThickness, const QColor& color) {
|
||||
Properties properties = { QFont(family, pointSize, weight, italic), effect, effectThickness, color };
|
||||
TextRenderer*& instance = _instances[properties];
|
||||
if (!instance) {
|
||||
instance = new TextRenderer(properties);
|
||||
|
|
|
@ -50,11 +50,10 @@ public:
|
|||
EffectType effect;
|
||||
int effectThickness;
|
||||
QColor color;
|
||||
int copy; // Use to separate renderers that are otherwise identical.
|
||||
};
|
||||
|
||||
static TextRenderer* getInstance(const char* family, int pointSize = -1, int weight = -1, bool italic = false,
|
||||
EffectType effect = NO_EFFECT, int effectThickness = 1, const QColor& color = QColor(255, 255, 255), int copy = 0);
|
||||
EffectType effect = NO_EFFECT, int effectThickness = 1, const QColor& color = QColor(255, 255, 255));
|
||||
|
||||
~TextRenderer();
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
//
|
||||
|
||||
#include <limits>
|
||||
#include <typeinfo>
|
||||
#include <Application.h>
|
||||
#include <Menu.h>
|
||||
|
||||
|
@ -358,18 +357,3 @@ bool Overlays::isLoaded(unsigned int id) {
|
|||
return overlay->isLoaded();
|
||||
}
|
||||
|
||||
float Overlays::textWidth(unsigned int id, const QString& text) {
|
||||
if (_overlays2D.contains(id)) {
|
||||
Overlay* thisOverlay = _overlays2D[id];
|
||||
if (typeid(*thisOverlay) == typeid(TextOverlay)) {
|
||||
return static_cast<TextOverlay*>(thisOverlay)->textWidth(text);
|
||||
}
|
||||
}
|
||||
if (_overlays3D.contains(id)) {
|
||||
Overlay* thisOverlay = _overlays3D[id];
|
||||
if (typeid(*thisOverlay) == typeid(Text3DOverlay)) {
|
||||
return static_cast<Text3DOverlay*>(thisOverlay)->textWidth(text);
|
||||
}
|
||||
}
|
||||
return 0.f;
|
||||
}
|
||||
|
|
|
@ -65,10 +65,6 @@ public slots:
|
|||
/// returns whether the overlay's assets are loaded or not
|
||||
bool isLoaded(unsigned int id);
|
||||
|
||||
/// returns the width of the given text in the specified overlay if it is a text overlay: in pixels if it is a 2D text
|
||||
/// overlay; in meters if it is a 3D text overlay
|
||||
float textWidth(unsigned int id, const QString& text);
|
||||
|
||||
private:
|
||||
QMap<unsigned int, Overlay*> _overlays2D;
|
||||
QMap<unsigned int, Overlay*> _overlays3D;
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 };
|
||||
const float DEFAULT_MARGIN = 0.1f;
|
||||
const int FIXED_FONT_POINT_SIZE = 40;
|
||||
const float LINE_SCALE_RATIO = 1.2f;
|
||||
|
||||
Text3DOverlay::Text3DOverlay() :
|
||||
_backgroundColor(DEFAULT_BACKGROUND_COLOR),
|
||||
|
@ -89,9 +87,11 @@ void Text3DOverlay::render(RenderArgs* args) {
|
|||
glVertex3f(-halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND);
|
||||
glEnd();
|
||||
|
||||
const int FIXED_FONT_POINT_SIZE = 40;
|
||||
const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 40.0f; // this is a ratio determined through experimentation
|
||||
|
||||
TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||
float LINE_SCALE_RATIO = 1.2f;
|
||||
float maxHeight = (float)textRenderer->calculateHeight("Xy") * LINE_SCALE_RATIO;
|
||||
|
||||
float scaleFactor = (maxHeight / FIXED_FONT_SCALING_RATIO) * _lineHeight;
|
||||
|
@ -179,11 +179,4 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
|
||||
}
|
||||
|
||||
float Text3DOverlay::textWidth(const QString& text) {
|
||||
const int TEXT3DOVERLAY_TEXTWIDTH_RENDERER = 2; // Separate to that used for drawing text so that doesn't interfere.
|
||||
TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE, -1, false,
|
||||
TextRenderer::NO_EFFECT, 1, QColor(255, 255, 255), TEXT3DOVERLAY_TEXTWIDTH_RENDERER);
|
||||
|
||||
float scaleFactor = _lineHeight * LINE_SCALE_RATIO / (float)textRenderer->calculateHeight("X");
|
||||
return scaleFactor * (float)textRenderer->computeWidth(qPrintable(text));
|
||||
}
|
||||
|
|
|
@ -48,8 +48,6 @@ public:
|
|||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
|
||||
float textWidth(const QString& text); // Meters
|
||||
|
||||
private:
|
||||
void enableClipPlane(GLenum plane, float x, float y, float z, float w);
|
||||
|
||||
|
|
|
@ -126,10 +126,3 @@ void TextOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
|
||||
|
||||
float TextOverlay::textWidth(const QString& text) {
|
||||
const int TEXTOVERLAY_GETTEXTWIDTH_TEXTRENDERER = 1; // Separate to that used for drawing text so that doesn't interfere.
|
||||
TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, _fontSize, -1, false, TextRenderer::NO_EFFECT, 1,
|
||||
QColor(255, 255, 255), TEXTOVERLAY_GETTEXTWIDTH_TEXTRENDERER);
|
||||
|
||||
return textRenderer->computeWidth(qPrintable(text));
|
||||
}
|
||||
|
|
|
@ -53,8 +53,6 @@ public:
|
|||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
|
||||
float textWidth(const QString& text); // Pixels
|
||||
|
||||
private:
|
||||
|
||||
QString _text;
|
||||
|
|
Loading…
Reference in a new issue