mirror of
https://github.com/Dark98/SliceBeam.git
synced 2026-07-03 00:38:53 +00:00
Implement additional alternative camera control method
This commit is contained in:
@@ -4,12 +4,6 @@ import android.annotation.SuppressLint;
|
||||
import android.app.Application;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.instacart.library.truetime.TrueTime;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -32,15 +26,11 @@ import ru.ytkab0bp.slicebeam.boot.PrefsTask;
|
||||
import ru.ytkab0bp.slicebeam.boot.PrintConfigWarmupTask;
|
||||
import ru.ytkab0bp.slicebeam.boot.TrueTimeTask;
|
||||
import ru.ytkab0bp.slicebeam.boot.VibrationUtilsTask;
|
||||
import ru.ytkab0bp.slicebeam.cloud.CloudController;
|
||||
import ru.ytkab0bp.slicebeam.config.ConfigObject;
|
||||
import ru.ytkab0bp.slicebeam.slic3r.ConfigOptionDef;
|
||||
import ru.ytkab0bp.slicebeam.slic3r.PrintConfigDef;
|
||||
import ru.ytkab0bp.slicebeam.slic3r.Slic3rConfigWrapper;
|
||||
import ru.ytkab0bp.slicebeam.utils.IOUtils;
|
||||
import ru.ytkab0bp.slicebeam.utils.Prefs;
|
||||
import ru.ytkab0bp.slicebeam.utils.VibrationUtils;
|
||||
import ru.ytkab0bp.slicebeam.utils.ViewUtils;
|
||||
|
||||
public class SliceBeam extends Application {
|
||||
public static SliceBeam INSTANCE;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.ytkab0bp.slicebeam.components.bed_menu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.dynamicanimation.animation.FloatValueHolder;
|
||||
@@ -10,6 +11,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import ru.ytkab0bp.slicebeam.R;
|
||||
import ru.ytkab0bp.slicebeam.components.BeamAlertDialogBuilder;
|
||||
import ru.ytkab0bp.slicebeam.recycler.SimpleRecyclerItem;
|
||||
import ru.ytkab0bp.slicebeam.recycler.SpaceItem;
|
||||
import ru.ytkab0bp.slicebeam.render.Camera;
|
||||
@@ -122,7 +124,20 @@ public class CameraMenu extends ListBedMenu {
|
||||
animateTo(toOrigin, toPosition);
|
||||
}),
|
||||
new SpaceItem(portrait ? ViewUtils.dp(8) : 0, portrait ? 0 : ViewUtils.dp(8)),
|
||||
new BedMenuItem(R.string.MenuCameraEnableRotation, R.drawable.sync_outline_28).setCheckable((buttonView, isChecked) -> Prefs.setRotationEnabled(isChecked), Prefs.isRotationEnabled()),
|
||||
new BedMenuItem(R.string.MenuCameraControlMode, R.drawable.hand_point_up_outline_28).onClick(v -> {
|
||||
Context ctx = v.getContext();
|
||||
new BeamAlertDialogBuilder(v.getContext())
|
||||
.setTitle(R.string.MenuCameraControlMode)
|
||||
.setSingleChoiceItems(new CharSequence[] {
|
||||
ctx.getString(R.string.MenuCameraControlModeOne),
|
||||
ctx.getString(R.string.MenuCameraControlModeTwo),
|
||||
ctx.getString(R.string.MenuCameraControlModeThree)
|
||||
}, Prefs.getCameraControlMode(), (dialog, which) -> {
|
||||
Prefs.setCameraControlMode(which);
|
||||
dialog.dismiss();
|
||||
})
|
||||
.show();
|
||||
}),
|
||||
new BedMenuItem(R.string.MenuCameraOrtho, R.drawable.image_format_32).setCheckable((buttonView, isChecked) -> {
|
||||
Prefs.setOrthoProjectionEnabled(isChecked);
|
||||
fragment.getGlView().getRenderer().updateProjection();
|
||||
|
||||
@@ -68,12 +68,12 @@ public class Prefs {
|
||||
return mPrefs.getString("beam_server_data", "{}");
|
||||
}
|
||||
|
||||
public static boolean isRotationEnabled() {
|
||||
return mPrefs.getBoolean("rotation_enabled", true);
|
||||
public static int getCameraControlMode() {
|
||||
return mPrefs.getInt("camera_control_mode", mPrefs.getBoolean("rotation_enabled", true) ? CAMERA_CONTROL_MODE_ROTATE_MOVE : CAMERA_CONTROL_MODE_MOVE_ONLY);
|
||||
}
|
||||
|
||||
public static void setRotationEnabled(boolean e) {
|
||||
mPrefs.edit().putBoolean("rotation_enabled", e).apply();
|
||||
public static void setCameraControlMode(int mode) {
|
||||
mPrefs.edit().putInt("camera_control_mode", mode).apply();
|
||||
}
|
||||
|
||||
public static boolean isOrthoProjectionEnabled() {
|
||||
|
||||
@@ -38,8 +38,8 @@ public class GLView extends GLSurfaceView implements IThemeView {
|
||||
private int touchSlop;
|
||||
|
||||
private boolean fromTwoPointers;
|
||||
private boolean isRotating;
|
||||
private boolean isMoving;
|
||||
private boolean onePointerGesture;
|
||||
private boolean twoPointerGesture;
|
||||
private boolean isScaling;
|
||||
|
||||
private long lastActionTime = System.currentTimeMillis();
|
||||
@@ -268,14 +268,14 @@ public class GLView extends GLSurfaceView implements IThemeView {
|
||||
if (e.getPointerCount() == 1) {
|
||||
fromTwoPointers = false;
|
||||
isScaling = false;
|
||||
isMoving = false;
|
||||
twoPointerGesture = false;
|
||||
lastActionTime = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.getPointerCount() == 1) {
|
||||
if (!isRotating && action != MotionEvent.ACTION_CANCEL) {
|
||||
if (!onePointerGesture && action != MotionEvent.ACTION_CANCEL) {
|
||||
if (renderer.onClick(e.getX() * Prefs.getRenderScale(), e.getY() * Prefs.getRenderScale())) {
|
||||
requestRender();
|
||||
}
|
||||
@@ -283,7 +283,7 @@ public class GLView extends GLSurfaceView implements IThemeView {
|
||||
|
||||
lastX = e.getX(0);
|
||||
lastY = e.getY(0);
|
||||
isRotating = false;
|
||||
onePointerGesture = false;
|
||||
}
|
||||
|
||||
// TODO: Rotate with inertia
|
||||
@@ -300,16 +300,16 @@ public class GLView extends GLSurfaceView implements IThemeView {
|
||||
|
||||
if (deltaMs > 128) {
|
||||
isScaling = false;
|
||||
isMoving = false;
|
||||
twoPointerGesture = false;
|
||||
}
|
||||
|
||||
boolean startingGesture = false;
|
||||
if (!isScaling && !isMoving) {
|
||||
if (!isScaling && !twoPointerGesture) {
|
||||
if (Math.abs(distanceX) < touchSlop && Math.abs(distanceY) < touchSlop && Math.abs(len - lastLength) > touchSlop * 1.5f) {
|
||||
isScaling = true;
|
||||
startingGesture = true;
|
||||
} else if (Math.sqrt(distanceX * distanceX + distanceY * distanceY) >= touchSlop) {
|
||||
isMoving = true;
|
||||
twoPointerGesture = true;
|
||||
startingGesture = true;
|
||||
}
|
||||
}
|
||||
@@ -325,9 +325,14 @@ public class GLView extends GLSurfaceView implements IThemeView {
|
||||
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
} else if (isMoving) {
|
||||
} else if (twoPointerGesture) {
|
||||
if (!startingGesture) {
|
||||
renderer.getCamera().move(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
|
||||
int mode = Prefs.getCameraControlMode();
|
||||
if (mode == Prefs.CAMERA_CONTROL_MODE_ROTATE_MOVE || mode == Prefs.CAMERA_CONTROL_MODE_MOVE_ONLY) {
|
||||
renderer.getCamera().move(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
|
||||
} else {
|
||||
renderer.getCamera().rotateAround(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
|
||||
}
|
||||
requestRender();
|
||||
}
|
||||
|
||||
@@ -338,16 +343,17 @@ public class GLView extends GLSurfaceView implements IThemeView {
|
||||
float distanceX = lastX - e.getX(), distanceY = lastY - e.getY();
|
||||
boolean startingGesture = false;
|
||||
|
||||
if (!isRotating) {
|
||||
if (!onePointerGesture) {
|
||||
if (Math.sqrt(distanceX * distanceX + distanceY * distanceY) >= touchSlop) {
|
||||
isRotating = true;
|
||||
onePointerGesture = true;
|
||||
startingGesture = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isRotating) {
|
||||
if (onePointerGesture) {
|
||||
if (!startingGesture) {
|
||||
if (Prefs.isRotationEnabled()) {
|
||||
int mode = Prefs.getCameraControlMode();
|
||||
if (mode == Prefs.CAMERA_CONTROL_MODE_ROTATE_MOVE) {
|
||||
renderer.getCamera().rotateAround(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
|
||||
} else {
|
||||
renderer.getCamera().move(distanceX / touchSlop * Prefs.getCameraSensitivity(), distanceY / touchSlop * Prefs.getCameraSensitivity());
|
||||
|
||||
Reference in New Issue
Block a user