Click here to Skip to main content
15,892,809 members
Articles / Programming Languages / C#

User-driven applications

Rate me:
Please Sign up or sign in to vote.
4.88/5 (24 votes)
10 Apr 2010CPOL136 min read 33.1K   5   78  
User-driven applications are the programs in which full control is given to the users. Designers of such programs are responsible only for developing an instrument for solving some task, but they do not enforce users to work with this instrument according with a predefined scenario.
using System;
using System .Collections .Generic;
using System .Drawing;
using System .Windows .Forms;
using System .IO;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class RuralPlusRight : Building
    {
        int version = 606;
        Rectangle rcHouse,      // points 0 - 1 - 2 - 3
                  rcGarage;     // points 7 - 8 - 9 - 2
        Point ptPien,           // point 4
              ptSlopeL,         // point 5
              ptSlopeR,         // point 6
              ptGarageSlopeTop; // point 10
        int roomSize = 18;
        int windowSize = 10;
        int smallWindowSize = 6;
        int minRoofH = 18;
        int minGarageHeight = 12;
        int minGarageRoofHeight = 5;
        int minCornerDist = 4;

        int minHouseHeight, minHouseWidth;
        int maxHouseHeight, maxHouseWidth, maxRoofH;
        int minGarageWidth, maxGarageWidth;

        // -------------------------------------------------
        public RuralPlusRight (Rectangle rc, int roofH, Color [] clrs)
        {
            houseType = HouseType .RuralPlusRight;
            SetColors (clrs);
            DefaultSizes ();
            rcHouse = new Rectangle (rc .Left, rc .Top,
                                     Math .Min (Math .Max (minHouseWidth, rc .Width), maxHouseWidth),
                                     Math .Min (Math .Max (minHouseHeight, rc .Height), maxHouseHeight));
            roofH = Math .Min (Math .Max (minRoofH, roofH), maxRoofH);
            ptPien = new Point ((rcHouse .Left + rcHouse .Right) / 2, rcHouse .Top - roofH);
            rcGarage = new Rectangle (rcHouse .Right, rcHouse .Bottom - minGarageHeight,
                                      minGarageWidth, minGarageHeight);
            DefaultSlopeCorners ();
            ptGarageSlopeTop = new Point (rcGarage .Left, rcGarage .Top - minGarageRoofHeight);
        }
        // -------------------------------------------------
        public RuralPlusRight (Point ptLT, Size sizeHouse, int roofH, Color [] clrs)
            : this (new Rectangle (ptLT, sizeHouse), roofH, clrs)
        {
        }
        // -------------------------------------------------
        public RuralPlusRight (Rectangle rc, int roofH, Size sizeSlopeShift, Size sizeGarage, int roofGarage, Color [] clrs)
        {
            houseType = HouseType .RuralPlusRight;
            SetColors (clrs);
            DefaultSizes ();
            rcHouse = new Rectangle (rc .Left, rc .Top,
                                     Math .Min (Math .Max (minHouseWidth, rc .Width), maxHouseWidth),
                                     Math .Min (Math .Max (minHouseHeight, rc .Height), maxHouseHeight));
            roofH = Math .Min (Math .Max (minRoofH, roofH), maxRoofH);
            ptPien = new Point ((rcHouse .Left + rcHouse .Right) / 2, rcHouse .Top - roofH);

            int dx = Math .Abs (sizeSlopeShift .Width);
            int dy = Math .Abs (sizeSlopeShift .Height);
            Point ptNew_R = new Point (ptPien .X + dx, ptPien .Y + dy);
            Point ptRT = new Point (rcHouse .Right, rcHouse .Top);
            Point ptOnOuterSide = new Point (rcHouse .Right, ptPien .Y);
            if (minCornerDist <= dx && dx <= rcHouse .Width / 2 - minCornerDist &&
                minCornerDist <= dy && dy <= RoofHeight - minCornerDist &&
                Auxi_Geometry .SameSideOfLine (ptRT, ptPien, ptOnOuterSide, ptNew_R))
            {
                ptSlopeR = ptNew_R;
                ptSlopeL = new Point (ptPien .X - dx, ptSlopeR .Y);
            }
            else
            {
                DefaultSlopeCorners ();
            }

            int nWgar = Math .Min (Math .Max (minGarageWidth, sizeGarage .Width), maxGarageWidth);
            int nHgar = Math .Min (Math .Max (minGarageHeight, sizeGarage .Height), rcHouse .Height - minGarageRoofHeight);
            rcGarage = new Rectangle (rcHouse .Right, rcHouse .Bottom - nHgar, nWgar, nHgar);
            if (minGarageRoofHeight <= roofGarage && roofGarage <= rcGarage .Top - rcHouse .Top)
            {
                ptGarageSlopeTop = new Point (rcHouse .Right, rcGarage .Top - roofGarage);
            }
            else
            {
                ptGarageSlopeTop = new Point (rcHouse .Right, rcGarage .Top - minGarageRoofHeight);
            }
            SetColors (clrs);
        }
        // -------------------------------------------------        DefaultSizes
        public void DefaultSizes ()
        {
            minHouseHeight = roomSize;
            minHouseWidth = 2 * roomSize;
            maxHouseHeight = roomSize * 3 + 4;
            maxHouseWidth = roomSize * 5 + 4;

            maxRoofH = maxHouseHeight;
            minGarageWidth = roomSize;
            maxGarageWidth = 2 * roomSize;
        }
        // -------------------------------------------------        DefaultSlopeCorners
        public void DefaultSlopeCorners ()
        {
            int dx = rcHouse .Width / 3;
            int dy = RoofHeight / 3;
            ptSlopeL = new Point (ptPien .X - dx, ptPien .Y + dy);
            ptSlopeR = new Point (ptPien .X + dx, ptPien .Y + dy);
        }
        // -------------------------------------------------        Location
        public override Point Location ()
        {
            return (rcHouse .Location);
        }
        // -------------------------------------------------        RectAround
        public override RectangleF RectAround ()
        {
            return (new Rectangle (rcHouse .Left, ptPien .Y, rcHouse .Width + rcGarage .Width, rcHouse .Bottom - ptPien .Y));
        }
        // -------------------------------------------------        MainHouse
        public Rectangle MainHouse
        {
            get { return (rcHouse); }
        }
        // -------------------------------------------------        RoofHeight
        public int RoofHeight
        {
            get { return (rcHouse .Top - ptPien .Y); }
        }
        // -------------------------------------------------        Pien
        public Point Pien
        {
            get { return (ptPien); }
            set
            {
                int cy = Math .Min (Math .Max (rcHouse .Top - maxRoofH, value .Y), rcHouse .Top - minRoofH);
                ptPien = new Point ((rcHouse .Left + rcHouse .Right) / 2, cy);
                DefineCover ();
            }
        }
        // -------------------------------------------------        SlopeShift
        // shows the distance of both slope points from the pien; both cx and cy are shown as positive numbers
        public Size SlopeShift
        {
            get { return (new Size (ptSlopeR .X - ptPien .X, ptSlopeR .Y - ptPien .Y)); }
            set
            {
                int dx = Math .Abs (value .Width);
                int dy = Math .Abs (value .Height);
                Point ptNew_R = new Point (ptPien .X + dx, ptPien .Y + dy);
                Point ptRT = new Point (rcHouse .Right, rcHouse .Top);
                Point ptOnOuterSide = new Point (rcHouse .Right, ptPien .Y);
                if (minCornerDist <= dx && dx <= rcHouse .Width / 2 - minCornerDist &&
                    minCornerDist <= dy && dy <= RoofHeight - minCornerDist &&
                    Auxi_Geometry .SameSideOfLine (ptRT, ptPien, ptOnOuterSide, ptNew_R))
                {
                    ptSlopeR = ptNew_R;
                    ptSlopeL = new Point (ptPien .X - dx, ptSlopeR .Y);
                    DefineCover ();
                }
            }
        }
        // -------------------------------------------------        Garage
        public Rectangle Garage
        {
            get { return (rcGarage); }
        }
        // -------------------------------------------------        GarageRoofHeight
        public int GarageRoofHeight
        {
            get { return (rcGarage .Top - ptGarageSlopeTop .Y); }
            set
            {
                ptGarageSlopeTop = new Point (rcHouse .Right, Math .Min (Math .Max (rcHouse .Top, rcGarage .Top - value),
                                                                         rcGarage .Top - minGarageRoofHeight));
            }
        }
        // -------------------------------------------------        Copy
        public override Building Copy (Point ptLT)
        {
            Rectangle rc = new Rectangle (ptLT, MainHouse .Size);
            RuralPlusRight houseNew = new RuralPlusRight (rc, RoofHeight, SlopeShift, Garage .Size, GarageRoofHeight, GetColors ());
            return ((Building) houseNew);
        }
        // -------------------------------------------------        Draw
        public override void Draw (Graphics grfx)
        {
            Rectangle rc;
            int nSpace;

            grfx .FillRectangle (brushHouse, rcHouse);
            grfx .DrawRectangle (penEdge, rcHouse);
            Point [] ptsRoof = { rcHouse .Location, ptSlopeL, ptPien, ptSlopeR, new Point (rcHouse .Right, rcHouse .Top) };
            grfx .FillPolygon (brushRoof, ptsRoof);
            grfx .DrawPolygon (penEdge, ptsRoof);

            // windows
            // horizontal position can change according with the number of windows
            // vertically they must be always in the middle, except for the case of two stores
            int nRoomPerFloor = rcHouse .Width / roomSize;
            int roomWidth = rcHouse .Width / nRoomPerFloor;
            int nWindowMargin_W = (roomWidth - windowSize) / 2;
            int nStore = rcHouse .Height / roomSize;
            int roomHeight = rcHouse .Height / nStore;
            int nWindowMarginH = (roomHeight - windowSize) / 2;

            int cxL = rcHouse .Left;
            int cyT = rcHouse .Top;
            for (int i = 0; i < nStore; i++)
            {
                for (int j = 0; j < nRoomPerFloor; j++)
                {
                    rc = new Rectangle (cxL + j * roomWidth + nWindowMargin_W, cyT + i * roomHeight + nWindowMarginH, windowSize, windowSize);
                    grfx .FillRectangle (brushWindow, rc);
                    grfx .DrawRectangle (penEdge, rc);
                }
            }
            // windows on roof
            nSpace = smallWindowSize * 2 / 3;
            rc = new Rectangle (ptPien .X - (smallWindowSize + nSpace / 2),
                                rcHouse .Top - (smallWindowSize + nSpace), smallWindowSize, smallWindowSize);
            grfx .FillRectangle (brushWindow, rc);
            grfx .DrawRectangle (penEdge, rc);
            rc = new Rectangle (ptPien .X + nSpace / 2,
                                rcHouse .Top - (smallWindowSize + nSpace), smallWindowSize, smallWindowSize);
            grfx .FillRectangle (brushWindow, rc);
            grfx .DrawRectangle (penEdge, rc);

            // garage
            grfx .FillRectangle (brushHouse, rcGarage);
            grfx .DrawRectangle (penEdge, rcGarage);
            ptsRoof = new Point [] {new Point (rcGarage .Left, rcGarage .Top), ptGarageSlopeTop, 
                                    new Point (rcGarage .Right, rcGarage .Top) };
            grfx .FillPolygon (brushRoof, ptsRoof);
            grfx .DrawPolygon (penEdge, ptsRoof);
            nSpace = 3;
            Rectangle rcDoor = new Rectangle (rcGarage .Left + nSpace, rcGarage .Top + nSpace,
                                              rcGarage .Width - 2 * nSpace, rcGarage .Height - nSpace);
            grfx .FillRectangle (brushDoor, rcDoor);
            grfx .DrawRectangle (penEdge, rcDoor);
        }
        // -------------------------------------------------        DefineCover
        public override void DefineCover ()
        {
            CoverNode [] nodes = new CoverNode [19];

            nodes [0] = new CoverNode (0, new PointF (rcHouse .Left, rcHouse .Top), Cursors .SizeNWSE);
            nodes [1] = new CoverNode (1, new PointF (rcHouse .Right, rcHouse .Top), Cursors .SizeNESW);
            nodes [2] = new CoverNode (2, new PointF (rcHouse .Right, rcHouse .Bottom), Cursors .SizeNWSE);
            nodes [3] = new CoverNode (3, new PointF (rcHouse .Left, rcHouse .Bottom), Cursors .SizeNESW);
            nodes [4] = new CoverNode (4, ptPien, Cursors .SizeNS);
            nodes [5] = new CoverNode (5, ptSlopeL);
            nodes [6] = new CoverNode (6, ptSlopeR);
            nodes [7] = new CoverNode (7, new Point (rcGarage .Right, rcGarage .Bottom));
            nodes [8] = new CoverNode (8, new Point (rcGarage .Right, rcGarage .Top));
            nodes [9] = new CoverNode (9, new Point (rcGarage .Left, rcGarage .Top));
            nodes [10] = new CoverNode (10, ptGarageSlopeTop, Cursors .SizeNS);
            nodes [11] = new CoverNode (11, new Point (rcHouse .Right, rcHouse .Top), new Point (rcHouse .Right, rcHouse .Bottom), Cursors .SizeWE);
            nodes [12] = new CoverNode (12, new Point (rcHouse .Left, rcHouse .Top), new Point (rcHouse .Right, rcHouse .Top), Cursors .SizeNS);
            nodes [13] = new CoverNode (13, new Point (rcHouse .Left, rcHouse .Top), new Point (rcHouse .Left, rcHouse .Bottom), Cursors .SizeWE);
            nodes [14] = new CoverNode (14, new Point (rcGarage .Right, rcHouse .Bottom), new Point (rcHouse .Left, rcHouse .Bottom), Cursors .SizeNS);
            nodes [15] = new CoverNode (15, new Point (rcGarage .Right, rcGarage .Top), new Point (rcGarage .Right, rcGarage .Bottom), Cursors .SizeWE);
            nodes [16] = new CoverNode (16, new Point (rcGarage .Left, rcGarage .Top), new Point (rcGarage .Right, rcGarage .Top), Cursors .SizeNS);
            nodes [17] = new CoverNode (17, new Point [] { new Point (rcHouse .Left, rcHouse .Top), ptSlopeL, ptPien, ptSlopeR, 
                                                           new Point (rcHouse .Right, rcHouse .Top), new Point (rcHouse .Right, rcHouse .Bottom),
                                                           new Point (rcHouse .Left, rcHouse .Bottom) });
            nodes [18] = new CoverNode (18, new Point [] { ptGarageSlopeTop, new Point (rcGarage .Right, rcGarage .Top), 
                                                           new Point (rcGarage .Right, rcGarage .Bottom),
                                                           new Point (rcGarage .Left, rcGarage .Bottom) });
            cover = new Cover (nodes);
        }
        // -------------------------------------------------
        public override void Move (int cx, int cy)
        {
            rcHouse .X += cx;
            rcHouse .Y += cy;
            ptPien += new Size (cx, cy);
            ptSlopeL += new Size (cx, cy);
            ptSlopeR += new Size (cx, cy);
            rcGarage .X += cx;
            rcGarage .Y += cy;
            ptGarageSlopeTop += new Size (cx, cy);
        }
        // -------------------------------------------------        AdjustGarageHeight
        private void AdjustGarageHeight ()
        {
            if (ptGarageSlopeTop .Y < rcHouse .Top)
            {
                ptGarageSlopeTop .Y = rcHouse .Top;
                if (rcGarage .Top < ptGarageSlopeTop .Y + minGarageRoofHeight)
                {
                    rcGarage .Y = ptGarageSlopeTop .Y + minGarageRoofHeight;
                    rcGarage .Height = rcHouse .Bottom - rcGarage .Top;
                }
            }
        }
        // -------------------------------------------------        HorMoveGarage
        private void HorMoveGarage (int dx)
        {
            rcGarage .X += dx;
            ptGarageSlopeTop .X += dx;
        }
        // -------------------------------------------------        VerMoveGarage
        private void VerMoveGarage (int dy)
        {
            rcGarage .Y += dy;
            ptGarageSlopeTop .Y += dy;
        }
        // -------------------------------------------------        MoveGarageCeiling
        private void MoveGarageCeiling (int dy)
        {
            int garageRoofHeight = rcGarage .Top - ptGarageSlopeTop .Y;
            rcGarage .Y += dy;
            rcGarage .Height = rcHouse .Bottom - rcGarage .Y;
            ptGarageSlopeTop .Y = Math .Max (rcHouse .Top, rcGarage .Y - garageRoofHeight);
            DefineCover ();
        }
        // -------------------------------------------------        MoveGarageOuterSide
        private void MoveGarageOuterSide (int dx)
        {
            rcGarage .Width += dx;
            DefineCover ();
        }
        // -------------------------------------------------        MoveCeiling
        private void MoveCeiling (int dy)
        {
            rcHouse .Y += dy;
            rcHouse .Height -= dy;
            ptPien .Y += dy;
            ptSlopeL .Y += dy;
            ptSlopeR .Y += dy;
            AdjustGarageHeight ();
            DefineCover ();
        }
        // -------------------------------------------------        MoveFloor
        private void MoveFloor (int dy)
        {
            rcHouse .Height += dy;
            VerMoveGarage (dy);
            AdjustGarageHeight ();
            DefineCover ();
        }
        // -------------------------------------------------        MoveLeftSide
        private void MoveLeftSide (int dx)
        {
            int cxToSide = ptSlopeL .X - rcHouse .Left;
            rcHouse .X += dx;
            rcHouse .Width -= dx;
            ptPien .X = (rcHouse .Left + rcHouse .Right) / 2;
            ptSlopeL .X += dx;
            Point ptLT = new Point (rcHouse .Left, rcHouse .Top);
            Point ptOnOuterSide = new Point (rcHouse .Left, ptPien .Y);
            while (!Auxi_Geometry .SameSideOfLine (ptLT, ptPien, ptOnOuterSide, ptSlopeL))
            {
                ptSlopeL .X--;
            }
            ptSlopeR .X = ptPien .X + (ptPien .X - ptSlopeL .X);
            DefineCover ();
        }
        // -------------------------------------------------        MoveInnerWall
        private void MoveInnerWall (int dx)
        {
            int cxToSide = rcHouse .Right - ptSlopeR .X;
            rcHouse .Width += dx;
            ptPien .X = (rcHouse .Left + rcHouse .Right) / 2;
            ptSlopeR .X += dx;
            Point ptRT = new Point (rcHouse .Right, rcHouse .Top);
            Point ptOnOuterSide = new Point (rcHouse .Right, ptPien .Y);
            while (!Auxi_Geometry .SameSideOfLine (ptRT, ptPien, ptOnOuterSide, ptSlopeR))
            {
                ptSlopeR .X++;
            }
            ptSlopeL .X = rcHouse .Left + (rcHouse .Right - ptSlopeR .X);
            HorMoveGarage (dx);
            DefineCover ();
        }
        // -------------------------------------------------        MoveNode
        public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons catcher)
        {
            bool bRet = false;

            if (catcher == MouseButtons .Left)
            {
                Point ptOnOuterSide, ptNew, ptLT, ptRT;
                int cxNew, cyNew, hNew, wNew;

                switch (i)
                {
                    case 0:         // Left Top corner of the house
                        hNew = rcHouse .Height - dy;
                        if (minHouseHeight <= hNew && hNew <= maxHouseHeight)
                        {
                            MoveCeiling (dy);
                        }
                        wNew = rcHouse .Width - dx;
                        if (minHouseWidth <= wNew && wNew <= maxHouseWidth)
                        {
                            MoveLeftSide (dx);
                        }
                        break;

                    case 1:        // Right Top corner of the house
                        hNew = rcHouse .Height - dy;
                        if (minHouseHeight <= hNew && hNew <= maxHouseHeight)
                        {
                            MoveCeiling (dy);
                        }
                        wNew = rcHouse .Width + dx;
                        if (minHouseWidth <= wNew && wNew <= maxHouseWidth)
                        {
                            MoveInnerWall (dx);
                        }
                        break;

                    case 2:         // Right Bottom corner of the house
                        hNew = rcHouse .Height + dy;
                        if (minHouseHeight <= hNew && hNew <= maxHouseHeight)
                        {
                            MoveFloor (dy);
                        }
                        wNew = rcHouse .Width + dx;
                        if (minHouseWidth <= wNew && wNew <= maxHouseWidth)
                        {
                            MoveInnerWall (dx);
                        }
                        break;

                    case 3:         // Left Bottom corner of the house
                        hNew = rcHouse .Height + dy;
                        if (minHouseHeight <= hNew && hNew <= maxHouseHeight)
                        {
                            MoveFloor (dy);
                        }
                        wNew = rcHouse .Width - dx;
                        if (minHouseWidth <= wNew && wNew <= maxHouseWidth)
                        {
                            MoveLeftSide (dx);
                        }
                        break;

                    case 4:         // Pien
                        cyNew = ptPien .Y + dy;
                        hNew = rcHouse .Top - cyNew;
                        if (minRoofH <= hNew && hNew <= maxRoofH)
                        {
                            ptPien .Y += dy;
                            ptSlopeL .Y += dy;
                            ptLT = new Point (rcHouse .Left, rcHouse .Top);
                            ptOnOuterSide = new Point (rcHouse .Left, ptPien .Y);
                            while (!Auxi_Geometry .SameSideOfLine (ptLT, ptPien, ptOnOuterSide, ptSlopeL))
                            {
                                ptSlopeL .Y--;
                            }
                            ptSlopeR .Y = ptSlopeL .Y;
                            DefineCover ();
                        }
                        break;

                    case 5:         // Left slope point
                        ptLT = new Point (rcHouse .Left, rcHouse .Top);
                        ptOnOuterSide = new Point (rcHouse .Left, ptPien .Y);
                        cyNew = ptSlopeL .Y + dy;
                        ptNew = new Point (ptSlopeL .X, cyNew);
                        if (ptPien .Y + minCornerDist <= cyNew &&
                                                         cyNew <= rcHouse .Top - minCornerDist &&
                            Auxi_Geometry .SameSideOfLine (ptLT, ptPien, ptOnOuterSide, ptNew))
                        {
                            ptSlopeL .Y = cyNew;
                            ptSlopeR .Y = cyNew;
                            DefineCover ();
                        }
                        cxNew = ptSlopeL .X + dx;
                        ptNew = new Point (cxNew, ptSlopeL .Y);
                        if (rcHouse .Left + minCornerDist <= cxNew &&
                                                             cxNew <= ptPien .X - minCornerDist &&
                            Auxi_Geometry .SameSideOfLine (ptLT, ptPien, ptOnOuterSide, ptNew))
                        {
                            ptSlopeL .X = cxNew;
                            ptSlopeR .X = ptPien .X + (ptPien .X - ptSlopeL .X);
                            DefineCover ();
                        }
                        break;

                    case 6:         // Right slope point
                        ptRT = new Point (rcHouse .Right, rcHouse .Top);
                        ptOnOuterSide = new Point (rcHouse .Right, ptPien .Y);
                        cyNew = ptSlopeR .Y + dy;
                        ptNew = new Point (ptSlopeR .X, cyNew);
                        if (ptPien .Y + minCornerDist <= cyNew &&
                                                         cyNew <= rcHouse .Top - minCornerDist &&
                            Auxi_Geometry .SameSideOfLine (ptRT, ptPien, ptOnOuterSide, ptNew))
                        {
                            ptSlopeR .Y = cyNew;
                            ptSlopeL .Y = cyNew;
                            DefineCover ();
                        }
                        cxNew = ptSlopeR .X + dx;
                        ptNew = new Point (cxNew, ptSlopeR .Y);
                        if (ptPien .X + minCornerDist <= cxNew &&
                                                         cxNew <= rcHouse .Right - minCornerDist &&
                            Auxi_Geometry .SameSideOfLine (ptRT, ptPien, ptOnOuterSide, ptNew))
                        {
                            ptSlopeR .X = cxNew;
                            ptSlopeL .X = ptPien .X - (ptSlopeR .X - ptPien .X);
                            DefineCover ();
                        }
                        break;

                    case 7:         // Right (outer) Bottom corner of the garage
                        cyNew = rcGarage .Bottom + dy;
                        int hGarageNew = rcGarage .Height + dy;
                        int hHouseNew = rcHouse .Height + dy;
                        if (minGarageHeight <= hGarageNew &&
                            minHouseHeight <= hHouseNew && hHouseNew <= maxHouseHeight)
                        {
                            rcGarage .Height += dy;
                            rcHouse .Height += dy;
                            DefineCover ();
                        }
                        wNew = rcGarage .Width + dx;
                        if (minGarageWidth <= wNew && wNew <= maxGarageWidth)
                        {
                            MoveGarageOuterSide (dx);
                        }
                        break;

                    case 8:         // Right Top corner of the garage
                        cyNew = rcGarage .Top + dy;
                        if (rcHouse .Top + minGarageRoofHeight <= cyNew &&
                                                                  cyNew <= rcGarage .Bottom - minGarageHeight)
                        {
                            MoveGarageCeiling (dy);
                        }
                        wNew = rcGarage .Width + dx;
                        if (minGarageWidth <= wNew && wNew <= maxGarageWidth)
                        {
                            MoveGarageOuterSide (dx);
                        }
                        break;

                    case 9:         // Left (inner) Top corner of the garage
                        cyNew = rcGarage .Top + dy;
                        if (rcHouse .Top + minGarageRoofHeight <= cyNew &&
                                                                  cyNew <= rcGarage .Bottom - minGarageHeight)
                        {
                            MoveGarageCeiling (dy);
                        }
                        wNew = rcHouse .Width + dx;
                        if (minHouseWidth <= wNew && wNew <= maxHouseWidth)
                        {
                            MoveInnerWall (dx);
                        }
                        break;

                    case 10:        // Slope top of the garage
                        cyNew = ptGarageSlopeTop .Y + dy;
                        if (rcHouse .Top <= cyNew && cyNew + minGarageRoofHeight <= rcGarage .Top)
                        {
                            ptGarageSlopeTop .Y = cyNew;
                            bRet = true;
                        }
                        break;

                    case 11:        // inner wall
                        wNew = rcHouse .Width + dx;
                        if (minHouseWidth <= wNew && wNew <= maxHouseWidth)
                        {
                            MoveInnerWall (dx);
                        }
                        break;

                    case 12:         // ceiling of the house
                        hNew = rcHouse .Height - dy;
                        if (minHouseHeight <= hNew && hNew <= maxHouseHeight)
                        {
                            MoveCeiling (dy);
                        }
                        break;

                    case 13:        // left side
                        wNew = rcHouse .Width - dx;
                        if (minHouseWidth <= wNew && wNew <= maxHouseWidth)
                        {
                            MoveLeftSide (dx);
                        }
                        break;

                    case 14:         // floor
                        hNew = rcHouse .Height + dy;
                        if (minHouseHeight <= hNew && hNew <= maxHouseHeight)
                        {
                            MoveFloor (dy);
                        }
                        break;

                    case 15:        // garage outer side
                        wNew = rcGarage .Width + dx;
                        if (minGarageWidth <= wNew && wNew <= maxGarageWidth)
                        {
                            MoveGarageOuterSide (dx);
                        }
                        break;

                    case 16:         // garage ceiling
                        cyNew = rcGarage .Top + dy;
                        if (rcHouse .Top + minGarageRoofHeight <= cyNew &&
                                                                  cyNew <= rcGarage .Bottom - minGarageHeight)
                        {
                            MoveGarageCeiling (dy);
                        }
                        break;

                    case 17:
                    case 18:
                        Move (dx, dy);
                        break;
                }
            }
            return (bRet);
        }
        // -------------------------------------------------        IntoRegistry
        public override void IntoRegistry (RegistryKey regkey, string name)
        {
            try
            {
                regkey .SetValue (name, new string [] { version .ToString (),           // 0
                                                        id .ToString (),                // 1

                                                        rcHouse .Left .ToString (),     // 2
                                                        rcHouse .Top .ToString (),      // 3
                                                        rcHouse .Width .ToString (),    // 4
                                                        rcHouse .Height .ToString (),   // 5
                                                        RoofHeight .ToString (),            // 6
                                                        SlopeShift .Width .ToString (),     // 7
                                                        SlopeShift .Height .ToString (),    // 8
                                                        rcGarage .Width .ToString (),   // 9
                                                        rcGarage .Height .ToString (),  // 10
                                                        GarageRoofHeight .ToString (),  // 11

                                                        ((int) (HouseColor .A)) .ToString (),    // 12 
                                                        ((int) (HouseColor .R)) .ToString (),    //  
                                                        ((int) (HouseColor .G)) .ToString (),    //  
                                                        ((int) (HouseColor .B)) .ToString (),    // 

                                                        ((int) (RoofColor .A)) .ToString (),    // 16 
                                                        ((int) (RoofColor .R)) .ToString (),    //  
                                                        ((int) (RoofColor .G)) .ToString (),    //  
                                                        ((int) (RoofColor .B)) .ToString (),    // 

                                                        ((int) (WindowColor .A)) .ToString (),    // 20 
                                                        ((int) (WindowColor .R)) .ToString (),    //  
                                                        ((int) (WindowColor .G)) .ToString (),    //  
                                                        ((int) (WindowColor .B)) .ToString (),    // 

                                                        ((int) (DoorColor .A)) .ToString (),    // 24 
                                                        ((int) (DoorColor .R)) .ToString (),    //  
                                                        ((int) (DoorColor .G)) .ToString (),    //  
                                                        ((int) (DoorColor .B)) .ToString (),    // 

                                                        ((int) (EdgeColor .A)) .ToString (),    // 28 
                                                        ((int) (EdgeColor .R)) .ToString (),    //  
                                                        ((int) (EdgeColor .G)) .ToString (),    //  
                                                        ((int) (EdgeColor .B)) .ToString (),    // 
                                                    },
                                        RegistryValueKind .MultiString);
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromRegistry
        public static RuralPlusRight FromRegistry (RegistryKey regkey, string name)
        {
            try
            {
                RuralPlusRight house = null;
                string [] strs = (string []) regkey .GetValue (name);
                if (strs != null && strs .Length == 32 && Convert .ToInt32 (strs [0]) == 606)
                {
                    house = new RuralPlusRight (Auxi_Convert .ToRectangle (strs, 2),
                                                Convert .ToInt32 (strs [6]),
                                                Auxi_Convert .ToSize (strs, 7),
                                                Auxi_Convert .ToSize (strs, 9),
                                                Convert .ToInt32 (strs [11]),
                                                new Color [] {Auxi_Convert .ToColor (strs, 12), 
                                                              Auxi_Convert .ToColor (strs, 16), 
                                                              Auxi_Convert .ToColor (strs, 20), 
                                                              Auxi_Convert .ToColor (strs, 24), 
                                                              Auxi_Convert .ToColor (strs, 28)});
                    if (house != null)
                    {
                        house .ID = Convert .ToInt64 (strs [1]);
                    }
                }
                return (house);
            }
            catch
            {
                return (null);
            }
            finally
            {
            }
        }
        // -------------------------------------------------        IntoFile
        public override void IntoFile (BinaryWriter bw)
        {
            try
            {
                bw .Write (version);            // 0
                bw .Write (id);                 // 1
                Auxi_IO .Write_Rectangle (bw, rcHouse);     // 2 - 5
                bw .Write (RoofHeight);         // 6
                Auxi_IO .Write_Size (bw, SlopeShift);       // 7, 8
                Auxi_IO .Write_Size (bw, Garage .Size);     // 9, 10
                bw .Write (GarageRoofHeight);         // 11
                Auxi_IO .Write_Color (bw, HouseColor);      // 12
                Auxi_IO .Write_Color (bw, RoofColor);       // 16
                Auxi_IO .Write_Color (bw, WindowColor);     // 20
                Auxi_IO .Write_Color (bw, DoorColor);       // 24
                Auxi_IO .Write_Color (bw, EdgeColor);       // 28
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromFile
        public static RuralPlusRight FromFile (BinaryReader br)
        {
            try
            {
                RuralPlusRight house = null;
                int nVer = br .ReadInt32 ();        // 0
                long idRead = br .ReadInt64 ();     // 1
                if (nVer == 606)
                {
                    house = new RuralPlusRight (Auxi_IO .Read_Rectangle (br),        // 2 - 5
                                                br .ReadInt32 (),               // 6
                                                Auxi_IO .Read_Size (br),        // 7, 8
                                                Auxi_IO .Read_Size (br),        // 9, 10
                                                br .ReadInt32 (),               // 11
                                                new Color [] {  Auxi_IO .Read_Color (br),       // 12
                                                                Auxi_IO .Read_Color (br),       // 16
                                                                Auxi_IO .Read_Color (br),       // 20
                                                                Auxi_IO .Read_Color (br),       // 24
                                                                Auxi_IO .Read_Color (br)});     // 28
                    if (house != null)
                    {
                        house .ID = idRead;
                    }
                }
                return (house);
            }
            catch
            {
                return (null);
            }
            finally
            {
            }
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions