~w-shackleton/droidpad-android/stable

« back to all changes in this revision

Viewing changes to src/uk/digitalsquid/droidpad/ButtonView.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:
17
17
package uk.digitalsquid.droidpad;
18
18
 
19
19
import uk.digitalsquid.droidpad.buttons.Item;
 
20
import uk.digitalsquid.droidpad.buttons.Item.ScreenInfo;
20
21
import uk.digitalsquid.droidpad.buttons.Layout;
21
22
import uk.digitalsquid.droidpad.buttons.ModeSpec;
22
23
import uk.digitalsquid.droidpad.buttons.Slider;
81
82
                
82
83
                parent.sendEvent(layout);
83
84
        }
84
 
 
85
 
        private int widthIter;
86
 
        private int heightIter;
87
 
        
88
 
        private int width, height;
89
85
        
90
86
        private float scale = 1;
91
87
        
92
88
        private static final Paint P_BLACK = new Paint(0xFF000000);
93
89
        
 
90
        private ScreenInfo tmpScreenInfo = new ScreenInfo();
 
91
        
94
92
        @Override
95
93
        public void onDraw(Canvas canvas)
96
94
        {
97
95
                super.onDraw(canvas);
98
96
                scale = getResources().getDisplayMetrics().density;
99
97
                
100
 
                width = (int) ((float)canvas.getWidth() / scale);
101
 
                height = (int) ((float)canvas.getHeight() / scale);
 
98
                float width = (float)canvas.getWidth() / scale;
 
99
                float height = (float)canvas.getHeight() / scale;
102
100
                
103
101
                canvas.scale(scale, scale);
104
102
                
105
103
                canvas.drawRect(0, 0, width, height, P_BLACK);
106
104
                if(isInEditMode()) return;
107
 
                widthIter = width / layout.getWidth();
108
 
                heightIter = height / layout.getHeight();
 
105
                float widthIter = width / layout.getWidth();
 
106
                float heightIter = height / layout.getHeight();
 
107
                
 
108
                tmpScreenInfo.set(width, height, widthIter, heightIter, landscape);
109
109
                
110
110
                for(Item item : layout) {
111
 
                        item.draw(canvas, widthIter, heightIter, landscape);
 
111
                        item.draw(canvas, tmpScreenInfo);
112
112
                }
113
113
        }
114
114
 
119
119
                x /= scale;
120
120
                y /= scale;
121
121
                for(Item item : layout) {
122
 
                        if(item.pointIsInArea(x, y)) {
 
122
                        if(item.pointIsInArea(tmpScreenInfo, x, y)) {
123
123
                                if(!up)
124
 
                                        item.onMouseOn(x, y);
 
124
                                        item.onMouseOn(tmpScreenInfo, x, y);
125
125
                                else {
126
126
                                        item.onMouseOff();
127
127
                                        item.resetStickyLock();