예제 #1
0
 /// <summary> Method that is invoked in Update signal. </summary>
 /// <param name="allowDrag">True if drag is allowed. False otherwise.</param>
 public void Update(bool allowDrag)
 {
     if (!allowDrag)
     {
         _onDrag = false;
         return;
     }
     if (_mousePressedOnRightEdge)
     {
         _onDrag = true;
         SetStartAndEnd(SourceData.Start, _timeLinePanel.WorldXToTime(_mousePos.x + _diffAtGrab), SourceData.Duration);
     }
     else if (_mousePressedOnLeftEdge)
     {
         _onDrag = true;
         SetStartAndEnd(_timeLinePanel.WorldXToTime(_mousePos.x - _diffAtGrab), SourceData.End, SourceData.Duration);
     }
     else if (_mousePressedOnCenter)
     {
         _onDrag = true;
         TimeSpan newStart = _timeLinePanel.WorldXToTime(_mousePos.x - _diffAtGrab);
         SetStartAndEnd(newStart, newStart + SourceData.Duration, SourceData.Duration);
     }
     else
     {
         _onDrag = false;
     }
 }
예제 #2
0
        /// <summary> Draws the component [have to be invoked in OnGUI]..</summary>
        /// <param name="rect">X position for the timeline.</param>
        /// <param name="scrollDelta">Scroll delta.</param>
        /// <returns>Real component size.</returns>
        public Rect GUIDraw(float xPos, float scrollDelta)
        {
            base.Draw(_rect, _rectWasChanged);
            if (_rect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.ContextClick)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Add"), false, HandleLabelAdd, null);
                    if (CopyDataAvailable)
                    {
                        menu.AddItem(new GUIContent("Paste"), false, HandleLabelAdd, _copyData);
                    }
                    else
                    {
                        menu.AddItem(new GUIContent("Paste"), false, null, null);
                    }
                    menu.ShowAsContext();
                }

                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    _wasMouseDown = true;
                }

                if (_wasMouseDown && Event.current.type == EventType.MouseDrag)
                {
                    foreach (Label label in _labels)
                    {
                        if (label.OnDrag)
                        {
                            _wasMouseDown = false;
                            break;
                        }
                    }
                }

                if (_wasMouseDown && (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseUp))
                {
                    _timeLinePanel.TimeLineEngine.SetTime(_timeLinePanel.WorldXToTime(Event.current.mousePosition.x));
                }
                if (Event.current.type == EventType.MouseUp)
                {
                    _wasMouseDown = false;
                }
            }
            else if (Event.current.mousePosition.x < _controlRect.x || Event.current.mousePosition.x > _controlRect.x + _controlRect.width)
            {
                foreach (Label label in _labels)
                {
                    label.CancelDrag();
                }
            }

            if (_backgroundTextureOryginal == null || _durationWasChanged || _rectWasChanged || _lastXPos != xPos || scrollDelta != 0)
            {
                int textureWidth  = (int)_rect.width;
                int textureHeight = (int)_rect.height;

                if (_rectWasChanged || _backgroundTextureOryginal == null)
                {
                    _backgroundTextureOryginal = new Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false);
                    _backgroundTextureOryginal.SetPixels(_backgroundTexture.GetPixels());
                    _backgroundTextureOryginal.Apply();
                }
                _lastXPos           = xPos;
                _rectWasChanged     = false;
                _durationWasChanged = false;
                foreach (Label label in _labels)
                {
                    label.Refresh();
                }
            }

            bool redrawRequest = false;

            // checking if any label need redraw
            for (int i = _labels.Count - 1; i >= 0; i--)
            {
                if (_labels[i].DrawRequest || _labels[i].SourceData.RemoveRequest)
                {
                    // reset to oryginal
                    if (!redrawRequest)
                    {
                        _backgroundTexture.SetPixels(_backgroundTextureOryginal.GetPixels());
                    }
                    redrawRequest = true;

                    // removing requested label
                    if (_labels[i].SourceData.RemoveRequest)
                    {
                        _labels.RemoveAll(l => l.SourceData.Equals(_labels[i].SourceData));
                    }
                }
            }
            if (redrawRequest)
            {
                foreach (Label label in _labels)
                {
                    label.Draw(_backgroundTextureOryginal, _backgroundTexture);
                }

                _backgroundTexture.Apply();
            }
            foreach (Label label in _labels)
            {
                label.DrawGUI();
            }

            return(_controlRect);
        }
