Example #1
0
    // Update the virtual button rect in native
    public bool UpdateAreaRectangle(DataSet dataSet)
    {
        if (dataSet == null)
        {
            Debug.LogError("Attempting to update a virtual button without a dataset");
            return(false);
        }

        string        trackableName = this.GetImageTarget().TrackableName;
        RectangleData rectData      = new RectangleData();

        rectData.leftTopX     = mLeftTop.x;
        rectData.leftTopY     = mLeftTop.y;
        rectData.rightBottomX = mRightBottom.x;
        rectData.rightBottomY = mRightBottom.y;

        IntPtr rectPtr = Marshal.AllocHGlobal(Marshal.SizeOf(
                                                  typeof(RectangleData)));

        Marshal.StructureToPtr(rectData, rectPtr, false);
        int success = virtualButtonSetAreaRectangle(dataSet.DataSetPtr,
                                                    trackableName, this.VirtualButtonName, rectPtr);

        Marshal.FreeHGlobal(rectPtr);

        if (success == 0)
        {
            Debug.LogError("Virtual Button area rectangle could not be set.");
            return(false);
        }

        return(true);
    }
    private void CreateVirtualButtonsFromNative()
    {
        int virtualButtonDataArrayLength = QCARWrapper.Instance.ImageTargetGetNumVirtualButtons(this.mDataSet.DataSetPtr, base.Name);

        if (virtualButtonDataArrayLength > 0)
        {
            IntPtr virtualButtonDataArray = Marshal.AllocHGlobal((int)(Marshal.SizeOf(typeof(QCARManagerImpl.VirtualButtonData)) * virtualButtonDataArrayLength));
            IntPtr rectangleDataArray     = Marshal.AllocHGlobal((int)(Marshal.SizeOf(typeof(RectangleData)) * virtualButtonDataArrayLength));
            QCARWrapper.Instance.ImageTargetGetVirtualButtons(virtualButtonDataArray, rectangleDataArray, virtualButtonDataArrayLength, this.mDataSet.DataSetPtr, base.Name);
            for (int i = 0; i < virtualButtonDataArrayLength; i++)
            {
                IntPtr ptr = new IntPtr(virtualButtonDataArray.ToInt32() + (i * Marshal.SizeOf(typeof(QCARManagerImpl.VirtualButtonData))));
                QCARManagerImpl.VirtualButtonData data = (QCARManagerImpl.VirtualButtonData)Marshal.PtrToStructure(ptr, typeof(QCARManagerImpl.VirtualButtonData));
                if (!this.mVirtualButtons.ContainsKey(data.id))
                {
                    IntPtr        ptr4     = new IntPtr(rectangleDataArray.ToInt32() + (i * Marshal.SizeOf(typeof(RectangleData))));
                    RectangleData area     = (RectangleData)Marshal.PtrToStructure(ptr4, typeof(RectangleData));
                    int           capacity = 0x80;
                    StringBuilder vbName   = new StringBuilder(capacity);
                    if (QCARWrapper.Instance.ImageTargetGetVirtualButtonName(this.mDataSet.DataSetPtr, base.Name, i, vbName, capacity) == 0)
                    {
                        Debug.LogError("Failed to get virtual button name.");
                    }
                    else
                    {
                        VirtualButton button = new VirtualButtonImpl(vbName.ToString(), data.id, area, this, this.mDataSet);
                        this.mVirtualButtons.Add(data.id, button);
                    }
                }
            }
            Marshal.FreeHGlobal(virtualButtonDataArray);
            Marshal.FreeHGlobal(rectangleDataArray);
        }
    }
