void addHudUserItem(ref HUD.Custom cust, CheckBox sender) { setupPropertyInfo(ref cust.Item, (sender).Name, MainV2.comPort.MAV.cs); hud1.CustomItems[(sender).Name] = cust; hud1.Invalidate(); }
void drawstring(HUD e, string text, Font font, float fontsize, SolidBrush brush, float x, float y) { if (!opengl) { drawstring(graphicsObjectGDIP, text, font, fontsize, brush, x, y); return; } if (text == null || text == "") return; /* OpenTK.Graphics.Begin(); GL.PushMatrix(); GL.Translate(x, y, 0); printer.Print(text, font, c); GL.PopMatrix(); printer.End(); */ char[] chars = text.ToCharArray(); float maxy = 1; foreach (char cha in chars) { int charno = (int)cha; int charid = charno ^ (int)(fontsize * 1000) ^ brush.Color.ToArgb(); if (!charDict.ContainsKey(charid)) { charDict[charid] = new character() { bitmap = new Bitmap(128, 128, System.Drawing.Imaging.PixelFormat.Format32bppArgb) , size = (int)fontsize }; charDict[charid].bitmap.MakeTransparent(Color.Transparent); //charbitmaptexid float maxx = this.Width / 150; // for space // create bitmap using (Graphics gfx = Graphics.FromImage(charDict[charid].bitmap)) { pth.Reset(); if (text != null) pth.AddString(cha + "", font.FontFamily, 0, fontsize + 5, new Point((int)0, (int)0), StringFormat.GenericTypographic); gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; gfx.DrawPath(P, pth); //Draw the face gfx.FillPath(brush, pth); if (pth.PointCount > 0) { foreach (PointF pnt in pth.PathPoints) { if (pnt.X > maxx) maxx = pnt.X; if (pnt.Y > maxy) maxy = pnt.Y; } } } charDict[charid].width = (int)(maxx + 2); //charbitmaps[charid] = charbitmaps[charid].Clone(new RectangleF(0, 0, maxx + 2, maxy + 2), charbitmaps[charid].PixelFormat); //charbitmaps[charno * (int)fontsize].Save(charno + " " + (int)fontsize + ".png"); // create texture int textureId; GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvModeCombine.Replace);//Important, or wrong color on some computers Bitmap bitmap = charDict[charid].bitmap; GL.GenTextures(1, out textureId); GL.BindTexture(TextureTarget.Texture2D, textureId); BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); // GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest); //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Nearest); GL.Finish(); bitmap.UnlockBits(data); charDict[charid].gltextureid = textureId; } //GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, charDict[charid].gltextureid); float scale = 1.0f; GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0, 0); GL.Vertex2(x, y); GL.TexCoord2(1, 0); GL.Vertex2(x + charDict[charid].bitmap.Width * scale, y); GL.TexCoord2(1, 1); GL.Vertex2(x + charDict[charid].bitmap.Width * scale, y + charDict[charid].bitmap.Height * scale); GL.TexCoord2(0, 1); GL.Vertex2(x + 0, y + charDict[charid].bitmap.Height * scale); GL.End(); //GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Texture2D); x += charDict[charid].width * scale; } }
public FlightData() { log.Info("Ctor Start"); InitializeComponent(); log.Info("Components Done"); instance = this; // _serializer = new DockStateSerializer(dockContainer1); // _serializer.SavePath = Application.StartupPath + Path.DirectorySeparatorChar + "FDscreen.xml"; // dockContainer1.PreviewRenderer = new PreviewRenderer(); // mymap = gMapControl1; myhud = hud1; MainHcopy = MainH; mymap.Paint += mymap_Paint; // mymap.Manager.UseMemoryCache = false; log.Info("Tunning Graph Settings"); // setup default tuning graph if (MainV2.config["Tuning_Graph_Selected"] != null) { string line = MainV2.config["Tuning_Graph_Selected"].ToString(); string[] lines = line.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries); foreach (string option in lines) { using (var cb = new CheckBox {Name = option, Checked = true}) { chk_box_CheckedChanged(cb, new EventArgs()); } } } else { using (var cb = new CheckBox {Name = "roll", Checked = true}) { chk_box_CheckedChanged(cb, new EventArgs()); } using (var cb = new CheckBox {Name = "pitch", Checked = true}) { chk_box_CheckedChanged(cb, new EventArgs()); } using (var cb = new CheckBox {Name = "nav_roll", Checked = true}) { chk_box_CheckedChanged(cb, new EventArgs()); } using (var cb = new CheckBox {Name = "nav_pitch", Checked = true}) { chk_box_CheckedChanged(cb, new EventArgs()); } } if (MainV2.config.ContainsKey("hudcolor")) { hud1.hudcolor = Color.FromName(MainV2.config["hudcolor"].ToString()); } MainV2.comPort.MavChanged += comPort_MavChanged; log.Info("HUD Settings"); foreach (string item in MainV2.config.Keys) { if (item.StartsWith("hud1_useritem_")) { string selection = item.Replace("hud1_useritem_", ""); CheckBox chk = new CheckBox(); chk.Name = selection; chk.Checked = true; HUD.Custom cust = new HUD.Custom(); cust.Header = MainV2.config[item].ToString(); HUD.Custom.src = MainV2.comPort.MAV.cs; addHudUserItem(ref cust, chk); } } List<string> list = new List<string>(); { list.Add("LOITER_UNLIM"); list.Add("RETURN_TO_LAUNCH"); list.Add("PREFLIGHT_CALIBRATION"); list.Add("MISSION_START"); list.Add("PREFLIGHT_REBOOT_SHUTDOWN"); //DO_SET_SERVO //DO_REPEAT_SERVO } CMB_action.DataSource = list; CMB_modes.DataSource = Common.getModesList(MainV2.comPort.MAV.cs); CMB_modes.ValueMember = "Key"; CMB_modes.DisplayMember = "Value"; //default to auto CMB_modes.Text = "Auto"; CMB_setwp.SelectedIndex = 0; log.Info("Graph Setup"); CreateChart(zg1); // config map log.Info("Map Setup"); gMapControl1.CacheLocation = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "gmapcache" + Path.DirectorySeparatorChar; gMapControl1.MapProvider = GMapProviders.GoogleSatelliteMap; gMapControl1.MinZoom = 0; gMapControl1.MaxZoom = 24; gMapControl1.Zoom = 3; gMapControl1.OnMapZoomChanged += gMapControl1_OnMapZoomChanged; gMapControl1.DisableFocusOnMouseEnter = true; gMapControl1.OnMarkerEnter += gMapControl1_OnMarkerEnter; gMapControl1.OnMarkerLeave += gMapControl1_OnMarkerLeave; gMapControl1.RoutesEnabled = true; gMapControl1.PolygonsEnabled = true; tfrpolygons = new GMapOverlay("tfrpolygons"); gMapControl1.Overlays.Add(tfrpolygons); kmlpolygons = new GMapOverlay("kmlpolygons"); gMapControl1.Overlays.Add(kmlpolygons); geofence = new GMapOverlay("geofence"); gMapControl1.Overlays.Add(geofence); polygons = new GMapOverlay("polygons"); gMapControl1.Overlays.Add(polygons); routes = new GMapOverlay("routes"); gMapControl1.Overlays.Add(routes); rallypointoverlay = new GMapOverlay("rally points"); gMapControl1.Overlays.Add(rallypointoverlay); gMapControl1.Overlays.Add(poioverlay); try { if (MainV2.getConfig("GspeedMAX") != "") { Gspeed.MaxValue = float.Parse(MainV2.getConfig("GspeedMAX")); } } catch { } MainV2.comPort.ParamListChanged += FlightData_ParentChanged; MainV2.AdvancedChanged += MainV2_AdvancedChanged; // first run MainV2_AdvancedChanged(null, null); }
public HUD() { if (this.DesignMode) { opengl = false; //return; } this.Name = "Hud"; eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 50L); // or whatever other quality value you want objBitmap.MakeTransparent(); //InitializeComponent(); graphicsObject = this; graphicsObjectGDIP = Graphics.FromImage(objBitmap); }