Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikSurfaceView.java @ 85038b84

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
import org.distorted.objectlib.main.TwistyObjectNode;
35

    
36
import org.distorted.screens.ScreenList;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

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

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

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

    
55
      if( !mCreated )
56
        {
57
        mCreated = true;
58
        mObjectController.createNode(width,height);
59
        TwistyObjectNode objectNode = mObjectController.getNode();
60
        mRenderer.getScreen().attach(objectNode);
61
        }
62
      }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
    boolean isVertical()
67
      {
68
      return mScreenHeight>mScreenWidth;
69
      }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
    RubikRenderer getRenderer()
74
      {
75
      return mRenderer;
76
      }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
    ObjectControl getObjectControl()
81
      {
82
      return mObjectController;
83
      }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
// PUBLIC API
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
    public RubikSurfaceView(Context context, AttributeSet attrs)
90
      {
91
      super(context,attrs);
92

    
93
      mCreated = false;
94

    
95
      if(!isInEditMode())
96
        {
97
        RubikActivity act = (RubikActivity)context;
98
        RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
99
        mObjectController = new ObjectControl(act,ref);
100
        mRenderer = new RubikRenderer(this);
101

    
102
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
103

    
104
        try
105
          {
106
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
107
          int esVersion = configurationInfo.reqGlEsVersion>>16;
108
          setEGLContextClientVersion(esVersion);
109
          setRenderer(mRenderer);
110
          }
111
        catch(Exception ex)
112
          {
113
          act.OpenGLError();
114

    
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
          crashlytics.setCustomKey("GL version"    , version );
123
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
124
          crashlytics.setCustomKey("GLSL renderer" , renderer);
125
          crashlytics.recordException(ex);
126
          }
127
        }
128
      }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
    @Override
133
    public void onPause()
134
      {
135
      super.onPause();
136
      mObjectController.onPause();
137
      }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
    @Override
142
    public void onResume()
143
      {
144
      super.onResume();
145
      mObjectController.onResume();
146
      }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
    @SuppressLint("ClickableViewAccessibility")
151
    @Override
152
    public boolean onTouchEvent(MotionEvent event)
153
      {
154
      int mode = ScreenList.getMode();
155
      return mObjectController.onTouchEvent(event,mode);
156
      }
157
}
158

    
(4-4/4)