Exemplo n.º 1
0
 public void UnloadTextures()
 {
     CDraw.RemoveTexture(ref _Cursor);
 }
Exemplo n.º 2
0
        private void DrawJump(float CurrentBeat)
        {
            float x = _X - _width / 2; // most left position

            //find last active note
            int last_note = -1;

            for (int i = 0; i < _Notes.Count; i++)
            {
                if (CurrentBeat >= _Notes[i].StartBeat)
                {
                    last_note = i;
                }
            }

            int   jump_note = -1;
            int   end_beat  = -1;
            float jumpx     = 0f;

            for (int note = 0; note < _Notes.Count; note++)
            {
                _Text.X     = x;
                _Text.Style = EStyle.Bold;
                _Text.Text  = _Notes[note].Text;
                RectangleF rect = CDraw.GetTextBounds(_Text);

                if (_Notes[note].Type == ENoteType.Freestyle)
                {
                    _Text.Style = EStyle.BoldItalic;
                }

                if (CurrentBeat >= _Notes[note].StartBeat)
                {
                    bool last    = note == _Notes.Count - 1;
                    int  endbeat = _Notes[note].EndBeat;
                    if (note < _Notes.Count - 1)
                    {
                        endbeat = _Notes[note + 1].StartBeat - 1;
                    }

                    if (CurrentBeat <= _Notes[note].EndBeat)
                    {
                        jump_note = note;
                        end_beat  = endbeat;
                        jumpx     = _Text.X;
                    }
                    else
                    {
                        // already passed
                        if (note == last_note)
                        {
                            _Text.Color = ColorProcessed;
                        }
                        else
                        {
                            _Text.Color = Color;
                        }

                        _Text.Draw();
                    }
                }
                else
                {
                    // not passed
                    _Text.Color = Color;
                    _Text.Draw();
                }

                x += rect.Width;
            }

            if (jump_note > -1)
            {
                if (_Notes[jump_note].Duration == 0)
                {
                    return;
                }

                _Text.X     = jumpx;
                _Text.Text  = _Notes[jump_note].Text;
                _Text.Color = ColorProcessed;
                _Text.Style = EStyle.Bold;

                if (_Notes[jump_note].Type == ENoteType.Freestyle)
                {
                    _Text.Style = EStyle.BoldItalic;
                }

                float diff = _Notes[jump_note].EndBeat - _Notes[jump_note].StartBeat;
                if (diff <= 0f)
                {
                    diff = 1f;
                }

                float p = (CurrentBeat - _Notes[jump_note].StartBeat) / diff;
                if (p > 1f)
                {
                    p = 1f;
                }

                p = 1f - p;

                if (diff == 1)
                {
                    _Text.Draw();
                }
                else
                {
                    float y = _Text.Y;
                    _Text.Y -= _Text.Height * 0.1f * p;
                    _Text.Draw();
                    _Text.Y = y;
                }
            }
        }
