Beispiel #1
0
        /// <summary>
        /// Renders this face.
        /// </summary>
        public void Render(int offsetX, int offsetY)
        {
            renderingStack.Push(this);

            try
            {
                if (this.Background.Color.HasValue && Size.Width.HasValue && Size.Height.HasValue)
                {
                    Rectangle DrawArea = new Rectangle(offsetX, offsetY, Size.Width.Value, Size.Height.Value);

                    Gl.glMatrixMode(Gl.GL_MODELVIEW);
                    Gl.glPushMatrix();
                    Gl.glLoadIdentity();

                    Gl.glScalef(Game.Scale, Game.Scale, 1);

                    Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);

                    GlHelper.SetColor(this.Background.Color.Value);

                    Gl.glBegin(Gl.GL_QUADS);
                    Gl.glVertex3f(DrawArea.Left, DrawArea.Top, 0);
                    Gl.glVertex3f(DrawArea.Right, DrawArea.Top, 0);
                    Gl.glVertex3f(DrawArea.Right, DrawArea.Bottom, 0);
                    Gl.glVertex3f(DrawArea.Left, DrawArea.Bottom, 0);
                    Gl.glEnd();

                    Gl.glColor3f(1, 1, 1);
                    Gl.glPopMatrix();
                }

                if (this.Background.Image.HasValue)
                {
                    string currentImageId = this.Background.Image.Value;

                    if (string.IsNullOrEmpty(lastImageId) || currentImageId != lastImageId)
                    {
                        if (lastTexture != null)
                        {
                            lastTexture.RemoveUser();
                        }

                        lastImageId = currentImageId;
                        lastTexture = Game.TextureManager.GetTexture(this.Background.Image.Value);
                    }

                    lastTexture.Draw(offsetX, offsetY);
                }

                // TODO: Implement background repeat, preferably by cleverly using texture coordinates on the image rendering quad.
                // This is probably impossible for images in tile-sets (and any with custom DrawArea) without the use of shaders.
                // We can either split it in multiple quads (one tile each) - that's quite wasteful, or we can make the TextureManagerItem
                // split the original tile-set into multiple autonomous textures (tile-sets aren't implemented yet anyway)
                if (this.Background.Repeat.GetValueOrDefault(GuiRepeatStyle.NoRepeat) != GuiRepeatStyle.NoRepeat)
                {
                    throw new NotSupportedException("Background repeat not supported yet.");
                }

                foreach (var control in Controls)
                {
                    control.Render(offsetX, offsetY);
                }
            }
            finally
            {
                renderingStack.Pop();
            }
        }