Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// 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
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// 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
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.main;
21

    
22
import android.annotation.SuppressLint;
23
import android.app.ActivityManager;
24
import android.content.Context;
25
import android.content.pm.ConfigurationInfo;
26
import android.opengl.GLES30;
27
import android.opengl.GLSurfaceView;
28
import android.util.AttributeSet;
29
import android.view.MotionEvent;
30

    
31
import com.google.firebase.crashlytics.FirebaseCrashlytics;
32

    
33
import org.distorted.objectlib.main.ObjectControl;
34

    
35
import org.distorted.screens.ScreenList;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
public class RubikSurfaceView extends GLSurfaceView
40
{
41
    private ObjectControl mObjectController;
42
    private RubikRenderer mRenderer;
43
    private int mScreenWidth, mScreenHeight;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
    void setScreenSize(int width, int height)
48
      {
49
      mScreenWidth = width;
50
      mScreenHeight= height;
51
      mObjectController.setScreenSize(width,height);
52
      }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
    boolean isVertical()
57
      {
58
      return mScreenHeight>mScreenWidth;
59
      }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
    RubikRenderer getRenderer()
64
      {
65
      return mRenderer;
66
      }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
    ObjectControl getObjectControl()
71
      {
72
      return mObjectController;
73
      }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// PUBLIC API
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
    public RubikSurfaceView(Context context, AttributeSet attrs)
80
      {
81
      super(context,attrs);
82

    
83
      if(!isInEditMode())
84
        {
85
        RubikActivity act = (RubikActivity)context;
86
        RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
87
        mObjectController = new ObjectControl(act,ref);
88
        mRenderer = new RubikRenderer(this);
89

    
90
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
91

    
92
        try
93
          {
94
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
95
          int esVersion = configurationInfo.reqGlEsVersion>>16;
96
          setEGLContextClientVersion(esVersion);
97
          setRenderer(mRenderer);
98
          }
99
        catch(Exception ex)
100
          {
101
          act.OpenGLError();
102

    
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
          crashlytics.setCustomKey("GL version"    , version );
111
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
112
          crashlytics.setCustomKey("GLSL renderer" , renderer);
113
          crashlytics.recordException(ex);
114
          }
115
        }
116
      }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
    @Override
121
    public void onPause()
122
      {
123
      super.onPause();
124
      mObjectController.onPause();
125
      }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
    @Override
130
    public void onResume()
131
      {
132
      super.onResume();
133
      mObjectController.onResume();
134
      }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
    @SuppressLint("ClickableViewAccessibility")
139
    @Override
140
    public boolean onTouchEvent(MotionEvent event)
141
      {
142
      int mode = ScreenList.getMode();
143
      return mObjectController.onTouchEvent(event,mode);
144
      }
145
}
146

    
(4-4/4)