Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikSurfaceView.java @ 6b1998e0

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
      try
64
        {
65
        RubikActivity act = (RubikActivity)getContext();
66
        act.setScreenSize(width,height);
67
        }
68
      catch( Exception ex )
69
        {
70
        android.util.Log.e("D", "Failed to set screen size!");
71
        }
72
      }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
    boolean isVertical()
77
      {
78
      return mScreenHeight>mScreenWidth;
79
      }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
    RubikRenderer getRenderer()
84
      {
85
      return mRenderer;
86
      }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
    ObjectControl getObjectControl()
91
      {
92
      return mObjectController;
93
      }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
// PUBLIC API
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
    public RubikSurfaceView(Context context, AttributeSet attrs)
100
      {
101
      super(context,attrs);
102

    
103
      mCreated = false;
104

    
105
      if(!isInEditMode())
106
        {
107
        RubikActivity act = (RubikActivity)context;
108
        RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
109
        mObjectController = new ObjectControl(act,ref);
110
        mRenderer = new RubikRenderer(this);
111

    
112
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
113

    
114
        try
115
          {
116
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
117
          int esVersion = configurationInfo.reqGlEsVersion>>16;
118
          setEGLContextClientVersion(esVersion);
119
          setRenderer(mRenderer);
120
          }
121
        catch(Exception ex)
122
          {
123
          act.OpenGLError();
124

    
125
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
126
          String version = GLES30.glGetString(GLES30.GL_VERSION);
127
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
128
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
129

    
130
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
131
          crashlytics.setCustomKey("GLSL Version"  , shading );
132
          crashlytics.setCustomKey("GL version"    , version );
133
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
134
          crashlytics.setCustomKey("GLSL renderer" , renderer);
135
          crashlytics.recordException(ex);
136
          }
137
        }
138
      }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

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

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

    
151
    @Override
152
    public void onResume()
153
      {
154
      super.onResume();
155
      mObjectController.onResume();
156
      }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
    @SuppressLint("ClickableViewAccessibility")
161
    @Override
162
    public boolean onTouchEvent(MotionEvent event)
163
      {
164
      int mode = ScreenList.getMode();
165
      return mObjectController.onTouchEvent(event,mode);
166
      }
167
}
168

    
(4-4/4)