コード例 #1
0
ファイル: ShaderProgram.cs プロジェクト: martinlyra/YAGOL
 public void Dispose()
 {
     if (Handle != 0)
     {
         GL.DeleteProgram(Handle);
     }
     Vertex.Dispose();
     Fragment.Dispose();
 }
コード例 #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (FragmentContainerView != null)
         {
             FragmentContainerView.Dispose();
             FragmentContainerView = null;
         }
         if (Fragment != null)
         {
             Fragment.Dispose();
             Fragment = null;
         }
     }
     base.Dispose(disposing);
 }
コード例 #3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            //base.OnCreateView (savedInstanceState);
            var view = inflater.Inflate(Resource.Layout.Filtration, container, false);

            filtrationFragmentView = view;
            FiltrationNavList.PutInCache(0, DataService.whatVersionCatID, GetString(Resource.String.All_categories));

            //if (FragmentLaunched == "main")
            //{
            //    try {
            //        FragmentManager.BeginTransaction()
            //           .Remove(_lastFragment);
            //        _lastFragment.Dispose();
            //    }
            //    catch (Exception e) { var k = e.Message; }
            //}

            //Первоначальная загрузка
            _flyOut = view.FindViewById <FlyOutContainer>(Resource.Id.FlyOutContainer);
            var menuButton = view.FindViewById(Resource.Id.MenuButton);

            menuButton.Click += (sender, e) =>
            {
                _flyOut.AnimatedOpened = !_flyOut.AnimatedOpened;
            };

            //FRAGMENTS BEGINS
            //При открытии используется
            var categorieslistfragment = new FiltrCategoriesListFrag();

            _lastFragment    = categorieslistfragment;
            FragmentLaunched = "categorieslistfragment";
            FragmentManager.BeginTransaction()
            .Replace(Resource.Id.filtration_content_frame, categorieslistfragment, FragmentLaunched)
            .SetTransition(FragmentTransit.FragmentFade)
            .Commit();

            //Используем фрагмент ..., если открываем профиль аккаунта - ProfileFragments
            var filterControlTextView = view.FindViewById <TextView>(Resource.Id.textView5);

            filterControlTextView.Click += (sender, args) =>
            {
                //var profileFragment = new ProfileFragment();
                //FragmentManager.BeginTransaction()
                //    .Remove(_lastFragment)
                //    .Add(Resource.Id.filtration_content_frame, profileFragment)
                //    .SetTransition(FragmentTransit.FragmentFade)
                //    .Commit();

                //_lastFragment.Dispose();
                //_lastFragment = profileFragment;

                //_flyOut.ExternalyClosed();
            };

            //Используем фрагмент ..., если открываем категории - CategoriesListFragments
            var filterCategoryTextView = view.FindViewById <TextView>(Resource.Id.FilterCategory);

            filterCategoryTextView.Click += (sender, args) =>
            {
                var eventsListFragment2 = new FiltrCategoriesListFrag();
                FragmentManager.BeginTransaction()
                .Remove(_lastFragment)
                .Add(Resource.Id.filtration_content_frame, eventsListFragment2)
                //.AddToBackStack("categorieslistfragment")
                .SetTransition(FragmentTransit.FragmentFade)
                .Commit();

                _lastFragment.Dispose();
                _lastFragment = eventsListFragment2;

                _flyOut.ExternalyClosed();
            };
            //FRAGMENTS ENDS

            //Spinner filterSpinner = view.FindViewById<Spinner>(Resource.Id.FilterSpinner);
            //filterSpinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(filterSpinner_ItemSelected);
            //var filterAdapter = ArrayAdapter.CreateFromResource(Activity, Resource.Array.Filter_array, Android.Resource.Layout.SimpleSpinnerItem);
            //filterAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            //filterSpinner.Adapter = filterAdapter;

            //Навигация по уровням иерархии фильтруемого образа
            //Обработчик кликов по пунктам меню
            navFilSpinner = view.FindViewById <Spinner>(Resource.Id.NavFilSpinner);
            navFilSpinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(navFilSpinner_ItemSelected);

            //Первоначальное составление списка элементов в меню navFilSpinner
            FiltrationNavList.GetFromCache(0, -1, out idFiltrationNavList, out textFiltrationNavList);
            var navFilAdapter = new ArrayAdapter(Activity, Android.Resource.Layout.SimpleSpinnerItem, textFiltrationNavList);

            navFilAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            navigationFiltrationAdapter = navFilAdapter;
            navFilSpinner.Adapter       = navigationFiltrationAdapter;
            //result &= Service.GetRootCategory??
            //navFilSpinner.Adapter.RegisterDataSetObserver();

            return(view);
        }
