mirror of
https://github.com/13hannes11/archive.git
synced 2024-09-03 21:50:58 +02:00
added all past projects
This commit is contained in:
BIN
C#_Mono/PlanetSimulation/.vs/PlanetSimulation/v14/.suo
Normal file
BIN
C#_Mono/PlanetSimulation/.vs/PlanetSimulation/v14/.suo
Normal file
Binary file not shown.
20
C#_Mono/PlanetSimulation/PlanetSimulation.sln
Normal file
20
C#_Mono/PlanetSimulation/PlanetSimulation.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlanetSimulation", "PlanetSimulation\PlanetSimulation.csproj", "{2877F3FC-9913-4CA7-91BC-C358597CCCB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2877F3FC-9913-4CA7-91BC-C358597CCCB9}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{2877F3FC-9913-4CA7-91BC-C358597CCCB9}.Debug|x86.Build.0 = Debug|x86
|
||||
{2877F3FC-9913-4CA7-91BC-C358597CCCB9}.Release|x86.ActiveCfg = Release|x86
|
||||
{2877F3FC-9913-4CA7-91BC-C358597CCCB9}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = PlanetSimulation\PlanetSimulation.csproj
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
56
C#_Mono/PlanetSimulation/PlanetSimulation/Camera2D.cs
Normal file
56
C#_Mono/PlanetSimulation/PlanetSimulation/Camera2D.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace PlanetSimulation
|
||||
{
|
||||
public class Camera2d
|
||||
{
|
||||
protected float _zoom; // Camera Zoom
|
||||
public Matrix _transform; // Matrix Transform
|
||||
public Vector2 _pos; // Camera Position
|
||||
protected float _rotation; // Camera Rotation
|
||||
|
||||
public Camera2d()
|
||||
{
|
||||
_zoom = 1.0f;
|
||||
_rotation = 0.0f;
|
||||
_pos = Vector2.Zero;
|
||||
}
|
||||
// Sets and gets zoom
|
||||
public float Zoom
|
||||
{
|
||||
get { return _zoom; }
|
||||
set { _zoom = value; if (_zoom < 0.1f) _zoom = 0.1f; } // Negative zoom will flip image
|
||||
}
|
||||
|
||||
public float Rotation
|
||||
{
|
||||
get {return _rotation; }
|
||||
set { _rotation = value; }
|
||||
}
|
||||
// Auxiliary function to move the camera
|
||||
public void Move(Vector2 amount)
|
||||
{
|
||||
_pos += amount;
|
||||
}
|
||||
// Get set position
|
||||
public Vector2 Pos
|
||||
{
|
||||
get{ return _pos; }
|
||||
set{ _pos = value; }
|
||||
}
|
||||
|
||||
public Matrix get_transformation(GraphicsDevice graphicsDevice)
|
||||
{
|
||||
_transform = // Thanks to o KB o for this solution
|
||||
Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
|
||||
Matrix.CreateRotationZ(Rotation) *
|
||||
Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
|
||||
Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Width * 0.5f, graphicsDevice.Viewport.Height * 0.5f, 0));
|
||||
return _transform;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
110
C#_Mono/PlanetSimulation/PlanetSimulation/Game1.cs
Normal file
110
C#_Mono/PlanetSimulation/PlanetSimulation/Game1.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Storage;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using C3.XNA;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace PlanetSimulation
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the main type for your game
|
||||
/// </summary>
|
||||
public class Game1 : Game
|
||||
{
|
||||
Camera2d cam;
|
||||
|
||||
PlanetManager pManager;
|
||||
|
||||
GraphicsDeviceManager graphics;
|
||||
SpriteBatch spriteBatch;
|
||||
|
||||
public Game1 ()
|
||||
{
|
||||
graphics = new GraphicsDeviceManager (this);
|
||||
Content.RootDirectory = "Content";
|
||||
graphics.IsFullScreen = true;
|
||||
//graphics.ApplyChanges();
|
||||
}
|
||||
|
||||
/// <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
|
||||
|
||||
pManager = new PlanetManager();
|
||||
base.Initialize ();
|
||||
cam = new Camera2d();
|
||||
|
||||
}
|
||||
|
||||
/// <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
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
// For Mobile devices, this logic will close the Game when the Back button is pressed
|
||||
if (GamePad.GetState (PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) {
|
||||
Exit ();
|
||||
}
|
||||
|
||||
if(Keyboard.GetState().IsKeyDown(Keys.OemMinus))
|
||||
cam.Zoom -= 0.025f;
|
||||
if(Keyboard.GetState().IsKeyDown(Keys.OemPlus))
|
||||
cam.Zoom += 0.025f;
|
||||
|
||||
if(Keyboard.GetState().IsKeyDown(Keys.Down))
|
||||
cam.Pos = Vector2.Add(cam.Pos, new Vector2(0,cam.Zoom * 20));
|
||||
if(Keyboard.GetState().IsKeyDown(Keys.Up))
|
||||
cam.Pos = Vector2.Add(cam.Pos, new Vector2(0,-cam.Zoom * 20));
|
||||
if(Keyboard.GetState().IsKeyDown(Keys.Right))
|
||||
cam.Pos = Vector2.Add(cam.Pos, new Vector2(cam.Zoom * 20 ,0));
|
||||
if(Keyboard.GetState().IsKeyDown(Keys.Left))
|
||||
cam.Pos = Vector2.Add(cam.Pos, new Vector2(-cam.Zoom * 20 ,0));
|
||||
|
||||
pManager.Update(gameTime);
|
||||
// TODO: Add your update logic here
|
||||
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.Black);
|
||||
//TODO: Add your drawing code here
|
||||
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null,
|
||||
cam.get_transformation(GraphicsDevice /*Send the variable that has your graphic device here*/));
|
||||
|
||||
pManager.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
base.Draw (gameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
C#_Mono/PlanetSimulation/PlanetSimulation/Icon.png
Normal file
BIN
C#_Mono/PlanetSimulation/PlanetSimulation/Icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
136
C#_Mono/PlanetSimulation/PlanetSimulation/Planet.cs
Normal file
136
C#_Mono/PlanetSimulation/PlanetSimulation/Planet.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using C3.XNA;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PlanetSimulation
|
||||
{
|
||||
public class Planet
|
||||
{
|
||||
private long mass; public long Mass {
|
||||
get{ return mass;}
|
||||
set{ mass = value;}
|
||||
}
|
||||
private long radius; public long Radius {
|
||||
get{ return radius;}
|
||||
set{ radius = value;}
|
||||
}
|
||||
private Vector2 center; public Vector2 Center { get{return center;}}
|
||||
|
||||
private List<Vector2> forces; public List<Vector2> Forces {
|
||||
get { return forces; }
|
||||
set{ forces = value;}
|
||||
}
|
||||
private Vector2 acceleration;
|
||||
private Vector2 velocity; public Vector2 Velocity{ get{ return velocity;}}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlanetSimulation.Planet"/> class.
|
||||
/// </summary>
|
||||
/// <param name='center'>
|
||||
/// Center of the planet
|
||||
/// </param>
|
||||
/// <param name='mass'>
|
||||
/// Mass of the Planet
|
||||
/// </param>
|
||||
/// <param name='radius'>
|
||||
/// Radius of the planet
|
||||
/// </param>
|
||||
public Planet (Vector2 center, long mass, long radius)
|
||||
{
|
||||
this.velocity = Vector2.Zero;
|
||||
|
||||
this.mass = mass;
|
||||
this.radius = radius;
|
||||
this.center = center;
|
||||
this.forces = new List<Vector2>();
|
||||
this.acceleration = Vector2.Zero;
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlanetSimulation.Planet"/> class.
|
||||
/// </summary>
|
||||
/// <param name='center'>
|
||||
/// Center of the planet
|
||||
/// </param>
|
||||
/// <param name='mass'>
|
||||
/// Mass of the planet
|
||||
/// </param>
|
||||
/// <param name='radius'>
|
||||
/// Radius of the planet
|
||||
/// </param>
|
||||
/// <param name='velocity'>
|
||||
/// Velocity of the planet
|
||||
/// </param>
|
||||
public Planet (Vector2 center, long mass, long radius, Vector2 velocity)
|
||||
{
|
||||
this.velocity = velocity;
|
||||
|
||||
this.mass = mass;
|
||||
this.radius = radius;
|
||||
this.center = center;
|
||||
this.forces = new List<Vector2>();
|
||||
this.acceleration = Vector2.Zero;
|
||||
}
|
||||
|
||||
public void Update (GameTime gameTime)
|
||||
{
|
||||
calcAcceleration();
|
||||
calcVelocity(gameTime);
|
||||
move(gameTime);
|
||||
}
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
spriteBatch.DrawCircle(center, radius, (int)radius, Color.Red);
|
||||
/*foreach (var f in forces) {
|
||||
spriteBatch.DrawLine(center, Vector2.Add(center, Vector2.Multiply(Vector2.Normalize(f), 100)), Color.Green);
|
||||
//spriteBatch.DrawLine(center, Vector2.Add(center, f), Color.Green);
|
||||
}*/
|
||||
forces.Clear();
|
||||
//Draw Acceleration
|
||||
spriteBatch.DrawLine(center, Vector2.Add(center, Vector2.Multiply(acceleration, 1)), Color.Orange);
|
||||
//Draw Velocity
|
||||
spriteBatch.DrawLine(center, Vector2.Add(center, velocity), Color.White);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the Planet according to it's velocity.
|
||||
/// </summary>
|
||||
/// <param name='gameTime'>
|
||||
/// GameTime element from MonoGame/XNA
|
||||
/// </param>
|
||||
private void move (GameTime gameTime)
|
||||
{
|
||||
float elapsedSeconds = (float)gameTime.ElapsedGameTime.Milliseconds / 1000;
|
||||
center = Vector2.Add(center, Vector2.Multiply(velocity, elapsedSeconds));
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates the Velocity of the Planet by using the acceleration.
|
||||
/// </summary>
|
||||
/// <param name='gameTime'>
|
||||
/// GameTime element from MonoGame/XNA
|
||||
/// </param>
|
||||
private void calcVelocity (GameTime gameTime)
|
||||
{
|
||||
float elapsedSeconds = (float)gameTime.ElapsedGameTime.Milliseconds / 1000;
|
||||
|
||||
velocity = Vector2.Add(velocity, Vector2.Multiply(acceleration, elapsedSeconds));
|
||||
}
|
||||
/// <summary>
|
||||
/// Calculates the acceleration out of all occouring forces which are saved in the List forces which consists of 2D Vectors.
|
||||
/// </summary>
|
||||
private void calcAcceleration()
|
||||
{
|
||||
Vector2 f = Vector2.Zero;
|
||||
foreach(Vector2 v in forces)
|
||||
{
|
||||
f = Vector2.Add(f,v);
|
||||
}
|
||||
|
||||
//F = m x a <=> F/m = a
|
||||
acceleration = Vector2.Divide(f,mass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
108
C#_Mono/PlanetSimulation/PlanetSimulation/PlanetManager.cs
Normal file
108
C#_Mono/PlanetSimulation/PlanetSimulation/PlanetManager.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace PlanetSimulation
|
||||
{
|
||||
public class PlanetManager
|
||||
{
|
||||
public const float G = 0.02f;
|
||||
private Rectangle boundsOfUniverse;
|
||||
List<Planet> planets;
|
||||
public PlanetManager ()
|
||||
{
|
||||
int size = 5000;
|
||||
boundsOfUniverse = new Rectangle(-size,-size, 2*size, 2*size);
|
||||
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
planets = new List<Planet>();
|
||||
|
||||
//planets.Add(new Planet(Vector2.Zero, 30000, 100, new Vector2(0,0)));
|
||||
//planets.Add(new Planet(new Vector2(0,300), 1000, 20, new Vector2(20,0)));
|
||||
//p.Add(new Planet(new Vector2(0,500), 20, 5, new Vector2(75,0)));
|
||||
for (int i = 0; i < 200; i++) {
|
||||
|
||||
int radius = random.Next(1,40);
|
||||
planets.Add(new Planet(new Vector2(random.Next(boundsOfUniverse.X, boundsOfUniverse.Width + boundsOfUniverse.X),
|
||||
random.Next(boundsOfUniverse.Y, boundsOfUniverse.Height + boundsOfUniverse.Y))
|
||||
,(radius*radius)*6, radius
|
||||
,new Vector2(random.Next(-50,50),random.Next(-50,50))));
|
||||
}
|
||||
}
|
||||
public void Update (GameTime gameTime)
|
||||
{
|
||||
for (int i = 0; i < (planets.Count -1); i++) {
|
||||
for (int j = i+1; j < planets.Count; j++) {
|
||||
calcForce (planets[i], planets[j]);
|
||||
checkANDcalcCollision(planets[i], planets[j]);
|
||||
}
|
||||
}
|
||||
foreach (Planet planet in planets) {
|
||||
planet.Update(gameTime);
|
||||
}
|
||||
}
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
foreach(Planet planet in planets)
|
||||
{
|
||||
planet.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a Collision occours between the two planets occours and
|
||||
/// if they collide it calculates the Impact of the collision and the resulting force.
|
||||
/// </summary>
|
||||
/// <param name='p'>
|
||||
/// first planet
|
||||
/// </param>
|
||||
/// <param name='q'>
|
||||
/// second plane
|
||||
/// </param>
|
||||
private void checkANDcalcCollision (Planet p, Planet q)
|
||||
{
|
||||
var dx = p.Center.X - q.Center.X;
|
||||
var dy = p.Center.Y - q.Center.Y;
|
||||
var dist = p.Radius + q.Radius;
|
||||
|
||||
if (dx * dx + dy * dy <= dist * dist) {
|
||||
//The planets Crash...
|
||||
|
||||
Vector2 v = Vector2.Add(Vector2.Multiply(p.Velocity,((float)p.Mass/(p.Mass + q.Mass))), Vector2.Multiply(q.Velocity,((float)q.Mass/(q.Mass + p.Mass))));
|
||||
Vector2 center = (p.Mass > q.Mass)?p.Center:q.Center;
|
||||
long r = (long)Math.Sqrt((p.Radius*p.Radius + q.Radius* q.Radius));
|
||||
|
||||
Planet _tmp = new Planet(center, p.Mass + q.Mass, r, v);
|
||||
planets.Add(_tmp);
|
||||
planets.Remove(p);
|
||||
planets.Remove(q);
|
||||
//Insert What happens when the planets crash here
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Calculates the force of gravity which occours between the two planets
|
||||
/// and adds it to the List of Forces of each Planet
|
||||
/// </summary>
|
||||
/// <param name='p'>
|
||||
/// first planet.
|
||||
/// </param>
|
||||
/// <param name='q'>
|
||||
/// second planet.
|
||||
/// </param>
|
||||
private void calcForce(Planet p, Planet q)
|
||||
{
|
||||
//http://goo.gl/Yt6vdj Newtons law of Gravity
|
||||
Vector2 direction = Vector2.Add(-p.Center,q.Center);
|
||||
float F = G* ((p.Mass * q.Mass)/(Vector2.Distance(p.Center,q.Center)));
|
||||
|
||||
Vector2 Force = Vector2.Multiply(Vector2.Normalize(direction), F);
|
||||
p.Forces.Add(Force);
|
||||
q.Forces.Add(Vector2.Multiply(Force, -1f));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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)' == '' ">x86</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{2877F3FC-9913-4CA7-91BC-C358597CCCB9}</ProjectGuid>
|
||||
<ProjectTypeGuids>{9B831FEF-F496-498F-9FE8-180DA5CB4258};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>PlanetSimulation</RootNamespace>
|
||||
<MonoGamePlatform>Linux</MonoGamePlatform>
|
||||
<AssemblyName>PlanetSimulation</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="MonoGame.Framework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Game1.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Primitives2D.cs" />
|
||||
<Compile Include="Planet.cs" />
|
||||
<Compile Include="Camera2D.cs" />
|
||||
<Compile Include="PlanetManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Icon.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Content\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
539
C#_Mono/PlanetSimulation/PlanetSimulation/Primitives2D.cs
Normal file
539
C#_Mono/PlanetSimulation/PlanetSimulation/Primitives2D.cs
Normal file
@@ -0,0 +1,539 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace C3.XNA
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public static class Primitives2D
|
||||
{
|
||||
|
||||
|
||||
#region Private Members
|
||||
|
||||
private static readonly Dictionary<String, List<Vector2>> circleCache = new Dictionary<string, List<Vector2>>();
|
||||
//private static readonly Dictionary<String, List<Vector2>> arcCache = new Dictionary<string, List<Vector2>>();
|
||||
private static Texture2D pixel;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static void CreateThePixel(SpriteBatch spriteBatch)
|
||||
{
|
||||
pixel = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
|
||||
pixel.SetData(new[]{ Color.White });
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a list of connecting points
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// /// <param name="position">Where to position the points</param>
|
||||
/// <param name="points">The points to connect with lines</param>
|
||||
/// <param name="color">The color to use</param>
|
||||
/// <param name="thickness">The thickness of the lines</param>
|
||||
private static void DrawPoints(SpriteBatch spriteBatch, Vector2 position, List<Vector2> points, Color color, float thickness)
|
||||
{
|
||||
if (points.Count < 2)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < points.Count; i++)
|
||||
{
|
||||
DrawLine(spriteBatch, points[i - 1] + position, points[i] + position, color, thickness);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of vectors that represents a circle
|
||||
/// </summary>
|
||||
/// <param name="radius">The radius of the circle</param>
|
||||
/// <param name="sides">The number of sides to generate</param>
|
||||
/// <returns>A list of vectors that, if connected, will create a circle</returns>
|
||||
private static List<Vector2> CreateCircle(double radius, int sides)
|
||||
{
|
||||
// Look for a cached version of this circle
|
||||
String circleKey = radius + "x" + sides;
|
||||
if (circleCache.ContainsKey(circleKey))
|
||||
{
|
||||
return circleCache[circleKey];
|
||||
}
|
||||
|
||||
List<Vector2> vectors = new List<Vector2>();
|
||||
|
||||
const double max = 2.0 * Math.PI;
|
||||
double step = max / sides;
|
||||
|
||||
for (double theta = 0.0; theta < max; theta += step)
|
||||
{
|
||||
vectors.Add(new Vector2((float)(radius * Math.Cos(theta)), (float)(radius * Math.Sin(theta))));
|
||||
}
|
||||
|
||||
// then add the first vector again so it's a complete loop
|
||||
vectors.Add(new Vector2((float)(radius * Math.Cos(0)), (float)(radius * Math.Sin(0))));
|
||||
|
||||
// Cache this circle so that it can be quickly drawn next time
|
||||
circleCache.Add(circleKey, vectors);
|
||||
|
||||
return vectors;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of vectors that represents an arc
|
||||
/// </summary>
|
||||
/// <param name="radius">The radius of the arc</param>
|
||||
/// <param name="sides">The number of sides to generate in the circle that this will cut out from</param>
|
||||
/// <param name="startingAngle">The starting angle of arc, 0 being to the east, increasing as you go clockwise</param>
|
||||
/// <param name="radians">The radians to draw, clockwise from the starting angle</param>
|
||||
/// <returns>A list of vectors that, if connected, will create an arc</returns>
|
||||
private static List<Vector2> CreateArc(float radius, int sides, float startingAngle, float radians)
|
||||
{
|
||||
List<Vector2> points = new List<Vector2>();
|
||||
points.AddRange(CreateCircle(radius, sides));
|
||||
points.RemoveAt(points.Count - 1); // remove the last point because it's a duplicate of the first
|
||||
|
||||
// The circle starts at (radius, 0)
|
||||
double curAngle = 0.0;
|
||||
double anglePerSide = MathHelper.TwoPi / sides;
|
||||
|
||||
// "Rotate" to the starting point
|
||||
while ((curAngle + (anglePerSide / 2.0)) < startingAngle)
|
||||
{
|
||||
curAngle += anglePerSide;
|
||||
|
||||
// move the first point to the end
|
||||
points.Add(points[0]);
|
||||
points.RemoveAt(0);
|
||||
}
|
||||
|
||||
// Add the first point, just in case we make a full circle
|
||||
points.Add(points[0]);
|
||||
|
||||
// Now remove the points at the end of the circle to create the arc
|
||||
int sidesInArc = (int)((radians / anglePerSide) + 0.5);
|
||||
points.RemoveRange(sidesInArc + 1, points.Count - sidesInArc - 1);
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region FillRectangle
|
||||
|
||||
/// <summary>
|
||||
/// Draws a filled rectangle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="rect">The rectangle to draw</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
public static void FillRectangle(this SpriteBatch spriteBatch, Rectangle rect, Color color)
|
||||
{
|
||||
if (pixel == null)
|
||||
{
|
||||
CreateThePixel(spriteBatch);
|
||||
}
|
||||
|
||||
// Simply use the function already there
|
||||
spriteBatch.Draw(pixel, rect, color);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a filled rectangle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="rect">The rectangle to draw</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
/// <param name="angle">The angle in radians to draw the rectangle at</param>
|
||||
public static void FillRectangle(this SpriteBatch spriteBatch, Rectangle rect, Color color, float angle)
|
||||
{
|
||||
if (pixel == null)
|
||||
{
|
||||
CreateThePixel(spriteBatch);
|
||||
}
|
||||
|
||||
spriteBatch.Draw(pixel, rect, null, color, angle, Vector2.Zero, SpriteEffects.None, 0);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a filled rectangle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="location">Where to draw</param>
|
||||
/// <param name="size">The size of the rectangle</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
public static void FillRectangle(this SpriteBatch spriteBatch, Vector2 location, Vector2 size, Color color)
|
||||
{
|
||||
FillRectangle(spriteBatch, location, size, color, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a filled rectangle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="location">Where to draw</param>
|
||||
/// <param name="size">The size of the rectangle</param>
|
||||
/// <param name="angle">The angle in radians to draw the rectangle at</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
public static void FillRectangle(this SpriteBatch spriteBatch, Vector2 location, Vector2 size, Color color, float angle)
|
||||
{
|
||||
if (pixel == null)
|
||||
{
|
||||
CreateThePixel(spriteBatch);
|
||||
}
|
||||
|
||||
// stretch the pixel between the two vectors
|
||||
spriteBatch.Draw(pixel,
|
||||
location,
|
||||
null,
|
||||
color,
|
||||
angle,
|
||||
Vector2.Zero,
|
||||
size,
|
||||
SpriteEffects.None,
|
||||
0);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a filled rectangle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="x">The X coord of the left side</param>
|
||||
/// <param name="y">The Y coord of the upper side</param>
|
||||
/// <param name="w">Width</param>
|
||||
/// <param name="h">Height</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
public static void FillRectangle(this SpriteBatch spriteBatch, float x, float y, float w, float h, Color color)
|
||||
{
|
||||
FillRectangle(spriteBatch, new Vector2(x, y), new Vector2(w, h), color, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a filled rectangle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="x">The X coord of the left side</param>
|
||||
/// <param name="y">The Y coord of the upper side</param>
|
||||
/// <param name="w">Width</param>
|
||||
/// <param name="h">Height</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
/// <param name="angle">The angle of the rectangle in radians</param>
|
||||
public static void FillRectangle(this SpriteBatch spriteBatch, float x, float y, float w, float h, Color color, float angle)
|
||||
{
|
||||
FillRectangle(spriteBatch, new Vector2(x, y), new Vector2(w, h), color, angle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region DrawRectangle
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the thickness provided
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="rect">The rectangle to draw</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
public static void DrawRectangle(this SpriteBatch spriteBatch, Rectangle rect, Color color)
|
||||
{
|
||||
DrawRectangle(spriteBatch, rect, color, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the thickness provided
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="rect">The rectangle to draw</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
/// <param name="thickness">The thickness of the lines</param>
|
||||
public static void DrawRectangle(this SpriteBatch spriteBatch, Rectangle rect, Color color, float thickness)
|
||||
{
|
||||
|
||||
// TODO: Handle rotations
|
||||
// TODO: Figure out the pattern for the offsets required and then handle it in the line instead of here
|
||||
|
||||
DrawLine(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.Right, rect.Y), color, thickness); // top
|
||||
DrawLine(spriteBatch, new Vector2(rect.X + 1f, rect.Y), new Vector2(rect.X + 1f, rect.Bottom + thickness), color, thickness); // left
|
||||
DrawLine(spriteBatch, new Vector2(rect.X, rect.Bottom), new Vector2(rect.Right, rect.Bottom), color, thickness); // bottom
|
||||
DrawLine(spriteBatch, new Vector2(rect.Right + 1f, rect.Y), new Vector2(rect.Right + 1f, rect.Bottom + thickness), color, thickness); // right
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the thickness provided
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="location">Where to draw</param>
|
||||
/// <param name="size">The size of the rectangle</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
public static void DrawRectangle(this SpriteBatch spriteBatch, Vector2 location, Vector2 size, Color color)
|
||||
{
|
||||
DrawRectangle(spriteBatch, new Rectangle((int)location.X, (int)location.Y, (int)size.X, (int)size.Y), color, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the thickness provided
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="location">Where to draw</param>
|
||||
/// <param name="size">The size of the rectangle</param>
|
||||
/// <param name="color">The color to draw the rectangle in</param>
|
||||
/// <param name="thickness">The thickness of the line</param>
|
||||
public static void DrawRectangle(this SpriteBatch spriteBatch, Vector2 location, Vector2 size, Color color, float thickness)
|
||||
{
|
||||
DrawRectangle(spriteBatch, new Rectangle((int)location.X, (int)location.Y, (int)size.X, (int)size.Y), color, thickness);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region DrawLine
|
||||
|
||||
/// <summary>
|
||||
/// Draws a line from point1 to point2 with an offset
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="x1">The X coord of the first point</param>
|
||||
/// <param name="y1">The Y coord of the first point</param>
|
||||
/// <param name="x2">The X coord of the second point</param>
|
||||
/// <param name="y2">The Y coord of the second point</param>
|
||||
/// <param name="color">The color to use</param>
|
||||
public static void DrawLine(this SpriteBatch spriteBatch, float x1, float y1, float x2, float y2, Color color)
|
||||
{
|
||||
DrawLine(spriteBatch, new Vector2(x1, y1), new Vector2(x2, y2), color, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a line from point1 to point2 with an offset
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="x1">The X coord of the first point</param>
|
||||
/// <param name="y1">The Y coord of the first point</param>
|
||||
/// <param name="x2">The X coord of the second point</param>
|
||||
/// <param name="y2">The Y coord of the second point</param>
|
||||
/// <param name="color">The color to use</param>
|
||||
/// <param name="thickness">The thickness of the line</param>
|
||||
public static void DrawLine(this SpriteBatch spriteBatch, float x1, float y1, float x2, float y2, Color color, float thickness)
|
||||
{
|
||||
DrawLine(spriteBatch, new Vector2(x1, y1), new Vector2(x2, y2), color, thickness);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a line from point1 to point2 with an offset
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="point1">The first point</param>
|
||||
/// <param name="point2">The second point</param>
|
||||
/// <param name="color">The color to use</param>
|
||||
public static void DrawLine(this SpriteBatch spriteBatch, Vector2 point1, Vector2 point2, Color color)
|
||||
{
|
||||
DrawLine(spriteBatch, point1, point2, color, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a line from point1 to point2 with an offset
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="point1">The first point</param>
|
||||
/// <param name="point2">The second point</param>
|
||||
/// <param name="color">The color to use</param>
|
||||
/// <param name="thickness">The thickness of the line</param>
|
||||
public static void DrawLine(this SpriteBatch spriteBatch, Vector2 point1, Vector2 point2, Color color, float thickness)
|
||||
{
|
||||
// calculate the distance between the two vectors
|
||||
float distance = Vector2.Distance(point1, point2);
|
||||
|
||||
// calculate the angle between the two vectors
|
||||
float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
|
||||
|
||||
DrawLine(spriteBatch, point1, distance, angle, color, thickness);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a line from point1 to point2 with an offset
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="point">The starting point</param>
|
||||
/// <param name="length">The length of the line</param>
|
||||
/// <param name="angle">The angle of this line from the starting point in radians</param>
|
||||
/// <param name="color">The color to use</param>
|
||||
public static void DrawLine(this SpriteBatch spriteBatch, Vector2 point, float length, float angle, Color color)
|
||||
{
|
||||
DrawLine(spriteBatch, point, length, angle, color, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a line from point1 to point2 with an offset
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="point">The starting point</param>
|
||||
/// <param name="length">The length of the line</param>
|
||||
/// <param name="angle">The angle of this line from the starting point</param>
|
||||
/// <param name="color">The color to use</param>
|
||||
/// <param name="thickness">The thickness of the line</param>
|
||||
public static void DrawLine(this SpriteBatch spriteBatch, Vector2 point, float length, float angle, Color color, float thickness)
|
||||
{
|
||||
if (pixel == null)
|
||||
{
|
||||
CreateThePixel(spriteBatch);
|
||||
}
|
||||
|
||||
// stretch the pixel between the two vectors
|
||||
spriteBatch.Draw(pixel,
|
||||
point,
|
||||
null,
|
||||
color,
|
||||
angle,
|
||||
Vector2.Zero,
|
||||
new Vector2(length, thickness),
|
||||
SpriteEffects.None,
|
||||
0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region PutPixel
|
||||
|
||||
public static void PutPixel(this SpriteBatch spriteBatch, float x, float y, Color color)
|
||||
{
|
||||
PutPixel(spriteBatch, new Vector2(x, y), color);
|
||||
}
|
||||
|
||||
|
||||
public static void PutPixel(this SpriteBatch spriteBatch, Vector2 position, Color color)
|
||||
{
|
||||
if (pixel == null)
|
||||
{
|
||||
CreateThePixel(spriteBatch);
|
||||
}
|
||||
|
||||
spriteBatch.Draw(pixel, position, color);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region DrawCircle
|
||||
|
||||
/// <summary>
|
||||
/// Draw a circle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="center">The center of the circle</param>
|
||||
/// <param name="radius">The radius of the circle</param>
|
||||
/// <param name="sides">The number of sides to generate</param>
|
||||
/// <param name="color">The color of the circle</param>
|
||||
public static void DrawCircle(this SpriteBatch spriteBatch, Vector2 center, float radius, int sides, Color color)
|
||||
{
|
||||
DrawPoints(spriteBatch, center, CreateCircle(radius, sides), color, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draw a circle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="center">The center of the circle</param>
|
||||
/// <param name="radius">The radius of the circle</param>
|
||||
/// <param name="sides">The number of sides to generate</param>
|
||||
/// <param name="color">The color of the circle</param>
|
||||
/// <param name="thickness">The thickness of the lines used</param>
|
||||
public static void DrawCircle(this SpriteBatch spriteBatch, Vector2 center, float radius, int sides, Color color, float thickness)
|
||||
{
|
||||
DrawPoints(spriteBatch, center, CreateCircle(radius, sides), color, thickness);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draw a circle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="x">The center X of the circle</param>
|
||||
/// <param name="y">The center Y of the circle</param>
|
||||
/// <param name="radius">The radius of the circle</param>
|
||||
/// <param name="sides">The number of sides to generate</param>
|
||||
/// <param name="color">The color of the circle</param>
|
||||
public static void DrawCircle(this SpriteBatch spriteBatch, float x, float y, float radius, int sides, Color color)
|
||||
{
|
||||
DrawPoints(spriteBatch, new Vector2(x, y), CreateCircle(radius, sides), color, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draw a circle
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="x">The center X of the circle</param>
|
||||
/// <param name="y">The center Y of the circle</param>
|
||||
/// <param name="radius">The radius of the circle</param>
|
||||
/// <param name="sides">The number of sides to generate</param>
|
||||
/// <param name="color">The color of the circle</param>
|
||||
/// <param name="thickness">The thickness of the lines used</param>
|
||||
public static void DrawCircle(this SpriteBatch spriteBatch, float x, float y, float radius, int sides, Color color, float thickness)
|
||||
{
|
||||
DrawPoints(spriteBatch, new Vector2(x, y), CreateCircle(radius, sides), color, thickness);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region DrawArc
|
||||
|
||||
/// <summary>
|
||||
/// Draw a arc
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="center">The center of the arc</param>
|
||||
/// <param name="radius">The radius of the arc</param>
|
||||
/// <param name="sides">The number of sides to generate</param>
|
||||
/// <param name="startingAngle">The starting angle of arc, 0 being to the east, increasing as you go clockwise</param>
|
||||
/// <param name="radians">The number of radians to draw, clockwise from the starting angle</param>
|
||||
/// <param name="color">The color of the arc</param>
|
||||
public static void DrawArc(this SpriteBatch spriteBatch, Vector2 center, float radius, int sides, float startingAngle, float radians, Color color)
|
||||
{
|
||||
DrawArc(spriteBatch, center, radius, sides, startingAngle, radians, color, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draw a arc
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">The destination drawing surface</param>
|
||||
/// <param name="center">The center of the arc</param>
|
||||
/// <param name="radius">The radius of the arc</param>
|
||||
/// <param name="sides">The number of sides to generate</param>
|
||||
/// <param name="startingAngle">The starting angle of arc, 0 being to the east, increasing as you go clockwise</param>
|
||||
/// <param name="radians">The number of radians to draw, clockwise from the starting angle</param>
|
||||
/// <param name="color">The color of the arc</param>
|
||||
/// <param name="thickness">The thickness of the arc</param>
|
||||
public static void DrawArc(this SpriteBatch spriteBatch, Vector2 center, float radius, int sides, float startingAngle, float radians, Color color, float thickness)
|
||||
{
|
||||
List<Vector2> arc = CreateArc(radius, sides, startingAngle, radians);
|
||||
//List<Vector2> arc = CreateArc2(radius, sides, startingAngle, degrees);
|
||||
DrawPoints(spriteBatch, center, arc, color, thickness);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
24
C#_Mono/PlanetSimulation/PlanetSimulation/Program.cs
Normal file
24
C#_Mono/PlanetSimulation/PlanetSimulation/Program.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace PlanetSimulation
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
private static Game1 game;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main ()
|
||||
{
|
||||
game = new Game1 ();
|
||||
game.Run ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("PlanetSimulation")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("hannes")]
|
||||
[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.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("")]
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
C#_Mono/PlanetSimulation/PlanetSimulation/bin/Debug/OpenTK.dll
Normal file
BIN
C#_Mono/PlanetSimulation/PlanetSimulation/bin/Debug/OpenTK.dll
Normal file
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
<configuration>
|
||||
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
|
||||
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
|
||||
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
|
||||
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
|
||||
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
|
||||
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
|
||||
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
|
||||
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
|
||||
</configuration>
|
||||
Binary file not shown.
Binary file not shown.
BIN
C#_Mono/PlanetSimulation/PlanetSimulation/bin/Debug/Tao.Sdl.dll
Normal file
BIN
C#_Mono/PlanetSimulation/PlanetSimulation/bin/Debug/Tao.Sdl.dll
Normal file
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
<configuration>
|
||||
<dllmap dll="SDL.dll" os="windows" target="SDL.dll"/>
|
||||
<dllmap dll="SDL.dll" os="osx" target="/Library/Frameworks/SDL.framework/SDL" />
|
||||
<dllmap dll="SDL.dll" os="!windows,osx" target="libSDL-1.2.so.0"/>
|
||||
|
||||
<dllmap dll="SDL_image.dll" os="windows" target="SDL_image.dll"/>
|
||||
<dllmap dll="SDL_image.dll" os="osx" target="/Library/Frameworks/SDL_image.framework/SDL_image" />
|
||||
<dllmap dll="SDL_image.dll" os="!windows,osx" target="libSDL_image-1.2.so.0" />
|
||||
|
||||
<dllmap dll="SDL_mixer.dll" os="windows" target="SDL_mixer.dll"/>
|
||||
<dllmap dll="SDL_mixer.dll" os="osx" target="/Library/Frameworks/SDL_mixer.framework/SDL_mixer" />
|
||||
<dllmap dll="SDL_mixer.dll" os="!windows,osx" target="libSDL_mixer-1.2.so.0" />
|
||||
|
||||
<dllmap dll="SDL_ttf.dll" os="windows" target="SDL_ttf.dll"/>
|
||||
<dllmap dll="SDL_ttf.dll" os="osx" target="/Library/Frameworks/SDL_ttf.framework/SDL_ttf" />
|
||||
<dllmap dll="SDL_ttf.dll" os="!windows,osx" target="libSDL_ttf-2.0.so.0" />
|
||||
|
||||
<dllmap dll="SDL_net.dll" os="windows" target="SDL_net.dll"/>
|
||||
<dllmap dll="SDL_net.dll" os="osx" target="/Library/Frameworks/SDL_net.framework/SDL_net" />
|
||||
<dllmap dll="SDL_net.dll" os="!windows,osx" target="libSDL_net-1.2.so.0" />
|
||||
|
||||
<dllmap dll="smpeg.dll" os="windows" target="smpeg.dll"/>
|
||||
<dllmap dll="smpeg.dll" os="osx" target="/Library/Frameworks/smpeg.framework/smpeg" />
|
||||
<dllmap dll="smpeg.dll" os="!windows,osx" target="libsmpeg-0.4.so.0" />
|
||||
|
||||
<dllmap dll="SDL_gfx.dll" os="windows" target="SDL_gfx.dll"/>
|
||||
<dllmap dll="SDL_gfx.dll" os="osx" target="/Library/Frameworks/SDL_gfx.framework/SDL_gfx" />
|
||||
<dllmap dll="SDL_gfx.dll" os="!windows,osx" target="libSDL_gfx.so.13" />
|
||||
</configuration>
|
||||
BIN
C#_Mono/UI/.vs/UI/v14/.suo
Normal file
BIN
C#_Mono/UI/.vs/UI/v14/.suo
Normal file
Binary file not shown.
20
C#_Mono/UI/UI.sln
Normal file
20
C#_Mono/UI/UI.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UI", "UI\UI.csproj", "{C8A34B07-5506-435E-BD12-2C6E477E2EC5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C8A34B07-5506-435E-BD12-2C6E477E2EC5}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{C8A34B07-5506-435E-BD12-2C6E477E2EC5}.Debug|x86.Build.0 = Debug|x86
|
||||
{C8A34B07-5506-435E-BD12-2C6E477E2EC5}.Release|x86.ActiveCfg = Release|x86
|
||||
{C8A34B07-5506-435E-BD12-2C6E477E2EC5}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = UI\UI.csproj
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
16
C#_Mono/UI/UI.userprefs
Normal file
16
C#_Mono/UI/UI.userprefs
Normal file
@@ -0,0 +1,16 @@
|
||||
<Properties>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="UI/UI/Button.cs">
|
||||
<Files>
|
||||
<File FileName="UI/Game1.cs" Line="1" Column="1" />
|
||||
<File FileName="UI/DemoToolBox.cs" Line="1" Column="1" />
|
||||
<File FileName="UI/UI/ToolWindow.cs" Line="1" Column="1" />
|
||||
<File FileName="UI/UI/UIElement.cs" Line="1" Column="1" />
|
||||
<File FileName="UI/UI/Button.cs" Line="39" Column="1" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
|
||||
</Properties>
|
||||
17
C#_Mono/UI/UI/DemoToolBox.cs
Normal file
17
C#_Mono/UI/UI/DemoToolBox.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class DemoToolBox : ToolWindow
|
||||
{
|
||||
Button submit;
|
||||
public DemoToolBox (Vector2 pos, Vector2 size) : base(pos,size)
|
||||
{
|
||||
submit = new Button (offset, new Rectangle (10, 10, 100, 20), Color.Gray, 2, Color.Black);
|
||||
uiElements.Add(submit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
91
C#_Mono/UI/UI/Game1.cs
Normal file
91
C#_Mono/UI/UI/Game1.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Storage;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace UI
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the main type for your game
|
||||
/// </summary>
|
||||
public class Game1 : Game
|
||||
{
|
||||
GraphicsDeviceManager graphics;
|
||||
SpriteBatch spriteBatch;
|
||||
|
||||
DemoToolBox t;
|
||||
|
||||
public Game1 ()
|
||||
{
|
||||
graphics = new GraphicsDeviceManager (this);
|
||||
Content.RootDirectory = "Content";
|
||||
graphics.IsFullScreen = false;
|
||||
}
|
||||
|
||||
/// <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
|
||||
t = new DemoToolBox(Vector2.Zero, new Vector2(640, 480));
|
||||
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
// For Mobile devices, this logic will close the Game when the Back button is pressed
|
||||
if (GamePad.GetState (PlayerIndex.One).Buttons.Back == ButtonState.Pressed) {
|
||||
Exit ();
|
||||
}
|
||||
t.Update();
|
||||
// TODO: Add your update logic here
|
||||
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);
|
||||
|
||||
//TODO: Add your drawing code here
|
||||
//spriteBatch.Begin();
|
||||
// b.Draw(graphics.GraphicsDevice, spriteBatch);
|
||||
//spriteBatch.End();
|
||||
t.DrawStatic(GraphicsDevice, spriteBatch);
|
||||
base.Draw (gameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
C#_Mono/UI/UI/Icon.png
Normal file
BIN
C#_Mono/UI/UI/Icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
24
C#_Mono/UI/UI/Program.cs
Normal file
24
C#_Mono/UI/UI/Program.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace UI
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
private static Game1 game;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main ()
|
||||
{
|
||||
game = new Game1 ();
|
||||
game.Run ();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
C#_Mono/UI/UI/Properties/AssemblyInfo.cs
Normal file
27
C#_Mono/UI/UI/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("UI")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("hannes")]
|
||||
[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.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("")]
|
||||
|
||||
60
C#_Mono/UI/UI/UI.csproj
Normal file
60
C#_Mono/UI/UI/UI.csproj
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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)' == '' ">x86</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{C8A34B07-5506-435E-BD12-2C6E477E2EC5}</ProjectGuid>
|
||||
<ProjectTypeGuids>{9B831FEF-F496-498F-9FE8-180DA5CB4258};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>UI</RootNamespace>
|
||||
<MonoGamePlatform>Linux</MonoGamePlatform>
|
||||
<AssemblyName>UI</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="MonoGame.Framework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Game1.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UI\Button.cs" />
|
||||
<Compile Include="UI\SolidColorTexture.cs" />
|
||||
<Compile Include="UI\ToolWindow.cs" />
|
||||
<Compile Include="UI\MouseManager.cs" />
|
||||
<Compile Include="DemoToolBox.cs" />
|
||||
<Compile Include="UI\UIElement.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Icon.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Content\" />
|
||||
<Folder Include="UI\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
38
C#_Mono/UI/UI/UI/Button.cs
Normal file
38
C#_Mono/UI/UI/UI/Button.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class Button : UIElement
|
||||
{
|
||||
protected Color hColor {
|
||||
get{ return new Color(Color.Black, 60); }}
|
||||
protected Color innerColor;
|
||||
protected int borderSize;
|
||||
|
||||
public Button (Vector2 offset, Rectangle b, Color c, int borderThickness, Color bColor): base(offset, b, bColor)
|
||||
{
|
||||
innerColor = c;
|
||||
borderSize = borderThickness;
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
public override void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(graphicsDevice, spriteBatch);
|
||||
var texture = new SolidColorTexture(graphicsDevice, innerColor);
|
||||
var hTexture = new SolidColorTexture(graphicsDevice, hColor);
|
||||
Rectangle inner = new Rectangle(bound.X + borderSize, bound.Y + borderSize , bound.Width - 2*borderSize, bound.Height - 2* borderSize);
|
||||
|
||||
spriteBatch.Draw(texture, inner, Color.White);
|
||||
if(bound.Contains(m.MousePosition))
|
||||
spriteBatch.Draw(hTexture, inner, Color.White);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
48
C#_Mono/UI/UI/UI/MouseManager.cs
Normal file
48
C#_Mono/UI/UI/UI/MouseManager.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class MouseManager
|
||||
{
|
||||
public event EventHandler LeftButtonClicked;
|
||||
public event EventHandler LeftButtonReleased;
|
||||
bool leftButtonLastState;
|
||||
Point lastClickedPos;
|
||||
public Point LastClickedPos {
|
||||
get {return lastClickedPos;}}
|
||||
|
||||
public Point MousePosition {
|
||||
get{
|
||||
MouseState mState = Mouse.GetState();
|
||||
return new Point(mState.X, mState.Y);
|
||||
}
|
||||
}
|
||||
|
||||
public MouseManager ()
|
||||
{
|
||||
leftButtonLastState = false;
|
||||
}
|
||||
|
||||
public void Update ()
|
||||
{
|
||||
//If Clicked
|
||||
if (Mouse.GetState ().LeftButton == ButtonState.Pressed && !leftButtonLastState) {
|
||||
if (LeftButtonClicked != null)
|
||||
LeftButtonClicked(this, null);
|
||||
leftButtonLastState = true;
|
||||
lastClickedPos = MousePosition;
|
||||
}
|
||||
//If Released
|
||||
if(Mouse.GetState ().LeftButton == ButtonState.Released && leftButtonLastState)
|
||||
{
|
||||
if (LeftButtonReleased != null)
|
||||
LeftButtonReleased(this, null);
|
||||
leftButtonLastState = false;
|
||||
lastClickedPos = Point.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
C#_Mono/UI/UI/UI/SolidColorTexture.cs
Normal file
38
C#_Mono/UI/UI/UI/SolidColorTexture.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class SolidColorTexture : Texture2D
|
||||
{
|
||||
private Color _color;
|
||||
// Gets or sets the color used to create the texture
|
||||
public Color Color
|
||||
{
|
||||
get { return _color; }
|
||||
set
|
||||
{
|
||||
if (value != _color)
|
||||
{
|
||||
_color = value;
|
||||
SetData<Color>(new Color[] { _color });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SolidColorTexture(GraphicsDevice graphicsDevice)
|
||||
: base(graphicsDevice, 1, 1)
|
||||
{
|
||||
//default constructor
|
||||
}
|
||||
public SolidColorTexture(GraphicsDevice graphicsDevice, Color color)
|
||||
: base(graphicsDevice, 1, 1)
|
||||
{
|
||||
Color = color;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
60
C#_Mono/UI/UI/UI/ToolWindow.cs
Normal file
60
C#_Mono/UI/UI/UI/ToolWindow.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class ToolWindow
|
||||
{
|
||||
protected List<UIElement> uiElements;
|
||||
Button minimizeButton;
|
||||
|
||||
int windowBarHeight;
|
||||
Vector2 pos;
|
||||
Vector2 size;
|
||||
Boolean minimized;
|
||||
protected Vector2 offset;
|
||||
|
||||
public ToolWindow (Vector2 pos, Vector2 size)
|
||||
{
|
||||
uiElements = new List<UIElement>();
|
||||
windowBarHeight = 20;
|
||||
offset = new Vector2(pos.X, pos.Y + windowBarHeight);
|
||||
minimized = false;
|
||||
this.pos = pos;
|
||||
this.size = size;
|
||||
minimizeButton = new Button(new Vector2(2,2), new Rectangle((int)pos.X, (int) pos.Y, windowBarHeight - 4, windowBarHeight -4), Color.Red, 2, Color.Black);
|
||||
minimizeButton.Clicked += new EventHandler(minimize);
|
||||
}
|
||||
public void Update ()
|
||||
{
|
||||
minimizeButton.Update();
|
||||
foreach (var element in uiElements) {
|
||||
element.Update();
|
||||
}
|
||||
}
|
||||
public void DrawStatic (GraphicsDevice graphicsDevice, SpriteBatch spriteBatch)
|
||||
{
|
||||
var headBarTexture = new SolidColorTexture(graphicsDevice, Color.DarkGray);
|
||||
var bodyTexture = new SolidColorTexture(graphicsDevice, Color.DimGray);
|
||||
|
||||
spriteBatch.Begin();
|
||||
spriteBatch.Draw(headBarTexture, new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, windowBarHeight), Color.White);
|
||||
minimizeButton.Draw(graphicsDevice, spriteBatch);
|
||||
if (!minimized) {
|
||||
spriteBatch.Draw(bodyTexture, new Rectangle((int)pos.X, (int)pos.Y + windowBarHeight, (int)size.X,(int)size.Y - windowBarHeight), Color.White);
|
||||
//Draw all UI Elements
|
||||
foreach (var element in uiElements) {
|
||||
element.Draw(graphicsDevice, spriteBatch);
|
||||
}
|
||||
}
|
||||
spriteBatch.End();
|
||||
}
|
||||
protected void minimize(object sender, EventArgs e)
|
||||
{
|
||||
minimized = !minimized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
C#_Mono/UI/UI/UI/UICamera.cs
Normal file
12
C#_Mono/UI/UI/UI/UICamera.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class UICamera
|
||||
{
|
||||
public UICamera ()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
47
C#_Mono/UI/UI/UI/UIElement.cs
Normal file
47
C#_Mono/UI/UI/UI/UIElement.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class UIElement
|
||||
{
|
||||
protected MouseManager m;
|
||||
protected Rectangle bound;
|
||||
protected Color color;
|
||||
|
||||
public event EventHandler Clicked;
|
||||
|
||||
public UIElement (Vector2 offset ,Rectangle b, Color c)
|
||||
{
|
||||
m = new MouseManager();
|
||||
m.LeftButtonClicked += new EventHandler(click);
|
||||
|
||||
color = c;
|
||||
bound = new Rectangle((int)(b.X + offset.X), (int)(b.Y + offset.Y), b.Width, b.Height);
|
||||
}
|
||||
|
||||
public virtual void Update ()
|
||||
{
|
||||
m.Update();
|
||||
}
|
||||
public virtual void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch)
|
||||
{
|
||||
var texture = new SolidColorTexture(graphicsDevice, color);
|
||||
spriteBatch.Draw(texture, bound, Color.White);
|
||||
}
|
||||
private void click (object sender, EventArgs e)
|
||||
{
|
||||
if (Clicked != null && bound.Contains (m.MousePosition)) {
|
||||
onClick();
|
||||
Clicked (this, null);
|
||||
}
|
||||
}
|
||||
public virtual void onClick()
|
||||
{
|
||||
//Should be overidden by UI Elements
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BIN
C#_Mono/UI/UI/bin/Debug/Lidgren.Network.dll
Normal file
BIN
C#_Mono/UI/UI/bin/Debug/Lidgren.Network.dll
Normal file
Binary file not shown.
BIN
C#_Mono/UI/UI/bin/Debug/MonoGame.Framework.dll
Normal file
BIN
C#_Mono/UI/UI/bin/Debug/MonoGame.Framework.dll
Normal file
Binary file not shown.
BIN
C#_Mono/UI/UI/bin/Debug/OpenTK.dll
Normal file
BIN
C#_Mono/UI/UI/bin/Debug/OpenTK.dll
Normal file
Binary file not shown.
14
C#_Mono/UI/UI/bin/Debug/OpenTK.dll.config
Normal file
14
C#_Mono/UI/UI/bin/Debug/OpenTK.dll.config
Normal file
@@ -0,0 +1,14 @@
|
||||
<configuration>
|
||||
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
|
||||
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
|
||||
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
|
||||
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
|
||||
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
|
||||
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
|
||||
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
|
||||
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
|
||||
</configuration>
|
||||
BIN
C#_Mono/UI/UI/bin/Debug/Tao.Sdl.dll
Normal file
BIN
C#_Mono/UI/UI/bin/Debug/Tao.Sdl.dll
Normal file
Binary file not shown.
29
C#_Mono/UI/UI/bin/Debug/Tao.Sdl.dll.config
Normal file
29
C#_Mono/UI/UI/bin/Debug/Tao.Sdl.dll.config
Normal file
@@ -0,0 +1,29 @@
|
||||
<configuration>
|
||||
<dllmap dll="SDL.dll" os="windows" target="SDL.dll"/>
|
||||
<dllmap dll="SDL.dll" os="osx" target="/Library/Frameworks/SDL.framework/SDL" />
|
||||
<dllmap dll="SDL.dll" os="!windows,osx" target="libSDL-1.2.so.0"/>
|
||||
|
||||
<dllmap dll="SDL_image.dll" os="windows" target="SDL_image.dll"/>
|
||||
<dllmap dll="SDL_image.dll" os="osx" target="/Library/Frameworks/SDL_image.framework/SDL_image" />
|
||||
<dllmap dll="SDL_image.dll" os="!windows,osx" target="libSDL_image-1.2.so.0" />
|
||||
|
||||
<dllmap dll="SDL_mixer.dll" os="windows" target="SDL_mixer.dll"/>
|
||||
<dllmap dll="SDL_mixer.dll" os="osx" target="/Library/Frameworks/SDL_mixer.framework/SDL_mixer" />
|
||||
<dllmap dll="SDL_mixer.dll" os="!windows,osx" target="libSDL_mixer-1.2.so.0" />
|
||||
|
||||
<dllmap dll="SDL_ttf.dll" os="windows" target="SDL_ttf.dll"/>
|
||||
<dllmap dll="SDL_ttf.dll" os="osx" target="/Library/Frameworks/SDL_ttf.framework/SDL_ttf" />
|
||||
<dllmap dll="SDL_ttf.dll" os="!windows,osx" target="libSDL_ttf-2.0.so.0" />
|
||||
|
||||
<dllmap dll="SDL_net.dll" os="windows" target="SDL_net.dll"/>
|
||||
<dllmap dll="SDL_net.dll" os="osx" target="/Library/Frameworks/SDL_net.framework/SDL_net" />
|
||||
<dllmap dll="SDL_net.dll" os="!windows,osx" target="libSDL_net-1.2.so.0" />
|
||||
|
||||
<dllmap dll="smpeg.dll" os="windows" target="smpeg.dll"/>
|
||||
<dllmap dll="smpeg.dll" os="osx" target="/Library/Frameworks/smpeg.framework/smpeg" />
|
||||
<dllmap dll="smpeg.dll" os="!windows,osx" target="libsmpeg-0.4.so.0" />
|
||||
|
||||
<dllmap dll="SDL_gfx.dll" os="windows" target="SDL_gfx.dll"/>
|
||||
<dllmap dll="SDL_gfx.dll" os="osx" target="/Library/Frameworks/SDL_gfx.framework/SDL_gfx" />
|
||||
<dllmap dll="SDL_gfx.dll" os="!windows,osx" target="libSDL_gfx.so.13" />
|
||||
</configuration>
|
||||
BIN
C#_Mono/UI/UI/bin/Debug/UI.exe
Normal file
BIN
C#_Mono/UI/UI/bin/Debug/UI.exe
Normal file
Binary file not shown.
BIN
C#_Mono/UI/UI/bin/Debug/UI.exe.mdb
Normal file
BIN
C#_Mono/UI/UI/bin/Debug/UI.exe.mdb
Normal file
Binary file not shown.
BIN
C#_Mono/UI/UpgradeLog.htm
Normal file
BIN
C#_Mono/UI/UpgradeLog.htm
Normal file
Binary file not shown.
Reference in New Issue
Block a user