Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialSurfaceView.java @ 525a9a85

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.tutorials;
21

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

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

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

    
35
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
36

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

    
39
public class TutorialSurfaceView extends GLSurfaceView
40
{
41
    private ObjectControl mObjectController;
42
    private TutorialRenderer mRenderer;
43
    private int mScreenWidth, mScreenHeight;
44
    private boolean mCreated;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
    void setScreenSize(int width, int height)
49
      {
50
      mScreenWidth = width;
51
      mScreenHeight= height;
52
      mObjectController.setScreenSize(width,height);
53
      mObjectController.setObjectMove( (int)(-0.5f*width*TutorialActivity.BAR_RATIO), 0);
54
      mObjectController.setObjectScale(0.80f);
55

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

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

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

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
    ObjectControl getObjectControl()
75
      {
76
      return mObjectController;
77
      }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
// PUBLIC API
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
    public TutorialSurfaceView(Context context, AttributeSet attrs)
84
      {
85
      super(context,attrs);
86

    
87
      mCreated = false;
88

    
89
      if(!isInEditMode())
90
        {
91
        TutorialActivity act = (TutorialActivity)context;
92
        TutorialObjectLibInterface ref = new TutorialObjectLibInterface(act);
93
        mObjectController = new ObjectControl(act,ref);
94
        mRenderer = new TutorialRenderer(this);
95

    
96
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
97

    
98
        try
99
          {
100
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
101
          int esVersion = configurationInfo.reqGlEsVersion>>16;
102
          setEGLContextClientVersion(esVersion);
103
          setRenderer(mRenderer);
104
          }
105
        catch(Exception ex)
106
          {
107
          act.OpenGLError();
108

    
109
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
110
          String version = GLES30.glGetString(GLES30.GL_VERSION);
111
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
112
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
113

    
114
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
115
          crashlytics.setCustomKey("GLSL Version"  , shading );
116
          crashlytics.setCustomKey("GL version"    , version );
117
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
118
          crashlytics.setCustomKey("GLSL renderer" , renderer);
119
          crashlytics.recordException(ex);
120
          }
121
        }
122
      }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
    @Override
127
    public void onPause()
128
      {
129
      super.onPause();
130
      mObjectController.onPause();
131
      }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
    @Override
136
    public void onResume()
137
      {
138
      super.onResume();
139
      mObjectController.onResume();
140
      }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
    @Override
145
    public boolean onTouchEvent(MotionEvent event)
146
      {
147
      return mObjectController.onTouchEvent(event,MODE_ROTATE);
148
      }
149
}
150

    
(6-6/7)