Пример #1
0
        public override string ToString()
        {
            PopupWriter buffer = new PopupWriter("k");

            buffer.WriteNull();
            buffer.WritePopupString(this.title);
            if (this.opcode != null)
            {
                buffer.Write('s');
                buffer.WritePopupString(this.opcode);
                buffer.WritePopupString(this.parameter);
            }
            if (this.width > 0 && this.height > 0)
            {
                buffer.Write('w');
                buffer.WriteShort(this.width);
                buffer.WriteShort(this.height);
            }

            buffer.WriteForeground(new int[] { 0x00, 0x00, 0x00 });
            buffer.WriteBackground(this.background);
            buffer.Write('C');
            buffer.WriteEnd();

            foreach (IComponent com in this.components)
            {
                WriteComponent(com, buffer);
            }
            buffer.WriteEnd();

            return(buffer.ToString());
        }
Пример #2
0
        private static void WriteComponent(IComponent com, PopupWriter buffer)
        {
            if (com.Location != Location.NONE)
            {
                buffer.Write((char)com.Location);
            }

            buffer.Write((char)com.Type);

            switch (com.Type)
            {
            case ComponentType.LABEL:
                buffer.WritePopupString(com.Text);
                buffer.WriteFontStyle(((Label)com).Style, ((Label)com).Size);
                break;

            case ComponentType.PANEL:
                Panel panel = (Panel)com;
                if (!string.IsNullOrEmpty(panel.ID))
                {
                    buffer.WritePopupString(panel.ID);
                }

                if (panel.Background != null)
                {
                    buffer.WriteBackground(panel.Background, 'b');
                }

                if (panel.BackgroundImage != null)
                {
                    buffer.Write('U');
                    buffer.WritePopupString(panel.BackgroundImage);
                    buffer.Write('U');
                    buffer.WriteShort(panel.Width);
                    buffer.WriteShort(panel.Height);
                }
                if (panel.Layout != null)
                {
                    buffer.WriteLayout((char)panel.Layout.Type);
                    switch (panel.Layout.Type)
                    {
                    case LayoutType.GRID_LAYOUT:
                        GridLayout grid = (GridLayout)panel.Layout;
                        buffer.WriteSize(grid.Rows);
                        buffer.WriteSize(grid.Cols);
                        buffer.WriteSize(grid.HGap);
                        buffer.WriteSize(grid.VGap);
                        break;
                    }
                }
                var coms = panel.Components;
                foreach (var c in coms)
                {
                    WriteComponent(c, buffer);
                }
                break;

            case ComponentType.TEXT_PANEL:
                TextPanel tp = (TextPanel)com;
                buffer.WritePopupString(string.Format("°R>{{linkhovercolor}}<r°{0}°>{{linkhovercolorreset}}<°", com.Text));
                buffer.WriteFrameSize(tp.Width, tp.Height);
                buffer.WriteBackgroundImage(tp.BackgroundImage, tp.BackgroundPosition);
                break;

            case ComponentType.BUTTON:
                buffer.WritePopupString(com.Text);
                Button button = (Button)com;
                if (button.FontSize != 14 || button.FontWeight != 'p')
                {
                    buffer.WriteFontStyle(button.FontWeight, button.FontSize);
                }

                if (button.Styled)
                {
                    buffer.Write('c');
                    if (button.Colored)
                    {
                        buffer.Write('e');
                    }
                }

                if (button.Close)
                {
                    buffer.Write('d');
                }
                if (button.Action)
                {
                    buffer.Write('s');
                }

                // KP ?
                buffer.Write('b');
                buffer.Write('g');
                buffer.Write('O');

                if (button.Command != null)
                {
                    buffer.Write('u');
                    buffer.WritePopupString(button.Command);
                }
                break;

            case ComponentType.TEXT_FIELD:
                buffer.WritePopupString(com.Text);
                buffer.WriteSize(((TextField)com).Width);
                break;

            case ComponentType.TEXT_AREA:
                buffer.WritePopupString(com.Text);
                TextArea textarea = (TextArea)com;
                buffer.WriteSize(textarea.Rows);
                buffer.WriteSize(textarea.Cols);

                switch (textarea.Scrollbars)
                {
                case 0:
                    buffer.Write('b');
                    break;

                case 1:
                    buffer.Write('s');
                    break;

                case 2:
                    buffer.Write('w');
                    break;
                }
                if (textarea.Editable)
                {
                    buffer.Write('e');
                }
                break;

            case ComponentType.CHECKBOX:
                if (com.Text != null)
                {
                    buffer.Write('l');
                    buffer.WritePopupString(com.Text);
                }

                buffer.WriteFontStyle('p', 16);
                Checkbox checkbox = (Checkbox)com;

                if (checkbox.Disabled)
                {
                    buffer.Write('d');
                }

                if (checkbox.Selected)
                {
                    buffer.Write('s');
                    buffer.Write('t');
                }

                if (checkbox.Group != 0)
                {
                    buffer.Write('r');
                    buffer.WriteSize(checkbox.Group);
                }
                break;

            case ComponentType.CHOICE:
                Choice choice = (Choice)com;
                if (choice.Selected == null)
                {
                    buffer.Write('c');
                    buffer.Write(choice.SelectedIndex);
                }
                else
                {
                    buffer.Write('C');
                    buffer.WritePopupString(choice.Selected);
                }

                if (choice.Fontsize > 0)
                {
                    buffer.WriteFontStyle('p', choice.Fontsize);
                }

                if (choice.Disabled)
                {
                    buffer.Write('d');
                }

                buffer.WriteForeground(com.Foreground);
                buffer.WriteBackground(com.Background);

                buffer.WriteEnd();
                foreach (var item in choice.Items)
                {
                    buffer.WritePopupString(item);
                }
                break;
            }
            if (com.Type != ComponentType.PANEL && com.Type != ComponentType.CHOICE)
            {
                if (com.Background != new int[] { 255, 255, 255 })
                {
                    buffer.WriteBackground(com.Background);
                }
                if (com.Foreground != new int[] { 0, 0, 0 })
                {
                    buffer.WriteForeground(com.Foreground);
                }
            }

            buffer.WriteEnd();
        }