M3系统升级到STM32F207后,主频提升为120M,运行WPF和System.Windows.Froms库基本上问题不大了,所以对原先的System.Windows.Froms库又进行了升级改进。
以前的System.Windows.Froms库主要模仿WINCE界面开发的,需要用触摸笔才能操作,目前这种操作方式早就淘汰了,所以为了支持手指直接操作,主要从以下几个方面入手进行了改造。
(1)、重新编写了软键盘,支持手指单击输入;
(2)、默认字体由原来的12变为16,为了便于操控,控件也进行了扩大处理;
(3)、去掉了任务栏;
(4)、去掉任务菜单;
(5)、窗体界面大小覆盖全屏;
System.Windows.Form目前包括Button、TextBox、ListBox、ComboBox、CheckBox、GroupBox、RadioButton、PictureBox、ProgressBar、VScrollBar、HScrollBar等11种常用控件,此外还提供了MessageBox方法,使用方法和Windows平台的winform保持一致。
包含两类窗体、普通窗体及模式窗体,含义和windows平台相同。
软键盘一共四个不同界面,通过上面的功能键进行切换。
目前还不支持中文输入。
Graphics类的声明如下:
public sealed class Graphics : Microsoft.SPOT.DispatcherObject, IDisposable
{
public bool EmptyClipRect;
publicGraphics(Bitmap bmp);
publicGraphics(int width, intheight);
public Bitmap Bitmap { get;}
public Rectangle Clip { get;set; }
public int Height { get; }
public int Width { get; }
public void BlendImage(Bitmapsource, int destinationX, int destinationY, intsourceX, int sourceY, intsourceWidth, int sourceHeight, ushort opacity);
public void Clear(Colorcolor);
public static SizeComputeTextExtent(string text, Font font);
public static SizeComputeTextExtent(string text, Font font, intavailableWidth);
public void Dispose();
public void DrawEllipse(Penpen, Rectangle rect);
public void DrawEllipse(Penpen, int x, inty, int width, intheight);
public void DrawImage(Bitmapimage, int x, inty);
public void DrawImage(Bitmapimage, int destinationX, int destinationY, intsourceX, int sourceY, intsourceWidth, int sourceHeight);
public void DrawLine(Penpen, int x0, inty0, ushort Data);
public void DrawLine(Penpen, int x0, inty0, int x1, inty1);
public void DrawPolygon(Penpen, Point[] points);
public void DrawPolygon(Penpen, Point[] points, bool Sealed);
public void DrawRectangle(Penpen, Rectangle rect);
public void DrawRectangle(Penpen, int x, inty, int width, intheight);
public void DrawRoundRect(Penpen, Rectangle rect, int rx, int ry);
public void DrawRoundRect(Penpen, int x, inty, int width, intheight, int rx, intry);
public void DrawString(strings, Font font, Brushbrush, Rectangle rect);
public void DrawString(strings, Font font, Brushbrush, int x, inty);
public void DrawString(strings, Font font, Brushbrush, Rectangle rect, StringFormat format);
public void FillEllipse(Brushbrush, Rectangle rect);
public void FillEllipse(Brushbrush, int x, inty, int width, intheight);
public void FillPolygon(Brushbrush, Point[] points);
public void FillRectangle(Brushbrush, Rectangle rect);
public void FillRectangle(Brushbrush, int x, inty, int width, intheight);
public void GetTranslation(outint x, out int y);
public void ResetClip();
public void RotateImage(intangle, int destinationX, int destinationY, Bitmapbitmap, int sourceX, intsourceY, int sourceWidth, int sourceHeight, ushortopacity);
public void Scale9Image(intxDst, int yDst, intwidthDst, int heightDst, Bitmap bitmap, intleftBorder, int topBorder, int rightBorder, intbottomBorder, ushort opacity);
public void SetPixel(Colorcolor, int x, inty);
public void StretchImage(intxDst, int yDst, intwidthDst, int heightDst, Bitmap bitmap, intxSrc, int ySrc, intwidthSrc, int heightSrc, ushort opacity);
public void TileImage(intxDst, int yDst, Bitmapbitmap, int width, intheight, ushort opacity);
public void Translate(intdx, int dy);
}
由于.Net Micro Framework的IDE开发环境并不支持所见即所得的窗体设计功能,所以我们可以用.Net Framework和.Net Compact Framework开发环境设计窗体,然后把相关窗体文件(如Form1.cs和Form1.designer.cs文件)直接导入到.Net Micro Framework工程中,稍加删减即可为.Net Micro Framework所用。
(window 控件的字体可以设置为:字体"Arial" 大小11.25F,这种字体和底层设备的字体大小比较接近 )
由于字体文件相对较大,所以YFSoft.Font库文件是全开源的,用户可以根据需要自行定义字体,设置好进行编译,替换系统所提供的YFSoft.Font.*文件即可。
public Font(string name, float emSize, FontStylestyle)
{
switch(this._name)
{
default:
case"Arial":
switch(style)
{
//case FontStyle.Bold:
//_value = YFResource.GetFont(YFResource.FontResources.YFArial16B);
//break;
default:
case FontStyle.Regular:
_value = YFResource.GetFont(YFResource.FontResources.YFArial16);
break;
}
break;
}
this._size = emSize;
this._style= style;
}
根据需要上述代码进行必要的调整,理论上可以支持任意字体了。
(1)、采用组态软件进行界面设计,并自动生成界面相关的代码。
(2)、再扩展几个工业用控件,比如动态曲线,表格,仪表盘显示等等。
从演示效果上看,添加比较多的控件,性能还不尽人意。不过这是基于STM32F207(主频120M)测试的,后续采用STM32F407(主频168M)的芯片,性能会有比较大的改善(当然本框架从软件角度还会继续进行性能优化),想以前在STM32F103(主频72M)芯片上,这个框架根本跑步起来。期待ST推出性能更强大的Cortex-M3或Cortex-M4芯片。
<a href="http://weibo.com/1804832611?s=6uyXnP"></a>