Exemplo n.º 3
0
        public override void LoadTheme()
        {
            //Vocaluxe-Logo
            CDataBase.GetCreditsRessource("Logo_voc.png", ref _TexLogo);

            //Little stars for logo
            CDataBase.GetCreditsRessource("PerfectNoteStar.png", ref _TexPerfectNoteStar);

            //brunzel
            CDataBase.GetCreditsRessource("brunzel.png", ref _TexNameBrunzel);

            //Darkice
            CDataBase.GetCreditsRessource("Darkice.png", ref _TexNameDarkice);

            //flokuep
            CDataBase.GetCreditsRessource("flokuep.png", ref _TexNameFlokuep);

            //bohning
            CDataBase.GetCreditsRessource("bohning.png", ref _TexNameBohning);

            //mesand
            CDataBase.GetCreditsRessource("mesand.png", ref _TexNameMesand);

            //babene03
            CDataBase.GetCreditsRessource("babene03.png", ref _TexNameBabene03);

            //pantero
            CDataBase.GetCreditsRessource("pantero.png", ref _TexNamePantero);

            //Pinky007
            CDataBase.GetCreditsRessource("Pinky007.png", ref _TexNamePinky007);

            //Prepare Text
            int lastY = 280;

            for (int i = 0; i < paragraphs.Count; i++)
            {
                string line = "";
                for (int e = 0; e < paragraphs[i].Length; e++)
                {
                    if (paragraphs[i][e] != null)
                    {
                        string newline = line + " " + paragraphs[i][e];
                        CText  text    = new CText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line);
                        if (CDraw.GetTextBounds(text).Width < (CSettings.iRenderW - 220))
                        {
                            line = line + " " + paragraphs[i][e];

                            //Check if all words are used
                            if ((e + 1) == paragraphs[i].Length)
                            {
                                text.Text = line;
                                paragraphTexts.Add(text);
                                line   = "";
                                lastY += 40;
                            }
                        }
                        else
                        {
                            paragraphTexts.Add(text);
                            line   = " " + paragraphs[i][e];
                            lastY += 27;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void DrawColor()
        {
            SRectF bounds = new SRectF(0f, 0f, CSettings.iRenderW, CSettings.iRenderH, CSettings.zFar / 4);

            CDraw.DrawColor(Color, bounds);
        }
Exemplo n.º 5
0
        private void DrawZoom(float CurrentBeat)
        {
            float x = _X - _width / 2; // most left position

            //find last active note
            int last_note = -1;

            for (int i = 0; i < _Notes.Count; i++)
            {
                if (CurrentBeat >= _Notes[i].StartBeat)
                {
                    last_note = i;
                }
            }

            int   zoom_note = -1;
            int   end_beat  = -1;
            float zoomx     = 0f;

            for (int note = 0; note < _Notes.Count; note++)
            {
                _Text.X     = x;
                _Text.Style = EStyle.Bold;
                _Text.Text  = _Notes[note].Text;
                RectangleF rect = CDraw.GetTextBounds(_Text);

                if (_Notes[note].Type == ENoteType.Freestyle)
                {
                    _Text.Style = EStyle.BoldItalic;
                }

                if (CurrentBeat >= _Notes[note].StartBeat)
                {
                    bool last    = note == _Notes.Count - 1;
                    int  endbeat = _Notes[note].EndBeat;
                    if (note < _Notes.Count - 1)
                    {
                        endbeat = _Notes[note + 1].StartBeat - 1;
                    }

                    if (CurrentBeat <= endbeat)
                    {
                        zoom_note = note;
                        end_beat  = endbeat;
                        zoomx     = _Text.X;
                    }
                    else
                    {
                        // already passed
                        if (note == last_note)
                        {
                            _Text.Color = ColorProcessed;
                        }
                        else
                        {
                            _Text.Color = Color;
                        }

                        _Text.Draw();
                    }
                }
                else
                {
                    // not passed
                    _Text.Color = Color;
                    _Text.Draw();
                }

                x += rect.Width;
            }

            if (zoom_note > -1)
            {
                if (_Notes[zoom_note].Duration == 0)
                {
                    return;
                }

                _Text.X     = zoomx;
                _Text.Text  = _Notes[zoom_note].Text;
                _Text.Color = ColorProcessed;
                _Text.Style = EStyle.Bold;

                if (_Notes[zoom_note].Type == ENoteType.Freestyle)
                {
                    _Text.Style = EStyle.BoldItalic;
                }

                RectangleF rect = CDraw.GetTextBounds(_Text);

                float diff = end_beat - _Notes[zoom_note].StartBeat;
                if (diff <= 0f)
                {
                    diff = 1f;
                }

                float p = (CurrentBeat - _Notes[zoom_note].StartBeat) / diff;
                if (p > 1f)
                {
                    p = 1f;
                }

                p = 1f - p;

                float ty = _Text.Y;
                float tx = _Text.X;
                float th = _Text.Height;
                float tz = _Text.Z;

                _Text.Height += _Text.Height * p * 0.4f;
                RectangleF rectz = CDraw.GetTextBounds(_Text);
                _Text.X -= (rectz.Width - rect.Width) / 2f;
                _Text.Y -= (rectz.Height - rect.Height) / 2f;
                _Text.Z -= 0.1f;

                _Text.Draw();

                _Text.Y      = ty;
                _Text.X      = tx;
                _Text.Height = th;
                _Text.Z      = tz;
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolver);

            // Close program if there is another instance running
            if (!EnsureSingleInstance())
            {
                //TODO: put it into language file
                MessageBox.Show("Another Instance of Vocaluxe is already runnning!");
                return;
            }

            Application.DoEvents();

            try
            {
                // Init Log
                CLog.Init();

                CSettings.CreateFolders();
                Application.DoEvents();

                // Init Language
                CLog.StartBenchmark(0, "Init Language");
                CLanguage.Init();
                CLog.StopBenchmark(0, "Init Language");

                Application.DoEvents();

                // load config
                CLog.StartBenchmark(0, "Init Config");
                CConfig.LoadCommandLineParams(args);
                CConfig.UseCommandLineParamsBefore();
                CConfig.Init();
                CConfig.UseCommandLineParamsAfter();
                CLog.StopBenchmark(0, "Init Config");

                Application.DoEvents();
                _SplashScreen = new SplashScreen();
                Application.DoEvents();

                // Init Draw
                CLog.StartBenchmark(0, "Init Draw");
                CDraw.InitDraw();
                CLog.StopBenchmark(0, "Init Draw");

                Application.DoEvents();

                // Init Database
                CLog.StartBenchmark(0, "Init Database");
                CDataBase.Init();
                CLog.StopBenchmark(0, "Init Database");

                Application.DoEvents();

                // Init Playback
                CLog.StartBenchmark(0, "Init Playback");
                CSound.PlaybackInit();
                CLog.StopBenchmark(0, "Init Playback");

                Application.DoEvents();

                // Init Record
                CLog.StartBenchmark(0, "Init Record");
                CSound.RecordInit();
                CLog.StopBenchmark(0, "Init Record");

                Application.DoEvents();

                //Init Webcam
                CLog.StartBenchmark(0, "Init Webcam");
                CWebcam.Init();
                CLog.StopBenchmark(0, "Init Webcam");

                Application.DoEvents();

                // Init Background Music
                CLog.StartBenchmark(0, "Init Background Music");
                CBackgroundMusic.Init();
                CLog.StopBenchmark(0, "Init Background Music");

                Application.DoEvents();

                // Init Profiles
                CLog.StartBenchmark(0, "Init Profiles");
                CProfiles.Init();
                CLog.StopBenchmark(0, "Init Profiles");

                Application.DoEvents();

                // Init Font
                CLog.StartBenchmark(0, "Init Font");
                CFonts.Init();
                CLog.StopBenchmark(0, "Init Font");

                Application.DoEvents();

                // Init VideoDecoder
                CLog.StartBenchmark(0, "Init Videodecoder");
                CVideo.Init();
                CLog.StopBenchmark(0, "Init Videodecoder");

                Application.DoEvents();

                // Load Cover
                CLog.StartBenchmark(0, "Init Cover");
                CCover.Init();
                CLog.StopBenchmark(0, "Init Cover");

                Application.DoEvents();

                // Theme System
                CLog.StartBenchmark(0, "Init Theme");
                CTheme.InitTheme();
                CLog.StopBenchmark(0, "Init Theme");

                Application.DoEvents();

                // Init Screens
                CLog.StartBenchmark(0, "Init Screens");
                CGraphics.InitGraphics();
                CLog.StopBenchmark(0, "Init Screens");

                Application.DoEvents();

                // Init Input
                CLog.StartBenchmark(0, "Init Input");
                CInput.Init();
                CLog.StopBenchmark(0, "Init Input");

                // Init Game;
                CLog.StartBenchmark(0, "Init Game");
                CGame.Init();
                CLog.StopBenchmark(0, "Init Game");
            }
            catch (Exception e)
            {
                MessageBox.Show("Error on start up: " + e.Message + e.StackTrace);
                CLog.LogError("Error on start up: " + e.Message + e.StackTrace);
                CloseProgram();
                Environment.Exit(Environment.ExitCode);
            }
            Application.DoEvents();

            // Start Main Loop
            _SplashScreen.Close();

            try
            {
                CDraw.MainLoop();
            }
            catch (Exception e)
            {
                MessageBox.Show("Unhandled error: " + e.Message + e.StackTrace);
                CLog.LogError("Unhandled error: " + e.Message + e.StackTrace);
            }

            CloseProgram();
        }
Exemplo n.º 7
0
        public void Draw()
        {
            if (!Visible && CSettings.GameState != EGameState.EditTheme)
            {
                return;
            }

            STexture Texture           = CTheme.GetSkinTexture(_Theme.TextureName);
            STexture TextureArrowLeft  = CTheme.GetSkinTexture(_Theme.TextureArrowLeftName);
            STexture TextureArrowRight = CTheme.GetSkinTexture(_Theme.TextureArrowRightName);

            STexture STexture           = CTheme.GetSkinTexture(_Theme.STextureName);
            STexture STextureArrowLeft  = CTheme.GetSkinTexture(_Theme.STextureArrowLeftName);
            STexture STextureArrowRight = CTheme.GetSkinTexture(_Theme.STextureArrowRightName);

            STexture HTexture = CTheme.GetSkinTexture(_Theme.HTextureName);

            if (Selected)
            {
                if (Highlighted)
                {
                    CDraw.DrawTexture(HTexture, Rect, HColor);
                }
                else
                {
                    CDraw.DrawTexture(STexture, Rect, SColor);
                }
            }
            else
            {
                CDraw.DrawTexture(Texture, Rect, Color);
            }

            if (_Selection > 0 || CSettings.GameState == EGameState.EditTheme)
            {
                if (_ArrowLeftSelected)
                {
                    CDraw.DrawTexture(STextureArrowLeft, RectArrowLeft, SColorArrow);
                }
                else
                {
                    CDraw.DrawTexture(TextureArrowLeft, RectArrowLeft, ColorArrow);
                }
            }

            if (_Selection < _ValueNames.Count - 1 || CSettings.GameState == EGameState.EditTheme)
            {
                if (_ArrowRightSelected)
                {
                    CDraw.DrawTexture(STextureArrowRight, RectArrowRight, SColorArrow);
                }
                else
                {
                    CDraw.DrawTexture(TextureArrowRight, RectArrowRight, ColorArrow);
                }
            }

            if (_NumVisible < 1 || _ValueNames.Count == 0)
            {
                return;
            }

            float x  = Rect.X + Rect.W * 0.1f;
            float dx = Rect.W * 0.8f / _NumVisible;
            //float y = Rect.Y + (Rect.H - TextH);

            int offset = _Selection - (int)_NumVisible / 2;

            if (_ValueNames.Count - _NumVisible - offset < 0)
            {
                offset = _ValueNames.Count - _NumVisible;
            }

            if (offset < 0)
            {
                offset = 0;
            }


            int numvis = _NumVisible;

            if (_ValueNames.Count < numvis)
            {
                numvis = _ValueNames.Count;
            }

            _ValueBounds.Clear();
            for (int i = 0; i < numvis; i++)
            {
                CText   Text  = new CText(0, 0, 0, TextH, MaxW, EAlignment.Center, _Theme.TextStyle, _Theme.TextFont, TextColor, _ValueNames[i + offset]);
                SColorF Alpha = new SColorF(1f, 1f, 1f, 0.35f);
                if (i + offset == _Selection)
                {
                    Text.Color = STextColor;
                    Alpha      = new SColorF(1f, 1f, 1f, 1f);
                }

                RectangleF bounds = CDraw.GetTextBounds(Text);
                Text.X = x + dx / 2f + dx * i;

                if (!WithTextures)
                {
                    Text.Y = (int)(Rect.Y + (Rect.H - bounds.Height) / 2);
                }
                else
                {
                    Text.Y = (int)(Rect.Y + (Rect.H - bounds.Height));
                }

                Text.Z = Rect.Z;
                Text.Draw();

                if (WithTextures)
                {
                    float  dh   = Text.Y - Rect.Y - Rect.H * 0.1f;
                    SRectF rect = new SRectF(Text.X - dh / 2, Rect.Y + Rect.H * 0.05f, dh, dh, Rect.Z);
                    CDraw.DrawTexture(_Textures[i + offset], rect, Alpha);
                    _ValueBounds.Add(rect);
                }
                else
                {
                    _ValueBounds.Add(new SRectF(Text.X - bounds.Width / 2f, Text.Y, bounds.Width, bounds.Height, Rect.Z));
                }
            }
        }
Exemplo n.º 8
0
 public void UnloadTexture()
 {
     CDraw.RemoveTexture(ref Texture);
 }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
        private void DrawLyricHelper()
        {
            if (_FadeOut)
            {
                return;
            }

            if (!CSound.IsPlaying(_CurrentStream) && !CSound.IsPaused(_CurrentStream))
            {
                return;
            }

            CSong song = CGame.GetSong();

            if (song == null)
            {
                return;
            }

            float alpha = (float)((Math.Cos(_CurrentTime * Math.PI * 2) + 1) / 2.0) / 2f + 0.5f;

            if (_TimeToFirstNote > CSettings.LyricHelperMinTime && _RemainingTimeToFirstNote > 0f && _RemainingTimeToFirstNote < CSettings.LyricHelperEnableTime)
            {
                float time      = _RemainingTimeToFirstNote;
                float totaltime = CSettings.LyricHelperMoveTime;

                if (totaltime > _TimeToFirstNote)
                {
                    totaltime = _TimeToFirstNote;
                }

                if (time > totaltime)
                {
                    time = totaltime;
                }

                SRectF  Rect  = Statics[htStatics(StaticLyricHelper)].Rect;
                SColorF Color = new SColorF(
                    Statics[htStatics(StaticLyricHelper)].Color.R,
                    Statics[htStatics(StaticLyricHelper)].Color.G,
                    Statics[htStatics(StaticLyricHelper)].Color.B,
                    Statics[htStatics(StaticLyricHelper)].Color.A * Statics[htStatics(StaticLyricHelper)].Alpha * alpha);

                float distance = Lyrics[htLyrics(LyricMain)].GetCurrentLyricPosX() - Rect.X - Rect.W;
                CDraw.DrawTexture(Statics[htStatics(StaticLyricHelper)].Texture,
                                  new SRectF(Rect.X + distance * (1f - time / totaltime), Rect.Y, Rect.W, Rect.H, Rect.Z), Color);

                if (Statics[htStatics(StaticLyricsTop)].Visible)
                {
                    Rect  = Statics[htStatics(StaticLyricHelperTop)].Rect;
                    Color = new SColorF(
                        Statics[htStatics(StaticLyricHelperTop)].Color.R,
                        Statics[htStatics(StaticLyricHelperTop)].Color.G,
                        Statics[htStatics(StaticLyricHelperTop)].Color.B,
                        Statics[htStatics(StaticLyricHelperTop)].Color.A * Statics[htStatics(StaticLyricHelper)].Alpha * alpha);

                    distance = Lyrics[htLyrics(LyricMainTop)].GetCurrentLyricPosX() - Rect.X - Rect.W;
                    CDraw.DrawTexture(Statics[htStatics(StaticLyricHelperTop)].Texture,
                                      new SRectF(Rect.X + distance * (1f - time / totaltime), Rect.Y, Rect.W, Rect.H, Rect.Z), Color);
                }
            }

            if (song.IsDuet)
            {
                if (_TimeToFirstNoteDuet > CSettings.LyricHelperMinTime && _RemainingTimeToFirstNoteDuet > 0f && _RemainingTimeToFirstNoteDuet < CSettings.LyricHelperEnableTime)
                {
                    float time      = _RemainingTimeToFirstNoteDuet;
                    float totaltime = CSettings.LyricHelperMoveTime;

                    if (totaltime > _TimeToFirstNoteDuet)
                    {
                        totaltime = _TimeToFirstNoteDuet;
                    }

                    if (time > totaltime)
                    {
                        time = totaltime;
                    }

                    SRectF Rect = Statics[htStatics(StaticLyricHelperDuet)].Rect;

                    SColorF Color = new SColorF(
                        Statics[htStatics(StaticLyricHelperDuet)].Color.R,
                        Statics[htStatics(StaticLyricHelperDuet)].Color.G,
                        Statics[htStatics(StaticLyricHelperDuet)].Color.B,
                        Statics[htStatics(StaticLyricHelperDuet)].Color.A * Statics[htStatics(StaticLyricHelperDuet)].Alpha * alpha);

                    float distance = Lyrics[htLyrics(LyricMainDuet)].GetCurrentLyricPosX() - Rect.X - Rect.W;
                    CDraw.DrawTexture(Statics[htStatics(StaticLyricHelperDuet)].Texture,
                                      new SRectF(Rect.X + distance * (1f - time / totaltime), Rect.Y, Rect.W, Rect.H, Rect.Z),
                                      Color);
                }
            }
        }
Exemplo n.º 11
0
        public bool GetCover(string coverPath, ref CTextureRef tex, int maxSize)
        {
            if (_Connection == null)
            {
                return(false);
            }
            if (!File.Exists(coverPath))
            {
                CLog.LogError("Can't find File: " + coverPath);
                return(false);
            }

            lock (_Mutex)
            {
                //Double check here because we may have just closed our connection
                if (_Connection == null)
                {
                    return(false);
                }
                using (var command = new SQLiteCommand(_Connection))
                {
                    command.CommandText = "SELECT id, width, height FROM Cover WHERE [Path] = @path";
                    command.Parameters.Add("@path", DbType.String).Value = coverPath;

                    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 CoverData WHERE CoverID = @id";
                        command.Parameters.Add("@id", DbType.Int32).Value = id;
                        reader = command.ExecuteReader();

                        if (reader.HasRows)
                        {
                            reader.Read();
                            byte[] data2 = _GetBytes(reader);
                            reader.Dispose();
                            tex = CDraw.EnqueueTexture(w, h, data2);
                            return(true);
                        }
                        command.CommandText = "DELETE FROM Cover WHERE id = @id";
                        command.Parameters.Add("@id", DbType.Int32).Value = id;
                        command.ExecuteNonQuery();
                    }
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
            }

            // At this point we do not have a mathing entry in the CoverDB (either no Data found and deleted or nothing at all)
            // We break out of the lock to do the bitmap loading and resizing here to allow multithreaded loading

            Bitmap origin = CHelper.LoadBitmap(coverPath);

            if (origin == null)
            {
                return(false);
            }

            Size size = origin.GetSize();

            if (size.Width > maxSize || size.Height > maxSize)
            {
                size = CHelper.FitInBounds(new SRectF(0, 0, maxSize, maxSize, 0), (float)size.Width / size.Height, EAspect.LetterBox).SizeI;
                Bitmap tmp = origin.Resize(size);
                origin.Dispose();
                origin = tmp;
            }

            byte[] data;

            try
            {
                data = new byte[size.Width * size.Height * 4];
                BitmapData bmpData = origin.LockBits(origin.GetRect(), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                Marshal.Copy(bmpData.Scan0, data, 0, data.Length);
                origin.UnlockBits(bmpData);
            }
            finally
            {
                origin.Dispose();
            }

            tex = CDraw.EnqueueTexture(size.Width, size.Height, data);

            lock (_Mutex)
            {
                //Double check here because we may have just closed our connection
                if (_Connection == null)
                {
                    return(false);
                }
                if (_TransactionCover == null)
                {
                    _TransactionCover = _Connection.BeginTransaction();
                }
                using (var command = new SQLiteCommand(_Connection))
                {
                    command.CommandText = "INSERT INTO Cover (Path, width, height) VALUES (@path, @w, @h)";
                    command.Parameters.Add("@w", DbType.Int32).Value     = size.Width;
                    command.Parameters.Add("@h", DbType.Int32).Value     = size.Height;
                    command.Parameters.Add("@path", DbType.String).Value = coverPath;
                    command.ExecuteNonQuery();

                    command.CommandText = "SELECT id FROM Cover WHERE [Path] = @path";
                    command.Parameters.Add("@path", DbType.String).Value = coverPath;
                    SQLiteDataReader reader = command.ExecuteReader();

                    if (reader != null)
                    {
                        reader.Read();
                        int id = reader.GetInt32(0);
                        reader.Dispose();
                        command.CommandText = "INSERT INTO CoverData (CoverID, Data) VALUES (@id, @data)";
                        command.Parameters.Add("@id", DbType.Int32).Value    = id;
                        command.Parameters.Add("@data", DbType.Binary).Value = data;
                        command.ExecuteNonQuery();
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 12
0
        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();
        }
Exemplo n.º 13
0
        public override bool Draw()
        {
            if (_Active)
            {
                if (_CurrentVideo != -1 && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON)
                {
                    RectangleF bounds = new RectangleF(0, 0, CSettings.iRenderW, CSettings.iRenderH);
                    RectangleF rect   = new RectangleF(0f, 0f, _CurrentVideoTexture.width, _CurrentVideoTexture.height);
                    CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, _VideoAspect);

                    CDraw.DrawTexture(_CurrentVideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f),
                                      _CurrentVideoTexture.color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f), false);
                }
                else
                {   // Draw Background
                    RectangleF bounds = new RectangleF(0, 0, CSettings.iRenderW, CSettings.iRenderH);
                    RectangleF rect   = new RectangleF(0f, 0f, _Background.width, _Background.height);
                    CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, EAspect.Crop);

                    CDraw.DrawTexture(_Background, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f),
                                      _Background.color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f), false);
                }
            }

            base.DrawBG();

            foreach (CStatic stat in Statics)
            {
                stat.Draw();
            }

            foreach (CText text in Texts)
            {
                text.Draw();
            }

            switch (CConfig.TimerLook)
            {
            case ETimerLook.TR_CONFIG_TIMERLOOK_NORMAL:
                CDraw.DrawTexture(Statics[htStatics(StaticTimeLine)].Texture, Statics[htStatics(StaticTimeLine)].Rect, new SColorF(1, 1, 1, 1), _TimeLineRect);
                break;

            case ETimerLook.TR_CONFIG_TIMERLOOK_EXPANDED:
                for (int i = 0; i < _TimeRects.Count; i++)
                {
                    CDraw.DrawTexture(_TimeRects[i].rect.Texture, Statics[htStatics(StaticTimeLine)].Rect, _TimeRects[i].rect.Color, _TimeRects[i].rect.Rect);
                }
                break;
            }

            Lyrics[htLyrics(LyricSub)].Draw(-100);
            Lyrics[htLyrics(LyricMain)].Draw(CGame.Beat);

            Lyrics[htLyrics(LyricSubDuet)].Draw(-100);
            Lyrics[htLyrics(LyricMainDuet)].Draw(CGame.Beat);

            Lyrics[htLyrics(LyricSubTop)].Draw(-100);
            Lyrics[htLyrics(LyricMainTop)].Draw(CGame.Beat);


            for (int i = 0; i < CGame.NumPlayer; i++)
            {
                SingNotes[htSingNotes(SingBars)].Draw(NoteLines[i], CGame.Player[i].SingLine, i);
            }

            DrawLyricHelper();

            if (_Pause)
            {
                Statics[htStatics(StaticPauseBG)].ForceDraw();
                Texts[htTexts(TextPause)].ForceDraw();

                foreach (CButton button in Buttons)
                {
                    button.Draw();
                }

                foreach (CSelectSlide slide in SelectSlides)
                {
                    slide.Draw();
                }
            }

            return(true);
        }
Exemplo n.º 14
0
        private void DrawToneHelper(int n, int BaseLine, float XOffset)
        {
            int TonePlayer = CSound.RecordGetToneAbs(_PlayerNotes[n].PlayerNr);

            SRectF Rect = _PlayerNotes[n].Rect;

            while (TonePlayer - BaseLine < 0)
            {
                TonePlayer += 12;
            }

            while (TonePlayer - BaseLine > 12)
            {
                TonePlayer -= 12;
            }

            if (XOffset < 0f)
            {
                XOffset = 0f;
            }

            if (XOffset > Rect.W)
            {
                XOffset = Rect.W;
            }

            float  dy   = Rect.H / (CSettings.NumNoteLines);
            SRectF rect = new SRectF(
                Rect.X - dy + XOffset,
                Rect.Y + dy * (CSettings.NumNoteLines - 1 - (TonePlayer - BaseLine) / 2f),
                dy,
                dy,
                Rect.Z
                );

            SColorF color = new SColorF(
                _PlayerNotes[n].Color.R,
                _PlayerNotes[n].Color.G,
                _PlayerNotes[n].Color.B,
                _PlayerNotes[n].Color.A * _PlayerNotes[n].Alpha);

            STexture ToneHelper = CTheme.GetSkinTexture(_Theme.SkinToneHelperName);

            CDraw.DrawTexture(ToneHelper, rect, color);


            while (TonePlayer - BaseLine < 12)
            {
                TonePlayer += 12;
            }

            while (TonePlayer - BaseLine > 24)
            {
                TonePlayer -= 12;
            }

            rect = new SRectF(
                Rect.X - dy + XOffset,
                Rect.Y + dy * (CSettings.NumNoteLines - 1 - (TonePlayer - BaseLine) / 2f),
                dy,
                dy,
                Rect.Z
                );

            CDraw.DrawTexture(ToneHelper, rect, color);
        }
Exemplo n.º 15
0
        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
                        }
                    }
                }
        }
