Example #1
0
 public string ExitCommand(string[] args, out gxtVerbosityLevel v)
 {
     string result = "Exiting the application...";
     v = gxtVerbosityLevel.INFORMATIONAL;
     gxtRoot.Singleton.Unload();
     return result;
 }
Example #2
0
 public DummyProcess(TimeSpan duration, gxtVerbosityLevel verbosity, string msg)
     : base(true)
 {
     EndTime = duration;
     Verbosity = verbosity;
     message = msg;
 }
Example #3
0
 public string FPSCommand(string[] args, out gxtVerbosityLevel v)
 {
     string result = gxtDebug.GetFPS().ToString();
     v = gxtVerbosityLevel.INFORMATIONAL;
     return result;
 }
Example #4
0
        public string ResolutionCommand(string[] args, out gxtVerbosityLevel v)
        {
            if (args != null && args.Length == 2)
            {
                int width, height;
                bool parseSucceeded = int.TryParse(args[0], out width);
                if (parseSucceeded)
                {
                    parseSucceeded = int.TryParse(args[1], out height);
                    if (parseSucceeded)
                    {
                        bool requestSucceeded = gxtDisplayManager.Singleton.SetResolution(width, height, gxtDisplayManager.Singleton.FullScreen);
                        // possibly have a different request if it fails
                        v = gxtVerbosityLevel.SUCCESS;
                        return "Resolution request sent!";
                    }
                    else
                    {
                        v = gxtVerbosityLevel.WARNING;
                        return "Couldn't parse height parameter";
                    }
                }
                else
                {
                    v = gxtVerbosityLevel.WARNING;
                    return "Couldn't parse width parameter";
                }
            }
            else if (args.Length == 3)
            {
                int width, height;
                bool parseSucceeded = int.TryParse(args[0], out width);
                if (parseSucceeded)
                {
                    parseSucceeded = int.TryParse(args[1], out height);
                    if (parseSucceeded)
                    {
                        bool full;
                        bool fullValid = bool.TryParse(args[2], out full);
                        if (fullValid)
                        {
                            bool requestSucceeded = gxtDisplayManager.Singleton.SetResolution(width, height, full);

                            // possibly have a different request if it fails
                            v = gxtVerbosityLevel.SUCCESS;
                            return "Resolution request sent!";
                        }
                        else
                        {
                            v = gxtVerbosityLevel.WARNING;
                            return "FullScreen parameter invalid!";
                        }
                    }
                    else
                    {
                        v = gxtVerbosityLevel.WARNING;
                        return "Couldn't parse height parameter";
                    }
                }
                else
                {
                    v = gxtVerbosityLevel.WARNING;
                    return "Couldn't parse width parameter";
                }
            }
            else
            {
                v = gxtVerbosityLevel.WARNING;
                return "Must pass in arguments for width and height!";
            }
        }
Example #5
0
        /// <summary>
        /// Writeline, with verbosiy arguments
        /// </summary>
        /// <param name="verbosity">Verbosity</param>
        /// <param name="format">Formatted string</param>
        public void WriteLineV(gxtVerbosityLevel verbosity, string format)
        {
            if (!enabled) return;
            gxtVerbosityLevel activeVerbosity = ActiveVerbosityLevel;
            if (verbosity > activeVerbosity) return;

            string[] entries = format.Split('\n');
            int entry = 0;

            while (entry < entries.Length)
            {
                int idx = logWriteIndex;
                if (logWriteIndex == logBufferSize)
                {
                    idx = logBufferSize - 1;
                    int i;
                    for (i = 0; i < logBufferSize - 1; ++i)
                    {
                        logBufferNodes[i].DetachDrawable(logBufferEntries[i]);
                        logBufferEntries[i].Text = logBufferEntries[i + 1].Text;
                        logBufferEntries[i].Material = logBufferEntries[i + 1].Material;
                    }
                    logBufferNodes[idx].DetachDrawable(logBufferEntries[idx]);
                    for (i = 0; i < logBufferSize - 1; ++i)
                    {
                        logBufferNodes[i].AttachDrawable(logBufferEntries[i]);
                    }
                }

                gxtIMaterial logMaterial = GetLogMaterial(verbosity);
                logBufferEntries[idx].Material = logMaterial;

                if (UseTimeStamps)
                {
                    logBufferNodes[idx].DetachAllDrawables();
                    logBufferEntries[idx].Text = DateTime.Now.ToString("hh:mm:ss.fff tt :") + format;
                    logBufferNodes[idx].AttachDrawable(logBufferEntries[idx]);
                }
                else
                {
                    logBufferNodes[idx].DetachAllDrawables();
                    logBufferEntries[idx].Text = format;
                    logBufferNodes[idx].AttachDrawable(logBufferEntries[idx]);
                }
                logWriteIndex = gxtMath.IMin(logWriteIndex + 1, logBufferSize);
                ++entry;
            }
            AdjustConsoleTextPos();
        }
