Project

General

Profile

Download (5.74 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / main / RubikSurfaceView.java @ f57d0ad9

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 3f7a4363 Leszek Koltunski
35 fcd5b990 Leszek Koltunski
import org.distorted.screens.ScreenList;
36 0c52af30 Leszek Koltunski
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39 1bafcba4 Leszek Koltunski
public class RubikSurfaceView extends GLSurfaceView
40 0c52af30 Leszek Koltunski
{
41 dd1a65c1 Leszek Koltunski
    private ObjectControl mObjectController;
42 beb325a0 Leszek Koltunski
    private RubikRenderer mRenderer;
43 dd1a65c1 Leszek Koltunski
    private int mScreenWidth, mScreenHeight;
44 ee5c2ae1 Leszek Koltunski
45 0fd3ac1f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
46
47
    void setScreenSize(int width, int height)
48
      {
49
      mScreenWidth = width;
50
      mScreenHeight= height;
51 dd1a65c1 Leszek Koltunski
      mObjectController.setScreenSize(width,height);
52 0fd3ac1f Leszek Koltunski
      }
53
54 4c0cd600 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56
    boolean isVertical()
57
      {
58
      return mScreenHeight>mScreenWidth;
59
      }
60
61 0fd3ac1f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
62
63
    RubikRenderer getRenderer()
64
      {
65
      return mRenderer;
66
      }
67
68 8becce57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
69
70 2afc6754 Leszek Koltunski
    ObjectControl getObjectControl()
71 8becce57 Leszek Koltunski
      {
72 2afc6754 Leszek Koltunski
      return mObjectController;
73 e03e0352 Leszek Koltunski
      }
74
75 47ba5ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// PUBLIC API
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
79
    public RubikSurfaceView(Context context, AttributeSet attrs)
80
      {
81
      super(context,attrs);
82
83
      if(!isInEditMode())
84
        {
85 cd83d0aa Leszek Koltunski
        RubikActivity act = (RubikActivity)context;
86 e019c70b Leszek Koltunski
        RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
87
        mObjectController = new ObjectControl(act,ref);
88 2afc6754 Leszek Koltunski
        mRenderer = new RubikRenderer(this);
89 cd83d0aa Leszek Koltunski
90
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
91
92 4489e68e Leszek Koltunski
        try
93 cd83d0aa Leszek Koltunski
          {
94
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
95 e7e0a94d Leszek Koltunski
          int esVersion = configurationInfo.reqGlEsVersion>>16;
96
          setEGLContextClientVersion(esVersion);
97 cd83d0aa Leszek Koltunski
          setRenderer(mRenderer);
98
          }
99 4489e68e Leszek Koltunski
        catch(Exception ex)
100
          {
101 e7e0a94d Leszek Koltunski
          act.OpenGLError();
102 4489e68e Leszek Koltunski
103
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
104
          String version = GLES30.glGetString(GLES30.GL_VERSION);
105
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
106
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
107
108
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
109
          crashlytics.setCustomKey("GLSL Version"  , shading );
110 0812242b Leszek Koltunski
          crashlytics.setCustomKey("GL version"    , version );
111 4489e68e Leszek Koltunski
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
112 0812242b Leszek Koltunski
          crashlytics.setCustomKey("GLSL renderer" , renderer);
113 4489e68e Leszek Koltunski
          crashlytics.recordException(ex);
114
          }
115 47ba5ddc Leszek Koltunski
        }
116
      }
117
118 eaf46415 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
119
120 c65a5efe Leszek Koltunski
    @Override
121
    public void onPause()
122 eaf46415 Leszek Koltunski
      {
123 c65a5efe Leszek Koltunski
      super.onPause();
124
      mObjectController.onPause();
125 eaf46415 Leszek Koltunski
      }
126
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
129 05c20dad Leszek Koltunski
    @Override
130
    public void onResume()
131 9205f15e Leszek Koltunski
      {
132 05c20dad Leszek Koltunski
      super.onResume();
133 c65a5efe Leszek Koltunski
      mObjectController.onResume();
134 9205f15e Leszek Koltunski
      }
135
136 47ba5ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
137
138 f57d0ad9 Leszek Koltunski
    @SuppressLint("ClickableViewAccessibility")
139 47ba5ddc Leszek Koltunski
    @Override
140
    public boolean onTouchEvent(MotionEvent event)
141
      {
142 dd1a65c1 Leszek Koltunski
      int mode = ScreenList.getMode();
143
      return mObjectController.onTouchEvent(event,mode);
144 47ba5ddc Leszek Koltunski
      }
145 0c52af30 Leszek Koltunski
}