Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikSurfaceView.java @ 2da68298

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 2da68298 Leszek Koltunski
53
      try
54
        {
55
        RubikActivity act = (RubikActivity)getContext();
56
        act.setScreenSize(width,height);
57
        }
58
      catch( Exception ex )
59
        {
60
        android.util.Log.e("D", "Failed to set screen size!");
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
      if(!isInEditMode())
94
        {
95 cd83d0aa Leszek Koltunski
        RubikActivity act = (RubikActivity)context;
96 e019c70b Leszek Koltunski
        RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
97
        mObjectController = new ObjectControl(act,ref);
98 2afc6754 Leszek Koltunski
        mRenderer = new RubikRenderer(this);
99 cd83d0aa Leszek Koltunski
100
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
101
102 4489e68e Leszek Koltunski
        try
103 cd83d0aa Leszek Koltunski
          {
104
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
105 e7e0a94d Leszek Koltunski
          int esVersion = configurationInfo.reqGlEsVersion>>16;
106
          setEGLContextClientVersion(esVersion);
107 cd83d0aa Leszek Koltunski
          setRenderer(mRenderer);
108
          }
109 4489e68e Leszek Koltunski
        catch(Exception ex)
110
          {
111 e7e0a94d Leszek Koltunski
          act.OpenGLError();
112 4489e68e Leszek Koltunski
113
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
114
          String version = GLES30.glGetString(GLES30.GL_VERSION);
115
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
116
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
117
118
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
119
          crashlytics.setCustomKey("GLSL Version"  , shading );
120 0812242b Leszek Koltunski
          crashlytics.setCustomKey("GL version"    , version );
121 4489e68e Leszek Koltunski
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
122 0812242b Leszek Koltunski
          crashlytics.setCustomKey("GLSL renderer" , renderer);
123 4489e68e Leszek Koltunski
          crashlytics.recordException(ex);
124
          }
125 47ba5ddc Leszek Koltunski
        }
126
      }
127
128 eaf46415 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
129
130 c65a5efe Leszek Koltunski
    @Override
131
    public void onPause()
132 eaf46415 Leszek Koltunski
      {
133 c65a5efe Leszek Koltunski
      super.onPause();
134
      mObjectController.onPause();
135 eaf46415 Leszek Koltunski
      }
136
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
139 05c20dad Leszek Koltunski
    @Override
140
    public void onResume()
141 9205f15e Leszek Koltunski
      {
142 05c20dad Leszek Koltunski
      super.onResume();
143 c65a5efe Leszek Koltunski
      mObjectController.onResume();
144 9205f15e Leszek Koltunski
      }
145
146 47ba5ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
147
148 f57d0ad9 Leszek Koltunski
    @SuppressLint("ClickableViewAccessibility")
149 47ba5ddc Leszek Koltunski
    @Override
150
    public boolean onTouchEvent(MotionEvent event)
151
      {
152 dd1a65c1 Leszek Koltunski
      int mode = ScreenList.getMode();
153
      return mObjectController.onTouchEvent(event,mode);
154 47ba5ddc Leszek Koltunski
      }
155 0c52af30 Leszek Koltunski
}