Microsoft Robotics Pad GUI服务(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/microsoft-robotics-pad-gui-service-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 4 分钟阅读 - 1893 个词 阅读量 0Microsoft Robotics Pad GUI服务(译文)
原文地址:https://www.codeproject.com/Articles/20407/Microsoft-Robotics-Pad-GUI-Service
原文作者:Pedro77
译文由本站 robot-v1.0 翻译
前言
An article to create a game pad graphic user interface service that will use Microsoft Robotics Environment
创建使用Microsoft Robotics Environment的游戏手柄图形用户界面服务的文章
介绍(Introduction)
在里面(In the) 上一篇文章(previous article) ,我们创建了游戏手柄服务.在这里,我们将创建另一个服务,该服务将提供有关打击垫的图形反馈.即使是本文,也请记住,这不是(, we created a game pad service. Here, we will create another service that will provide graphical feedback about the pad. Even for this article, remember that this is not a) CCR(CCR) 或一个(or a) DSS(DSS) 教程,并且对这些技术有很好的了解将非常有用.在本文中,我假设您知道什么是消息,队列和服务.我还将跳过与先前服务相似的所有操作:服务创建,消息定义和消息处理.(tutorial, and a good knowledge of these technologies will be very useful. In this article, I assume you know what messages, queues and services are. I will also skip all the actions that are similar to the previous service: service creation, message definition and message handling.) 基本思想是:GUI服务可以接收某些类型的消息,并且在相应的消息处理程序中,对UI表单元素进行了修改.(The base idea is this: the GUI service can receive some kinds of messages and in the corresponding message handlers, the UI forms elements are modified.)
建筑(Architecture)
我决定创建服务,而不是修改(I decided to create a service rather than modify the) 便笺簿服务(pad service) 避免紧耦合模块. GUI服务始终比单个表单更可重用.它还可以用于处理不同的硬件,例如操纵杆.关于消息的几句话:在这里,服务被定义为(form to avoid tight coupling modules. A GUI service is always more reusable than a single form. It can also be used to handle different hardwares such as a joystick. Few words about messages: in this, services are defined as)所有(ALL)Pad服务消息,以便我们在两个服务消息之间具有1对1的关系.我认为这与" Pad Service"无关,因为消息定义非常抽象.请记住,此服务假定棍子范围在(the Pad service messages so that we have a 1 to 1 relationship between the two services messages. I don’t think this is a coupling to “Pad Service” because the message definition is quite abstract. Remember that this service assumes that stick ranges are in) [-1,1]
.请记住,服务消息具有相同的类名,但在两个不同的名称空间中定义.(. Remember that Service Messages have the same class name but are defined inside two different namespaces.)
图形用户界面(The GUI)
该解决方案有两个项目:(The Solution has two projects:)
Pad.Controls
:包含一个简单的尺规用户控件(: contains a simple stick gauge user control)PadGui
:带有消息定义和主要形式的服务.(: the service with messages definitions and the main form.) 主窗体具有两个控制杆控件和4个标签,当按下按钮时这些标签将变为红色.我们还有一个"关于"框.在主窗体内,声明了几个属性以处理填充状态.在 - 的里面(The main form has two stick controls and 4 labels which will be red when a button is pressed. We also have an About box. Inside the main form, several properties are declared to handle pad state. Inside the)StickGauge
类,定义了两个属性来处理(class, two properties are defined to handle)x
和(and)y
棍子位置.每当值更改时,(stick position. Whenever the values change, an)Invalidate()
被执行,相应的(is performed and the corresponding)OnPaint
代码如下:(code is as follows:)
private void panelPainter_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(
new Pen(Brushes.Red), 5, 5, panelPainter.Width - 10,
panelPainter.Height - 10);
e.Graphics.FillEllipse(
Brushes.Red,
panelPainter.Width / 2 - 5, panelPainter.Height / 2 - 5, 10f, 10f);
int x = Convert.ToInt32((_x + 1) * panelPainter.Width / 2);
int y = Convert.ToInt32((_y + 1) * panelPainter.Height / 2);
e.Graphics.FillEllipse(Brushes.Blue, x - 5, y - 5, 10, 10);
e.Graphics.DrawCurve(new Pen(Brushes.Blue),
new Point[]{
new Point(panelPainter.Width/2,0),
new Point(x,y),
new Point(panelPainter.Width/2,panelPainter.Height),
});
e.Graphics.DrawCurve(new Pen(Brushes.Blue),
new Point[]{
new Point(0,panelPainter.Height/2),
new Point(x,y),
new Point(panelPainter.Width,panelPainter.Height/2),
});
txtXY.Text = string.Format("X({0})
Y({1})",Math.Round(_x,4),Math.Round(_y,4));
}
这并不是真正令人惊奇的图形体验,但是拥有设备反馈是完美的.(This is not a really amazing graphic experience, but it is perfect to have device feedback.)
服务(The service)
在服务启动阶段,我使用此代码段启动一个Window.记住要添加对程序集的引用(Inside the service startup phase, I use this snippet to start a Window. Remember to add a reference to the assembly)Ccr.Adapters.WinForms.dll(Ccr.Adapters.WinForms.dll):(:)
using Microsoft.Ccr.Adapters.WinForms;
...
//Create Form
PadInfoForm _form = new PadInfoForm();
WinFormsServicePort.Post(new RunForm(
delegate()
{
return _form;
}
));
每当收到消息时,我们都会执行以下操作:(And whenever a message is received, we perform the following actions:)
[ServiceHandler(ServiceHandlerBehavior.Exclusive)]
public IEnumerator<ITask> RightStickUpdateHandler(RightStickUpdate rsUpd)
{
_form.RX = rsUpd.Body.Stick.StickValueX;
_form.RY = rsUpd.Body.Stick.StickValueY;
rsUpd.ResponsePort.Post(DefaultUpdateResponseType.Instance);
yield break;
}
分配给表单属性会导致操纵杆更新.(The assignment to form property causes the stick update.)
结论(Conclusion)
如果您要询问谁将消息通知给GUI服务,那么您将走在正确的道路上.在这里,我们创建了一个(If you are asking who notifies messages to the GUI Service, you are on the right path. Right here, we created an) 主动服务(Active Service) 将通知发送到其他服务.相反,此服务类似于"被动服务".它仅接收消息,以便我们可以编译和运行该服务,但是只要不向该服务发送消息,我们就不会收到任何反馈.这是我将写的下一篇文章的目的.我将使用VPL连接Pad服务和Pad GUI服务.该服务的下一个改进将是WPF接口.(that sends notifications to other services. This service instead is something like a “Passive Service”. It receives only messages so that we can compile and run this service but we won’t get any feedback as long as we don’t send messages to this service. This is the aim of the next article that I’ll write. I will use VPL to connect the pad service and the pad GUI service. The next improvement for this service will be a WPF Interface.) 而已!(That’s it!)
历史(History)
- 2007年9月:第一版(September 2007: First release)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# C#2.0 WinXP Windows .NET .NET2.0 Visual-Studio VS2005 Dev 新闻 翻译