Example #3
0
    private bool CreateNewVirtualButtonFromBehaviour(VirtualButtonBehaviour newVBB)
    {
        // Calculate the button area:
        Vector2 leftTop, rightBottom;

        newVBB.CalculateButtonArea(out leftTop, out rightBottom);
        RectangleData area = new RectangleData
        {
            leftTopX     = leftTop.x,
            leftTopY     = leftTop.y,
            rightBottomX = rightBottom.x,
            rightBottomY = rightBottom.y
        };

        VirtualButton virtualButton = mImageTarget.CreateVirtualButton(newVBB.VirtualButtonName, area);

        if (virtualButton == null)
        {
            Destroy(newVBB.gameObject);
            return(false);
        }

        IEditorVirtualButtonBehaviour newEditorVBB = newVBB;

        newEditorVBB.InitializeVirtualButton(virtualButton);
        mVirtualButtonBehaviours.Add(virtualButton.ID, newVBB);
        return(true);
    }
    private bool CreateNewVirtualButtonFromBehaviour(VirtualButtonAbstractBehaviour newVBB)
    {
        Vector2 vector;
        Vector2 vector2;

        newVBB.CalculateButtonArea(out vector, out vector2);
        RectangleData area = new RectangleData {
            leftTopX     = vector.x,
            leftTopY     = vector.y,
            rightBottomX = vector2.x,
            rightBottomY = vector2.y
        };
        VirtualButton virtualButton = this.mImageTarget.CreateVirtualButton(newVBB.VirtualButtonName, area);

        if (virtualButton == null)
        {
            UnityEngine.Object.Destroy(newVBB.gameObject);
            return(false);
        }
        IEditorVirtualButtonBehaviour behaviour = newVBB;

        behaviour.InitializeVirtualButton(virtualButton);
        this.mVirtualButtonBehaviours.Add(virtualButton.ID, newVBB);
        return(true);
    }
    private VirtualButton CreateNewVirtualButtonInNative(string name, RectangleData rectangleData)
    {
        if (this.ImageTargetType != ImageTargetType.PREDEFINED)
        {
            Debug.LogError("DataSet.RegisterVirtualButton: virtual button '" + name + "' cannot be registered for a user defined target.");
            return(null);
        }
        IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleData)));

        Marshal.StructureToPtr(rectangleData, ptr, false);
        bool          flag   = QCARWrapper.Instance.ImageTargetCreateVirtualButton(this.mDataSet.DataSetPtr, base.Name, name, ptr) != 0;
        VirtualButton button = null;

        if (!flag)
        {
            return(button);
        }
        int key = QCARWrapper.Instance.VirtualButtonGetId(this.mDataSet.DataSetPtr, base.Name, name);

        if (!this.mVirtualButtons.ContainsKey(key))
        {
            button = new VirtualButtonImpl(name, key, rectangleData, this, this.mDataSet);
            this.mVirtualButtons.Add(key, button);
            return(button);
        }
        return(this.mVirtualButtons[key]);
    }
Example #6
0
 public RectangleData CreateRectangleData(Point position, Point size, Color color)
 {
     RectangleData rectangleData = new RectangleData();
     rectangleData.position = position;
     rectangleData.size = size;
     rectangleData.color = new SerialColor(color.R, color.G, color.B);
     return rectangleData;
 }
 public VirtualButtonImpl(string name, int id, RectangleData area, ImageTarget imageTarget, DataSet dataSet)
 {
     this.mName              = name;
     this.mID                = id;
     this.mArea              = area;
     this.mIsEnabled         = true;
     this.mParentImageTarget = imageTarget;
     this.mParentDataSet     = (DataSetImpl)dataSet;
 }
    /// <summary>
    /// Creates virtual buttons for this ImageTarget from native and stores them
    /// </summary>
    private void CreateVirtualButtonsFromNative()
    {
        // Allocate array for all Image Targets.
        int numVirtualButtons = QCARWrapper.Instance.ImageTargetGetNumVirtualButtons(mDataSet.DataSetPtr, Name);

        if (numVirtualButtons > 0)
        {
            IntPtr virtualButtonDataPtr =
                Marshal.AllocHGlobal(Marshal.SizeOf(typeof(QCARManagerImpl.VirtualButtonData)) * numVirtualButtons);
            IntPtr rectangleDataPtr =
                Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleData)) * numVirtualButtons);

            // Copy Virtual Button data from native.
            QCARWrapper.Instance.ImageTargetGetVirtualButtons(virtualButtonDataPtr,
                                                              rectangleDataPtr,
                                                              numVirtualButtons,
                                                              mDataSet.DataSetPtr,
                                                              Name);

            for (int i = 0; i < numVirtualButtons; ++i)
            {
                IntPtr vbPtr = new IntPtr(virtualButtonDataPtr.ToInt32() + i *
                                          Marshal.SizeOf(typeof(QCARManagerImpl.VirtualButtonData)));
                QCARManagerImpl.VirtualButtonData vbData = (QCARManagerImpl.VirtualButtonData)
                                                           Marshal.PtrToStructure(vbPtr, typeof(QCARManagerImpl.VirtualButtonData));

                // Do not overwrite existing Virtual Buttons.
                if (mVirtualButtons.ContainsKey(vbData.id))
                {
                    continue;
                }

                IntPtr rectPtr = new IntPtr(rectangleDataPtr.ToInt32() + i *
                                            Marshal.SizeOf(typeof(RectangleData)));
                RectangleData rectData = (RectangleData)
                                         Marshal.PtrToStructure(rectPtr, typeof(RectangleData));

                // QCAR support names up to 64 characters in length, but here we allocate
                // a slightly larger buffer:
                int nameLength = 128;
                System.Text.StringBuilder vbName = new System.Text.StringBuilder(nameLength);
                if (QCARWrapper.Instance.ImageTargetGetVirtualButtonName(mDataSet.DataSetPtr, Name,
                                                                         i, vbName, nameLength) == 0)
                {
                    Debug.LogError("Failed to get virtual button name.");
                    continue;
                }

                VirtualButton virtualButton = new VirtualButtonImpl(vbName.ToString(), vbData.id, rectData, this, mDataSet);
                mVirtualButtons.Add(vbData.id, virtualButton);
            }

            Marshal.FreeHGlobal(virtualButtonDataPtr);
            Marshal.FreeHGlobal(rectangleDataPtr);
        }
    }
 public VirtualButtonImpl(string name, int id, RectangleData area,
     ImageTarget imageTarget, DataSet dataSet)
 {
     mName = name;
     mID = id;
     mArea = area;
     mIsEnabled = true;
     mParentImageTarget = imageTarget;
     mParentDataSet = (DataSetImpl)dataSet;
 }
