Exemplo n.º 1
0
        //

        public SlaveWindow(string[] arg)
        {
            deltaTime = 0;

            //just dont die for now
            Program.ScreenX = int.Parse(arg[1]);
            Program.ScreenY = int.Parse(arg[2]);
            _file           = MemoryMappedFile.OpenExisting(arg[0]);
            _pipe           = new NamedPipeClientStream(arg[0]);
            _pipe.Connect();

            _data            = new SlaveManager.SlaveData();
            _data.foreColors = new ConsoleColor[Program.ScreenX, Program.ScreenY];
            _data.backColors = new ConsoleColor[Program.ScreenX, Program.ScreenY];
            _data.characters = new char[Program.ScreenX, Program.ScreenY];

            display = new SlaveDisplay();
            new Thread(() =>
            {
                while (_alive)
                {
                    if (!_pipe.IsConnected)
                    {
                        _alive = false;
                    }
                    byte[] messageBuffer = new byte[520];
                    _pipe.Read(messageBuffer, 0, 520);
                    string input = Encoding.UTF8.GetString(messageBuffer);
                    if (input.StartsWith("close"))
                    {
                        this._alive = false;
                    }
                    string[] args = input.Split("|");
                    switch (args[0])
                    {
                    case "SetWindowPos":
                        display.windowManager.moveWindow(float.Parse(args[1]), float.Parse(args[2]));
                        break;

                    case "SetWindowEase":
                        if (_easeGo)
                        {
                            display.windowManager.moveWindow(_endX, _endY);
                            _timepassed = 0;
                        }
                        _startX     = float.Parse(args[1]);
                        _startY     = float.Parse(args[2]);
                        _endX       = float.Parse(args[3]);
                        _endY       = float.Parse(args[4]);
                        _duration   = float.Parse(args[5]);
                        _easing     = args[6];
                        _timepassed = 0;
                        _easeGo     = true;
                        break;

                    case "StopEase":
                        _timepassed = _duration;
                        break;

                    case "SetTitle":
                        Console.Title = args[1];
                        break;

                    default:
                        break;
                    }
                }
            }).Start();
            while (_alive)
            {
                _stopwatch.Start();


                var stream    = _file.CreateViewStream();
                int curOffset = 0;
                for (int x = 0; x < Program.ScreenX; x++)
                {
                    for (int y = 0; y < Program.ScreenY; y++)
                    {
                        byte[] buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        _data.foreColors[x, y] = (ConsoleColor)BitConverter.ToInt32(buffer);
                        curOffset += 4;

                        stream.Read(buffer, 0, 4);
                        _data.backColors[x, y] = (ConsoleColor)BitConverter.ToInt32(buffer);
                        curOffset += 4;

                        buffer = new byte[2];
                        stream.Read(buffer, 0, 2);
                        _data.characters[x, y] = BitConverter.ToChar(buffer);
                        curOffset += 2;
                    }
                }
                display.DrawFrame(_data);
                //
                if (_easeGo)
                {
                    if (_timepassed >= _duration)
                    {
                        display.windowManager.moveWindow(_endX, _endY);
                        _easeGo = false;
                    }
                    else
                    {
                        float x = (_startX) + ((_endX - _startX) * Ease.byName[_easing](_timepassed / _duration));
                        float y = (_startY) + ((_endY - _startY) * Ease.byName[_easing](_timepassed / _duration));
                        display.windowManager.moveWindow(x, y);
                    }
                    _timepassed += (float)deltaTime;
                }

                Thread.Sleep(1); //just in case
                _stopwatch.Stop();
                deltaTime = _stopwatch.ElapsedMilliseconds * 0.001;
                _stopwatch.Reset();
            }
        }
