AxiosEngine-old 

AxiosEngine-old Commit Details


Date:2014-11-28 19:16:00 (10 years 23 days ago)
Author:Natalie Adams
Branch:default
Commit:08bf2cedf079
Parents: f37496249731
Message:Adding prompt class to generate rounded square for text display

Updating README
Changes:
Aaxios/Factories/Prompt.cs (full)
MREADME (2 diffs)
Maxios/Axios_Windows.csproj (1 diff)

File differences

README
3131
3232
3333
34
34
3535
3636
3737
38
38
3939
4040
4141
4242
4343
44
4445
4546
4647
......
6566
6667
6768
68
69
70
71
72
Official versions can be downloaded here:
http://code.google.com/p/axiosengine/downloads/list
https://srchub.org/p/axiosengine/downloads/
Of course you can always build from source from:
http://code.google.com/p/axiosengine/source/checkout
https://srchub.org/hg/axiosengine
Authors
-------
General questions/comments/concerns can be directed at:
Nathan Adams - adamsna[at]datanethost.net
Contributors:
http://xnacc.codeplex.com/
Portions of this product are (C) 2009-2011 JRTwine Software, LLC
Portions of this product are (C) 2009-2011 JRTwine Software, LLC
Prompt Factory - By Blaze Phoenix
http://stackoverflow.com/a/17260476/195722
axios/Axios_Windows.csproj
249249
250250
251251
252
252253
253254
254255
<Compile Include="Factories\FixtureFactory.cs" />
<Compile Include="Factories\JointFactory.cs" />
<Compile Include="Factories\LinkFactory.cs" />
<Compile Include="Factories\Prompt.cs" />
<Compile Include="PrimitiveBatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenSystem\BackgroundScreen.cs" />
axios/Factories/Prompt.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Axios.Factories
{
public static class Prompt
{
// Copied from http://stackoverflow.com/a/17260476/195722
// Written by Blaze Phoenix
/// <summary>
/// Creates a rounded rectangle
/// </summary>
/// <param name="graphics"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="borderThickness"></param>
/// <param name="borderRadius"></param>
/// <param name="borderShadow"></param>
/// <param name="backgroundColors"></param>
/// <param name="borderColors"></param>
/// <param name="initialShadowIntensity"></param>
/// <param name="finalShadowIntensity"></param>
/// <returns></returns>
public static Texture2D CreateRoundedRectangleTexture(this GraphicsDevice graphics, int width, int height, int borderThickness, int borderRadius, int borderShadow, List<Color> backgroundColors, List<Color> borderColors, float initialShadowIntensity, float finalShadowIntensity)
{
if (backgroundColors == null || backgroundColors.Count == 0) throw new ArgumentException("Must define at least one background color (up to four).");
if (borderColors == null || borderColors.Count == 0) throw new ArgumentException("Must define at least one border color (up to three).");
if (borderRadius < 1) throw new ArgumentException("Must define a border radius (rounds off edges).");
if (borderThickness < 1) throw new ArgumentException("Must define border thikness.");
if (borderThickness + borderRadius > height / 2 || borderThickness + borderRadius > width / 2) throw new ArgumentException("Border will be too thick and/or rounded to fit on the texture.");
if (borderShadow > borderRadius) throw new ArgumentException("Border shadow must be lesser in magnitude than the border radius (suggeted: shadow <= 0.25 * radius).");
Texture2D texture = new Texture2D(graphics, width, height, false, SurfaceFormat.Color);
Color[] color = new Color[width * height];
for (int x = 0; x < texture.Width; x++)
{
for (int y = 0; y < texture.Height; y++)
{
switch (backgroundColors.Count)
{
case 4:
Color leftColor0 = Color.Lerp(backgroundColors[0], backgroundColors[1], ((float)y / (width - 1)));
Color rightColor0 = Color.Lerp(backgroundColors[2], backgroundColors[3], ((float)y / (height - 1)));
color[x + width * y] = Color.Lerp(leftColor0, rightColor0, ((float)x / (width - 1)));
break;
case 3:
Color leftColor1 = Color.Lerp(backgroundColors[0], backgroundColors[1], ((float)y / (width - 1)));
Color rightColor1 = Color.Lerp(backgroundColors[1], backgroundColors[2], ((float)y / (height - 1)));
color[x + width * y] = Color.Lerp(leftColor1, rightColor1, ((float)x / (width - 1)));
break;
case 2:
color[x + width * y] = Color.Lerp(backgroundColors[0], backgroundColors[1], ((float)x / (width - 1)));
break;
default:
color[x + width * y] = backgroundColors[0];
break;
}
color[x + width * y] = ColorBorder(x, y, width, height, borderThickness, borderRadius, borderShadow, color[x + width * y], borderColors, initialShadowIntensity, finalShadowIntensity);
}
}
texture.SetData<Color>(color);
return texture;
}
private static Color ColorBorder(int x, int y, int width, int height, int borderThickness, int borderRadius, int borderShadow, Color initialColor, List<Color> borderColors, float initialShadowIntensity, float finalShadowIntensity)
{
Rectangle internalRectangle = new Rectangle((borderThickness + borderRadius), (borderThickness + borderRadius), width - 2 * (borderThickness + borderRadius), height - 2 * (borderThickness + borderRadius));
if (internalRectangle.Contains(x, y)) return initialColor;
Vector2 origin = Vector2.Zero;
Vector2 point = new Vector2(x, y);
if (x < borderThickness + borderRadius)
{
if (y < borderRadius + borderThickness)
origin = new Vector2(borderRadius + borderThickness, borderRadius + borderThickness);
else if (y > height - (borderRadius + borderThickness))
origin = new Vector2(borderRadius + borderThickness, height - (borderRadius + borderThickness));
else
origin = new Vector2(borderRadius + borderThickness, y);
}
else if (x > width - (borderRadius + borderThickness))
{
if (y < borderRadius + borderThickness)
origin = new Vector2(width - (borderRadius + borderThickness), borderRadius + borderThickness);
else if (y > height - (borderRadius + borderThickness))
origin = new Vector2(width - (borderRadius + borderThickness), height - (borderRadius + borderThickness));
else
origin = new Vector2(width - (borderRadius + borderThickness), y);
}
else
{
if (y < borderRadius + borderThickness)
origin = new Vector2(x, borderRadius + borderThickness);
else if (y > height - (borderRadius + borderThickness))
origin = new Vector2(x, height - (borderRadius + borderThickness));
}
if (!origin.Equals(Vector2.Zero))
{
float distance = Vector2.Distance(point, origin);
if (distance > borderRadius + borderThickness + 1)
{
return Color.Transparent;
}
else if (distance > borderRadius + 1)
{
if (borderColors.Count > 2)
{
float modNum = distance - borderRadius;
if (modNum < borderThickness / 2)
{
return Color.Lerp(borderColors[2], borderColors[1], (float)((modNum) / (borderThickness / 2.0)));
}
else
{
return Color.Lerp(borderColors[1], borderColors[0], (float)((modNum - (borderThickness / 2.0)) / (borderThickness / 2.0)));
}
}
if (borderColors.Count > 0)
return borderColors[0];
}
else if (distance > borderRadius - borderShadow + 1)
{
float mod = (distance - (borderRadius - borderShadow)) / borderShadow;
float shadowDiff = initialShadowIntensity - finalShadowIntensity;
return DarkenColor(initialColor, ((shadowDiff * mod) + finalShadowIntensity));
}
}
return initialColor;
}
private static Color DarkenColor(Color color, float shadowIntensity)
{
return Color.Lerp(color, Color.Black, shadowIntensity);
}
}
}

Archive Download the corresponding diff file

Page rendered in 0.41737s using 14 queries.