Click here to Skip to main content
11,413,961 members (76,648 online)
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 MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class StripInRectangle : GraphicalObject
    {
        RectangleF rc;
        double coefX_anchor, coefY_anchor;  // from [0, 1];  [0,0] is for left-top corner;  [1,1] is for right-bottom corner
        PointF ptAnchor;
        LineDir linedir;
        double coefX_size, coefY_size;          // can be of any sign
        double coef_min_size, coef_max_size;    // can be of any sign

        SolidBrush brush;
        int halfsense = 3;

        // -------------------------------------------------
        public StripInRectangle (RectangleF rcParent, float coefX_pt, float coefY_pt,
                                 LineDir dirUnchangeable, float coefX_initialsize, float coefY_initialsize,
                                 float minSizeCoef, float maxSizeCoef, Color clr)
        {
            rc = rcParent;
            coefX_anchor = Math .Min (Math .Max (0, coefX_pt), 1);
            coefY_anchor = Math .Min (Math .Max (0, coefY_pt), 1);
            ptAnchor = new PointF (rc .Left + Convert .ToSingle (coefX_anchor * rc .Width),
                                   rc .Top + Convert .ToSingle (coefY_anchor * rc .Height));

            linedir = dirUnchangeable;
            coefX_size = coefX_initialsize;
            coefY_size = coefY_initialsize;

            coef_min_size = Math .Min (minSizeCoef, maxSizeCoef);
            coef_max_size = Math .Max (minSizeCoef, maxSizeCoef);
            switch (linedir)
            {
                case LineDir .Hor:
                    coefY_size = Math .Min (Math .Max (coef_min_size, coefY_size), coef_max_size);
                    break;
                case LineDir .Ver:
                    coefX_size = Math .Min (Math .Max (coef_min_size, coefX_size), coef_max_size);
                    break;
            }
            brush = new SolidBrush (clr);
        }
        // -------------------------------------------------        ParentRect
        public RectangleF ParentRect
        {
            get { return (rc); }
            set
            {
                rc = value;
                ptAnchor = new PointF (rc .Left + Convert .ToSingle (coefX_anchor * rc .Width),
                                       rc .Top + Convert .ToSingle (coefY_anchor * rc .Height));
                DefineCover ();
            }
        }
        // -------------------------------------------------        Ycoef
        public double Ycoef
        {
            get { return (coefY_size); }
        }
        // -------------------------------------------------        Color
        public Color Color
        {
            get { return (brush .Color); }
            set { brush = new SolidBrush (value); }
        }
        // -------------------------------------------------        Draw
        public void Draw (Graphics grfx)
        {
            float dw = Convert .ToSingle (rc .Width * coefX_size);
            float dh = Convert .ToSingle (rc .Height * coefY_size);
            float cxL = Math .Min (ptAnchor .X, ptAnchor .X + dw);
            float cxR = Math .Max (ptAnchor .X, ptAnchor .X + dw);
            float cyT = Math .Min (ptAnchor .Y, ptAnchor .Y + dh);
            float cyB = Math .Max (ptAnchor .Y, ptAnchor .Y + dh);

            grfx .FillRectangle (brush, cxL, cyT, cxR - cxL, cyB - cyT);
        }
        // -------------------------------------------------        Draw
        public override void DefineCover ()
        {
            float dw = Convert .ToSingle (rc .Width * coefX_size);
            float dh = Convert .ToSingle (rc .Height * coefY_size);
            float cxL = Math .Min (ptAnchor .X, ptAnchor .X + dw);
            float cxR = Math .Max (ptAnchor .X, ptAnchor .X + dw);
            float cyT = Math .Min (ptAnchor .Y, ptAnchor .Y + dh);
            float cyB = Math .Max (ptAnchor .Y, ptAnchor .Y + dh);
            CoverNode [] nodes = new CoverNode [2];
            switch (linedir)
            {
                case LineDir .Hor:
                    float cy = ptAnchor .Y + dh;
                    nodes [0] = new CoverNode (0, new RectangleF (cxL, cy - halfsense, cxR - cxL, 2 * halfsense), Cursors .SizeNS);
                    break;

                case LineDir .Ver:
                    float cx = ptAnchor .X + dw;
                    nodes [0] = new CoverNode (0, new RectangleF (cx - halfsense, cyT, 2 * halfsense, cyB - cyT), Cursors .SizeWE);
                    break;
            }
            nodes [1] = new CoverNode (1, new RectangleF (cxL, cyT, cxR - cxL, Math .Max (2, cyB - cyT)),
                                          MovementFreedom .None, Cursors .Default);
            cover = new Cover (nodes);
        }
        // -------------------------------------------------        Move
        public override void Move (int dx, int dy)
        {
            ptAnchor += new Size (dx, dy);
        }
        // -------------------------------------------------        MoveNode
        public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons catcher)
        {
            bool bRet = false;
            if (catcher == MouseButtons .Left && i == 0)
            {
                float distCur, distNext;
                float coefNext;
                switch (linedir)
                {
                    case LineDir .Hor:
                        distCur = Convert .ToSingle (rc .Height * coefY_size);
                        distNext = distCur + dy;
                        coefNext = distNext / rc .Height;
                        if (coef_min_size <= coefNext && coefNext <= coef_max_size)
                        {
                            coefY_size = coefNext;
                            bRet = true;
                        }
                        break;

                    case LineDir .Ver:
                        distCur = Convert .ToSingle (rc .Width * coefX_size);
                        distNext = distCur + dx;
                        coefNext = distNext / rc .Width;
                        if (coef_min_size <= coefNext && coefNext <= coef_max_size)
                        {
                            coefX_size = coefNext;
                            bRet = true;
                        }
                        break;
                }
            }
            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 | Terms of Use | Mobile
Web01 | 2.8.150427.2 | Last Updated 10 Apr 2010
Article Copyright 2010 by SergeyAndreyev
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid