Skip to content

Commit b10ebe4

Browse files
authored
Update UI sample (#32)
1 parent bdbeac2 commit b10ebe4

File tree

95 files changed

+699
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+699
-232
lines changed

samples/GraphicsWpf/Primitives/Primitives.nfproj renamed to samples/Graphics/Primitives/Primitives.nfproj

+29-14
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
</PropertyGroup>
1919
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
2020
<ItemGroup>
21+
<Compile Include="SimplePrimitives\BouncingBalls.cs" />
22+
<Compile Include="SimplePrimitives\ColourGradient.cs" />
23+
<Compile Include="SimplePrimitives\Colours.cs" />
24+
<Compile Include="SimplePrimitives\Extensions.cs" />
2125
<Compile Include="SimplePrimitives\InformationBar.cs" />
22-
<Compile Include="SimplePrimitives\RandomClipping.cs" />
26+
<Compile Include="SimplePrimitives\PagedText.cs" />
2327
<Compile Include="SimplePrimitives\MatrixRain.cs" />
2428
<Compile Include="PandaGif.cs" />
2529
<Compile Include="Program.cs" />
@@ -30,18 +34,18 @@
3034
<DependentUpon>Resource.resx</DependentUpon>
3135
</Compile>
3236
<Compile Include="SimplePrimitives\FontExamples.cs" />
33-
<Compile Include="SimplePrimitives\RandomEllipses.cs" />
3437
<Compile Include="SimplePrimitives\RandomDrawLine.cs" />
3538
<Compile Include="SimplePrimitives\RandomRectangles.cs" />
39+
<Compile Include="SimplePrimitives\RandomEllipsesAndClipping.cs" />
3640
<Compile Include="SimplePrimitives\RotateImage.cs" />
3741
<Compile Include="SimplePrimitives\SetPixels.cs" />
3842
<Compile Include="SimplePrimitives\SliceScaling9.cs" />
3943
<Compile Include="SimplePrimitives\StretchImage.cs" />
4044
<Compile Include="SimplePrimitives\TileImage.cs" />
41-
<Compile Include="Untitled.cs" />
4245
<Compile Include="WaterFallJpg.cs" />
4346
</ItemGroup>
4447
<ItemGroup>
48+
<None Include="app.config" />
4549
<None Include="packages.config" />
4650
<None Include="Resources\comicsansms16.tinyfnt" />
4751
<None Include="Resources\courierregular10.tinyfnt" />
@@ -57,34 +61,45 @@
5761
</EmbeddedResource>
5862
</ItemGroup>
5963
<ItemGroup>
60-
<Reference Include="mscorlib, Version=1.5.1.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
61-
<HintPath>..\packages\nanoFramework.CoreLibrary.1.5.1-preview.1\lib\mscorlib.dll</HintPath>
64+
<Reference Include="mscorlib, Version=1.7.2.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
65+
<HintPath>..\packages\nanoFramework.CoreLibrary.1.7.2-preview.7\lib\mscorlib.dll</HintPath>
6266
<Private>True</Private>
6367
<SpecificVersion>True</SpecificVersion>
6468
</Reference>
65-
<Reference Include="nanoFramework.Graphics.Wpf">
66-
<HintPath>..\..\..\..\..\lib-nanoFramework.Graphics.Wpf\source\nanoFramework.Graphics.Wpf\bin\Debug\nanoFramework.Graphics.Wpf.dll</HintPath>
69+
<Reference Include="nanoFramework.Graphics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
70+
<HintPath>packages\nanoFramework.Graphics.1.0.0-preview.1\lib\nanoFramework.Graphics.dll</HintPath>
71+
<Private>True</Private>
72+
<SpecificVersion>True</SpecificVersion>
6773
</Reference>
6874
<Reference Include="nanoFramework.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
69-
<HintPath>..\packages\nanoFramework.ResourceManager.1.0.0-preview.4\lib\nanoFramework.ResourceManager.dll</HintPath>
75+
<HintPath>..\packages\nanoFramework.ResourceManager.1.0.0-preview.14\lib\nanoFramework.ResourceManager.dll</HintPath>
7076
<Private>True</Private>
7177
<SpecificVersion>True</SpecificVersion>
7278
</Reference>
73-
<Reference Include="nanoFramework.Runtime.Events, Version=1.4.1.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
74-
<HintPath>..\packages\nanoFramework.Runtime.Events.1.4.1-preview.3\lib\nanoFramework.Runtime.Events.dll</HintPath>
79+
<Reference Include="nanoFramework.Runtime.Events, Version=1.4.2.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
80+
<HintPath>..\packages\nanoFramework.Runtime.Events.1.4.2-preview.7\lib\nanoFramework.Runtime.Events.dll</HintPath>
7581
<Private>True</Private>
7682
<SpecificVersion>True</SpecificVersion>
7783
</Reference>
78-
<Reference Include="nanoFramework.Runtime.Native, Version=1.2.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
79-
<HintPath>..\packages\nanoFramework.Runtime.Native.1.2.0-preview.7\lib\nanoFramework.Runtime.Native.dll</HintPath>
84+
<Reference Include="nanoFramework.Runtime.Native, Version=1.2.1.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
85+
<HintPath>..\packages\nanoFramework.Runtime.Native.1.2.1-preview.1\lib\nanoFramework.Runtime.Native.dll</HintPath>
8086
<Private>True</Private>
8187
<SpecificVersion>True</SpecificVersion>
8288
</Reference>
83-
<Reference Include="nanoFramework.System.Collections, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
84-
<HintPath>..\packages\nanoFramework.System.Collections.1.0.0-preview.6\lib\nanoFramework.System.Collections.dll</HintPath>
89+
<Reference Include="nanoFramework.System.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
90+
<HintPath>..\packages\nanoFramework.System.Collections.1.0.1-preview.6\lib\nanoFramework.System.Collections.dll</HintPath>
8591
<Private>True</Private>
8692
<SpecificVersion>True</SpecificVersion>
8793
</Reference>
94+
<Reference Include="System.Math, Version=1.2.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
95+
<HintPath>packages\nanoFramework.System.Math.1.2.0-preview.16\lib\System.Math.dll</HintPath>
96+
<Private>True</Private>
97+
<SpecificVersion>True</SpecificVersion>
98+
</Reference>
99+
</ItemGroup>
100+
<ItemGroup>
101+
<Content Include="Resources\SoccerBall.gif" />
102+
<Content Include="Resources\waterfall_costa_rica.jpg" />
88103
</ItemGroup>
89104
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
90105
<ProjectExtensions>
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30011.22
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Primitives", "Primitives.nfproj", "{3CB7ECF3-F8C0-4B5C-ACFF-9950F330277C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3CB7ECF3-F8C0-4B5C-ACFF-9950F330277C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3CB7ECF3-F8C0-4B5C-ACFF-9950F330277C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3CB7ECF3-F8C0-4B5C-ACFF-9950F330277C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{3CB7ECF3-F8C0-4B5C-ACFF-9950F330277C}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{3CB7ECF3-F8C0-4B5C-ACFF-9950F330277C}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{3CB7ECF3-F8C0-4B5C-ACFF-9950F330277C}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {26C3D99A-F38D-49F8-82D1-4B2C1CC359EA}
26+
EndGlobalSection
27+
EndGlobal

samples/GraphicsWpf/Primitives/Program.cs renamed to samples/Graphics/Primitives/Program.cs

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System;
2-
using System.Threading;
1+
using System.Threading;
32
using nanoFramework.UI;
43
using Primitives.SimplePrimitives;
54

5+
66
namespace Primitives
77
{
88
public class Program
@@ -12,48 +12,56 @@ public static void Main()
1212
DisplayControl dc = new DisplayControl();
1313
int height = dc.ShorterSide;
1414
int width = dc.LongerSide;
15-
int bpp = dc.BitsPerPixel;
16-
int delayBetween = 3000;
15+
int delayBetween = 1100;
16+
DisplayOrientation orientation = (DisplayOrientation)dc.Orientation;
1717

18-
Bitmap fullScreenBitmap = new Bitmap(width, height); // Use this bitmap as our output to the screen.
18+
Bitmap fullScreenBitmap = new Bitmap(width, height); // Use this bitmap as our buffered output to the screen.
1919
fullScreenBitmap.Clear();
20-
fullScreenBitmap.Flush();
21-
DisplayOrientation orientation = (DisplayOrientation)dc.Orientation;
20+
2221
Font DisplayFont = Resource.GetFont(Resource.FontResources.SegoeUIRegular12);
2322

2423
while (true)
2524
{
26-
SetPixels sp = new SetPixels(fullScreenBitmap, DisplayFont);
25+
RandomDrawLine rdlt = new RandomDrawLine(fullScreenBitmap, DisplayFont);
2726
Thread.Sleep(delayBetween);
2827

29-
FontExamples fe = new FontExamples(fullScreenBitmap);
28+
RotateImage ri = new RotateImage(fullScreenBitmap, DisplayFont);
3029
Thread.Sleep(delayBetween);
3130

32-
StretchImage si = new StretchImage(fullScreenBitmap, DisplayFont);
31+
ColourGradient colourGradient = new ColourGradient(fullScreenBitmap, DisplayFont);
3332
Thread.Sleep(delayBetween);
3433

35-
RandomDrawLine rdlt = new RandomDrawLine(fullScreenBitmap, DisplayFont);
34+
Colours ColourExample = new Colours(fullScreenBitmap, DisplayFont);
3635
Thread.Sleep(delayBetween);
3736

38-
TileImage ti = new TileImage(fullScreenBitmap, DisplayFont);
37+
PagedText pt = new PagedText(fullScreenBitmap, DisplayFont);
3938
Thread.Sleep(delayBetween);
4039

41-
RandomEllipses re = new RandomEllipses(fullScreenBitmap, DisplayFont);
40+
BouncingBalls bb = new BouncingBalls(fullScreenBitmap, DisplayFont);
4241
Thread.Sleep(delayBetween);
4342

44-
RandomRectangles rr = new RandomRectangles(fullScreenBitmap, DisplayFont);
43+
TileImage ti = new TileImage(fullScreenBitmap, DisplayFont);
4544
Thread.Sleep(delayBetween);
4645

47-
SliceScaling9 ss = new SliceScaling9(fullScreenBitmap, DisplayFont);
46+
StretchImage si = new StretchImage(fullScreenBitmap, DisplayFont);
4847
Thread.Sleep(delayBetween);
49-
50-
RotateImage ri = new RotateImage(fullScreenBitmap, DisplayFont);
48+
49+
SetPixels sp = new SetPixels(fullScreenBitmap, DisplayFont);
50+
Thread.Sleep(delayBetween);
51+
52+
FontExamples fe = new FontExamples(fullScreenBitmap);
53+
Thread.Sleep(delayBetween);
54+
55+
RandomRectangles rr = new RandomRectangles(fullScreenBitmap, DisplayFont);
56+
Thread.Sleep(delayBetween);
57+
58+
SliceScaling9 ss = new SliceScaling9(fullScreenBitmap, DisplayFont);
5159
Thread.Sleep(delayBetween);
5260

53-
RandomClipping rc = new RandomClipping(fullScreenBitmap, DisplayFont);
61+
RandomClipping rc = new RandomClipping(fullScreenBitmap, DisplayFont);
5462
Thread.Sleep(delayBetween);
5563

56-
MatrixRain mr = new MatrixRain(fullScreenBitmap, DisplayFont);
64+
MatrixRain mr = new MatrixRain(fullScreenBitmap);
5765
Thread.Sleep(Timeout.Infinite);
5866
}
5967
}

samples/GraphicsWpf/Primitives/Resource.Designer.cs renamed to samples/Graphics/Primitives/Resource.Designer.cs

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
using nanoFramework.Presentation.Media;
2+
using nanoFramework.UI;
3+
using System;
4+
5+
namespace Primitives.SimplePrimitives
6+
{
7+
public class BouncingBalls
8+
{
9+
struct Rectangle
10+
{
11+
public int X;
12+
public int Y;
13+
public int Width;
14+
public int Height;
15+
public Rectangle(int x, int y, int width, int height)
16+
{
17+
this.X = x;
18+
this.Y = y;
19+
this.Width = width;
20+
this.Height = height;
21+
}
22+
}
23+
struct Point { public int X; public int Y; };
24+
private Rectangle[] BallLocation;
25+
private Point[] BallVelocity;
26+
private Bitmap ScreenBitmap { get; set; }
27+
28+
public BouncingBalls(Bitmap fullScreenBitmap, Font DisplayFont)
29+
{
30+
ScreenBitmap = fullScreenBitmap;
31+
SetupBalls();
32+
33+
for (int iCount = 0; iCount < 180; iCount++)
34+
{
35+
MoveBalls();
36+
DrawBalls();
37+
}
38+
39+
}
40+
private void SetupBalls()
41+
{
42+
Random rand = new Random();
43+
const int num_balls = 12;
44+
int vx = 0;
45+
int vy = 0;
46+
47+
BallLocation = new Rectangle[num_balls];
48+
BallVelocity = new Point[num_balls];
49+
50+
for (int iBall = 0; iBall < num_balls; iBall++)
51+
{
52+
int width = rand.Next(3, 50);
53+
BallLocation[iBall] = new Rectangle
54+
{
55+
X = rand.Next(0, ScreenBitmap.Width - 2 * width),
56+
Y = rand.Next(0, ScreenBitmap.Height - 2 * width),
57+
Width = width,
58+
Height = width
59+
};
60+
// Setup 1/2 the balls with different speeds
61+
if (iBall % 2 == 0)
62+
{
63+
vx = rand.Next(2, 10);
64+
vy = rand.Next(2, 10);
65+
}
66+
else
67+
{
68+
vx = rand.Next(12, 25);
69+
vy = rand.Next(12, 25);
70+
}
71+
72+
// Setup random directions
73+
if (rand.Next(0, 2) == 0) vx = -vx;
74+
if (rand.Next(0, 2) == 0) vy = -vy;
75+
BallVelocity[iBall] = new Point { X = vx, Y = vy };
76+
}
77+
}
78+
79+
private void MoveBalls()
80+
{
81+
for (int ball_num = 0;
82+
ball_num < BallLocation.Length;
83+
ball_num++)
84+
{
85+
// Move the ball.
86+
int new_x = BallLocation[ball_num].X +
87+
BallVelocity[ball_num].X;
88+
int new_y = BallLocation[ball_num].Y +
89+
BallVelocity[ball_num].Y;
90+
if (new_x < 0)
91+
{
92+
BallVelocity[ball_num].X = -BallVelocity[ball_num].X;
93+
}
94+
else if (new_x + BallLocation[ball_num].Width > ScreenBitmap.Width)
95+
{
96+
BallVelocity[ball_num].X = -BallVelocity[ball_num].X;
97+
}
98+
if (new_y < 0)
99+
{
100+
BallVelocity[ball_num].Y = -BallVelocity[ball_num].Y;
101+
}
102+
else if (new_y + BallLocation[ball_num].Height > ScreenBitmap.Height)
103+
{
104+
BallVelocity[ball_num].Y = -BallVelocity[ball_num].Y;
105+
}
106+
107+
BallLocation[ball_num] = new Rectangle(new_x, new_y,
108+
BallLocation[ball_num].Width,
109+
BallLocation[ball_num].Height);
110+
}
111+
}
112+
113+
114+
private void DrawBalls()
115+
{
116+
ScreenBitmap.Clear();
117+
for (int i = 0; i < BallLocation.Length; i++)
118+
{
119+
ScreenBitmap.DrawEllipse(Color.Yellow, 1, BallLocation[i].X, BallLocation[i].Y, BallLocation[i].Width, BallLocation[i].Height,
120+
0, 0, 0, 0, 0, 0, Bitmap.OpacityOpaque);
121+
}
122+
ScreenBitmap.Flush();
123+
}
124+
}
125+
}
126+
127+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using nanoFramework.Presentation.Media;
2+
using nanoFramework.UI;
3+
using System;
4+
5+
namespace Primitives.SimplePrimitives
6+
{
7+
public class ColourGradient
8+
{
9+
public ColourGradient(Bitmap fullScreenBitmap, Font DisplayFont)
10+
{
11+
fullScreenBitmap.DrawRectangle(Color.White, // outline color
12+
1, // outline thickness
13+
100, 100, // x and y of top left corner
14+
200, 100, // width and height
15+
0, 0, // x and y corner radius
16+
Color.White, // gradient start color
17+
100, 100, // gradient start coordinates
18+
Color.Black, // gradient end color
19+
100 + 200, 100 + 100, // gradient end coordinates
20+
Bitmap.OpacityOpaque); // opacity
21+
fullScreenBitmap.Flush();
22+
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)