//--------------------------------------------------------------------
            public ItemLayout LayoutItem(Graphics Graphics, Image Image, string Text, Size MaxSize, bool SmallestLayout)
            {
                if (MaxSize.Width <= 0)
                {
                    throw new Exception("Width is a required parameter but was not supplied.");
                }
                ItemLayout actual_layout = null;

                // Get the image size.
                Size image_size = new Size(0, 0);

                if (Image != null)
                {
                    image_size = Image.Size;
                }

                if (MaxSize.Height <= 0)
                {
                    // Calculate the layout based upon the given width and maximum height.
                    ItemLayout max_layout = this.OutsideInLayout(Graphics, image_size, new Size(MaxSize.Width, int.MaxValue));

                    // Get the actual text size.
                    Size text_size = this.MeasureText(Graphics, Text, max_layout.Text.Size);

                    // Readjust layout to fit specifications.
                    if (SmallestLayout)
                    {
                        // Minimize width and height.
                        actual_layout = this.InsideOutLayout(image_size, text_size);
                    }
                    else
                    {
                        // Minimize height.
                        text_size.Width = max_layout.Text.Width;
                        actual_layout   = this.InsideOutLayout(image_size, text_size);
                    }
                }
                else
                {
                    // Calculate the layout based upon the maximum size.
                    ItemLayout max_layout = this.OutsideInLayout(Graphics, image_size, MaxSize);

                    // Readjust layout to fit specifications.
                    if (SmallestLayout)
                    {
                        // Get the actual text size.
                        Size text_size = this.MeasureText(Graphics, Text, max_layout.Text.Size);

                        // Minimize width and height.
                        actual_layout = this.InsideOutLayout(image_size, text_size);
                    }
                    else
                    {
                        // No reduction, keep layout at maximum size.
                        actual_layout = max_layout;
                    }
                }

                return(actual_layout);
            }
예제 #2
0
        public void ItemLayoutgetCPtr()
        {
            tlog.Debug(tag, $"ItemLayoutgetCPtr START");

            using (View view = new View())
            {
                var testingTarget = new MyItemLayout(view.SwigCPtr.Handle, false);
                Assert.IsNotNull(testingTarget, "Should be not null!");
                Assert.IsInstanceOf <ItemLayout>(testingTarget, "Should be an Instance of ItemLayout!");

                try
                {
                    ItemLayout.getCPtr(testingTarget);
                }
                catch (Exception e)
                {
                    tlog.Debug(tag, e.Message.ToString());
                    Assert.Fail("Caught Exception : Failed!");
                }

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"ItemLayoutgetCPtr END (OK)");
        }