Example #6
0
 /// <summary>
 /// Simple function that gets the console color based on the verbosity level
 /// Keep updated if number of verbosity levels grow
 /// </summary>
 /// <param name="v">Verbosity</param>
 /// <returns>Matching Console Color</returns>
 /*
 private Color GetLogColor(gxtVerbosityLevel v)
 {
     if (v == gxtVerbosityLevel.CRITICAL)
         return CriticalColor;
     else if (v == gxtVerbosityLevel.WARNING)
         return WarningColor;
     else if (v == gxtVerbosityLevel.SUCCESS)
         return SuccessColor;
     else
         return InformationalColor;
 }
 */
 /// <summary>
 /// Retrieves appropriate material for the given verbosity level
 /// </summary>
 /// <param name="v">Verbosity Level</param>
 /// <returns>Log Material</returns>
 private gxtIMaterial GetLogMaterial(gxtVerbosityLevel v)
 {
     if (v == gxtVerbosityLevel.CRITICAL)
         return criticalMaterial;
     else if (v == gxtVerbosityLevel.WARNING)
         return warningMaterial;
     else if (v == gxtVerbosityLevel.SUCCESS)
         return successMaterial;
     else
         return informationalMaterial;
 }
Example #7
0
 /// <summary>
 /// Simple function that gets the console color based on the verbosity level
 /// Keep updated if number of verbosity levels grow
 /// </summary>
 /// <param name="v">Verbosity</param>
 /// <returns>Matching Log Color</returns>
 private string GetLogColor(gxtVerbosityLevel v)
 {
     if (v == gxtVerbosityLevel.CRITICAL)
         return CriticalColor;
     else if (v == gxtVerbosityLevel.WARNING)
         return WarningColor;
     else if (v == gxtVerbosityLevel.SUCCESS)
         return SuccessColor;
     else
         return InformationalColor;
 }
