Exemple #1
0
        /// <summary>
        /// Adds or updates an OSD item.
        /// </summary>
        /// <param name="text">Item text</param>
        /// <param name="pos_x">Item X position</param>
        /// <param name="pos_y">Item Y position</param>
        /// <param name="color">Text color</param>
        /// <param name="identifier">Unique identifier, set to be able to update the item without recreating it</param>
        /// <param name="timer">Duration in frames, -1 for permanent, don't set to keep the previous value when updating an existing item</param>
        public void UpdateOSDItem(string text, int pos_x, int pos_y, RawColorBGRA color, string identifier = "", int timer = 0)
        {
            foreach (OSDItem osd in OSDItems)
            {
                if (osd.id != "" && osd.id == identifier)
                {
                    osd.text = text;
                    if (timer != 0)
                    {
                        osd.timer = timer;
                    }
                    osd.pos_x = pos_x - 8;
                    osd.pos_y = pos_y;
                    osd.color = color;
                    return;
                }
            }
            OSDItem newosd = new OSDItem();

            newosd.text  = text;
            newosd.id    = identifier;
            newosd.timer = timer;
            newosd.pos_x = pos_x - 8;
            newosd.pos_y = pos_y;
            newosd.color = color;
            OSDItems.Add(newosd);
        }
Exemple #2
0
        /// <summary>
        /// Updates OSD/message timers and deletes old messages. Returns true if 3D view needs to be redrawn.
        /// </summary>
        public bool UpdateTimer()
        {
            bool removeditems = false;

            foreach (var key in MessageList.Keys.ToList())
            {
                if (!timer_freeze)
                {
                    MessageList[key]--;
                }
                if (MessageList[key] <= 0)
                {
                    MessageList.Remove(key);
                    removeditems = true;
                }
            }
            foreach (OSDItem osd in OSDItems.ToList())
            {
                if (osd.timer != -1)
                {
                    osd.timer--;
                    if (osd.timer <= 0)
                    {
                        OSDItems.Remove(osd);
                        removeditems = true;
                    }
                }
            }
            return(removeditems);
        }
Exemple #3
0
        /// <summary>
        /// Draw pending log and OSD items. Call this before D3DDevice.Present().
        /// </summary>
        public void ProcessMessages()
        {
            StringBuilder MessageString = new StringBuilder();

            //Update timers on render because the form's timer freezes when stuff is rendered
            UpdateTimer();
            //Create the full log string
            foreach (var key in MessageList.Keys.ToList())
            {
                MessageString.AppendFormat(key + "\n");
            }
            textSprite.Begin(SpriteFlags.AlphaBlend);
            //Process OSD items
            if (show_osd)
            {
                foreach (OSDItem osd in OSDItems.ToList())
                {
                    SharpDX.Rectangle rec = EditorOptions.OnscreenFont.MeasureText(null, osd.text, FontDrawFlags.Right);
                    EditorOptions.OnscreenFont.DrawText(textSprite, osd.text, osd.pos_x + 1 + rec.X, osd.pos_y + 1, Color.Black.ToRawColorBGRA());
                    EditorOptions.OnscreenFont.DrawText(textSprite, osd.text, osd.pos_x + rec.X, osd.pos_y + 1, Color.Black.ToRawColorBGRA());
                    EditorOptions.OnscreenFont.DrawText(textSprite, osd.text, osd.pos_x - 1 + rec.X, osd.pos_y - 1, Color.Black.ToRawColorBGRA());
                    EditorOptions.OnscreenFont.DrawText(textSprite, osd.text, osd.pos_x + rec.X, osd.pos_y - 1, Color.Black.ToRawColorBGRA());
                    EditorOptions.OnscreenFont.DrawText(textSprite, osd.text, osd.pos_x + rec.X, osd.pos_y, osd.color);
                }
            }
            //Process messages
            if (MessageList.Count > 0 && d3ddevice != null)
            {
                EditorOptions.OnscreenFont.DrawText(textSprite, MessageString.ToString(), 9, 9, Color.Black.ToRawColorBGRA());
                EditorOptions.OnscreenFont.DrawText(textSprite, MessageString.ToString(), 7, 7, Color.Black.ToRawColorBGRA());
                EditorOptions.OnscreenFont.DrawText(textSprite, MessageString.ToString(), 7, 9, Color.Black.ToRawColorBGRA());
                EditorOptions.OnscreenFont.DrawText(textSprite, MessageString.ToString(), 9, 7, Color.Black.ToRawColorBGRA());
                EditorOptions.OnscreenFont.DrawText(textSprite, MessageString.ToString(), 8, 8, logcolor);
            }
            textSprite.End();
            //Refresh messages after drawing
            MessageString.Clear();
        }