Browse Source

Added Input Sample

dellis1972 13 years ago
parent
commit
d529dc670f

+ 26 - 0
Samples/Android/MonoGame.Samples.Input/Activity1.cs

@@ -0,0 +1,26 @@
+using System;
+
+using Android.App;
+using Android.Content;
+using Android.Runtime;
+using Android.Views;
+using Android.Widget;
+using Android.OS;
+
+namespace MonoGame.Samples.Input
+{
+	[Activity (Label = "MonoGame.Samples.Input", MainLauncher = true,Icon = "@drawable/icon", Theme = "@style/Theme.Splash")]
+	public class Activity1 :  Microsoft.Xna.Framework.AndroidGameActivity
+	{
+		protected override void OnCreate (Bundle bundle)
+		{
+			base.OnCreate (bundle);
+	        Game1.Activity = this;
+            var g = new Game1();
+            SetContentView(g.Window);
+            g.Run();
+		}
+	}
+}
+
+

+ 132 - 0
Samples/Android/MonoGame.Samples.Input/Game1.cs

@@ -0,0 +1,132 @@
+using System;
+using System.Collections.Generic;
+
+#if ANDROID
+using Android.App;
+#endif
+
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input;
+using Microsoft.Xna.Framework.Input.Touch;
+using Microsoft.Xna.Framework.Media;
+using Microsoft.Xna.Framework.Storage;
+
+namespace MonoGame.Samples.Input
+{
+	public class Game1 : Microsoft.Xna.Framework.Game
+	{
+		GraphicsDeviceManager graphics;
+		SpriteBatch spriteBatch;		
+		
+		SpriteFont font;
+		
+		KeyboardState currentKeyboardState;
+		GamePadState currentGamePadState;
+		TouchCollection currentTouchState;
+		
+		public Game1 ()
+		{
+			graphics = new GraphicsDeviceManager (this);
+			
+			Content.RootDirectory = "Content";
+			
+			graphics.PreferMultiSampling = true;
+			graphics.IsFullScreen = true;	
+
+			graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight 
+				//| DisplayOrientation.Portrait
+				;
+		}
+		
+		/// <summary>
+		/// Allows the game to perform any initialization it needs to before starting to run.
+		/// This is where it can query for any required services and load any non-graphic
+		/// related content.  Calling base.Initialize will enumerate through any components
+		/// and initialize them as well.
+		/// </summary>
+		protected override void Initialize ()
+		{
+			// TODO: Add your initialization logic here
+
+			base.Initialize ();
+		}
+		
+		/// <summary>
+		/// LoadContent will be called once per game and is the place to load
+		/// all of your content.
+		/// </summary>
+		protected override void LoadContent ()
+		{
+			// Create a new SpriteBatch, which can be used to draw textures.
+			spriteBatch = new SpriteBatch (GraphicsDevice);
+
+			// TODO: use this.Content to load your game content here
+			font = Content.Load<SpriteFont> ("spriteFont1");
+						
+		}
+
+		/// <summary>
+		/// Allows the game to run logic such as updating the world,
+		/// checking for collisions, gathering input, and playing audio.
+		/// </summary>
+		/// <param name="gameTime">Provides a snapshot of timing values.</param>
+		protected override void Update (GameTime gameTime)
+		{			
+			currentKeyboardState = Keyboard.GetState ();
+			currentGamePadState = GamePad.GetState (PlayerIndex.One);
+			currentTouchState = TouchPanel.GetState();
+									
+			base.Update (gameTime);
+		}
+				
+		/// <summary>
+		/// This is called when the game should draw itself.
+		/// </summary>
+		/// <param name="gameTime">Provides a snapshot of timing values.</param>
+		protected override void Draw (GameTime gameTime)
+		{
+			graphics.GraphicsDevice.Clear (Color.CornflowerBlue);
+			
+			// Won't be visible until we hide the movie
+			spriteBatch.Begin();	
+			
+			Vector2 center = new Vector2(GraphicsDevice.Viewport.Width /2, GraphicsDevice.Viewport.Height /2);
+			Vector2 s1 = font.MeasureString("Touch the Screen");
+			center.X -= (s1.X /2);
+			spriteBatch.DrawString(font, "Touch the Screen", center, Color.Red);
+			center.Y += 20;
+			spriteBatch.DrawString(font, GraphicsDevice.Viewport.Width.ToString() + " x " + GraphicsDevice.Viewport.Height.ToString(), center, Color.Red);
+			center.Y += 20;
+			spriteBatch.DrawString(font, GraphicsDevice.PresentationParameters.DisplayOrientation.ToString(), center, Color.Red);
+			
+			
+			spriteBatch.DrawString(font, "0,0", new Vector2(0,0), Color.Red);
+			string s = GraphicsDevice.Viewport.Width.ToString() + ",0";
+			Vector2 v = font.MeasureString(s);			
+			spriteBatch.DrawString(font, s, new Vector2(GraphicsDevice.Viewport.Width-v.X, 0), Color.Red);
+			s = "0,"+GraphicsDevice.Viewport.Height.ToString();
+			v = font.MeasureString(s);			
+			spriteBatch.DrawString(font, s , new Vector2(0, GraphicsDevice.Viewport.Height-v.Y), Color.Red);
+		    string wandh = GraphicsDevice.Viewport.Width.ToString() + ", " + GraphicsDevice.Viewport.Height.ToString();
+			Vector2 wh = font.MeasureString(wandh);
+			spriteBatch.DrawString(font, wandh, new Vector2(GraphicsDevice.Viewport.Width-wh.X, GraphicsDevice.Viewport.Height-wh.Y), Color.Red);
+			
+								
+			if (currentTouchState != null && currentTouchState.Count > 0) 
+			{
+				for (int i = 0 ; i < currentTouchState.Count; i++)
+				{
+					center.Y += s1.Y;
+					Vector2 p = currentTouchState[i].Position;
+					spriteBatch.DrawString(font, "+", p, Color.Red);
+					spriteBatch.DrawString(font, p.ToString(), center, Color.Red);
+				}
+			}
+			
+			spriteBatch.End();
+		}
+	}
+}
+