예제 #3
0
        /// <summary> Draws the component [have to be invoked in OnGUI]..</summary>
        /// <param name="rect">X position for the timeline.</param>
        /// <param name="scrollDelta">Scroll delta.</param>
        /// <returns>Real component size.</returns>
        public Rect GUIDraw(float xPos, float scrollDelta)
        {
            base.Draw(_rect, _rectWasChanged);

            _mousePos = Event.current.mousePosition;
            Rect GUITextureSoundRectTemp = GUITextureSoundRect;

            if (_allowDrag && _rect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    _wasMouseDown = true;
                    if (GUITextureSoundRectTemp.Contains(_mousePos))
                    {
                        _diffAtGrab = _mousePos.x - _timeLinePanel.TimeToWorldX((float)_audioClipStartTime);
                    }
                }
                if (_wasMouseDown && Event.current.type == EventType.MouseDrag)
                {
                    _wasMouseDown = false;
                    if (!_dragOutsideAudioClip && GUITextureSoundRectTemp.Contains(_mousePos))
                    {
                        _dragOnAudioClip = true;
                    }
                    else
                    {
                        _dragOutsideAudioClip = true;
                    }
                }

                if (((_wasMouseDown && Event.current.type == EventType.MouseUp) || _dragOutsideAudioClip))
                {
                    _timeLinePanel.TimeLineEngine.SetTime(_timeLinePanel.WorldXToTime(Event.current.mousePosition.x));
                }
            }
            if (Event.current.type == EventType.MouseUp)
            {
                _dragOnAudioClip      = false;
                _dragOutsideAudioClip = false;
                _wasMouseDown         = false;
            }


            if (_soundWavesTexture == null || _durationWasChanged || _rectWasChanged || _lastXPos != xPos || scrollDelta != 0)
            {
                _lastXPos           = xPos;
                _rectWasChanged     = false;
                _durationWasChanged = false;

                int textureWidth  = (int)_rect.width;
                int textureHeight = (int)_rect.height;

                int soundWavesTextureWidth  = textureWidth - BorderThickness * 2;
                int soundWavesTextureHeight = textureHeight - BorderThickness * 2;
                _soundWavesTexture = new Texture2D(soundWavesTextureWidth, soundWavesTextureHeight, TextureFormat.ARGB32, false);
                bool valid = true;

                Rect textureSoundRect = TextureSoundRect;
                if (_audioClip == null || textureSoundRect.width == 0)
                {
                    valid = false;
                }

                Color[] soundWavesBackgroundColors;
                soundWavesBackgroundColors = new Color[soundWavesTextureWidth * soundWavesTextureHeight];
                soundWavesBackgroundColors.Fill(NormalColor);
                _soundWavesTexture.SetPixels(0, 0, soundWavesTextureWidth, soundWavesTextureHeight, soundWavesBackgroundColors);

                if (valid)
                {
                    soundWavesBackgroundColors = new Color[(int)(textureSoundRect.width * textureSoundRect.height)];
                    soundWavesBackgroundColors.Fill(new Color32(211, 211, 211, 255));

                    _soundWavesTexture.SetPixels((int)textureSoundRect.x, (int)textureSoundRect.y, (int)textureSoundRect.width, (int)textureSoundRect.height, soundWavesBackgroundColors);
                    if (_audioClip != null)
                    {
                        AudioUtils.DoRenderPreview(_audioClip, _soundWavesTexture, _timeLinePanel.TimeLineEngine, _lastXPos, _audioClipStartTime);
                    }
                    else
                    {
                        _soundWavesTexture.Apply();
                    }
                }
                else
                {
                    _soundWavesTexture.Apply();
                }

                _soundWavesTextureStyle.normal.background = _soundWavesTexture;
                // refresh
                SetTimeFromSec((float)AudioClipStartTime.TotalSeconds);
            }

            GUI.Box(new Rect(_rect.x + BorderThickness, _rect.y + BorderThickness, _rect.width - BorderThickness * 2, _rect.height - BorderThickness * 2), GUIContent.none, _soundWavesTextureStyle);
            if (_dragOnAudioClip)
            {
                EditorGUIUtility.AddCursorRect(GUITextureSoundRectTemp, MouseCursor.Pan);
            }
            return(_controlRect);
        }