1 |
58fd2ec0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.config;
|
11 |
|
|
|
12 |
|
|
import static org.distorted.objectlib.main.ObjectControl.MODE_REPLACE;
|
13 |
|
|
|
14 |
|
|
import android.annotation.SuppressLint;
|
15 |
|
|
import android.app.ActivityManager;
|
16 |
|
|
import android.content.Context;
|
17 |
|
|
import android.content.pm.ConfigurationInfo;
|
18 |
|
|
import android.opengl.GLES30;
|
19 |
|
|
import android.opengl.GLSurfaceView;
|
20 |
|
|
import android.util.AttributeSet;
|
21 |
|
|
import android.view.MotionEvent;
|
22 |
|
|
|
23 |
|
|
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
24 |
|
|
|
25 |
|
|
import org.distorted.objectlib.main.ObjectControl;
|
26 |
|
|
import org.distorted.objectlib.main.TwistyObjectNode;
|
27 |
|
|
import org.distorted.os.OSInterface;
|
28 |
|
|
|
29 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
|
31 |
|
|
public class ConfigSurfaceView extends GLSurfaceView
|
32 |
|
|
{
|
33 |
|
|
private ObjectControl mObjectController;
|
34 |
|
|
private ConfigRenderer mRenderer;
|
35 |
|
|
private OSInterface mInterface;
|
36 |
|
|
private boolean mCreated;
|
37 |
|
|
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
|
|
void setScreenSize(int width, int height)
|
41 |
|
|
{
|
42 |
|
|
mObjectController.setScreenSizeAndScaling(width,height, Math.min(width,height));
|
43 |
|
|
mObjectController.setObjectScale(1.00f);
|
44 |
|
|
|
45 |
|
|
if( !mCreated )
|
46 |
|
|
{
|
47 |
|
|
mCreated = true;
|
48 |
|
|
mObjectController.createNode(width,height);
|
49 |
|
|
TwistyObjectNode objectNode = mObjectController.getNode();
|
50 |
|
|
mRenderer.getScreen().attach(objectNode);
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
|
|
ObjectControl getObjectControl()
|
57 |
|
|
{
|
58 |
|
|
return mObjectController;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
|
|
ConfigRenderer getRenderer()
|
64 |
|
|
{
|
65 |
|
|
return mRenderer;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
|
|
void resetObject()
|
71 |
|
|
{
|
72 |
14da3188
|
leszek
|
ConfigActivity act = (ConfigActivity)getContext();
|
73 |
|
|
act.recreateStickers(ConfigScreenPane.DEFAULT_BORDERS,ConfigScreenPane.DEFAULT_CORNERS);
|
74 |
|
|
act.resetUI();
|
75 |
58fd2ec0
|
leszek
|
}
|
76 |
|
|
|
77 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
|
|
// PUBLIC API
|
79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
|
|
|
81 |
|
|
public ConfigSurfaceView(Context context, AttributeSet attrs)
|
82 |
|
|
{
|
83 |
|
|
super(context,attrs);
|
84 |
|
|
|
85 |
|
|
mCreated = false;
|
86 |
|
|
|
87 |
|
|
if(!isInEditMode())
|
88 |
|
|
{
|
89 |
|
|
ConfigActivity act = (ConfigActivity)context;
|
90 |
e91771e4
|
leszek
|
ConfigObjectLibInterface ref = new ConfigObjectLibInterface(act);
|
91 |
58fd2ec0
|
leszek
|
mInterface = new OSInterface(act,ref);
|
92 |
|
|
mObjectController = new ObjectControl(mInterface);
|
93 |
|
|
mObjectController.setRotateOnCreation(true);
|
94 |
|
|
mRenderer = new ConfigRenderer(this);
|
95 |
|
|
|
96 |
|
|
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
97 |
|
|
|
98 |
|
|
try
|
99 |
|
|
{
|
100 |
|
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
101 |
|
|
int esVersion = configurationInfo.reqGlEsVersion>>16;
|
102 |
|
|
setEGLContextClientVersion(esVersion);
|
103 |
|
|
setRenderer(mRenderer);
|
104 |
|
|
}
|
105 |
|
|
catch(Exception ex)
|
106 |
|
|
{
|
107 |
|
|
act.OpenGLError();
|
108 |
|
|
|
109 |
|
|
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
|
110 |
|
|
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
111 |
|
|
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
112 |
|
|
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
113 |
|
|
|
114 |
|
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
115 |
|
|
crashlytics.setCustomKey("GLSL Version" , shading );
|
116 |
|
|
crashlytics.setCustomKey("GL version" , version );
|
117 |
|
|
crashlytics.setCustomKey("GL Vendor " , vendor );
|
118 |
|
|
crashlytics.setCustomKey("GLSL renderer" , renderer);
|
119 |
|
|
crashlytics.recordException(ex);
|
120 |
|
|
}
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125 |
|
|
|
126 |
|
|
@Override
|
127 |
|
|
public void onPause()
|
128 |
|
|
{
|
129 |
|
|
super.onPause();
|
130 |
|
|
mObjectController.onPause();
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
134 |
|
|
|
135 |
|
|
@Override
|
136 |
|
|
public void onResume()
|
137 |
|
|
{
|
138 |
|
|
super.onResume();
|
139 |
|
|
mObjectController.onResume();
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143 |
|
|
|
144 |
|
|
@SuppressLint("ClickableViewAccessibility")
|
145 |
|
|
@Override
|
146 |
|
|
public boolean onTouchEvent(MotionEvent event)
|
147 |
|
|
{
|
148 |
|
|
mInterface.setMotionEvent(event);
|
149 |
|
|
return mObjectController.onTouchEvent(MODE_REPLACE);
|
150 |
|
|
}
|
151 |
|
|
}
|