Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikSurfaceView.java @ 79357e2b

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.main;
11

    
12
import android.annotation.SuppressLint;
13
import android.app.ActivityManager;
14
import android.content.Context;
15
import android.content.pm.ConfigurationInfo;
16
import android.opengl.GLES30;
17
import android.opengl.GLSurfaceView;
18
import android.util.AttributeSet;
19
import android.view.MotionEvent;
20

    
21
import com.google.firebase.crashlytics.FirebaseCrashlytics;
22

    
23
import org.distorted.external.RubikScores;
24
import org.distorted.library.main.DistortedScreen;
25
import org.distorted.objectlib.main.ObjectControl;
26
import org.distorted.objectlib.main.TwistyObjectNode;
27
import org.distorted.overlays.DataStars;
28
import org.distorted.overlays.OverlayStars;
29
import org.distorted.screens.ScreenList;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class RubikSurfaceView extends GLSurfaceView
34
{
35
    private ObjectControl mObjectController;
36
    private RubikRenderer mRenderer;
37
    private int mScreenWidth, mScreenHeight;
38
    private boolean mCreated;
39
    private boolean mShowStars;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
    void setScreenSize(int width, int height)
44
      {
45
      mScreenWidth = width;
46
      mScreenHeight= height;
47
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height)));
48

    
49
      if( !mCreated )
50
        {
51
        mCreated = true;
52
        mObjectController.createNode(width,height);
53
        TwistyObjectNode objectNode = mObjectController.getNode();
54
        objectNode.glDepthMask(false);
55
        objectNode.glStencilMask(0);
56
        mRenderer.getScreen().attach(objectNode);
57

    
58
        if( mShowStars )
59
          {
60
          mShowStars = false;
61
          RubikScores scores = RubikScores.getInstance();
62
          int totStars = scores.getNumStars();
63
          DistortedScreen screen = mRenderer.getScreen();
64
          OverlayStars stars = new OverlayStars();
65
          DataStars data = new DataStars(totStars,0,getResources());
66
          stars.startOverlay(screen,null,data);
67
          }
68
        }
69
      }
70

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

    
73
    void setShowStars()
74
      {
75
      mShowStars = true;
76
      }
77

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

    
80
    boolean isVertical()
81
      {
82
      return mScreenHeight>mScreenWidth;
83
      }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
    RubikRenderer getRenderer()
88
      {
89
      return mRenderer;
90
      }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
    ObjectControl getObjectControl()
95
      {
96
      return mObjectController;
97
      }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
// PUBLIC API
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
    public RubikSurfaceView(Context context, AttributeSet attrs)
104
      {
105
      super(context,attrs);
106

    
107
      mCreated = false;
108
      mShowStars = false;
109

    
110
      if(!isInEditMode())
111
        {
112
        RubikActivity act = (RubikActivity)context;
113
        RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
114
        mObjectController = new ObjectControl(act,ref);
115
        mRenderer = new RubikRenderer(this);
116

    
117
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
118

    
119
        try
120
          {
121
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
122
          int esVersion = configurationInfo.reqGlEsVersion>>16;
123
          setEGLContextClientVersion(esVersion);
124
          setRenderer(mRenderer);
125
          }
126
        catch(Exception ex)
127
          {
128
          act.OpenGLError();
129

    
130
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
131
          String version = GLES30.glGetString(GLES30.GL_VERSION);
132
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
133
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
134

    
135
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
136
          crashlytics.setCustomKey("GLSL Version"  , shading );
137
          crashlytics.setCustomKey("GL version"    , version );
138
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
139
          crashlytics.setCustomKey("GLSL renderer" , renderer);
140
          crashlytics.recordException(ex);
141
          }
142
        }
143
      }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
    @Override
148
    public void onPause()
149
      {
150
      super.onPause();
151
      mObjectController.onPause();
152
      }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
    @Override
157
    public void onResume()
158
      {
159
      super.onResume();
160
      mObjectController.onResume();
161
      }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
    @SuppressLint("ClickableViewAccessibility")
166
    @Override
167
    public boolean onTouchEvent(MotionEvent event)
168
      {
169
      int mode = ScreenList.getMode();
170
      return mObjectController.onTouchEvent(event,mode);
171
      }
172
}
173

    
(4-4/4)