[9102] | 1 | ///
|
---|
| 2 | /// This file is part of ILNumerics Community Edition.
|
---|
| 3 | ///
|
---|
| 4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
| 5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
| 6 | ///
|
---|
| 7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
| 8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
| 9 | /// the Free Software Foundation.
|
---|
| 10 | ///
|
---|
| 11 | /// ILNumerics Community Edition is distributed in the hope that it will be useful,
|
---|
| 12 | /// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | /// GNU General Public License for more details.
|
---|
| 15 | ///
|
---|
| 16 | /// You should have received a copy of the GNU General Public License
|
---|
| 17 | /// along with ILNumerics Community Edition. See the file License.txt in the root
|
---|
| 18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | ///
|
---|
| 20 | /// In addition this software uses the following components and/or licenses:
|
---|
| 21 | ///
|
---|
| 22 | /// =================================================================================
|
---|
| 23 | /// The Open Toolkit Library License
|
---|
| 24 | ///
|
---|
| 25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
| 26 | ///
|
---|
| 27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
| 28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
| 29 | /// in the Software without restriction, including without limitation the rights to
|
---|
| 30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
| 31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
| 32 | /// so, subject to the following conditions:
|
---|
| 33 | ///
|
---|
| 34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
| 35 | /// copies or substantial portions of the Software.
|
---|
| 36 | ///
|
---|
| 37 | /// =================================================================================
|
---|
| 38 | ///
|
---|
| 39 |
|
---|
| 40 | using System;
|
---|
| 41 | using System.Collections.Generic;
|
---|
| 42 | using System.Text;
|
---|
| 43 | using System.Drawing;
|
---|
| 44 | using ILNumerics.Drawing.Graphs;
|
---|
| 45 | using ILNumerics.Drawing;
|
---|
| 46 | using ILNumerics.Drawing.Interfaces;
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | namespace ILNumerics.Drawing.Labeling {
|
---|
| 50 | /// <summary>
|
---|
| 51 | /// a label used for labeling shapes (screen coords, defined via world coords)
|
---|
| 52 | /// </summary>
|
---|
| 53 | public class ILShapeLabel : ILLabelingElement {
|
---|
| 54 |
|
---|
| 55 | #region attributes
|
---|
| 56 | ILPanel m_panel;
|
---|
| 57 | CoordSystem m_coordSystem;
|
---|
| 58 | Color m_fringeColor = Color.LightGray;
|
---|
| 59 | ILArray<int> m_fringeOffsets = ILMath.returnType<int>();
|
---|
| 60 | #endregion
|
---|
| 61 |
|
---|
| 62 | #region properties
|
---|
| 63 | /// <summary>
|
---|
| 64 | /// get/set the color used for drawing a fringe around glyphs, empty: no fringe
|
---|
| 65 | /// </summary>
|
---|
| 66 | public Color FringeColor {
|
---|
| 67 | get { return m_fringeColor; }
|
---|
| 68 | set { m_fringeColor = value; }
|
---|
| 69 | }
|
---|
| 70 | #endregion
|
---|
| 71 |
|
---|
| 72 | #region constructors
|
---|
| 73 | public ILShapeLabel(ILPanel panel) : base(panel, null, Color.Black) {
|
---|
| 74 | m_panel = panel;
|
---|
| 75 | m_coordSystem = CoordSystem.Screen;
|
---|
| 76 | m_anchor = new PointF(.5f,.5f); // TickLabelAlign.center | TickLabelAlign.vertCenter;
|
---|
| 77 | m_fringeOffsets.a = new int[,]{
|
---|
| 78 | { -1, -1 },
|
---|
| 79 | { -1, 0 },
|
---|
| 80 | { -1, 1 },
|
---|
| 81 | { 0, -1 },
|
---|
| 82 | { 0, 1 },
|
---|
| 83 | { 1, -1 },
|
---|
| 84 | { 1, 0 },
|
---|
| 85 | { 1, 1 }};
|
---|
| 86 | m_fringeOffsets.a = m_fringeOffsets.T;
|
---|
| 87 | }
|
---|
| 88 | public ILShapeLabel(ILPanel panel, CoordSystem coordSystem)
|
---|
| 89 | : base(panel, null, Color.Black) {
|
---|
| 90 | m_panel = panel;
|
---|
| 91 | m_coordSystem = CoordSystem.Screen;
|
---|
| 92 | m_anchor = new PointF(.5f, .5f); // TickLabelAlign.center | TickLabelAlign.vertCenter;
|
---|
| 93 | m_renderer.CacheCleared -= new EventHandler(m_renderer_CacheCleared);
|
---|
| 94 | m_renderer = panel.TextRendererManager.GetDefault(coordSystem);
|
---|
| 95 | m_renderer.CacheCleared += new EventHandler(m_renderer_CacheCleared);
|
---|
| 96 | m_fringeOffsets.a = new int[,]{
|
---|
| 97 | { -1, -1 },
|
---|
| 98 | { -1, 0 },
|
---|
| 99 | { -1, 1 },
|
---|
| 100 | { 0, -1 },
|
---|
| 101 | { 0, 1 },
|
---|
| 102 | { 1, -1 },
|
---|
| 103 | { 1, 0 },
|
---|
| 104 | { 1, 1 }};
|
---|
| 105 | m_fringeOffsets.a = m_fringeOffsets.T;
|
---|
| 106 | }
|
---|
| 107 | #endregion
|
---|
| 108 |
|
---|
| 109 | #region public interface
|
---|
| 110 | /// <summary>
|
---|
| 111 | /// (internal use)
|
---|
| 112 | /// </summary>
|
---|
| 113 | /// <param name="p">render properties</param>
|
---|
| 114 | /// <param name="center">center position for the label</param>
|
---|
| 115 | public void Draw(ILRenderProperties p, ILPoint3Df center ) {
|
---|
| 116 | if (!String.IsNullOrEmpty(Text)) {
|
---|
| 117 | if (m_expression != m_cachedExpression)
|
---|
| 118 | interprete(m_expression);
|
---|
| 119 | double[] modelview = null;
|
---|
| 120 | m_renderer.Begin(p, ref modelview);
|
---|
| 121 | Point dest = m_panel.World2Screen(center, modelview);
|
---|
| 122 | offsetAlignment(m_size, ref dest);
|
---|
| 123 | if (m_fringeColor.IsEmpty) {
|
---|
| 124 | m_renderer.Draw(m_renderQueue, dest, TextOrientation.Horizontal, m_color);
|
---|
| 125 | } else {
|
---|
| 126 | drawFringed(m_renderer, m_renderQueue, dest, TextOrientation.Horizontal, m_color);
|
---|
| 127 | }
|
---|
| 128 | m_renderer.End(p);
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /// <summary>
|
---|
| 133 | /// draws a fringe around the render output in fringe color
|
---|
| 134 | /// </summary>
|
---|
| 135 | /// <param name="m_renderer"></param>
|
---|
| 136 | /// <param name="m_rendererQueue"></param>
|
---|
| 137 | /// <param name="dest"></param>
|
---|
| 138 | /// <param name="textOrientation"></param>
|
---|
| 139 | /// <param name="m_color"></param>
|
---|
| 140 | private void drawFringed(IILTextRenderer m_renderer, object m_rendererQueue, Point dest, TextOrientation textOrientation, Color m_color) {
|
---|
| 141 | m_renderer.ColorOverride = m_fringeColor;
|
---|
| 142 | for (int i = 0; i < m_fringeOffsets.Size[0]; i++) {
|
---|
| 143 | m_renderer.Draw(m_renderQueue
|
---|
| 144 | , new Point(dest.X + m_fringeOffsets.GetValue(i,0), dest.Y + m_fringeOffsets.GetValue(i,1))
|
---|
| 145 | , TextOrientation.Horizontal, m_fringeColor);
|
---|
| 146 | }
|
---|
| 147 | m_renderer.ColorOverride = Color.Empty;
|
---|
| 148 | m_renderer.Draw(m_renderQueue, dest, TextOrientation.Horizontal, m_color);
|
---|
| 149 |
|
---|
| 150 | }
|
---|
| 151 | /// <summary>
|
---|
| 152 | /// (internal use)
|
---|
| 153 | /// </summary>
|
---|
| 154 | /// <param name="p">render properties</param>
|
---|
| 155 | /// <param name="min">minimum coord for label area</param>
|
---|
| 156 | /// <param name="max">maximum coord for label area</param>
|
---|
| 157 | public void Draw(ILRenderProperties p, ILPoint3Df min, ILPoint3Df max) {
|
---|
| 158 | if (!String.IsNullOrEmpty(Text)) {
|
---|
| 159 | if (m_expression != m_cachedExpression)
|
---|
| 160 | interprete(m_expression);
|
---|
| 161 | m_renderer.Begin(p);
|
---|
| 162 | m_renderer.Draw(m_renderQueue,min.X,min.Y,min.Z,max.X,max.Y,max.Z, m_color);
|
---|
| 163 | m_renderer.End(p);
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | #endregion
|
---|
| 167 | }
|
---|
| 168 | }
|
---|