Example #8
0
        /// <summary>
        /// Note: consider making a struct that packages all these settings, or one or two structs
        /// At this rate, the number of variables for this function is growing to the point that it 
        /// deteroriates readability
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="consoleHeight"></param>
        /// <param name="initEnabled"></param>
        /// <param name="verbosity"></param>
        /// <param name="useGlobalVerbosity"></param>
        /// <param name="useTimeStamps"></param>
        /// <param name="consoleFont"></param>
        /// <param name="initOpen"></param>
        /// <param name="consolePrefix"></param>
        /// <param name="consoleTextRenderDepth"></param>
        /// <param name="consoleBackgroundRenderDepth"></param>
        /// <param name="logBufferSize"></param>
        public void Initialize(gxtSceneGraph scene, float consoleHeight, bool initEnabled = true, gxtVerbosityLevel verbosity = gxtVerbosityLevel.INFORMATIONAL, bool useGlobalVerbosity = true, bool useTimeStamps = false, SpriteFont consoleFont = null, 
            bool initOpen = true, string consolePrefix = "console: ", float consoleTextRenderDepth = 0.0f, float consoleBackgroundRenderDepth = 1.0f, int logBufferSize = 6)
        {
            gxtDebug.Assert(logBufferSize >= 0);
            gxtDebug.Assert(gxtDisplayManager.SingletonIsInitialized);

            this.enabled = initEnabled;
            this.useGlobalVerbosity = useGlobalVerbosity;
            this.verbosityLevel = verbosity;
            this.useTimeStamps = useTimeStamps;
            this.isOpen = initOpen;
            this.text = string.Empty;

            // all these colors and depths should be taken as parameters
            this.consoleSpriteFont = consoleFont;
            this.informationalMaterial = new gxtMaterial(isOpen, Color.White, consoleTextRenderDepth);
            this.successMaterial = new gxtMaterial(isOpen, Color.Green, consoleTextRenderDepth);
            this.warningMaterial = new gxtMaterial(isOpen, Color.Yellow, consoleTextRenderDepth);
            this.criticalMaterial = new gxtMaterial(isOpen, Color.Red, consoleTextRenderDepth);
            this.inputMaterial = new gxtMaterial(isOpen, Color.Black, consoleTextRenderDepth);
            this.backgroundMaterial = new gxtMaterial(isOpen, new Color(255, 255, 255, 65), consoleBackgroundRenderDepth);

            this.resolutionWidth = gxtDisplayManager.Singleton.ResolutionWidth;
            this.resolutionHeight = gxtDisplayManager.Singleton.ResolutionHeight;
            this.consoleWidth = resolutionWidth;
            this.consoleHeight = gxtMath.Clamp(consoleHeight, 0.0f, resolutionHeight);
            gxtDisplayManager.Singleton.resolutionChanged += OnResolutionChange;
            // these should be taken as parameters
            this.horizontalPadding = 15.0f;
            this.verticalPadding = 0.0f;
            this.verticalTextSpacing = 5.0f;

            // background rectangle and container node
            backgroundRectangle = new gxtRectangle(consoleWidth, consoleHeight, backgroundMaterial);
            consoleNode = new gxtSceneNode();
            consoleNode.Position = new Vector2(0.0f, (-resolutionHeight * 0.5f) + (consoleHeight * 0.5f));
            consoleNode.AttachDrawable(backgroundRectangle);

            // textnode
            this.consolePrefix = consolePrefix;
            consoleTextField = new gxtTextField(consoleFont, consolePrefix + "_", inputMaterial);
            consoleTextNode = new gxtSceneNode();
            consoleTextNode.AttachDrawable(consoleTextField);

            consoleNode.AddChild(consoleTextNode);

            this.logBufferSize = logBufferSize;
            this.logWriteIndex = 0;

            logBufferNodes = new gxtSceneNode[logBufferSize];
            logBufferEntries = new gxtTextField[logBufferSize];

            // consider using a fixed size queue instead
            gxtISceneNode topAnchor = new gxtSceneNode();
            topAnchor.Position = new Vector2((consoleWidth * 0.5f) - horizontalPadding, (-consoleHeight * 0.5f) + verticalPadding);
            logBufferNodes[0] = topAnchor;
            logBufferEntries[0] = new gxtTextField(consoleFont);
            logBufferEntries[0].Material = new gxtMaterial();
            logBufferNodes[0].AttachDrawable(logBufferEntries[0]);

            gxtISceneNode current = topAnchor;
            for (int i = 1; i < logBufferSize; ++i)
            {
                gxtISceneNode node = new gxtSceneNode();
                logBufferNodes[i] = node;
                current.AddChild(node);
                node.Position = new Vector2(0.0f, verticalTextSpacing);
                current = node;

                gxtTextField tf = new gxtTextField(consoleFont);
                logBufferEntries[i] = tf;
                tf.Material = new gxtMaterial();
                current.AttachDrawable(tf);
            }

            consoleNode.AddChild(topAnchor);
            scene.AddNode(consoleNode);

            AdjustConsoleTextPos();
        }
Example #9
0
        /// <summary>
        /// Writes a pre formatted string to the logger
        /// </summary>
        /// <param name="verbosity">Verbosity</param>
        /// <param name="format">Formatted string</param>
        public void WriteLineV(gxtVerbosityLevel verbosity, string format)
        {
            if (!Enabled) return;
            gxtVerbosityLevel activeVerbosity = ActiveVerbosityLevel;
            if (verbosity > activeVerbosity) return;

            string color = GetLogColor(verbosity);
            // need to split on linebreaks
            // \n is not a line break in HTML
            string[] lines = format.Split('\n');
            if (UseTimeStamps)
            {
                string timeStamp = DateTime.Now.ToString("hh:mm:ss.fff tt : ");
                for (int i = 0; i < lines.Length; ++i)
                {
                    streamWriter.WriteLine("<span style=\"color:" + color + "\">" + timeStamp + lines[i] + "</span><br>");
                }
            }
            else
            {
                for (int i = 0; i < lines.Length; ++i)
                {
                    streamWriter.WriteLine("<span style=\"color:" + color + "\">" + lines[i] + "</span><br>");
                }
            }
        }
