Merge pull request #3820 from huffman/grid-updates

Grid tool updates + fixes
This commit is contained in:
Brad Hefta-Gaub 2014-11-18 14:57:08 -08:00
commit ee19a2d5a7
6 changed files with 97 additions and 36 deletions

View file

@ -12,14 +12,13 @@
{ red: 0, green: 0, blue: 255 },
];
posY = document.getElementById("horiz-y");
minorSpacing = document.getElementById("minor-spacing");
majorSpacing = document.getElementById("major-spacing");
gridOn = document.getElementById("grid-on");
snapToGrid = document.getElementById("snap-to-grid");
hGridVisible = document.getElementById("horiz-grid-visible");
bMoveToSelection = document.getElementById("move-to-selection");
bMoveToAvatar = document.getElementById("move-to-avatar");
elPosY = document.getElementById("horiz-y");
elMinorSpacing = document.getElementById("minor-spacing");
elMajorSpacing = document.getElementById("major-spacing");
elSnapToGrid = document.getElementById("snap-to-grid");
elHorizontalGridVisible = document.getElementById("horiz-grid-visible");
elMoveToSelection = document.getElementById("move-to-selection");
elMoveToAvatar = document.getElementById("move-to-avatar");
if (window.EventBridge !== undefined) {
EventBridge.scriptEventReceived.connect(function(data) {
@ -27,27 +26,27 @@
if (data.origin) {
var origin = data.origin;
posY.value = origin.y;
elPosY.value = origin.y.toFixed(2);
}
if (data.minorGridSpacing) {
minorSpacing.value = data.minorGridSpacing;
elMinorSpacing.value = data.minorGridSpacing;
}
if (data.majorGridEvery) {
majorSpacing.value = data.majorGridEvery;
elMajorSpacing.value = data.majorGridEvery;
}
if (data.gridColor) {
gridColor = data.gridColor;
}
if (data.snapToGrid !== undefined) {
snapToGrid.checked = data.snapToGrid == true;
if (data.elSnapToGrid !== undefined) {
elSnapToGrid.checked = data.snapToGrid == true;
}
if (data.visible !== undefined) {
hGridVisible.checked = data.visible == true;
elHorizontalGridVisible.checked = data.visible == true;
}
});
@ -55,29 +54,31 @@
EventBridge.emitWebEvent(JSON.stringify({
type: "update",
origin: {
y: posY.value,
y: elPosY.value,
},
minorGridSpacing: minorSpacing.value,
majorGridEvery: majorSpacing.value,
minorGridSpacing: elMinorSpacing.value,
majorGridEvery: elMajorSpacing.value,
gridColor: gridColor,
snapToGrid: snapToGrid.checked,
visible: hGridVisible.checked,
snapToGrid: elSnapToGrid.checked,
visible: elHorizontalGridVisible.checked,
}));
}
}
document.addEventListener("input", emitUpdate);
hGridVisible.addEventListener("change", emitUpdate);
snapToGrid.addEventListener("change", emitUpdate);
elPosY.addEventListener("change", emitUpdate);
elMinorSpacing.addEventListener("change", emitUpdate);
elMajorSpacing.addEventListener("change", emitUpdate);
elSnapToGrid.addEventListener("change", emitUpdate);
elHorizontalGridVisible.addEventListener("change", emitUpdate);
bMoveToAvatar.addEventListener("click", function() {
elMoveToAvatar.addEventListener("click", function() {
EventBridge.emitWebEvent(JSON.stringify({
type: "action",
action: "moveToAvatar",
}));
});
bMoveToSelection.addEventListener("click", function() {
elMoveToSelection.addEventListener("click", function() {
EventBridge.emitWebEvent(JSON.stringify({
type: "action",
action: "moveToSelection",

View file

@ -1403,6 +1403,8 @@ SelectionDisplay = (function () {
vector = vec3Mult(mask, vector);
vector = grid.snapToSpacing(vector);
var changeInDimensions = Vec3.multiply(-1, vec3Mult(signs, vector));
var newDimensions;
if (proportional) {

View file

@ -15,7 +15,7 @@ Grid = function(opts) {
var minorGridWidth = 0.5;
var majorGridWidth = 1.5;
var snapToGrid = true;
var snapToGrid = false;
var gridOverlay = Overlays.addOverlay("grid", {
position: { x: 0 , y: 0, z: 0 },
@ -69,6 +69,24 @@ Grid = function(opts) {
return Vec3.sum(position, origin);
}
that.snapToSpacing = function(delta, majorOnly) {
print('snaptogrid? ' + snapToGrid);
if (!snapToGrid) {
return delta;
}
var spacing = majorOnly ? (minorGridSpacing * majorGridEvery) : minorGridSpacing;
var snappedDelta = {
x: Math.round(delta.x / spacing) * spacing,
y: Math.round(delta.y / spacing) * spacing,
z: Math.round(delta.z / spacing) * spacing,
};
return snappedDelta;
}
that.setPosition = function(newPosition, noUpdate) {
origin = Vec3.subtract(newPosition, { x: 0, y: yOffset, z: 0 });
origin.x = 0;

View file

@ -19,6 +19,8 @@ ToolWindow::ToolWindow(QWidget* parent) :
QMainWindow(parent),
_hasShown(false),
_lastGeometry() {
Application::getInstance()->installEventFilter(this);
}
bool ToolWindow::event(QEvent* event) {
@ -47,8 +49,37 @@ bool ToolWindow::event(QEvent* event) {
return QMainWindow::event(event);
}
bool ToolWindow::eventFilter(QObject* sender, QEvent* event) {
switch (event->type()) {
case QEvent::WindowStateChange:
if (Application::getInstance()->getWindow()->isMinimized()) {
// If we are already visible, we are self-hiding
_selfHidden = isVisible();
setVisible(false);
} else {
if (_selfHidden) {
setVisible(true);
}
}
break;
case QEvent::ApplicationDeactivate:
_selfHidden = isVisible();
setVisible(false);
break;
case QEvent::ApplicationActivate:
if (_selfHidden) {
setVisible(true);
}
break;
default:
break;
}
return false;
}
void ToolWindow::onChildVisibilityUpdated(bool visible) {
if (visible) {
if (!_selfHidden && visible) {
setVisible(true);
} else {
bool hasVisible = false;
@ -59,7 +90,10 @@ void ToolWindow::onChildVisibilityUpdated(bool visible) {
break;
}
}
setVisible(hasVisible);
// If a child was hidden and we don't have any children still visible, hide ourself.
if (!hasVisible) {
setVisible(false);
}
}
}

View file

@ -28,11 +28,15 @@ public:
virtual void addDockWidget(Qt::DockWidgetArea area, QDockWidget* dockWidget, Qt::Orientation orientation);
virtual void removeDockWidget(QDockWidget* dockWidget);
virtual bool eventFilter(QObject* sender, QEvent* event);
public slots:
void onChildVisibilityUpdated(bool visible);
private:
// Indicates whether this window was hidden by itself (because the main window lost focus).
bool _selfHidden;
bool _hasShown;
QRect _lastGeometry;
};

View file

@ -69,9 +69,10 @@ void Grid3DOverlay::render(RenderArgs* args) {
xColor color = getColor();
glm::vec3 position = getPosition();
const int GRID_DIVISIONS = 300;
const int MINOR_GRID_DIVISIONS = 100;
const int MAJOR_GRID_DIVISIONS = 50;
const float MAX_COLOR = 255.0f;
float scale = GRID_DIVISIONS * spacing;
glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
@ -80,12 +81,13 @@ void Grid3DOverlay::render(RenderArgs* args) {
// Minor grid
glPushMatrix();
{
glTranslatef(_minorGridWidth * (floorf(rotated.x / spacing) - GRID_DIVISIONS / 2),
spacing * (floorf(rotated.y / spacing) - GRID_DIVISIONS / 2), position.z);
glTranslatef(_minorGridWidth * (floorf(rotated.x / spacing) - MINOR_GRID_DIVISIONS / 2),
spacing * (floorf(rotated.y / spacing) - MINOR_GRID_DIVISIONS / 2), position.z);
float scale = MINOR_GRID_DIVISIONS * spacing;
glScalef(scale, scale, scale);
Application::getInstance()->getGeometryCache()->renderGrid(GRID_DIVISIONS, GRID_DIVISIONS);
Application::getInstance()->getGeometryCache()->renderGrid(MINOR_GRID_DIVISIONS, MINOR_GRID_DIVISIONS);
}
glPopMatrix();
@ -94,13 +96,13 @@ void Grid3DOverlay::render(RenderArgs* args) {
{
glLineWidth(4.0f);
spacing *= _majorGridEvery;
glTranslatef(spacing * (floorf(rotated.x / spacing) - GRID_DIVISIONS / 2),
spacing * (floorf(rotated.y / spacing) - GRID_DIVISIONS / 2), position.z);
glTranslatef(spacing * (floorf(rotated.x / spacing) - MAJOR_GRID_DIVISIONS / 2),
spacing * (floorf(rotated.y / spacing) - MAJOR_GRID_DIVISIONS / 2), position.z);
scale *= _majorGridEvery;
float scale = MAJOR_GRID_DIVISIONS * spacing;
glScalef(scale, scale, scale);
Application::getInstance()->getGeometryCache()->renderGrid(GRID_DIVISIONS, GRID_DIVISIONS);
Application::getInstance()->getGeometryCache()->renderGrid(MAJOR_GRID_DIVISIONS, MAJOR_GRID_DIVISIONS);
}
glPopMatrix();