Exemple #1
0
        // Rendering (UNUSED, See HtmlLayout)
        public void Render(Renderer rend)
        {
            rend.Clear();

            foreach (HtmlNode elem in Elements)
            {
                HtmlAttribute x       = elem.Get("x");
                HtmlAttribute y       = elem.Get("y");
                CSSElement    csselem = null;

                if (csselem == null)
                {
                    HtmlAttribute style = elem.Get("style");

                    if (style != null)
                    {
                        csselem = StyleContainer.ParseStyleString(style.Value);
                    }
                }

                if (CSS != null && csselem == null)
                {
                    csselem = CSS.Get(elem.Tag);
                }

                if (elem.Tag == "RECT" && (x != null && y != null))
                {
                    int xi = int.Parse(x.Value);
                    int yi = int.Parse(y.Value);

                    rend.DrawRect(new Rectangle(xi, yi, 200, 200), GetColor(csselem.Get(elem.Tag)));
                }
            }
        }
Exemple #2
0
        public new void Render(Renderer rend, bool terminal = false)
        {
            _Rend = rend;

            if (terminal)
            {
                rend.Term_Clear();
            }
            else
            {
                rend.Clear();
            }

            LineY = 0;
            LineX = 0;

            int lasty = -1;

            foreach (HtmlNode elem in Elements)
            {
                HtmlAttribute x       = elem.Get("x");
                HtmlAttribute y       = elem.Get("y");
                CSSElement    csselem = null;

                if (csselem == null)
                {
                    HtmlAttribute style = elem.Get("style");

                    if (style != null)
                    {
                        csselem = StyleContainer.ParseStyleString(style.Value);
                    }
                }

                if (CSS != null && csselem == null)
                {
                    csselem = CSS.Get(elem.Tag);
                }
                int lf = -1;

                if (csselem != null)
                {
                    Style left = csselem.Get("left");

                    if (left != null)
                    {
                        lf = int.Parse(left.Value);
                    }
                }

                if (LineY != lasty)
                {
                    lasty = LineY;

                    LeftPadToPosition(lf);
                }

                if (elem.Tag == "RECT" && (x != null && y != null))
                {
                    int xi = int.Parse(x.Value);
                    int yi = int.Parse(y.Value);

                    if (!terminal)
                    {
                        rend.DrawRect(new Rectangle(xi, yi, 200, 200), GetColor(csselem.Get(elem.Tag)));
                    }
                    continue;
                }

                if (elem.Tag == "P")
                {
                    if (terminal)
                    {
                        rend.Term_DrawString(elem.TagBody, new PointF(0, 0));
                        continue;
                    }

                    rend.DrawString(elem.TagBody, new PointF(LineX, LineY));
                    LineX += (int)rend.Measure(elem.TagBody).Width;
                }

                if (elem.Tag.StartsWith("H") && elem.Tag.Length == 2)
                {
                    rend.Term_DrawString("<BOLD>" + elem.TagBody, new Point(0, 0));
                    rend.Term_DrawString("\n\n", new PointF(0, 0));
                }

                if (elem.Tag == "IMG")
                {
                    if (terminal)
                    {
                        WebImage image = new WebImage(elem);

                        for (int i = 0; i < image.SizeY; i++)
                        {
                            LeftPadToPosition(lf); // Pad to the left style property

                            // Get pixel(character and color) data and draw it
                            foreach (WebImage.PixelData pixel in image.GetRow(i))
                            {
                                rend.Term_DrawString("" + pixel.Character, new PointF(0, 0), pixel.Color);
                            }

                            if (i != image.SizeY - 1)
                            {
                                rend.Term_DrawString("\n", new PointF(0, 0));
                                LineY += 1;
                                LineX  = 0;
                            }
                        }
                    }
                }

                if (elem.Tag == "B")
                {
                    if (csselem.Get("background") != null)
                    {
                        if (terminal)
                        {
                            LineX += elem.TagBody.Length;
                            rend.Term_DrawString(elem.TagBody, new PointF(0, 0), GetColor(csselem.Get("background")), GetColor(csselem.Get("color")));
                            continue;
                        }

                        SizeF bounds = rend.Measure(elem.TagBody, rend.Bold);

                        rend.DrawRect(new Rectangle(LineX, LineY, (int)bounds.Width, (int)bounds.Height), GetColor(csselem.Get("background")));
                    }

                    if (terminal)
                    {
                        rend.Term_DrawString(elem.TagBody, new PointF(0, 0), ColorEnum.White, GetColor(csselem.Get("color")));
                        LineX += elem.TagBody.Length;
                        continue;
                    }

                    rend.DrawString(elem.TagBody, new PointF(LineX, LineY), rend.Bold, GetColor(csselem.Get("color")));

                    LineX += (int)rend.Measure(elem.TagBody).Width;
                }

                if (elem.Tag == "SCRIPT")
                {
                    JSState.Engine.Execute(elem.TagBody);
                }

                if (elem.Tag == "BR")
                {
                    if (terminal)
                    {
                        LineX  = 0;
                        LineY += 1;
                        rend.Term_DrawString("\n", new PointF(0, 0));
                        continue;
                    }

                    LineX  = 0;
                    LineY += (int)rend.Measure("A").Height;
                }
            }
        }