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
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 .Drawing .Drawing2D;
using System .IO;
using System .Windows .Forms;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class BuildingsGroup : GraphicalObject
    {
        int version = 606;
        List<Building> elements = new List<Building> ();
        int [] sidespace = new int [4];                 // Left, Top, Right, Bottom
        Rectangle rcFrame;                  // only through calculation
        SolidBrush brushBack;
        bool bShowFrame;
        Pen penFrame;
        int minFrameSpace = 6;

        // -------------------------------------------------        
        public BuildingsGroup (List<Building> elems, int [] framespaces, Pen pen)
        {
            elements = elems;
            foreach (Building elem in elements)
            {
                elem .ParentID = id;
            }
            for (int i = 0; i < 4; i++)
            {
                sidespace [i] = Math .Max (minFrameSpace, framespaces [i]);
            }
            FrameArea ();
            brushBack = new SolidBrush (Color .FromArgb (204, Color .Cyan));   // transparency = 0.2   A = 255 * (1 - coef)
            bShowFrame = true;
            penFrame = pen;
        }
        // -------------------------------------------------        
        public BuildingsGroup (List<Building> elems)
            : this (elems, new int [] { 10, 10, 10, 10 }, new Pen (Color .Blue))
        {
        }
        // -------------------------------------------------        FrameArea
        private void FrameArea ()
        {
            RectangleF unionArea = elements [0] .RectAround ();

            for (int i = 1; i < elements .Count; i++)
            {
                unionArea = RectangleF .Union (unionArea, elements [i] .RectAround ());
            }
            unionArea .X -= sidespace [0];
            unionArea .Y -= sidespace [1];
            unionArea .Width += sidespace [0] + sidespace [2];
            unionArea .Height += sidespace [1] + sidespace [3];
            rcFrame = Rectangle .Round (unionArea);
        }
        // -------------------------------------------------        RectAround
        new public Rectangle RectAround
        {
            get
            {
                FrameArea ();
                return (rcFrame);
            }
        }
        // -------------------------------------------------        Frame
        // when any building is moved outside the frame, the call to Frame prior to RectAround  can give different results  !!! 
        public Rectangle Frame
        {
            get { return (rcFrame); }
        }
        // -------------------------------------------------        Update
        public void Update ()
        {
            FrameArea ();
            DefineCover ();
        }
        // -------------------------------------------------        ID
        new public long ID
        {
            get { return (id); }
            set
            {
                id = value;
                foreach (Building elem in elements)
                {
                    elem .ParentID = id;
                }
            }
        }
        // -------------------------------------------------        Elements
        public List<Building> Elements
        {
            get { return (elements); }
        }
        // -------------------------------------------------        SideSpaces
        public int [] SideSpaces
        {
            get { return (sidespace); }
            set
            {
                if (value != null && value .Length == 4)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        sidespace [k] = Math .Max (minFrameSpace, value [k]);
                    }
                    Update ();
                }
            }
        }
        // -------------------------------------------------        ShowFrame
        public bool ShowFrame
        {
            get { return (bShowFrame); }
            set { bShowFrame = value; }
        }
        // -------------------------------------------------        FrameColor
        public Color FrameColor
        {
            get { return (penFrame .Color); }
            set { penFrame .Color = value; }
        }
        // -------------------------------------------------        BackColor
        public Color BackColor
        {
            get { return (brushBack .Color); }
            //set { brushBack = new SolidBrush (value); }
        }
        // -------------------------------------------------        Pen
        public Pen Pen
        {
            get { return (penFrame); }
            set { penFrame = value; }
        }
        // -------------------------------------------------        Draw
        public void Draw (Graphics grfx)
        {
            grfx .FillRectangle (brushBack, Rectangle .FromLTRB (rcFrame .Left - 3, rcFrame .Top - 3, rcFrame .Right + 3, rcFrame .Bottom + 3));
            Auxi_Drawing .CurvedFrame (grfx, rcFrame, penFrame);
        }
        // -------------------------------------------------        DefineCover
        public override void DefineCover ()
        {
            Rectangle rc = rcFrame;
            rc .Inflate (3, 3);
            cover = new Cover (rc, Resizing .None);
            cover .SetCursor (Cursors .Hand);
        }
        // -------------------------------------------------        Move
        public override void Move (int dx, int dy)
        {
            rcFrame .X += dx;
            rcFrame .Y += dy;
            foreach (Building elem in elements)
            {
                elem .Move (dx, dy);
            }
        }
        // -------------------------------------------------        MoveNode
        public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons mb)
        {
            bool bRet = false;

            if (mb == MouseButtons .Left)
            {
                Move (dx, dy);
                bRet = true;
            }
            return (bRet);
        }

    }
}

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.140827.1 | Last Updated 10 Apr 2010
Article Copyright 2010 by SergeyAndreyev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid