3 * This file is part of shape4a.
5 * shape4a is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * shape4a is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with shape4a. If not, see <http://www.gnu.org/licenses/>.
19 package org.ocera.orte.shape4a;
21 import org.ocera.orte.*;
22 import org.ocera.orte.types.*;
24 import android.util.Log;
27 * Object to be send throw ORTE.
29 * @author jiri hubacek <jiri.hubacek@gmail.com>
33 public class Box extends MessageData
35 private static final double DESTINATION_WIDTH = 389.0;
36 private static final double DESTINATION_HEIGHT = 256.0;
38 public boolean allowScaling;
40 // is more shape than strength,
41 // strength is solved throw
42 // publisherProperties or
43 // throw subscriberProperties...
45 public BoxRect rectangle;
47 private double scaleWidth;
48 private double scaleHeight;
51 * Add topic of new object.
57 public Box(DomainApp appDomain, String newTopic) {
59 this.setTopic(newTopic);
61 if (!appDomain.regNewDataType("Box", this.getMaxDataLength())) {
62 Log.e("Box", "Cannot register data type 'Box'.");
65 this.rectangle = new BoxRect();
66 this.allowScaling = true;
72 * Read data from buffer.
78 if (this.allowScaling) {
79 this.rectangle.top_left_x = (short) (buffer.getShort() / this.scaleWidth);
80 this.rectangle.top_left_y = (short) (buffer.getShort() / this.scaleHeight);
81 this.rectangle.bottom_right_x = (short) (buffer.getShort() / this.scaleWidth);
82 this.rectangle.bottom_right_y = (short) (buffer.getShort() / this.scaleHeight);
84 this.rectangle.top_left_x = buffer.getShort();
85 this.rectangle.top_left_y = buffer.getShort();
86 this.rectangle.bottom_right_x = buffer.getShort();
87 this.rectangle.bottom_right_y = buffer.getShort();
90 this.strength = (int) buffer.getShort();
94 * Write data to buffer.
100 if (this.allowScaling) {
101 buffer.putShort((short) (rectangle.top_left_x * this.scaleWidth));
102 buffer.putShort((short) (rectangle.top_left_y * this.scaleHeight));
103 buffer.putShort((short) (rectangle.bottom_right_x * this.scaleWidth));
104 buffer.putShort((short) (rectangle.bottom_right_y * this.scaleHeight));
106 buffer.putShort(rectangle.top_left_x);
107 buffer.putShort(rectangle.top_left_y);
108 buffer.putShort(rectangle.bottom_right_x);
109 buffer.putShort(rectangle.bottom_right_y);
112 buffer.putShort((short) this.strength);
116 * Get maximum length of data.
120 public int getMaxDataLength() {
121 return 5 * ORTEConstant.SHORT_FIELD_SIZE;
125 * Object to be truly send throw ORTE.
131 public short top_left_x;
132 public short top_left_y;
133 public short bottom_right_x;
134 public short bottom_right_y;
141 * When screen rotates, change scale variables to
142 * fit the destination screen.
146 public void setScale(int currentWidth, int currentHeight)
148 this.scaleWidth = DESTINATION_WIDTH / currentWidth;
149 this.scaleHeight = DESTINATION_HEIGHT / currentHeight;