Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayView.java @ 083d854d

1 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 da56b12f Leszek Koltunski
// Copyright 2022 Leszek Koltunski                                                               //
3 9530f6b0 Leszek Koltunski
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 44fec653 Leszek Koltunski
// 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 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.bandaged;
11
12 565d139b Leszek Koltunski
import android.annotation.SuppressLint;
13 9530f6b0 Leszek Koltunski
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 565d139b Leszek Koltunski
import android.view.MotionEvent;
20 9530f6b0 Leszek Koltunski
21
import com.google.firebase.crashlytics.FirebaseCrashlytics;
22
23
import org.distorted.objectlib.main.ObjectControl;
24
import org.distorted.objectlib.main.TwistyObjectNode;
25
26 565d139b Leszek Koltunski
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
27
28 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
29
30
public class BandagedPlayView extends GLSurfaceView
31
{
32
    private ObjectControl mObjectController;
33
    private BandagedPlayRenderer mRenderer;
34
    private int mScreenWidth, mScreenHeight;
35
    private boolean mCreated;
36
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39
    void setScreenSize(int width, int height)
40
      {
41
      mScreenWidth = width;
42
      mScreenHeight= height;
43 b1178f5f Leszek Koltunski
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height)) );
44 9530f6b0 Leszek Koltunski
      mObjectController.setObjectScale(1.00f);
45
46
      if( !mCreated )
47
        {
48
        mCreated = true;
49
        mObjectController.createNode(width,height);
50
        TwistyObjectNode objectNode = mObjectController.getNode();
51
        mRenderer.getScreen().attach(objectNode);
52
        }
53
      }
54
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
57
    boolean isVertical()
58
      {
59
      return mScreenHeight>mScreenWidth;
60
      }
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64
    ObjectControl getObjectControl()
65
      {
66
      return mObjectController;
67
      }
68
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
// PUBLIC API
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73
    public BandagedPlayView(Context context, AttributeSet attrs)
74
      {
75
      super(context,attrs);
76
77
      mCreated = false;
78
79
      if(!isInEditMode())
80
        {
81
        BandagedPlayActivity act = (BandagedPlayActivity)context;
82 88b94310 Leszek Koltunski
        BandagedPlayLibInterface ref = new BandagedPlayLibInterface(act);
83 9530f6b0 Leszek Koltunski
        mObjectController = new ObjectControl(act,ref);
84
        mObjectController.setRotateOnCreation(true);
85
        mRenderer = new BandagedPlayRenderer(this);
86
87
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
88
89
        try
90
          {
91
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
92
          int esVersion = configurationInfo.reqGlEsVersion>>16;
93
          setEGLContextClientVersion(esVersion);
94
          setRenderer(mRenderer);
95
          }
96
        catch(Exception ex)
97
          {
98
          act.OpenGLError();
99
100
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
101
          String version = GLES30.glGetString(GLES30.GL_VERSION);
102
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
103
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
104
105
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
106
          crashlytics.setCustomKey("GLSL Version"  , shading );
107
          crashlytics.setCustomKey("GL version"    , version );
108
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
109
          crashlytics.setCustomKey("GLSL renderer" , renderer);
110
          crashlytics.recordException(ex);
111
          }
112
        }
113
      }
114
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
117
    @Override
118
    public void onPause()
119
      {
120
      super.onPause();
121
      mObjectController.onPause();
122
      }
123
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
126
    @Override
127
    public void onResume()
128
      {
129
      super.onResume();
130
      mObjectController.onResume();
131
      }
132 565d139b Leszek Koltunski
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
135
    @SuppressLint("ClickableViewAccessibility")
136
    @Override
137
    public boolean onTouchEvent(MotionEvent event)
138
      {
139
      return mObjectController.onTouchEvent(event,MODE_ROTATE);
140
      }
141 9530f6b0 Leszek Koltunski
}