Skip to content

Commit 7c24af0

Browse files
authored
Update DisplayControl (#28)
1 parent c2fa1f9 commit 7c24af0

File tree

2 files changed

+43
-62
lines changed

2 files changed

+43
-62
lines changed

nanoFramework.Graphics/Primitive/DisplayControl.cs

Lines changed: 41 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
// See LICENSE file in the project root for full license information.
55
//
66

7-
using System;
87
using System.Runtime.CompilerServices;
98

109
namespace nanoFramework.UI
1110
{
1211
/// <summary>
13-
///
12+
/// Display orientation. No all display drivers support every orientation.
1413
/// </summary>
1514
public enum DisplayOrientation : int
1615
{
1716
/// <summary>
18-
/// Portrain
17+
/// Portrait
1918
/// </summary>
2019
PORTRAIT,
2120
/// <summary>
@@ -33,75 +32,58 @@ public enum DisplayOrientation : int
3332
};
3433

3534
/// <summary>
36-
///
35+
/// Display Control.
3736
/// </summary>
38-
public sealed class DisplayControl : MarshalByRefObject, IDisposable
37+
public static class DisplayControl
3938
{
39+
static Bitmap _fullScreen = null;
4040

41-
static DisplayControl dc;
42-
static DisplayControl()
43-
{
44-
dc = new DisplayControl();
45-
}
46-
47-
/// <summary>
48-
///
49-
/// </summary>
50-
public static int ScreenWidth
51-
{
52-
get
53-
{
54-
//return dc.Width;
55-
return 800;
56-
}
57-
}
58-
// Gets the height of the screen
5941
/// <summary>
60-
///
42+
/// Returns a bitmap the size of the current display.
6143
/// </summary>
62-
public static int ScreenHeight
44+
public static Bitmap FullScreen
6345
{
6446
get
6547
{
66-
//return dc.Height;
67-
return 480;
48+
if (_fullScreen == null)
49+
{
50+
_fullScreen = new Bitmap(ScreenWidth, ScreenHeight);
51+
}
52+
return _fullScreen;
6853
}
6954
}
7055

71-
72-
73-
7456
/// <summary>
75-
/// The screens number of pixel for the longer side.
57+
/// The screens number of pixels for the longer side.
7658
/// </summary>
77-
extern public int LongerSide
59+
extern static public int LongerSide
7860
{
7961
[MethodImplAttribute(MethodImplOptions.InternalCall)]
8062
get;
8163
}
8264

8365
/// <summary>
84-
/// The screens number of pixel for the shorter side.
66+
/// The screens number of pixels for the shorter side.
8567
/// </summary>
86-
extern public int ShorterSide
68+
extern static public int ShorterSide
8769
{
8870
[MethodImplAttribute(MethodImplOptions.InternalCall)]
8971
get;
9072
}
9173

9274
/// <summary>
93-
/// The screens number of pixel for the width based on the orientation.
75+
/// The displays number of pixel for the width based on the orientation.
9476
/// </summary>
95-
extern public int Width
77+
extern static public int ScreenWidth
9678
{
9779
[MethodImplAttribute(MethodImplOptions.InternalCall)]
9880
get;
9981
}
10082

10183
/// <summary>
102-
/// The screens number of pixel for the height based on the orientation.
84+
/// The displays number of pixel for the height based on the orientation.
10385
/// </summary>
104-
extern public int Height
86+
extern static public int ScreenHeight
10587
{
10688
[MethodImplAttribute(MethodImplOptions.InternalCall)]
10789
get;
@@ -110,45 +92,44 @@ extern public int Height
11092
/// <summary>
11193
/// Currently 16 bits in RBG565 format. ( There is some 1 bit code available but untested )
11294
/// </summary>
113-
extern public int BitsPerPixel
95+
extern static public int BitsPerPixel
11496
{
11597
[MethodImplAttribute(MethodImplOptions.InternalCall)]
11698
get;
11799
}
118100

119101
/// <summary>
120-
/// The orientation landscape, portrain
102+
/// Return the current display orientation landscape, portrait.
121103
/// </summary>
122-
extern public int Orientation
104+
extern static public DisplayOrientation Orientation
123105
{
124106
[MethodImplAttribute(MethodImplOptions.InternalCall)]
125107
get;
126108
}
127109

128110
/// <summary>
129-
///
130-
/// </summary>
131-
/// <param name="Orientation"></param>
132-
/// <returns></returns>
133-
[MethodImplAttribute(MethodImplOptions.InternalCall)]
134-
extern public bool ChangeOrientation(ref int Orientation);
135-
136-
/// <summary>
137-
/// Release resources
138-
/// </summary>
139-
/// <param name="disposing"></param>
140-
[MethodImplAttribute(MethodImplOptions.InternalCall)]
141-
extern private void Dispose(bool disposing);
142-
143-
/// <summary>
144-
///
111+
/// Change the orientation of the display.
145112
/// </summary>
146-
public void Dispose()
113+
/// <remarks>
114+
/// When the orientation is changed the display canvas is disposed and recreated with the new dimensions
115+
/// when DisplayControl.FullScreen is next called.
116+
/// </remarks>
117+
/// <param name="Orientation">New Orientation</param>
118+
/// <returns>True if the orientation was supported and changed.</returns>
119+
static public bool ChangeOrientation(DisplayOrientation Orientation)
147120
{
148-
this.Dispose(true);
149-
GC.SuppressFinalize(this);
121+
bool result = NativeChangeOrientation(Orientation);
122+
// if change happened then destroy bitmap as it needs to be recreated with new dimensions.
123+
if (result && _fullScreen != null)
124+
{
125+
_fullScreen.Dispose();
126+
_fullScreen = null;
127+
}
128+
return result;
150129
}
151130

131+
[MethodImplAttribute(MethodImplOptions.InternalCall)]
132+
private extern static bool NativeChangeOrientation(DisplayOrientation Orientation);
152133
}
153134
}
154135

nanoFramework.Graphics/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.InteropServices;
33

44
// General Information about an assembly is controlled through the following
@@ -11,7 +11,7 @@
1111

1212
////////////////////////////////////////////////////////////////
1313
// update this whenever the native assembly signature changes //
14-
[assembly: AssemblyNativeVersion("100.0.0.1")]
14+
[assembly: AssemblyNativeVersion("100.0.0.2")]
1515
////////////////////////////////////////////////////////////////
1616

1717
// Setting ComVisible to false makes the types in this assembly not visible

0 commit comments

Comments
 (0)