コード例 #4
0
ファイル: Template.cs プロジェクト: masterheroit/Layered
        /// <summary>Default constructor.</summary>
        /// <param name="template"><see cref="System.Drawing.Bitmap"/>, that will be used as a template.</param>
        /// <param name="marginMask"><see cref="System.Drawing.Bitmap"/>, that reprensets a map with two colors (transparent and opaque) and used to determine margin (<see cref="System.Windows.Forms.Padding"/>).</param>
        /// <param name="gradientWidth">Minumum width or height of gradient.</param>
        public Template(Bitmap template, Bitmap marginMask = null, int gradientWidth = 20)
        {
            // Basicly, we're cutting each fragment from provided template, then triming each
            // side in order to get rid of empty space. After that, we're drawing onto new
            // bitmap those fragments and creating everything we need to launch the test.

            // Provided bitmap must have specific size, so we could divide it onto three parts
            // horizontally and vertically. A little later, we're checking results...
            var width  = template.Width / 3;
            var height = template.Height / 3;

            // ...and throwing exception, if something wrong
            if ((width % 1) != 0 || (height % 1) != 0)
            {
                throw new Exception($"Width or height of provided bitmap wrong. Width / 3: {width}; Height / 3: {height}");
            }

            // Here we might ignore it, but when updating layered windows, there might be problems.
            if (template.PixelFormat != PixelFormat.Format32bppArgb)
            {
                throw new Exception("Pixel format of provided bitmap not equals PixelFormat.Format32bppArgb");
            }

            // Creating fragments of corners for horizontal sides
            var hTopLeft     = new Fragment(template, new Rectangle(0, 0, width, height), true);
            var hTopRight    = new Fragment(template, new Rectangle(width * 2, 0, width, height), true);
            var hBottomLeft  = new Fragment(template, new Rectangle(0, height * 2, width, height), true);
            var hBottomRight = new Fragment(template, new Rectangle(width * 2, height * 2, width, height), true);

            // Creating fragments of corners for vertical sides
            var vTopLeft     = new Fragment(template, new Rectangle(0, 0, width, height), true);
            var vTopRight    = new Fragment(template, new Rectangle(width * 2, 0, width, height), true);
            var vBottomLeft  = new Fragment(template, new Rectangle(0, height * 2, width, height), true);
            var vBottomRight = new Fragment(template, new Rectangle(width * 2, height * 2, width, height), true);

            // Creating fragments of sides
            var left   = new Fragment(template, new Rectangle(0, height, width, height), true);
            var right  = new Fragment(template, new Rectangle(width * 2, height, width, height), true);
            var top    = new Fragment(template, new Rectangle(width, 0, width, height), true);
            var bottom = new Fragment(template, new Rectangle(width, height * 2, width, height), true);

            // You can't move several layered windows simultaniusly, even DeferWindowPos fails.
            // But we could create specific mask, that will cover any delays in movement

            // Generating and applying mask to each corner
            hTopLeft.ApplyMask(MaskType.HTopLeft, gradientWidth);
            hTopRight.ApplyMask(MaskType.HTopRight, gradientWidth);
            hBottomLeft.ApplyMask(MaskType.HBottomLeft, gradientWidth);
            hBottomRight.ApplyMask(MaskType.HBottomRight, gradientWidth);

            // ...
            vTopLeft.ApplyMask(MaskType.VTopLeft, gradientWidth);
            vTopRight.ApplyMask(MaskType.VTopRight, gradientWidth);
            vBottomLeft.ApplyMask(MaskType.VBottomLeft, gradientWidth);
            vBottomRight.ApplyMask(MaskType.VBottomRight, gradientWidth);

            // Calculating maximum size of each side. This will be used during scaling sides and
            // creating inner rectangle. Last thing will be used in order to create Metrics.
            var leftSide   = Max(vTopLeft.Width, left.Width, vBottomLeft.Width);
            var topSide    = Max(vTopLeft.Height, top.Height, vTopRight.Height);
            var rightSide  = Max(vTopRight.Width, right.Width, vBottomRight.Width);
            var bottomSide = Max(vBottomLeft.Height, bottom.Height, vBottomRight.Height);

            // Since we're having two types of corners, we need a place for all of them.
            // So, we could scale sides and store 4 corners inside of square.
            left.Scale(0, topSide + bottomSide);
            right.Scale(0, topSide + bottomSide);
            top.Scale(leftSide + bottomSide, 0);
            bottom.Scale(leftSide + bottomSide, 0);

            // Creating bitmap, that will contain all eight corners and four sides
            Bitmap = new Bitmap((leftSide + rightSide) * 2, (topSide + bottomSide) * 2, PixelFormat.Format32bppArgb);

            // Calculating inner rectangle, that will be used as a parameter for Metrics
            InnerRectangle = new Rectangle {
                X      = leftSide,
                Y      = topSide,
                Width  = leftSide + rightSide,
                Height = topSide + bottomSide
            };

            // Metrics contain information about each fragment on bitmap, and we're
            // creating metrics in order to draw each fragment onto bitmap, simple.
            Metrics = new Metrics(Bitmap.Size, InnerRectangle);

            // ...
            using (var g = Graphics.FromImage(Bitmap)) {
                // Sides
                g.DrawImage(top.Bitmap, Metrics.Top, new Rectangle(Point.Empty, top.Size), GraphicsUnit.Pixel);
                g.DrawImage(bottom.Bitmap, Metrics.Bottom, new Rectangle(Point.Empty, bottom.Size), GraphicsUnit.Pixel);
                g.DrawImage(left.Bitmap, Metrics.Left, new Rectangle(Point.Empty, left.Size), GraphicsUnit.Pixel);
                g.DrawImage(right.Bitmap, Metrics.Right, new Rectangle(Point.Empty, right.Size), GraphicsUnit.Pixel);

                // Corners for vertical sides
                g.DrawImage(vTopLeft.Bitmap, Metrics.Vertical.TopLeft, new Rectangle(Point.Empty, vTopLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(vTopRight.Bitmap, Metrics.Vertical.TopRight, new Rectangle(Point.Empty, vTopRight.Size), GraphicsUnit.Pixel);
                g.DrawImage(vBottomLeft.Bitmap, Metrics.Vertical.BottomLeft, new Rectangle(Point.Empty, vBottomLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(vBottomRight.Bitmap, Metrics.Vertical.BottomRight, new Rectangle(Point.Empty, vBottomRight.Size), GraphicsUnit.Pixel);

                // Corners for horizontal sides
                g.DrawImage(hTopLeft.Bitmap, Metrics.Horizontal.TopLeft, new Rectangle(Point.Empty, vTopLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(hTopRight.Bitmap, Metrics.Horizontal.TopRight, new Rectangle(Point.Empty, vTopRight.Size), GraphicsUnit.Pixel);
                g.DrawImage(hBottomLeft.Bitmap, Metrics.Horizontal.BottomLeft, new Rectangle(Point.Empty, vBottomLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(hBottomRight.Bitmap, Metrics.Horizontal.BottomRight, new Rectangle(Point.Empty, vBottomRight.Size), GraphicsUnit.Pixel);
            }

            // After we're done with creating result-bitmap, we can dispose from each fragment
            hTopLeft.Dispose();
            hTopRight.Dispose();
            hBottomLeft.Dispose();
            hBottomRight.Dispose();

            // ...
            vTopLeft.Dispose();
            vTopRight.Dispose();
            vBottomLeft.Dispose();
            vBottomRight.Dispose();

            // ...
            left.Dispose();
            right.Dispose();
            top.Dispose();
            bottom.Dispose();

            // Developer could specify margin manually, but it will take time to get it right.
            // So, instead of manual setup, we're using bitmap, that contains two types of pixels:
            // one pixels are fully transparent (Color.A == 0), the other one opaque (Color.A = 255).
            // Using the same class to cut and trim fragments, we can calculate what we need.
            if (marginMask != null)
            {
                // Creating fragments from sides (top, bottom, left, right)
                var topBitmap    = new Fragment(marginMask, new Rectangle(width, 0, width, height), true);
                var bottomBitmap = new Fragment(marginMask, new Rectangle(width, height * 2, width, height), true);
                var leftBitmap   = new Fragment(marginMask, new Rectangle(0, height, width, height), true);
                var rightBitmap  = new Fragment(marginMask, new Rectangle(width * 2, height, width, height), true);

                // ...
                Margin = new Padding(-leftBitmap.Width, -topBitmap.Height, -(rightBitmap.Width + 1), -(bottomBitmap.Height + 1));

                // ...
                topBitmap.Dispose();
                bottomBitmap.Dispose();
                leftBitmap.Dispose();
                rightBitmap.Dispose();
            }
            else
            {
                // In this case, bitmap wasn't specified, so, margin will be empty. In this case,
                // developer can open testing form and tweak margin on each side manually.
                Margin = Padding.Empty;
            }

            // Final steps, creating theme and form. From now, developer can test generated
            // bitmap and see, what's wrong and what's not.
            Theme = new Theme(Bitmap, Metrics, Margin);
            Form  = new TestingForm(this);
        }
コード例 #5
0
        //private Android.Support.V7.Widget.SearchView _searchView;        //dfdfds

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            string text     = Intent.GetStringExtra("Account") ?? "Emeri";
            string workMode = Intent.GetStringExtra("Password") ?? "Data not available";

            //TO DO
            //if (workMode == "q") { WorkingInetAndSQL.DeleteRowsInDBIfNeed("events.sqlite"); };

            FragmentLaunched = "main";
            try
            {
                SetContentView(Resource.Layout.MainOld);
            }
            catch (Exception e) { var a = e; throw; }

            SupportActionBar.SetDisplayShowHomeEnabled(true);

            if (FragmentLaunched == "main")
            {
                try
                {
                    FragmentManager.BeginTransaction()
                    .Remove(_lastFragment);
                    _lastFragment.Dispose();
                }
                catch (Exception e) { var k = e.Message; }
            }

            //Первоначальная загрузка
            _flyOut = FindViewById <FlyOutContainer>(Resource.Id.FlyOutContainer);

            //ГЛАВНОЕ МЕНЮ контейнера
            var menuButton = FindViewById(Resource.Id.MenuButton);

            menuButton.Click += (sender, e) =>
            {
                _flyOut.AnimatedOpened = !_flyOut.AnimatedOpened;
            };

            // mess with fragments begin //
            var eventsListFragment = new EventsListFragment();

            _lastFragment = eventsListFragment;

            var arguments = new Bundle();

            arguments.PutString(EventsListFragment.Account, "Emeri");
            arguments.PutString(EventsListFragment.Password, "Emeri");
            eventsListFragment.Arguments = arguments;

            FragmentManager.BeginTransaction()
            .Add(Resource.Id.content_frame, eventsListFragment)
            .Commit();

            //Избавляемся от фрагмента, если открываем профиль аккаунта - ProfileFragments
            var profileTextView = FindViewById <TextView>(Resource.Id.textView6);

            profileTextView.Click += (sender, args) =>
            {
                var profileFragment = new ProfileFragment();

                FragmentManager.BeginTransaction()
                .Remove(_lastFragment)
                .Add(Resource.Id.content_frame, profileFragment)
                .Commit();

                _lastFragment.Dispose();
                _lastFragment = profileFragment;

                _flyOut.ExternalyClosed();
            };

            //Избавляемся от фрагмента, если открываем события - EventListFragments
            var eventsListTextView = FindViewById <TextView>(Resource.Id.textView1);

            eventsListTextView.Click += (sender, args) =>
            {
                var eventsListFragment2 = new EventsListFragment();

                FragmentManager.BeginTransaction()
                .Remove(_lastFragment)
                .Add(Resource.Id.content_frame, eventsListFragment2)
                .Commit();

                _lastFragment.Dispose();
                _lastFragment = eventsListFragment2;

                _flyOut.ExternalyClosed();
            };
        }
コード例 #6
0
ファイル: Exchange.cs プロジェクト: arsuq/brays
 public void Dispose()
 {
     Fragment?.Dispose();
     Interlocked.Exchange(ref state, (int)XState.Disposed);
 }
コード例 #7
0
ファイル: Template.cs プロジェクト: ikenni/Layered
        /// <summary>Default constructor.</summary>
        /// <param name="template"><see cref="System.Drawing.Bitmap"/>, that will be used as a template.</param>
        /// <param name="marginMask"><see cref="System.Drawing.Bitmap"/>, that reprensets a map with two colors (transparent and opaque) and used to determine margin (<see cref="System.Windows.Forms.Padding"/>).</param>
        /// <param name="gradientWidth">Minumum width or height of gradient.</param>
        public Template(Bitmap template, Bitmap marginMask = null, int gradientWidth = 20)
        {
            // Basicly, we're cutting each fragment from provided template, then triming each
            // side in order to get rid of empty space. After that, we're drawing onto new
            // bitmap those fragments and creating everything we need to launch the test.

            // Provided bitmap must have specific size, so we could divide it onto three parts
            // horizontally and vertically. A little later, we're checking results...
            var width = template.Width / 3;
            var height = template.Height / 3;

            // ...and throwing exception, if something wrong
            if ((width%1) != 0 || (height%1) != 0) {
                throw new Exception($"Width or height of provided bitmap wrong. Width / 3: {width}; Height / 3: {height}");
            }

            // Here we might ignore it, but when updating layered windows, there might be problems.
            if (template.PixelFormat != PixelFormat.Format32bppArgb) {
                throw new Exception("Pixel format of provided bitmap not equals PixelFormat.Format32bppArgb");
            }

            // Creating fragments of corners for horizontal sides
            var hTopLeft = new Fragment(template, new Rectangle(0, 0, width, height), true);
            var hTopRight = new Fragment(template, new Rectangle(width * 2, 0, width, height), true);
            var hBottomLeft = new Fragment(template, new Rectangle(0, height * 2, width, height), true);
            var hBottomRight = new Fragment(template, new Rectangle(width * 2, height * 2, width, height), true);

            // Creating fragments of corners for vertical sides
            var vTopLeft = new Fragment(template, new Rectangle(0, 0, width, height), true);
            var vTopRight = new Fragment(template, new Rectangle(width * 2, 0, width, height), true);
            var vBottomLeft = new Fragment(template, new Rectangle(0, height * 2, width, height), true);
            var vBottomRight = new Fragment(template, new Rectangle(width * 2, height * 2, width, height), true);

            // Creating fragments of sides
            var left = new Fragment(template, new Rectangle(0, height, width, height), true);
            var right = new Fragment(template, new Rectangle(width * 2, height, width, height), true);
            var top = new Fragment(template, new Rectangle(width, 0, width, height), true);
            var bottom = new Fragment(template, new Rectangle(width, height * 2, width, height), true);

            // You can't move several layered windows simultaniusly, even DeferWindowPos fails.
            // But we could create specific mask, that will cover any delays in movement

            // Generating and applying mask to each corner
            hTopLeft.ApplyMask(MaskType.HTopLeft, gradientWidth);
            hTopRight.ApplyMask(MaskType.HTopRight, gradientWidth);
            hBottomLeft.ApplyMask(MaskType.HBottomLeft, gradientWidth);
            hBottomRight.ApplyMask(MaskType.HBottomRight, gradientWidth);

            // ...
            vTopLeft.ApplyMask(MaskType.VTopLeft, gradientWidth);
            vTopRight.ApplyMask(MaskType.VTopRight, gradientWidth);
            vBottomLeft.ApplyMask(MaskType.VBottomLeft, gradientWidth);
            vBottomRight.ApplyMask(MaskType.VBottomRight, gradientWidth);

            // Calculating maximum size of each side. This will be used during scaling sides and
            // creating inner rectangle. Last thing will be used in order to create Metrics.
            var leftSide = Max(vTopLeft.Width, left.Width, vBottomLeft.Width);
            var topSide = Max(vTopLeft.Height, top.Height, vTopRight.Height);
            var rightSide = Max(vTopRight.Width, right.Width, vBottomRight.Width);
            var bottomSide = Max(vBottomLeft.Height, bottom.Height, vBottomRight.Height);

            // Since we're having two types of corners, we need a place for all of them.
            // So, we could scale sides and store 4 corners inside of square.
            left.Scale(0, topSide + bottomSide);
            right.Scale(0, topSide + bottomSide);
            top.Scale(leftSide + bottomSide, 0);
            bottom.Scale(leftSide + bottomSide, 0);

            // Creating bitmap, that will contain all eight corners and four sides
            Bitmap = new Bitmap((leftSide + rightSide) * 2, (topSide + bottomSide) * 2, PixelFormat.Format32bppArgb);

            // Calculating inner rectangle, that will be used as a parameter for Metrics
            InnerRectangle = new Rectangle {
                X = leftSide,
                Y = topSide,
                Width = leftSide + rightSide,
                Height = topSide + bottomSide
            };

            // Metrics contain information about each fragment on bitmap, and we're
            // creating metrics in order to draw each fragment onto bitmap, simple.
            Metrics = new Metrics(Bitmap.Size, InnerRectangle);

            // ...
            using (var g = Graphics.FromImage(Bitmap)) {

                // Sides
                g.DrawImage(top.Bitmap, Metrics.Top, new Rectangle(Point.Empty, top.Size), GraphicsUnit.Pixel);
                g.DrawImage(bottom.Bitmap, Metrics.Bottom, new Rectangle(Point.Empty, bottom.Size), GraphicsUnit.Pixel);
                g.DrawImage(left.Bitmap, Metrics.Left, new Rectangle(Point.Empty, left.Size), GraphicsUnit.Pixel);
                g.DrawImage(right.Bitmap, Metrics.Right, new Rectangle(Point.Empty, right.Size), GraphicsUnit.Pixel);

                // Corners for vertical sides
                g.DrawImage(vTopLeft.Bitmap, Metrics.Vertical.TopLeft, new Rectangle(Point.Empty, vTopLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(vTopRight.Bitmap, Metrics.Vertical.TopRight, new Rectangle(Point.Empty, vTopRight.Size), GraphicsUnit.Pixel);
                g.DrawImage(vBottomLeft.Bitmap, Metrics.Vertical.BottomLeft, new Rectangle(Point.Empty, vBottomLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(vBottomRight.Bitmap, Metrics.Vertical.BottomRight, new Rectangle(Point.Empty, vBottomRight.Size), GraphicsUnit.Pixel);

                // Corners for horizontal sides
                g.DrawImage(hTopLeft.Bitmap, Metrics.Horizontal.TopLeft, new Rectangle(Point.Empty, vTopLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(hTopRight.Bitmap, Metrics.Horizontal.TopRight, new Rectangle(Point.Empty, vTopRight.Size), GraphicsUnit.Pixel);
                g.DrawImage(hBottomLeft.Bitmap, Metrics.Horizontal.BottomLeft, new Rectangle(Point.Empty, vBottomLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(hBottomRight.Bitmap, Metrics.Horizontal.BottomRight, new Rectangle(Point.Empty, vBottomRight.Size), GraphicsUnit.Pixel);

            }

            // After we're done with creating result-bitmap, we can dispose from each fragment
            hTopLeft.Dispose();
            hTopRight.Dispose();
            hBottomLeft.Dispose();
            hBottomRight.Dispose();

            // ...
            vTopLeft.Dispose();
            vTopRight.Dispose();
            vBottomLeft.Dispose();
            vBottomRight.Dispose();

            // ...
            left.Dispose();
            right.Dispose();
            top.Dispose();
            bottom.Dispose();

            // Developer could specify margin manually, but it will take time to get it right.
            // So, instead of manual setup, we're using bitmap, that contains two types of pixels:
            // one pixels are fully transparent (Color.A == 0), the other one opaque (Color.A = 255).
            // Using the same class to cut and trim fragments, we can calculate what we need.
            if (marginMask != null) {

                // Creating fragments from sides (top, bottom, left, right)
                var topBitmap = new Fragment(marginMask, new Rectangle(width, 0, width, height), true);
                var bottomBitmap = new Fragment(marginMask, new Rectangle(width, height*2, width, height), true);
                var leftBitmap = new Fragment(marginMask, new Rectangle(0, height, width, height), true);
                var rightBitmap = new Fragment(marginMask, new Rectangle(width*2, height, width, height), true);

                // ...
                Margin = new Padding(-leftBitmap.Width, -topBitmap.Height, -(rightBitmap.Width + 1), -(bottomBitmap.Height + 1));

                // ...
                topBitmap.Dispose();
                bottomBitmap.Dispose();
                leftBitmap.Dispose();
                rightBitmap.Dispose();

            } else {

                // In this case, bitmap wasn't specified, so, margin will be empty. In this case,
                // developer can open testing form and tweak margin on each side manually.
                Margin = Padding.Empty;

            }

            // Final steps, creating theme and form. From now, developer can test generated
            // bitmap and see, what's wrong and what's not.
            Theme = new Theme(Bitmap, Metrics, Margin);
            Form = new TestingForm(this);
        }