<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpGL
{
    /// <summary>
    /// 支持UI布局的渲染器
    /// </summary>
    public class UIRenderer : RendererBase, ILayout
    {
        private ViewportSwitch viewportSwitch;
        private ScissorTestSwitch scissorTestSwitch;

        Renderer renderer;

        public Renderer Renderer
        {
            get { return renderer; }
            set { renderer = value; }
        }

        public UIRenderer(Renderer renderer,
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int zNear, int zFar)
        {
            this.Controls = new GLControlCollection(this);

            this.renderer = renderer;
            this.Anchor = anchor; this.Margin = margin;
            this.Size = size; this.zNear = zNear; this.zFar = zFar;
        }

        public ILayout Container { get; set; }

        public ICollection<ILayout> Controls { get; internal set; }

        public System.Windows.Forms.AnchorStyles Anchor { get; set; }

        public System.Windows.Forms.Padding Margin { get; set; }

        public System.Drawing.Point Location { get; set; }

        public System.Drawing.Size Size { get; set; }

        public int zNear { get; set; }

        public int zFar { get; set; }

        protected override void DoInitialize()
        {
            Renderer renderer = this.renderer;
            if (renderer != null)
            {
                renderer.Initialize();
            }

            this.viewportSwitch = new ViewportSwitch();
            this.scissorTestSwitch = new ScissorTestSwitch();

        }

        protected override void DoRender(RenderEventArgs arg)
        {
            Renderer renderer = this.renderer;
            if (renderer != null)
            {
                this.viewportSwitch.X = this.Location.X;
                this.viewportSwitch.Y = this.Location.Y;
                this.viewportSwitch.Width = this.Size.Width;
                this.viewportSwitch.Height = this.Size.Height;
                this.scissorTestSwitch.X = this.Location.X;
                this.scissorTestSwitch.Y = this.Location.Y;
                this.scissorTestSwitch.Width = this.Size.Width;
                this.scissorTestSwitch.Height = this.Size.Height;

                this.scissorTestSwitch.On();
                this.viewportSwitch.On();

                // 把所有在此之前渲染的内容都推到最远。
                OpenGL.Clear(OpenGL.GL_DEPTH_BUFFER_BIT);

                renderer.Render(arg);
<commit_msg>DoInitialize<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpGL
{
    /// <summary>
    /// 支持UI布局的渲染器
    /// </summary>
    public class UIRenderer : RendererBase, ILayout
    {
        private ViewportSwitch viewportSwitch;
        private ScissorTestSwitch scissorTestSwitch;

        Renderer renderer;

        public Renderer Renderer
        {
            get { return renderer; }
            set { renderer = value; }
        }

        public UIRenderer(Renderer renderer,
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int zNear, int zFar)
        {
            this.Controls = new GLControlCollection(this);

            this.renderer = renderer;
            this.Anchor = anchor; this.Margin = margin;
            this.Size = size; this.zNear = zNear; this.zFar = zFar;
        }

        public ILayout Container { get; set; }

        public ICollection<ILayout> Controls { get; internal set; }

        public System.Windows.Forms.AnchorStyles Anchor { get; set; }

        public System.Windows.Forms.Padding Margin { get; set; }

        public System.Drawing.Point Location { get; set; }

        public System.Drawing.Size Size { get; set; }

        public int zNear { get; set; }

        public int zFar { get; set; }

        protected override void DoInitialize()
        {
            this.viewportSwitch = new ViewportSwitch();
            this.scissorTestSwitch = new ScissorTestSwitch();

            Renderer renderer = this.renderer;
            if (renderer != null)
            {
                renderer.Initialize();
            }
        }

        protected override void DoRender(RenderEventArgs arg)
        {
            Renderer renderer = this.renderer;
            if (renderer != null)
            {
                this.viewportSwitch.X = this.Location.X;
                this.viewportSwitch.Y = this.Location.Y;
                this.viewportSwitch.Width = this.Size.Width;
                this.viewportSwitch.Height = this.Size.Height;
                this.scissorTestSwitch.X = this.Location.X;
                this.scissorTestSwitch.Y = this.Location.Y;
                this.scissorTestSwitch.Width = this.Size.Width;
                this.scissorTestSwitch.Height = this.Size.Height;

                this.scissorTestSwitch.On();
                this.viewportSwitch.On();

                // 把所有在此之前渲染的内容都推到最远。
                OpenGL.Clear(OpenGL.GL_DEPTH_BUFFER_BIT);

                renderer.Render(arg);

{'fraction_non_alphanumeric': 0.08984078847611827, 'fraction_numerical': 0.0, 'mean_word_length': 1.7920634920634921, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4799361', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1458, 'n_words': 310}