use of com.talosvfx.talos.editor.addons.scene.widgets.gizmos.Gizmo in project talos by rockbite.
the class SceneEditorWorkspace method initListeners.
protected void initListeners() {
addListener(new InputListener() {
Vector2 vec = new Vector2();
Gizmo touchedGizmo = null;
// selection stuff
boolean dragged = false;
Vector2 startPos = new Vector2();
Rectangle rectangle = new Rectangle();
boolean upWillClear = true;
GameObject selectedGameObject;
@Override
public boolean mouseMoved(InputEvent event, float x, float y) {
Vector2 hitCords = getWorldFromLocal(x, y);
for (int i = 0; i < gizmoList.size; i++) {
Gizmo item = gizmoList.get(i);
if (item.isSelected()) {
item.mouseMoved(hitCords.x, hitCords.y);
}
}
return super.mouseMoved(event, x, y);
}
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
upWillClear = true;
dragged = false;
touchedGizmo = null;
Vector2 hitCords = getWorldFromLocal(x, y);
Gizmo gizmo = hitGizmo(hitCords.x, hitCords.y);
selectedGameObject = null;
if (gizmo != null) {
touchedGizmo = gizmo;
GameObject gameObject = touchedGizmo.getGameObject();
upWillClear = false;
if (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) && !touchedGizmo.catchesShift()) {
// toggling
if (selection.contains(gameObject, true)) {
removeFromSelection(gameObject);
} else {
addToSelection(gameObject);
selectedGameObject = gameObject;
}
} else {
if (!selection.contains(gameObject, true)) {
selectGameObject(gameObject);
selectedGameObject = gameObject;
}
}
Notifications.fireEvent(Notifications.obtainEvent(GameObjectSelectionChanged.class).set(selection));
touchedGizmo.touchDown(hitCords.x, hitCords.y, button);
// also tell all other selected gizmos about this touchdown
for (int i = 0; i < gizmoList.size; i++) {
Gizmo item = gizmoList.get(i);
if (item.isSelected() && item.getClass().equals(touchedGizmo.getClass()) && item != touchedGizmo) {
item.touchDown(hitCords.x, hitCords.y, button);
}
}
getStage().setKeyboardFocus(SceneEditorWorkspace.this);
event.handle();
templateListPopup.remove();
return true;
} else {
touchedGizmo = null;
if (button == 1 && !event.isCancelled()) {
final Vector2 vec = new Vector2(Gdx.input.getX(), Gdx.input.getY());
(TalosMain.Instance().UIStage().getStage().getViewport()).unproject(vec);
Vector2 location = new Vector2(vec);
Vector2 createLocation = new Vector2(hitCords);
templateListPopup.showPopup(getStage(), location, createLocation);
return true;
}
}
if (button == 2 || ctrlPressed()) {
selectionRect.setVisible(true);
selectionRect.setSize(0, 0);
startPos.set(x, y);
return true;
}
clearSelection();
Notifications.fireEvent(Notifications.obtainEvent(GameObjectSelectionChanged.class).set(selection));
getStage().setKeyboardFocus(SceneEditorWorkspace.this);
return false;
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
super.touchDragged(event, x, y, pointer);
dragged = true;
Vector2 hitCords = getWorldFromLocal(x, y);
if (touchedGizmo != null) {
touchedGizmo.touchDragged(hitCords.x, hitCords.y);
for (int i = 0; i < gizmoList.size; i++) {
Gizmo item = gizmoList.get(i);
if (item.isSelected() && item.getClass().equals(touchedGizmo.getClass()) && item != touchedGizmo) {
item.touchDragged(hitCords.x, hitCords.y);
}
}
}
if (selectionRect.isVisible()) {
vec.set(x, y);
vec.sub(startPos);
if (vec.x < 0) {
rectangle.setX(x);
} else {
rectangle.setX(startPos.x);
}
if (vec.y < 0) {
rectangle.setY(y);
} else {
rectangle.setY(startPos.y);
}
rectangle.setWidth(Math.abs(vec.x));
rectangle.setHeight(Math.abs(vec.y));
selectionRect.setPosition(rectangle.x, rectangle.y);
selectionRect.setSize(rectangle.getWidth(), rectangle.getHeight());
}
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
Vector2 hitCords = getWorldFromLocal(x, y);
Gizmo gizmo = hitGizmo(hitCords.x, hitCords.y);
if (touchedGizmo != null) {
touchedGizmo.touchUp(hitCords.x, hitCords.y);
for (int i = 0; i < gizmoList.size; i++) {
Gizmo item = gizmoList.get(i);
if (item.isSelected() && item.getClass().equals(touchedGizmo.getClass()) && item != touchedGizmo) {
item.touchUp(hitCords.x, hitCords.y);
}
}
}
touchedGizmo = null;
if (selectionRect.isVisible()) {
upWillClear = false;
selectByRect(rectangle);
Notifications.fireEvent(Notifications.obtainEvent(GameObjectSelectionChanged.class).set(selection));
} else if (upWillClear) {
FocusManager.resetFocus(getStage());
clearSelection();
Notifications.fireEvent(Notifications.obtainEvent(GameObjectSelectionChanged.class).set(selection));
} else {
if (!Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
// deselect all others, if they are selected
if (deselectOthers(selectedGameObject)) {
Notifications.fireEvent(Notifications.obtainEvent(GameObjectSelectionChanged.class).set(selection));
}
}
}
getStage().setKeyboardFocus(SceneEditorWorkspace.this);
selectionRect.setVisible(false);
}
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Input.Keys.DEL || keycode == Input.Keys.FORWARD_DEL) {
Array<GameObject> deleteList = new Array<>();
deleteList.addAll(selection);
clearSelection();
deleteGameObjects(deleteList);
Notifications.fireEvent(Notifications.obtainEvent(GameObjectSelectionChanged.class).set(selection));
}
if (keycode == Input.Keys.C && ctrlPressed()) {
copySelected();
}
if (keycode == Input.Keys.V && ctrlPressed()) {
pasteFromClipboard();
}
if (keycode == Input.Keys.A && ctrlPressed()) {
selectAll();
Notifications.fireEvent(Notifications.obtainEvent(GameObjectSelectionChanged.class).set(selection));
}
if (keycode == Input.Keys.Z && ctrlPressed() && !Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
TalosMain.Instance().ProjectController().undo();
}
if (keycode == Input.Keys.Z && ctrlPressed() && Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
TalosMain.Instance().ProjectController().redo();
}
for (Gizmo gizmo : gizmoList) {
if (gizmo.isSelected()) {
gizmo.keyDown(event, keycode);
}
}
return super.keyDown(event, keycode);
}
});
}
use of com.talosvfx.talos.editor.addons.scene.widgets.gizmos.Gizmo in project talos by rockbite.
the class SceneEditorWorkspace method selectByRect.
private void selectByRect(Rectangle rectangle) {
if (!Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
clearSelection();
}
for (int i = 0; i < gizmoList.size; i++) {
Gizmo gizmo = gizmoList.get(i);
if (gizmo instanceof TransformGizmo) {
TransformGizmo transformGizmo = (TransformGizmo) gizmo;
Vector2 worldPos = transformGizmo.getWorldPos();
Vector2 local = getLocalFromWorld(worldPos.x, worldPos.y);
if (rectangle.contains(local)) {
if (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
addToSelection(gizmo.getGameObject());
} else {
addToSelection(gizmo.getGameObject());
}
}
}
}
}
use of com.talosvfx.talos.editor.addons.scene.widgets.gizmos.Gizmo in project talos by rockbite.
the class SceneEditorWorkspace method removeGizmos.
private void removeGizmos(GameObject gameObject) {
Array<Gizmo> list = gizmoMap.get(gameObject);
for (Gizmo gizmo : list) {
gizmo.notifyRemove();
}
gizmoList.removeAll(list, true);
gizmoMap.remove(gameObject);
}
use of com.talosvfx.talos.editor.addons.scene.widgets.gizmos.Gizmo in project talos by rockbite.
the class SceneEditorWorkspace method drawContent.
@Override
public void drawContent(Batch batch, float parentAlpha) {
if (!(TalosMain.Instance().Project() instanceof SceneEditorProject))
return;
batch.end();
drawGrid(batch, parentAlpha);
batch.begin();
drawMainRenderer(batch, parentAlpha);
for (int i = 0; i < gizmoList.size; i++) {
Gizmo gizmo = gizmoList.get(i);
gizmo.setWoldWidth(getWorldWidth() * camera.zoom);
gizmo.draw(batch, parentAlpha);
}
}
use of com.talosvfx.talos.editor.addons.scene.widgets.gizmos.Gizmo in project talos by rockbite.
the class SceneEditorWorkspace method act.
@Override
public void act(float delta) {
if (!(TalosMain.Instance().Project() instanceof SceneEditorProject))
return;
super.act(delta);
for (int i = 0; i < gizmoList.size; i++) {
Gizmo gizmo = gizmoList.get(i);
gizmo.act(delta);
}
if (reloadScheduled > 0) {
reloadScheduled -= delta;
if (reloadScheduled <= 0) {
reloadScheduled = -1;
reloadProjectExplorer();
}
}
}
Aggregations