Ejemplo n.º 1
0
Archivo: UIGrid.cs Proyecto: wjk17/WSA
        public void Input()
        {
            ic.order = drawOrder;
            this.BeginOrtho();
            var startPos = this.AbsRefPos();

            rects = new List <Rect>();
            for (int y = 0; y < gridCount.y; y++)
            {
                for (int x = 0; x < gridCount.x; x++)
                {
                    rects.Add(new Rect(startPos + gridOsFactor * new Vector2(x, y) *
                                       (gridOs + gridSize), gridSize, pivot));
                }
            }
            var i = 0; bool clicked = false;

            foreach (var rt in rects)
            {
                if (visible.NotEmpty() && !visible[i])
                {
                    i++; continue;
                }
                GLUI.fontColor = fontColor;
                GLUI.BeginOrder(0);

                if (!clickable[i])
                {
                    DrawButton(rt, 2);
                }
                else
                {
                    if (rt.Contains(UI.mousePosRef) && clickable[i])
                    {
                        OnOver(i);
                        if (Events.Mouse1to3)
                        {
                            DrawButton(rt, 2);
                            if (Events.MouseDown1to3 && !clicked)
                            {
                                OnClick(i);
                                clicked = true;
                            }
                        }
                        else
                        {
                            DrawButton(rt, 1);
                            if (drawTips)
                            {
                                // tips
                                var str  = names[i];
                                var size = IMUI.CalSize(str);
                                size += fontBorder;

                                var os = offset + osFactor * size;
                                GLUI.DrawString(str, UI.mousePosRef + os, Vectors.half2d);
                                GLUI.BeginOrder(3);
                                var bg = new Rect(UI.mousePosRef + os, size, Vectors.half2d);
                                bg.Draw(Color.white, true);
                            }
                        }
                    }
                    else
                    {
                        DrawButton(rt, 0);
                    }
                    if (drawName)
                    {
                        GLUI.DrawString(names[i], (rt.pos + nameOffset), Vectors.half2d);
                    }
                    GLUI.BeginOrder(1);
                    if (textures.NotEmpty() && textures[i] != null)
                    {
                        GLUI.DrawTex(textures[i], rt.ToPointsCWLT(-1));
                    }

                    GLUI.SetLineMat();
                    GLUI.BeginOrder(0);
                }
                // 待做优化 tex和line分开两个loop
                GLUI.BeginOrder(2);
                if (drawBorder)
                {
                    rt.Draw(drawBorderClr, false);
                }
                i++;
            }
        }
Ejemplo n.º 2
0
        public void Input()
        {
            this.BeginOrtho(drawOrder);
            var RT       = new RectTrans(this);
            var startPos = margin + RT.centerT;

            var psy = startPos.Average(osAbs.Y(), gridCount.y, Vector2.zero);

            for (int y = 0; y < gridCount.y; y++)
            {
                var os = osAbs != Vector2.zero ? osAbs : gridOs + gridSize;
                var ps = psy[y].Average(os.x, gridCount.x, Vectors.halfRight2d);
                for (int x = 0; x < gridCount.x; x++)
                {
                    var n = new Rect(ps[x], gridSize, pivot);
                    gridUnitProp[y * gridCount.x + x].rect = n;
                }
            }
            var i = 0; bool clicked = false;

            foreach (var gup in gridUnitProp)
            {
                if (!gup.visible)
                {
                    i++; continue;
                }
                GLUI.SetFontColor(fontColor);
                GLUI.BeginOrder(0);

                if (!gup.clickable)
                {
                    DrawButton(gup, 2);
                    if (drawName)
                    {
                        gup.DrawName(nameOffset);
                    }

                    if (gup.Hover())
                    {
                        Events.Use();
                    }
                }
                else
                {
                    if (gup.Hover() && !Events.used)
                    {
                        OnOver(i);
                        if (Events.Mouse1to3)
                        {
                            DrawButton(gup, 2);
                            if (Events.MouseDown1to3 && !clicked)
                            {
                                OnClick(i);
                                clicked = true;
                            }
                        }
                        else
                        {
                            DrawButton(gup, 1);
                        }
                        Events.Use();
                    }
                    else
                    {
                        DrawButton(gup, 0);
                    }

                    if (drawName)
                    {
                        gup.DrawName(nameOffset);
                    }

                    GLUI.BeginOrder(1);

                    if (gup.texture != null)
                    {
                        gup.DrawTexture();
                    }

                    GLUI.SetLineMat();
                    GLUI.BeginOrder(0);
                }
                // 待做优化 tex和line分开两个loop
                GLUI.BeginOrder(2);
                if (drawBorder)
                {
                    gup.rect.Draw(drawBorderClr, false);
                }
                i++;
            }
        }