Example #10
0
        static void InitiateDrag(object sender, MouseEventArgs e)
        {
            var target = (Rectangle)sender;

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                var data       = new RectangleData(target);
                var dataObject = new DataObject(DataFormats.Serializable, data);
                DragDrop.DoDragDrop(target, dataObject, DragDropEffects.Copy);
            }
        }
        static Rectangle CreateRectangleFromData(RectangleData data)
        {
            var child = new Rectangle
            {
                Fill   = data.Fill,
                Height = data.Height,
                Width  = data.Width
            };

            return(child);
        }
    public VirtualButton CreateVirtualButton(string name, RectangleData area)
    {
        VirtualButton button = this.CreateNewVirtualButtonInNative(name, area);

        if (button == null)
        {
            Debug.LogError("Could not create Virtual Button.");
            return(button);
        }
        Debug.Log("Created Virtual Button successfully.");
        return(button);
    }
Example #13
0
    /// <summary>
    /// Creates a new virtual button and adds it to the ImageTarget
    /// Returns NULL if the corresponding DataSet is currently active.
    /// </summary>
    public VirtualButton CreateVirtualButton(string name, RectangleData area)
    {
        VirtualButton virtualButton = CreateNewVirtualButtonInNative(name, area);

        if (virtualButton == null)
        {
            Debug.LogError("Could not create Virtual Button.");
        }
        else
        {
            Debug.Log("Created Virtual Button successfully.");
        }

        return virtualButton;
    }
    public bool UpdateAreaRectangle()
    {
        RectangleData area = new RectangleData {
            leftTopX     = this.mLeftTop.x,
            leftTopY     = this.mLeftTop.y,
            rightBottomX = this.mRightBottom.x,
            rightBottomY = this.mRightBottom.y
        };

        if (this.mVirtualButton == null)
        {
            return(false);
        }
        return(this.mVirtualButton.SetArea(area));
    }
    public override bool SetArea(RectangleData area)
    {
        IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleData)));

        Marshal.StructureToPtr(area, ptr, false);
        int num = QCARWrapper.Instance.VirtualButtonSetAreaRectangle(this.mParentDataSet.DataSetPtr, this.mParentImageTarget.Name, this.Name, ptr);

        Marshal.FreeHGlobal(ptr);
        if (num == 0)
        {
            Debug.LogError("Virtual Button area rectangle could not be set.");
            return(false);
        }
        return(true);
    }
    /// <summary>
    /// Update the virtual button rect in native
    /// </summary>
    public bool UpdateAreaRectangle()
    {
        RectangleData rectData = new RectangleData();

        rectData.leftTopX     = mLeftTop.x;
        rectData.leftTopY     = mLeftTop.y;
        rectData.rightBottomX = mRightBottom.x;
        rectData.rightBottomY = mRightBottom.y;

        if (mVirtualButton == null)
        {
            return(false);
        }

        return(mVirtualButton.SetArea(rectData));
    }
    public override bool SetArea(RectangleData area)
    {
        IntPtr rectPtr = Marshal.AllocHGlobal(Marshal.SizeOf(
                                typeof(VirtualButton.RectangleData)));
        Marshal.StructureToPtr(area, rectPtr, false);
        int success = QCARWrapper.Instance.VirtualButtonSetAreaRectangle(mParentDataSet.DataSetPtr,
            mParentImageTarget.Name, this.Name, rectPtr);
        Marshal.FreeHGlobal(rectPtr);

        if (success == 0)
        {
            Debug.LogError("Virtual Button area rectangle could not be set.");
            return false;
        }

        return true;
    }
    void IEditorImageTargetBehaviour.AssociateExistingVirtualButtonBehaviour(VirtualButtonAbstractBehaviour virtualButtonBehaviour)
    {
        VirtualButton virtualButtonByName = this.mImageTarget.GetVirtualButtonByName(virtualButtonBehaviour.VirtualButtonName);

        if (virtualButtonByName == null)
        {
            Vector2 vector;
            Vector2 vector2;
            virtualButtonBehaviour.CalculateButtonArea(out vector, out vector2);
            RectangleData area = new RectangleData {
                leftTopX     = vector.x,
                leftTopY     = vector.y,
                rightBottomX = vector2.x,
                rightBottomY = vector2.y
            };
            virtualButtonByName = this.mImageTarget.CreateVirtualButton(virtualButtonBehaviour.VirtualButtonName, area);
            if (virtualButtonByName != null)
            {
                Debug.Log("Successfully created virtual button " + virtualButtonBehaviour.VirtualButtonName + " at startup");
                virtualButtonBehaviour.UnregisterOnDestroy = true;
            }
            else
            {
                Debug.LogError("Failed to create virtual button " + virtualButtonBehaviour.VirtualButtonName + " at startup");
            }
        }
        if ((virtualButtonByName != null) && !this.mVirtualButtonBehaviours.ContainsKey(virtualButtonByName.ID))
        {
            IEditorVirtualButtonBehaviour behaviour = virtualButtonBehaviour;
            behaviour.InitializeVirtualButton(virtualButtonByName);
            this.mVirtualButtonBehaviours.Add(virtualButtonByName.ID, virtualButtonBehaviour);
            Debug.Log(string.Concat(new object[] { "Found VirtualButton named ", virtualButtonBehaviour.VirtualButton.Name, " with id ", virtualButtonBehaviour.VirtualButton.ID }));
            virtualButtonBehaviour.UpdatePose();
            if (!virtualButtonBehaviour.UpdateAreaRectangle() || !virtualButtonBehaviour.UpdateSensitivity())
            {
                Debug.LogError("Failed to update virtual button " + virtualButtonBehaviour.VirtualButton.Name + " at startup");
            }
            else
            {
                Debug.Log("Updated virtual button " + virtualButtonBehaviour.VirtualButton.Name + " at startup");
            }
        }
    }
