예제 #1
0
 // interface:
 public bool pt_inside(DXGui gui, Point p)
 {
     TGCVector2[] Q = new TGCVector2[2];
     Q[0] = new TGCVector2(rc.X, rc.Y);
     Q[1] = new TGCVector2(rc.X + rc.Width, rc.Y + rc.Height);
     gui.Transform(Q, 2);
     Rectangle r = new Rectangle((int)Q[0].X, (int)Q[0].Y, (int)(Q[1].X - Q[0].X), (int)(Q[1].Y - Q[0].Y));
     return r.Contains(p);
 }
        public override void Render(DXGui gui)
        {
            bool sel  = gui.sel == nro_item ? true : false;
            bool foco = gui.foco == nro_item ? true : false;

            // recuadro del edit
            gui.RoundRect(rc.Left, rc.Top, rc.Right, rc.Bottom, 11, 2, Color.FromArgb(80, 220, 20));

            if (foco)
            {
                // tiene foco
                gui.RoundRect(rc.Left, rc.Top, rc.Right, rc.Bottom, 8, 1, Color.FromArgb(255, 255, 255, 255), true);
            }

            // Texto del edit
            Color color = foco ? Color.FromArgb(0, 0, 0) : Color.FromArgb(130, 255, 130);

            gui.font.DrawText(gui.sprite, text, rc, DrawTextFormat.Top | DrawTextFormat.Left, color);

            if (foco)
            {
                // si esta vacio, le agrego una I para que cuente bien el alto del caracter
                string p = text;
                if (p.Length == 0)
                {
                    p += "I";
                }

                Rectangle tw = new Rectangle();
                int       h  = gui.font.DrawText(gui.sprite, p, tw, DrawTextFormat.Top | DrawTextFormat.NoClip, color);

                //Rectangle tw = gui.font.MeasureString(gui.sprite, p, DrawTextFormat.Top | DrawTextFormat.NoClip, color);


                Rectangle rc2 = new Rectangle(rc.Right + tw.Width, rc.Top, 12, rc.Height);
                // dibujo el cursor titilando
                int cursor = (int)(gui.time * 5);
                if (cursor % 2 != 0)
                {
                    gui.line.Width = 8;
                    TGCVector2[] pt = new TGCVector2[2];
                    pt[0].X = rc2.Left;
                    pt[1].X = rc2.Right;
                    pt[1].Y = pt[0].Y = rc2.Bottom;

                    gui.Transform(pt, 2);
                    gui.line.Begin();
                    gui.line.Draw(TGCVector2.ToVector2Array(pt), Color.FromArgb(0, 64, 0));
                    gui.line.End();
                }
            }
        }
예제 #3
0
        public virtual void Render(DXGui gui)
        {
            bool  sel   = gui.sel == nro_item && !disabled ? true : false;
            Color color = sel ? c_selected : c_font;

            if (rc.Width == 0 || rc.Height == 0)
            {
                // Ajusta el rectangulo para que adapte al texto a dibujar
                Rectangle tw = gui.font.MeasureString(gui.sprite, text, DrawTextFormat.NoClip | DrawTextFormat.Top, color);
                rc.Width  = tw.Width + 20;
                rc.Height = tw.Height + 10;
                rc.X     -= 10;
                rc.Y     -= 5;

                // Recalcula el centro
                center = new Point(rc.X + rc.Width / 2, rc.Y + rc.Height / 2);
            }

            Texture tx = sel && textura_sel != null ? textura_sel : textura;

            if (tx != null)
            {
                TGCVector3 pos = image_centrada ? new TGCVector3(rc.X - image_width, rc.Y + (rc.Height - image_height) / 2, 0) : new TGCVector3(rc.X, rc.Y, 0);
                gui.sprite.Draw(tx, Rectangle.Empty, TGCVector3.Empty, pos, Color.FromArgb(gui.alpha, 255, 255, 255));
            }

            if (sel)
            {
                gui.RoundRect(rc.Left - 8, rc.Top - 6, rc.Right + 8, rc.Bottom + 6, 6, 3,
                              Color.FromArgb(gui.alpha, DXGui.c_selected_frame), false);
                int dy = rc.Height / 2;

                gui.line.Width = 2f;
                gui.line.Begin();

                byte r0 = DXGui.c_grad_inf_0.R;
                byte g0 = DXGui.c_grad_inf_0.G;
                byte b0 = DXGui.c_grad_inf_0.B;
                byte r1 = DXGui.c_grad_inf_1.R;
                byte g1 = DXGui.c_grad_inf_1.G;
                byte b1 = DXGui.c_grad_inf_1.B;

                // Gradiente de abajo
                for (int i = 0; i < dy; ++i)
                {
                    TGCVector2[] pt = new TGCVector2[2];
                    pt[0].X = rc.X - 3;
                    pt[1].X = rc.X + rc.Width + 3;
                    pt[1].Y = pt[0].Y = rc.Y + rc.Height / 2 - i;
                    gui.Transform(pt, 2);
                    float t = i / (float)dy;
                    byte  r = (byte)(r0 * t + r1 * (1 - t));
                    byte  g = (byte)(g0 * t + g1 * (1 - t));
                    byte  b = (byte)(b0 * t + b1 * (1 - t));
                    gui.line.Draw(TGCVector2.ToVector2Array(pt), Color.FromArgb(gui.alpha, r, g, b));
                }

                // Gradiente de arriba
                r0 = DXGui.c_grad_sup_0.R;
                g0 = DXGui.c_grad_sup_0.G;
                b0 = DXGui.c_grad_sup_0.B;
                r1 = DXGui.c_grad_sup_1.R;
                g1 = DXGui.c_grad_sup_1.G;
                b1 = DXGui.c_grad_sup_1.B;

                for (int i = 0; i < dy; ++i)
                {
                    TGCVector2[] pt = new TGCVector2[2];
                    pt[0].X = rc.X - 3;
                    pt[1].X = rc.X + rc.Width + 3;
                    pt[1].Y = pt[0].Y = rc.Y + rc.Height / 2 + i;
                    gui.Transform(pt, 2);
                    float t = i / (float)dy;
                    byte  r = (byte)(r0 * t + r1 * (1 - t));
                    byte  g = (byte)(g0 * t + g1 * (1 - t));
                    byte  b = (byte)(b0 * t + b1 * (1 - t));
                    gui.line.Draw(TGCVector2.ToVector2Array(pt), Color.FromArgb(gui.alpha, r, g, b));
                }
                gui.line.End();
            }

            // dibujo el texto pp dicho
            gui.font.DrawText(gui.sprite, text, rc, DrawTextFormat.NoClip | DrawTextFormat.VerticalCenter, disabled ? Color.FromArgb(gui.alpha, DXGui.c_item_disabled) : sel ? Color.FromArgb(gui.alpha, 0, 32, 128) : c_font);
        }