mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
AndroidGCS: Show some less shitty graphics for PFD
This commit is contained in:
parent
2e554ebf8e
commit
ae36f39f1a
BIN
androidgcs/res/drawable-hdpi/im_pfd_horizon.png
Normal file
BIN
androidgcs/res/drawable-hdpi/im_pfd_horizon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
@ -4,13 +4,9 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<org.openpilot.androidgcs.CompassView
|
||||
android:id="@+id/compass_view"
|
||||
<org.openpilot.androidgcs.AttitudeView
|
||||
android:id="@+id/attitude_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<org.openpilot.androidgcs.AttitudeView
|
||||
android:id="@+id/attitude_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
</LinearLayout>
|
||||
|
@ -24,14 +24,15 @@
|
||||
package org.openpilot.androidgcs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
public class AttitudeView extends View {
|
||||
|
||||
private Paint markerPaint;
|
||||
public AttitudeView(Context context) {
|
||||
super(context);
|
||||
initAttitudeView();
|
||||
@ -49,16 +50,10 @@ public class AttitudeView extends View {
|
||||
|
||||
protected void initAttitudeView() {
|
||||
setFocusable(true);
|
||||
|
||||
circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
circlePaint.setColor(getResources().getColor(R.color.background_color));
|
||||
circlePaint.setStrokeWidth(1);
|
||||
circlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||
Resources r = this.getResources();
|
||||
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
textPaint.setColor(r.getColor(R.color.text_color));
|
||||
markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
markerPaint.setColor(r.getColor(R.color.marker_color));
|
||||
markerPaint.setColor(getContext().getResources().getColor(
|
||||
R.color.marker_color));
|
||||
|
||||
}
|
||||
|
||||
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
@ -85,28 +80,40 @@ public class AttitudeView extends View {
|
||||
return result;
|
||||
}
|
||||
|
||||
private double roll;
|
||||
private float roll;
|
||||
public void setRoll(double roll) {
|
||||
this.roll = roll;
|
||||
}
|
||||
private double pitch;
|
||||
public void setPitch(double d) {
|
||||
this.pitch = d;
|
||||
this.roll = (float) roll;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
// Drawing related code
|
||||
private Paint markerPaint;
|
||||
private Paint textPaint;
|
||||
private Paint circlePaint;
|
||||
private float pitch;
|
||||
public void setPitch(double d) {
|
||||
this.pitch = (float) d;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
int px = getMeasuredWidth() / 2;
|
||||
int py = getMeasuredHeight() /2 ;
|
||||
int radius = Math.min(px, py);
|
||||
|
||||
canvas.drawLine(px,py, (int) (px+radius * Math.cos(roll)), (int) (py + radius * Math.sin(roll)), markerPaint);
|
||||
canvas.drawLine(px,py, (int) (px+radius * Math.cos(pitch)), (int) (py + radius * Math.sin(pitch)), markerPaint);
|
||||
final int PX = getMeasuredWidth() / 2;
|
||||
final int PY = getMeasuredHeight() / 2;
|
||||
|
||||
// TODO: Figure out why these magic numbers are needed to center it
|
||||
final int WIDTH = 600;
|
||||
final int HEIGHT = 600;
|
||||
final int DEG_TO_PX = 10; // Magic number for how to scale pitch
|
||||
|
||||
canvas.save(0);
|
||||
canvas.rotate(-roll, PX, PY);
|
||||
canvas.translate(0, pitch * DEG_TO_PX);
|
||||
Drawable horizon = getContext().getResources().getDrawable(
|
||||
R.drawable.im_pfd_horizon);
|
||||
// This puts the image at the center of the PFD canvas (after it was
|
||||
// translated)
|
||||
horizon.setBounds(-(WIDTH - PX) / 2, -(HEIGHT - PY) / 2, WIDTH, HEIGHT);
|
||||
horizon.draw(canvas);
|
||||
canvas.restore();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,13 +52,14 @@ public class PFD extends ObjectManagerActivity {
|
||||
pitch = obj.getField("Pitch").getDouble();
|
||||
roll = obj.getField("Roll").getDouble();
|
||||
|
||||
CompassView compass = (CompassView) findViewById(R.id.compass_view);
|
||||
compass.setBearing((int) heading);
|
||||
compass.invalidate();
|
||||
/*
|
||||
* CompassView compass = (CompassView) findViewById(R.id.compass_view);
|
||||
* compass.setBearing((int) heading); compass.invalidate();
|
||||
*/
|
||||
|
||||
AttitudeView attitude = (AttitudeView) findViewById(R.id.attitude_view);
|
||||
attitude.setRoll(roll / 180 * Math.PI);
|
||||
attitude.setPitch(pitch / 180 * Math.PI);
|
||||
attitude.setRoll(roll);
|
||||
attitude.setPitch(pitch);
|
||||
attitude.invalidate();
|
||||
}
|
||||
|
||||
|
4267
artwork/Android/hdpi/_pre_production/pfd.ai
Normal file
4267
artwork/Android/hdpi/_pre_production/pfd.ai
Normal file
File diff suppressed because one or more lines are too long
BIN
artwork/Android/hdpi/im_pfd_horizon.png
Normal file
BIN
artwork/Android/hdpi/im_pfd_horizon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Loading…
x
Reference in New Issue
Block a user