Exemplo n.º 2
0
        public void DrawFrame(SlaveManager.SlaveData data)
        {
            //remove objects from main list that need to be

            //add objects to main list that need to be

            ConsoleColor[,] finalForeColors = new ConsoleColor[Program.ScreenX, Program.ScreenY];
            ConsoleColor[,] finalBackColors = new ConsoleColor[Program.ScreenX, Program.ScreenY];
            char[,] finalChars = new char[Program.ScreenX, Program.ScreenY];
            //sosorry


            //DisplayData newData = screenFilter.RunFilt(finalForeColors, finalBackColors, finalChars);
            finalForeColors = data.foreColors;
            finalBackColors = data.backColors;
            finalChars      = data.characters;

            //not gonna try drawing this way anymore...

            /*
             * Console.SetCursorPosition(0, 0);
             * for (int y = 0; y < Program.ScreenY; y++)
             * {
             *  for (int x = 0; x < Program.ScreenX; x++)
             *  {
             *      //only draw changes
             *      if(currentBackColors[x, y] != finalBackColors[x,y] || currentForeColors[x,y] != finalForeColors[x,y] || currentFinalChars[x,y] != finalChars[x,y])
             *      {
             *          Console.SetCursorPosition(x, Program.ScreenY - y);
             *          Console.ForegroundColor = finalForeColors[x, y];
             *          Console.BackgroundColor = finalBackColors[x, y];
             *          Console.Write(finalChars[x, y]);
             *      }
             *
             *  }
             * }
             */
            //here we go oh boy.
            WindowManager.CHAR_INFO[] buffer = new WindowManager.CHAR_INFO[Program.ScreenX * Program.ScreenY];

            for (int y = 0; y < Program.ScreenY; y++)
            {
                for (int x = 0; x < Program.ScreenX; x++)
                {
                    ushort attributes = None;
                    switch (finalForeColors[x, Program.ScreenY - (y + 1)])
                    {
                    case ConsoleColor.Black:
                        attributes = None;
                        break;

                    case ConsoleColor.DarkBlue:
                        attributes = FOREGROUND_BLUE;
                        break;

                    case ConsoleColor.DarkGreen:
                        attributes = FOREGROUND_GREEN;
                        break;

                    case ConsoleColor.DarkCyan:
                        attributes = (ushort)(FOREGROUND_GREEN | FOREGROUND_BLUE);
                        break;

                    case ConsoleColor.DarkRed:
                        attributes = FOREGROUND_RED;
                        break;

                    case ConsoleColor.DarkMagenta:
                        attributes = (ushort)(FOREGROUND_RED | FOREGROUND_BLUE);
                        break;

                    case ConsoleColor.DarkYellow:
                        attributes = (ushort)(FOREGROUND_RED | FOREGROUND_GREEN);
                        break;

                    case ConsoleColor.Gray:
                        attributes = (ushort)(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
                        break;

                    case ConsoleColor.DarkGray:
                        attributes = FOREGROUND_INTENSITY;
                        break;

                    case ConsoleColor.Blue:
                        attributes = (ushort)(FOREGROUND_BLUE | FOREGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Green:
                        attributes = (ushort)(FOREGROUND_GREEN | FOREGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Cyan:
                        attributes = (ushort)(FOREGROUND_BLUE | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Red:
                        attributes = (ushort)(FOREGROUND_RED | FOREGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Magenta:
                        attributes = (ushort)(FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Yellow:
                        attributes = (ushort)(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
                        break;

                    case ConsoleColor.White:
                        attributes = (ushort)(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
                        break;

                    default:
                        break;
                    }

                    ushort backattribute = None;
                    switch (finalBackColors[x, Program.ScreenY - (y + 1)])
                    {
                    case ConsoleColor.Black:
                        backattribute = None;
                        break;

                    case ConsoleColor.DarkBlue:
                        backattribute = BACKGROUND_BLUE;
                        break;

                    case ConsoleColor.DarkGreen:
                        backattribute = BACKGROUND_GREEN;
                        break;

                    case ConsoleColor.DarkCyan:
                        backattribute = (ushort)(BACKGROUND_GREEN | BACKGROUND_BLUE);
                        break;

                    case ConsoleColor.DarkRed:
                        backattribute = BACKGROUND_RED;
                        break;

                    case ConsoleColor.DarkMagenta:
                        backattribute = (ushort)(BACKGROUND_RED | BACKGROUND_BLUE);
                        break;

                    case ConsoleColor.DarkYellow:
                        backattribute = (ushort)(BACKGROUND_RED | BACKGROUND_GREEN);
                        break;

                    case ConsoleColor.Gray:
                        backattribute = (ushort)(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
                        break;

                    case ConsoleColor.DarkGray:
                        backattribute = BACKGROUND_INTENSITY;
                        break;

                    case ConsoleColor.Blue:
                        backattribute = (ushort)(BACKGROUND_BLUE | BACKGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Green:
                        backattribute = (ushort)(BACKGROUND_GREEN | BACKGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Cyan:
                        backattribute = (ushort)(BACKGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Red:
                        backattribute = (ushort)(BACKGROUND_RED | BACKGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Magenta:
                        backattribute = (ushort)(BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY);
                        break;

                    case ConsoleColor.Yellow:
                        backattribute = (ushort)(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY);
                        break;

                    case ConsoleColor.White:
                        backattribute = (ushort)(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
                        break;

                    default:
                        break;
                    }

                    //im so sorry for these switch cases interop is not nice
                    attributes = (ushort)(backattribute | attributes);

                    buffer[y * Program.ScreenX + x] = new WindowManager.CHAR_INFO {
                        UnicodeChar = finalChars[x, Program.ScreenY - (y + 1)], Attributes = attributes
                    };
                }
            }
            //buffer[1 + 1] = new WindowManager.CHAR_INFO { UnicodeChar = 'h', Attributes = (ushort)(BACKGROUND_BLUE | FOREGROUND_GREEN ) };
            windowManager.RenderBuffer(buffer);
            //save changes
            currentBackColors = finalBackColors;
            currentForeColors = finalForeColors;
            currentFinalChars = finalChars;
        }