| 32 | | public class RenderableGeometry |
| 33 | | { |
| 34 | | private Pen m_pen; |
| 35 | | private string m_label; |
| 36 | | private LabelFormat m_labelFormat; |
| 37 | | |
| 38 | | public Pen LinePen |
| 39 | | { |
| 40 | | get |
| | 32 | public class RenderableGeometry |
| | 33 | { |
| | 34 | private Pen m_pen; |
| | 35 | private string m_label; |
| | 36 | private LabelFormat m_labelFormat; |
| | 37 | |
| | 38 | public Pen LinePen |
| | 39 | { |
| | 40 | get |
| | 41 | { |
| | 42 | return m_pen; |
| | 43 | } |
| | 44 | set |
| | 45 | { |
| | 46 | m_pen = value; |
| | 47 | } |
| | 48 | } |
| | 49 | |
| | 50 | public string Label |
| | 51 | { |
| | 52 | get |
| | 53 | { |
| | 54 | return m_label; |
| | 55 | } |
| | 56 | set |
| | 57 | { |
| | 58 | m_label = value; |
| | 59 | } |
| | 60 | } |
| | 61 | |
| | 62 | public LabelFormat Format |
| | 63 | { |
| | 64 | get |
| | 65 | { |
| | 66 | return m_labelFormat; |
| | 67 | } |
| | 68 | set |
| | 69 | { |
| | 70 | m_labelFormat = value; |
| | 71 | } |
| | 72 | } |
| | 73 | |
| | 74 | //perhaps this method should be in SharedDotNetUtils |
| | 75 | public static uint Argb2Abgr(Color color) |
| | 76 | { |
| | 77 | uint colorArgb = (uint)(color.ToArgb()); |
| | 78 | // we don't set the alpha here because FvMappingGraphicsCom doesn't support alpha blending |
| | 79 | uint colorAbgr = |
| | 80 | ((colorArgb & 0x000000ff) << 16)//blue moves left |
| | 81 | + (colorArgb & 0x0000ff00)//green stays in place |
| | 82 | + ((colorArgb & 0x00ff0000) >> 16);//red moves right |
| | 83 | return colorAbgr; |
| | 84 | } |
| | 85 | |
| | 86 | public static void DrawText(Graphics graphics, int x, int y, string label, LabelFormat format) |
| | 87 | { |
| | 88 | if (label != null) |
| | 89 | { |
| | 90 | DrawText(label, |
| | 91 | x + format.displacement.X, |
| | 92 | y + format.displacement.Y, |
| | 93 | format.anchor_pos, |
| | 94 | format.fontName, |
| | 95 | format.fontSize, |
| | 96 | format.font_attrib, |
| | 97 | format.background, |
| | 98 | format.color, |
| | 99 | format.bkcolor, |
| | 100 | format.angle, |
| | 101 | graphics); |
| | 102 | } |
| | 103 | } |
| | 104 | |
| | 105 | public static void DrawText( |
| | 106 | string Text, // text to draw |
| | 107 | int x, int y, // screen x,y position |
| | 108 | int anchor_pos, // reference position of text |
| | 109 | string Fontname, // font name |
| | 110 | int font_size, // font size in points |
| | 111 | int font_attrib, // font attributes (bold, italic, etc) |
| | 112 | int background, // background type |
| | 113 | Color color, // RGB for text color |
| | 114 | Color bkcolor, // RGB for background color |
| | 115 | double angle, // angle of text |
| | 116 | Graphics graphics) |
| | 117 | { |
| | 118 | SharedDotNetUtils.FVGraphicsWrapper.Point[] cpt = new FVGraphicsWrapper.Point[4]; |
| | 119 | IntPtr hdc = graphics.GetHdc(); |
| | 120 | try |
| | 121 | { |
| | 122 | |
| | 123 | SharedDotNetUtils.FVGraphicsWrapper.draw_text_RGB( |
| | 124 | hdc, |
| | 125 | Text, |
| | 126 | x, y, anchor_pos, Fontname, font_size, font_attrib, |
| | 127 | background, Argb2Abgr(color), Argb2Abgr(bkcolor), |
| | 128 | angle, cpt, 1); |
| | 129 | graphics.ReleaseHdc(hdc); |
| | 130 | return; |
| | 131 | } |
| | 132 | catch (Exception ex) |
| | 133 | { |
| | 134 | LoggingUtils.ReportError(ex); |
| | 135 | graphics.ReleaseHdc(hdc); |
| | 136 | } |
| | 137 | // Fall back To GDI+ |
| | 138 | |
| | 139 | GraphicsPath pth = new GraphicsPath(); |
| | 140 | |
| | 141 | //Add a string |
| | 142 | pth.AddString(Text, |
| | 143 | new FontFamily(Fontname), |
| | 144 | font_attrib, |
| | 145 | font_size, |
| | 146 | new PointF((float)x, (float)y), |
| | 147 | StringFormat.GenericTypographic); |
| | 148 | |
| | 149 | // draw the text |
| | 150 | graphics.FillPath(new SolidBrush(color), pth); |
| | 151 | |
| | 152 | //Select the pen |
| | 153 | Pen p = new Pen(bkcolor, 1.0f); |
| | 154 | //draw the hollow outlined text |
| | 155 | graphics.DrawPath(p, pth); |
| | 156 | pth.Reset(); |
| | 157 | p.Dispose(); |
| | 158 | pth.Dispose(); |
| | 159 | } |
| | 160 | |
| | 161 | |
| | 162 | public static bool PointRenderable(ISettableMapProj settableMapProj, |
| | 163 | double lat, double lon, |
| | 164 | double northBound, double southBound, |
| | 165 | double westBound, double eastBound, |
| | 166 | bool wrap, |
| | 167 | out int x, out int y) |
| | 168 | { |
| | 169 | int result; |
| | 170 | settableMapProj.geo_in_surface(lat, lon, out result); |
| | 171 | if (result != 0) |
| | 172 | { |
| | 173 | return GeometrySegmentEnumerator.TranslateWorldToScreen( |
| | 174 | settableMapProj, lat, lon, |
| | 175 | northBound, southBound, |
| | 176 | westBound, eastBound, |
| | 177 | wrap, |
| | 178 | out x, |
| | 179 | out y); |
| | 180 | } |
| | 181 | //must assign values |
| | 182 | x = 0; |
| | 183 | y = 0; |
| | 184 | return false; |
| | 185 | } |
| | 186 | |
| | 187 | public static void Render(GeometrySegmentEnumerator enumerator, |
| | 188 | int hdc, int attribDc, float lineWidth, |
| | 189 | IGraphicsUtilities utilities) |
| | 190 | { |
| | 191 | LineSegmentRenderer renderer = new LineSegmentRendererClass(); |
| | 192 | utilities.GetLineSegmentRenderer(ref renderer); |
| | 193 | |
| | 194 | enumerator.Wrap = false; |
| | 195 | renderer.Render(ref hdc, ref attribDc, enumerator, lineWidth); |
| | 196 | enumerator.Wrap = true; |
| | 197 | renderer.Render(ref hdc, ref attribDc, enumerator, lineWidth); |
| | 198 | } |
| | 199 | |
| | 200 | public virtual void RenderLabel( |
| | 201 | Graphics graphics, ISettableMapProj settableMapProj, |
| | 202 | double lat, double lon, |
| | 203 | double northBound, double southBound, |
| | 204 | double westBound, double eastBound) |
| | 205 | { |
| | 206 | RenderLabel(graphics, settableMapProj, lat, lon, northBound, southBound, westBound, eastBound, false); |
| | 207 | RenderLabel(graphics, settableMapProj, lat, lon, northBound, southBound, westBound, eastBound, true); |
| | 208 | } |
| | 209 | |
| | 210 | public virtual void RenderLabel( |
| | 211 | Graphics graphics, ISettableMapProj settableMapProj, |
| | 212 | double lat, double lon, |
| | 213 | double northBound, double southBound, |
| | 214 | double westBound, double eastBound, |
| | 215 | bool wrap) |
| | 216 | { |
| | 217 | int x, y; |
| | 218 | |
| | 219 | if (Label != null) |
| | 220 | { |
| | 221 | if (PointRenderable(settableMapProj, lat, lon, |
| | 222 | northBound, southBound, |
| | 223 | westBound, eastBound, |
| | 224 | wrap, |
| | 225 | out x, out y)) |
| 44 | | set |
| 45 | | { |
| 46 | | m_pen = value; |
| 47 | | } |
| 48 | | } |
| 49 | | |
| 50 | | public string Label |
| 51 | | { |
| 52 | | get |
| 53 | | { |
| 54 | | return m_label; |
| 55 | | } |
| 56 | | set |
| 57 | | { |
| 58 | | m_label = value; |
| 59 | | } |
| 60 | | } |
| 61 | | |
| 62 | | public LabelFormat Format |
| 63 | | { |
| 64 | | get |
| 65 | | { |
| 66 | | return m_labelFormat; |
| 67 | | } |
| 68 | | set |
| 69 | | { |
| 70 | | m_labelFormat = value; |
| 71 | | } |
| 72 | | } |
| 73 | | |
| 74 | | //perhaps this method should be in SharedDotNetUtils |
| 75 | | public static uint Argb2Abgr(Color color) |
| 76 | | { |
| 77 | | uint colorArgb = (uint)(color.ToArgb()); |
| 78 | | |
| 79 | | uint colorAbgr = |
| 80 | | ((colorArgb & 0x000000ff) << 16)//blue moves left |
| 81 | | + (colorArgb & 0x0000ff00)//green stays in place |
| 82 | | + ((colorArgb & 0x00ff0000) >> 16);//red moves right |
| 83 | | return colorAbgr; |
| 84 | | } |
| 85 | | |
| 86 | | |
| 87 | | |
| 88 | | public static void DrawText(Graphics graphics, int x, int y, string label, LabelFormat format) |
| 89 | | { |
| 90 | | if (label != null) |
| 91 | | { |
| 92 | | DrawText(label, |
| 93 | | x + format.displacement.X, |
| 94 | | y + format.displacement.Y, |
| 95 | | format.anchor_pos, |
| 96 | | format.fontName, |
| 97 | | format.fontSize, |
| 98 | | format.font_attrib, |
| 99 | | format.background, |
| 100 | | format.color, |
| 101 | | format.bkcolor, |
| 102 | | format.angle, |
| 103 | | graphics); |
| 104 | | } |
| 105 | | } |
| 106 | | |
| 107 | | public static void DrawText( |
| 108 | | string Text, // text to draw |
| 109 | | int x, int y, // screen x,y position |
| 110 | | int anchor_pos, // reference position of text |
| 111 | | string Fontname, // font name |
| 112 | | int font_size, // font size in points |
| 113 | | int font_attrib, // font attributes (bold, italic, etc) |
| 114 | | int background, // background type |
| 115 | | Color color, // RGB for text color |
| 116 | | Color bkcolor, // RGB for background color |
| 117 | | double angle, // angle of text |
| 118 | | Graphics graphics) |
| 119 | | { |
| 120 | | SharedDotNetUtils.FVGraphicsWrapper.Point[] cpt = new FVGraphicsWrapper.Point[4]; |
| 121 | | IntPtr hdc = graphics.GetHdc(); |
| 122 | | try |
| 123 | | { |
| 124 | | |
| 125 | | SharedDotNetUtils.FVGraphicsWrapper.draw_text_RGB( |
| 126 | | hdc, |
| 127 | | Text, |
| 128 | | x, y, anchor_pos, Fontname, font_size, font_attrib, |
| 129 | | background, Argb2Abgr(color), Argb2Abgr(bkcolor), |
| 130 | | angle, cpt, 1); |
| 131 | | graphics.ReleaseHdc(hdc); |
| 132 | | return; |
| 133 | | } |
| 134 | | catch (Exception ex) |
| 135 | | { |
| 136 | | LoggingUtils.ReportError(ex); |
| 137 | | graphics.ReleaseHdc(hdc); |
| 138 | | } |
| 139 | | // Fall back To GDI+ |
| 140 | | |
| 141 | | GraphicsPath pth = new GraphicsPath(); |
| 142 | | |
| 143 | | //Add a string |
| 144 | | pth.AddString(Text, |
| 145 | | new FontFamily(Fontname), |
| 146 | | font_attrib, |
| 147 | | font_size, |
| 148 | | new PointF((float)x, (float)y), |
| 149 | | StringFormat.GenericTypographic); |
| 150 | | |
| 151 | | // draw the text |
| 152 | | graphics.FillPath(new SolidBrush(color), pth); |
| 153 | | |
| 154 | | //Select the pen |
| 155 | | Pen p = new Pen(bkcolor, 1.0f); |
| 156 | | //draw the hollow outlined text |
| 157 | | graphics.DrawPath(p, pth); |
| 158 | | pth.Reset(); |
| 159 | | p.Dispose(); |
| 160 | | pth.Dispose(); |
| 161 | | } |
| 162 | | |
| 163 | | |
| 164 | | public static bool PointRenderable(ISettableMapProj settableMapProj, |
| 165 | | double lat, double lon, |
| 166 | | double northBound, double southBound, |
| 167 | | double westBound, double eastBound, |
| 168 | | bool wrap, |
| 169 | | out int x, out int y) |
| 170 | | { |
| 171 | | int result; |
| 172 | | settableMapProj.geo_in_surface(lat, lon, out result); |
| 173 | | if (result != 0) |
| 174 | | { |
| 175 | | return GeometrySegmentEnumerator.TranslateWorldToScreen( |
| 176 | | settableMapProj, lat, lon, |
| 177 | | northBound, southBound, |
| 178 | | westBound, eastBound, |
| 179 | | wrap, |
| 180 | | out x, |
| 181 | | out y); |
| 182 | | } |
| 183 | | //must assign values |
| 184 | | x = 0; |
| 185 | | y = 0; |
| 186 | | return false; |
| 187 | | } |
| 188 | | |
| 189 | | public static void Render(GeometrySegmentEnumerator enumerator, |
| 190 | | int hdc, int attribDc, float lineWidth, |
| 191 | | IGraphicsUtilities utilities) |
| 192 | | { |
| 193 | | LineSegmentRenderer renderer = new LineSegmentRendererClass(); |
| 194 | | utilities.GetLineSegmentRenderer(ref renderer); |
| 195 | | |
| 196 | | enumerator.Wrap = false; |
| 197 | | renderer.Render(ref hdc, ref attribDc, enumerator, lineWidth); |
| 198 | | enumerator.Wrap = true; |
| 199 | | renderer.Render(ref hdc, ref attribDc, enumerator, lineWidth); |
| 200 | | } |
| 201 | | |
| 202 | | public virtual void RenderLabel( |
| 203 | | Graphics graphics, ISettableMapProj settableMapProj, |
| 204 | | double lat, double lon, |
| 205 | | double northBound, double southBound, |
| 206 | | double westBound, double eastBound) |
| 207 | | { |
| 208 | | RenderLabel(graphics, settableMapProj, lat, lon, northBound, southBound, westBound, eastBound, false); |
| 209 | | RenderLabel(graphics, settableMapProj, lat, lon, northBound, southBound, westBound, eastBound, true); |
| 210 | | } |
| 211 | | |
| 212 | | public virtual void RenderLabel( |
| 213 | | Graphics graphics, ISettableMapProj settableMapProj, |
| 214 | | double lat, double lon, |
| 215 | | double northBound, double southBound, |
| 216 | | double westBound, double eastBound, |
| 217 | | bool wrap) |
| 218 | | { |
| 219 | | int x, y; |
| 220 | | |
| 221 | | if (Label != null) |
| 222 | | { |
| 223 | | if (PointRenderable(settableMapProj, lat, lon, |
| 224 | | northBound, southBound, |
| 225 | | westBound, eastBound, |
| 226 | | wrap, |
| 227 | | out x, out y)) |
| 228 | | { |
| 229 | | DrawText(graphics, x, y, Label, Format); |
| 230 | | } |
| 231 | | } |
| 232 | | } |
| 233 | | |
| 234 | | public virtual void RenderLabel( |
| 235 | | IPoint point, |
| 236 | | Graphics graphics, |
| 237 | | ISettableMapProj settableMapProj) |
| 238 | | { |
| 239 | | RenderLabel(graphics, settableMapProj, point.y, point.x, |
| 240 | | point.y + .005, point.y - .005, |
| 241 | | point.x - .005, point.x + .005); |
| 242 | | } |
| 243 | | |
| 244 | | } |
| | 229 | } |
| | 230 | } |
| | 231 | |
| | 232 | public virtual void RenderLabel( |
| | 233 | IPoint point, |
| | 234 | Graphics graphics, |
| | 235 | ISettableMapProj settableMapProj) |
| | 236 | { |
| | 237 | RenderLabel(graphics, settableMapProj, point.y, point.x, |
| | 238 | point.y + .005, point.y - .005, |
| | 239 | point.x - .005, point.x + .005); |
| | 240 | } |
| | 241 | } |