Example #10
0
        /// <summary>
        /// Sets up the listener with the given settings
        /// </summary>
        /// <param name="initEnabled">Enabled flag</param>
        /// <param name="verbosity">Logger verbosity level</param>
        /// <param name="useGlobalVerbosity">If using the global verbosity</param>
        /// <param name="useTimeStamps">Timestamps before each log entry</param>
        /// <param name="relativePath">Relative file path of the file</param>
        /// <param name="informationalColor">Informational HTML color</param>
        /// <param name="successColor">Success HTML color</param>
        /// <param name="warningColor">Warning HTML color</param>
        /// <param name="criticalColor">Critical HTML color</param>
        public void Initialize(bool initEnabled = true, gxtVerbosityLevel verbosity = gxtVerbosityLevel.INFORMATIONAL, bool useGlobalVerbosity = true, bool useTimeStamps = true, string relativePath = @"\log\", string informationalColor = "000000", string successColor = "#009900",
            string warningColor = "#FFCC00", string criticalColor = "#CC0000")
        {
            Enabled = initEnabled;

            UseGlobalVerbosity = useGlobalVerbosity;
            Verbosity = verbosity;

            InformationalColor = informationalColor;
            SuccessColor = successColor;
            WarningColor = warningColor;
            CriticalColor = criticalColor;

            string timeStamp = DateTime.Now.ToString("yyyy.MM.dd-hh.mm.ss");

            // warning, this is PC specific
            string directory = Directory.GetCurrentDirectory() + relativePath;
            DirectoryInfo directoryInfo = new DirectoryInfo(directory);
            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }

            filePath = directory + timeStamp + "_log.html";

            streamWriter = new StreamWriter(filePath);
            streamWriter.AutoFlush = true;
        }
Example #11
0
 /// <summary>
 /// Simple function that gets the console color based on the verbosity level
 /// Keep updated if number of verbosity levels grow
 /// </summary>
 /// <param name="v">Verbosity</param>
 /// <returns>Matching Console Color</returns>
 private ConsoleColor GetLogColor(gxtVerbosityLevel v)
 {
     if (v == gxtVerbosityLevel.CRITICAL)
         return criticalConsoleColor;
     else if (v == gxtVerbosityLevel.WARNING)
         return warningConsoleColor;
     else if (v == gxtVerbosityLevel.SUCCESS)
         return successConsoleColor;
     else
         return informationalConsoleColor;
 }
Example #12
0
 /// <summary>
 /// Writeline, with verbosiy arguments
 /// </summary>
 /// <param name="verbosity">Verbosity</param>
 /// <param name="format">Formatted string</param>
 public void WriteLineV(gxtVerbosityLevel verbosity, string format)
 {
     if (!enabled) return;
     gxtVerbosityLevel activeVerbosity = ActiveVerbosityLevel;
     if (verbosity > activeVerbosity) return;
     ConsoleColor color = GetLogColor(verbosity);
     Console.ForegroundColor = color;
     if (UseTimeStamps)
         Console.WriteLine(DateTime.Now.ToString("hh:mm:ss.fff tt : ") + format);
     else
         Console.WriteLine(format);
 }
Example #13
0
        /// <summary>
        /// Initializes the ConsoleLogger
        /// Every parameter has a default
        /// </summary>
        /// <param name="initEnabled">Enabled in init</param>
        /// <param name="verbosity">Logger Verbosity</param>
        /// <param name="useGlobalVerbosity">Use Global Verbosity?</param>
        /// <param name="useTimeStamps">Timestamps?</param>
        /// <param name="windowTitle">Window Title</param>
        /// <param name="informationalColor">Informational Console Color</param>
        /// <param name="successColor">Success Console Color</param>
        /// <param name="warningColor">Warning Console Color</param>
        /// <param name="criticalColor">Critical Console Color</param>
        public void Initialize(bool initEnabled = true, gxtVerbosityLevel verbosity = gxtVerbosityLevel.INFORMATIONAL, bool useGlobalVerbosity = true, bool useTimeStamps = false, string windowTitle = "GXT Console Log", 
            ConsoleColor informationalColor = ConsoleColor.White, ConsoleColor successColor = ConsoleColor.Green, ConsoleColor warningColor = ConsoleColor.Yellow, ConsoleColor criticalColor = ConsoleColor.Red)
        {
            Enabled = initEnabled;
            UseGlobalVerbosity = useGlobalVerbosity;
            Verbosity = verbosity;
            UseTimeStamps = useTimeStamps;

            InformationalColor = informationalColor;
            SuccessColor = successColor;
            WarningColor = warningColor;
            CriticalColor = criticalColor;
            WindowTitle = windowTitle;
        }