예제 #3
0
    static void DrawGameObjectName(ItemReference itemReference, GizmoType gizmoType)
    {
        // Dont show gizmos over item references that live in an inactive layout
        if (itemReference.transform.parent)
        {
            ItemLayout layout = itemReference.transform.parent.GetComponent <ItemLayout>();

            if (layout && !layout.visualize)
            {
                return;
            }
        }

        if (!backgroundTexture)
        {
            backgroundTexture = new Texture2D(1, 1);
            backgroundTexture.SetPixel(0, 0, new Color(0f, 0f, 0f, .75f));
            backgroundTexture.Apply();
        }

        GUIStyle labelStyle = new GUIStyle();

        labelStyle.fontSize          = 14;
        labelStyle.fontStyle         = FontStyle.Bold;
        labelStyle.normal.textColor  = itemReference.GetStatusColor();
        labelStyle.normal.background = backgroundTexture;

        Handles.Label(itemReference.transform.position, "Ref" + itemReference.NiceName(), labelStyle);

        // TODO: edit the bounds gizmo
//        Handles.CubeCap(0, itemReference.transform.position, Quaternion.identity, 1f);
//        Handles.RectangleCap(0, itemReference.transform.position, Quaternion.identity, 1f);
    }
            //--------------------------------------------------------------------
            public ItemLayout DrawItem(Graphics Graphics, Image Image, string Text, ItemLayout Layout)
            {
                ItemLayout layout = Layout.Clone();

                // Draw the border.
                if (this._BorderStyle != null)
                {
                    if (this._TextStyle == null)
                    {
                        this._TextStyle = new TextStyle();
                    }
                    layout.Content = this._BorderStyle.Draw(Graphics, Layout.Bounds, this._TextStyle.BackColor);
                }

                //// Erase the content background.
                //this.TextStyle.EraseBackground( Graphics, Layout.Content );

                // Draw the image.
                if ((this._ImageStyle != null) && (Image != null))
                {
                    layout.Image = this._ImageStyle.Draw(Graphics, Layout.Image, Image);
                }

                // Draw the text.
                if (string.IsNullOrEmpty(Text) != true)
                {
                    if (this._TextStyle == null)
                    {
                        this._TextStyle = new TextStyle();
                    }
                    layout.Text = this._TextStyle.Draw(Graphics, Text, Layout.Text, false);
                }

                return(layout);
            }
            //-------------------------------------------------
            public ItemLayout OutsideInLayout(Graphics Graphics, Size ImageSize, Size MaxSize)
            {
                ItemLayout layout = new ItemLayout();

                // Get the bounding rectangle.
                layout.Bounds = new Rectangle(0, 0, MaxSize.Width, MaxSize.Height);

                // Get the content rectangle.
                if (this._BorderStyle == null)
                {
                    layout.Content = layout.Bounds;
                }
                else
                {
                    layout.Content = this._BorderStyle.GetInnerRectangle(layout.Bounds);
                }

                // Get the image rectangle.
                if (this._ImageStyle == null)
                {
                    layout.Image = new Rectangle(layout.Content.Location, new Size(0, 0));
                }
                else
                {
                    layout.Image = LocateContentRectangle(layout.Bounds, ImageSize, this._ImageStyle.Alignment);
                }

                // Get the text rectangle.
                List <Rectangle> unoccupied_rectangles = GetUnoccupiedRectangles(layout.Content, layout.Image);

                layout.Text = GetLargestRectangle(unoccupied_rectangles);

                return(layout);
            }
            //-------------------------------------------------
            public ItemLayout Clone()
            {
                ItemLayout layout = new ItemLayout();

                layout.Bounds  = new Rectangle(this.Bounds.Location, this.Bounds.Size);
                layout.Content = new Rectangle(this.Content.Location, this.Content.Size);
                layout.Image   = new Rectangle(this.Image.Location, this.Image.Size);
                layout.Text    = new Rectangle(this.Text.Location, this.Text.Size);
                return(layout);
            }
