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.Marker;
|
---|
45 | using ILNumerics.Drawing;
|
---|
46 | using OpenTK.Graphics;
|
---|
47 | using ILNumerics.Drawing.Labeling;
|
---|
48 | using ILNumerics.Drawing.Shapes;
|
---|
49 |
|
---|
50 |
|
---|
51 | namespace ILNumerics.Drawing.Platform.OpenGL {
|
---|
52 | public class ILOGLBitmapMarkerShape : ILBitmapMarkerShape {
|
---|
53 |
|
---|
54 | #region constructors
|
---|
55 | internal ILOGLBitmapMarkerShape(ILPanel panel, Bitmap bitmap)
|
---|
56 | : base(panel,bitmap) {}
|
---|
57 | #endregion
|
---|
58 |
|
---|
59 | #region public interface
|
---|
60 | internal override void Draw(ILRenderProperties p, ILMarker marker, C4bV3f[] vertices, int startID, int vertCount) {
|
---|
61 | if (vertCount == 0 && vertCount != -1) return;
|
---|
62 | string texKey = Hash();
|
---|
63 | ILTextureData texData;
|
---|
64 | if (!m_panel.TextureManager.Exists(texKey)) {
|
---|
65 | storeBitmap(m_bitmap);
|
---|
66 | }
|
---|
67 | texData = m_panel.TextureManager.GetTextureItem(texKey,true);
|
---|
68 | System.Diagnostics.Debug.Assert(texData != null,"The texture key for the bitmap was expected to exist in texture storage, but it was not found!");
|
---|
69 | // prepare for plotting
|
---|
70 | GL.Color3(marker.Color);
|
---|
71 | GL.PushAttrib(AttribMask.AllAttribBits);
|
---|
72 |
|
---|
73 | GL.Enable(EnableCap.Texture2D);
|
---|
74 | GL.Enable(EnableCap.Blend);
|
---|
75 | GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
|
---|
76 | GL.Disable(EnableCap.DepthTest);
|
---|
77 | RectangleF rectF = texData.TextureRectangle;
|
---|
78 | float w,h;
|
---|
79 | if (vertCount > 0) {
|
---|
80 | #region draw textured points (slow version: textured quads)
|
---|
81 | #region determine size for markers in world coords (graph limits)
|
---|
82 | ILClippingData clip = m_panel.Limits;
|
---|
83 | float s05x;
|
---|
84 | float s05y;
|
---|
85 | //if (m_marker.)
|
---|
86 | s05x = Math.Abs(marker.Size * clip.WidthF / (m_panel.ClientSize.Width));
|
---|
87 | s05y = Math.Abs(marker.Size * clip.HeightF / (m_panel.ClientSize.Height));
|
---|
88 |
|
---|
89 | #endregion
|
---|
90 | // draw all markers using quads.
|
---|
91 | // this is slow! Todo: replace by point sprites!
|
---|
92 | GL.Begin(BeginMode.Quads);
|
---|
93 | for (int i = 0; i < vertCount; i++) {
|
---|
94 | w = vertices[i].Position.X;
|
---|
95 | h = vertices[i].Position.Y;
|
---|
96 | if (m_panel.ClipViewData && (w < clip.XMin || w > clip.XMax || h < clip.YMin || h > clip.YMax))
|
---|
97 | continue;
|
---|
98 | w -= s05x;
|
---|
99 | h -= s05y;
|
---|
100 | GL.TexCoord2(rectF.Left,rectF.Bottom);
|
---|
101 | GL.Vertex2(w,h); // ul
|
---|
102 | GL.TexCoord2(rectF.Left,rectF.Top);
|
---|
103 | GL.Vertex2(w,h + 2 * s05y); // bl
|
---|
104 | w += 2 * s05x;
|
---|
105 | GL.TexCoord2(rectF.Right,rectF.Top);
|
---|
106 | GL.Vertex2(w,h + 2 * s05y); // br
|
---|
107 | GL.TexCoord2(rectF.Right,rectF.Bottom);
|
---|
108 | GL.Vertex2(w,h); // tr
|
---|
109 | }
|
---|
110 | GL.End();
|
---|
111 | #endregion
|
---|
112 | } else if (vertCount == -1) {
|
---|
113 | #region render to legend
|
---|
114 | // draw all markers using quads.
|
---|
115 | // this is slow! Todo: replace by point sprites!
|
---|
116 | GL.Begin(BeginMode.Quads);
|
---|
117 | w = vertices[0].XPosition - m_bitmap.Width / 2;
|
---|
118 | h = vertices[0].YPosition - m_bitmap.Height / 2;
|
---|
119 | GL.TexCoord2(rectF.Left,rectF.Top);
|
---|
120 | GL.Vertex2(w,h); // ul
|
---|
121 | GL.TexCoord2(rectF.Left,rectF.Bottom);
|
---|
122 | GL.Vertex2(w,h + m_bitmap.Height); // bl
|
---|
123 | w += m_bitmap.Width;
|
---|
124 | GL.TexCoord2(rectF.Right,rectF.Bottom);
|
---|
125 | GL.Vertex2(w,h + m_bitmap.Height); // br
|
---|
126 | GL.TexCoord2(rectF.Right,rectF.Top);
|
---|
127 | GL.Vertex2(w,h); // tr
|
---|
128 | GL.End();
|
---|
129 | #endregion
|
---|
130 | }
|
---|
131 | GL.PopAttrib();
|
---|
132 | }
|
---|
133 |
|
---|
134 | #endregion
|
---|
135 | }
|
---|
136 | }
|
---|