1 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
fdec60a3
|
Leszek Koltunski
|
// This file is part of Magic Cube. //
|
5 |
0c52af30
|
Leszek Koltunski
|
// //
|
6 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
0c52af30
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
0c52af30
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
fdec60a3
|
Leszek Koltunski
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.main;
|
21 |
0c52af30
|
Leszek Koltunski
|
|
22 |
f57d0ad9
|
Leszek Koltunski
|
import android.annotation.SuppressLint;
|
23 |
0c52af30
|
Leszek Koltunski
|
import android.app.ActivityManager;
|
24 |
|
|
import android.content.Context;
|
25 |
|
|
import android.content.pm.ConfigurationInfo;
|
26 |
4489e68e
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
27 |
0c52af30
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
28 |
|
|
import android.util.AttributeSet;
|
29 |
|
|
import android.view.MotionEvent;
|
30 |
|
|
|
31 |
b96a20a4
|
Leszek Koltunski
|
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
32 |
|
|
|
33 |
dd1a65c1
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectControl;
|
34 |
a946af34
|
Leszek Koltunski
|
import org.distorted.objectlib.main.TwistyObjectNode;
|
35 |
3f7a4363
|
Leszek Koltunski
|
|
36 |
fcd5b990
|
Leszek Koltunski
|
import org.distorted.screens.ScreenList;
|
37 |
0c52af30
|
Leszek Koltunski
|
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
1bafcba4
|
Leszek Koltunski
|
public class RubikSurfaceView extends GLSurfaceView
|
41 |
0c52af30
|
Leszek Koltunski
|
{
|
42 |
dd1a65c1
|
Leszek Koltunski
|
private ObjectControl mObjectController;
|
43 |
beb325a0
|
Leszek Koltunski
|
private RubikRenderer mRenderer;
|
44 |
dd1a65c1
|
Leszek Koltunski
|
private int mScreenWidth, mScreenHeight;
|
45 |
338babe8
|
Leszek Koltunski
|
private boolean mCreated;
|
46 |
ee5c2ae1
|
Leszek Koltunski
|
|
47 |
0fd3ac1f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
|
|
|
49 |
|
|
void setScreenSize(int width, int height)
|
50 |
|
|
{
|
51 |
|
|
mScreenWidth = width;
|
52 |
|
|
mScreenHeight= height;
|
53 |
dd1a65c1
|
Leszek Koltunski
|
mObjectController.setScreenSize(width,height);
|
54 |
2da68298
|
Leszek Koltunski
|
|
55 |
338babe8
|
Leszek Koltunski
|
if( !mCreated )
|
56 |
|
|
{
|
57 |
|
|
mCreated = true;
|
58 |
|
|
mObjectController.createNode(width,height);
|
59 |
a946af34
|
Leszek Koltunski
|
TwistyObjectNode objectNode = mObjectController.getNode();
|
60 |
338babe8
|
Leszek Koltunski
|
mRenderer.getScreen().attach(objectNode);
|
61 |
|
|
}
|
62 |
0fd3ac1f
|
Leszek Koltunski
|
}
|
63 |
|
|
|
64 |
4c0cd600
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
65 |
|
|
|
66 |
|
|
boolean isVertical()
|
67 |
|
|
{
|
68 |
|
|
return mScreenHeight>mScreenWidth;
|
69 |
|
|
}
|
70 |
|
|
|
71 |
0fd3ac1f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72 |
|
|
|
73 |
|
|
RubikRenderer getRenderer()
|
74 |
|
|
{
|
75 |
|
|
return mRenderer;
|
76 |
|
|
}
|
77 |
|
|
|
78 |
8becce57
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79 |
|
|
|
80 |
2afc6754
|
Leszek Koltunski
|
ObjectControl getObjectControl()
|
81 |
8becce57
|
Leszek Koltunski
|
{
|
82 |
2afc6754
|
Leszek Koltunski
|
return mObjectController;
|
83 |
e03e0352
|
Leszek Koltunski
|
}
|
84 |
|
|
|
85 |
47ba5ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86 |
|
|
// PUBLIC API
|
87 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88 |
|
|
|
89 |
|
|
public RubikSurfaceView(Context context, AttributeSet attrs)
|
90 |
|
|
{
|
91 |
|
|
super(context,attrs);
|
92 |
|
|
|
93 |
338babe8
|
Leszek Koltunski
|
mCreated = false;
|
94 |
|
|
|
95 |
47ba5ddc
|
Leszek Koltunski
|
if(!isInEditMode())
|
96 |
|
|
{
|
97 |
cd83d0aa
|
Leszek Koltunski
|
RubikActivity act = (RubikActivity)context;
|
98 |
e019c70b
|
Leszek Koltunski
|
RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
|
99 |
|
|
mObjectController = new ObjectControl(act,ref);
|
100 |
2afc6754
|
Leszek Koltunski
|
mRenderer = new RubikRenderer(this);
|
101 |
cd83d0aa
|
Leszek Koltunski
|
|
102 |
|
|
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
103 |
|
|
|
104 |
4489e68e
|
Leszek Koltunski
|
try
|
105 |
cd83d0aa
|
Leszek Koltunski
|
{
|
106 |
|
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
107 |
e7e0a94d
|
Leszek Koltunski
|
int esVersion = configurationInfo.reqGlEsVersion>>16;
|
108 |
|
|
setEGLContextClientVersion(esVersion);
|
109 |
cd83d0aa
|
Leszek Koltunski
|
setRenderer(mRenderer);
|
110 |
|
|
}
|
111 |
4489e68e
|
Leszek Koltunski
|
catch(Exception ex)
|
112 |
|
|
{
|
113 |
e7e0a94d
|
Leszek Koltunski
|
act.OpenGLError();
|
114 |
4489e68e
|
Leszek Koltunski
|
|
115 |
|
|
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
|
116 |
|
|
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
117 |
|
|
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
118 |
|
|
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
119 |
|
|
|
120 |
|
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
121 |
|
|
crashlytics.setCustomKey("GLSL Version" , shading );
|
122 |
0812242b
|
Leszek Koltunski
|
crashlytics.setCustomKey("GL version" , version );
|
123 |
4489e68e
|
Leszek Koltunski
|
crashlytics.setCustomKey("GL Vendor " , vendor );
|
124 |
0812242b
|
Leszek Koltunski
|
crashlytics.setCustomKey("GLSL renderer" , renderer);
|
125 |
4489e68e
|
Leszek Koltunski
|
crashlytics.recordException(ex);
|
126 |
|
|
}
|
127 |
47ba5ddc
|
Leszek Koltunski
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
eaf46415
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131 |
|
|
|
132 |
c65a5efe
|
Leszek Koltunski
|
@Override
|
133 |
|
|
public void onPause()
|
134 |
eaf46415
|
Leszek Koltunski
|
{
|
135 |
c65a5efe
|
Leszek Koltunski
|
super.onPause();
|
136 |
|
|
mObjectController.onPause();
|
137 |
eaf46415
|
Leszek Koltunski
|
}
|
138 |
|
|
|
139 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140 |
|
|
|
141 |
05c20dad
|
Leszek Koltunski
|
@Override
|
142 |
|
|
public void onResume()
|
143 |
9205f15e
|
Leszek Koltunski
|
{
|
144 |
05c20dad
|
Leszek Koltunski
|
super.onResume();
|
145 |
c65a5efe
|
Leszek Koltunski
|
mObjectController.onResume();
|
146 |
9205f15e
|
Leszek Koltunski
|
}
|
147 |
|
|
|
148 |
47ba5ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149 |
|
|
|
150 |
f57d0ad9
|
Leszek Koltunski
|
@SuppressLint("ClickableViewAccessibility")
|
151 |
47ba5ddc
|
Leszek Koltunski
|
@Override
|
152 |
|
|
public boolean onTouchEvent(MotionEvent event)
|
153 |
|
|
{
|
154 |
dd1a65c1
|
Leszek Koltunski
|
int mode = ScreenList.getMode();
|
155 |
|
|
return mObjectController.onTouchEvent(event,mode);
|
156 |
47ba5ddc
|
Leszek Koltunski
|
}
|
157 |
0c52af30
|
Leszek Koltunski
|
}
|