Exemple #1
0
        static public Vector2 XYControl(Rect rect, Vector2 value, FloatRange x_range, FloatRange y_range)
        {
            GUIControlHandle handle = GUIExtensions.GetControlHandle(FocusType.Passive);

            Vector2 mouse_point = handle.GetEvent().mousePosition;

            FloatRange interface_x_range = rect.GetHorizontalRange();
            FloatRange interface_y_range = rect.GetVerticalRange().GetFlipped();

            Vector2 point = new Vector2(
                value.x.ConvertFromRangeToRange(x_range, interface_x_range),
                value.y.ConvertFromRangeToRange(y_range, interface_y_range)
                );

            GUIExtensions.DrawPoint(
                point,
                4.0f,
                Color.red
                );

            if (rect.Contains(mouse_point))
            {
                if (handle.GetEventType().IsMouseDownish())
                {
                    return(new Vector2(
                               mouse_point.x.ConvertFromRangeToRange(interface_x_range, x_range),
                               mouse_point.y.ConvertFromRangeToRange(interface_y_range, y_range)
                               ));
                }
            }

            return(value);
        }
Exemple #2
0
        static public bool DropZoneUnityObjects(Rect rect, out IList <UnityEngine.Object> dragging)
        {
            GUIControlHandle handle = GUIExtensions.GetControlHandle(FocusType.Passive);

            if (rect.Contains(handle.GetEvent().mousePosition))
            {
                dragging = DragAndDrop
                           .objectReferences
                           .ToList();

                if (dragging.IsNotEmpty())
                {
                    switch (handle.GetEventType())
                    {
                    case EventType.DragUpdated:
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        break;

                    case EventType.DragPerform:
                        DragAndDrop.AcceptDrag();
                        handle.UseEvent();
                        return(true);
                    }
                }
            }

            dragging = Empty.IList <UnityEngine.Object>();
            return(false);
        }
Exemple #3
0
        protected override void DrawInternal()
        {
            GUIControlHandle handle = GUIExtensions.GetControlHandle(FocusType.Passive);

            Texture2D  texture            = this.GetContents <Texture2D>();
            Vector3    position           = this.GetAuxContents <Vector3>("position");
            Quaternion rotation           = this.GetAuxContents <Quaternion>("rotation");
            Vector2    size               = this.GetAuxContents <Vector2>("size");
            bool       is_overlay_enabled = this.GetAuxContents <bool>("is_overlay_enabled");

            Surface <Color> surface = texture.GetSurface();
            Utensil <Color> utensil = Painter.GetInstance().GetUtensil();

            Matrix4x4 transform     = Matrix4x4.TRS(position, rotation, size.GetSpacar(1.0f));
            Matrix4x4 inv_transform = transform.inverse;

            Vector3 world_point = Camera.current.ScreenToWorldPlanePoint(
                transform.MultiplyPlane(PlaneExtensions.CreateNormalAndPoint(new Vector3(0.0f, 0.0f, 1.0f), Vector3.zero)),
                handle.GetEvent().mousePosition.ConvertFromGUIToScreen()
                );

            Vector3 local_point   = inv_transform.MultiplyPoint(world_point);
            Vector2 texture_point = local_point.GetComponentMultiply(texture.GetSize()).GetPlanar() + 0.5f * texture.GetSize();

            Vector3 brush_size = new Vector2(Painter.GetInstance().GetBrushSize(), Painter.GetInstance().GetBrushSize())
                                 .GetComponentDivide(texture.GetSize())
                                 .GetComponentMultiply(size)
                                 .GetSpacar(1.0f);

            if (handle.IsControlCaptured() && is_overlay_enabled)
            {
                surface_now_mesh.GetMaterial().SetMainTexture(texture);
                surface_now_mesh.Draw(transform);
            }

            brush_now_mesh.Draw(world_point, rotation, brush_size);

            if (handle.GetEventType().IsMouseRelated() && handle.GetEvent().button == 0)
            {
                if (handle.GetEventType() == EventType.MouseDown)
                {
                    handle.CaptureControl();

                    this.Execute("MouseDown");
                    last_texture_point = texture_point;
                }

                if (handle.GetEventType() == EventType.MouseUp)
                {
                    handle.ReleaseControl();

                    this.Execute("MouseUp");
                }

                if (handle.IsControlCaptured())
                {
                    line_tool.MarkLines(surface, utensil, last_texture_point.GetVectorF2(), texture_point.GetVectorF2());
                    texture.Apply();
                }

                last_texture_point = texture_point;
                handle.UseEvent();
            }
        }