Exemplo n.º 16
0
        private static void _Run(string[] args)
        {
            Application.DoEvents();

            try
            {
                // Create data folder
                Directory.CreateDirectory(CSettings.DataFolder);

                // Init Log
                CLog.Init();

                if (!CProgrammHelper.CheckRequirements())
                {
                    return;
                }
                CProgrammHelper.Init();

                CLog.StartBenchmark("Init Program");
                CMain.Init();
                Application.DoEvents();

                // Init Language
                CLog.StartBenchmark("Init Language");
                if (!CLanguage.Init())
                {
                    throw new CLoadingException("Language");
                }
                CLog.StopBenchmark("Init Language");

                Application.DoEvents();

                // load config
                CLog.StartBenchmark("Init Config");
                CConfig.LoadCommandLineParams(args);
                CConfig.UseCommandLineParamsBefore();
                CConfig.Init();
                CConfig.UseCommandLineParamsAfter();
                CLog.StopBenchmark("Init Config");

                // Create folders
                CSettings.CreateFolders();

                _SplashScreen = new CSplashScreen();
                Application.DoEvents();

                // Init Draw
                CLog.StartBenchmark("Init Draw");
                if (!CDraw.Init())
                {
                    throw new CLoadingException("drawing");
                }
                CLog.StopBenchmark("Init Draw");

                Application.DoEvents();

                // Init Playback
                CLog.StartBenchmark("Init Playback");
                if (!CSound.Init())
                {
                    throw new CLoadingException("playback");
                }
                CLog.StopBenchmark("Init Playback");

                Application.DoEvents();

                // Init Record
                CLog.StartBenchmark("Init Record");
                if (!CRecord.Init())
                {
                    throw new CLoadingException("record");
                }
                CLog.StopBenchmark("Init Record");

                Application.DoEvents();

                // Init VideoDecoder
                CLog.StartBenchmark("Init Videodecoder");
                if (!CVideo.Init())
                {
                    throw new CLoadingException("video");
                }
                CLog.StopBenchmark("Init Videodecoder");

                Application.DoEvents();

                // Init Database
                CLog.StartBenchmark("Init Database");
                if (!CDataBase.Init())
                {
                    throw new CLoadingException("database");
                }
                CLog.StopBenchmark("Init Database");

                Application.DoEvents();

                //Init Webcam
                CLog.StartBenchmark("Init Webcam");
                if (!CWebcam.Init())
                {
                    throw new CLoadingException("webcam");
                }
                CLog.StopBenchmark("Init Webcam");

                Application.DoEvents();

                // Init Background Music
                CLog.StartBenchmark("Init Background Music");
                CBackgroundMusic.Init();
                CLog.StopBenchmark("Init Background Music");

                Application.DoEvents();

                // Init Profiles
                CLog.StartBenchmark("Init Profiles");
                CProfiles.Init();
                CLog.StopBenchmark("Init Profiles");

                Application.DoEvents();

                // Init Fonts
                CLog.StartBenchmark("Init Fonts");
                if (!CFonts.Init())
                {
                    throw new CLoadingException("fonts");
                }
                CLog.StopBenchmark("Init Fonts");

                Application.DoEvents();

                // Theme System
                CLog.StartBenchmark("Init Theme");
                if (!CThemes.Init())
                {
                    throw new CLoadingException("theme");
                }
                CLog.StopBenchmark("Init Theme");

                CLog.StartBenchmark("Load Theme");
                CThemes.Load();
                CLog.StopBenchmark("Load Theme");

                Application.DoEvents();

                // Load Cover
                CLog.StartBenchmark("Init Cover");
                if (!CCover.Init())
                {
                    throw new CLoadingException("covertheme");
                }
                CLog.StopBenchmark("Init Cover");

                Application.DoEvents();

                // Init Screens
                CLog.StartBenchmark("Init Screens");
                CGraphics.Init();
                CLog.StopBenchmark("Init Screens");

                Application.DoEvents();

                // Init Server
                CLog.StartBenchmark("Init Server");
                CVocaluxeServer.Init();
                CLog.StopBenchmark("Init Server");

                Application.DoEvents();

                // Init Input
                CLog.StartBenchmark("Init Input");
                CController.Init();
                CController.Connect();
                CLog.StopBenchmark("Init Input");

                Application.DoEvents();

                // Init Game;
                CLog.StartBenchmark("Init Game");
                CGame.Init();
                CProfiles.Update();
                CConfig.UsePlayers();
                CLog.StopBenchmark("Init Game");

                Application.DoEvents();

                // Init Party Modes;
                CLog.StartBenchmark("Init Party Modes");
                if (!CParty.Init())
                {
                    throw new CLoadingException("Party Modes");
                }
                CLog.StopBenchmark("Init Party Modes");

                Application.DoEvents();
                //Only reasonable point to call GC.Collect() because initialization may cause lots of garbage
                //Rely on GC doing its job afterwards and call Dispose methods where appropriate
                GC.Collect();
                CLog.StopBenchmark("Init Program");
            }
            catch (Exception e)
            {
                MessageBox.Show("Error on start up: " + e.Message);
                CLog.LogError("Error on start up: " + e);
                if (_SplashScreen != null)
                {
                    _SplashScreen.Close();
                }
                _CloseProgram();
                return;
            }
            Application.DoEvents();

            // Start Main Loop
            if (_SplashScreen != null)
            {
                _SplashScreen.Close();
            }

            CDraw.MainLoop();
        }