~w-shackleton/droidpad-android/stable

« back to all changes in this revision

Viewing changes to src/uk/digitalsquid/droidpad/buttons/TouchPanel.java

  • Committer: William Shackleton
  • Date: 2013-04-12 14:42:12 UTC
  • mfrom: (51.3.5 json)
  • mto: This revision was merged to the branch mainline in revision 52.
  • Revision ID: w.shackleton@gmail.com-20130412144212-4f7pueqwee0lc3yd
Imported code to load JSON layouts

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import uk.digitalsquid.droidpad.LogTag;
20
20
import android.graphics.Canvas;
21
 
import android.graphics.Point;
 
21
import android.graphics.PointF;
22
22
import android.graphics.RectF;
23
23
import android.util.FloatMath;
24
24
 
27
27
        
28
28
        private static final long serialVersionUID = -8300732746587169324L;
29
29
 
30
 
        public static enum PanelType {
31
 
                X,
32
 
                Y,
33
 
                Both
34
 
        }
35
 
        
36
30
        static final int SLIDER_TOT = 16384;
37
31
        
38
32
        static final int SLIDER_GAP = 16;
49
43
         */
50
44
        static final float CLICK_TIME = 100f / 1000f;
51
45
        
52
 
        public final PanelType type;
 
46
        public final Orientation type;
53
47
        
54
48
        /**
55
49
         * Axis X direction thing
68
62
        
69
63
        private long startTime;
70
64
 
71
 
        public TouchPanel(int x, int y, int sx, int sy, PanelType type) {
 
65
        public TouchPanel(int x, int y, int sx, int sy, Orientation type) {
72
66
                super(x, y, sx, sy);
73
67
                this.type = type;
 
68
        }
 
69
        
 
70
        public TouchPanel(float x, float y, float sx, float sy, boolean free, Orientation type) {
 
71
                super(x, y, sx, sy, free);
 
72
                this.type = type;
74
73
        }
75
74
 
76
75
        @Override
77
 
        public void drawInArea(Canvas c, RectF area, Point centre, boolean landscape) { }
 
76
        public void drawInArea(Canvas c, RectF area, PointF centre, boolean landscape) { }
78
77
 
79
78
        @Override
80
79
        public String getOutputString() {
104
103
        }
105
104
 
106
105
        @Override
107
 
        public void onMouseOn(float x, float y) {
108
 
                Point centre = computeCentre();
109
 
                RectF area = computeArea();
 
106
        public void onMouseOn(ScreenInfo info, float x, float y) {
 
107
                PointF centre = pos.computeCentre(info);
 
108
                RectF area = pos.computeArea(info);
110
109
                final float tempXw = area.width() - (2 * SLIDER_GAP);
111
110
                final float tempYw = area.height() - (2 * SLIDER_GAP);
112
111
                
113
 
                if(type == PanelType.X || type == PanelType.Both) {
 
112
                if(type == Orientation.X || type == Orientation.Both) {
114
113
                        tmpAx = ((float)(x - centre.x) / tempXw * 2f * SLIDER_TOT);
115
114
                        if(tmpAx < -SLIDER_TOT)
116
115
                                tmpAx = -SLIDER_TOT;
117
116
                        else if(tmpAx > SLIDER_TOT)
118
117
                                tmpAx = SLIDER_TOT;
119
118
                }
120
 
                if(type == PanelType.Y || type == PanelType.Both) {
 
119
                if(type == Orientation.Y || type == Orientation.Both) {
121
120
                        tmpAy = ((float)(y - centre.y) / tempYw * 2 * SLIDER_TOT);
122
121
                        if(tmpAy < -SLIDER_TOT)
123
122
                                tmpAy = -SLIDER_TOT;