예제 #7
0
        public void ReadLayoutFromXMLFile(string file)
        {
            var config = new Configure();
            var doc    = new XmlDocument();

            try
            {
                void NodeToBox(XmlNode groupNode, ListBox box, bool sorted = false)
                {
                    var items = groupNode.ChildNodes;
                    var list  = new List <KeyValuePair <int, string> >();

                    foreach (XmlNode node in items)
                    {
                        int    ID   = int.Parse(node.Attributes["ID"].Value);
                        string Name = node.Attributes["Name"].Value;
                        list.Add(new KeyValuePair <int, string>(ID, Name));
                    }
                    if (sorted)
                    {
                        list = list.Cast <KeyValuePair <int, string> >().OrderBy(item => item.Value).ToList();
                    }
                    foreach (var item in list)
                    {
                        box.Items.Add(item);
                    }
                }

                doc.LoadXml(File.ReadAllText(file));
                var groups = doc.GetElementsByTagName("Group");
                for (int i = 0; i < groups.Count; i++)
                {
                    NodeToBox(groups[i], config.boxes[i + 1]);
                }
                NodeToBox(doc.GetElementsByTagName("Untracked")[0], config.UntrackedBox, true);

                var  options = doc.GetElementsByTagName("Options")[0];
                bool columns = bool.Parse(options.Attributes["Columns"].Value);
                config.ColumnBtn.Checked = columns;
                config.RowBtn.Checked    = !columns;

                config.CompactBox.Checked = bool.Parse(options.Attributes["Compact"].Value);
                config.BackgroundColor    = Color.FromArgb(int.Parse(options.Attributes["BackColor"].Value));
                config.ForeColorFound     = Color.FromArgb(int.Parse(options.Attributes["ForeColorFound"].Value));
                config.ForeColorMissing   = Color.FromArgb(int.Parse(options.Attributes["ForeColorMissing"].Value));

                config.OutputData();
                config.SortUntracked();
                Layout = new ItemLayout(config, this);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #8
0
        public override void Save(Serializer.RSFileWriter bw)
        {
            base.Save(bw);

            bw.WriteByte(15);
            ItemLayout.Save(bw);

            bw.WriteByte(16);
            ItemMargin.Save(bw);

            bw.WriteByte(17);
            ItemPadding.Save(bw);

            bw.WriteByte(0);
        }
예제 #9
0
        public void ItemLayoutConstructor()
        {
            tlog.Debug(tag, $"ItemLayoutConstructor START");

            using (View view = new View())
            {
                var testingTarget = new ItemLayout(view.SwigCPtr.Handle, false);
                Assert.IsNotNull(testingTarget, "Should be not null!");
                Assert.IsInstanceOf <ItemLayout>(testingTarget, "Should be an Instance of ItemLayout!");

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"ItemLayoutConstructor END (OK)");
        }
예제 #10
0
        public override bool Load(Serializer.RSFileReader br)
        {
            if (base.Load(br))
            {
                byte b;
                while ((b = br.ReadByte()) != 0)
                {
                    switch (b)
                    {
                    case 10:
                        br.ReadInt32();
                        break;

                    case 11:
                        br.ReadInt32();
                        break;

                    case 12:
                        br.ReadFloat();
                        break;

                    case 13:
                        br.ReadBool();
                        break;

                    case 14:
                        br.ReadInt32();
                        break;

                    case 15:
                        ItemLayout.Load(br);
                        break;

                    case 16:
                        ItemMargin.Load(br);
                        break;

                    case 17:
                        ItemPadding.Load(br);
                        break;
                    }
                }
                return(true);
            }

            return(false);
        }
예제 #11
0
        private void configureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var config = new Configure();
            var k      = KeyNames.Concat(RingNames).Cast <KeyValuePair <int, string> >().OrderBy(item => item.Value).ToList();

            if (Layout == null)
            {
                foreach (var x in k)
                {
                    config.UntrackedBox.Items.Add(x);
                }
            }
            else
            {
                config.CompactBox.Checked = Layout.Compact;
                config.ColumnBtn.Checked  = Layout.Columns;
                config.RowBtn.Checked     = !Layout.Columns;

                config.BackgroundColor        = Layout.BackColor;
                config.BackColorBtn.BackColor = Layout.BackColor;

                config.ForeColorFound = Layout.ForeColorFound;
                config.ForeColorFoundBtn.BackColor = Layout.ForeColorFound;

                config.ForeColorMissing = Layout.ForeColorMissing;
                config.ForeColorMissingBtn.BackColor = Layout.ForeColorMissing;

                foreach (var item in Layout.Untracked)
                {
                    config.UntrackedBox.Items.Add(item);
                }
                for (int i = 0; i < Layout.Groups.Count; i++)
                {
                    var list = Layout.Groups[i].Select(kd => new KeyValuePair <int, string>(kd.ID, kd.Name)).ToList();
                    foreach (var kv in list)
                    {
                        config.boxes[i + 1].Items.Add(kv);
                    }
                }
            }

            if (config.ShowDialog() == DialogResult.OK)
            {
                KeyGroupPanel.Controls.Clear();
                Layout = new ItemLayout(config, this);
            }
        }
예제 #12
0
        public async Task <IActionResult> UpdateLayout(Guid listId, Guid todoId, [FromBody] ItemLayout itemLayout)
        {
            var userEmail = User.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value;

            var list = await _dapperQuery.GetListAsync(listId);

            var todoListAuthorizationValidator = new TodoListAuthorizationValidator(list.Contributors, userEmail);

            if (todoListAuthorizationValidator.IsUserAuthorized())
            {
                itemLayout.AccountId = User.ReadClaimAsGuidValue("urn:codefliptodo:accountid");
                itemLayout.ItemId    = todoId;
                await _mediator.Send(itemLayout);

                return(Ok());
            }

            return(Forbid());
        }
        /// <summary>
        /// Updates the layout of control items via an implementation of <see cref="IItemLayout" />
        /// </summary>
        protected virtual void UpdateItems()
        {
            int bestHeight;

            // custom?
            if (ItemLayout != null)
            {
                bestHeight = ItemLayout.LayoutItems(this, items);
            }
            else
            {
                // nope, use the default
                bestHeight = defaultItemLayout.LayoutItems(this, items);
            }

            // IFF we are auto-sizing then adjust our height, and possibly our parents height
            if (AutoSize)
            {
                SetBestHeight(bestHeight);
            }
        }
예제 #14
0
            //-------------------------------------------------
            public ItemLayout InsideOutLayout(Size ImageSize, Size TextSize)
            {
                ItemLayout layout = new ItemLayout();

                // Get the text rectangle.
                layout.Text = new Rectangle(0, 0, TextSize.Width, TextSize.Height);

                // Get the image rectangle.
                if (this._ImageStyle == null)
                {
                    layout.Image = new Rectangle(layout.Content.Location, new Size(0, 0));
                    //layout.Image = new Rectangle( layout.Content.Location, ImageSize );
                }
                else
                {
                    layout.Image = ArrangeContentRectangle(layout.Text, ImageSize, this._ImageStyle.Alignment);
                }

                // Get the content rectangle.
                layout.Content = Rectangle.Union(layout.Text, layout.Image);

                // Get the bounding rectangle.
                if (this._BorderStyle == null)
                {
                    layout.Bounds = layout.Content;
                }
                else
                {
                    layout.Bounds = this._BorderStyle.GetOuterRectangle(layout.Content);
                }

                // Offset the rectangles to make the layout zero based.
                layout.Offset((0 - layout.Bounds.Left), (0 - layout.Bounds.Top));

                return(layout);
            }
예제 #15
0
    private void ShowLayouts(Item item)
    {
        GUILayout.Label("Layouts");

        ItemLayout[] layouts = item.GetItemLayouts();

        if (GUILayout.Button("Add new layout"))
        {
            GameObject layoutGO = new GameObject("Layout");
            layoutGO.transform.parent        = item.transform;
            layoutGO.transform.localPosition = Vector3.zero;
            layoutGO.transform.localRotation = Quaternion.identity;
            layoutGO.transform.localScale    = Vector3.one;
            ItemLayout layout = layoutGO.AddComponent <ItemLayout>();

            int maxLayoutId = -1;

            for (int i = 0; i < layouts.Length; i++)
            {
                if (maxLayoutId < layouts[i].layoutId)
                {
                    maxLayoutId = layouts[i].layoutId;
                }
            }

            layout.layoutId = maxLayoutId + 1;
        }

        for (int i = 0; i < layouts.Length; i++)
        {
            GUILayout.BeginVertical("Box");
            GUILayout.BeginHorizontal();

            layouts[i].visualize = EditorGUILayout.Toggle(layouts[i].visualize, GUILayout.MaxWidth(30f));

            GUILayout.Label(layouts[i].name);

            GUILayout.Label("W:" + layouts[i].weight.ToString());

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Select"))
            {
                Selection.activeGameObject = layouts[i].gameObject;
            }

            if (GUILayout.Button("Duplicate"))
            {
                ItemLayout layout = GameObject.Instantiate <ItemLayout>(layouts[i]);
                layout.transform.parent        = item.transform;
                layout.transform.localPosition = Vector3.zero;
                layout.transform.localRotation = Quaternion.identity;
                layout.transform.localScale    = Vector3.one;

                int maxLayoutId = -1;

                for (int j = 0; j < layouts.Length; j++)
                {
                    if (maxLayoutId < layouts[j].layoutId)
                    {
                        maxLayoutId = layouts[j].layoutId;
                    }
                }

                layout.layoutId = maxLayoutId + 1;
            }

            if (GUILayout.Button("Remove"))
            {
                if (EditorUtility.DisplayDialog("Delete layout", "Are you sure you want to remove this layout?", "Remove", "Cancel"))
                {
                    GameObject.DestroyImmediate(layouts[i].gameObject);
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
    }
예제 #16
0
    public void OnDrawGizmos()
    {
        if (Application.isPlaying)
        {
            return;
        }

        bool layoutViz = false;

        // Dont show gizmos over item references that live in an inactive layout
        if (transform.parent)
        {
            ItemLayout layout = transform.parent.GetComponent <ItemLayout>();

            layoutViz = layout.visualizeAllRandom;

            if (layout && !layout.visualize)
            {
                return;
            }
        }

        bool previzRandom    = (visualizeRandomness && Selection.activeGameObject == this.gameObject) || layoutViz;
        int  previzInstances = previzRandom ? (instanceCount > 1 ? instanceCount : 15) : 1;

        System.Random rnd = new System.Random(itemId.GetHashCode());

        if (procedural)
        {
            for (int i = 0; i < previzInstances; i++)
            {
                Matrix4x4 previzRandomMatrix = Matrix4x4.identity;

                if (previzRandom)
                {
                    Vector3 randomOffset   = ItemFactory.GetRandomPositionOffset(randomPositionAmplitude, rnd);
                    Vector3 randomRotation = ItemFactory.GetRandomRotationOffset(randomRotationAmplitude, rnd);
                    Vector3 randomScale    = ItemFactory.GetRandomScaleOffset(randomScaleAmplitude, uniformScale, rnd);

                    previzRandomMatrix = Matrix4x4.TRS(randomOffset, Quaternion.Euler(randomRotation), randomScale);
                }

                Gizmos.matrix = this.transform.localToWorldMatrix * previzRandomMatrix;
                Gizmos.color  = Color.yellow;
                Gizmos.DrawWireCube(Vector3.zero, this.availableProceduralVolume.size);

                Gizmos.color = new Color(0f, 1f, 1f, .5f);
                Gizmos.DrawCube(GetAnchorPositionWorld() - this.transform.position, GetAnchorPlaneSize());
            }
        }
        else
        {
            LoadMeshes();

            Bounds itemBounds = CalculateBoundsWorldSpace(1);
            Gizmos.color = Color.yellow;
            Gizmos.DrawWireCube(itemBounds.center, itemBounds.size);

            for (int i = 0; i < previzInstances; i++)
            {
                Matrix4x4 previzRandomMatrix = Matrix4x4.identity;

                if (previzRandom)
                {
                    Vector3 randomOffset   = ItemFactory.GetRandomPositionOffset(randomPositionAmplitude, rnd);
                    Vector3 randomRotation = ItemFactory.GetRandomRotationOffset(randomRotationAmplitude, rnd);
                    Vector3 randomScale    = ItemFactory.GetRandomScaleOffset(randomScaleAmplitude, uniformScale, rnd);

                    previzRandomMatrix = Matrix4x4.TRS(randomOffset, Quaternion.Euler(randomRotation), randomScale);
                }

                foreach (MeshTransform m  in cachedMeshes)
                {
                    m.material.SetPass(0);
                    Graphics.DrawMeshNow(m.mesh, transform.localToWorldMatrix * previzRandomMatrix * m.matrix, 0);
                }
            }
        }
    }
예제 #17
0
 void Start()
 {
     layout = gameObject.GetComponent <ItemLayout> ();
 }
예제 #18
0
파일: Utility.cs 프로젝트: Bingostew/Zesty
 public void RemoveItem(ItemLayout item)
 {
     GridManager.RemoveGridItem(Grid, item);
 }
예제 #19
0
    public override void OnInspectorGUI()
    {
        ItemLayout layout = (ItemLayout) target;

        if(!layout)
            return;

        Undo.RecordObject(layout, "Modify item layout");

        GUILayout.Space(5f);

        GUILayout.BeginVertical("Item Layout", "Window", GUILayout.MinHeight(75f));

        layout.weight = EditorGUILayout.IntField("Weight", layout.weight);
        layout.visualize = EditorGUILayout.Toggle("Visualize", layout.visualize);
        layout.visualizeAllRandom = EditorGUILayout.Toggle("View Random", layout.visualizeAllRandom);

        if(layout.transform.parent)
        {
            if(GUILayout.Button("Select parent"))
                Selection.activeGameObject = layout.transform.parent.gameObject;
        }

        if(GUILayout.Button("Add item reference"))
        {
            GameObject itemRef = new GameObject("ItemRef");
            itemRef.transform.parent = layout.transform;
            itemRef.transform.localPosition = Vector3.zero;
            itemRef.transform.localRotation = Quaternion.identity;
            itemRef.transform.localScale = Vector3.one;
            itemRef.AddComponent<ItemReference>();
        }

        ItemReference[] refs = layout.GetItemReferences();

        for(int i = 0; i < refs.Length; i++)
        {
            GUILayout.BeginHorizontal();

            Color prevColor = GUI.color;

            GUI.color = refs[i].GetStatusColor();

            GUILayout.Label(refs[i].NiceName());

            GUI.color = prevColor;

            if(GUILayout.Button("Select"))
                Selection.activeGameObject = refs[i].gameObject;
            
            if(GUILayout.Button("Remove"))
            {
                if (EditorUtility.DisplayDialog("Delete item reference", "Are you sure you want to remove this reference?", "Remove", "Cancel"))
                    GameObject.DestroyImmediate(refs[i].gameObject);
            }

            GUILayout.EndHorizontal();
        }


        GUILayout.EndVertical();

        if(GUI.changed)
            EditorUtility.SetDirty(layout);
    }
예제 #20
0
 public static IEditable GetField(this IEditableObject source, ItemLayout itemField)
 {
     return(source.GetField((int)itemField));
 }