Example #19
0
        public bool CreateGrips(RectangleData data)
        {
            if (GripCount > 0)
            {
                return(false);
            }

            plane = data.Plane;

            activeRectangle   = data.Rectangle.Corner(2);
            originalRectangle = new Point3d(activeRectangle);

            rectangleGrip.OriginalLocation = new Point3d(activeRectangle);
            rectangleGrip.Active           = true;

            AddGrip(rectangleGrip);

            return(true);
        }
    // Registers a Virtual Button at native code.
    private VirtualButton CreateNewVirtualButtonInNative(string name, RectangleData rectangleData)
    {
        // virtual buttons cannot be registered for user defined targets:
        if (ImageTargetType != ImageTargetType.PREDEFINED)
        {
            Debug.LogError("DataSet.RegisterVirtualButton: virtual button '" + name +
                           "' cannot be registered for a user defined target.");
            return(null);
        }


        IntPtr rectPtr = Marshal.AllocHGlobal(
            Marshal.SizeOf(typeof(RectangleData)));

        Marshal.StructureToPtr(rectangleData, rectPtr, false);

        bool registerWorked =
            (QCARWrapper.Instance.ImageTargetCreateVirtualButton(mDataSet.DataSetPtr, Name,
                                                                 name, rectPtr) != 0);

        VirtualButton vb = null;

        if (registerWorked)
        {
            int id = QCARWrapper.Instance.VirtualButtonGetId(mDataSet.DataSetPtr, Name,
                                                             name);

            // Check we don't have an entry for this id:
            if (!mVirtualButtons.ContainsKey(id))
            {
                // Add:
                vb = new VirtualButtonImpl(name, id, rectangleData, this, mDataSet);
                mVirtualButtons.Add(id, vb);
            }
            else
            {
                vb = mVirtualButtons[id];
            }
        }

        return(vb);
    }
