Re: New layout language.

Here's the code from my .Net 2.0 application

Form1.cs
=====================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        public float CanvasWidth = 850;
        public float CanvasHeight = 420;

        public List<Region> regions = new List<Region>();
        public Form1()
        {
            InitializeComponent();

            //new Region(left, top, width, height, leftGrowth,
topGrowth, widthGrowth, heightGrowth)
            regions.Add(new Region(10, 10, 200, 400, 0, 0, 0, 1));
            regions.Add(new Region(220, 10, 200, 320, 0, 0, 0.5f, 0.8f));
            regions.Add(new Region(430, 10, 200, 320, 0.5f, 0, 0.5f, 0.8f));
            regions.Add(new Region(640, 10, 200, 400, 1, 0, 0, 1));
            regions.Add(new Region(220, 340, 410, 70, 0, 0.8f, 1, 0.2f));

            this.ResizeRedraw = true;
        }
        
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            int clientWidth = this.ClientRectangle.Width;
            int clientHeight = this.ClientRectangle.Height;

            foreach (Region region in regions)
            {
                e.Graphics.DrawRectangle(new Pen(Brushes.Black),
                    region.Left     + Math.Max(clientWidth -
CanvasWidth,   0) * region.LeftGrowth,
                    region.Top      + Math.Max(clientHeight -
CanvasHeight, 0) * region.TopGrowth,
                    region.Width    + Math.Max(clientWidth -
CanvasWidth,   0) * region.WidthGrowth,
                    region.Height   + Math.Max(clientHeight -
CanvasHeight, 0) * region.HeightGrowth);
            }
        }
    }
}

Region.cs
================

using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication2
{
    public class Region
    {
        public float Left;
        public float LeftGrowth;
        public float Top;
        public float TopGrowth;
        public float Width;
        public float WidthGrowth;
        public float Height;
        public float HeightGrowth;

        public Region(float left, float top, float width, float
height, float leftGrowth, float topGrowth, float widthGrowth, float
heightGrowth)
        {
            Left = left;
            Top = top;
            Width = width;
            Height = height;
            LeftGrowth = leftGrowth;
            TopGrowth = topGrowth;
            WidthGrowth = widthGrowth;
            HeightGrowth = heightGrowth;
        }
    }
}

Received on Thursday, 7 July 2005 00:16:43 UTC