绘制互动元素的基于节点接口用C# [英] Drawing interactive elements for a Node-Based-Interface with C#

查看:362
本文介绍了绘制互动元素的基于节点接口用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这个问题不是使用一些预制库,所以它不是一个公开的实现基于节点的图形界面?






尝试使像Autodesk 3DS MAX这样的基于节点的界面在材质编辑器中使用:





到目前为止,我有一些简单的图形(.png) line algorythm(Cubic Bezier Curve)



到目前为止,所有的逻辑,类和一些其他代码都是70%,但我想知道什么是 在C#WinForm中实现基于节点的接口的方式。



我想过使用OpenGL或XNA(Direct3D),但后来我认为这将是一个



下一个WPF进入我的想法,但我没有使用WPF这样的东西,所以我不知道如果这将是可行的,也在性能上很好。



如果,我能够拖动每个节点?我可以使用绘制的图形注册点击和拖动事件吗?



我想能够让用户创建节点,给它们提供属性和值,连接节点并拖动它们在WinForm的滚动区域(如在容器中)



好,你的建议是什么?从哪里开始?该怎么办 ?



这里是一个简单的(图形)结构的例子我想要做的节点:$ b​​ $ b



你可以看到,我想在节点内有按钮,或其他用户控制的元素,如开关或东西像一个调光器。注意,这个图像只是为了显示我想要如何结构的节点和每个矩形。



所以每个矩形应该有自己的属性
= true / false,connectedNode =node_id)
以及它自己的鼠标事件,我想将所有矩形分组到一个代表一个节点的对象。



所以我的问题是:我如何绘制一个控制元素像面板?矩形?
(最好的情况下,我想使用.png的主矩形和连接器矩形,而不是绘制纯颜色重新排列)






UPDATE:
什么是system.drawing类?我可以简单地绘制成一个面板元素?

$ p

解决方案

你应该能够找到一个自定义Winforms用户控件的鼠标向上和鼠标事件可以响应。从中你应该能够实现点击和拖动(鼠标点击的控制相对位置通常在事件结构中传递)并从那里去。



I开始写一个能够拖动单个对象并从中移动的小型原型 - 尝试几种不同的方式,看看什么是可以理解的,干净的。



你已经可以开始设计一个类设置;你可能想把一些常用的拖放代码放在一个实现边界框和类似的基类中,然后创建一个要绘制的对象/节点/线的列表及其关联。只是慢慢地建立你的方式;不要一次性构建整个事物。


NOTE: this question is not about using some premade libarys, so it's propably not a dublicate of Implementing a node-based graphical interface?


I'm trying to make a Node-Based-Interface like Autodesk 3DS MAX uses in the Material Editor :

so far i have some simple graphics ( .png ) for some nodes and i just finished the curved-line algorythm ( Cubic Bezier Curve )

All the logics, Classes and some other code are made 70 % till now, but i'm wondering what exactly would be the "right" way of implementing the Node Based Interface in a C# WinForm.

I've thought of using OpenGL or XNA ( Direct3D ), but then i thought that this would be a kind of too much for the purpose.

Next WPF came into my mind, but i've not worked with WPF for things like this anyway, so i've no idea if this would be makable and also nice in performance.

cuestions like, would i be able to drag around each nodes ? could i be able to register click and drag events with drawed graphics ?

I would like to be able to let the user create nodes, give them proppertys and values, connect the nodes and drag them arround in a scrolling area of the WinForm ( like in a container )

well, what are your suggestions ? where to begin ? what to do ? and maybe any examples or reference ?


EDIT:

here is an simple ( graphical ) example of the structure for the nodes i'm trying to make:

as you can see, i want to have buttons inside a node, or other user controled elements like switches or something like a dimmer. note that this image is only for showing how i want to structure the nodes and each "rectangle".

so each rectangle should have it's own propertys ( signal = true / false , connectedNode = "node_id" ) and also it's own mouse events, i want to group all there rectangles to an object that will represent a node.

so my question is: HOW can i draw the rectangles inside a Control Element like a "Panel" ? ( im best case i would like to use .png's for the main rectangle and for the connector-rectangles instead of drawing plain color recrangles )


UPDATE: what is with the system.drawing class ? can i simply draw into a "Panel" element ? and what is with the dragability ?

解决方案

You should be able to find mouse up and mouse down events that a custom Winforms user control can respond to. From that you should be able to implement click and drag (the control-relative position of the mouse click is usually passed in the event structure) and go from there.

I'd start by writing a small prototype of being able to drag around a single object and go from there - try a few different ways, see what's understandable and clean.

After you've got that you could start designing a class setup; you'll probably want to put a lot of your common drag/drop code in a base class that implements bounding boxes and similar, then create a list of objects/nodes/lines to draw and their associations. Just build your way up slowly; don't plan to build the entire thing in one shot.

这篇关于绘制互动元素的基于节点接口用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