Example #21
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // get plane
            var rc = RhinoGet.GetPlane(out var plane);

            if (rc != Result.Success)
            {
                return(rc);
            }

            // get width
            double width = 0;

            rc = RhinoGet.GetNumber("Specify width", false, ref width, 0.1, 1000000);
            if (rc != Result.Success)
            {
                return(rc);
            }

            // get height
            double height = 0;

            rc = RhinoGet.GetNumber("Specify height", false, ref height, 0.1, 1000000);
            if (rc != Result.Success)
            {
                return(rc);
            }

            // create rectangleData
            var data = new RectangleData(plane, width, height);
            // and sphere object
            var rectangleObject = data.CreateCustomObject();

            // add sphereObject to doc
            doc.Objects.AddRhinoObject(rectangleObject, rectangleObject.CurveGeometry);

            //redraw views
            doc.Views.Redraw();
            // return success
            return(Result.Success);
        }
Example #22
0
        public void CreateRectangle(RectangleData recData)
        {
            Rectangle rectangle = new Rectangle();

            rectangle.Width = recData.size.X;
            rectangle.Height = recData.size.Y;

            SolidColorBrush blueBrush = new SolidColorBrush();

            Color c = new Color();
            c.R = recData.color.R;
            c.G = recData.color.G;
            c.B = recData.color.B;
            c.A = 255;
            blueBrush.Color = c;

            rectangle.Fill = blueBrush;

            Canvas.SetLeft(rectangle, recData.position.X);
            Canvas.SetTop(rectangle, recData.position.Y);

            canvas.Children.Add(rectangle);
        }
    // Update the virtual button rect in native
    public bool UpdateAreaRectangle(DataSet dataSet)
    {
        if (dataSet == null)
        {
            Debug.LogError("Attempting to update a virtual button without a dataset");
            return false;
        }

        string trackableName = this.GetImageTarget().TrackableName;
        RectangleData rectData = new RectangleData();

        rectData.leftTopX = mLeftTop.x;
        rectData.leftTopY = mLeftTop.y;
        rectData.rightBottomX = mRightBottom.x;
        rectData.rightBottomY = mRightBottom.y;

        IntPtr rectPtr = Marshal.AllocHGlobal(Marshal.SizeOf(
                                typeof(RectangleData)));
        Marshal.StructureToPtr(rectData, rectPtr, false);
        int success = virtualButtonSetAreaRectangle(dataSet.DataSetPtr,
            trackableName, this.VirtualButtonName, rectPtr);
        Marshal.FreeHGlobal(rectPtr);

        if (success == 0)
        {
            Debug.LogError("Virtual Button area rectangle could not be set.");
            return false;
        }

        return true;
    }
    /// <summary>
    /// Update the virtual button rect in native
    /// </summary>
    public bool UpdateAreaRectangle()
    {
        RectangleData rectData = new RectangleData();

        rectData.leftTopX = mLeftTop.x;
        rectData.leftTopY = mLeftTop.y;
        rectData.rightBottomX = mRightBottom.x;
        rectData.rightBottomY = mRightBottom.y;

        if (mVirtualButton == null) return false;

        return mVirtualButton.SetArea(rectData);
    }
 /// <summary>
 /// Defines a new area for the button area in 3D scene units (the
 /// coordinate system is local to the ImageTarget).
 ///
 /// This method must not be called while the corresponding DataSet is
 /// active or it will return false.
 /// </summary>
 public abstract bool SetArea(RectangleData area);
Example #26
0
 public Rectangle(int x, int y, int w, int h, ConsoleColor color)
 {
     _rectangleData = new RectangleData(x, y, w, h, color);
 }
