精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。
This library lets you manipulate graphic objects in your app at runtime.
这个库允许您在你的应用程序在运行时操作图形对象。
Sometime ago, I read that someone had asked for a way to drag items over a panel. Since I had the same problem (all began with the designer of MyNeoReport project) I tried to solve this in a generic way, so that the system could be used in different applications without efforts.
不久以前,我读到有人要求在面板拖动图形部分的方法。因为我有同样的问题(所有始于MyNeoReport项目的设计师)我试图用一个通用的方式来解决这个问题,这样,该系统能够轻松的在不同的应用中使用。
AGE supports items dragging, snap-to-grid, multiselection, layers and much more.AGE支持项目拖动,捕捉网格,多项选择,图层等等。
AGE is growing fast; if I were you I would keep an eye on this project. AGE发展迅速;如果我是你,我会继续关注这个项目。
GraphicItem: The item to be drawn GraphicItem:该项目绘制出图形。
Painter: The class that does the "dirty work" of painting Painter:实现绘制“脏活”的类
GraphicDocument: The class that collects all the items to be drawn on a single surface GraphicDocument:收集管理所有的图形,实现在一个单独面板上显示。
Canvas: The control that shows the drawing Canvas:控制显示绘图
Q: Why do I need an RendererBase and why don't I put the Render() method directly to the GraphicItem class? 问:为什么我需要一个RendererBase,为什么不直接把Render()方法用到GraphicItem类中?
A: Because I need more abstraction. 答:因为我要让它更抽象。
In this way I separate the logical item from the actor of the rendering. 这样我可以把这个项目合理的从渲染行为里分离出来。
I can virtually have the same renderer for different items or I can choose a different renderer for a single item. 我有相同的渲染器适合于不同的项目或我可以为一个单独的项目选择不同的渲染器。
Q: Why is the GraphicDocument a separate class from Canvas? I could add all the items to draw directly to the Canvas. 问:为什么Canvas和GraphicDocument是一个分享的类?我可以直接在画布上绘制添加所有项目。
A: Same reason of the first question: the GraphicDocument is the logical items aggregation, it is the document, the canvas is the surface on which the document is drawn. 答:第一个问题同样的原因:GraphicDocument是合理的项目聚集,,这是文档,画布是文档绘制的表面。
And again, in this way, I could have the same document open on more canvas. 再一次,这样,我可以有相同的文档支持多个打开的画布。
Ok, Let's Start... How Does It Work? 好的,让我们开始…它是如何工作的呢?
Q: How can I make my own graphic document? 问:我如何能制作自己的GraphicDocument?
A: Ok, let's define a complete new custom document: 答:好的,让我们来定义一个完整的新的自定义文档:
class CustomDocument : GraphicDocument { // define here your document properties } // define a custom item: an ellipse. class Ellipse : GraphicItem { Color _foreColor = Color.Blue; public Ellipse() { Painter = new EllipsePainter(); } public Color ForeColor { get{ return _foreColor; } set{ _foreColor = value; } } } // define the ellipse painter class EllipsePainter : Painter { // how the ellipse is painted... protected override void Paint(Graphics g) { Ellipse ellipse = (Ellipse)Item; Pen pen = new Pen(ellipse.ForeColor); g.DrawEllipse(pen, Item.Bounds);
pen.Dispose(); } } ...
canvas1.Document = new CustomDocument();
// add a new ellipse to the default layer
canvas1.Document.AddItem(new Ellipse());
From release 1.4.0.0, you can also use ScriptAge to define your custom graphic item at runtime: 从版本1.4.0.0,您还可以在运行时使用ScriptAge自定义图形项:
ScriptedItem triangle = new ScriptedItem(); // Of course: it doesn't make much sense to hard code the script :) // Rather you would load it from a separate text file or a string resource. triangle.Script = "stroke: Polygon\n", "pen: #7070ff, 2!\n", "brush: gradient, #0000ff, #000000ff, (0; 0.5) (1; 1)\n", "points: (0; 0.5) (1; 0.0) (1; 1)\n"