+ 81 - 0
Samples/Android/MonoGame.Samples.Input/MonoGame.Samples.Input.csproj

@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{CB2084E4-BEC8-4318-8011-93CC2E3C9E94}</ProjectGuid>
+    <ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <OutputType>Library</OutputType>
+    <RootNamespace>MonoGame.Samples.Input</RootNamespace>
+    <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
+    <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
+    <AndroidResgenClass>Resource</AndroidResgenClass>
+    <AndroidApplication>True</AndroidApplication>
+    <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
+    <AssemblyName>MonoGame.Samples.Input</AssemblyName>
+    <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ConsolePause>false</ConsolePause>
+    <AndroidLinkMode>None</AndroidLinkMode>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>none</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
+    <ConsolePause>false</ConsolePause>
+    <AndroidLinkMode>SdkOnly</AndroidLinkMode>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Xml" />
+    <Reference Include="System.Core" />
+    <Reference Include="Mono.Android" />
+    <Reference Include="OpenTK" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Activity1.cs" />
+    <Compile Include="Resources\Resource.designer.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Game1.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <AndroidResource Include="Resources\layout\Main.axml" />
+    <AndroidResource Include="Resources\values\Strings.xml" />
+    <AndroidResource Include="Resources\drawable\Icon.png" />
+    <AndroidResource Include="Resources\drawable\Splash.png" />
+    <AndroidResource Include="Resources\values\Styles.xml" />
+  </ItemGroup>
+  <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\..\MonoGame\ThirdParty\Lidgren.Network\Lidgren.Network.Android.csproj">
+      <Project>{565129E0-4EE5-4F6F-B403-C3484C9740BE}</Project>
+      <Name>Lidgren.Network.Android</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\..\..\MonoGame\MonoGame.Framework\MonoGame.Framework.Android.csproj">
+      <Project>{BA9476CF-99BA-4D03-92F2-73D2C5E58883}</Project>
+      <Name>MonoGame.Framework.Android</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Assets\Content\" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Properties\AndroidManifest.xml" />
+    <None Include="..\..\iOS\Draw2D\Content\spriteFont1.xnb">
+      <Link>Assets\Content\spriteFont1.xnb</Link>
+    </None>
+  </ItemGroup>
+</Project>

+ 7 - 0
Samples/Android/MonoGame.Samples.Input/Properties/AndroidManifest.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="monogamesamplesinput.monogamesamplesinput">
+	<application android:label="MonoGame.Samples.Input" android:debuggable="true" android:icon="@drawable/icon"></application>
+	<uses-sdk android:minSdkVersion="8" />
+	<uses-permission android:name="android.permission.INTERNET" />
+	<uses-permission android:name="android.permission.SET_ORIENTATION" />
+</manifest>