Example #27
0
 /// <summary>
 /// Defines a new area for the button area in 3D scene units (the
 /// coordinate system is local to the ImageTarget).
 ///
 /// This method must not be called while the corresponding DataSet is
 /// active or it will return false.
 /// </summary>
 public abstract bool SetArea(RectangleData area);
 /// <summary>
 /// Creates a new virtual button and adds it to the ImageTarget
 /// This is not supported for CloudReco targets.
 /// </summary>
 public VirtualButton CreateVirtualButton(string name, RectangleData area)
 {
     Debug.LogError("Virtual buttons are currently not supported for cloud reco targets.");
     return(null);
 }
Example #29
0
    // Registers a Virtual Button at native code.
    private VirtualButton CreateNewVirtualButtonInNative(string name, RectangleData rectangleData)
    {
        // virtual buttons cannot be registered for user defined targets:
        if (ImageTargetType != ImageTargetType.PREDEFINED)
        {
            Debug.LogError("DataSet.RegisterVirtualButton: virtual button '" + name +
                           "' cannot be registered for a user defined target.");
            return null;
        }

        IntPtr rectPtr = Marshal.AllocHGlobal(
            Marshal.SizeOf(typeof(RectangleData)));
        Marshal.StructureToPtr(rectangleData, rectPtr, false);

        bool registerWorked =
            (QCARWrapper.Instance.ImageTargetCreateVirtualButton(mDataSet.DataSetPtr, Name,
                                            name, rectPtr) != 0);

        VirtualButton vb = null;

        if (registerWorked)
        {
            int id = QCARWrapper.Instance.VirtualButtonGetId(mDataSet.DataSetPtr, Name,
                                        name);

            // Check we don't have an entry for this id:
            if (!mVirtualButtons.ContainsKey(id))
            {
                // Add:
                vb = new VirtualButtonImpl(name, id, rectangleData, this, mDataSet);
                mVirtualButtons.Add(id, vb);
            }
            else
            {
                vb = mVirtualButtons[id];
            }
        }

        return vb;
    }
 /// <summary>
 /// Creates a new virtual button and adds it to the ImageTarget
 /// This is not supported for CloudReco targets.
 /// </summary>
 public VirtualButton CreateVirtualButton(string name, RectangleData area)
 {
     Debug.LogError("Virtual buttons are currently not supported for cloud reco targets.");
     return null;
 }
