private void _GenerateQRs() { QRCodeGenerator qr = new QRCodeGenerator(); //ServerAddress QRCodeGenerator.QRCode qrcode = qr.CreateQrCode(CVocaluxeServer.GetServerAddress(), QRCodeGenerator.ECCLevel.H); _QRServerAddress = CDraw.AddTexture(qrcode.GetGraphic(20)); }
/// <summary> /// Gets a frame /// </summary> /// <param name="frame">Referenz to texture where frame should be put in (can be null, then texture is created)</param> /// <param name="time">Maximum start time for frame</param> /// <param name="finished">Set to whether there are no more frames (stream finished, no loop, future calls will always return false)</param> /// <returns>True if a new frame was gotten</returns> public bool GetFrame(ref CTextureRef frame, ref float time, out bool finished) { bool result; if (Math.Abs(_LastShownTime - time) < _FrameDuration && frame != null) //Check 1 frame difference { time = _LastShownTime; result = false; } else { CFramebuffer.CFrame curFrame = _FindFrame(time); if (curFrame != null) { if (frame == null) { frame = CDraw.AddTexture(_Width, _Height, curFrame.Data); } else { CDraw.UpdateTexture(frame, _Width, _Height, curFrame.Data); } if (!_Paused) { curFrame.SetRead(); } time = curFrame.Time; _LastShownTime = time; result = frame != null; } else { result = false; } if (_IsSleeping) { _IsSleeping = false; _EvWakeUp.Set(); } } finished = _NoMoreFrames && _Framebuffer.IsEmpty(); return(result); }
public CCursor(string textureName, SColorF color, float w, float h, float z) { _CursorFadingTimer = new Stopwatch(); ShowCursor = true; _CursorTargetAlpha = 1f; _CursorStartAlpha = 0f; _CursorFadingTime = 0.5f; _CursorName = textureName; _Cursor = CDraw.AddTexture(CTheme.GetSkinFilePath(_CursorName)); _Cursor.color = color; _Cursor.rect.W = w; _Cursor.rect.H = h; _Cursor.rect.Z = z; _Movetimer = new Stopwatch(); }
public bool GetCreditsRessource(string fileName, ref CTextureRef tex) { if (_Connection == null) { return(false); } bool result = false; using (var command = new SQLiteCommand(_Connection)) { command.CommandText = "SELECT id, width, height FROM Images WHERE [Path] = @path"; command.Parameters.Add("@path", DbType.String, 0).Value = fileName; SQLiteDataReader reader = command.ExecuteReader(); if (reader != null && reader.HasRows) { reader.Read(); int id = reader.GetInt32(0); int w = reader.GetInt32(1); int h = reader.GetInt32(2); reader.Close(); command.CommandText = "SELECT Data FROM ImageData WHERE ImageID = @id"; command.Parameters.Add("@id", DbType.Int32).Value = id; reader = command.ExecuteReader(); if (reader.HasRows) { result = true; reader.Read(); byte[] data = _GetBytes(reader); tex = CDraw.AddTexture(w, h, data); } } if (reader != null) { reader.Dispose(); } } return(result); }
public bool GetFrame(ref CTextureRef frame) { lock (_MutexData) { if (_Data != null && _Data.Length == _Width * _Height * 4 && _NewFrameAvailable) { if (frame == null) { frame = CDraw.AddTexture(_Width, _Height, _Data); } else { CDraw.UpdateTexture(frame, _Width, _Height, _Data); } _NewFrameAvailable = false; return(true); } return(false); } }
private void UploadNewFrame(ref STexture frame) { if (!_FileOpened) { return; } lock (MutexFramebuffer) { int num = FindFrame(); if (num >= 0) { if (frame.index == -1 || _Width != frame.width || _Height != frame.height) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(_Width, _Height, ref _FrameBuffer[num].data); } else { CDraw.UpdateTexture(ref frame, ref _FrameBuffer[num].data); } lock (MutexSyncSignals) { _CurrentVideoTime = _FrameBuffer[num].time; } _Finished = false; //EventDecode.Set(); } else { if (_NoMoreFrames) { _Finished = true; } } } }
public bool GetFrame(ref STexture Frame) { if ((_CurrentFrame != null) && (_Webcam != null)) { lock (_CurrentFrame) { BitmapData bitmapdata = _CurrentFrame.LockBits(new Rectangle(0, 0, _CurrentFrame.Width, _CurrentFrame.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); byte[] data = new byte[4 * _CurrentFrame.Width * _CurrentFrame.Height]; Marshal.Copy(bitmapdata.Scan0, data, 0, data.Length); _CurrentFrame.UnlockBits(bitmapdata); if (((Frame.index == -1) || (_CurrentFrame.Width != Frame.width)) || (_CurrentFrame.Height != Frame.height)) { CDraw.RemoveTexture(ref Frame); Frame = CDraw.AddTexture(_CurrentFrame.Width, _CurrentFrame.Height, ref data); } else { CDraw.UpdateTexture(ref Frame, ref data); } } } return(false); }
public virtual bool Load() { if (_IsLoaded) { return(true); } Debug.Assert(_Textures.Count == 0 && _Videos.Count == 0); // load skins/textures foreach (KeyValuePair <string, string> kvp in _Data.Skins) { CTextureRef texture = CDraw.AddTexture(Path.Combine(_Folder, kvp.Value)); if (texture == null) { CLog.Error("Error on loading texture \"" + kvp.Key + "\": " + kvp.Value, true); return(false); } _Textures.Add(kvp.Key, texture); } // load videos foreach (KeyValuePair <string, string> kvp in _Data.Videos) { CVideoSkinElement sk = new CVideoSkinElement { FileName = kvp.Value }; if (!File.Exists(Path.Combine(_Folder, sk.FileName))) { CLog.Error("Video \"" + kvp.Key + "\": (" + sk.FileName + ") not found!"); continue; } _Videos.Add(kvp.Key, sk); } _IsLoaded = true; return(true); }
public void ReloadTextures() { UnloadTextures(); _Cursor = CDraw.AddTexture(CTheme.GetSkinFilePath(_CursorName)); }
public CGlyph(char chr, float maxHigh) { Sizeh = maxHigh; float outline = CFonts.Outline; const TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; float factor = _GetFactor(chr, flags); CFonts.Height = Sizeh * factor; System.Drawing.Font fo; Size sizeB; SizeF size; using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) { fo = CFonts.GetFont(); sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); size = g.MeasureString(chr.ToString(), fo); } using (Bitmap bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height)) { Graphics g = Graphics.FromImage(bmp); g.Clear(Color.Transparent); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; CFonts.Height = Sizeh; fo = CFonts.GetFont(); PointF point = new PointF( outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + Sizeh / 5f, (sizeB.Height - size.Height - (size.Height + Sizeh / 4f) * (1f - factor)) / 2f); using (GraphicsPath path = new GraphicsPath()) { path.AddString( chr.ToString(), fo.FontFamily, (int)fo.Style, Sizeh, point, new StringFormat()); using (Pen pen = new Pen( Color.FromArgb( (int)CFonts.OutlineColor.A * 255, (int)CFonts.OutlineColor.R * 255, (int)CFonts.OutlineColor.G * 255, (int)CFonts.OutlineColor.B * 255), Sizeh * outline)) { pen.LineJoin = LineJoin.Round; g.DrawPath(pen, path); g.FillPath(Brushes.White, path); } } /* g.DrawString( chr.ToString(), fo, Brushes.White, point); * */ Texture = CDraw.AddTexture(bmp); //bmp.Save("font/" + chr + CFonts.Style + ".png", ImageFormat.Png); Width = (int)((1f + outline / 2f) * sizeB.Width * Texture.Width / factor / bmp.Width); g.Dispose(); } fo.Dispose(); }
private void LoadNextSong() { CGame.NextRound(); if (CGame.IsFinished()) { CGraphics.FadeTo(EScreens.ScreenScore); _FadeOut = true; return; } CSong song = CGame.GetSong(); if (song == null) { CLog.LogError("Critical Error! ScreenSing.LoadNextSong() song is null!"); return; } CloseSong(); if (!song.CoverSmallLoaded) { song.ReadNotes(); } string songname = song.Artist + " - " + song.Title; int rounds = CGame.GetNumSongs(); if (rounds > 1) { songname += " (" + CGame.RoundNr + "/" + rounds.ToString() + ")"; } Texts[htTexts(TextSongName)].Text = songname; _CurrentStream = CSound.Load(song.GetMP3(), true); CSound.SetStreamVolume(_CurrentStream, _Volume); CSound.SetPosition(_CurrentStream, song.Start); _CurrentTime = song.Start; _FinishTime = song.Finish; _TimeToFirstNote = 0f; _TimeToFirstNoteDuet = 0f; CGame.ResetPlayer(); CDraw.RemoveTexture(ref _CurrentVideoTexture); if (song.VideoFileName != String.Empty) { _CurrentVideo = CVideo.VdLoad(Path.Combine(song.Folder, song.VideoFileName)); CVideo.VdSkip(_CurrentVideo, song.Start, song.VideoGap); _VideoAspect = song.VideoAspect; } CDraw.RemoveTexture(ref _Background); if (song.BackgroundFileName != String.Empty) { _Background = CDraw.AddTexture(Path.Combine(song.Folder, song.BackgroundFileName)); } SingNotes[htSingNotes(SingBars)].Reset(); bool LyricsOnTop = CGame.NumPlayer == 2 && CConfig.LyricsOnTop == EOffOn.TR_CONFIG_ON; if (song.IsDuet) { CGame.Player[1].LineNr = 1; Statics[htStatics(StaticLyricsDuet)].Visible = true; Lyrics[htLyrics(LyricMainDuet)].Visible = true; Lyrics[htLyrics(LyricSubDuet)].Visible = true; Lyrics[htLyrics(LyricMainTop)].Visible = false; Lyrics[htLyrics(LyricSubTop)].Visible = false; Statics[htStatics(StaticLyricsTop)].Visible = false; } else { Statics[htStatics(StaticLyricsDuet)].Visible = false; Lyrics[htLyrics(LyricMainDuet)].Visible = false; Lyrics[htLyrics(LyricSubDuet)].Visible = false; Lyrics[htLyrics(LyricMainTop)].Visible = LyricsOnTop; Lyrics[htLyrics(LyricSubTop)].Visible = LyricsOnTop; Statics[htStatics(StaticLyricsTop)].Visible = LyricsOnTop; } for (int p = 0; p < CGame.NumPlayer; p++) { NoteLines[p] = SingNotes[htSingNotes(SingBars)].AddPlayer( SingNotes[htSingNotes(SingBars)].BarPos[p, CGame.NumPlayer - 1], CTheme.GetPlayerColor(p + 1), p); } /* * case 4: * NoteLines[0] = SingNotes[htSingNotes(SingBars)].AddPlayer(new SRectF(35f, 100f, 590f, 200f, -0.5f), CTheme.ThemeColors.Player[0]); * NoteLines[1] = SingNotes[htSingNotes(SingBars)].AddPlayer(new SRectF(35f, 350f, 590f, 200f, -0.5f), CTheme.ThemeColors.Player[1]); * NoteLines[2] = SingNotes[htSingNotes(SingBars)].AddPlayer(new SRectF(640f, 100f, 590f, 200f, -0.5f), CTheme.ThemeColors.Player[2]); * NoteLines[3] = SingNotes[htSingNotes(SingBars)].AddPlayer(new SRectF(640f, 350f, 590f, 200f, -0.5f), CTheme.ThemeColors.Player[3]); * break; */ _TimerSongText.Stop(); _TimerSongText.Reset(); if (song.Notes.Lines.Length != 2) { _TimerSongText.Start(); } StartSong(); }
public CGlyph(char chr, CFontStyle fontStyle, float maxHeight) { MaxHeight = maxHeight; float outlineSize = fontStyle.Outline * maxHeight; string chrString = chr.ToString(); Font fo = fontStyle.GetSystemFont(maxHeight); SizeF fullSize; Size bmpSize; using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) { fullSize = g.MeasureString(chrString, fo); if (chr != ' ') { //Gets exact height and width for drawing more than 1 char. But width is to small to draw char on bitmap as e.g. italic chars will get cropped //See https://stackoverflow.com/questions/11708621/how-to-measure-width-of-a-string-precisely StringFormat format = StringFormat.GenericTypographic; RectangleF rect = new RectangleF(0, 0, 1000, 1000); CharacterRange[] ranges = { new CharacterRange(0, chrString.Length) }; format.SetMeasurableCharacterRanges(ranges); _BoundingBox = g.MeasureCharacterRanges(chrString, fo, rect, format)[0].GetBounds(g).Size; // ReSharper disable CompareOfFloatsByEqualityOperator if (_BoundingBox.Height == 0) { // ReSharper restore CompareOfFloatsByEqualityOperator _BoundingBox.Height = fullSize.Height; } _BoundingBox.Width += outlineSize / 2; _BoundingBox.Height += outlineSize; fullSize.Width += outlineSize; bmpSize = new Size((int)fullSize.Width, (int)Math.Round(_BoundingBox.Height)); } else { _BoundingBox = fullSize; _BoundingBox.Height += outlineSize; bmpSize = new Size(1, 1); } } using (var bmp = new Bitmap(bmpSize.Width, bmpSize.Height, PixelFormat.Format32bppArgb)) using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(Color.Transparent); if (chr == ' ') { _Texture = CDraw.AddTexture(bmp); _DrawBounding = new RectangleF(0, 0, 0, 0); } else { g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; var point = new PointF(outlineSize / 2, outlineSize / 4); using (var path = new GraphicsPath()) { //Have to use size in em not pixels! float emSize = fo.Size * fo.FontFamily.GetCellAscent(fo.Style) / fo.FontFamily.GetEmHeight(fo.Style); path.AddString(chrString, fo.FontFamily, (int)fo.Style, emSize, point, new StringFormat()); using (var pen = new Pen(fontStyle.OutlineColor.AsColor(), outlineSize)) { pen.LineJoin = LineJoin.Round; g.DrawPath(pen, path); g.FillPath(Brushes.White, path); } } _DrawBounding = _GetRealBounds(bmp); using (Bitmap bmpCropped = bmp.Clone(_DrawBounding, PixelFormat.Format32bppArgb)) { float dx = (fullSize.Width - _BoundingBox.Width - 1) / 2; _DrawBounding.X -= dx; _Texture = CDraw.AddTexture(bmpCropped); /*_DrawBounding.X *= _Texture.Width / _DrawBounding.Width; * _DrawBounding.Y *= _Texture.Width / _DrawBounding.Width; * _DrawBounding.Width = _Texture.Width; * _DrawBounding.Height = _Texture.Height;*/ #if FONT_DEBUG_OUTPUT if (Char.IsLetterOrDigit(chr)) { if (outline > 0) { bmpCropped.Save("font_" + chr + "o" + CFonts.Style + "2.png", ImageFormat.Png); } else { bmpCropped.Save("font_" + chr + CFonts.Style + "2.png", ImageFormat.Png); } } #endif } } } }