コード例 #1
0
        /// Create a new GuiControl and move all the controls contained in the GuiEditorGroup into it.
        public void group()
        {
            GuiControl parent = this.groupParent;

            // Create group.

            GuiControl group = new ObjectCreator("GuiControl").Create();
            parent.addGuiControl(group);
            this.groupObject = group;

            // Make group fit around selection.

            string bounds = this.getGlobalBounds();
            string parentGlobalPos = parent.getGlobalPosition().AsString();

            int x = Util.getWord(bounds, 0).AsInt() - Util.getWord(parentGlobalPos, 0).AsInt();
            int y = Util.getWord(bounds, 1).AsInt() - Util.getWord(parentGlobalPos, 1).AsInt();

            group.setPosition(x, y);
            group.setExtent(new Point2F(Util.getWord(bounds, 2).AsFloat(), Util.getWord(bounds, 3).AsFloat()));

            // Reparent all objects to group.

            for (int i = 0; i < this.count; i ++)
                {
                GuiControl ctrl = this["ctrl[" + i + "]"];

                // Save parent for undo.

                this["ctrlParent[" + i + "]"] = ctrl.parentGroup;

                // Reparent.

                group.addGuiControl(ctrl);

                // Move into place in new parent.

                string pos = ctrl.getPosition().AsString();
                ctrl.setPosition(Util.getWord(pos, 0).AsInt() - x, Util.getWord(pos, 1).AsInt() - y);
                }
        }