Example #31
0
    /// <summary>
    /// Associates existing virtual button behaviour with virtualbuttons and creates new VirtualButtons if necessary
    /// </summary>
    void IEditorImageTargetBehaviour.AssociateExistingVirtualButtonBehaviour(VirtualButtonBehaviour virtualButtonBehaviour)
    {
        VirtualButton virtualButton = mImageTarget.GetVirtualButtonByName(virtualButtonBehaviour.VirtualButtonName);

        if (virtualButton == null)
        {
            Vector2 leftTop, rightBottom;
            virtualButtonBehaviour.CalculateButtonArea(out leftTop, out rightBottom);
            var area = new RectangleData
            {
                leftTopX     = leftTop.x,
                leftTopY     = leftTop.y,
                rightBottomX = rightBottom.x,
                rightBottomY = rightBottom.y
            };
            virtualButton = mImageTarget.CreateVirtualButton(virtualButtonBehaviour.VirtualButtonName, area);

            // Create the virtual button
            if (virtualButton != null)
            {
                Debug.Log("Successfully created virtual button " +
                          virtualButtonBehaviour.VirtualButtonName +
                          " at startup");

                virtualButtonBehaviour.UnregisterOnDestroy = true;
            }
            else
            {
                Debug.LogError("Failed to create virtual button " +
                               virtualButtonBehaviour.VirtualButtonName +
                               " at startup");
            }
        }

        if (virtualButton != null)
        {
            //  Duplicate check:
            if (!mVirtualButtonBehaviours.ContainsKey(virtualButton.ID))
            {
                // OK:
                IEditorVirtualButtonBehaviour editorVirtualButtonBehaviour = virtualButtonBehaviour;
                editorVirtualButtonBehaviour.InitializeVirtualButton(virtualButton);
                mVirtualButtonBehaviours.Add(virtualButton.ID, virtualButtonBehaviour);

                Debug.Log("Found VirtualButton named " +
                          virtualButtonBehaviour.VirtualButton.Name + " with id " +
                          virtualButtonBehaviour.VirtualButton.ID);

                // Handle any changes to the virtual button in the scene
                // that are not reflected in the config file
                virtualButtonBehaviour.UpdatePose();
                if (!virtualButtonBehaviour.UpdateAreaRectangle() ||
                    !virtualButtonBehaviour.UpdateSensitivity())
                {
                    Debug.LogError("Failed to update virtual button " +
                                   virtualButtonBehaviour.VirtualButton.Name +
                                   " at startup");
                }
                else
                {
                    Debug.Log("Updated virtual button " +
                              virtualButtonBehaviour.VirtualButton.Name +
                              " at startup");
                }
            }
        }
    }
    /// <summary>
    /// Associates existing virtual button behaviour with virtualbuttons and creates new VirtualButtons if necessary
    /// </summary>
    void IEditorImageTargetBehaviour.AssociateExistingVirtualButtonBehaviour(VirtualButtonBehaviour virtualButtonBehaviour)
    {
        VirtualButton virtualButton = mImageTarget.GetVirtualButtonByName(virtualButtonBehaviour.VirtualButtonName);

        if (virtualButton == null)
        {
            Vector2 leftTop, rightBottom;
            virtualButtonBehaviour.CalculateButtonArea(out leftTop, out rightBottom);
            var area = new RectangleData
                {
                    leftTopX = leftTop.x,
                    leftTopY = leftTop.y,
                    rightBottomX = rightBottom.x,
                    rightBottomY = rightBottom.y
                };
            virtualButton = mImageTarget.CreateVirtualButton(virtualButtonBehaviour.VirtualButtonName, area);

            // Create the virtual button
            if (virtualButton != null)
            {
                Debug.Log("Successfully created virtual button " +
                          virtualButtonBehaviour.VirtualButtonName +
                          " at startup");

                virtualButtonBehaviour.UnregisterOnDestroy = true;
            }
            else
            {
                Debug.LogError("Failed to create virtual button " +
                               virtualButtonBehaviour.VirtualButtonName +
                               " at startup");
            }
        }

        if (virtualButton != null)
        {
            //  Duplicate check:
            if (!mVirtualButtonBehaviours.ContainsKey(virtualButton.ID))
            {
                // OK:
                IEditorVirtualButtonBehaviour editorVirtualButtonBehaviour = virtualButtonBehaviour;
                editorVirtualButtonBehaviour.InitializeVirtualButton(virtualButton);
                mVirtualButtonBehaviours.Add(virtualButton.ID, virtualButtonBehaviour);

                Debug.Log("Found VirtualButton named " +
                        virtualButtonBehaviour.VirtualButton.Name + " with id " +
                        virtualButtonBehaviour.VirtualButton.ID);

                // Handle any changes to the virtual button in the scene
                // that are not reflected in the config file
                virtualButtonBehaviour.UpdatePose();
                if (!virtualButtonBehaviour.UpdateAreaRectangle() ||
                    !virtualButtonBehaviour.UpdateSensitivity())
                {
                    Debug.LogError("Failed to update virtual button " +
                                   virtualButtonBehaviour.VirtualButton.Name +
                                   " at startup");
                }
                else
                {
                    Debug.Log("Updated virtual button " +
                              virtualButtonBehaviour.VirtualButton.Name +
                              " at startup");
                }
            }
        }
    }
    private bool CreateNewVirtualButtonFromBehaviour(VirtualButtonBehaviour newVBB)
    {
        // Calculate the button area:
        Vector2 leftTop, rightBottom;
        newVBB.CalculateButtonArea(out leftTop, out rightBottom);
        RectangleData area = new RectangleData
        {
            leftTopX = leftTop.x,
            leftTopY = leftTop.y,
            rightBottomX = rightBottom.x,
            rightBottomY = rightBottom.y
        };

        VirtualButton virtualButton = mImageTarget.CreateVirtualButton(newVBB.VirtualButtonName, area);

        if (virtualButton == null)
        {
            Destroy(newVBB.gameObject);
            return false;
        }

        IEditorVirtualButtonBehaviour newEditorVBB = newVBB;
        newEditorVBB.InitializeVirtualButton(virtualButton);
        mVirtualButtonBehaviours.Add(virtualButton.ID, newVBB);
        return true;
    }