Draw DPad on Android

This commit is contained in:
Florian Märkl 2019-09-24 21:51:32 +02:00
commit 8b9dd17f64
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
7 changed files with 264 additions and 2 deletions

View file

@ -20,8 +20,7 @@ android {
"-DCHIAKI_ENABLE_GUI=OFF",
"-DCHIAKI_ENABLE_ANDROID=ON",
"-DCHIAKI_LIB_ENABLE_OPUS=OFF",
"-DCHIAKI_LIB_OPENSSL_EXTERNAL_PROJECT=ON",
"-DCMAKE_VERBOSE_MAKEFILE=ON"
"-DCHIAKI_LIB_OPENSSL_EXTERNAL_PROJECT=ON"
}
}
}

View file

@ -1,3 +1,20 @@
/*
* This file is part of Chiaki.
*
* Chiaki is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chiaki is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
*/
package com.metallic.chiaki
import android.content.Context

View file

@ -0,0 +1,49 @@
/*
* This file is part of Chiaki.
*
* Chiaki is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chiaki is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
*/
package com.metallic.chiaki.touchcontrols
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent
import android.view.View
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import com.metallic.chiaki.R
class DPadView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr)
{
private val colorPrimary = resources.getColor(R.color.control_primary, null)
private val dpadDrawable = VectorDrawableCompat.create(resources, R.drawable.control_dpad, null)
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
dpadDrawable?.setBounds(0, 0, width, height)
dpadDrawable?.setTint(colorPrimary)
dpadDrawable?.draw(canvas)
}
override fun onTouchEvent(event: MotionEvent): Boolean
{
Log.i("DPadView", "onTouchEvent $event")
return true
}
}

View file

@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="135.46667"
android:viewportHeight="135.46667">
<path
android:pathData="M45.244,0L45.244,36.263L62.162,53.181l11.144,0L90.223,36.263L90.223,0Z"
android:strokeAlpha="1"
android:strokeWidth="30.92149353"
android:fillColor="#000000"
android:strokeColor="#00000000"
android:fillAlpha="1"/>
<path
android:pathData="M0,45.244L0,90.223L36.263,90.223L53.181,73.305L53.181,62.162L36.263,45.244Z"
android:strokeAlpha="1"
android:strokeWidth="30.92149353"
android:fillColor="#000000"
android:strokeColor="#00000000"
android:fillAlpha="1"/>
<path
android:pathData="M99.203,45.244 L82.285,62.162l0,11.144L99.203,90.223L135.467,90.223L135.467,45.244Z"
android:strokeAlpha="1"
android:strokeWidth="30.92149353"
android:fillColor="#000000"
android:strokeColor="#00000000"
android:fillAlpha="1"/>
<path
android:pathData="M62.162,82.285 L45.244,99.203L45.244,135.467L90.223,135.467L90.223,99.203L73.305,82.285Z"
android:strokeAlpha="1"
android:strokeWidth="30.92149353"
android:fillColor="#000000"
android:strokeColor="#00000000"
android:fillAlpha="1"/>
</vector>

View file

@ -51,4 +51,12 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/morningEditText" />
<com.metallic.chiaki.touchcontrols.DPadView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="32dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -6,4 +6,6 @@
<color name="stream_text">@android:color/white</color>
<color name="stream_background">@android:color/black</color>
<color name="control_primary">@android:color/white</color>
</resources>