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

User-driven applications

, 10 Apr 2010
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
{
    public class Hangar : Building
    {
        int version = 606;
        Point ptCenter;
        int radius;
        int nrSmall = 5;
        int distanceNeighbours = 8;

        int minRadius = 20;
        int maxRadius = 60;
        int nDoorSize = 14;

        int nNodesOnPerimeter;

        // -------------------------------------------------
        public Hangar (Point ptC, int nR, Color [] clrs)
        {
            houseType = HouseType .Hangar;
            SetColors (clrs);
            ptCenter = ptC;
            radius = Math .Min (Math .Max (minRadius, Math .Abs (nR)), maxRadius);
            NodesCalc ();
        }
        // -------------------------------------------------        Copy
        public override Building Copy (Point ptC)
        {
            Hangar houseNew = new Hangar (ptC, Radius, GetColors ());
            return ((Building) houseNew);
        }
        // -------------------------------------------------        Location
        public override Point Location ()
        {
            return (ptCenter);
        }
        // -------------------------------------------------        RectAround
        public override RectangleF RectAround ()
        {
            return (new Rectangle (ptCenter .X - radius, ptCenter .Y - radius, 2 * radius, radius));
        }
        // -------------------------------------------------        Radius
        public int Radius
        {
            get { return (radius); }
        }
        // -------------------------------------------------        Draw
        public override void Draw (Graphics grfx)
        {
            Rectangle rc = new Rectangle (ptCenter .X - radius, ptCenter .Y - radius, 2 * radius, 2 * radius);
            grfx .FillPie (brushHouse, rc, 0, -180);
            grfx .DrawPie (penEdge, rc, 0, -180);
            Rectangle rcDoor = new Rectangle (ptCenter .X - nDoorSize / 2, ptCenter .Y - nDoorSize, nDoorSize, nDoorSize);
            grfx .FillRectangle (brushDoor, rcDoor);
            grfx .DrawRectangle (penEdge, rcDoor);
            int cx = ptCenter .X;
            grfx .DrawLine (penEdge, cx, rcDoor .Top, cx, rcDoor .Bottom);
        }
        // -------------------------------------------------        NodesCalc
        private void NodesCalc ()
        {
            nNodesOnPerimeter = Convert .ToInt32 ((Math .PI * radius) / distanceNeighbours) + 1;
        }
        // -------------------------------------------------        RedefineCover
        public void RedefineCover ()
        {
            NodesCalc ();
            DefineCover ();
        }
        // -------------------------------------------------        DefineCover
        public override void DefineCover ()
        {
            CoverNode [] nodes = new CoverNode [nNodesOnPerimeter + 2];
            PointF [] pt = new PointF [nNodesOnPerimeter];
            for (int i = 0; i < nNodesOnPerimeter; i++)
            {
                pt [i] = Auxi_Geometry .PointToPoint (ptCenter, Math .PI * i / (nNodesOnPerimeter - 1), radius);
            }
            for (int i = 0; i < nNodesOnPerimeter; i++)
            {
                nodes [i] = new CoverNode (i, pt [i], nrSmall);
            }
            nodes [nNodesOnPerimeter] = new CoverNode (nNodesOnPerimeter, new Rectangle (ptCenter .X - radius, ptCenter .Y, 2 * radius, radius),
                                                       MovementFreedom .Transparent, Cursors .Default);
            nodes [nNodesOnPerimeter + 1] = new CoverNode (nNodesOnPerimeter + 1, ptCenter, radius, Cursors .SizeAll);
            cover = new Cover (nodes);
        }
        // -------------------------------------------------
        public override void Move (int cx, int cy)
        {
            ptCenter += new Size (cx, cy);
        }
        // -------------------------------------------------        MoveNode
        public override bool MoveNode (int i, int cx, int cy, Point ptM, MouseButtons catcher)
        {
            bool bRet = false;

            if (catcher == MouseButtons .Left)
            {
                if (i < nNodesOnPerimeter)
                {
                    int newR = Convert .ToInt32 (Auxi_Geometry .Distance (ptCenter, ptM));
                    if (minRadius <= newR && newR <= maxRadius)
                    {
                        radius = newR;
                        bRet = true;
                    }
                }
                else
                {
                    Move (cx, cy);
                }
            }
            return (bRet);
        }
        // -------------------------------------------------        IntoRegistry
        public override void IntoRegistry (RegistryKey regkey, string name)
        {
            try
            {
                regkey .SetValue (name, new string [] { version .ToString (),           // 0
                                                        id .ToString (),                // 1

                                                        ptCenter .X .ToString (),       // 2
                                                        ptCenter .Y .ToString (),       // 3
                                                        Radius .ToString (),            // 4
                                                        
                                                        ((int) (HouseColor .A)) .ToString (),    // 75 
                                                        ((int) (HouseColor .R)) .ToString (),    //  
                                                        ((int) (HouseColor .G)) .ToString (),    //  
                                                        ((int) (HouseColor .B)) .ToString (),    // 

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

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

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

                                                        ((int) (EdgeColor .A)) .ToString (),    // 21 
                                                        ((int) (EdgeColor .R)) .ToString (),    //  
                                                        ((int) (EdgeColor .G)) .ToString (),    //  
                                                        ((int) (EdgeColor .B)) .ToString (),    // 
                                                    },
                                        RegistryValueKind .MultiString);
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromRegistry
        public static Hangar FromRegistry (RegistryKey regkey, string name)
        {
            try
            {
                Hangar house = null;
                string [] strs = (string []) regkey .GetValue (name);
                if (strs != null && strs .Length == 25 && Convert .ToInt32 (strs [0]) == 606)
                {
                    house = new Hangar (Auxi_Convert .ToPoint (strs, 2), Convert .ToInt32 (strs [4]),
                                        new Color [] {  Auxi_Convert .ToColor (strs, 5), 
                                                        Auxi_Convert .ToColor (strs, 9), 
                                                        Auxi_Convert .ToColor (strs, 13), 
                                                        Auxi_Convert .ToColor (strs, 17), 
                                                        Auxi_Convert .ToColor (strs, 21)});
                    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_Point (bw, ptCenter);     // 2, 3
                bw .Write (Radius);             // 4
                Auxi_IO .Write_Color (bw, HouseColor);      // 5 - 8
                Auxi_IO .Write_Color (bw, RoofColor);       // 9
                Auxi_IO .Write_Color (bw, WindowColor);     // 13
                Auxi_IO .Write_Color (bw, DoorColor);       // 17
                Auxi_IO .Write_Color (bw, EdgeColor);       // 21
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromFile
        public static Hangar FromFile (BinaryReader br)
        {
            try
            {
                Hangar house = null;
                int nVer = br .ReadInt32 ();        // 0
                long idRead = br .ReadInt64 ();     // 1
                if (nVer == 606)
                {
                    house = new Hangar (Auxi_IO .Read_Point (br),   // 2, 3
                                        br .ReadInt32 (),           // 4
                                        new Color [] {  Auxi_IO .Read_Color (br),       // 5 - 8
                                                        Auxi_IO .Read_Color (br),       // 9
                                                        Auxi_IO .Read_Color (br),       // 13
                                                        Auxi_IO .Read_Color (br),       // 17
                                                        Auxi_IO .Read_Color (br)});     // 21
                    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 | Mobile
Web01 | 2.8.140916.1 | Last Updated 10 Apr 2010
Article Copyright 2010 by SergeyAndreyev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid