Beispiel #1
0
        // This calculates the sector brightness level
        public int CalculateBrightness(int level)
        {
            float flevel = level;

            // Simulat doom light levels
            if ((level < 192) && General.Map.Config.DoomLightLevels)
            {
                flevel = (192.0f - (float)(192 - level) * 1.5f);
            }

            byte       blevel = (byte)General.Clamp((int)flevel, 0, 255);
            PixelColor c      = new PixelColor(255, blevel, blevel, blevel);

            return(c.ToInt());
        }
Beispiel #2
0
        // This updates the text if needed
        internal void Update(float translatex, float translatey, float scalex, float scaley)
        {
            RectangleF absview;
            float      beginx = 0;
            float      beginy = 0;

            byte[]     textbytes;
            DataStream stream;

            // Check if transformation changed and needs to be updated
            if (transformcoords)
            {
                if ((translatex != lasttranslatex) ||
                    (translatey != lasttranslatey) ||
                    (scalex != lastscalex) ||
                    (scaley != lastscaley))
                {
                    updateneeded = true;
                }
            }

            // Update if needed
            if (updateneeded)
            {
                // Only build when there are any vertices
                if (text.Length > 0)
                {
                    // Do we have to make a new buffer?
                    if ((textbuffer == null) || (text.Length > capacity))
                    {
                        // Dispose previous
                        if (textbuffer != null)
                        {
                            textbuffer.Dispose();
                        }

                        // Determine new capacity
                        if (capacity < text.Length)
                        {
                            capacity = text.Length;
                        }

                        // Create the buffer
                        textbuffer = new VertexBuffer(General.Map.Graphics.Device,
                                                      capacity * 12 * FlatVertex.Stride,
                                                      Usage.Dynamic | Usage.WriteOnly,
                                                      VertexFormat.None, Pool.Default);
                    }

                    // Transform?
                    if (transformcoords)
                    {
                        // Calculate absolute coordinates
                        Vector2D lt = new Vector2D(rect.Left, rect.Top);
                        Vector2D rb = new Vector2D(rect.Right, rect.Bottom);
                        lt      = lt.GetTransformed(translatex, translatey, scalex, scaley);
                        rb      = rb.GetTransformed(translatex, translatey, scalex, scaley);
                        absview = new RectangleF(lt.x, lt.y, rb.x - lt.x, rb.y - lt.y);
                    }
                    else
                    {
                        // Fixed coordinates
                        absview = rect;
                    }

                    // Calculate text dimensions
                    size = General.Map.Graphics.Font.GetTextSize(text, scale);

                    // Align the text horizontally
                    switch (alignx)
                    {
                    case TextAlignmentX.Left: beginx = absview.X; break;

                    case TextAlignmentX.Center: beginx = absview.X + (absview.Width - size.Width) * 0.5f; break;

                    case TextAlignmentX.Right: beginx = absview.X + absview.Width - size.Width; break;
                    }

                    // Align the text vertically
                    switch (aligny)
                    {
                    case TextAlignmentY.Top: beginy = absview.Y; break;

                    case TextAlignmentY.Middle: beginy = absview.Y + (absview.Height - size.Height) * 0.5f; break;

                    case TextAlignmentY.Bottom: beginy = absview.Y + absview.Height - size.Height; break;
                    }

                    // Get the ASCII bytes for the text
                    textbytes = Encoding.ASCII.GetBytes(text);

                    // Lock the buffer
                    stream = textbuffer.Lock(0, capacity * 12 * FlatVertex.Stride,
                                             LockFlags.Discard | LockFlags.NoSystemLock);

                    // Go for all chars in text to create the backgrounds
                    float textx = beginx;
                    foreach (byte b in textbytes)
                    {
                        General.Map.Graphics.Font.SetupVertices(stream, b, scale, backcolor.ToInt(),
                                                                ref textx, beginy, size.Height, 0.5f);
                    }

                    // Go for all chars in text to create the text
                    textx = beginx;
                    foreach (byte b in textbytes)
                    {
                        General.Map.Graphics.Font.SetupVertices(stream, b, scale, color.ToInt(),
                                                                ref textx, beginy, size.Height, 0.0f);
                    }

                    // Done filling the vertex buffer
                    textbuffer.Unlock();
                    stream.Dispose();

                    // Calculate number of triangles
                    numfaces = text.Length * 4;
                }
                else
                {
                    // No faces in polygon
                    numfaces = 0;
                    size     = new SizeF(0f, 0f);
                }

                // Text updated
                updateneeded = false;
            }
        }