+ 28 - 0
Samples/Android/MonoGame.Samples.Input/Properties/AssemblyInfo.cs

@@ -0,0 +1,28 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using Android.App;
+
+// Information about this assembly is defined by the following attributes. 
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("MonoGame.Samples.Input")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("technomage")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly, 
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+

+ 87 - 0
Samples/Android/MonoGame.Samples.Input/Resources/Resource.designer.cs

@@ -0,0 +1,87 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.239
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace MonoGame.Samples.Input
+{
+	
+	
+	public partial class Resource
+	{
+		
+		public partial class Attribute
+		{
+			
+			private Attribute()
+			{
+			}
+		}
+		
+		public partial class Drawable
+		{
+			
+			// aapt resource value: 0x7f020000
+			public const int Icon = 2130837504;
+			
+			// aapt resource value: 0x7f020001
+			public const int Splash = 2130837505;
+			
+			private Drawable()
+			{
+			}
+		}
+		
+		public partial class Id
+		{
+			
+			// aapt resource value: 0x7f060000
+			public const int myButton = 2131099648;
+			
+			private Id()
+			{
+			}
+		}
+		
+		public partial class Layout
+		{
+			
+			// aapt resource value: 0x7f030000
+			public const int Main = 2130903040;
+			
+			private Layout()
+			{
+			}
+		}
+		
+		public partial class String
+		{
+			
+			// aapt resource value: 0x7f040001
+			public const int app_name = 2130968577;
+			
+			// aapt resource value: 0x7f040000
+			public const int hello = 2130968576;
+			
+			private String()
+			{
+			}
+		}
+		
+		public partial class Style
+		{
+			
+			// aapt resource value: 0x7f050000
+			public const int Theme_Splash = 2131034112;
+			
+			private Style()
+			{
+			}
+		}
+	}
+}

BIN
Samples/Android/MonoGame.Samples.Input/Resources/drawable/Icon.png


BIN
Samples/Android/MonoGame.Samples.Input/Resources/drawable/Splash.png


+ 14 - 0
Samples/Android/MonoGame.Samples.Input/Resources/layout/Main.axml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+<Button  
+    android:id="@+id/myButton"
+    android:layout_width="fill_parent" 
+    android:layout_height="wrap_content" 
+    android:text="@string/hello"
+    />
+</LinearLayout>
+

+ 5 - 0
Samples/Android/MonoGame.Samples.Input/Resources/values/Strings.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+	<string name="hello">Hello World, Click Me!</string>
+	<string name="app_name">MonoGame.Samples.Input</string>
+</resources>

+ 7 - 0
Samples/Android/MonoGame.Samples.Input/Resources/values/Styles.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+  <style name="Theme.Splash" parent="android:Theme">
+    <item name="android:windowBackground">@drawable/splash</item>
+    <item name="android:windowNoTitle">true</item>
+  </style>
+</resources>

+ 6 - 0
Samples/MonoGame.Samples.Android.sln

@@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sound", "Android\Sound\Soun
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Samples.VideoPlayer", "Android\VideoPlayer\MonoGame.Samples.VideoPlayer.csproj", "{27C3DD7C-5322-4C2D-8EE4-07610390CDAF}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Samples.Input", "Android\MonoGame.Samples.Input\MonoGame.Samples.Input.csproj", "{CB2084E4-BEC8-4318-8011-93CC2E3C9E94}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -43,6 +45,10 @@ Global
 		{BA9476CF-99BA-4D03-92F2-73D2C5E58883}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{BA9476CF-99BA-4D03-92F2-73D2C5E58883}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{BA9476CF-99BA-4D03-92F2-73D2C5E58883}.Release|Any CPU.Build.0 = Release|Any CPU
+		{CB2084E4-BEC8-4318-8011-93CC2E3C9E94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{CB2084E4-BEC8-4318-8011-93CC2E3C9E94}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{CB2084E4-BEC8-4318-8011-93CC2E3C9E94}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{CB2084E4-BEC8-4318-8011-93CC2E3C9E94}.Release|Any CPU.Build.0 = Release|Any CPU
 		{DEDD20B5-8F83-46FD-AD05-8F8FCC49FCD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{DEDD20B5-8F83-46FD-AD05-8F8FCC49FCD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{DEDD20B5-8F83-46FD-AD05-8F8FCC49FCD6}.Release|Any CPU.ActiveCfg = Release|Any CPU