Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

User-driven applications

, 10 Apr 2010 CPOL
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.
TheoryOfUserDrivenApplications.zip
TheoryOfUserDrivenApplications
TheoryOfUserDrivenApplications
bin
Debug
TheoryOfUserDrivenApplications.vshost.exe
Release
MoveGraphLibrary.dll
TheoryOfUserDrivenApplications.bin
TheoryOfUserDrivenApplications.exe
TheoryOfUserDrivenApplications.vshost.exe
Properties
Settings.settings
Resources
ArrowDown.bmp
ArrowUp.bmp
DELETE.BMP
Hangar.bmp
Lock.bmp
palette_.bmp
RuralHouse.bmp
RuralLeftPlus.bmp
RuralRightPlus.bmp
SimpleHouse.bmp
User_driven_applications.doc
User_driven_applications.pdf
using System;
using System .Collections .Generic;
using System .Drawing;
using System .Windows .Forms;
using System .IO;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    // the main part of the house will be like RuralHouse, but there will be addition on the left 
    //
    public class RuralPlusLeft : Building
    {
        int version = 606;
        Rectangle rcHouse,      // points 0 - 1 - 2 - 3
                  rcGarage;     // points 8 - 9 - 3 - 7
        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 RuralPlusLeft (Rectangle rc, int roofH, Color [] clrs)
        {
            houseType = HouseType .RuralPlusLeft;
            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 .Left - minGarageWidth, rcHouse .Bottom - minGarageHeight,
                                      minGarageWidth, minGarageHeight);
            DefaultSlopeCorners ();
            ptGarageSlopeTop = new Point (rcGarage .Right, rcGarage .Top - minGarageRoofHeight);
        }
        // -------------------------------------------------
        public RuralPlusLeft (Point ptLT, Size sizeHouse, int roofH, Color [] clrs)
            : this (new Rectangle (ptLT, sizeHouse), roofH, clrs)
        {
        }
        // -------------------------------------------------
        public RuralPlusLeft (Rectangle rc, int roofH, Size sizeSlopeShift, Size sizeGarage, int roofGarage, Color [] clrs)
        {
            houseType = HouseType .RuralPlusLeft;
            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 .Left - nWgar, rcHouse .Bottom - nHgar, nWgar, nHgar);
            if (minGarageRoofHeight <= roofGarage && roofGarage <= rcGarage .Top - rcHouse .Top)
            {
                ptGarageSlopeTop = new Point (rcHouse .Left, rcGarage .Top - roofGarage);
            }
            else
            {
                ptGarageSlopeTop = new Point (rcHouse .Left, 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 (rcGarage .Left, ptPien .Y, rcGarage .Width + rcHouse .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 .Left, 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);
            RuralPlusLeft houseNew = new RuralPlusLeft (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
            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 .Left, rcGarage .Bottom));
            nodes [8] = new CoverNode (8, new Point (rcGarage .Left, rcGarage .Top));
            nodes [9] = new CoverNode (9, new Point (rcGarage .Right, rcGarage .Top));
            nodes [10] = new CoverNode (10, ptGarageSlopeTop, Cursors .SizeNS);
            nodes [11] = new CoverNode (11, new Point (rcHouse .Left, rcHouse .Top), new Point (rcHouse .Left, 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 .Right, rcHouse .Top), new Point (rcHouse .Right, rcHouse .Bottom), Cursors .SizeWE);
            nodes [14] = new CoverNode (14, new Point (rcGarage .Left, rcHouse .Bottom), new Point (rcHouse .Right, rcHouse .Bottom), Cursors .SizeNS);
            nodes [15] = new CoverNode (15, new Point (rcGarage .Left, rcGarage .Top), new Point (rcGarage .Left, 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 [] { new Point (rcGarage .Left, rcGarage .Top), ptGarageSlopeTop, 
                                                           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;
            rcGarage .X += 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 ();
        }
        // -------------------------------------------------        MoveInnerWall
        private void MoveInnerWall (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);
            HorMoveGarage (dx);
            DefineCover ();
        }
        // -------------------------------------------------        MoveRightSide
        private void MoveRightSide (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);
            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)
                        {
                            MoveInnerWall (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)
                        {
                            MoveRightSide (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)
                        {
                            MoveRightSide (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)
                        {
                            MoveInnerWall (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:         // Left (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:         // Left 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:         // Right (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:        // right side
                        wNew = rcHouse .Width + dx;
                        if (minHouseWidth <= wNew && wNew <= maxHouseWidth)
                        {
                            MoveRightSide (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 RuralPlusLeft FromRegistry (RegistryKey regkey, string name)
        {
            try
            {
                RuralPlusLeft house = null;
                string [] strs = (string []) regkey .GetValue (name);
                if (strs != null && strs .Length == 32 && Convert .ToInt32 (strs [0]) == 606)
                {
                    house = new RuralPlusLeft (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 RuralPlusLeft FromFile (BinaryReader br)
        {
            try
            {
                RuralPlusLeft house = null;
                int nVer = br .ReadInt32 ();        // 0
                long idRead = br .ReadInt64 ();     // 1
                if (nVer == 606)
                {
                    house = new RuralPlusLeft (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)

Share

About the Author

SergeyAndreyev

United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411028.1 | Last Updated 10 Apr 2010
Article Copyright 2010 by SergeyAndreyev
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid